⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 74568 in webkit


Ignore:
Timestamp:
Dec 23, 2010, 11:16:59 AM (16 years ago)
Author:
enne@google.com
Message:

2010-12-20 Adrienne Walker <​enne@google.com>

Reviewed by Kenneth Russell.

[chromium] Tile root layer of the compositor.
​https://bugs.webkit.org/show_bug.cgi?id=49947

Refactor root layer update and drawing from LayerRendererChromium into
LayerTilerChromium. The root layer is now drawn as multiple tiles
rather than as one single large texture. Scrollbars are now drawn
separately rather than as part of the root layer.

Test: LayoutTests/compositing/

  • WebCore.gypi:
  • page/FrameView.cpp: (WebCore::FrameView::repaintContentRectangle):
  • platform/ScrollView.cpp: (WebCore::ScrollView::ScrollView): (WebCore::ScrollView::setClipsRepaints):
  • platform/ScrollView.h: (WebCore::ScrollView::clipsRepaints):
  • platform/graphics/chromium/LayerChromium.h:
  • platform/graphics/chromium/LayerRendererChromium.cpp: (WebCore::LayerRendererChromium::LayerRendererChromium): (WebCore::LayerRendererChromium::~LayerRendererChromium): (WebCore::LayerRendererChromium::useShader): (WebCore::LayerRendererChromium::verticalScrollbarRect): (WebCore::LayerRendererChromium::horizontalScrollbarRect): (WebCore::LayerRendererChromium::invalidateRootLayerRect): (WebCore::LayerRendererChromium::updateAndDrawRootLayer): (WebCore::LayerRendererChromium::drawLayers): (WebCore::LayerRendererChromium::setRootLayer): (WebCore::LayerRendererChromium::initializeSharedObjects): (WebCore::LayerRendererChromium::cleanupSharedObjects):
  • platform/graphics/chromium/LayerRendererChromium.h:
  • platform/graphics/chromium/LayerTilerChromium.cpp: Added. (WebCore::LayerTilerChromium::create): (WebCore::LayerTilerChromium::LayerTilerChromium): (WebCore::LayerTilerChromium::~LayerTilerChromium): (WebCore::LayerTilerChromium::layerRendererContext): (WebCore::LayerTilerChromium::setTileSize): (WebCore::LayerTilerChromium::reset): (WebCore::LayerTilerChromium::createTile): (WebCore::LayerTilerChromium::invalidateTiles): (WebCore::LayerTilerChromium::contentRectToTileIndices): (WebCore::LayerTilerChromium::contentRectToLayerRect): (WebCore::LayerTilerChromium::layerRectToContentRect): (WebCore::LayerTilerChromium::tileIndex): (WebCore::LayerTilerChromium::tileContentRect): (WebCore::LayerTilerChromium::tileLayerRect): (WebCore::LayerTilerChromium::invalidateRect): (WebCore::LayerTilerChromium::invalidateEntireLayer): (WebCore::LayerTilerChromium::update): (WebCore::LayerTilerChromium::setLayerPosition): (WebCore::LayerTilerChromium::draw): (WebCore::LayerTilerChromium::resizeLayer): (WebCore::LayerTilerChromium::growLayerToContain): (WebCore::LayerTilerChromium::Tile::~Tile): (WebCore::LayerTilerChromium::Tile::releaseTextureId):
  • platform/graphics/chromium/LayerTilerChromium.h: Added. (WebCore::LayerTilerChromium::Tile::Tile): (WebCore::LayerTilerChromium::Tile::textureId): (WebCore::LayerTilerChromium::Tile::dirty): (WebCore::LayerTilerChromium::Tile::clearDirty): (WebCore::LayerTilerChromium::layerRenderer):

2010-12-20 Adrienne Walker <​enne@google.com>

Reviewed by Kenneth Russell.

[chromium] Tile root layer of the compositor.
​https://bugs.webkit.org/show_bug.cgi?id=49947

