Changeset 120135 in webkit


Ignore:
Timestamp:
Jun 12, 2012 4:04:17 PM (12 years ago)
Author:
enne@google.com
Message:

[chromium] Paint scrollbars on WebKit thread and composite those textures
https://bugs.webkit.org/show_bug.cgi?id=88145

Reviewed by James Robinson.

Source/WebCore:

Scrollbars were previously painted and uploaded on the compositor
thread. This isn't possible to do for many scrollbar themes. This
patch changes ScrollbarLayerChromium to paint the scrollbar into two
parts: the thumb, and everything else. These are uploaded into
textures and synced over to the CCScrollbarImpl where they are
composited and drawn.

Mac and overlay scrollbars are still not enabled to have compositor
thread-updated scrollbars.

As a bonus, fix LayerRendererChromium::drawTextureQuad to draw quads
that do not fill the entire layer bounds.

Tested by existing layout and unit tests by removing the condition
that these scrollbar layers are only created when the threaded proxy
exists.

  • page/scrolling/chromium/ScrollingCoordinatorChromium.cpp:

(WebCore::scrollbarLayerDidChange):

  • platform/ScrollbarThemeComposite.cpp:

(WebCore::ScrollbarThemeComposite::thumbRect):
(WebCore):

  • platform/ScrollbarThemeComposite.h:

(ScrollbarThemeComposite):

  • platform/graphics/chromium/LayerRendererChromium.cpp:

(WebCore::LayerRendererChromium::drawTextureQuad):

  • platform/graphics/chromium/ScrollbarLayerChromium.cpp:

(WebCore::ScrollbarLayerChromium::ScrollbarLayerChromium):
(WebCore::ScrollbarLayerChromium::theme):
(WebCore):
(WebCore::ScrollbarLayerChromium::pushPropertiesTo):
(ScrollbarBackgroundPainter):
(WebCore::ScrollbarBackgroundPainter::create):
(WebCore::ScrollbarBackgroundPainter::paint):
(WebCore::ScrollbarBackgroundPainter::ScrollbarBackgroundPainter):
(ScrollbarThumbPainter):
(WebCore::ScrollbarThumbPainter::create):
(WebCore::ScrollbarThumbPainter::paint):
(WebCore::ScrollbarThumbPainter::ScrollbarThumbPainter):
(WebCore::ScrollbarLayerChromium::setLayerTreeHost):
(WebCore::ScrollbarLayerChromium::createTextureUpdaterIfNeeded):
(WebCore::ScrollbarLayerChromium::updatePart):
(WebCore::ScrollbarLayerChromium::update):

  • platform/graphics/chromium/ScrollbarLayerChromium.h:

(WebCore):
(ScrollbarLayerChromium):

  • platform/graphics/chromium/cc/CCScrollbarLayerImpl.cpp:

(WebCore::CCScrollbarLayerImpl::CCScrollbarLayerImpl):
(WebCore::CCScrollbarLayerImpl::appendQuads):

  • platform/graphics/chromium/cc/CCScrollbarLayerImpl.h:

(WebCore::CCScrollbarLayerImpl::setBackgroundTextureId):
(WebCore::CCScrollbarLayerImpl::setThumbTextureId):
(CCScrollbarLayerImpl):

Source/WebKit/chromium:

