https://bugs.webkit.org/show_bug.cgi?id=68190
Reviewed by Kenneth Russell.
This introduces an interface TextureAllocator that the TextureManager uses to allocate/deallocate textures.
This means that TextureManager does not need to depend directly on GraphicsContext3D, other than for the format
enum type, making it more testable. It also allows us to track the allocations by subclassing TextureAllocator
to make sure we aren't leaking any textures.
* WebCore.gypi:
* platform/graphics/chromium/Canvas2DLayerChromium.cpp:
(WebCore::Canvas2DLayerChromium::updateCompositorResources):
* platform/graphics/chromium/Canvas2DLayerChromium.h:
* platform/graphics/chromium/ImageLayerChromium.cpp:
(WebCore::ImageLayerTextureUpdater::updateTextureRect):
* platform/graphics/chromium/LayerChromium.h:
(WebCore::LayerChromium::updateCompositorResources):
* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::LayerRendererChromium):
(WebCore::LayerRendererChromium::releaseRenderSurfaceTextures):
(WebCore::LayerRendererChromium::drawLayers):
(WebCore::LayerRendererChromium::useRenderSurface):
(WebCore::LayerRendererChromium::initializeSharedObjects):
(WebCore::LayerRendererChromium::cleanupSharedObjects):
* platform/graphics/chromium/LayerRendererChromium.h:
(WebCore::LayerRendererChromium::renderSurfaceTextureAllocator):
(WebCore::LayerRendererChromium::contentsTextureAllocator):
* platform/graphics/chromium/LayerTextureUpdater.h:
* platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp:
(WebCore::LayerTextureUpdaterBitmap::updateTextureRect):
(WebCore::LayerTextureUpdaterSkPicture::updateTextureRect):
* platform/graphics/chromium/LayerTextureUpdaterCanvas.h:
* platform/graphics/chromium/ManagedTexture.cpp:
(WebCore::ManagedTexture::bindTexture):
(WebCore::ManagedTexture::framebufferTexture2D):
* platform/graphics/chromium/ManagedTexture.h:
* platform/graphics/chromium/TextureManager.cpp:
(WebCore::TextureManager::memoryUseBytes):
(WebCore::TextureManager::deleteEvictedTextures):
(WebCore::TextureManager::evictAndDeleteAllTextures):
(WebCore::TextureManager::removeTexture):
(WebCore::TextureManager::allocateTexture):
(WebCore::TextureManager::requestTexture):
* platform/graphics/chromium/TextureManager.h:
(WebCore::TextureAllocator::~TextureAllocator):
* platform/graphics/chromium/TiledLayerChromium.cpp:
(WebCore::TiledLayerChromium::updateCompositorResources):
* platform/graphics/chromium/TiledLayerChromium.h:
* platform/graphics/chromium/TrackingTextureAllocator.cpp: Added.
(WebCore::TrackingTextureAllocator::TrackingTextureAllocator):
(WebCore::TrackingTextureAllocator::~TrackingTextureAllocator):
(WebCore::TrackingTextureAllocator::createTexture):
(WebCore::TrackingTextureAllocator::deleteTexture):
* platform/graphics/chromium/TrackingTextureAllocator.h: Copied from Source/WebCore/platform/graphics/chromium/ManagedTexture.h.
(WebCore::TrackingTextureAllocator::create):
(WebCore::TrackingTextureAllocator::currentMemoryUseBytes):
* platform/graphics/chromium/VideoLayerChromium.cpp:
(WebCore::VideoLayerChromium::updateCompositorResources):
(WebCore::VideoLayerChromium::updateTexture):
* platform/graphics/chromium/VideoLayerChromium.h:
* platform/graphics/chromium/WebGLLayerChromium.cpp:
(WebCore::WebGLLayerChromium::updateCompositorResources):
* platform/graphics/chromium/WebGLLayerChromium.h:
* platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
(WebCore::CCHeadsUpDisplay::draw):
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::~CCLayerTreeHost):
(WebCore::CCLayerTreeHost::deleteContentsTexturesOnCCThread):
(WebCore::CCLayerTreeHost::commitToOnCCThread):
(WebCore::CCLayerTreeHost::didRecreateGraphicsContext):
(WebCore::CCLayerTreeHost::updateCompositorResources):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::contentsTextureAllocator):
(WebCore::CCLayerTreeHostImpl::initializeLayerRenderer):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
* platform/graphics/chromium/cc/CCRenderSurface.cpp:
(WebCore::CCRenderSurface::drawSurface):
* platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
(WebCore::CCSingleThreadProxy::setNeedsCommit):
(WebCore::CCSingleThreadProxy::stop):
(WebCore::CCSingleThreadProxy::recreateContextIfNeeded):
(WebCore::CCSingleThreadProxy::commitIfNeeded):
* platform/graphics/chromium/cc/CCThreadProxy.cpp:
(WebCore::CCThreadProxy::commitOnCCThread):
(WebCore::CCThreadProxy::layerTreeHostClosedOnCCThread):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96141
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2011-09-27 James Robinson <jamesr@chromium.org>
+
+ [chromium] LayerRenderChromium asserts about leaking textures.
+ https://bugs.webkit.org/show_bug.cgi?id=68190
+
+ Reviewed by Kenneth Russell.
+
+ This introduces an interface TextureAllocator that the TextureManager uses to allocate/deallocate textures.
+ This means that TextureManager does not need to depend directly on GraphicsContext3D, other than for the format
+ enum type, making it more testable. It also allows us to track the allocations by subclassing TextureAllocator
+ to make sure we aren't leaking any textures.
+
+ * WebCore.gypi:
+ * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
+ (WebCore::Canvas2DLayerChromium::updateCompositorResources):
+ * platform/graphics/chromium/Canvas2DLayerChromium.h:
+ * platform/graphics/chromium/ImageLayerChromium.cpp:
+ (WebCore::ImageLayerTextureUpdater::updateTextureRect):
+ * platform/graphics/chromium/LayerChromium.h:
+ (WebCore::LayerChromium::updateCompositorResources):
+ * platform/graphics/chromium/LayerRendererChromium.cpp:
+ (WebCore::LayerRendererChromium::LayerRendererChromium):
+ (WebCore::LayerRendererChromium::releaseRenderSurfaceTextures):
+ (WebCore::LayerRendererChromium::drawLayers):
+ (WebCore::LayerRendererChromium::useRenderSurface):
+ (WebCore::LayerRendererChromium::initializeSharedObjects):
+ (WebCore::LayerRendererChromium::cleanupSharedObjects):
+ * platform/graphics/chromium/LayerRendererChromium.h:
+ (WebCore::LayerRendererChromium::renderSurfaceTextureAllocator):
+ (WebCore::LayerRendererChromium::contentsTextureAllocator):
+ * platform/graphics/chromium/LayerTextureUpdater.h:
+ * platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp:
+ (WebCore::LayerTextureUpdaterBitmap::updateTextureRect):
+ (WebCore::LayerTextureUpdaterSkPicture::updateTextureRect):
+ * platform/graphics/chromium/LayerTextureUpdaterCanvas.h:
+ * platform/graphics/chromium/ManagedTexture.cpp:
+ (WebCore::ManagedTexture::bindTexture):
+ (WebCore::ManagedTexture::framebufferTexture2D):
+ * platform/graphics/chromium/ManagedTexture.h:
+ * platform/graphics/chromium/TextureManager.cpp:
+ (WebCore::TextureManager::memoryUseBytes):
+ (WebCore::TextureManager::deleteEvictedTextures):
+ (WebCore::TextureManager::evictAndDeleteAllTextures):
+ (WebCore::TextureManager::removeTexture):
+ (WebCore::TextureManager::allocateTexture):
+ (WebCore::TextureManager::requestTexture):
+ * platform/graphics/chromium/TextureManager.h:
+ (WebCore::TextureAllocator::~TextureAllocator):
+ * platform/graphics/chromium/TiledLayerChromium.cpp:
+ (WebCore::TiledLayerChromium::updateCompositorResources):
+ * platform/graphics/chromium/TiledLayerChromium.h:
+ * platform/graphics/chromium/TrackingTextureAllocator.cpp: Added.
+ (WebCore::TrackingTextureAllocator::TrackingTextureAllocator):
+ (WebCore::TrackingTextureAllocator::~TrackingTextureAllocator):
+ (WebCore::TrackingTextureAllocator::createTexture):
+ (WebCore::TrackingTextureAllocator::deleteTexture):
+ * platform/graphics/chromium/TrackingTextureAllocator.h: Copied from Source/WebCore/platform/graphics/chromium/ManagedTexture.h.
+ (WebCore::TrackingTextureAllocator::create):
+ (WebCore::TrackingTextureAllocator::currentMemoryUseBytes):
+ * platform/graphics/chromium/VideoLayerChromium.cpp:
+ (WebCore::VideoLayerChromium::updateCompositorResources):
+ (WebCore::VideoLayerChromium::updateTexture):
+ * platform/graphics/chromium/VideoLayerChromium.h:
+ * platform/graphics/chromium/WebGLLayerChromium.cpp:
+ (WebCore::WebGLLayerChromium::updateCompositorResources):
+ * platform/graphics/chromium/WebGLLayerChromium.h:
+ * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
+ (WebCore::CCHeadsUpDisplay::draw):
+ * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+ (WebCore::CCLayerTreeHost::~CCLayerTreeHost):
+ (WebCore::CCLayerTreeHost::deleteContentsTexturesOnCCThread):
+ (WebCore::CCLayerTreeHost::commitToOnCCThread):
+ (WebCore::CCLayerTreeHost::didRecreateGraphicsContext):
+ (WebCore::CCLayerTreeHost::updateCompositorResources):
+ * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+ * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
+ (WebCore::CCLayerTreeHostImpl::contentsTextureAllocator):
+ (WebCore::CCLayerTreeHostImpl::initializeLayerRenderer):
+ * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
+ * platform/graphics/chromium/cc/CCRenderSurface.cpp:
+ (WebCore::CCRenderSurface::drawSurface):
+ * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
+ (WebCore::CCSingleThreadProxy::setNeedsCommit):
+ (WebCore::CCSingleThreadProxy::stop):
+ (WebCore::CCSingleThreadProxy::recreateContextIfNeeded):
+ (WebCore::CCSingleThreadProxy::commitIfNeeded):
+ * platform/graphics/chromium/cc/CCThreadProxy.cpp:
+ (WebCore::CCThreadProxy::commitOnCCThread):
+ (WebCore::CCThreadProxy::layerTreeHostClosedOnCCThread):
+
2011-06-28 Robert Hogan <robert@webkit.org>
Reviewed by David Hyatt.
'platform/graphics/chromium/ShaderChromium.h',
'platform/graphics/chromium/SimpleFontDataChromiumWin.cpp',
'platform/graphics/chromium/SimpleFontDataLinux.cpp',
+ 'platform/graphics/chromium/TrackingTextureAllocator.cpp',
+ 'platform/graphics/chromium/TrackingTextureAllocator.h',
'platform/graphics/chromium/TextureManager.cpp',
'platform/graphics/chromium/TextureManager.h',
'platform/graphics/chromium/TiledLayerChromium.cpp',
&& (m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR));
}
-void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D*)
+void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D*, TextureAllocator*)
{
if (m_dirtyRect.isEmpty() || !drawsContent())
return;
static PassRefPtr<Canvas2DLayerChromium> create(GraphicsContext3D*);
virtual ~Canvas2DLayerChromium();
virtual bool drawsContent() const;
- virtual void updateCompositorResources(GraphicsContext3D*);
+ virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*);
void setTextureChanged();
m_texSubImage.setSubImageSize(tileSize);
}
- virtual void updateTextureRect(GraphicsContext3D* context, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
+ virtual void updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
- texture->bindTexture(context);
+ texture->bindTexture(context, allocator);
// Source rect should never go outside the image pixels, even if this
// is requested because the texture extends outside the image.
// These methods typically need to be overwritten by derived classes.
virtual bool drawsContent() const { return false; }
virtual void paintContentsIfDirty() { }
- virtual void updateCompositorResources(GraphicsContext3D*) { }
+ virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*) { }
virtual void setIsMask(bool) {}
virtual void unreserveContentsTexture() { }
virtual void bindContentsTexture() { }
#include "TextureManager.h"
#include "TreeSynchronizer.h"
#include "TraceEvent.h"
+#include "TrackingTextureAllocator.h"
#include "WebGLLayerChromium.h"
#include "cc/CCLayerImpl.h"
#include "cc/CCLayerTreeHostCommon.h"
: m_owner(owner)
, m_currentRenderSurface(0)
, m_offscreenFramebufferId(0)
- , m_contentsTextureMemoryUseBytes(0)
, m_context(context)
, m_defaultRenderSurface(0)
, m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f))
void LayerRendererChromium::releaseRenderSurfaceTextures()
{
- m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_context.get());
+ m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_renderSurfaceTextureAllocator.get());
}
void LayerRendererChromium::viewportChanged()
if (!rootLayer())
return;
- m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - m_contentsTextureMemoryUseBytes);
+ size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes();
+ m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - contentsMemoryUseBytes);
drawLayersInternal();
- if (TextureManager::reclaimLimitBytes() > m_contentsTextureMemoryUseBytes)
- m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - m_contentsTextureMemoryUseBytes);
+ if (TextureManager::reclaimLimitBytes() > contentsMemoryUseBytes)
+ m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - contentsMemoryUseBytes);
else
m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
- m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
+ m_renderSurfaceTextureManager->deleteEvictedTextures(m_renderSurfaceTextureAllocator.get());
if (settings().compositeOffscreen)
copyOffscreenTextureToDisplay();
GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
}
-// FIXME: This method should eventually be replaced by a proper texture manager.
-unsigned LayerRendererChromium::createLayerTexture()
-{
- unsigned textureId = 0;
- GLC(m_context.get(), textureId = m_context->createTexture());
- GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
- // Do basic linear filtering on resize.
- GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
- GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
- // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
- GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
- GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
- return textureId;
-}
-
-void LayerRendererChromium::deleteLayerTexture(unsigned textureId)
-{
- if (!textureId)
- return;
-
- GLC(m_context.get(), m_context->deleteTexture(textureId));
-}
-
// Returns true if any part of the layer falls within the visibleRect
bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const TransformationMatrix& matrix, const IntRect& visibleRect)
{
if (!renderSurface->prepareContentsTexture(this))
return false;
- renderSurface->contentsTexture()->framebufferTexture2D(m_context.get());
+ renderSurface->contentsTexture()->framebufferTexture2D(m_context.get(), m_renderSurfaceTextureAllocator.get());
#if !defined ( NDEBUG )
if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
GLC(m_context.get(), m_context->flush());
m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_capabilities.maxTextureSize);
+ m_contentsTextureAllocator = TrackingTextureAllocator::create(m_context.get());
+ m_renderSurfaceTextureAllocator = TrackingTextureAllocator::create(m_context.get());
return true;
}
if (m_offscreenFramebufferId)
GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId));
- ASSERT(!m_contentsTextureMemoryUseBytes);
releaseRenderSurfaceTextures();
}
#include "FloatQuad.h"
#include "IntRect.h"
#include "LayerChromium.h"
+#include "TrackingTextureAllocator.h"
#include "VideoLayerChromium.h"
#include "cc/CCCanvasLayerImpl.h"
#include "cc/CCHeadsUpDisplay.h"
class GeometryBinding;
class GraphicsContext3D;
class NonCompositedContentHost;
+class TrackingTextureAllocator;
// Class that handles drawing of composited render layers using GL.
class LayerRendererChromium {
// Must be called in order to allow the LayerRendererChromium to destruct
void close();
- virtual ~LayerRendererChromium();
+ ~LayerRendererChromium();
const CCSettings& settings() const { return m_owner->settings(); }
const LayerRendererCapabilities& capabilities() const { return m_capabilities; }
void setZoomAnimatorTransform(const TransformationMatrix& t) { m_zoomAnimatorTransform = t; }
- unsigned createLayerTexture();
- void deleteLayerTexture(unsigned);
-
static void debugGLCall(GraphicsContext3D*, const char* command, const char* file, int line);
const TransformationMatrix& projectionMatrix() const { return m_projectionMatrix; }
void getFramebufferPixels(void *pixels, const IntRect& rect);
TextureManager* renderSurfaceTextureManager() const { return m_renderSurfaceTextureManager.get(); }
+ TextureAllocator* renderSurfaceTextureAllocator() const { return m_renderSurfaceTextureAllocator.get(); }
+ TextureAllocator* contentsTextureAllocator() const { return m_contentsTextureAllocator.get(); }
CCHeadsUpDisplay* headsUpDisplay() { return m_headsUpDisplay.get(); }
typedef Vector<RefPtr<CCLayerImpl> > CCLayerList;
- void setContentsTextureMemoryUseBytes(size_t contentsTextureMemoryUseBytes) { m_contentsTextureMemoryUseBytes = contentsTextureMemoryUseBytes; }
-
static void toGLMatrix(float*, const TransformationMatrix&);
void drawTexturedQuad(const TransformationMatrix& layerMatrix,
float width, float height, float opacity, const FloatQuad&,
OwnPtr<CCVideoLayerImpl::RGBAProgram> m_videoLayerRGBAProgram;
OwnPtr<CCVideoLayerImpl::YUVProgram> m_videoLayerYUVProgram;
- size_t m_contentsTextureMemoryUseBytes;
OwnPtr<TextureManager> m_renderSurfaceTextureManager;
+ OwnPtr<TrackingTextureAllocator> m_contentsTextureAllocator;
+ OwnPtr<TrackingTextureAllocator> m_renderSurfaceTextureAllocator;
OwnPtr<CCHeadsUpDisplay> m_headsUpDisplay;
class IntRect;
class IntSize;
class ManagedTexture;
+class TextureAllocator;
class LayerTextureUpdater : public RefCounted<LayerTextureUpdater> {
public:
// If the format is TexelFormatBGRA, vec4.x is blue and vec4.z is red.
virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) = 0;
virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels) = 0;
- virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0;
+ virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0;
};
} // namespace WebCore
paintContents(*canvasPainter.context(), contentRect);
}
-void LayerTextureUpdaterBitmap::updateTextureRect(GraphicsContext3D* context, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
+void LayerTextureUpdaterBitmap::updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
PlatformCanvas::AutoLocker locker(&m_canvas);
- texture->bindTexture(context);
+ texture->bindTexture(context, allocator);
m_texSubImage.upload(locker.pixels(), contentRect(), sourceRect, destRect, texture->format(), context);
}
m_picture.endRecording();
}
-void LayerTextureUpdaterSkPicture::updateTextureRect(GraphicsContext3D* compositorContext, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
+void LayerTextureUpdaterSkPicture::updateTextureRect(GraphicsContext3D* compositorContext, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
ASSERT(!m_context || m_context == compositorContext);
m_context = compositorContext;
// Bind texture.
context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
- texture->framebufferTexture2D(context());
+ texture->framebufferTexture2D(context(), allocator);
ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE);
// Make sure SKIA uses the correct GL context.
virtual Orientation orientation() { return LayerTextureUpdater::BottomUpOrientation; }
virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels);
- virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
+ virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
private:
LayerTextureUpdaterBitmap(PassOwnPtr<LayerPainterChromium>, bool useMapTexSubImage);
virtual Orientation orientation() { return LayerTextureUpdater::TopDownOrientation; }
virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels);
- virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
+ virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
private:
explicit LayerTextureUpdaterSkPicture(PassOwnPtr<LayerPainterChromium>);
m_textureManager->unprotectTexture(m_token);
}
-void ManagedTexture::bindTexture(GraphicsContext3D* context)
+void ManagedTexture::bindTexture(GraphicsContext3D* context, TextureAllocator* allocator)
{
ASSERT(m_textureManager->hasTexture(m_token));
if (!m_textureId)
- m_textureId = m_textureManager->allocateTexture(context, m_token);
+ m_textureId = m_textureManager->allocateTexture(allocator, m_token);
context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
}
-void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context)
+void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context, TextureAllocator* allocator)
{
ASSERT(m_textureManager->hasTexture(m_token));
if (!m_textureId)
- m_textureId = m_textureManager->allocateTexture(context, m_token);
+ m_textureId = m_textureManager->allocateTexture(allocator, m_token);
context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_textureId, 0);
}
namespace WebCore {
class GraphicsContext3D;
-class TextureManager;
class ManagedTexture {
WTF_MAKE_NONCOPYABLE(ManagedTexture);
return m_textureManager->isProtected(m_token);
}
- void bindTexture(GraphicsContext3D*);
- void framebufferTexture2D(GraphicsContext3D*);
+ void bindTexture(GraphicsContext3D*, TextureAllocator*);
+ void framebufferTexture2D(GraphicsContext3D*, TextureAllocator*);
IntSize size() const { return m_size; }
unsigned format() const { return m_format; }
namespace WebCore {
-static size_t memoryUseBytes(IntSize size, GC3Denum textureFormat)
-{
- // FIXME: This assumes all textures are 1 byte/component.
- const GC3Denum type = GraphicsContext3D::UNSIGNED_BYTE;
- unsigned int componentsPerPixel = 4;
- unsigned int bytesPerComponent = 1;
- if (!GraphicsContext3D::computeFormatAndTypeParameters(textureFormat, type, &componentsPerPixel, &bytesPerComponent))
- ASSERT_NOT_REACHED();
-
- return size.width() * size.height() * componentsPerPixel * bytesPerComponent;
-}
-
size_t TextureManager::highLimitBytes()
{
return 128 * 1024 * 1024;
return 3 * 1024 * 1024;
}
+size_t TextureManager::memoryUseBytes(const IntSize& size, GC3Denum textureFormat)
+{
+ // FIXME: This assumes all textures are 1 byte/component.
+ const GC3Denum type = GraphicsContext3D::UNSIGNED_BYTE;
+ unsigned int componentsPerPixel = 4;
+ unsigned int bytesPerComponent = 1;
+ if (!GraphicsContext3D::computeFormatAndTypeParameters(textureFormat, type, &componentsPerPixel, &bytesPerComponent))
+ ASSERT_NOT_REACHED();
+
+ return size.width() * size.height() * componentsPerPixel * bytesPerComponent;
+}
+
+
TextureManager::TextureManager(size_t memoryLimitBytes, int maxTextureSize)
: m_memoryLimitBytes(memoryLimitBytes)
, m_memoryUseBytes(0)
m_textureLRUSet.add(token);
}
-void TextureManager::deleteEvictedTextures(GraphicsContext3D* context)
+void TextureManager::deleteEvictedTextures(TextureAllocator* allocator)
{
- if (context) {
+ if (allocator) {
for (size_t i = 0; i < m_evictedTextures.size(); ++i) {
if (m_evictedTextures[i].textureId) {
#ifndef NDEBUG
- ASSERT(m_evictedTextures[i].allocatingContext == context);
+ ASSERT(m_evictedTextures[i].allocator == allocator);
#endif
- GLC(context, context->deleteTexture(m_evictedTextures[i].textureId));
+ allocator->deleteTexture(m_evictedTextures[i].textureId, m_evictedTextures[i].size, m_evictedTextures[i].format);
}
}
}
m_evictedTextures.clear();
}
-void TextureManager::evictAndDeleteAllTextures(GraphicsContext3D* context)
+void TextureManager::evictAndDeleteAllTextures(TextureAllocator* allocator)
{
unprotectAllTextures();
reduceMemoryToLimit(0);
- deleteEvictedTextures(context);
+ deleteEvictedTextures(allocator);
}
void TextureManager::removeTexture(TextureToken token, TextureInfo info)
m_textureLRUSet.remove(token);
EvictionEntry entry;
entry.textureId = info.textureId;
+ entry.size = info.size;
+ entry.format = info.format;
#ifndef NDEBUG
- entry.allocatingContext = info.allocatingContext;
+ entry.allocator = info.allocator;
#endif
m_evictedTextures.append(entry);
}
-unsigned TextureManager::allocateTexture(GraphicsContext3D* context, TextureToken token)
+unsigned TextureManager::allocateTexture(TextureAllocator* allocator, TextureToken token)
{
TextureMap::iterator it = m_textures.find(token);
ASSERT(it != m_textures.end());
TextureInfo* info = &it.get()->second;
ASSERT(info->isProtected);
- unsigned textureId;
- GLC(context, textureId = context->createTexture());
- GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
- // Do basic linear filtering on resize.
- GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
- GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
- // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
- GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
- GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
- GLC(context, context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, info->format, info->size.width(), info->size.height(), 0, info->format, GraphicsContext3D::UNSIGNED_BYTE));
+ unsigned textureId = allocator->createTexture(info->size, info->format);
info->textureId = textureId;
#ifndef NDEBUG
- info->allocatingContext = context;
+ info->allocator = allocator;
#endif
return textureId;
}
info.textureId = 0;
info.isProtected = true;
#ifndef NDEBUG
- info.allocatingContext = 0;
+ info.allocator = 0;
#endif
addTexture(token, info);
return true;
typedef int TextureToken;
+class TextureAllocator {
+public:
+ virtual unsigned createTexture(const IntSize&, GC3Denum format) = 0;
+ virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum) = 0;
+
+protected:
+ virtual ~TextureAllocator() { }
+};
+
class TextureManager {
WTF_MAKE_NONCOPYABLE(TextureManager);
public:
// The maximum texture memory usage when asked to release textures.
static size_t lowLimitBytes();
+ static size_t memoryUseBytes(const IntSize&, GC3Denum format);
+
void setMemoryLimitBytes(size_t);
TextureToken getToken();
void unprotectAllTextures();
bool isProtected(TextureToken);
- unsigned allocateTexture(GraphicsContext3D*, TextureToken);
- void deleteEvictedTextures(GraphicsContext3D*);
+ unsigned allocateTexture(TextureAllocator*, TextureToken);
+ void deleteEvictedTextures(TextureAllocator*);
- void evictAndDeleteAllTextures(GraphicsContext3D*);
+ void evictAndDeleteAllTextures(TextureAllocator*);
void reduceMemoryToLimit(size_t);
size_t currentMemoryUseBytes() const { return m_memoryUseBytes; }
unsigned textureId;
bool isProtected;
#ifndef NDEBUG
- GraphicsContext3D* allocatingContext;
+ TextureAllocator* allocator;
#endif
};
struct EvictionEntry {
unsigned textureId;
+ IntSize size;
+ GC3Denum format;
#ifndef NDEBUG
- GraphicsContext3D* allocatingContext;
+ TextureAllocator* allocator;
#endif
};
isNonCompositedContent() ? CCLayerTilingData::NoBorderTexels : CCLayerTilingData::HasBorderTexels);
}
-void TiledLayerChromium::updateCompositorResources(GraphicsContext3D* context)
+void TiledLayerChromium::updateCompositorResources(GraphicsContext3D* context, TextureAllocator* allocator)
{
// Painting could cause compositing to get turned off, which may cause the tiler to become invalidated mid-update.
if (m_skipsDraw || m_updateRect.isEmpty() || !m_tiler->numTiles())
if (paintOffset.y() + destRect.height() > m_paintRect.height())
CRASH();
- tile->texture()->bindTexture(context);
+ tile->texture()->bindTexture(context, allocator);
const GC3Dint filter = m_tiler->hasBorderTexels() ? GraphicsContext3D::LINEAR : GraphicsContext3D::NEAREST;
GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, filter));
GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, filter));
GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0));
- textureUpdater()->updateTextureRect(context, tile->texture(), sourceRect, destRect);
+ textureUpdater()->updateTextureRect(context, allocator, tile->texture(), sourceRect, destRect);
tile->clearDirty();
}
}
virtual ~TiledLayerChromium();
- virtual void updateCompositorResources(GraphicsContext3D*);
+ virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*);
virtual void setIsMask(bool);
virtual void pushPropertiesTo(CCLayerImpl*);
--- /dev/null
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "TrackingTextureAllocator.h"
+
+#include "IntRect.h"
+#include "LayerRendererChromium.h" // For the GLC() macro
+
+namespace WebCore {
+
+TrackingTextureAllocator::TrackingTextureAllocator(PassRefPtr<GraphicsContext3D> context)
+ : m_context(context)
+ , m_currentMemoryUseBytes(0)
+{
+}
+
+TrackingTextureAllocator::~TrackingTextureAllocator()
+{
+ ASSERT(!m_currentMemoryUseBytes);
+}
+
+unsigned TrackingTextureAllocator::createTexture(const IntSize& size, GC3Denum format)
+{
+ m_currentMemoryUseBytes += TextureManager::memoryUseBytes(size, format);
+
+ unsigned textureId = 0;
+ GLC(m_context.get(), textureId = m_context->createTexture());
+ GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
+ // Do basic linear filtering on resize.
+ GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
+ GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
+ // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
+ GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
+ GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
+ GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE));
+ return textureId;
+}
+
+void TrackingTextureAllocator::deleteTexture(unsigned textureId, const IntSize& size, GC3Denum format)
+{
+ m_currentMemoryUseBytes -= TextureManager::memoryUseBytes(size, format);
+ GLC(m_context.get(), m_context->deleteTexture(textureId));
+}
+
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TrackingTextureAllocator_h
+#define TrackingTextureAllocator_h
+
+#include "GraphicsContext3D.h"
+#include "TextureManager.h"
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class TrackingTextureAllocator : public TextureAllocator {
+ WTF_MAKE_NONCOPYABLE(TrackingTextureAllocator);
+public:
+ static PassOwnPtr<TrackingTextureAllocator> create(PassRefPtr<GraphicsContext3D> context)
+ {
+ return adoptPtr(new TrackingTextureAllocator(context));
+ }
+ virtual ~TrackingTextureAllocator();
+
+ virtual unsigned createTexture(const IntSize&, GC3Denum format);
+ virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum format);
+
+ size_t currentMemoryUseBytes() const { return m_currentMemoryUseBytes; }
+
+protected:
+ explicit TrackingTextureAllocator(PassRefPtr<GraphicsContext3D>);
+
+ RefPtr<GraphicsContext3D> m_context;
+ size_t m_currentMemoryUseBytes;
+};
+
+}
+
+#endif
releaseCurrentFrame();
}
-void VideoLayerChromium::updateCompositorResources(GraphicsContext3D* context)
+void VideoLayerChromium::updateCompositorResources(GraphicsContext3D* context, TextureAllocator* allocator)
{
if (!m_delegate)
return;
Texture& texture = m_textures[plane];
ASSERT(texture.m_texture);
ASSERT(frame->requiredTextureSize(plane) == texture.m_texture->size());
- updateTexture(context, texture, frame->data(plane));
+ updateTexture(context, allocator, texture, frame->data(plane));
}
m_planes = frame->planes();
return IntSize(visibleWidth, visibleHeight);
}
-void VideoLayerChromium::updateTexture(GraphicsContext3D* context, Texture& texture, const void* data) const
+void VideoLayerChromium::updateTexture(GraphicsContext3D* context, TextureAllocator* allocator, Texture& texture, const void* data) const
{
ASSERT(context);
ASSERT(texture.m_texture);
- texture.m_texture->bindTexture(context);
+ texture.m_texture->bindTexture(context, allocator);
GC3Denum format = texture.m_texture->format();
IntSize dimensions = texture.m_texture->size();
virtual PassRefPtr<CCLayerImpl> createCCLayerImpl();
- virtual void updateCompositorResources(GraphicsContext3D*);
+ virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*);
virtual bool drawsContent() const { return true; }
// This function is called by VideoFrameProvider. When this method is called
static IntSize computeVisibleSize(const VideoFrameChromium*, unsigned plane);
bool texturesValid();
bool reserveTextures(const VideoFrameChromium*, GC3Denum textureFormat);
- void updateTexture(GraphicsContext3D*, Texture&, const void*) const;
+ void updateTexture(GraphicsContext3D*, TextureAllocator*, Texture&, const void*) const;
void resetFrameParameters();
return (m_context && m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
}
-void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D* rendererContext)
+void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D* rendererContext, TextureAllocator*)
{
if (!drawsContent())
return;
virtual ~WebGLLayerChromium();
virtual bool drawsContent() const;
- virtual void updateCompositorResources(GraphicsContext3D*);
+ virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*);
void setTextureUpdated();
bool paintRenderedResultsToCanvas(ImageBuffer*);
{
PlatformCanvas::AutoLocker locker(&canvas);
- m_hudTexture->bindTexture(context);
+ m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator());
bool uploadedViaMap = false;
if (m_useMapSubForUploads) {
Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(context->getExtensions());
const Program* program = m_layerRenderer->headsUpDisplayProgram();
ASSERT(program && program->initialized());
GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
- m_hudTexture->bindTexture(context);
+ m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator());
GLC(context, context->useProgram(program->program()));
GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
m_proxy->stop();
m_proxy.clear();
clearPendingUpdate();
- ASSERT(!m_contentsTextureManager || !m_contentsTextureManager->currentMemoryUseBytes());
- m_contentsTextureManager.clear();
}
-void CCLayerTreeHost::deleteContentsTextures(GraphicsContext3D* context)
+void CCLayerTreeHost::deleteContentsTexturesOnCCThread(TextureAllocator* allocator)
{
ASSERT(CCProxy::isImplThread());
if (m_contentsTextureManager)
- m_contentsTextureManager->evictAndDeleteAllTextures(context);
+ m_contentsTextureManager->evictAndDeleteAllTextures(allocator);
}
void CCLayerTreeHost::animateAndLayout(double frameBeginTime)
// code that is logically a main thread operation, e.g. deletion of a LayerChromium,
// should be delayed until the CCLayerTreeHost::commitComplete, which will run
// after the commit, but on the main thread.
-void CCLayerTreeHost::commitTo(CCLayerTreeHostImpl* hostImpl)
+void CCLayerTreeHost::commitToOnCCThread(CCLayerTreeHostImpl* hostImpl)
{
ASSERT(CCProxy::isImplThread());
TRACE_EVENT("CCLayerTreeHost::commitTo", this, 0);
hostImpl->setSourceFrameNumber(frameNumber());
contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes());
- contentsTextureManager()->deleteEvictedTextures(hostImpl->context());
+ contentsTextureManager()->deleteEvictedTextures(hostImpl->contentsTextureAllocator());
- updateCompositorResources(m_updateList, hostImpl->context());
+ updateCompositorResources(m_updateList, hostImpl->context(), hostImpl->contentsTextureAllocator());
hostImpl->setVisible(m_visible);
hostImpl->setZoomAnimatorTransform(m_zoomAnimatorTransform);
hostImpl->setViewport(viewportSize());
- hostImpl->layerRenderer()->setContentsTextureMemoryUseBytes(m_contentsTextureManager->currentMemoryUseBytes());
-
// Synchronize trees, if one exists at all...
if (rootLayer())
hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostImpl->rootLayer()));
void CCLayerTreeHost::didRecreateGraphicsContext(bool success)
{
- m_contentsTextureManager->evictAndDeleteAllTextures(0);
-
if (rootLayer())
rootLayer()->cleanupResourcesRecursive();
m_client->didRecreateGraphicsContext(success);
}
}
-void CCLayerTreeHost::updateCompositorResources(const LayerList& renderSurfaceLayerList, GraphicsContext3D* context)
+void CCLayerTreeHost::updateCompositorResources(const LayerList& renderSurfaceLayerList, GraphicsContext3D* context, TextureAllocator* allocator)
{
for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
LayerChromium* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
if (layer->renderSurface() && layer->renderSurface() != renderSurface)
continue;
- updateCompositorResources(layer, context);
+ updateCompositorResources(layer, context, allocator);
}
}
}
-void CCLayerTreeHost::updateCompositorResources(LayerChromium* layer, GraphicsContext3D* context)
+void CCLayerTreeHost::updateCompositorResources(LayerChromium* layer, GraphicsContext3D* context, TextureAllocator* allocator)
{
if (layer->bounds().isEmpty())
return;
return;
if (layer->maskLayer())
- updateCompositorResources(layer->maskLayer(), context);
+ updateCompositorResources(layer->maskLayer(), context, allocator);
if (layer->replicaLayer())
- updateCompositorResources(layer->replicaLayer(), context);
+ updateCompositorResources(layer->replicaLayer(), context, allocator);
if (layer->drawsContent())
- layer->updateCompositorResources(context);
+ layer->updateCompositorResources(context, allocator);
}
void CCLayerTreeHost::clearPendingUpdate()
--- /dev/null
+--- Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
++++ Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
+@@ -130,14 +140,12 @@
+ contentsTextureManager()->deleteEvictedTextures(hostImpl->context());
+
+ updateCompositorResources(m_updateList, hostImpl->context());
+- clearPendingUpdate();
+
+ hostImpl->setVisible(m_visible);
+ hostImpl->setZoomAnimatorScale(m_zoomAnimatorScale);
+ hostImpl->setViewport(viewportSize());
+
+ hostImpl->layerRenderer()->setContentsTextureMemoryUseBytes(m_contentsTextureManager->currentMemoryUseBytes());
+- m_contentsTextureManager->unprotectAllTextures();
+
+ // Synchronize trees, if one exists at all...
+ if (rootLayer())
class GraphicsContext3D;
class LayerChromium;
class LayerPainterChromium;
+class TextureAllocator;
class TextureManager;
class CCLayerTreeHostClient {
// CCLayerTreeHost interface to CCProxy.
void animateAndLayout(double frameBeginTime);
void commitComplete();
- void commitTo(CCLayerTreeHostImpl*);
+ void commitToOnCCThread(CCLayerTreeHostImpl*);
PassOwnPtr<CCThread> createCompositorThread();
PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
#if !USE(THREADED_COMPOSITING)
void scheduleComposite();
#endif
+ void deleteContentsTexturesOnCCThread(TextureAllocator*);
// CCLayerTreeHost interface to WebView.
bool animating() const { return m_animating; }
void updateLayers();
- void deleteContentsTextures(GraphicsContext3D*);
-
protected:
CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
bool initialize();
void paintLayerContents(const LayerList&);
void updateLayers(LayerChromium*);
- void updateCompositorResources(const LayerList&, GraphicsContext3D*);
- void updateCompositorResources(LayerChromium*, GraphicsContext3D*);
+ void updateCompositorResources(const LayerList&, GraphicsContext3D*, TextureAllocator*);
+ void updateCompositorResources(LayerChromium*, GraphicsContext3D*, TextureAllocator*);
void clearPendingUpdate();
bool m_animating;
return m_layerRenderer->capabilities();
}
+TextureAllocator* CCLayerTreeHostImpl::contentsTextureAllocator() const
+{
+ return m_layerRenderer->contentsTextureAllocator();
+}
+
void CCLayerTreeHostImpl::present()
{
ASSERT(m_layerRenderer && !isContextLost());
layerRenderer = LayerRendererChromium::create(this, context);
}
- // If we had a previous layer renderer, then its context must have been lost along with all of its resources.
- // Let the old layer renderer known its resources are gone.
- if (m_layerRenderer) {
- m_layerRenderer->setContentsTextureMemoryUseBytes(0);
+ if (m_layerRenderer)
m_layerRenderer->close();
- }
m_layerRenderer = layerRenderer.release();
return m_layerRenderer;
class CCCompletionEvent;
class CCLayerImpl;
class LayerRendererChromium;
+class TextureAllocator;
struct LayerRendererCapabilities;
class TransformationMatrix;
bool isContextLost();
LayerRendererChromium* layerRenderer() { return m_layerRenderer.get(); }
const LayerRendererCapabilities& layerRendererCapabilities() const;
+ TextureAllocator* contentsTextureAllocator() const;
void present();
GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
GLC(context3D, context3D->uniform1i(program->fragmentShader().samplerLocation(), 0));
- m_contentsTexture->bindTexture(context3D);
+ m_contentsTexture->bindTexture(context3D, layerRenderer->renderSurfaceTextureAllocator());
if (shaderMaskSamplerLocation != -1) {
GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE1));
{
ScopedSetImplThread impl;
m_layerTreeHostImpl->beginCommit();
- m_layerTreeHost->commitTo(m_layerTreeHostImpl.get());
+ m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get());
m_layerTreeHostImpl->commitComplete();
}
m_layerTreeHost->commitComplete();
ASSERT(CCProxy::isMainThread());
{
ScopedSetImplThread impl;
- m_layerTreeHost->deleteContentsTextures(m_layerTreeHostImpl->context());
+ m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator());
m_layerTreeHostImpl.clear();
}
m_layerTreeHost = 0;
bool ok;
{
ScopedSetImplThread impl;
+ m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator());
ok = m_layerTreeHostImpl->initializeLayerRenderer(context);
if (ok)
m_layerRendererCapabilitiesForMainThread = m_layerTreeHostImpl->layerRendererCapabilities();
{
ScopedSetImplThread impl;
m_layerTreeHostImpl->beginCommit();
- m_layerTreeHost->commitTo(m_layerTreeHostImpl.get());
+ m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get());
m_layerTreeHostImpl->commitComplete();
}
m_layerTreeHost->commitComplete();
return;
}
m_layerTreeHostImpl->beginCommit();
- m_layerTreeHost->commitTo(m_layerTreeHostImpl.get());
+ m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get());
m_layerTreeHostImpl->commitComplete();
completion->signal();
{
TRACE_EVENT("CCThreadProxy::layerTreeHostClosedOnCCThread", this, 0);
ASSERT(isImplThread());
- m_layerTreeHost->deleteContentsTextures(m_layerTreeHostImpl->context());
+ m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator());
m_layerTreeHostImpl.clear();
completion->signal();
}