Changeset 92900 in webkit


Ignore:
Timestamp:
Aug 11, 2011 7:07:24 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Defer managed texture creation and destruction until updateCompositorResources
https://bugs.webkit.org/show_bug.cgi?id=64772

Patch by James Robinson <jamesr@chromium.org> on 2011-08-11
Reviewed by Kenneth Russell.

This adds support for deferring GraphicsContext3D calls for texture creation and destruction for managed
textures and defers these calls until updateCompositorResources() for contents textures. The primary benefit of
this change is that it decouples managing the texture budget for the next frame (which has to happen before
painting layer contents) from the actual GL calls that create/destroy textures. That way, in the threaded
compositing world we can continue to use textures from the previous frame while software painting contents for
the next frame into software buffers or SkPictures.

Also renames LayerTexture to ManagedTexture to better reflect what it is. Not all ManagedTextures we create are
necessarily associated with layers, but they are all managed by a TextureManager.

Covered by compositing/ layout tests.

  • WebCore.gypi:
  • platform/graphics/chromium/ContentLayerChromium.h:
  • platform/graphics/chromium/ImageLayerChromium.cpp:

(WebCore::ImageLayerTextureUpdater::updateTextureRect):

  • platform/graphics/chromium/LayerRendererChromium.cpp:

(WebCore::LayerRendererChromium::releaseTextures):
(WebCore::LayerRendererChromium::drawLayers):
(WebCore::LayerRendererChromium::updateLayers):
(WebCore::LayerRendererChromium::getOffscreenLayerTexture):
(WebCore::LayerRendererChromium::useRenderSurface):
(WebCore::LayerRendererChromium::initializeSharedObjects):

  • platform/graphics/chromium/LayerRendererChromium.h:
  • platform/graphics/chromium/LayerTextureUpdater.h:
  • platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp:

(WebCore::LayerTextureUpdaterBitmap::updateTextureRect):
(WebCore::LayerTextureUpdaterSkPicture::updateTextureRect):

  • platform/graphics/chromium/LayerTextureUpdaterCanvas.h:
  • platform/graphics/chromium/LayerTilerChromium.cpp:

(WebCore::LayerTilerChromium::getSingleTexture):
(WebCore::LayerTilerChromium::createTile):
(WebCore::LayerTilerChromium::updateRect):
(WebCore::LayerTilerChromium::drawTiles):

  • platform/graphics/chromium/LayerTilerChromium.h:

(WebCore::LayerTilerChromium::Tile::Tile):
(WebCore::LayerTilerChromium::Tile::texture):

  • platform/graphics/chromium/ManagedTexture.cpp: Renamed from Source/WebCore/platform/graphics/chromium/LayerTexture.cpp.

(WebCore::ManagedTexture::ManagedTexture):
(WebCore::ManagedTexture::~ManagedTexture):
(WebCore::ManagedTexture::isValid):
(WebCore::ManagedTexture::reserve):
(WebCore::ManagedTexture::unreserve):
(WebCore::ManagedTexture::bindTexture):
(WebCore::ManagedTexture::framebufferTexture2D):

  • platform/graphics/chromium/ManagedTexture.h: Renamed from Source/WebCore/platform/graphics/chromium/LayerTexture.h.

(WebCore::ManagedTexture::create):
(WebCore::ManagedTexture::format):
(WebCore::ManagedTexture::isReserved):

  • platform/graphics/chromium/RenderSurfaceChromium.h:
  • platform/graphics/chromium/TextureManager.cpp:

(WebCore::TextureManager::TextureManager):
(WebCore::TextureManager::deleteEvictedTextures):
(WebCore::TextureManager::removeTexture):
(WebCore::TextureManager::allocateTexture):
(WebCore::TextureManager::requestTexture):

  • platform/graphics/chromium/TextureManager.h:

(WebCore::TextureManager::create):
(WebCore::TextureManager::setAssociatedContextDebugOnly):
(WebCore::TextureManager::associatedContextDebugOnly):

  • platform/graphics/chromium/TiledLayerChromium.h:
  • platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:

(WebCore::CCHeadsUpDisplay::draw):

  • platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
  • platform/graphics/chromium/cc/CCRenderSurface.cpp:

(WebCore::CCRenderSurface::prepareContentsTexture):
(WebCore::CCRenderSurface::drawSurface):

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

