Changeset 151262 in webkit


Ignore:
Timestamp:
Jun 6, 2013 2:43:20 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
https://bugs.webkit.org/show_bug.cgi?id=108899

Patch by Jae Hyun Park <jae.park@company100.net> on 2013-06-06
Reviewed by Noam Rosenthal.

This is a preparation patch for Threaded Coordinated Graphics.

This patch changes CoordinatedSurface to be responsible for the
lifecycle of GraphicsContext used in Coordinated Graphics System.
CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
of GraphicsContext anymore. Instead, those classes use client pattern to
ask the CoordiantedSurface to paint to the GraphicsContext.

This refactoring is needed to implement CoordinatedSurface for Threaded
Coordinated Graphics.

Source/WebCore:

No new tests, covered by existing tests.

  • platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:

(WebCore::CoordinatedGraphicsLayer::paintToSurface):

  • platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
  • platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:

(WebCore::ImageBackingSurfaceClient::ImageBackingSurfaceClient):
(WebCore::CoordinatedImageBacking::update):

  • platform/graphics/texmap/coordinated/CoordinatedSurface.h:

(WebCore::CoordinatedSurface::Client::~Client):

  • platform/graphics/texmap/coordinated/CoordinatedTile.cpp:

(WebCore::CoordinatedTile::updateBackBuffer):
(WebCore::CoordinatedTile::paintToSurfaceContext):

  • platform/graphics/texmap/coordinated/CoordinatedTile.h:
  • platform/graphics/texmap/coordinated/UpdateAtlas.cpp:

(WebCore::UpdateAtlasSurfaceClient::UpdateAtlasSurfaceClient):
(WebCore::UpdateAtlas::paintOnAvailableBuffer):

  • platform/graphics/texmap/coordinated/UpdateAtlas.h:

Source/WebKit2:

  • Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp:

(WebKit::WebCoordinatedSurface::paintToSurface):

  • Shared/CoordinatedGraphics/WebCoordinatedSurface.h:
  • WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:

(WebKit::CoordinatedLayerTreeHost::paintToSurface):

  • WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r151259 r151262  
     12013-06-06  Jae Hyun Park  <jae.park@company100.net>
     2
     3        Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
     4        https://bugs.webkit.org/show_bug.cgi?id=108899
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        This is a preparation patch for Threaded Coordinated Graphics.
     9
     10        This patch changes CoordinatedSurface to be responsible for the
     11        lifecycle of GraphicsContext used in Coordinated Graphics System.
     12        CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
     13        of GraphicsContext anymore. Instead, those classes use client pattern to
     14        ask the CoordiantedSurface to paint to the GraphicsContext.
     15
     16        This refactoring is needed to implement CoordinatedSurface for Threaded
     17        Coordinated Graphics.
     18
     19        No new tests, covered by existing tests.
     20
     21        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
     22        (WebCore::CoordinatedGraphicsLayer::paintToSurface):
     23        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
     24        * platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
     25        (WebCore::ImageBackingSurfaceClient::ImageBackingSurfaceClient):
     26        (WebCore::CoordinatedImageBacking::update):
     27        * platform/graphics/texmap/coordinated/CoordinatedSurface.h:
     28        (WebCore::CoordinatedSurface::Client::~Client):
     29        * platform/graphics/texmap/coordinated/CoordinatedTile.cpp:
     30        (WebCore::CoordinatedTile::updateBackBuffer):
     31        (WebCore::CoordinatedTile::paintToSurfaceContext):
     32        * platform/graphics/texmap/coordinated/CoordinatedTile.h:
     33        * platform/graphics/texmap/coordinated/UpdateAtlas.cpp:
     34        (WebCore::UpdateAtlasSurfaceClient::UpdateAtlasSurfaceClient):
     35        (WebCore::UpdateAtlas::paintOnAvailableBuffer):
     36        * platform/graphics/texmap/coordinated/UpdateAtlas.h:
     37
    1382013-06-05  Ryosuke Niwa  <rniwa@webkit.org>
    239
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

    r151220 r151262  
    960960}
    961961
    962 PassOwnPtr<GraphicsContext> CoordinatedGraphicsLayer::beginContentUpdate(const IntSize& size, uint32_t& atlas, IntPoint& offset)
     962bool CoordinatedGraphicsLayer::paintToSurface(const IntSize& size, uint32_t& atlas, IntPoint& offset, CoordinatedSurface::Client* client)
    963963{
    964964    ASSERT(m_coordinator);
    965965    ASSERT(m_coordinator->isFlushingLayerChanges());
    966     return m_coordinator->beginContentUpdate(size, contentsOpaque() ? CoordinatedSurface::NoFlags : CoordinatedSurface::SupportsAlpha, atlas, offset);
     966    return m_coordinator->paintToSurface(size, contentsOpaque() ? CoordinatedSurface::NoFlags : CoordinatedSurface::SupportsAlpha, atlas, offset, client);
    967967}
    968968
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h

    r151220 r151262  
    5353    virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) = 0;
    5454    virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
    55     virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&) = 0;
     55    virtual bool paintToSurface(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client*) = 0;
    5656
    5757    virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
     
    143143    virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE;
    144144    virtual void removeTile(uint32_t tileID) OVERRIDE;
    145     virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, uint32_t& atlasID, IntPoint&) OVERRIDE;
     145    virtual bool paintToSurface(const IntSize&, uint32_t& /* atlasID */, IntPoint&, CoordinatedSurface::Client*) OVERRIDE;
    146146
    147147    void setCoordinator(CoordinatedGraphicsLayerClient*);
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp

    r151214 r151262  
    3333
    3434namespace WebCore {
     35
     36class ImageBackingSurfaceClient : public CoordinatedSurface::Client {
     37public:
     38    ImageBackingSurfaceClient(Image* image, const IntRect& rect)
     39        : m_image(image)
     40        , m_rect(rect)
     41    {
     42    }
     43
     44    virtual void paintToSurfaceContext(GraphicsContext* context) OVERRIDE
     45    {
     46        context->drawImage(m_image, ColorSpaceDeviceRGB, m_rect, m_rect);
     47    }
     48
     49private:
     50    Image* m_image;
     51    IntRect m_rect;
     52};
    3553
    3654CoordinatedImageBackingID CoordinatedImageBacking::getCoordinatedImageBackingID(Image* image)
     
    110128
    111129    IntRect rect(IntPoint::zero(), m_image->size());
    112     OwnPtr<GraphicsContext> context = m_surface->createGraphicsContext(rect);
    113     context->drawImage(m_image.get(), ColorSpaceDeviceRGB, rect, rect);
     130
     131    ImageBackingSurfaceClient surfaceClient(m_image.get(), rect);
     132    m_surface->paintToSurface(rect, &surfaceClient);
    114133
    115134    m_nativeImagePtr = m_image->nativeImageForCurrentFrame();
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedSurface.h

    r141543 r151262  
    4040    typedef unsigned Flags;
    4141
     42    class Client {
     43    public:
     44        virtual ~Client() { }
     45        virtual void paintToSurfaceContext(GraphicsContext*) = 0;
     46    };
     47
    4248    typedef PassRefPtr<CoordinatedSurface> Factory(const IntSize&, Flags);
    4349    static void setFactory(Factory);
     
    4955    virtual IntSize size() const = 0;
    5056
    51     // Create a graphics context that can be used to paint into the backing store.
    52     virtual PassOwnPtr<GraphicsContext> createGraphicsContext(const IntRect&) = 0;
     57    virtual void paintToSurface(const IntRect&, Client*) = 0;
    5358
    5459#if USE(TEXTURE_MAPPER)
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.cpp

    r141543 r151262  
    7474
    7575    SurfaceUpdateInfo updateInfo;
    76     OwnPtr<GraphicsContext> graphicsContext = m_client->beginContentUpdate(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset);
    77     if (!graphicsContext)
     76
     77    if (!m_client->paintToSurface(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset, this))
    7878        return Vector<IntRect>();
    79     graphicsContext->translate(-m_dirtyRect.x(), -m_dirtyRect.y());
    80     graphicsContext->scale(FloatSize(m_tiledBackingStore->contentsScale(), m_tiledBackingStore->contentsScale()));
    81     m_tiledBackingStore->client()->tiledBackingStorePaint(graphicsContext.get(), m_tiledBackingStore->mapToContents(m_dirtyRect));
    8279
    8380    updateInfo.updateRect = m_dirtyRect;
    8481    updateInfo.updateRect.move(-m_rect.x(), -m_rect.y());
    8582    updateInfo.scaleFactor = m_tiledBackingStore->contentsScale();
    86     graphicsContext.release();
    8783
    8884    static uint32_t id = 1;
     
    10096    m_dirtyRect = IntRect();
    10197    return updatedRects;
     98}
     99
     100void CoordinatedTile::paintToSurfaceContext(GraphicsContext* context)
     101{
     102    context->translate(-m_dirtyRect.x(), -m_dirtyRect.y());
     103    context->scale(FloatSize(m_tiledBackingStore->contentsScale(), m_tiledBackingStore->contentsScale()));
     104    m_tiledBackingStore->client()->tiledBackingStorePaint(context, m_tiledBackingStore->mapToContents(m_dirtyRect));
    102105}
    103106
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.h

    r141543 r151262  
    2929#if USE(TILED_BACKING_STORE)
    3030
     31#include "CoordinatedSurface.h"
    3132#include "IntRect.h"
    3233#include "Tile.h"
     
    4041class TiledBackingStore;
    4142
    42 class CoordinatedTile : public Tile {
     43class CoordinatedTile : public Tile, public CoordinatedSurface::Client {
    4344public:
    4445    static PassRefPtr<Tile> create(CoordinatedTileClient* client, TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate) { return adoptRef(new CoordinatedTile(client, tiledBackingStore, tileCoordinate)); }
     
    5556    const IntRect& rect() const { return m_rect; }
    5657    void resize(const IntSize&);
     58
     59    virtual void paintToSurfaceContext(GraphicsContext*) OVERRIDE;
    5760
    5861private:
     
    7679    virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) = 0;
    7780    virtual void removeTile(uint32_t tileID) = 0;
    78     virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, uint32_t& atlasID, IntPoint&) = 0;
     81    virtual bool paintToSurface(const IntSize&, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client*) = 0;
    7982};
    8083
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp

    r151214 r151262  
    3131namespace WebCore {
    3232
     33class UpdateAtlasSurfaceClient : public CoordinatedSurface::Client {
     34public:
     35    UpdateAtlasSurfaceClient(CoordinatedSurface::Client* client, const IntSize& size, bool supportsAlpha)
     36        : m_client(client)
     37        , m_size(size)
     38        , m_supportsAlpha(supportsAlpha)
     39    {
     40    }
     41
     42    virtual void paintToSurfaceContext(GraphicsContext* context) OVERRIDE
     43    {
     44        if (m_supportsAlpha) {
     45            context->setCompositeOperation(CompositeCopy);
     46            context->fillRect(IntRect(IntPoint::zero(), m_size), Color::transparent, ColorSpaceDeviceRGB);
     47            context->setCompositeOperation(CompositeSourceOver);
     48        }
     49
     50        m_client->paintToSurfaceContext(context);
     51    }
     52
     53private:
     54    CoordinatedSurface::Client* m_client;
     55    IntSize m_size;
     56    bool m_supportsAlpha;
     57};
     58
    3359UpdateAtlas::UpdateAtlas(Client* client, int dimension, CoordinatedSurface::Flags flags)
    3460    : m_client(client)
     
    6288}
    6389
    64 PassOwnPtr<GraphicsContext> UpdateAtlas::beginPaintingOnAvailableBuffer(uint32_t& atlasID, const IntSize& size, IntPoint& offset)
     90
     91bool UpdateAtlas::paintOnAvailableBuffer(const IntSize& size, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
    6592{
    6693    m_inactivityInSeconds = 0;
     
    6895    IntRect rect = m_areaAllocator->allocate(size);
    6996
    70     // No available buffer was found, returning null.
     97    // No available buffer was found.
    7198    if (rect.isEmpty())
    72         return PassOwnPtr<GraphicsContext>();
     99        return false;
    73100
    74101    if (!m_surface)
    75         return PassOwnPtr<GraphicsContext>();
     102        return false;
    76103
    77104    atlasID = m_ID;
     
    79106    // FIXME: Use tri-state buffers, to allow faster updates.
    80107    offset = rect.location();
    81     OwnPtr<GraphicsContext> graphicsContext = m_surface->createGraphicsContext(rect);
    82108
    83     if (supportsAlpha()) {
    84         graphicsContext->setCompositeOperation(CompositeCopy);
    85         graphicsContext->fillRect(IntRect(IntPoint::zero(), size), Color::transparent, ColorSpaceDeviceRGB);
    86         graphicsContext->setCompositeOperation(CompositeSourceOver);
    87     }
     109    UpdateAtlasSurfaceClient surfaceClient(client, size, supportsAlpha());
     110    m_surface->paintToSurface(rect, &surfaceClient);
    88111
    89     return graphicsContext.release();
     112    return true;
    90113}
    91114
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h

    r151214 r151262  
    4646    inline IntSize size() const { return m_surface->size(); }
    4747
    48     // Returns a null pointer of there is no available buffer.
    49     PassOwnPtr<GraphicsContext> beginPaintingOnAvailableBuffer(uint32_t& atlasID, const IntSize&, IntPoint& offset);
     48    // Returns false if there is no available buffer.
     49    bool paintOnAvailableBuffer(const IntSize&, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client*);
    5050    void didSwapBuffers();
    5151    bool supportsAlpha() const { return m_surface->supportsAlpha(); }
  • trunk/Source/WebKit2/ChangeLog

    r151251 r151262  
     12013-06-06  Jae Hyun Park  <jae.park@company100.net>
     2
     3        Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
     4        https://bugs.webkit.org/show_bug.cgi?id=108899
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        This is a preparation patch for Threaded Coordinated Graphics.
     9
     10        This patch changes CoordinatedSurface to be responsible for the
     11        lifecycle of GraphicsContext used in Coordinated Graphics System.
     12        CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
     13        of GraphicsContext anymore. Instead, those classes use client pattern to
     14        ask the CoordiantedSurface to paint to the GraphicsContext.
     15
     16        This refactoring is needed to implement CoordinatedSurface for Threaded
     17        Coordinated Graphics.
     18
     19        * Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp:
     20        (WebKit::WebCoordinatedSurface::paintToSurface):
     21        * Shared/CoordinatedGraphics/WebCoordinatedSurface.h:
     22        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
     23        (WebKit::CoordinatedLayerTreeHost::paintToSurface):
     24        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
     25
    1262013-06-05  Kangil Han  <kangil.han@samsung.com>
    227
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp

    r141632 r151262  
    184184}
    185185
     186void WebCoordinatedSurface::paintToSurface(const IntRect& rect, CoordinatedSurface::Client* client)
     187{
     188    ASSERT(client);
     189
     190    OwnPtr<GraphicsContext> context = createGraphicsContext(rect);
     191    client->paintToSurfaceContext(context.get());
     192}
     193
    186194#if USE(TEXTURE_MAPPER)
    187195void WebCoordinatedSurface::copyToTexture(PassRefPtr<WebCore::BitmapTexture> passTexture, const IntRect& target, const IntPoint& sourceOffset)
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.h

    r141632 r151262  
    7474    virtual WebCore::IntSize size() const OVERRIDE { return m_size; }
    7575
    76     virtual PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(const WebCore::IntRect&) OVERRIDE;
     76    virtual void paintToSurface(const WebCore::IntRect&, WebCore::CoordinatedSurface::Client*) OVERRIDE;
    7777
    7878#if USE(TEXTURE_MAPPER)
     
    8888    static PassRefPtr<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags, PassRefPtr<ShareableBitmap>);
    8989
     90    PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(const WebCore::IntRect&);
    9091#if USE(GRAPHICS_SURFACE)
    9192    WebCoordinatedSurface(const WebCore::IntSize&, Flags, PassRefPtr<WebCore::GraphicsSurface>);
  • trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp

    r151220 r151262  
    671671}
    672672
    673 PassOwnPtr<GraphicsContext> CoordinatedLayerTreeHost::beginContentUpdate(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset)
    674 {
    675     OwnPtr<GraphicsContext> graphicsContext;
     673bool CoordinatedLayerTreeHost::paintToSurface(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
     674{
    676675    for (unsigned i = 0; i < m_updateAtlases.size(); ++i) {
    677676        UpdateAtlas* atlas = m_updateAtlases[i].get();
    678677        if (atlas->supportsAlpha() == (flags & CoordinatedSurface::SupportsAlpha)) {
    679             // This will return null if there is no available buffer space.
    680             graphicsContext = atlas->beginPaintingOnAvailableBuffer(atlasID, size, offset);
    681             if (graphicsContext)
    682                 return graphicsContext.release();
     678            // This will false if there is no available buffer space.
     679            if (atlas->paintOnAvailableBuffer(size, atlasID, offset, client))
     680                return true;
    683681        }
    684682    }
     
    687685    m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
    688686    scheduleReleaseInactiveAtlases();
    689     return m_updateAtlases.last()->beginPaintingOnAvailableBuffer(atlasID, size, offset);
     687    return m_updateAtlases.last()->paintOnAvailableBuffer(size, atlasID, offset, client);
    690688}
    691689
  • trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h

    r151214 r151262  
    125125    virtual PassRefPtr<WebCore::CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
    126126    virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
    127     virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& atlasID, WebCore::IntPoint&);
     127    virtual bool paintToSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& /* atlasID */, WebCore::IntPoint&, WebCore::CoordinatedSurface::Client*) OVERRIDE;
    128128    virtual void syncLayerState(WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayerState&);
    129129
Note: See TracChangeset for help on using the changeset viewer.