Changeset 96141 in webkit
- Timestamp:
- Sep 27, 2011 12:41:24 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 29 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96139 r96141 1 2011-09-27 James Robinson <jamesr@chromium.org> 2 3 [chromium] LayerRenderChromium asserts about leaking textures. 4 https://bugs.webkit.org/show_bug.cgi?id=68190 5 6 Reviewed by Kenneth Russell. 7 8 This introduces an interface TextureAllocator that the TextureManager uses to allocate/deallocate textures. 9 This means that TextureManager does not need to depend directly on GraphicsContext3D, other than for the format 10 enum type, making it more testable. It also allows us to track the allocations by subclassing TextureAllocator 11 to make sure we aren't leaking any textures. 12 13 * WebCore.gypi: 14 * platform/graphics/chromium/Canvas2DLayerChromium.cpp: 15 (WebCore::Canvas2DLayerChromium::updateCompositorResources): 16 * platform/graphics/chromium/Canvas2DLayerChromium.h: 17 * platform/graphics/chromium/ImageLayerChromium.cpp: 18 (WebCore::ImageLayerTextureUpdater::updateTextureRect): 19 * platform/graphics/chromium/LayerChromium.h: 20 (WebCore::LayerChromium::updateCompositorResources): 21 * platform/graphics/chromium/LayerRendererChromium.cpp: 22 (WebCore::LayerRendererChromium::LayerRendererChromium): 23 (WebCore::LayerRendererChromium::releaseRenderSurfaceTextures): 24 (WebCore::LayerRendererChromium::drawLayers): 25 (WebCore::LayerRendererChromium::useRenderSurface): 26 (WebCore::LayerRendererChromium::initializeSharedObjects): 27 (WebCore::LayerRendererChromium::cleanupSharedObjects): 28 * platform/graphics/chromium/LayerRendererChromium.h: 29 (WebCore::LayerRendererChromium::renderSurfaceTextureAllocator): 30 (WebCore::LayerRendererChromium::contentsTextureAllocator): 31 * platform/graphics/chromium/LayerTextureUpdater.h: 32 * platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp: 33 (WebCore::LayerTextureUpdaterBitmap::updateTextureRect): 34 (WebCore::LayerTextureUpdaterSkPicture::updateTextureRect): 35 * platform/graphics/chromium/LayerTextureUpdaterCanvas.h: 36 * platform/graphics/chromium/ManagedTexture.cpp: 37 (WebCore::ManagedTexture::bindTexture): 38 (WebCore::ManagedTexture::framebufferTexture2D): 39 * platform/graphics/chromium/ManagedTexture.h: 40 * platform/graphics/chromium/TextureManager.cpp: 41 (WebCore::TextureManager::memoryUseBytes): 42 (WebCore::TextureManager::deleteEvictedTextures): 43 (WebCore::TextureManager::evictAndDeleteAllTextures): 44 (WebCore::TextureManager::removeTexture): 45 (WebCore::TextureManager::allocateTexture): 46 (WebCore::TextureManager::requestTexture): 47 * platform/graphics/chromium/TextureManager.h: 48 (WebCore::TextureAllocator::~TextureAllocator): 49 * platform/graphics/chromium/TiledLayerChromium.cpp: 50 (WebCore::TiledLayerChromium::updateCompositorResources): 51 * platform/graphics/chromium/TiledLayerChromium.h: 52 * platform/graphics/chromium/TrackingTextureAllocator.cpp: Added. 53 (WebCore::TrackingTextureAllocator::TrackingTextureAllocator): 54 (WebCore::TrackingTextureAllocator::~TrackingTextureAllocator): 55 (WebCore::TrackingTextureAllocator::createTexture): 56 (WebCore::TrackingTextureAllocator::deleteTexture): 57 * platform/graphics/chromium/TrackingTextureAllocator.h: Copied from Source/WebCore/platform/graphics/chromium/ManagedTexture.h. 58 (WebCore::TrackingTextureAllocator::create): 59 (WebCore::TrackingTextureAllocator::currentMemoryUseBytes): 60 * platform/graphics/chromium/VideoLayerChromium.cpp: 61 (WebCore::VideoLayerChromium::updateCompositorResources): 62 (WebCore::VideoLayerChromium::updateTexture): 63 * platform/graphics/chromium/VideoLayerChromium.h: 64 * platform/graphics/chromium/WebGLLayerChromium.cpp: 65 (WebCore::WebGLLayerChromium::updateCompositorResources): 66 * platform/graphics/chromium/WebGLLayerChromium.h: 67 * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp: 68 (WebCore::CCHeadsUpDisplay::draw): 69 * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: 70 (WebCore::CCLayerTreeHost::~CCLayerTreeHost): 71 (WebCore::CCLayerTreeHost::deleteContentsTexturesOnCCThread): 72 (WebCore::CCLayerTreeHost::commitToOnCCThread): 73 (WebCore::CCLayerTreeHost::didRecreateGraphicsContext): 74 (WebCore::CCLayerTreeHost::updateCompositorResources): 75 * platform/graphics/chromium/cc/CCLayerTreeHost.h: 76 * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp: 77 (WebCore::CCLayerTreeHostImpl::contentsTextureAllocator): 78 (WebCore::CCLayerTreeHostImpl::initializeLayerRenderer): 79 * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h: 80 * platform/graphics/chromium/cc/CCRenderSurface.cpp: 81 (WebCore::CCRenderSurface::drawSurface): 82 * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp: 83 (WebCore::CCSingleThreadProxy::setNeedsCommit): 84 (WebCore::CCSingleThreadProxy::stop): 85 (WebCore::CCSingleThreadProxy::recreateContextIfNeeded): 86 (WebCore::CCSingleThreadProxy::commitIfNeeded): 87 * platform/graphics/chromium/cc/CCThreadProxy.cpp: 88 (WebCore::CCThreadProxy::commitOnCCThread): 89 (WebCore::CCThreadProxy::layerTreeHostClosedOnCCThread): 90 1 91 2011-06-28 Robert Hogan <robert@webkit.org> 2 92 -
trunk/Source/WebCore/WebCore.gypi
r96073 r96141 3466 3466 'platform/graphics/chromium/SimpleFontDataChromiumWin.cpp', 3467 3467 'platform/graphics/chromium/SimpleFontDataLinux.cpp', 3468 'platform/graphics/chromium/TrackingTextureAllocator.cpp', 3469 'platform/graphics/chromium/TrackingTextureAllocator.h', 3468 3470 'platform/graphics/chromium/TextureManager.cpp', 3469 3471 'platform/graphics/chromium/TextureManager.h', -
trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp
r95901 r96141 65 65 } 66 66 67 void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D* )67 void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D*, TextureAllocator*) 68 68 { 69 69 if (m_dirtyRect.isEmpty() || !drawsContent()) -
trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h
r95901 r96141 47 47 virtual ~Canvas2DLayerChromium(); 48 48 virtual bool drawsContent() const; 49 virtual void updateCompositorResources(GraphicsContext3D* );49 virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*); 50 50 51 51 void setTextureChanged(); -
trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
r95901 r96141 67 67 } 68 68 69 virtual void updateTextureRect(GraphicsContext3D* context, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)69 virtual void updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect) 70 70 { 71 texture->bindTexture(context );71 texture->bindTexture(context, allocator); 72 72 73 73 // Source rect should never go outside the image pixels, even if this -
trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h
r95901 r96141 153 153 virtual bool drawsContent() const { return false; } 154 154 virtual void paintContentsIfDirty() { } 155 virtual void updateCompositorResources(GraphicsContext3D* ) { }155 virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*) { } 156 156 virtual void setIsMask(bool) {} 157 157 virtual void unreserveContentsTexture() { } -
trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
r96066 r96141 52 52 #include "TreeSynchronizer.h" 53 53 #include "TraceEvent.h" 54 #include "TrackingTextureAllocator.h" 54 55 #include "WebGLLayerChromium.h" 55 56 #include "cc/CCLayerImpl.h" … … 148 149 , m_currentRenderSurface(0) 149 150 , m_offscreenFramebufferId(0) 150 , m_contentsTextureMemoryUseBytes(0)151 151 , m_context(context) 152 152 , m_defaultRenderSurface(0) … … 215 215 void LayerRendererChromium::releaseRenderSurfaceTextures() 216 216 { 217 m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_ context.get());217 m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_renderSurfaceTextureAllocator.get()); 218 218 } 219 219 … … 238 238 return; 239 239 240 m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - m_contentsTextureMemoryUseBytes); 240 size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes(); 241 m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - contentsMemoryUseBytes); 241 242 drawLayersInternal(); 242 243 243 if (TextureManager::reclaimLimitBytes() > m_contentsTextureMemoryUseBytes)244 m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - m_contentsTextureMemoryUseBytes);244 if (TextureManager::reclaimLimitBytes() > contentsMemoryUseBytes) 245 m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - contentsMemoryUseBytes); 245 246 else 246 247 m_renderSurfaceTextureManager->reduceMemoryToLimit(0); 247 m_renderSurfaceTextureManager->deleteEvictedTextures(m_ context.get());248 m_renderSurfaceTextureManager->deleteEvictedTextures(m_renderSurfaceTextureAllocator.get()); 248 249 249 250 if (settings().compositeOffscreen) … … 437 438 } 438 439 439 // FIXME: This method should eventually be replaced by a proper texture manager.440 unsigned LayerRendererChromium::createLayerTexture()441 {442 unsigned textureId = 0;443 GLC(m_context.get(), textureId = m_context->createTexture());444 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));445 // Do basic linear filtering on resize.446 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));447 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));448 // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.449 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));450 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));451 return textureId;452 }453 454 void LayerRendererChromium::deleteLayerTexture(unsigned textureId)455 {456 if (!textureId)457 return;458 459 GLC(m_context.get(), m_context->deleteTexture(textureId));460 }461 462 440 // Returns true if any part of the layer falls within the visibleRect 463 441 bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const TransformationMatrix& matrix, const IntRect& visibleRect) … … 517 495 return false; 518 496 519 renderSurface->contentsTexture()->framebufferTexture2D(m_context.get() );497 renderSurface->contentsTexture()->framebufferTexture2D(m_context.get(), m_renderSurfaceTextureAllocator.get()); 520 498 521 499 #if !defined ( NDEBUG ) … … 636 614 637 615 m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_capabilities.maxTextureSize); 616 m_contentsTextureAllocator = TrackingTextureAllocator::create(m_context.get()); 617 m_renderSurfaceTextureAllocator = TrackingTextureAllocator::create(m_context.get()); 638 618 return true; 639 619 } … … 844 824 GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId)); 845 825 846 ASSERT(!m_contentsTextureMemoryUseBytes);847 826 releaseRenderSurfaceTextures(); 848 827 } -
trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
r95988 r96141 39 39 #include "IntRect.h" 40 40 #include "LayerChromium.h" 41 #include "TrackingTextureAllocator.h" 41 42 #include "VideoLayerChromium.h" 42 43 #include "cc/CCCanvasLayerImpl.h" … … 69 70 class GraphicsContext3D; 70 71 class NonCompositedContentHost; 72 class TrackingTextureAllocator; 71 73 72 74 // Class that handles drawing of composited render layers using GL. … … 79 81 void close(); 80 82 81 virtual~LayerRendererChromium();83 ~LayerRendererChromium(); 82 84 83 85 const CCSettings& settings() const { return m_owner->settings(); } … … 105 107 106 108 void setZoomAnimatorTransform(const TransformationMatrix& t) { m_zoomAnimatorTransform = t; } 107 108 unsigned createLayerTexture();109 void deleteLayerTexture(unsigned);110 109 111 110 static void debugGLCall(GraphicsContext3D*, const char* command, const char* file, int line); … … 134 133 135 134 TextureManager* renderSurfaceTextureManager() const { return m_renderSurfaceTextureManager.get(); } 135 TextureAllocator* renderSurfaceTextureAllocator() const { return m_renderSurfaceTextureAllocator.get(); } 136 TextureAllocator* contentsTextureAllocator() const { return m_contentsTextureAllocator.get(); } 136 137 137 138 CCHeadsUpDisplay* headsUpDisplay() { return m_headsUpDisplay.get(); } … … 148 149 149 150 typedef Vector<RefPtr<CCLayerImpl> > CCLayerList; 150 151 void setContentsTextureMemoryUseBytes(size_t contentsTextureMemoryUseBytes) { m_contentsTextureMemoryUseBytes = contentsTextureMemoryUseBytes; }152 151 153 152 static void toGLMatrix(float*, const TransformationMatrix&); … … 214 213 OwnPtr<CCVideoLayerImpl::YUVProgram> m_videoLayerYUVProgram; 215 214 216 size_t m_contentsTextureMemoryUseBytes;217 215 OwnPtr<TextureManager> m_renderSurfaceTextureManager; 216 OwnPtr<TrackingTextureAllocator> m_contentsTextureAllocator; 217 OwnPtr<TrackingTextureAllocator> m_renderSurfaceTextureAllocator; 218 218 219 219 OwnPtr<CCHeadsUpDisplay> m_headsUpDisplay; -
trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h
r95901 r96141 39 39 class IntSize; 40 40 class ManagedTexture; 41 class TextureAllocator; 41 42 42 43 class LayerTextureUpdater : public RefCounted<LayerTextureUpdater> { … … 62 63 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) = 0; 63 64 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels) = 0; 64 virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0;65 virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect) = 0; 65 66 }; 66 67 -
trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp
r95901 r96141 94 94 } 95 95 96 void LayerTextureUpdaterBitmap::updateTextureRect(GraphicsContext3D* context, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)96 void LayerTextureUpdaterBitmap::updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect) 97 97 { 98 98 PlatformCanvas::AutoLocker locker(&m_canvas); 99 99 100 texture->bindTexture(context );100 texture->bindTexture(context, allocator); 101 101 m_texSubImage.upload(locker.pixels(), contentRect(), sourceRect, destRect, texture->format(), context); 102 102 } … … 146 146 } 147 147 148 void LayerTextureUpdaterSkPicture::updateTextureRect(GraphicsContext3D* compositorContext, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)148 void LayerTextureUpdaterSkPicture::updateTextureRect(GraphicsContext3D* compositorContext, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect) 149 149 { 150 150 ASSERT(!m_context || m_context == compositorContext); … … 161 161 // Bind texture. 162 162 context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 163 texture->framebufferTexture2D(context() );163 texture->framebufferTexture2D(context(), allocator); 164 164 ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE); 165 165 -
trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.h
r95901 r96141 72 72 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat); 73 73 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels); 74 virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);74 virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect); 75 75 76 76 private: … … 89 89 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat); 90 90 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels); 91 virtual void updateTextureRect(GraphicsContext3D*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);91 virtual void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect); 92 92 93 93 private: -
trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp
r95901 r96141 81 81 } 82 82 83 void ManagedTexture::bindTexture(GraphicsContext3D* context )83 void ManagedTexture::bindTexture(GraphicsContext3D* context, TextureAllocator* allocator) 84 84 { 85 85 ASSERT(m_textureManager->hasTexture(m_token)); 86 86 if (!m_textureId) 87 m_textureId = m_textureManager->allocateTexture( context, m_token);87 m_textureId = m_textureManager->allocateTexture(allocator, m_token); 88 88 context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId); 89 89 } 90 90 91 void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context )91 void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context, TextureAllocator* allocator) 92 92 { 93 93 ASSERT(m_textureManager->hasTexture(m_token)); 94 94 if (!m_textureId) 95 m_textureId = m_textureManager->allocateTexture( context, m_token);95 m_textureId = m_textureManager->allocateTexture(allocator, m_token); 96 96 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_textureId, 0); 97 97 } -
trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h
r95901 r96141 37 37 38 38 class GraphicsContext3D; 39 class TextureManager;40 39 41 40 class ManagedTexture { … … 57 56 } 58 57 59 void bindTexture(GraphicsContext3D* );60 void framebufferTexture2D(GraphicsContext3D* );58 void bindTexture(GraphicsContext3D*, TextureAllocator*); 59 void framebufferTexture2D(GraphicsContext3D*, TextureAllocator*); 61 60 62 61 IntSize size() const { return m_size; } -
trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp
r95901 r96141 33 33 namespace WebCore { 34 34 35 static size_t memoryUseBytes(IntSize size, GC3Denum textureFormat) 35 size_t TextureManager::highLimitBytes() 36 { 37 return 128 * 1024 * 1024; 38 } 39 40 size_t TextureManager::reclaimLimitBytes() 41 { 42 return 64 * 1024 * 1024; 43 } 44 45 size_t TextureManager::lowLimitBytes() 46 { 47 return 3 * 1024 * 1024; 48 } 49 50 size_t TextureManager::memoryUseBytes(const IntSize& size, GC3Denum textureFormat) 36 51 { 37 52 // FIXME: This assumes all textures are 1 byte/component. … … 45 60 } 46 61 47 size_t TextureManager::highLimitBytes()48 {49 return 128 * 1024 * 1024;50 }51 52 size_t TextureManager::reclaimLimitBytes()53 {54 return 64 * 1024 * 1024;55 }56 57 size_t TextureManager::lowLimitBytes()58 {59 return 3 * 1024 * 1024;60 }61 62 62 63 TextureManager::TextureManager(size_t memoryLimitBytes, int maxTextureSize) … … 153 154 } 154 155 155 void TextureManager::deleteEvictedTextures( GraphicsContext3D* context)156 { 157 if ( context) {156 void TextureManager::deleteEvictedTextures(TextureAllocator* allocator) 157 { 158 if (allocator) { 158 159 for (size_t i = 0; i < m_evictedTextures.size(); ++i) { 159 160 if (m_evictedTextures[i].textureId) { 160 161 #ifndef NDEBUG 161 ASSERT(m_evictedTextures[i].allocat ingContext == context);162 #endif 163 GLC(context, context->deleteTexture(m_evictedTextures[i].textureId));162 ASSERT(m_evictedTextures[i].allocator == allocator); 163 #endif 164 allocator->deleteTexture(m_evictedTextures[i].textureId, m_evictedTextures[i].size, m_evictedTextures[i].format); 164 165 } 165 166 } … … 168 169 } 169 170 170 void TextureManager::evictAndDeleteAllTextures( GraphicsContext3D* context)171 void TextureManager::evictAndDeleteAllTextures(TextureAllocator* allocator) 171 172 { 172 173 unprotectAllTextures(); 173 174 reduceMemoryToLimit(0); 174 deleteEvictedTextures( context);175 deleteEvictedTextures(allocator); 175 176 } 176 177 … … 185 186 EvictionEntry entry; 186 187 entry.textureId = info.textureId; 187 #ifndef NDEBUG 188 entry.allocatingContext = info.allocatingContext; 188 entry.size = info.size; 189 entry.format = info.format; 190 #ifndef NDEBUG 191 entry.allocator = info.allocator; 189 192 #endif 190 193 m_evictedTextures.append(entry); 191 194 } 192 195 193 unsigned TextureManager::allocateTexture( GraphicsContext3D* context, TextureToken token)196 unsigned TextureManager::allocateTexture(TextureAllocator* allocator, TextureToken token) 194 197 { 195 198 TextureMap::iterator it = m_textures.find(token); … … 198 201 ASSERT(info->isProtected); 199 202 200 unsigned textureId; 201 GLC(context, textureId = context->createTexture()); 202 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId)); 203 // Do basic linear filtering on resize. 204 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); 205 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); 206 // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE. 207 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); 208 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); 209 GLC(context, context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, info->format, info->size.width(), info->size.height(), 0, info->format, GraphicsContext3D::UNSIGNED_BYTE)); 203 unsigned textureId = allocator->createTexture(info->size, info->format); 210 204 info->textureId = textureId; 211 205 #ifndef NDEBUG 212 info->allocat ingContext = context;206 info->allocator = allocator; 213 207 #endif 214 208 return textureId; … … 240 234 info.isProtected = true; 241 235 #ifndef NDEBUG 242 info.allocat ingContext= 0;236 info.allocator = 0; 243 237 #endif 244 238 addTexture(token, info); -
trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h
r95901 r96141 38 38 typedef int TextureToken; 39 39 40 class TextureAllocator { 41 public: 42 virtual unsigned createTexture(const IntSize&, GC3Denum format) = 0; 43 virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum) = 0; 44 45 protected: 46 virtual ~TextureAllocator() { } 47 }; 48 40 49 class TextureManager { 41 50 WTF_MAKE_NONCOPYABLE(TextureManager); … … 53 62 static size_t lowLimitBytes(); 54 63 64 static size_t memoryUseBytes(const IntSize&, GC3Denum format); 65 55 66 void setMemoryLimitBytes(size_t); 56 67 … … 66 77 bool isProtected(TextureToken); 67 78 68 unsigned allocateTexture( GraphicsContext3D*, TextureToken);69 void deleteEvictedTextures( GraphicsContext3D*);79 unsigned allocateTexture(TextureAllocator*, TextureToken); 80 void deleteEvictedTextures(TextureAllocator*); 70 81 71 void evictAndDeleteAllTextures( GraphicsContext3D*);82 void evictAndDeleteAllTextures(TextureAllocator*); 72 83 73 84 void reduceMemoryToLimit(size_t); … … 83 94 bool isProtected; 84 95 #ifndef NDEBUG 85 GraphicsContext3D* allocatingContext;96 TextureAllocator* allocator; 86 97 #endif 87 98 }; … … 101 112 struct EvictionEntry { 102 113 unsigned textureId; 114 IntSize size; 115 GC3Denum format; 103 116 #ifndef NDEBUG 104 GraphicsContext3D* allocatingContext;117 TextureAllocator* allocator; 105 118 #endif 106 119 }; -
trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp
r95901 r96141 152 152 } 153 153 154 void TiledLayerChromium::updateCompositorResources(GraphicsContext3D* context )154 void TiledLayerChromium::updateCompositorResources(GraphicsContext3D* context, TextureAllocator* allocator) 155 155 { 156 156 // Painting could cause compositing to get turned off, which may cause the tiler to become invalidated mid-update. … … 198 198 CRASH(); 199 199 200 tile->texture()->bindTexture(context );200 tile->texture()->bindTexture(context, allocator); 201 201 const GC3Dint filter = m_tiler->hasBorderTexels() ? GraphicsContext3D::LINEAR : GraphicsContext3D::NEAREST; 202 202 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, filter)); … … 204 204 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0)); 205 205 206 textureUpdater()->updateTextureRect(context, tile->texture(), sourceRect, destRect);206 textureUpdater()->updateTextureRect(context, allocator, tile->texture(), sourceRect, destRect); 207 207 tile->clearDirty(); 208 208 } -
trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h
r95901 r96141 44 44 virtual ~TiledLayerChromium(); 45 45 46 virtual void updateCompositorResources(GraphicsContext3D* );46 virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*); 47 47 virtual void setIsMask(bool); 48 48 -
trunk/Source/WebCore/platform/graphics/chromium/TrackingTextureAllocator.h
r96140 r96141 1 1 /* 2 * Copyright (C) 201 0, Google Inc. All rights reserved.2 * Copyright (C) 2011, Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 23 23 */ 24 24 25 #ifndef ManagedTexture_h26 #define ManagedTexture_h25 #ifndef TrackingTextureAllocator_h 26 #define TrackingTextureAllocator_h 27 27 28 #include " IntSize.h"28 #include "GraphicsContext3D.h" 29 29 #include "TextureManager.h" 30 31 #include <wtf/FastAllocBase.h> 32 #include <wtf/Noncopyable.h> 33 #include <wtf/PassOwnPtr.h> 34 #include <wtf/RefPtr.h> 30 #include <wtf/PassRefPtr.h> 35 31 36 32 namespace WebCore { 37 33 38 class GraphicsContext3D; 39 class TextureManager; 34 class TrackingTextureAllocator : public TextureAllocator { 35 WTF_MAKE_NONCOPYABLE(TrackingTextureAllocator); 36 public: 37 static PassOwnPtr<TrackingTextureAllocator> create(PassRefPtr<GraphicsContext3D> context) 38 { 39 return adoptPtr(new TrackingTextureAllocator(context)); 40 } 41 virtual ~TrackingTextureAllocator(); 40 42 41 class ManagedTexture { 42 WTF_MAKE_NONCOPYABLE(ManagedTexture); 43 public: 44 static PassOwnPtr<ManagedTexture> create(TextureManager* manager) 45 { 46 return adoptPtr(new ManagedTexture(manager)); 47 } 48 ~ManagedTexture(); 43 virtual unsigned createTexture(const IntSize&, GC3Denum format); 44 virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum format); 49 45 50 bool isValid(const IntSize&, unsigned format); 51 bool reserve(const IntSize&, unsigned format); 52 void unreserve(); 53 bool isReserved() 54 { 55 ASSERT(m_textureManager); 56 return m_textureManager->isProtected(m_token); 57 } 46 size_t currentMemoryUseBytes() const { return m_currentMemoryUseBytes; } 58 47 59 void bindTexture(GraphicsContext3D*); 60 void framebufferTexture2D(GraphicsContext3D*);48 protected: 49 explicit TrackingTextureAllocator(PassRefPtr<GraphicsContext3D>); 61 50 62 IntSize size() const { return m_size; } 63 unsigned format() const { return m_format; } 64 unsigned textureId() const { return m_textureId; } 65 66 private: 67 explicit ManagedTexture(TextureManager*); 68 69 TextureManager* m_textureManager; 70 TextureToken m_token; 71 IntSize m_size; 72 unsigned m_format; 73 unsigned m_textureId; 51 RefPtr<GraphicsContext3D> m_context; 52 size_t m_currentMemoryUseBytes; 74 53 }; 75 54 76 55 } 77 56 78 #endif // ManagedTexture_h57 #endif -
trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp
r95957 r96141 79 79 } 80 80 81 void VideoLayerChromium::updateCompositorResources(GraphicsContext3D* context )81 void VideoLayerChromium::updateCompositorResources(GraphicsContext3D* context, TextureAllocator* allocator) 82 82 { 83 83 if (!m_delegate) … … 131 131 ASSERT(texture.m_texture); 132 132 ASSERT(frame->requiredTextureSize(plane) == texture.m_texture->size()); 133 updateTexture(context, texture, frame->data(plane));133 updateTexture(context, allocator, texture, frame->data(plane)); 134 134 } 135 135 … … 248 248 } 249 249 250 void VideoLayerChromium::updateTexture(GraphicsContext3D* context, Texture & texture, const void* data) const250 void VideoLayerChromium::updateTexture(GraphicsContext3D* context, TextureAllocator* allocator, Texture& texture, const void* data) const 251 251 { 252 252 ASSERT(context); 253 253 ASSERT(texture.m_texture); 254 254 255 texture.m_texture->bindTexture(context );255 texture.m_texture->bindTexture(context, allocator); 256 256 257 257 GC3Denum format = texture.m_texture->format(); -
trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h
r95957 r96141 51 51 virtual PassRefPtr<CCLayerImpl> createCCLayerImpl(); 52 52 53 virtual void updateCompositorResources(GraphicsContext3D* );53 virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*); 54 54 virtual bool drawsContent() const { return true; } 55 55 … … 77 77 bool texturesValid(); 78 78 bool reserveTextures(const VideoFrameChromium*, GC3Denum textureFormat); 79 void updateTexture(GraphicsContext3D*, Texture &, const void*) const;79 void updateTexture(GraphicsContext3D*, TextureAllocator*, Texture&, const void*) const; 80 80 81 81 void resetFrameParameters(); -
trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
r95901 r96141 66 66 } 67 67 68 void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D* rendererContext )68 void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D* rendererContext, TextureAllocator*) 69 69 { 70 70 if (!drawsContent()) -
trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h
r95901 r96141 51 51 52 52 virtual bool drawsContent() const; 53 virtual void updateCompositorResources(GraphicsContext3D* );53 virtual void updateCompositorResources(GraphicsContext3D*, TextureAllocator*); 54 54 void setTextureUpdated(); 55 55 bool paintRenderedResultsToCanvas(ImageBuffer*); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp
r96066 r96141 127 127 PlatformCanvas::AutoLocker locker(&canvas); 128 128 129 m_hudTexture->bindTexture(context );129 m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator()); 130 130 bool uploadedViaMap = false; 131 131 if (m_useMapSubForUploads) { … … 149 149 ASSERT(program && program->initialized()); 150 150 GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); 151 m_hudTexture->bindTexture(context );151 m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator()); 152 152 GLC(context, context->useProgram(program->program())); 153 153 GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
r96066 r96141 93 93 m_proxy.clear(); 94 94 clearPendingUpdate(); 95 ASSERT(!m_contentsTextureManager || !m_contentsTextureManager->currentMemoryUseBytes()); 96 m_contentsTextureManager.clear(); 97 } 98 99 void CCLayerTreeHost::deleteContentsTextures(GraphicsContext3D* context) 95 } 96 97 void CCLayerTreeHost::deleteContentsTexturesOnCCThread(TextureAllocator* allocator) 100 98 { 101 99 ASSERT(CCProxy::isImplThread()); 102 100 if (m_contentsTextureManager) 103 m_contentsTextureManager->evictAndDeleteAllTextures( context);101 m_contentsTextureManager->evictAndDeleteAllTextures(allocator); 104 102 } 105 103 … … 116 114 // should be delayed until the CCLayerTreeHost::commitComplete, which will run 117 115 // after the commit, but on the main thread. 118 void CCLayerTreeHost::commitTo (CCLayerTreeHostImpl* hostImpl)116 void CCLayerTreeHost::commitToOnCCThread(CCLayerTreeHostImpl* hostImpl) 119 117 { 120 118 ASSERT(CCProxy::isImplThread()); … … 123 121 124 122 contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes()); 125 contentsTextureManager()->deleteEvictedTextures(hostImpl->conte xt());126 127 updateCompositorResources(m_updateList, hostImpl->context() );123 contentsTextureManager()->deleteEvictedTextures(hostImpl->contentsTextureAllocator()); 124 125 updateCompositorResources(m_updateList, hostImpl->context(), hostImpl->contentsTextureAllocator()); 128 126 129 127 hostImpl->setVisible(m_visible); 130 128 hostImpl->setZoomAnimatorTransform(m_zoomAnimatorTransform); 131 129 hostImpl->setViewport(viewportSize()); 132 133 hostImpl->layerRenderer()->setContentsTextureMemoryUseBytes(m_contentsTextureManager->currentMemoryUseBytes());134 130 135 131 // Synchronize trees, if one exists at all... … … 165 161 void CCLayerTreeHost::didRecreateGraphicsContext(bool success) 166 162 { 167 m_contentsTextureManager->evictAndDeleteAllTextures(0);168 169 163 if (rootLayer()) 170 164 rootLayer()->cleanupResourcesRecursive(); … … 378 372 } 379 373 380 void CCLayerTreeHost::updateCompositorResources(const LayerList& renderSurfaceLayerList, GraphicsContext3D* context )374 void CCLayerTreeHost::updateCompositorResources(const LayerList& renderSurfaceLayerList, GraphicsContext3D* context, TextureAllocator* allocator) 381 375 { 382 376 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { … … 395 389 continue; 396 390 397 updateCompositorResources(layer, context );391 updateCompositorResources(layer, context, allocator); 398 392 } 399 393 } 400 394 } 401 395 402 void CCLayerTreeHost::updateCompositorResources(LayerChromium* layer, GraphicsContext3D* context )396 void CCLayerTreeHost::updateCompositorResources(LayerChromium* layer, GraphicsContext3D* context, TextureAllocator* allocator) 403 397 { 404 398 if (layer->bounds().isEmpty()) … … 409 403 410 404 if (layer->maskLayer()) 411 updateCompositorResources(layer->maskLayer(), context );405 updateCompositorResources(layer->maskLayer(), context, allocator); 412 406 if (layer->replicaLayer()) 413 updateCompositorResources(layer->replicaLayer(), context );407 updateCompositorResources(layer->replicaLayer(), context, allocator); 414 408 415 409 if (layer->drawsContent()) 416 layer->updateCompositorResources(context );410 layer->updateCompositorResources(context, allocator); 417 411 } 418 412 -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
r96066 r96141 46 46 class LayerChromium; 47 47 class LayerPainterChromium; 48 class TextureAllocator; 48 49 class TextureManager; 49 50 … … 99 100 void animateAndLayout(double frameBeginTime); 100 101 void commitComplete(); 101 void commitTo (CCLayerTreeHostImpl*);102 void commitToOnCCThread(CCLayerTreeHostImpl*); 102 103 PassOwnPtr<CCThread> createCompositorThread(); 103 104 PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D(); … … 107 108 void scheduleComposite(); 108 109 #endif 110 void deleteContentsTexturesOnCCThread(TextureAllocator*); 109 111 110 112 // CCLayerTreeHost interface to WebView. … … 153 155 void updateLayers(); 154 156 155 void deleteContentsTextures(GraphicsContext3D*);156 157 157 protected: 158 158 CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&); … … 164 164 void paintLayerContents(const LayerList&); 165 165 void updateLayers(LayerChromium*); 166 void updateCompositorResources(const LayerList&, GraphicsContext3D* );167 void updateCompositorResources(LayerChromium*, GraphicsContext3D* );166 void updateCompositorResources(const LayerList&, GraphicsContext3D*, TextureAllocator*); 167 void updateCompositorResources(LayerChromium*, GraphicsContext3D*, TextureAllocator*); 168 168 void clearPendingUpdate(); 169 169 -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp
r96066 r96141 99 99 } 100 100 101 TextureAllocator* CCLayerTreeHostImpl::contentsTextureAllocator() const 102 { 103 return m_layerRenderer->contentsTextureAllocator(); 104 } 105 101 106 void CCLayerTreeHostImpl::present() 102 107 { … … 135 140 } 136 141 137 // If we had a previous layer renderer, then its context must have been lost along with all of its resources. 138 // Let the old layer renderer known its resources are gone. 139 if (m_layerRenderer) { 140 m_layerRenderer->setContentsTextureMemoryUseBytes(0); 142 if (m_layerRenderer) 141 143 m_layerRenderer->close(); 142 }143 144 144 145 m_layerRenderer = layerRenderer.release(); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h
r95988 r96141 38 38 class CCLayerImpl; 39 39 class LayerRendererChromium; 40 class TextureAllocator; 40 41 struct LayerRendererCapabilities; 41 42 class TransformationMatrix; … … 62 63 LayerRendererChromium* layerRenderer() { return m_layerRenderer.get(); } 63 64 const LayerRendererCapabilities& layerRendererCapabilities() const; 65 TextureAllocator* contentsTextureAllocator() const; 64 66 65 67 void present(); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp
r95901 r96141 188 188 GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0)); 189 189 GLC(context3D, context3D->uniform1i(program->fragmentShader().samplerLocation(), 0)); 190 m_contentsTexture->bindTexture(context3D );190 m_contentsTexture->bindTexture(context3D, layerRenderer->renderSurfaceTextureAllocator()); 191 191 192 192 if (shaderMaskSamplerLocation != -1) { -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp
r96066 r96141 161 161 ScopedSetImplThread impl; 162 162 m_layerTreeHostImpl->beginCommit(); 163 m_layerTreeHost->commitTo (m_layerTreeHostImpl.get());163 m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get()); 164 164 m_layerTreeHostImpl->commitComplete(); 165 165 } … … 191 191 { 192 192 ScopedSetImplThread impl; 193 m_layerTreeHost->deleteContentsTextures (m_layerTreeHostImpl->context());193 m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator()); 194 194 m_layerTreeHostImpl.clear(); 195 195 } … … 228 228 { 229 229 ScopedSetImplThread impl; 230 m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator()); 230 231 ok = m_layerTreeHostImpl->initializeLayerRenderer(context); 231 232 if (ok) … … 264 265 ScopedSetImplThread impl; 265 266 m_layerTreeHostImpl->beginCommit(); 266 m_layerTreeHost->commitTo (m_layerTreeHostImpl.get());267 m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get()); 267 268 m_layerTreeHostImpl->commitComplete(); 268 269 } -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp
r96066 r96141 346 346 } 347 347 m_layerTreeHostImpl->beginCommit(); 348 m_layerTreeHost->commitTo (m_layerTreeHostImpl.get());348 m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get()); 349 349 m_layerTreeHostImpl->commitComplete(); 350 350 … … 431 431 TRACE_EVENT("CCThreadProxy::layerTreeHostClosedOnCCThread", this, 0); 432 432 ASSERT(isImplThread()); 433 m_layerTreeHost->deleteContentsTextures (m_layerTreeHostImpl->context());433 m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator()); 434 434 m_layerTreeHostImpl.clear(); 435 435 completion->signal();
Note: See TracChangeset
for help on using the changeset viewer.