(WebCore::CCRenderSurface::contentsTexture):

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

(WebCore::CCTiledLayerImpl::bindContentsTexture):

Location:
trunk/Source/WebCore
Files:
20 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92897 r92900  
     12011-08-11  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] Defer managed texture creation and destruction until updateCompositorResources
     4        https://bugs.webkit.org/show_bug.cgi?id=64772
     5
     6        Reviewed by Kenneth Russell.
     7
     8        This adds support for deferring GraphicsContext3D calls for texture creation and destruction for managed
     9        textures and defers these calls until updateCompositorResources() for contents textures.  The primary benefit of
     10        this change is that it decouples managing the texture budget for the next frame (which has to happen before
     11        painting layer contents) from the actual GL calls that create/destroy textures.  That way, in the threaded
     12        compositing world we can continue to use textures from the previous frame while software painting contents for
     13        the next frame into software buffers or SkPictures.
     14
     15        Also renames LayerTexture to ManagedTexture to better reflect what it is.  Not all ManagedTextures we create are
     16        necessarily associated with layers, but they are all managed by a TextureManager.
     17
     18        Covered by compositing/ layout tests.
     19
     20        * WebCore.gypi:
     21        * platform/graphics/chromium/ContentLayerChromium.h:
     22        * platform/graphics/chromium/ImageLayerChromium.cpp:
     23        (WebCore::ImageLayerTextureUpdater::updateTextureRect):
     24        * platform/graphics/chromium/LayerRendererChromium.cpp:
     25        (WebCore::LayerRendererChromium::releaseTextures):
     26        (WebCore::LayerRendererChromium::drawLayers):
     27        (WebCore::LayerRendererChromium::updateLayers):
     28        (WebCore::LayerRendererChromium::getOffscreenLayerTexture):
     29        (WebCore::LayerRendererChromium::useRenderSurface):
     30        (WebCore::LayerRendererChromium::initializeSharedObjects):
     31        * platform/graphics/chromium/LayerRendererChromium.h:
     32        * platform/graphics/chromium/LayerTextureUpdater.h:
     33        * platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp:
     34        (WebCore::LayerTextureUpdaterBitmap::updateTextureRect):
     35        (WebCore::LayerTextureUpdaterSkPicture::updateTextureRect):
     36        * platform/graphics/chromium/LayerTextureUpdaterCanvas.h:
     37        * platform/graphics/chromium/LayerTilerChromium.cpp:
     38        (WebCore::LayerTilerChromium::getSingleTexture):
     39        (WebCore::LayerTilerChromium::createTile):
     40        (WebCore::LayerTilerChromium::updateRect):
     41        (WebCore::LayerTilerChromium::drawTiles):
     42        * platform/graphics/chromium/LayerTilerChromium.h:
     43        (WebCore::LayerTilerChromium::Tile::Tile):
     44        (WebCore::LayerTilerChromium::Tile::texture):
     45        * platform/graphics/chromium/ManagedTexture.cpp: Renamed from Source/WebCore/platform/graphics/chromium/LayerTexture.cpp.
     46        (WebCore::ManagedTexture::ManagedTexture):
     47        (WebCore::ManagedTexture::~ManagedTexture):
     48        (WebCore::ManagedTexture::isValid):
     49        (WebCore::ManagedTexture::reserve):
     50        (WebCore::ManagedTexture::unreserve):
     51        (WebCore::ManagedTexture::bindTexture):
     52        (WebCore::ManagedTexture::framebufferTexture2D):
     53        * platform/graphics/chromium/ManagedTexture.h: Renamed from Source/WebCore/platform/graphics/chromium/LayerTexture.h.
     54        (WebCore::ManagedTexture::create):
     55        (WebCore::ManagedTexture::format):
     56        (WebCore::ManagedTexture::isReserved):
     57        * platform/graphics/chromium/RenderSurfaceChromium.h:
     58        * platform/graphics/chromium/TextureManager.cpp:
     59        (WebCore::TextureManager::TextureManager):
     60        (WebCore::TextureManager::deleteEvictedTextures):
     61        (WebCore::TextureManager::removeTexture):
     62        (WebCore::TextureManager::allocateTexture):
     63        (WebCore::TextureManager::requestTexture):
     64        * platform/graphics/chromium/TextureManager.h:
     65        (WebCore::TextureManager::create):
     66        (WebCore::TextureManager::setAssociatedContextDebugOnly):
     67        (WebCore::TextureManager::associatedContextDebugOnly):
     68        * platform/graphics/chromium/TiledLayerChromium.h:
     69        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
     70        (WebCore::CCHeadsUpDisplay::draw):
     71        * platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
     72        * platform/graphics/chromium/cc/CCRenderSurface.cpp:
     73        (WebCore::CCRenderSurface::prepareContentsTexture):
     74        (WebCore::CCRenderSurface::drawSurface):
     75        * platform/graphics/chromium/cc/CCRenderSurface.h:
     76        (WebCore::CCRenderSurface::contentsTexture):
     77        * platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:
     78        (WebCore::CCTiledLayerImpl::bindContentsTexture):
     79
    1802011-08-11  David Kilzer  <ddkilzer@apple.com>
    281
  • trunk/Source/WebCore/WebCore.gypi

    r92890 r92900  
    35023502            'platform/graphics/chromium/LayerRendererChromium.cpp',
    35033503            'platform/graphics/chromium/LayerRendererChromium.h',
    3504             'platform/graphics/chromium/LayerTexture.cpp',
    3505             'platform/graphics/chromium/LayerTexture.h',
     3504            'platform/graphics/chromium/ManagedTexture.cpp',
     3505            'platform/graphics/chromium/ManagedTexture.h',
    35063506            'platform/graphics/chromium/LayerTextureSubImage.cpp',
    35073507            'platform/graphics/chromium/LayerTextureSubImage.h',
  • trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h

    r91823 r92900  
    4040namespace WebCore {
    4141
    42 class LayerTexture;
    4342class LayerTilerChromium;
    4443class LayerTextureUpdater;
  • trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp

    r90963 r92900  
    3838#include "Image.h"
    3939#include "LayerRendererChromium.h"
    40 #include "LayerTexture.h"
     40#include "ManagedTexture.h"
    4141#include "LayerTextureSubImage.h"
    4242#include "LayerTextureUpdater.h"
     
    6868    }
    6969
    70     virtual void updateTextureRect(LayerTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
     70    virtual void updateTextureRect(ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
    7171    {
    72         texture->bindTexture();
     72        texture->bindTexture(context());
    7373
    7474        // Source rect should never go outside the image pixels, even if this
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r92895 r92900  
    4242#include "LayerChromium.h"
    4343#include "LayerPainterChromium.h"
    44 #include "LayerTexture.h"
     44#include "ManagedTexture.h"
    4545#include "LayerTextureUpdaterCanvas.h"
    4646#include "NotImplemented.h"
     
    521521    m_contentsTextureManager->reduceMemoryToLimit(textureMemoryLowLimitBytes);
    522522    m_contentsTextureManager->unprotectAllTextures();
     523    m_contentsTextureManager->deleteEvictedTextures(m_context.get());
    523524    // Evict all RenderSurface textures.
    524525    m_renderSurfaceTextureManager->unprotectAllTextures();
    525526    m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
     527    m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
    526528}
    527529
     
    604606
    605607    m_contentsTextureManager->unprotectAllTextures();
    606     m_contentsTextureManager->reduceMemoryToLimit(textureMemoryReclaimLimitBytes);
    607608
    608609    if (textureMemoryReclaimLimitBytes > m_contentsTextureManager->currentMemoryUseBytes())
     
    610611    else
    611612        m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
     613    m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
    612614
    613615    if (settings().compositeOffscreen)
     
    655657
    656658    m_contentsTextureManager->reduceMemoryToLimit(textureMemoryReclaimLimitBytes);
     659    m_contentsTextureManager->deleteEvictedTextures(m_context.get());
    657660    updateCompositorResources(renderSurfaceLayerList);
    658661}
     
    983986}
    984987
    985 LayerTexture* LayerRendererChromium::getOffscreenLayerTexture()
     988ManagedTexture* LayerRendererChromium::getOffscreenLayerTexture()
    986989{
    987990    return settings().compositeOffscreen && m_rootCCLayerImpl ? m_rootCCLayerImpl->renderSurface()->contentsTexture() : 0;
     
    10231026        return false;
    10241027
    1025     renderSurface->contentsTexture()->framebufferTexture2D();
     1028    renderSurface->contentsTexture()->framebufferTexture2D(m_context.get());
    10261029
    10271030#if !defined ( NDEBUG )
     
    11601163    GLC(m_context.get(), m_context->flush());
    11611164
    1162     m_contentsTextureManager = TextureManager::create(m_context.get(), textureMemoryHighLimitBytes, m_maxTextureSize);
    1163     m_renderSurfaceTextureManager = TextureManager::create(m_context.get(), textureMemoryHighLimitBytes, m_maxTextureSize);
     1165    m_contentsTextureManager = TextureManager::create(textureMemoryHighLimitBytes, m_maxTextureSize);
     1166    m_renderSurfaceTextureManager = TextureManager::create(textureMemoryHighLimitBytes, m_maxTextureSize);
     1167#ifndef NDEBUG
     1168    m_contentsTextureManager->setAssociatedContextDebugOnly(m_context.get());
     1169    m_renderSurfaceTextureManager->setAssociatedContextDebugOnly(m_context.get());
     1170#endif
    11641171    return true;
    11651172}
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h

    r92895 r92900  
    179179
    180180    void drawRootLayer();
    181     LayerTexture* getOffscreenLayerTexture();
     181    ManagedTexture* getOffscreenLayerTexture();
    182182    void copyOffscreenTextureToDisplay();
    183183
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h

    r90963 r92900  
    3737class IntRect;
    3838class IntSize;
    39 class LayerTexture;
     39class ManagedTexture;
    4040
    4141class LayerTextureUpdater {
     
    6262    virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) = 0;
    6363    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels) = 0;
    64     virtual void updateTextureRect(LayerTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0;
     64    virtual void updateTextureRect(ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0;
    6565
    6666protected:
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp

    r92541 r92900  
    3434#include "GraphicsContext.h"
    3535#include "LayerPainterChromium.h"
    36 #include "LayerTexture.h"
     36#include "ManagedTexture.h"
    3737#include "PlatformColor.h"
    3838#include "TraceEvent.h"
     
    9595}
    9696
    97 void LayerTextureUpdaterBitmap::updateTextureRect(LayerTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
     97void LayerTextureUpdaterBitmap::updateTextureRect(ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
    9898{
    9999    PlatformCanvas::AutoLocker locker(&m_canvas);
    100100
    101     texture->bindTexture();
     101    texture->bindTexture(context());
    102102    m_texSubImage.upload(locker.pixels(), contentRect(), sourceRect, destRect, texture->format(), context());
    103103}
     
    146146}
    147147
    148 void LayerTextureUpdaterSkPicture::updateTextureRect(LayerTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
     148void LayerTextureUpdaterSkPicture::updateTextureRect(ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
    149149{
    150150    if (m_createFrameBuffer) {
     
    158158    // Bind texture.
    159159    context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    160     texture->framebufferTexture2D();
     160    texture->framebufferTexture2D(context());
    161161    ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE);
    162162
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.h

    r89647 r92900  
    7777    virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
    7878    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels);
    79     virtual void updateTextureRect(LayerTexture*, const IntRect& sourceRect, const IntRect& destRect);
     79    virtual void updateTextureRect(ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
    8080
    8181private:
     
    9595    virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
    9696    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels);
    97     virtual void updateTextureRect(LayerTexture*, const IntRect& sourceRect, const IntRect& destRect);
     97    virtual void updateTextureRect(ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
    9898
    9999private:
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp

    r92867 r92900  
    3636#include "GraphicsContext3D.h"
    3737#include "LayerRendererChromium.h"
    38 #include "LayerTexture.h"
     38#include "ManagedTexture.h"
    3939#include "LayerTextureUpdater.h"
    4040#include "PlatformColor.h"
     
    8888}
    8989
    90 LayerTexture* LayerTilerChromium::getSingleTexture()
     90ManagedTexture* LayerTilerChromium::getSingleTexture()
    9191{
    9292    if (m_tilingData.numTiles() != 1)
     
    116116        ASSERT(tile->refCount() == 1);
    117117    } else {
    118         GraphicsContext3D* context = layerRendererContext();
    119118        TextureManager* manager = layerRenderer()->contentsTextureManager();
    120         tile = adoptRef(new Tile(LayerTexture::create(context, manager)));
     119        tile = adoptRef(new Tile(ManagedTexture::create(manager)));
    121120    }
    122121    m_tiles.add(make_pair(i, j), tile);
     
    356355                CRASH();
    357356
    358             tile->texture()->bindTexture();
     357            tile->texture()->bindTexture(context);
    359358            const GC3Dint filter = m_tilingData.borderTexels() ? GraphicsContext3D::LINEAR : GraphicsContext3D::NEAREST;
    360359            GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, filter));
     
    541540            ASSERT(tile->texture()->isReserved());
    542541
    543             tile->texture()->bindTexture();
     542            tile->texture()->bindTexture(context);
    544543
    545544            // Don't use tileContentRect here, as that contains the full
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h

    r92255 r92900  
    3131
    3232#include "LayerChromium.h"
    33 #include "LayerTexture.h"
     33#include "ManagedTexture.h"
    3434#include "LayerTextureUpdater.h"
    3535#include "TilingData.h"
     
    8686
    8787    // If this tiler has exactly one tile, return its texture. Otherwise, null.
    88     LayerTexture* getSingleTexture();
     88    ManagedTexture* getSingleTexture();
    8989
    9090private:
     
    9494        WTF_MAKE_NONCOPYABLE(Tile);
    9595    public:
    96         explicit Tile(PassOwnPtr<LayerTexture> tex) : m_tex(tex), m_i(-1), m_j(-1) { }
     96        explicit Tile(PassOwnPtr<ManagedTexture> tex) : m_tex(tex), m_i(-1), m_j(-1) { }
    9797
    98         LayerTexture* texture() { return m_tex.get(); }
     98        ManagedTexture* texture() { return m_tex.get(); }
    9999
    100100        bool dirty() const { return !m_dirtyLayerRect.isEmpty(); }
     
    108108        IntRect m_dirtyLayerRect;
    109109    private:
    110         OwnPtr<LayerTexture> m_tex;
     110        OwnPtr<ManagedTexture> m_tex;
    111111        int m_i;
    112112        int m_j;
  • trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp

    r92897 r92900  
    2727#if USE(ACCELERATED_COMPOSITING)
    2828
    29 #include "LayerTexture.h"
     29#include "ManagedTexture.h"
    3030
    3131#include "GraphicsContext3D.h"
     
    3434namespace WebCore {
    3535
    36 LayerTexture::LayerTexture(GraphicsContext3D* context, TextureManager* manager)
    37     : m_context(context)
    38     , m_textureManager(manager)
     36ManagedTexture::ManagedTexture(TextureManager* manager)
     37    : m_textureManager(manager)
    3938    , m_token(0)
    4039    , m_format(0)
     
    4342}
    4443
    45 LayerTexture::~LayerTexture()
     44ManagedTexture::~ManagedTexture()
    4645{
    4746    if (m_token)
     
    4948}
    5049
    51 bool LayerTexture::isValid(const IntSize& size, unsigned format)
     50bool ManagedTexture::isValid(const IntSize& size, unsigned format)
    5251{
    5352    return m_token && size == m_size && format == m_format && m_textureManager->hasTexture(m_token);
    5453}
    5554
    56 bool LayerTexture::reserve(const IntSize& size, unsigned format)
     55bool ManagedTexture::reserve(const IntSize& size, unsigned format)
    5756{
    5857    if (!m_token)
    5958        m_token = m_textureManager->getToken();
    6059
     60    bool reserved = true;
    6161    if (size == m_size && format == m_format && m_textureManager->hasTexture(m_token))
    6262        m_textureManager->protectTexture(m_token);
    6363    else {
    64         m_textureId = m_textureManager->requestTexture(m_token, size, format);
    65         if (m_textureId) {
     64        m_textureId = 0;
     65        reserved = m_textureManager->requestTexture(m_token, size, format);
     66        if (reserved) {
    6667            m_size = size;
    6768            m_format = format;
     
    6970    }
    7071
    71     return m_textureId;
     72    return reserved;
    7273}
    7374
    74 void LayerTexture::unreserve()
     75void ManagedTexture::unreserve()
    7576{
    7677    if (!m_token)
     
    8081}
    8182
    82 void LayerTexture::bindTexture()
     83void ManagedTexture::bindTexture(GraphicsContext3D* context)
    8384{
    8485    ASSERT(m_textureManager->hasTexture(m_token));
    85     m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
     86    ASSERT(context == m_textureManager->associatedContextDebugOnly());
     87    if (!m_textureId)
     88        m_textureId = m_textureManager->allocateTexture(context, m_token);
     89    context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
    8690}
    8791
    88 void LayerTexture::framebufferTexture2D()
     92void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context)
    8993{
    90     m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_textureId, 0);
     94    ASSERT(m_textureManager->hasTexture(m_token));
     95    ASSERT(context == m_textureManager->associatedContextDebugOnly());
     96    if (!m_textureId)
     97        m_textureId = m_textureManager->allocateTexture(context, m_token);
     98    context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_textureId, 0);
    9199}
    92100
  • trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h

    r92897 r92900  
    2323 */
    2424
    25 #ifndef LayerTexture_h
    26 #define LayerTexture_h
     25#ifndef ManagedTexture_h
     26#define ManagedTexture_h
    2727
    2828#include "IntSize.h"
     
    3939class TextureManager;
    4040
    41 class LayerTexture {
    42     WTF_MAKE_NONCOPYABLE(LayerTexture); WTF_MAKE_FAST_ALLOCATED;
     41class ManagedTexture {
     42    WTF_MAKE_NONCOPYABLE(ManagedTexture);
    4343public:
    44     static PassOwnPtr<LayerTexture> create(GraphicsContext3D* context, TextureManager* manager)
     44    static PassOwnPtr<ManagedTexture> create(TextureManager* manager)
    4545    {
    46         return adoptPtr(new LayerTexture(context, manager));
     46        return adoptPtr(new ManagedTexture(manager));
    4747    }
    48     ~LayerTexture();
     48    ~ManagedTexture();
    4949
    5050    unsigned format() const { return m_format; }
     
    5858    }
    5959
    60     void bindTexture();
    61     void framebufferTexture2D();
     60    void bindTexture(GraphicsContext3D*);
     61    void framebufferTexture2D(GraphicsContext3D*);
    6262
    6363private:
    64     LayerTexture(GraphicsContext3D*, TextureManager*);
     64    explicit ManagedTexture(TextureManager*);
    6565
    66     RefPtr<GraphicsContext3D> m_context;
    6766    TextureManager* m_textureManager;
    6867    TextureToken m_token;
     
    7473}
    7574
    76 #endif
     75#endif // ManagedTexture_h
    7776
  • trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h

    r92245 r92900  
    4242class LayerChromium;
    4343class LayerRendererChromium;
    44 class LayerTexture;
     44class ManagedTexture;
    4545
    4646class RenderSurfaceChromium {
  • trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp

    r91629 r92900  
    3939}
    4040
    41 TextureManager::TextureManager(GraphicsContext3D* context, size_t memoryLimitBytes, int maxTextureSize)
    42     : m_context(context)
    43     , m_memoryLimitBytes(memoryLimitBytes)
     41TextureManager::TextureManager(size_t memoryLimitBytes, int maxTextureSize)
     42    : m_memoryLimitBytes(memoryLimitBytes)
    4443    , m_memoryUseBytes(0)
    4544    , m_maxTextureSize(maxTextureSize)
     
    133132}
    134133
     134void TextureManager::deleteEvictedTextures(GraphicsContext3D* context)
     135{
     136    ASSERT(context == m_associatedContextDebugOnly);
     137    for (size_t i = 0; i < m_evictedTextureIds.size(); ++i)
     138        GLC(context, context->deleteTexture(m_evictedTextureIds[i]));
     139    m_evictedTextureIds.clear();
     140}
     141
    135142void TextureManager::removeTexture(TextureToken token, TextureInfo info)
    136143{
     
    141148    ASSERT(m_textureLRUSet.contains(token));
    142149    m_textureLRUSet.remove(token);
    143     GLC(m_context.get(), m_context->deleteTexture(info.textureId));
    144 }
    145 
    146 unsigned TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format)
     150    m_evictedTextureIds.append(info.textureId);
     151}
     152
     153unsigned TextureManager::allocateTexture(GraphicsContext3D* context, TextureToken token)
     154{
     155    ASSERT(context == m_associatedContextDebugOnly);
     156    TextureMap::iterator it = m_textures.find(token);
     157    ASSERT(it != m_textures.end());
     158    TextureInfo* info = &it.get()->second;
     159    ASSERT(info->isProtected);
     160
     161    unsigned textureId;
     162    GLC(context, textureId = context->createTexture());
     163    GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
     164    // Do basic linear filtering on resize.
     165    GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
     166    GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
     167    // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
     168    GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
     169    GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
     170    GLC(context, context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, info->format, info->size.width(), info->size.height(), 0, info->format, GraphicsContext3D::UNSIGNED_BYTE));
     171    info->textureId = textureId;
     172    return textureId;
     173}
     174
     175bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format)
    147176{
    148177    if (size.width() > m_maxTextureSize || size.height() > m_maxTextureSize)
    149         return 0;
     178        return false;
    150179
    151180    TextureMap::iterator it = m_textures.find(token);
     
    157186    size_t memoryRequiredBytes = memoryUseBytes(size, format);
    158187    if (memoryRequiredBytes > m_memoryLimitBytes)
    159         return 0;
     188        return false;
    160189
    161190    reduceMemoryToLimit(m_memoryLimitBytes - memoryRequiredBytes);
    162191    if (m_memoryUseBytes + memoryRequiredBytes > m_memoryLimitBytes)
    163         return 0;
    164 
    165     unsigned textureId;
    166     GLC(m_context.get(), textureId = m_context->createTexture());
    167     GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
    168     // Do basic linear filtering on resize.
    169     GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
    170     GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
    171     // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
    172     GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
    173     GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
    174     GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE));
     192        return false;
     193
    175194    TextureInfo info;
    176195    info.size = size;
    177196    info.format = format;
    178     info.textureId = textureId;
     197    info.textureId = 0;
    179198    info.isProtected = true;
    180199    addTexture(token, info);
    181     return textureId;
     200    return true;
    182201}
    183202
  • trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h

    r91629 r92900  
    4141    WTF_MAKE_NONCOPYABLE(TextureManager);
    4242public:
    43     static PassOwnPtr<TextureManager> create(GraphicsContext3D* context, size_t memoryLimitBytes, int maxTextureSize)
     43    static PassOwnPtr<TextureManager> create(size_t memoryLimitBytes, int maxTextureSize)
    4444    {
    45         return adoptPtr(new TextureManager(context, memoryLimitBytes, maxTextureSize));
     45        return adoptPtr(new TextureManager(memoryLimitBytes, maxTextureSize));
    4646    }
    4747
     
    5252    bool hasTexture(TextureToken);
    5353
    54     unsigned requestTexture(TextureToken, IntSize, unsigned textureFormat);
     54    bool requestTexture(TextureToken, IntSize, unsigned textureFormat);
    5555
    5656    void protectTexture(TextureToken);
     
    5959    bool isProtected(TextureToken);
    6060
     61    unsigned allocateTexture(GraphicsContext3D*, TextureToken);
     62    void deleteEvictedTextures(GraphicsContext3D*);
     63
    6164    void reduceMemoryToLimit(size_t);
    6265    size_t currentMemoryUseBytes() const { return m_memoryUseBytes; }
    6366
     67#ifndef NDEBUG
     68    void setAssociatedContextDebugOnly(GraphicsContext3D* context) { m_associatedContextDebugOnly = context; }
     69    GraphicsContext3D* associatedContextDebugOnly() const { return m_associatedContextDebugOnly; }
     70#endif
     71
    6472private:
    65     TextureManager(GraphicsContext3D*, size_t memoryLimitBytes, int maxTextureSize);
     73    TextureManager(size_t memoryLimitBytes, int maxTextureSize);
    6674
    6775    struct TextureInfo {
     
    7583    void removeTexture(TextureToken, TextureInfo);
    7684
    77     RefPtr<GraphicsContext3D> m_context;
    78 
    7985    typedef HashMap<TextureToken, TextureInfo> TextureMap;
    8086    TextureMap m_textures;
     
    8591    int m_maxTextureSize;
    8692    TextureToken m_nextToken;
     93
     94#ifndef NDEBUG
     95    GraphicsContext3D* m_associatedContextDebugOnly;
     96#endif
     97
     98    Vector<unsigned> m_evictedTextureIds;
    8799};
    88100
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h

    r92255 r92900  
    3434namespace WebCore {
    3535
    36 class LayerTexture;
    3736class LayerTilerChromium;
    3837class LayerTextureUpdater;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp

    r92895 r92900  
    3535#include "LayerChromium.h"
    3636#include "LayerRendererChromium.h"
    37 #include "LayerTexture.h"
     37#include "ManagedTexture.h"
    3838#include "PlatformCanvas.h"
    3939#include "TextRun.h"
     
    9797    GraphicsContext3D* context = m_layerRenderer->context();
    9898    if (!m_hudTexture)
    99         m_hudTexture = LayerTexture::create(context, m_layerRenderer->renderSurfaceTextureManager());
     99        m_hudTexture = ManagedTexture::create(m_layerRenderer->renderSurfaceTextureManager());
    100100
    101101    // Use a fullscreen texture only if we need to...
     
    124124        PlatformCanvas::AutoLocker locker(&canvas);
    125125
    126         m_hudTexture->bindTexture();
     126        m_hudTexture->bindTexture(context);
    127127        bool uploadedViaMap = false;
    128128        if (m_useMapSubForUploads) {
     
    146146    ASSERT(program && program->initialized());
    147147    GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
    148     m_hudTexture->bindTexture();
     148    m_hudTexture->bindTexture(context);
    149149    GLC(context, context->useProgram(program->program()));
    150150    GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h

    r92895 r92900  
    3838class GraphicsContext3D;
    3939class LayerRendererChromium;
    40 class LayerTexture;
     40class ManagedTexture;
    4141
    4242// Class that handles drawing of composited render layers using GL.
     
    7272    double m_filteredFrameTime;
    7373
    74     OwnPtr<LayerTexture> m_hudTexture;
     74    OwnPtr<ManagedTexture> m_hudTexture;
    7575
    7676    LayerRendererChromium* m_layerRenderer;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp

    r92245 r92900  
    3333#include "LayerChromium.h"
    3434#include "LayerRendererChromium.h"
    35 #include "LayerTexture.h"
     35#include "ManagedTexture.h"
    3636#include "TextStream.h"
    3737#include "cc/CCLayerImpl.h"
     
    8686
    8787    if (!m_contentsTexture)
    88         m_contentsTexture = LayerTexture::create(layerRenderer()->context(), textureManager);
     88        m_contentsTexture = ManagedTexture::create(textureManager);
    8989
    9090    if (m_contentsTexture->isReserved())
     
    124124            GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
    125125            GLC(context3D, context3D->uniform1i(maskProgram->fragmentShader().samplerLocation(), 0));
    126             m_contentsTexture->bindTexture();
     126            m_contentsTexture->bindTexture(context3D);
    127127            GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE1));
    128128            GLC(context3D, context3D->uniform1i(maskProgram->fragmentShader().maskSamplerLocation(), 1));
     
    137137    if (!useMask) {
    138138        GLC(context3D, context3D->useProgram(program->program()));
    139         m_contentsTexture->bindTexture();
     139        m_contentsTexture->bindTexture(context3D);
    140140        GLC(context3D, context3D->uniform1i(program->fragmentShader().samplerLocation(), 0));
    141141        shaderMatrixLocation = program->vertexShader().matrixLocation();
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.h

    r92245 r92900  
    4242class CCLayerImpl;
    4343class LayerRendererChromium;
    44 class LayerTexture;
     44class ManagedTexture;
    4545
    4646class CCRenderSurface {
     
    9292    typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlphaMask> MaskProgram;
    9393
    94     LayerTexture* contentsTexture() const { return m_contentsTexture.get(); }
     94    ManagedTexture* contentsTexture() const { return m_contentsTexture.get(); }
    9595
    9696    int owningLayerId() const;
     
    105105    bool m_skipsDraw;
    106106
    107     OwnPtr<LayerTexture> m_contentsTexture;
     107    OwnPtr<ManagedTexture> m_contentsTexture;
    108108    float m_drawOpacity;
    109109    TransformationMatrix m_drawTransform;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp

    r92245 r92900  
    3030#include "cc/CCTiledLayerImpl.h"
    3131
     32#include "LayerRendererChromium.h"
     33
    3234#include <wtf/text/WTFString.h>
    3335
    3436namespace WebCore {
    3537
    36 class LayerTexture;
     38class ManagedTexture;
    3739
    3840CCTiledLayerImpl::CCTiledLayerImpl(int id)
     
    5860    ASSERT(m_tiler);
    5961
    60     LayerTexture* texture = m_tiler->getSingleTexture();
     62    ManagedTexture* texture = m_tiler->getSingleTexture();
    6163    ASSERT(texture);
    6264
    63     texture->bindTexture();
     65    texture->bindTexture(layerRenderer()->context());
    6466}
    6567
Note: See TracChangeset for help on using the changeset viewer.