Remove scrollbarLayerLostContext test that no longer makes sense. The
compositor won't draw at all after a lost context if it has no
contents.

  • tests/CCLayerTreeHostImplTest.cpp:
Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r120132 r120135  
     12012-06-12  Adrienne Walker  <enne@google.com>
     2
     3        [chromium] Paint scrollbars on WebKit thread and composite those textures
     4        https://bugs.webkit.org/show_bug.cgi?id=88145
     5
     6        Reviewed by James Robinson.
     7
     8        Scrollbars were previously painted and uploaded on the compositor
     9        thread. This isn't possible to do for many scrollbar themes. This
     10        patch changes ScrollbarLayerChromium to paint the scrollbar into two
     11        parts: the thumb, and everything else. These are uploaded into
     12        textures and synced over to the CCScrollbarImpl where they are
     13        composited and drawn.
     14
     15        Mac and overlay scrollbars are still not enabled to have compositor
     16        thread-updated scrollbars.
     17
     18        As a bonus, fix LayerRendererChromium::drawTextureQuad to draw quads
     19        that do not fill the entire layer bounds.
     20
     21        Tested by existing layout and unit tests by removing the condition
     22        that these scrollbar layers are only created when the threaded proxy
     23        exists.
     24
     25        * page/scrolling/chromium/ScrollingCoordinatorChromium.cpp:
     26        (WebCore::scrollbarLayerDidChange):
     27        * platform/ScrollbarThemeComposite.cpp:
     28        (WebCore::ScrollbarThemeComposite::thumbRect):
     29        (WebCore):
     30        * platform/ScrollbarThemeComposite.h:
     31        (ScrollbarThemeComposite):
     32        * platform/graphics/chromium/LayerRendererChromium.cpp:
     33        (WebCore::LayerRendererChromium::drawTextureQuad):
     34        * platform/graphics/chromium/ScrollbarLayerChromium.cpp:
     35        (WebCore::ScrollbarLayerChromium::ScrollbarLayerChromium):
     36        (WebCore::ScrollbarLayerChromium::theme):
     37        (WebCore):
     38        (WebCore::ScrollbarLayerChromium::pushPropertiesTo):
     39        (ScrollbarBackgroundPainter):
     40        (WebCore::ScrollbarBackgroundPainter::create):
     41        (WebCore::ScrollbarBackgroundPainter::paint):
     42        (WebCore::ScrollbarBackgroundPainter::ScrollbarBackgroundPainter):
     43        (ScrollbarThumbPainter):
     44        (WebCore::ScrollbarThumbPainter::create):
     45        (WebCore::ScrollbarThumbPainter::paint):
     46        (WebCore::ScrollbarThumbPainter::ScrollbarThumbPainter):
     47        (WebCore::ScrollbarLayerChromium::setLayerTreeHost):
     48        (WebCore::ScrollbarLayerChromium::createTextureUpdaterIfNeeded):
     49        (WebCore::ScrollbarLayerChromium::updatePart):
     50        (WebCore::ScrollbarLayerChromium::update):
     51        * platform/graphics/chromium/ScrollbarLayerChromium.h:
     52        (WebCore):
     53        (ScrollbarLayerChromium):
     54        * platform/graphics/chromium/cc/CCScrollbarLayerImpl.cpp:
     55        (WebCore::CCScrollbarLayerImpl::CCScrollbarLayerImpl):
     56        (WebCore::CCScrollbarLayerImpl::appendQuads):
     57        * platform/graphics/chromium/cc/CCScrollbarLayerImpl.h:
     58        (WebCore::CCScrollbarLayerImpl::setBackgroundTextureId):
     59        (WebCore::CCScrollbarLayerImpl::setThumbTextureId):
     60        (CCScrollbarLayerImpl):
     61
    1622012-06-12  Tony Chang  <tony@chromium.org>
    263
  • trunk/Source/WebCore/page/scrolling/chromium/ScrollingCoordinatorChromium.cpp

    r120125 r120135  
    121121        scrollbarGraphicsLayer->setContentsOpaque(isOpaqueRootScrollbar);
    122122
    123     // Only certain platforms support the way that scrollbars are currently
    124     // being painted on the impl thread. For example, Cocoa is not threadsafe.
    125     bool platformSupported = false;
    126 #if OS(LINUX)
    127     platformSupported = true;
     123    // FIXME: Mac scrollbar themes are not thread-safe.
     124    bool platformSupported = true;
     125#if OS(DARWIN)
     126    platformSupported = false;
    128127#endif
    129128
    130     if (scrollbar->isCustomScrollbar() || !CCProxy::hasImplThread() || !platformSupported) {
     129    if (!platformSupported || scrollbar->isOverlayScrollbar()) {
    131130        scrollbarGraphicsLayer->setContentsToMedia(0);
    132131        scrollbarGraphicsLayer->setDrawsContent(true);
  • trunk/Source/WebCore/platform/ScrollbarThemeComposite.cpp

    r119617 r120135  
    272272}
    273273
     274IntRect ScrollbarThemeComposite::thumbRect(ScrollbarThemeClient* scrollbar)
     275{
     276    if (!hasThumb(scrollbar))
     277        return IntRect();
     278
     279    IntRect track = trackRect(scrollbar);
     280    IntRect startTrackRect;
     281    IntRect thumbRect;
     282    IntRect endTrackRect;
     283    splitTrack(scrollbar, track, startTrackRect, thumbRect, endTrackRect);
     284
     285    return thumbRect;
     286}
     287
    274288void ScrollbarThemeComposite::paintOverhangAreas(ScrollView*, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
    275289{   
  • trunk/Source/WebCore/platform/ScrollbarThemeComposite.h

    r109451 r120135  
    3333class ScrollbarThemeComposite : public ScrollbarTheme {
    3434public:
     35    // Implement ScrollbarTheme interface
    3536    virtual bool paint(ScrollbarThemeClient*, GraphicsContext*, const IntRect& damageRect);
    36 
    3737    virtual ScrollbarPart hitTest(ScrollbarThemeClient*, const PlatformMouseEvent&);
    38 
    3938    virtual void invalidatePart(ScrollbarThemeClient*, ScrollbarPart);
    40 
    4139    virtual int thumbPosition(ScrollbarThemeClient*);
    4240    virtual int thumbLength(ScrollbarThemeClient*);
    4341    virtual int trackPosition(ScrollbarThemeClient*);
    4442    virtual int trackLength(ScrollbarThemeClient*);
    45 
    4643    virtual void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect& cornerRect);
    4744    virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
    4845
    49 protected:
    5046    virtual bool hasButtons(ScrollbarThemeClient*) = 0;
    5147    virtual bool hasThumb(ScrollbarThemeClient*) = 0;
     
    5450    virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) = 0;
    5551    virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false) = 0;
     52    virtual IntRect thumbRect(ScrollbarThemeClient*);
    5653
    5754    virtual void splitTrack(ScrollbarThemeClient*, const IntRect& track, IntRect& startTrack, IntRect& thumb, IntRect& endTrack);
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r120073 r120135  
    11311131        GLC(context(), context()->blendFunc(GraphicsContext3D::SRC_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
    11321132
    1133     const IntSize& bounds = quad->quadRect().size();
    1134 
    1135     drawTexturedQuad(quad->layerTransform(), bounds.width(), bounds.height(), quad->opacity(), sharedGeometryQuad(), binding.matrixLocation, binding.alphaLocation, -1);
     1133    WebTransformationMatrix quadTransform = quad->quadTransform();
     1134    IntRect quadRect = quad->quadRect();
     1135    quadTransform.translate(quadRect.x() + quadRect.width() / 2.0, quadRect.y() + quadRect.height() / 2.0);
     1136
     1137    drawTexturedQuad(quadTransform, quadRect.width(), quadRect.height(), quad->opacity(), sharedGeometryQuad(), binding.matrixLocation, binding.alphaLocation, -1);
    11361138
    11371139    if (!quad->premultipliedAlpha())
  • trunk/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp

    r110338 r120135  
    2929#include "ScrollbarLayerChromium.h"
    3030
     31#include "BitmapCanvasLayerTextureUpdater.h"
     32#include "LayerPainterChromium.h"
    3133#include "Scrollbar.h"
     34#include "ScrollbarThemeComposite.h"
     35#include "cc/CCLayerTreeHost.h"
    3236#include "cc/CCScrollbarLayerImpl.h"
     37#include "cc/CCTextureUpdater.h"
    3338
    3439namespace WebCore {
     
    4752    : m_scrollbar(scrollbar)
    4853    , m_scrollLayerId(scrollLayerId)
     54    , m_textureFormat(GraphicsContext3D::INVALID_ENUM)
    4955    , m_scrollbarOverlayStyle(scrollbar->scrollbarOverlayStyle())
    5056    , m_isScrollableAreaActive(scrollbar->isScrollableAreaActive())
     
    5561}
    5662
     63ScrollbarThemeComposite* ScrollbarLayerChromium::theme() const
     64{
     65    // All Chromium scrollbars are ScrollbarThemeComposite-derived.
     66    return static_cast<ScrollbarThemeComposite*>(m_scrollbar->theme());
     67}
     68
    5769void ScrollbarLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
    5870{
     
    6274
    6375    scrollbarLayer->setScrollbarOverlayStyle(m_scrollbarOverlayStyle);
     76
     77    if (m_background && m_background->texture()->isReserved())
     78        scrollbarLayer->setBackgroundTextureId(m_background->texture()->textureId());
     79    else
     80        scrollbarLayer->setBackgroundTextureId(0);
     81
     82    if (m_thumb && m_thumb->texture()->isReserved())
     83        scrollbarLayer->setThumbTextureId(m_thumb->texture()->textureId());
     84    else
     85        scrollbarLayer->setThumbTextureId(0);
    6486
    6587    Vector<IntRect> tickmarks;
     
    80102}
    81103
     104class ScrollbarBackgroundPainter : public LayerPainterChromium {
     105    WTF_MAKE_NONCOPYABLE(ScrollbarBackgroundPainter);
     106public:
     107    static PassOwnPtr<ScrollbarBackgroundPainter> create(ScrollbarThemeClient* scrollbar, ScrollbarThemeComposite* theme)
     108    {
     109        return adoptPtr(new ScrollbarBackgroundPainter(scrollbar, theme));
     110    }
     111
     112    virtual void paint(GraphicsContext& context, const IntRect& contentRect)
     113    {
     114        // The following is a simplification of ScrollbarThemeComposite::paint.
     115        m_theme->paintScrollbarBackground(&context, m_scrollbar);
     116
     117        if (m_theme->hasButtons(m_scrollbar)) {
     118            IntRect backButtonStartPaintRect = m_theme->backButtonRect(m_scrollbar, BackButtonStartPart, true);
     119            m_theme->paintButton(&context, m_scrollbar, backButtonStartPaintRect, BackButtonStartPart);
     120
     121            IntRect backButtonEndPaintRect = m_theme->backButtonRect(m_scrollbar, BackButtonEndPart, true);
     122            m_theme->paintButton(&context, m_scrollbar, backButtonEndPaintRect, BackButtonEndPart);
     123
     124            IntRect forwardButtonStartPaintRect = m_theme->forwardButtonRect(m_scrollbar, ForwardButtonStartPart, true);
     125            m_theme->paintButton(&context, m_scrollbar, forwardButtonStartPaintRect, ForwardButtonStartPart);
     126
     127            IntRect forwardButtonEndPaintRect = m_theme->forwardButtonRect(m_scrollbar, ForwardButtonEndPart, true);
     128            m_theme->paintButton(&context, m_scrollbar, forwardButtonEndPaintRect, ForwardButtonEndPart);
     129        }
     130
     131        IntRect trackPaintRect = m_theme->trackRect(m_scrollbar, true);
     132        m_theme->paintTrackBackground(&context, m_scrollbar, trackPaintRect);
     133
     134        bool thumbPresent = m_theme->hasThumb(m_scrollbar);
     135        if (thumbPresent) {
     136            // FIXME: There's no "paint the whole track" part. Drawing both the
     137            // BackTrackPart and the ForwardTrackPart in their splitTrack rects
     138            // ends up leaving a distinctive line. Painting one part as the
     139            // entire track appears to be identical to painting both and
     140            // covering up the split between them with the thumb.
     141            m_theme->paintTrackPiece(&context, m_scrollbar, trackPaintRect, BackTrackPart);
     142        }
     143
     144        m_theme->paintTickmarks(&context, m_scrollbar, trackPaintRect);
     145    }
     146private:
     147    ScrollbarBackgroundPainter(ScrollbarThemeClient* scrollbar, ScrollbarThemeComposite* theme)
     148        : m_scrollbar(scrollbar)
     149        , m_theme(theme)
     150    {
     151    }
     152
     153    ScrollbarThemeClient* m_scrollbar;
     154    ScrollbarThemeComposite* m_theme;
     155};
     156
     157class ScrollbarThumbPainter : public LayerPainterChromium {
     158    WTF_MAKE_NONCOPYABLE(ScrollbarThumbPainter);
     159public:
     160    static PassOwnPtr<ScrollbarThumbPainter> create(ScrollbarThemeClient* scrollbar, ScrollbarThemeComposite* theme)
     161    {
     162        return adoptPtr(new ScrollbarThumbPainter(scrollbar, theme));
     163    }
     164
     165    virtual void paint(GraphicsContext& context, const IntRect& contentRect)
     166    {
     167        context.clearRect(contentRect);
     168
     169        // Consider the thumb to be at the origin when painting.
     170        IntRect thumbRect = IntRect(IntPoint(), m_theme->thumbRect(m_scrollbar).size());
     171        m_theme->paintThumb(&context, m_scrollbar, thumbRect);
     172    }
     173
     174private:
     175    ScrollbarThumbPainter(ScrollbarThemeClient* scrollbar, ScrollbarThemeComposite* theme)
     176        : m_scrollbar(scrollbar)
     177        , m_theme(theme)
     178    {
     179    }
     180
     181    ScrollbarThemeClient* m_scrollbar;
     182    ScrollbarThemeComposite* m_theme;
     183};
     184
     185void ScrollbarLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
     186{
     187    if (!host || host != layerTreeHost()) {
     188        m_backgroundUpdater.clear();
     189        m_background.clear();
     190        m_thumbUpdater.clear();
     191        m_thumb.clear();
     192    }
     193
     194    LayerChromium::setLayerTreeHost(host);
     195}
     196
     197void ScrollbarLayerChromium::createTextureUpdaterIfNeeded()
     198{
     199    bool useMapSubImage = layerTreeHost()->layerRendererCapabilities().usingMapSub;
     200    m_textureFormat = layerTreeHost()->layerRendererCapabilities().bestTextureFormat;
     201
     202    if (!m_backgroundUpdater)
     203        m_backgroundUpdater = BitmapCanvasLayerTextureUpdater::create(ScrollbarBackgroundPainter::create(m_scrollbar.get(), theme()), useMapSubImage);
     204    if (!m_background)
     205        m_background = m_backgroundUpdater->createTexture(layerTreeHost()->contentsTextureManager());
     206
     207    if (!m_thumbUpdater)
     208        m_thumbUpdater = BitmapCanvasLayerTextureUpdater::create(ScrollbarThumbPainter::create(m_scrollbar.get(), theme()), useMapSubImage);
     209    if (!m_thumb)
     210        m_thumb = m_thumbUpdater->createTexture(layerTreeHost()->contentsTextureManager());
     211}
     212
     213void ScrollbarLayerChromium::updatePart(LayerTextureUpdater* painter, LayerTextureUpdater::Texture* texture, const IntRect& rect, CCTextureUpdater& updater)
     214{
     215    bool textureValid = texture->texture()->isValid(rect.size(), m_textureFormat);
     216    // Skip painting and uploading if there are no invalidations.
     217    if (textureValid && m_updateRect.isEmpty()) {
     218        texture->texture()->reserve(rect.size(), m_textureFormat);
     219        return;
     220    }
     221
     222    // ScrollbarLayerChromium doesn't support partial uploads, so any
     223    // invalidation is treated a full layer invalidation.
     224    if (layerTreeHost()->bufferedUpdates() && textureValid)
     225        layerTreeHost()->deleteTextureAfterCommit(texture->texture()->steal());
     226
     227    if (!texture->texture()->reserve(rect.size(), m_textureFormat))
     228        return;
     229
     230    // Paint and upload the entire part.
     231    IntRect paintedOpaqueRect;
     232    painter->prepareToUpdate(rect, rect.size(), false, 1, paintedOpaqueRect);
     233    texture->prepareRect(rect);
     234
     235    IntRect destRect(IntPoint(), rect.size());
     236    updater.appendUpdate(texture, rect, destRect);
     237}
     238
     239void ScrollbarLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
     240{
     241    if (contentBounds().isEmpty())
     242        return;
     243
     244    createTextureUpdaterIfNeeded();
     245
     246    IntPoint scrollbarOrigin(m_scrollbar->x(), m_scrollbar->y());
     247    IntRect contentRect(scrollbarOrigin, contentBounds());
     248    updatePart(m_backgroundUpdater.get(), m_background.get(), contentRect, updater);
     249
     250    // Consider the thumb to be at the origin when painting.
     251    IntRect thumbRect = IntRect(IntPoint(), theme()->thumbRect(m_scrollbar.get()).size());
     252    if (!thumbRect.isEmpty())
     253        updatePart(m_thumbUpdater.get(), m_thumb.get(), thumbRect, updater);
     254}
     255
    82256}
    83257#endif // USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.h

    r120125 r120135  
    3030
    3131#include "LayerChromium.h"
     32#include "LayerTextureUpdater.h"
    3233#include "ScrollTypes.h"
    3334
     
    3536
    3637class Scrollbar;
     38class ScrollbarThemeComposite;
     39class CCTextureUpdater;
    3740
    3841class ScrollbarLayerChromium : public LayerChromium {
     
    4144    static PassRefPtr<ScrollbarLayerChromium> create(Scrollbar*, int scrollLayerId);
    4245
    43     virtual void pushPropertiesTo(CCLayerImpl*);
     46    // LayerChromium interface
     47    virtual void update(CCTextureUpdater&, const CCOcclusionTracker*) OVERRIDE;
     48    virtual void setLayerTreeHost(CCLayerTreeHost*) OVERRIDE;
     49    virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE;
    4450
    4551    int scrollLayerId() const { return m_scrollLayerId; }
     
    5258
    5359private:
     60    ScrollbarThemeComposite* theme() const;
     61    void updatePart(LayerTextureUpdater*, LayerTextureUpdater::Texture*, const IntRect&, CCTextureUpdater&);
     62    void createTextureUpdaterIfNeeded();
     63
    5464    RefPtr<Scrollbar> m_scrollbar;
    5565    int m_scrollLayerId;
     66
     67    GC3Denum m_textureFormat;
     68
     69    RefPtr<LayerTextureUpdater> m_backgroundUpdater;
     70    RefPtr<LayerTextureUpdater> m_thumbUpdater;
     71
     72    // All the parts of the scrollbar except the thumb
     73    OwnPtr<LayerTextureUpdater::Texture> m_background;
     74    OwnPtr<LayerTextureUpdater::Texture> m_thumb;
    5675
    5776    ScrollbarOverlayStyle m_scrollbarOverlayStyle;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCScrollbarLayerImpl.cpp

    r119419 r120135  
    3030#include "CCScrollbarLayerImpl.h"
    3131
    32 #include "CCTileDrawQuad.h"
    3332#include "LayerRendererChromium.h"
    3433#include "ManagedTexture.h"
    3534#include "PlatformCanvas.h"
    3635#include "ScrollbarTheme.h"
     36#include "ScrollbarThemeComposite.h"
    3737#include "cc/CCQuadCuller.h"
     38#include "cc/CCTextureDrawQuad.h"
    3839
    3940namespace WebCore {
     
    4849    , m_scrollLayer(0)
    4950    , m_scrollbar(this)
    50 {
    51 }
    52 
    53 void CCScrollbarLayerImpl::willDraw(CCRenderer* layerRenderer, CCGraphicsContext* context)
    54 {
    55     CCLayerImpl::willDraw(layerRenderer, context);
    56 
    57     if (bounds().isEmpty() || contentBounds().isEmpty())
     51    , m_backgroundTextureId(0)
     52    , m_thumbTextureId(0)
     53{
     54}
     55
     56void CCScrollbarLayerImpl::appendQuads(CCQuadCuller& quadList, const CCSharedQuadState* sharedQuadState, bool&)
     57{
     58    ScrollbarThemeComposite* theme = static_cast<ScrollbarThemeComposite*>(ScrollbarTheme::theme());
     59    if (!theme)
    5860        return;
    5961
    60     if (!m_texture)
    61         m_texture = ManagedTexture::create(layerRenderer->implTextureManager());
    62 
    63     // The context could have been lost since the last frame and the old texture
    64     // manager may no longer be valid.
    65     m_texture->setTextureManager(layerRenderer->implTextureManager());
    66 
    67     IntSize textureSize = contentBounds();
    68     if (!m_texture->reserve(textureSize, GraphicsContext3D::RGBA))
     62    bool premultipledAlpha = false;
     63    FloatRect uvRect(0, 0, 1, 1);
     64    bool flipped = false;
     65
     66    IntRect thumbRect = theme->thumbRect(&m_scrollbar);
     67    thumbRect.move(-m_scrollbar.x(), -m_scrollbar.y());
     68    if (m_thumbTextureId && theme->hasThumb(&m_scrollbar) && !thumbRect.isEmpty())
     69        quadList.append(CCTextureDrawQuad::create(sharedQuadState, thumbRect, m_thumbTextureId, premultipledAlpha, uvRect, flipped));
     70    if (!m_backgroundTextureId)
    6971        return;
    7072
    71     PlatformCanvas canvas;
    72     canvas.resize(textureSize);
    73     {
    74         PlatformCanvas::Painter painter(&canvas, PlatformCanvas::Painter::GrayscaleText);
    75         paint(painter.context());
    76     }
    77 
    78     {
    79         PlatformCanvas::AutoLocker locker(&canvas);
    80         m_texture->bindTexture(context, layerRenderer->implTextureAllocator());
    81 
    82         // FIXME: Skia uses BGRA actually, we correct that with the swizzle pixel shader.
    83         GraphicsContext3D* context3d = context->context3D();
    84         if (!context3d) {
    85             // FIXME: Implement this path for software compositing.
    86             return;
    87         }
    88 
    89         GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, m_texture->format(), canvas.size().width(), canvas.size().height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, locker.pixels()));
    90     }
    91 }
    92 
    93 void CCScrollbarLayerImpl::appendQuads(CCQuadCuller& quadList, const CCSharedQuadState* sharedQuadState, bool&)
    94 {
    95     if (!m_texture->isReserved())
    96         return;
    97 
    98     IntRect quadRect(IntPoint(), bounds());
    99     quadList.append(CCTileDrawQuad::create(sharedQuadState, quadRect, quadRect, m_texture->textureId(), IntPoint(), m_texture->size(), GraphicsContext3D::NEAREST, true, true, true, true, true));
    100 }
    101 
    102 void CCScrollbarLayerImpl::didDraw()
    103 {
    104     CCLayerImpl::didDraw();
    105 
    106     m_texture->unreserve();
    107 }
    108 
    109 void CCScrollbarLayerImpl::paint(GraphicsContext* context)
    110 {
    111     ScrollbarTheme* theme = ScrollbarTheme::theme(); // FIXME: should make impl-side clone if needed
    112 
    113     context->clearRect(IntRect(IntPoint(), contentBounds()));
    114     theme->paint(&m_scrollbar, context, IntRect(IntPoint(), contentBounds()));
    115 }
    116 
     73    IntRect backgroundRect(IntPoint(), contentBounds());
     74    quadList.append(CCTextureDrawQuad::create(sharedQuadState, backgroundRect, m_backgroundTextureId, premultipledAlpha, uvRect, flipped));
     75}
    11776
    11877int CCScrollbarLayerImpl::CCScrollbar::x() const
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCScrollbarLayerImpl.h

    r119313 r120135  
    5656    void setEnabled(bool enabled) { m_enabled = enabled; }
    5757
     58    void setBackgroundTextureId(unsigned id) { m_backgroundTextureId = id; }
     59    void setThumbTextureId(unsigned id) { m_thumbTextureId = id; }
    5860
    5961    CCLayerImpl* scrollLayer() const { return m_scrollLayer; }
    6062    void setScrollLayer(CCLayerImpl* scrollLayer) { m_scrollLayer = scrollLayer; }
    6163
    62     virtual void willDraw(CCRenderer*, CCGraphicsContext*) OVERRIDE;
    6364    virtual void appendQuads(CCQuadCuller&, const CCSharedQuadState*, bool& hadMissingTiles) OVERRIDE;
    64     virtual void didDraw() OVERRIDE;
    6565
    6666protected:
    6767    explicit CCScrollbarLayerImpl(int id);
    6868
    69     virtual void paint(GraphicsContext*);
    70 
    7169private:
    7270    CCLayerImpl* m_scrollLayer;
    73     OwnPtr<ManagedTexture> m_texture;
    7471
    7572    // nested class only to avoid namespace problem
     
    129126    CCScrollbar m_scrollbar;
    130127
     128    unsigned m_backgroundTextureId;
     129    unsigned m_thumbTextureId;
     130
    131131    ScrollbarOverlayStyle m_scrollbarOverlayStyle;
    132132    Vector<IntRect> m_tickmarks;
  • trunk/Source/WebKit/chromium/ChangeLog

    r120131 r120135  
     12012-06-12  Adrienne Walker  <enne@google.com>
     2
     3        [chromium] Paint scrollbars on WebKit thread and composite those textures
     4        https://bugs.webkit.org/show_bug.cgi?id=88145
     5
     6        Reviewed by James Robinson.
     7
     8        Remove scrollbarLayerLostContext test that no longer makes sense. The
     9        compositor won't draw at all after a lost context if it has no
     10        contents.
     11
     12        * tests/CCLayerTreeHostImplTest.cpp:
     13
    1142012-06-12  Joshua Bell  <jsbell@chromium.org>
    215
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp

    r120127 r120135  
    15851585};
    15861586
    1587 TEST_F(CCLayerTreeHostImplTest, scrollbarLayerLostContext)
    1588 {
    1589     m_hostImpl->setRootLayer(ScrollbarLayerFakePaint::create(0));
    1590     ScrollbarLayerFakePaint* scrollbar = static_cast<ScrollbarLayerFakePaint*>(m_hostImpl->rootLayer());
    1591     scrollbar->setBounds(IntSize(1, 1));
    1592     scrollbar->setContentBounds(IntSize(1, 1));
    1593     scrollbar->setDrawsContent(true);
    1594 
    1595     for (int i = 0; i < 2; ++i) {
    1596         CCLayerTreeHostImpl::FrameData frame;
    1597         EXPECT_TRUE(m_hostImpl->prepareToDraw(frame));
    1598         ASSERT(frame.renderPasses.size() == 1);
    1599         CCRenderPass* renderPass = frame.renderPasses[0].get();
    1600         // Scrollbar layer should always generate quads, even after lost context
    1601         EXPECT_GT(renderPass->quadList().size(), 0u);
    1602         m_hostImpl->didDrawAllLayers(frame);
    1603         m_hostImpl->initializeLayerRenderer(createContext(), UnthrottledUploader);
    1604     }
    1605 }
    1606 
    16071587// Fake WebGraphicsContext3D that will cause a failure if trying to use a
    16081588// resource that wasn't created by it (resources created by
Note: See TracChangeset for help on using the changeset viewer.