Refactor root layer logic out of WebViewImpl and into
LayerTilerChromium. The painting is now done through an interface
rather than directly in WebViewImpl.

  • src/WebViewImpl.cpp: (WebKit::WebViewImpl::scrollRootLayerRect): (WebKit::WebViewImpl::invalidateRootLayerRect): (WebKit::WebViewImpl::setIsAcceleratedCompositingActive): (WebKit::WebViewImplTilePaintInterface::WebViewImplTilePaintInterface): (WebKit::WebViewImplTilePaintInterface::paint): (WebKit::WebViewImplScrollbarPaintInterface::WebViewImplScrollbarPaintInterface): (WebKit::WebViewImplScrollbarPaintInterface::paint): (WebKit::WebViewImpl::doComposite):
  • src/WebViewImpl.h:
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r74566 r74568  
     12010-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
    1682010-12-22  Ryosuke Niwa  <rniwa@webkit.org>
    269
  • trunk/WebCore/WebCore.gypi

    r74236 r74568  
    26002600            'platform/graphics/chromium/LayerTexture.cpp',
    26012601            'platform/graphics/chromium/LayerTexture.h',
     2602            'platform/graphics/chromium/LayerTilerChromium.cpp',
     2603            'platform/graphics/chromium/LayerTilerChromium.h',
    26022604            'platform/graphics/chromium/MediaPlayerPrivateChromium.h',
    26032605            'platform/graphics/chromium/PlatformIcon.h',
  • trunk/WebCore/page/FrameView.cpp

    r74524 r74568  
    13151315    if ((m_deferringRepaints || m_deferredRepaintTimer.isActive() || delay) && !immediate) {
    13161316        IntRect paintRect = r;
    1317         if (!paintsEntireContents())
     1317        if (clipsRepaints() && !paintsEntireContents())
    13181318            paintRect.intersect(visibleContentRect());
    13191319        if (paintRect.isEmpty())
  • trunk/WebCore/platform/ScrollView.cpp

    r73941 r74568  
    5454    , m_useFixedLayout(false)
    5555    , m_paintsEntireContents(false)
     56    , m_clipsRepaints(true)
    5657    , m_delegatesScrolling(false)
    5758{
    … …  
    201202{
    202203    m_paintsEntireContents = paintsEntireContents;
     204}
     205
     206void ScrollView::setClipsRepaints(bool clipsRepaints)
     207{
     208    m_clipsRepaints = clipsRepaints;
    203209}
    204210
    … …  
    795801{
    796802    IntRect paintRect = rect;
    797     if (!paintsEntireContents())
     803    if (clipsRepaints() && !paintsEntireContents())
    798804        paintRect.intersect(visibleContentRect());
    799805    if (paintRect.isEmpty())
    … …  
    11561162
    11571163}
    1158 
  • trunk/WebCore/platform/ScrollView.h

    r73941 r74568  
    112112    void setPaintsEntireContents(bool);
    113113
     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
    114119    // By default programmatic scrolling is handled by WebCore and not by the UI application.
    115120    // In the case of using a tiled backing store, this mode can be set, so that the scroll requests
    … …  
    326331
    327332    bool m_paintsEntireContents;
     333    bool m_clipsRepaints;
    328334    bool m_delegatesScrolling;
    329335
  • trunk/WebCore/platform/graphics/chromium/LayerChromium.h

    r73663 r74568  
    6161class LayerChromium : public RefCounted<LayerChromium> {
    6262    friend class LayerRendererChromium;
     63    friend class LayerTilerChromium;
    6364public:
    6465    static PassRefPtr<LayerChromium> create(GraphicsLayerChromium* owner = 0);
  • trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r74440 r74568  
    101101
    102102LayerRendererChromium::LayerRendererChromium(PassRefPtr<GraphicsContext3D> context)
    103     : m_rootLayerTextureId(0)
    104     , m_rootLayerTextureWidth(0)
     103    : m_rootLayerTextureWidth(0)
    105104    , m_rootLayerTextureHeight(0)
    106105    , m_rootLayer(0)
    … …  
    113112{
    114113    m_hardwareCompositing = initializeSharedObjects();
     114    m_rootLayerTiler = LayerTilerChromium::create(this, IntSize(256, 256));
     115    ASSERT(m_rootLayerTiler);
    115116}
    116117
    … …  
    118119{
    119120    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();
    120127}
    121128
    … …  
    132139}
    133140
    134 // Creates a canvas and an associated graphics context that the root layer will
    135 // 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 up
    143     // 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 #else
    162 #error "Need to implement for your platform."
    163 #endif
    164 
    165     m_rootLayerCanvasSize = size;
    166 }
    167 
    168141void LayerRendererChromium::useShader(unsigned programId)
    169142{
    … …  
    174147}
    175148
    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)
     149IntRect 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
     155IntRect 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
     161void 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
     181void 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
     215void LayerRendererChromium::drawLayers(const IntRect& visibleRect, const IntRect& contentRect,
     216                                       const IntPoint& scrollPosition, TilePaintInterface& tilePaint,
     217                                       TilePaintInterface& scrollbarPaint)
    182218{
    183219    ASSERT(m_hardwareCompositing);
    … …  
    187223
    188224    makeContextCurrent();
    189 
    190     GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_rootLayerTextureId));
    191 
    192     bool skipScroll = false;
    193225
    194226    // If the size of the visible area has changed then allocate a new texture
    … …  
    200232        m_rootLayerTextureWidth = visibleRectWidth;
    201233        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));
    203234
    204235        // Reset the current render surface to force an update of the viewport and
    205236        // projection matrix next time useRenderSurface is called.
    206237        m_currentRenderSurface = 0;
    207 
    208         // The root layer texture was just resized so its contents are not
    209         // useful for scrolling.
    210         skipScroll = true;
    211238    }
    212239
    … …  
    224251    GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND));
    225252
    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 is
    234     // 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 backbuffer
    239     if (!skipScroll && (scrollDelta.x() || scrollDelta.y())) {
    240         // Scrolling works as follows: We render a quad with the current root layer contents
    241         // translated by the amount the page has scrolled since the last update and then read the
    242         // pixels of the content area (visible area excluding the scroll bars) back into the
    243         // root layer texture. The newly exposed area will be filled by a subsequent drawLayersIntoRect call
    244         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 
    260253    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 #else
    286 #error "Need to implement for your platform."
    287 #endif
    288     // 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);
    295254
    296255    m_defaultRenderSurface = m_rootLayer->m_renderSurface.get();
    … …  
    305264    m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
    306265
    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);
    323267
    324268    // Set the root visible/content rects --- used by subsequent drawLayers calls.
    … …  
    388332    // consider exposing a different entry point on GraphicsContext3D.
    389333    m_context->prepareTexture();
     334}
     335
     336void 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();
    390344}
    391345
    … …  
    783737    makeContextCurrent();
    784738
    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 repeated
    793     // 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 
    798739    // Get the max texture size supported by the system.
    799740    m_maxTextureSize = 0;
    … …  
    830771    m_pluginLayerSharedValues.clear();
    831772    m_renderSurfaceSharedValues.clear();
    832 
    833     if (m_rootLayerTextureId) {
    834         deleteLayerTexture(m_rootLayerTextureId);
    835         m_rootLayerTextureId = 0;
    836     }
    837 
    838773    if (m_offscreenFramebufferId)
    839774        GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId));
  • trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.h

    r74358 r74568  
    3939#include "IntRect.h"
    4040#include "LayerChromium.h"
     41#include "LayerTilerChromium.h"
    4142#include "PluginLayerChromium.h"
    4243#include "RenderSurfaceChromium.h"
    … …  
    6869    GraphicsContext3D* context();
    6970
    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);
    7877
    7978    // waits for rendering to finish
    … …  
    8382    void present();
    8483
    85     void setRootLayer(PassRefPtr<LayerChromium> layer) { m_rootLayer = layer; }
     84    void setRootLayer(PassRefPtr<LayerChromium> layer);
    8685    LayerChromium* rootLayer() { return m_rootLayer.get(); }
    8786    void transferRootLayer(LayerRendererChromium* other) { other->m_rootLayer = m_rootLayer.release(); }
    … …  
    127126    void drawLayer(LayerChromium*, RenderSurfaceChromium*);
    128127
     128    void updateAndDrawRootLayer(TilePaintInterface& tilePaint, TilePaintInterface& scrollbarPaint, const IntRect& visibleRect, const IntRect& contentRect);
     129
    129130    bool isLayerVisible(LayerChromium*, const TransformationMatrix&, const IntRect& visibleRect);
    130131
    … …  
    140141    void cleanupSharedObjects();
    141142
    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
    143146    int m_rootLayerTextureWidth;
    144147    int m_rootLayerTextureHeight;
    … …  
    147150
    148151    RefPtr<LayerChromium> m_rootLayer;
     152    OwnPtr<LayerTilerChromium> m_rootLayerTiler;
     153    OwnPtr<LayerTilerChromium> m_horizontalScrollbarTiler;
     154    OwnPtr<LayerTilerChromium> m_verticalScrollbarTiler;
    149155
    150156    IntPoint m_scrollPosition;
  • trunk/WebKit/chromium/ChangeLog

    r74566 r74568  
     12010-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
    1232010-12-22  Ryosuke Niwa  <rniwa@webkit.org>
    224
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r73940 r74568  
    22692269void WebViewImpl::scrollRootLayerRect(const IntSize& scrollDelta, const IntRect& clipRect)
    22702270{
     2271    setRootLayerNeedsDisplay();
     2272}
     2273
     2274void WebViewImpl::invalidateRootLayerRect(const IntRect& rect)
     2275{
    22712276    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();
    22802282    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);
    23482287    setRootLayerNeedsDisplay();
    23492288}
    … …  
    23622301            m_layerRenderer->finish(); // finish all GL rendering before we hide the window?
    23632302        m_client->didActivateAcceleratedCompositing(false);
    2364         return;
    2365     }
    2366 
    2367     if (m_layerRenderer) {
     2303    } else if (m_layerRenderer) {
    23682304        m_isAcceleratedCompositingActive = true;
    23692305        m_layerRenderer->resizeOnscreenContent(WebCore::IntSize(std::max(1, m_size.width),
    … …  
    23712307
    23722308        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;
    23872309    } 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
     2331class WebViewImplTilePaintInterface : public TilePaintInterface {
     2332public:
     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
     2347private:
     2348    WebViewImpl* m_webViewImpl;
     2349};
     2350
     2351
     2352class WebViewImplScrollbarPaintInterface : public TilePaintInterface {
     2353public:
     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
     2371private:
     2372    WebViewImpl* m_webViewImpl;
     2373};
    24472374
    24482375void WebViewImpl::doComposite()
    … …  
    24562383    IntRect visibleRect = view->visibleContentRect(true);
    24572384    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);
    24842391}
    24852392
  • trunk/WebKit/chromium/src/WebViewImpl.h

    r73940 r74568  
    397397#if USE(ACCELERATED_COMPOSITING)
    398398    void setIsAcceleratedCompositingActive(bool);
    399     void updateRootLayerContents(const WebCore::IntRect&);
    400399    void doComposite();
    401400    void doPixelReadbackToCanvas(WebCanvas*, const WebCore::IntRect&);
    … …  
    529528
    530529#if USE(ACCELERATED_COMPOSITING)
    531     WebCore::IntRect m_rootLayerDirtyRect;
    532530    WebCore::IntRect m_rootLayerScrollDamage;
    533531    RefPtr<WebCore::LayerRendererChromium> m_layerRenderer;
Note: See TracChangeset for help on using the changeset viewer.