Changeset 74568 in webkit
- Timestamp:
- Dec 23, 2010, 11:16:59 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/WebCore.gypi (modified) (1 diff)
-
WebCore/page/FrameView.cpp (modified) (1 diff)
-
WebCore/platform/ScrollView.cpp (modified) (4 diffs)
-
WebCore/platform/ScrollView.h (modified) (2 diffs)
-
WebCore/platform/graphics/chromium/LayerChromium.h (modified) (1 diff)
-
WebCore/platform/graphics/chromium/LayerRendererChromium.cpp (modified) (12 diffs)
-
WebCore/platform/graphics/chromium/LayerRendererChromium.h (modified) (6 diffs)
-
WebCore/platform/graphics/chromium/LayerTilerChromium.cpp (added)
-
WebCore/platform/graphics/chromium/LayerTilerChromium.h (added)
-
WebKit/chromium/ChangeLog (modified) (1 diff)
-
WebKit/chromium/src/WebViewImpl.cpp (modified) (4 diffs)
-
WebKit/chromium/src/WebViewImpl.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r74566 r74568 1 2010-12-20 Adrienne Walker <enne@google.com> 2 3 Reviewed by Kenneth Russell. 4 5 [chromium] Tile root layer of the compositor. 6 https://bugs.webkit.org/show_bug.cgi?id=49947 7 8 Refactor root layer update and drawing from LayerRendererChromium into 9 LayerTilerChromium. The root layer is now drawn as multiple tiles 10 rather than as one single large texture. Scrollbars are now drawn 11 separately rather than as part of the root layer. 12 13 Test: LayoutTests/compositing/ 14 15 * WebCore.gypi: 16 * page/FrameView.cpp: 17 (WebCore::FrameView::repaintContentRectangle): 18 * platform/ScrollView.cpp: 19 (WebCore::ScrollView::ScrollView): 20 (WebCore::ScrollView::setClipsRepaints): 21 * platform/ScrollView.h: 22 (WebCore::ScrollView::clipsRepaints): 23 * platform/graphics/chromium/LayerChromium.h: 24 * platform/graphics/chromium/LayerRendererChromium.cpp: 25 (WebCore::LayerRendererChromium::LayerRendererChromium): 26 (WebCore::LayerRendererChromium::~LayerRendererChromium): 27 (WebCore::LayerRendererChromium::useShader): 28 (WebCore::LayerRendererChromium::verticalScrollbarRect): 29 (WebCore::LayerRendererChromium::horizontalScrollbarRect): 30 (WebCore::LayerRendererChromium::invalidateRootLayerRect): 31 (WebCore::LayerRendererChromium::updateAndDrawRootLayer): 32 (WebCore::LayerRendererChromium::drawLayers): 33 (WebCore::LayerRendererChromium::setRootLayer): 34 (WebCore::LayerRendererChromium::initializeSharedObjects): 35 (WebCore::LayerRendererChromium::cleanupSharedObjects): 36 * platform/graphics/chromium/LayerRendererChromium.h: 37 * platform/graphics/chromium/LayerTilerChromium.cpp: Added. 38 (WebCore::LayerTilerChromium::create): 39 (WebCore::LayerTilerChromium::LayerTilerChromium): 40 (WebCore::LayerTilerChromium::~LayerTilerChromium): 41 (WebCore::LayerTilerChromium::layerRendererContext): 42 (WebCore::LayerTilerChromium::setTileSize): 43 (WebCore::LayerTilerChromium::reset): 44 (WebCore::LayerTilerChromium::createTile): 45 (WebCore::LayerTilerChromium::invalidateTiles): 46 (WebCore::LayerTilerChromium::contentRectToTileIndices): 47 (WebCore::LayerTilerChromium::contentRectToLayerRect): 48 (WebCore::LayerTilerChromium::layerRectToContentRect): 49 (WebCore::LayerTilerChromium::tileIndex): 50 (WebCore::LayerTilerChromium::tileContentRect): 51 (WebCore::LayerTilerChromium::tileLayerRect): 52 (WebCore::LayerTilerChromium::invalidateRect): 53 (WebCore::LayerTilerChromium::invalidateEntireLayer): 54 (WebCore::LayerTilerChromium::update): 55 (WebCore::LayerTilerChromium::setLayerPosition): 56 (WebCore::LayerTilerChromium::draw): 57 (WebCore::LayerTilerChromium::resizeLayer): 58 (WebCore::LayerTilerChromium::growLayerToContain): 59 (WebCore::LayerTilerChromium::Tile::~Tile): 60 (WebCore::LayerTilerChromium::Tile::releaseTextureId): 61 * platform/graphics/chromium/LayerTilerChromium.h: Added. 62 (WebCore::LayerTilerChromium::Tile::Tile): 63 (WebCore::LayerTilerChromium::Tile::textureId): 64 (WebCore::LayerTilerChromium::Tile::dirty): 65 (WebCore::LayerTilerChromium::Tile::clearDirty): 66 (WebCore::LayerTilerChromium::layerRenderer): 67 1 68 2010-12-22 Ryosuke Niwa <rniwa@webkit.org> 2 69 -
trunk/WebCore/WebCore.gypi
r74236 r74568 2600 2600 'platform/graphics/chromium/LayerTexture.cpp', 2601 2601 'platform/graphics/chromium/LayerTexture.h', 2602 'platform/graphics/chromium/LayerTilerChromium.cpp', 2603 'platform/graphics/chromium/LayerTilerChromium.h', 2602 2604 'platform/graphics/chromium/MediaPlayerPrivateChromium.h', 2603 2605 'platform/graphics/chromium/PlatformIcon.h', -
trunk/WebCore/page/FrameView.cpp
r74524 r74568 1315 1315 if ((m_deferringRepaints || m_deferredRepaintTimer.isActive() || delay) && !immediate) { 1316 1316 IntRect paintRect = r; 1317 if ( !paintsEntireContents())1317 if (clipsRepaints() && !paintsEntireContents()) 1318 1318 paintRect.intersect(visibleContentRect()); 1319 1319 if (paintRect.isEmpty()) -
trunk/WebCore/platform/ScrollView.cpp
r73941 r74568 54 54 , m_useFixedLayout(false) 55 55 , m_paintsEntireContents(false) 56 , m_clipsRepaints(true) 56 57 , m_delegatesScrolling(false) 57 58 { … … 201 202 { 202 203 m_paintsEntireContents = paintsEntireContents; 204 } 205 206 void ScrollView::setClipsRepaints(bool clipsRepaints) 207 { 208 m_clipsRepaints = clipsRepaints; 203 209 } 204 210 … … 795 801 { 796 802 IntRect paintRect = rect; 797 if ( !paintsEntireContents())803 if (clipsRepaints() && !paintsEntireContents()) 798 804 paintRect.intersect(visibleContentRect()); 799 805 if (paintRect.isEmpty()) … … 1156 1162 1157 1163 } 1158 -
trunk/WebCore/platform/ScrollView.h
r73941 r74568 112 112 void setPaintsEntireContents(bool); 113 113 114 // By default, paint events are clipped to the visible area. If set to 115 // false, paint events are no longer clipped. paintsEntireContents() implies !clipsRepaints(). 116 bool clipsRepaints() const { return m_clipsRepaints; } 117 void setClipsRepaints(bool); 118 114 119 // By default programmatic scrolling is handled by WebCore and not by the UI application. 115 120 // In the case of using a tiled backing store, this mode can be set, so that the scroll requests … … 326 331 327 332 bool m_paintsEntireContents; 333 bool m_clipsRepaints; 328 334 bool m_delegatesScrolling; 329 335 -
trunk/WebCore/platform/graphics/chromium/LayerChromium.h
r73663 r74568 61 61 class LayerChromium : public RefCounted<LayerChromium> { 62 62 friend class LayerRendererChromium; 63 friend class LayerTilerChromium; 63 64 public: 64 65 static PassRefPtr<LayerChromium> create(GraphicsLayerChromium* owner = 0); -
trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
r74440 r74568 101 101 102 102 LayerRendererChromium::LayerRendererChromium(PassRefPtr<GraphicsContext3D> context) 103 : m_rootLayerTextureId(0) 104 , m_rootLayerTextureWidth(0) 103 : m_rootLayerTextureWidth(0) 105 104 , m_rootLayerTextureHeight(0) 106 105 , m_rootLayer(0) … … 113 112 { 114 113 m_hardwareCompositing = initializeSharedObjects(); 114 m_rootLayerTiler = LayerTilerChromium::create(this, IntSize(256, 256)); 115 ASSERT(m_rootLayerTiler); 115 116 } 116 117 … … 118 119 { 119 120 cleanupSharedObjects(); 121 122 // Because the tilers need to clean up textures, clean them up explicitly 123 // before the GraphicsContext3D is destroyed. 124 m_rootLayerTiler.clear(); 125 m_horizontalScrollbarTiler.clear(); 126 m_verticalScrollbarTiler.clear(); 120 127 } 121 128 … … 132 139 } 133 140 134 // Creates a canvas and an associated graphics context that the root layer will135 // render into.136 void LayerRendererChromium::setRootLayerCanvasSize(const IntSize& size)137 {138 if (size == m_rootLayerCanvasSize)139 return;140 141 #if PLATFORM(SKIA)142 // Create new canvas and context. OwnPtr takes care of freeing up143 // the old ones.144 m_rootLayerCanvas = new skia::PlatformCanvas(size.width(), size.height(), false);145 m_rootLayerSkiaContext = new PlatformContextSkia(m_rootLayerCanvas.get());146 m_rootLayerGraphicsContext = new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(m_rootLayerSkiaContext.get()));147 #elif PLATFORM(CG)148 // Release the previous CGBitmapContext before reallocating the backing store as a precaution.149 m_rootLayerCGContext.adoptCF(0);150 int rowBytes = 4 * size.width();151 m_rootLayerBackingStore.resize(rowBytes * size.height());152 memset(m_rootLayerBackingStore.data(), 0, m_rootLayerBackingStore.size());153 RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());154 m_rootLayerCGContext.adoptCF(CGBitmapContextCreate(m_rootLayerBackingStore.data(),155 size.width(), size.height(), 8, rowBytes,156 colorSpace.get(),157 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));158 CGContextTranslateCTM(m_rootLayerCGContext.get(), 0, size.height());159 CGContextScaleCTM(m_rootLayerCGContext.get(), 1, -1);160 m_rootLayerGraphicsContext = new GraphicsContext(m_rootLayerCGContext.get());161 #else162 #error "Need to implement for your platform."163 #endif164 165 m_rootLayerCanvasSize = size;166 }167 168 141 void LayerRendererChromium::useShader(unsigned programId) 169 142 { … … 174 147 } 175 148 176 // This method must be called before any other updates are made to the 177 // root layer texture. It resizes the root layer texture and scrolls its 178 // contents as needed. It also sets up common GL state used by the rest 179 // of the layer drawing code. 180 void LayerRendererChromium::prepareToDrawLayers(const IntRect& visibleRect, const IntRect& contentRect, 181 const IntPoint& scrollPosition) 149 IntRect LayerRendererChromium::verticalScrollbarRect(const IntRect& visibleRect, const IntRect& contentRect) 150 { 151 IntRect verticalScrollbar(IntPoint(contentRect.right(), contentRect.y()), IntSize(visibleRect.width() - contentRect.width(), visibleRect.height())); 152 return verticalScrollbar; 153 } 154 155 IntRect LayerRendererChromium::horizontalScrollbarRect(const IntRect& visibleRect, const IntRect& contentRect) 156 { 157 IntRect horizontalScrollbar(IntPoint(contentRect.x(), contentRect.bottom()), IntSize(visibleRect.width(), visibleRect.height() - contentRect.height())); 158 return horizontalScrollbar; 159 } 160 161 void LayerRendererChromium::invalidateRootLayerRect(const IntRect& dirtyRect, const IntRect& visibleRect, const IntRect& contentRect) 162 { 163 if (contentRect.intersects(dirtyRect)) 164 m_rootLayerTiler->invalidateRect(dirtyRect); 165 if (m_horizontalScrollbarTiler) { 166 IntRect scrollbar = horizontalScrollbarRect(visibleRect, contentRect); 167 if (dirtyRect.intersects(scrollbar)) { 168 m_horizontalScrollbarTiler->setLayerPosition(scrollbar.location()); 169 m_horizontalScrollbarTiler->invalidateRect(dirtyRect); 170 } 171 } 172 if (m_verticalScrollbarTiler) { 173 IntRect scrollbar = verticalScrollbarRect(visibleRect, contentRect); 174 if (dirtyRect.intersects(scrollbar)) { 175 m_verticalScrollbarTiler->setLayerPosition(scrollbar.location()); 176 m_verticalScrollbarTiler->invalidateRect(dirtyRect); 177 } 178 } 179 } 180 181 void LayerRendererChromium::updateAndDrawRootLayer(TilePaintInterface& tilePaint, TilePaintInterface& scrollbarPaint, const IntRect& visibleRect, const IntRect& contentRect) 182 { 183 // Mask out writes to alpha channel: subpixel antialiasing via Skia results in invalid 184 // zero alpha values on text glyphs. The root layer is always opaque. 185 GLC(m_context.get(), m_context->colorMask(true, true, true, false)); 186 187 m_rootLayerTiler->update(tilePaint, visibleRect); 188 m_rootLayerTiler->draw(visibleRect); 189 190 if (visibleRect.width() > contentRect.width()) { 191 IntRect verticalScrollbar = verticalScrollbarRect(visibleRect, contentRect); 192 IntSize tileSize = verticalScrollbar.size().shrunkTo(IntSize(m_maxTextureSize, m_maxTextureSize)); 193 if (!m_verticalScrollbarTiler) 194 m_verticalScrollbarTiler = LayerTilerChromium::create(this, tileSize); 195 else 196 m_verticalScrollbarTiler->setTileSize(tileSize); 197 m_verticalScrollbarTiler->setLayerPosition(verticalScrollbar.location()); 198 m_verticalScrollbarTiler->update(scrollbarPaint, visibleRect); 199 m_verticalScrollbarTiler->draw(visibleRect); 200 } 201 202 if (visibleRect.height() > contentRect.height()) { 203 IntRect horizontalScrollbar = horizontalScrollbarRect(visibleRect, contentRect); 204 IntSize tileSize = horizontalScrollbar.size().shrunkTo(IntSize(m_maxTextureSize, m_maxTextureSize)); 205 if (!m_horizontalScrollbarTiler) 206 m_horizontalScrollbarTiler = LayerTilerChromium::create(this, tileSize); 207 else 208 m_horizontalScrollbarTiler->setTileSize(tileSize); 209 m_horizontalScrollbarTiler->setLayerPosition(horizontalScrollbar.location()); 210 m_horizontalScrollbarTiler->update(scrollbarPaint, visibleRect); 211 m_horizontalScrollbarTiler->draw(visibleRect); 212 } 213 } 214 215 void LayerRendererChromium::drawLayers(const IntRect& visibleRect, const IntRect& contentRect, 216 const IntPoint& scrollPosition, TilePaintInterface& tilePaint, 217 TilePaintInterface& scrollbarPaint) 182 218 { 183 219 ASSERT(m_hardwareCompositing); … … 187 223 188 224 makeContextCurrent(); 189 190 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_rootLayerTextureId));191 192 bool skipScroll = false;193 225 194 226 // If the size of the visible area has changed then allocate a new texture … … 200 232 m_rootLayerTextureWidth = visibleRectWidth; 201 233 m_rootLayerTextureHeight = visibleRectHeight; 202 GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, m_rootLayerTextureWidth, m_rootLayerTextureHeight, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE));203 234 204 235 // Reset the current render surface to force an update of the viewport and 205 236 // projection matrix next time useRenderSurface is called. 206 237 m_currentRenderSurface = 0; 207 208 // The root layer texture was just resized so its contents are not209 // useful for scrolling.210 skipScroll = true;211 238 } 212 239 … … 224 251 GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND)); 225 252 226 if (m_scrollPosition == IntPoint(-1, -1)) {227 m_scrollPosition = scrollPosition;228 skipScroll = true;229 }230 231 IntPoint scrollDelta = toPoint(scrollPosition - m_scrollPosition);232 233 // Scrolling larger than the contentRect size does not preserve any of the pixels, so there is234 // no need to copy framebuffer pixels back into the texture.235 if (abs(scrollDelta.y()) > contentRect.height() || abs(scrollDelta.x()) > contentRect.width())236 skipScroll = true;237 238 // Scroll the backbuffer239 if (!skipScroll && (scrollDelta.x() || scrollDelta.y())) {240 // Scrolling works as follows: We render a quad with the current root layer contents241 // translated by the amount the page has scrolled since the last update and then read the242 // pixels of the content area (visible area excluding the scroll bars) back into the243 // root layer texture. The newly exposed area will be filled by a subsequent drawLayersIntoRect call244 TransformationMatrix scrolledLayerMatrix;245 246 scrolledLayerMatrix.translate3d(0.5 * visibleRect.width() - scrollDelta.x(),247 0.5 * visibleRect.height() + scrollDelta.y(), 0);248 scrolledLayerMatrix.scale3d(1, -1, 1);249 250 const RenderSurfaceChromium::SharedValues* rsv = renderSurfaceSharedValues();251 useShader(rsv->shaderProgram());252 GLC(m_context.get(), m_context->uniform1i(rsv->shaderSamplerLocation(), 0));253 LayerChromium::drawTexturedQuad(m_context.get(), m_projectionMatrix, scrolledLayerMatrix,254 visibleRect.width(), visibleRect.height(), 1,255 rsv->shaderMatrixLocation(), rsv->shaderAlphaLocation());256 257 GLC(m_context.get(), m_context->copyTexSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, 0, 0, contentRect.width(), contentRect.height()));258 }259 260 253 m_scrollPosition = scrollPosition; 261 }262 263 void LayerRendererChromium::updateRootLayerTextureRect(const IntRect& updateRect)264 {265 ASSERT(m_hardwareCompositing);266 267 if (!m_rootLayer)268 return;269 270 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_rootLayerTextureId));271 272 // Update the root layer texture.273 ASSERT((updateRect.right() <= m_rootLayerTextureWidth)274 && (updateRect.bottom() <= m_rootLayerTextureHeight));275 276 #if PLATFORM(SKIA)277 // Get the contents of the updated rect.278 const SkBitmap& bitmap = m_rootLayerCanvas->getDevice()->accessBitmap(false);279 ASSERT(bitmap.width() == updateRect.width() && bitmap.height() == updateRect.height());280 void* pixels = bitmap.getPixels();281 #elif PLATFORM(CG)282 // Get the contents of the updated rect.283 ASSERT(static_cast<int>(CGBitmapContextGetWidth(m_rootLayerCGContext.get())) == updateRect.width() && static_cast<int>(CGBitmapContextGetHeight(m_rootLayerCGContext.get())) == updateRect.height());284 void* pixels = m_rootLayerBackingStore.data();285 #else286 #error "Need to implement for your platform."287 #endif288 // Copy the contents of the updated rect to the root layer texture.289 GLC(m_context.get(), m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));290 }291 292 void LayerRendererChromium::drawLayers(const IntRect& visibleRect, const IntRect& contentRect)293 {294 ASSERT(m_hardwareCompositing);295 254 296 255 m_defaultRenderSurface = m_rootLayer->m_renderSurface.get(); … … 305 264 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); 306 265 307 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_rootLayerTextureId)); 308 309 // Render the root layer using a quad that takes up the entire visible area of the window. 310 // We reuse the shader program used by ContentLayerChromium. 311 const ContentLayerChromium::SharedValues* contentLayerValues = contentLayerSharedValues(); 312 useShader(contentLayerValues->contentShaderProgram()); 313 GLC(m_context.get(), m_context->uniform1i(contentLayerValues->shaderSamplerLocation(), 0)); 314 // Mask out writes to alpha channel: ClearType via Skia results in invalid 315 // zero alpha values on text glyphs. The root layer is always opaque. 316 GLC(m_context.get(), m_context->colorMask(true, true, true, false)); 317 TransformationMatrix layerMatrix; 318 layerMatrix.translate3d(visibleRect.width() * 0.5f, visibleRect.height() * 0.5f, 0); 319 LayerChromium::drawTexturedQuad(m_context.get(), m_projectionMatrix, layerMatrix, 320 visibleRect.width(), visibleRect.height(), 1, 321 contentLayerValues->shaderMatrixLocation(), contentLayerValues->shaderAlphaLocation()); 322 GLC(m_context.get(), m_context->colorMask(true, true, true, true)); 266 updateAndDrawRootLayer(tilePaint, scrollbarPaint, visibleRect, contentRect); 323 267 324 268 // Set the root visible/content rects --- used by subsequent drawLayers calls. … … 388 332 // consider exposing a different entry point on GraphicsContext3D. 389 333 m_context->prepareTexture(); 334 } 335 336 void LayerRendererChromium::setRootLayer(PassRefPtr<LayerChromium> layer) 337 { 338 m_rootLayer = layer; 339 m_rootLayerTiler->invalidateEntireLayer(); 340 if (m_horizontalScrollbarTiler) 341 m_horizontalScrollbarTiler->invalidateEntireLayer(); 342 if (m_verticalScrollbarTiler) 343 m_verticalScrollbarTiler->invalidateEntireLayer(); 390 344 } 391 345 … … 783 737 makeContextCurrent(); 784 738 785 // Create a texture object to hold the contents of the root layer.786 m_rootLayerTextureId = createLayerTexture();787 if (!m_rootLayerTextureId) {788 LOG_ERROR("Failed to create texture for root layer");789 cleanupSharedObjects();790 return false;791 }792 // Turn off filtering for the root layer to avoid blurring from the repeated793 // writes and reads to the framebuffer that happen while scrolling.794 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_rootLayerTextureId));795 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST));796 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::NEAREST));797 798 739 // Get the max texture size supported by the system. 799 740 m_maxTextureSize = 0; … … 830 771 m_pluginLayerSharedValues.clear(); 831 772 m_renderSurfaceSharedValues.clear(); 832 833 if (m_rootLayerTextureId) {834 deleteLayerTexture(m_rootLayerTextureId);835 m_rootLayerTextureId = 0;836 }837 838 773 if (m_offscreenFramebufferId) 839 774 GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId)); -
trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.h
r74358 r74568 39 39 #include "IntRect.h" 40 40 #include "LayerChromium.h" 41 #include "LayerTilerChromium.h" 41 42 #include "PluginLayerChromium.h" 42 43 #include "RenderSurfaceChromium.h" … … 68 69 GraphicsContext3D* context(); 69 70 70 // updates size of root texture, if needed, and scrolls the backbuffer. 71 void prepareToDrawLayers(const IntRect& visibleRect, const IntRect& contentRect, const IntPoint& scrollPosition); 72 73 // updates a rectangle within the root layer texture 74 void updateRootLayerTextureRect(const IntRect& updateRect); 75 76 // draws the current layers onto the backbuffer 77 void drawLayers(const IntRect& visibleRect, const IntRect& contentRect); 71 void invalidateRootLayerRect(const IntRect& dirtyRect, const IntRect& visibleRect, const IntRect& contentRect); 72 73 // updates and draws the current layers onto the backbuffer 74 void drawLayers(const IntRect& visibleRect, const IntRect& contentRect, 75 const IntPoint& scrollPosition, TilePaintInterface& tilePaint, 76 TilePaintInterface& scrollbarPaint); 78 77 79 78 // waits for rendering to finish … … 83 82 void present(); 84 83 85 void setRootLayer(PassRefPtr<LayerChromium> layer) { m_rootLayer = layer; }84 void setRootLayer(PassRefPtr<LayerChromium> layer); 86 85 LayerChromium* rootLayer() { return m_rootLayer.get(); } 87 86 void transferRootLayer(LayerRendererChromium* other) { other->m_rootLayer = m_rootLayer.release(); } … … 127 126 void drawLayer(LayerChromium*, RenderSurfaceChromium*); 128 127 128 void updateAndDrawRootLayer(TilePaintInterface& tilePaint, TilePaintInterface& scrollbarPaint, const IntRect& visibleRect, const IntRect& contentRect); 129 129 130 bool isLayerVisible(LayerChromium*, const TransformationMatrix&, const IntRect& visibleRect); 130 131 … … 140 141 void cleanupSharedObjects(); 141 142 142 unsigned m_rootLayerTextureId; 143 static IntRect verticalScrollbarRect(const IntRect& visibleRect, const IntRect& contentRect); 144 static IntRect horizontalScrollbarRect(const IntRect& visibleRect, const IntRect& contentRect); 145 143 146 int m_rootLayerTextureWidth; 144 147 int m_rootLayerTextureHeight; … … 147 150 148 151 RefPtr<LayerChromium> m_rootLayer; 152 OwnPtr<LayerTilerChromium> m_rootLayerTiler; 153 OwnPtr<LayerTilerChromium> m_horizontalScrollbarTiler; 154 OwnPtr<LayerTilerChromium> m_verticalScrollbarTiler; 149 155 150 156 IntPoint m_scrollPosition; -
trunk/WebKit/chromium/ChangeLog
r74566 r74568 1 2010-12-20 Adrienne Walker <enne@google.com> 2 3 Reviewed by Kenneth Russell. 4 5 [chromium] Tile root layer of the compositor. 6 https://bugs.webkit.org/show_bug.cgi?id=49947 7 8 Refactor root layer logic out of WebViewImpl and into 9 LayerTilerChromium. The painting is now done through an interface 10 rather than directly in WebViewImpl. 11 12 * src/WebViewImpl.cpp: 13 (WebKit::WebViewImpl::scrollRootLayerRect): 14 (WebKit::WebViewImpl::invalidateRootLayerRect): 15 (WebKit::WebViewImpl::setIsAcceleratedCompositingActive): 16 (WebKit::WebViewImplTilePaintInterface::WebViewImplTilePaintInterface): 17 (WebKit::WebViewImplTilePaintInterface::paint): 18 (WebKit::WebViewImplScrollbarPaintInterface::WebViewImplScrollbarPaintInterface): 19 (WebKit::WebViewImplScrollbarPaintInterface::paint): 20 (WebKit::WebViewImpl::doComposite): 21 * src/WebViewImpl.h: 22 1 23 2010-12-22 Ryosuke Niwa <rniwa@webkit.org> 2 24 -
trunk/WebKit/chromium/src/WebViewImpl.cpp
r73940 r74568 2269 2269 void WebViewImpl::scrollRootLayerRect(const IntSize& scrollDelta, const IntRect& clipRect) 2270 2270 { 2271 setRootLayerNeedsDisplay(); 2272 } 2273 2274 void WebViewImpl::invalidateRootLayerRect(const IntRect& rect) 2275 { 2271 2276 ASSERT(m_layerRenderer); 2272 // Compute the damage rect in viewport space. 2273 WebFrameImpl* webframe = mainFrameImpl(); 2274 if (!webframe) 2275 return; 2276 FrameView* view = webframe->frameView(); 2277 if (!view) 2278 return; 2279 2277 2278 if (!page()) 2279 return; 2280 2281 FrameView* view = page()->mainFrame()->view(); 2280 2282 IntRect contentRect = view->visibleContentRect(false); 2281 IntRect screenRect = view->contentsToWindow(contentRect); 2282 2283 // We support fast scrolling in one direction at a time. 2284 if (scrollDelta.width() && scrollDelta.height()) { 2285 invalidateRootLayerRect(WebRect(screenRect)); 2286 return; 2287 } 2288 2289 // Compute the region we will expose by scrolling. We use the 2290 // content rect for invalidation. Using this space for damage 2291 // rects allows us to intermix invalidates with scrolls. 2292 IntRect damagedContentsRect; 2293 if (scrollDelta.width()) { 2294 int dx = scrollDelta.width(); 2295 damagedContentsRect.setY(screenRect.y()); 2296 damagedContentsRect.setHeight(screenRect.height()); 2297 if (dx > 0) { 2298 damagedContentsRect.setX(screenRect.x()); 2299 damagedContentsRect.setWidth(dx); 2300 } else { 2301 damagedContentsRect.setX(screenRect.right() + dx); 2302 damagedContentsRect.setWidth(-dx); 2303 } 2304 } else { 2305 int dy = scrollDelta.height(); 2306 damagedContentsRect.setX(screenRect.x()); 2307 damagedContentsRect.setWidth(screenRect.width()); 2308 if (dy > 0) { 2309 damagedContentsRect.setY(screenRect.y()); 2310 damagedContentsRect.setHeight(dy); 2311 } else { 2312 damagedContentsRect.setY(screenRect.bottom() + dy); 2313 damagedContentsRect.setHeight(-dy); 2314 } 2315 } 2316 2317 // Move the previous damage 2318 m_rootLayerScrollDamage.move(scrollDelta.width(), scrollDelta.height()); 2319 // Union with the new damage rect. 2320 m_rootLayerScrollDamage.unite(damagedContentsRect); 2321 2322 // Scroll any existing damage that intersects with clip rect 2323 if (clipRect.intersects(m_rootLayerDirtyRect)) { 2324 // Find the inner damage 2325 IntRect innerDamage(clipRect); 2326 innerDamage.intersect(m_rootLayerDirtyRect); 2327 2328 // Move the damage 2329 innerDamage.move(scrollDelta.width(), scrollDelta.height()); 2330 2331 // Merge it back into the damaged rect 2332 m_rootLayerDirtyRect.unite(innerDamage); 2333 } 2334 2335 setRootLayerNeedsDisplay(); 2336 } 2337 2338 void WebViewImpl::invalidateRootLayerRect(const IntRect& rect) 2339 { 2340 ASSERT(m_layerRenderer); 2341 2342 if (!page()) 2343 return; 2344 2345 // FIXME: add a smarter damage aggregation logic and/or unify with 2346 // LayerChromium's damage logic 2347 m_rootLayerDirtyRect.unite(rect); 2283 IntRect visibleRect = view->visibleContentRect(true); 2284 2285 IntRect dirtyRect = view->windowToContents(rect); 2286 m_layerRenderer->invalidateRootLayerRect(dirtyRect, visibleRect, contentRect); 2348 2287 setRootLayerNeedsDisplay(); 2349 2288 } … … 2362 2301 m_layerRenderer->finish(); // finish all GL rendering before we hide the window? 2363 2302 m_client->didActivateAcceleratedCompositing(false); 2364 return; 2365 } 2366 2367 if (m_layerRenderer) { 2303 } else if (m_layerRenderer) { 2368 2304 m_isAcceleratedCompositingActive = true; 2369 2305 m_layerRenderer->resizeOnscreenContent(WebCore::IntSize(std::max(1, m_size.width), … … 2371 2307 2372 2308 m_client->didActivateAcceleratedCompositing(true); 2373 return;2374 }2375 2376 RefPtr<GraphicsContext3D> context = m_temporaryOnscreenGraphicsContext3D.release();2377 if (!context) {2378 context = GraphicsContext3D::create(getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow);2379 if (context)2380 context->reshape(std::max(1, m_size.width), std::max(1, m_size.height));2381 }2382 m_layerRenderer = LayerRendererChromium::create(context.release());2383 if (m_layerRenderer) {2384 m_client->didActivateAcceleratedCompositing(true);2385 m_isAcceleratedCompositingActive = true;2386 m_compositorCreationFailed = false;2387 2309 } else { 2388 m_isAcceleratedCompositingActive = false; 2389 m_client->didActivateAcceleratedCompositing(false); 2390 m_compositorCreationFailed = true; 2391 } 2392 } 2393 2394 void WebViewImpl::updateRootLayerContents(const IntRect& rect) 2395 { 2396 if (!isAcceleratedCompositingActive()) 2397 return; 2398 2399 WebFrameImpl* webframe = mainFrameImpl(); 2400 if (!webframe) 2401 return; 2402 FrameView* view = webframe->frameView(); 2403 if (!view) 2404 return; 2405 2406 LayerChromium* rootLayer = m_layerRenderer->rootLayer(); 2407 if (rootLayer) { 2408 IntRect visibleRect = view->visibleContentRect(true); 2409 2410 m_layerRenderer->setRootLayerCanvasSize(IntSize(rect.width(), rect.height())); 2411 GraphicsContext* rootLayerContext = m_layerRenderer->rootLayerGraphicsContext(); 2412 2413 #if PLATFORM(SKIA) 2414 PlatformContextSkia* skiaContext = rootLayerContext->platformContext(); 2415 skia::PlatformCanvas* platformCanvas = skiaContext->canvas(); 2416 2417 platformCanvas->save(); 2418 2419 // Bring the canvas into the coordinate system of the paint rect. 2420 platformCanvas->translate(static_cast<SkScalar>(-rect.x()), static_cast<SkScalar>(-rect.y())); 2421 2422 rootLayerContext->save(); 2423 2424 webframe->paintWithContext(*rootLayerContext, rect); 2425 rootLayerContext->restore(); 2426 2427 platformCanvas->restore(); 2428 #elif PLATFORM(CG) 2429 CGContextRef cgContext = rootLayerContext->platformContext(); 2430 2431 CGContextSaveGState(cgContext); 2432 2433 // Bring the CoreGraphics context into the coordinate system of the paint rect. 2434 CGContextTranslateCTM(cgContext, -rect.x(), -rect.y()); 2435 2436 rootLayerContext->save(); 2437 2438 webframe->paintWithContext(*rootLayerContext, rect); 2439 rootLayerContext->restore(); 2440 2441 CGContextRestoreGState(cgContext); 2442 #else 2443 #error Must port to your platform 2444 #endif 2445 } 2446 } 2310 RefPtr<GraphicsContext3D> context = m_temporaryOnscreenGraphicsContext3D.release(); 2311 if (!context) { 2312 context = GraphicsContext3D::create(getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow); 2313 if (context) 2314 context->reshape(std::max(1, m_size.width), std::max(1, m_size.height)); 2315 } 2316 m_layerRenderer = LayerRendererChromium::create(context.release()); 2317 if (m_layerRenderer) { 2318 m_client->didActivateAcceleratedCompositing(true); 2319 m_isAcceleratedCompositingActive = true; 2320 m_compositorCreationFailed = false; 2321 } else { 2322 m_isAcceleratedCompositingActive = false; 2323 m_client->didActivateAcceleratedCompositing(false); 2324 m_compositorCreationFailed = true; 2325 } 2326 } 2327 if (page()) 2328 page()->mainFrame()->view()->setClipsRepaints(!m_isAcceleratedCompositingActive); 2329 } 2330 2331 class WebViewImplTilePaintInterface : public TilePaintInterface { 2332 public: 2333 explicit WebViewImplTilePaintInterface(WebViewImpl* webViewImpl) 2334 : m_webViewImpl(webViewImpl) 2335 { 2336 } 2337 2338 virtual void paint(GraphicsContext& context, const IntRect& contentRect) 2339 { 2340 Page* page = m_webViewImpl->page(); 2341 if (!page) 2342 return; 2343 FrameView* view = page->mainFrame()->view(); 2344 view->paintContents(&context, contentRect); 2345 } 2346 2347 private: 2348 WebViewImpl* m_webViewImpl; 2349 }; 2350 2351 2352 class WebViewImplScrollbarPaintInterface : public TilePaintInterface { 2353 public: 2354 explicit WebViewImplScrollbarPaintInterface(WebViewImpl* webViewImpl) 2355 : m_webViewImpl(webViewImpl) 2356 { 2357 } 2358 2359 virtual void paint(GraphicsContext& context, const IntRect& contentRect) 2360 { 2361 Page* page = m_webViewImpl->page(); 2362 if (!page) 2363 return; 2364 FrameView* view = page->mainFrame()->view(); 2365 2366 context.translate(view->scrollX(), view->scrollY()); 2367 IntRect windowRect = view->contentsToWindow(contentRect); 2368 view->paintScrollbars(&context, windowRect); 2369 } 2370 2371 private: 2372 WebViewImpl* m_webViewImpl; 2373 }; 2447 2374 2448 2375 void WebViewImpl::doComposite() … … 2456 2383 IntRect visibleRect = view->visibleContentRect(true); 2457 2384 IntRect contentRect = view->visibleContentRect(false); 2458 IntRect viewPort = IntRect(0, 0, m_size.width, m_size.height); 2459 2460 // Give the compositor a chance to setup/resize the root texture handle and perform scrolling. 2461 m_layerRenderer->prepareToDrawLayers(visibleRect, contentRect, IntPoint(view->scrollX(), view->scrollY())); 2462 2463 // Draw the contents of the root layer. 2464 Vector<IntRect> damageRects; 2465 damageRects.append(m_rootLayerScrollDamage); 2466 damageRects.append(m_rootLayerDirtyRect); 2467 for (size_t i = 0; i < damageRects.size(); ++i) { 2468 IntRect damagedRect = damageRects[i]; 2469 2470 // Intersect this rectangle with the viewPort. 2471 damagedRect.intersect(viewPort); 2472 2473 // Now render it. 2474 if (damagedRect.width() && damagedRect.height()) { 2475 updateRootLayerContents(damagedRect); 2476 m_layerRenderer->updateRootLayerTextureRect(damagedRect); 2477 } 2478 } 2479 m_rootLayerDirtyRect = IntRect(); 2480 m_rootLayerScrollDamage = IntRect(); 2481 2482 // Draw the actual layers... 2483 m_layerRenderer->drawLayers(visibleRect, contentRect); 2385 IntPoint scroll(view->scrollX(), view->scrollY()); 2386 2387 WebViewImplTilePaintInterface tilePaint(this); 2388 2389 WebViewImplScrollbarPaintInterface scrollbarPaint(this); 2390 m_layerRenderer->drawLayers(visibleRect, contentRect, scroll, tilePaint, scrollbarPaint); 2484 2391 } 2485 2392 -
trunk/WebKit/chromium/src/WebViewImpl.h
r73940 r74568 397 397 #if USE(ACCELERATED_COMPOSITING) 398 398 void setIsAcceleratedCompositingActive(bool); 399 void updateRootLayerContents(const WebCore::IntRect&);400 399 void doComposite(); 401 400 void doPixelReadbackToCanvas(WebCanvas*, const WebCore::IntRect&); … … 529 528 530 529 #if USE(ACCELERATED_COMPOSITING) 531 WebCore::IntRect m_rootLayerDirtyRect;532 530 WebCore::IntRect m_rootLayerScrollDamage; 533 531 RefPtr<WebCore::LayerRendererChromium> m_layerRenderer;
Note:
See TracChangeset
for help on using the changeset viewer.