Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h" | 37 #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h" |
| 38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 39 #include "public/platform/WebCompositorSupport.h" | 39 #include "public/platform/WebCompositorSupport.h" |
| 40 #include "public/platform/WebGraphicsContext3D.h" | 40 #include "public/platform/WebGraphicsContext3D.h" |
| 41 | 41 |
| 42 using WebKit::WebExternalTextureLayer; | 42 using WebKit::WebExternalTextureLayer; |
| 43 using WebKit::WebGraphicsContext3D; | 43 using WebKit::WebGraphicsContext3D; |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 void Canvas2DLayerBridgePtr::clear() | |
| 48 { | |
| 49 if (m_ptr) { | |
| 50 m_ptr->destroy(); | |
| 51 m_ptr.clear(); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 Canvas2DLayerBridgePtr& Canvas2DLayerBridgePtr::operator=(const PassRefPtr<Canva s2DLayerBridge>& other) | |
| 56 { | |
| 57 clear(); | |
| 58 m_ptr = other; | |
| 59 return *this; | |
| 60 } | |
| 61 | |
| 47 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz e) | 62 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz e) |
| 48 { | 63 { |
| 49 ASSERT(!context3D->webContext()->isContextLost()); | 64 ASSERT(!context3D->webContext()->isContextLost()); |
| 50 GrContext* gr = context3D->grContext(); | 65 GrContext* gr = context3D->grContext(); |
| 51 if (!gr) | 66 if (!gr) |
| 52 return 0; | 67 return 0; |
| 53 gr->resetContext(); | 68 gr->resetContext(); |
| 54 SkImage::Info info; | 69 SkImage::Info info; |
| 55 info.fWidth = size.width(); | 70 info.fWidth = size.width(); |
| 56 info.fHeight = size.height(); | 71 info.fHeight = size.height(); |
| 57 info.fColorType = SkImage::kPMColor_ColorType; | 72 info.fColorType = SkImage::kPMColor_ColorType; |
| 58 info.fAlphaType = SkImage::kPremul_AlphaType; | 73 info.fAlphaType = SkImage::kPremul_AlphaType; |
| 59 return SkSurface::NewRenderTarget(gr, info); | 74 return SkSurface::NewRenderTarget(gr, info); |
| 60 } | 75 } |
| 61 | 76 |
| 62 PassOwnPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC ontext3D> context, const IntSize& size, OpacityMode opacityMode) | 77 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC ontext3D> context, const IntSize& size, OpacityMode opacityMode) |
| 63 { | 78 { |
| 64 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 79 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
| 65 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size)); | 80 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size)); |
| 66 if (!surface.get()) | 81 if (!surface.get()) { |
| 67 return PassOwnPtr<Canvas2DLayerBridge>(); | 82 return PassRefPtr<Canvas2DLayerBridge>(); |
| 83 } | |
| 68 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get()); | 84 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get()); |
| 69 OwnPtr<Canvas2DLayerBridge> layerBridge = adoptPtr(new Canvas2DLayerBridge(c ontext, canvas, opacityMode)); | 85 RefPtr<Canvas2DLayerBridge> layerBridge = adoptRef(new Canvas2DLayerBridge(c ontext, canvas, opacityMode)); |
| 70 return layerBridge.release(); | 86 return layerBridge.release(); |
| 71 } | 87 } |
| 72 | 88 |
| 73 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) | 89 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) |
| 74 : m_canvas(canvas) | 90 : m_canvas(canvas) |
| 75 , m_context(context) | 91 , m_context(context) |
| 76 , m_bytesAllocated(0) | 92 , m_bytesAllocated(0) |
| 77 , m_didRecordDrawCommand(false) | 93 , m_didRecordDrawCommand(false) |
| 78 , m_surfaceIsValid(true) | 94 , m_surfaceIsValid(true) |
| 79 , m_framesPending(0) | 95 , m_framesPending(0) |
| 96 , m_destructionInProgress(false) | |
| 80 , m_rateLimitingEnabled(false) | 97 , m_rateLimitingEnabled(false) |
| 81 , m_next(0) | 98 , m_next(0) |
| 82 , m_prev(0) | 99 , m_prev(0) |
| 83 , m_lastImageId(0) | 100 , m_lastImageId(0) |
| 84 { | 101 { |
| 85 ASSERT(m_canvas); | 102 ASSERT(m_canvas); |
| 86 // Used by browser tests to detect the use of a Canvas2DLayerBridge. | 103 // Used by browser tests to detect the use of a Canvas2DLayerBridge. |
| 87 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 104 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
| 88 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this)); | 105 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this)); |
| 89 m_layer->setOpaque(opacityMode == Opaque); | 106 m_layer->setOpaque(opacityMode == Opaque); |
| 90 m_layer->setBlendBackgroundColor(opacityMode != Opaque); | 107 m_layer->setBlendBackgroundColor(opacityMode != Opaque); |
| 91 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 108 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 92 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 109 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 93 m_canvas->setNotificationClient(this); | 110 m_canvas->setNotificationClient(this); |
| 94 } | 111 } |
| 95 | 112 |
| 96 Canvas2DLayerBridge::~Canvas2DLayerBridge() | 113 Canvas2DLayerBridge::~Canvas2DLayerBridge() |
| 97 { | 114 { |
| 115 ASSERT(m_destructionInProgress); | |
| 116 m_layer.clear(); | |
| 117 Vector<MailboxInfo>::iterator mailboxInfo; | |
| 118 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | |
| 119 ASSERT(mailboxInfo->m_status != MailboxInUse); | |
| 120 if (mailboxInfo->m_status == MailboxReleased) { | |
| 121 if (mailboxInfo->m_mailbox.syncPoint) { | |
| 122 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint); | |
| 123 mailboxInfo->m_mailbox.syncPoint = 0; | |
| 124 } | |
| 125 // Invalidate texture state in case the compositor altered it since the copy-on-write. | |
| 126 mailboxInfo->m_image->getTexture()->invalidateCachedState(); | |
| 127 } | |
| 128 } | |
| 129 m_mailboxes.clear(); | |
| 130 } | |
| 131 | |
| 132 void Canvas2DLayerBridge::destroy() | |
| 133 { | |
| 134 ASSERT(!m_destructionInProgress); | |
| 135 m_destructionInProgress = true; | |
| 98 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 136 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 137 m_canvas->setNotificationClient(0); | |
| 138 m_layer->clearTexture(); | |
| 99 Canvas2DLayerManager::get().layerToBeDestroyed(this); | 139 Canvas2DLayerManager::get().layerToBeDestroyed(this); |
| 100 m_canvas->setNotificationClient(0); | |
| 101 m_mailboxes.clear(); | |
| 102 m_layer->clearTexture(); | |
| 103 m_layer.clear(); | |
| 104 } | 140 } |
| 105 | 141 |
| 106 void Canvas2DLayerBridge::limitPendingFrames() | 142 void Canvas2DLayerBridge::limitPendingFrames() |
| 107 { | 143 { |
| 144 ASSERT(!m_destructionInProgress); | |
| 108 if (m_didRecordDrawCommand) { | 145 if (m_didRecordDrawCommand) { |
| 109 m_framesPending++; | 146 m_framesPending++; |
| 110 m_didRecordDrawCommand = false; | 147 m_didRecordDrawCommand = false; |
| 111 if (m_framesPending > 1) { | 148 if (m_framesPending > 1) { |
| 112 // Turn on the rate limiter if this layer tends to accumulate a | 149 // Turn on the rate limiter if this layer tends to accumulate a |
| 113 // non-discardable multi-frame backlog of draw commands. | 150 // non-discardable multi-frame backlog of draw commands. |
| 114 setRateLimitingEnabled(true); | 151 setRateLimitingEnabled(true); |
| 115 } | 152 } |
| 116 if (m_rateLimitingEnabled) { | 153 if (m_rateLimitingEnabled) { |
| 117 flush(); | 154 flush(); |
| 118 } | 155 } |
| 119 } | 156 } |
| 120 } | 157 } |
| 121 | 158 |
| 122 void Canvas2DLayerBridge::prepareForDraw() | 159 void Canvas2DLayerBridge::prepareForDraw() |
| 123 { | 160 { |
| 161 ASSERT(!m_destructionInProgress); | |
| 124 ASSERT(m_layer); | 162 ASSERT(m_layer); |
| 125 if (!isValid()) { | 163 if (!isValid()) { |
| 126 if (m_canvas) { | 164 if (m_canvas) { |
| 127 // drop pending commands because there is no surface to draw to | 165 // drop pending commands because there is no surface to draw to |
| 128 m_canvas->silentFlush(); | 166 m_canvas->silentFlush(); |
| 129 } | 167 } |
| 130 return; | 168 return; |
| 131 } | 169 } |
| 132 m_context->makeContextCurrent(); | 170 m_context->makeContextCurrent(); |
| 133 } | 171 } |
| 134 | 172 |
| 135 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) | 173 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) |
| 136 { | 174 { |
| 175 ASSERT(!m_destructionInProgress); | |
| 137 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; | 176 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; |
| 138 m_bytesAllocated = bytesAllocated; | 177 m_bytesAllocated = bytesAllocated; |
| 139 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); | 178 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); |
| 140 } | 179 } |
| 141 | 180 |
| 142 size_t Canvas2DLayerBridge::storageAllocatedForRecording() | 181 size_t Canvas2DLayerBridge::storageAllocatedForRecording() |
| 143 { | 182 { |
| 183 ASSERT(!m_destructionInProgress); | |
| 144 return m_canvas->storageAllocatedForRecording(); | 184 return m_canvas->storageAllocatedForRecording(); |
| 145 } | 185 } |
| 146 | 186 |
| 147 void Canvas2DLayerBridge::flushedDrawCommands() | 187 void Canvas2DLayerBridge::flushedDrawCommands() |
| 148 { | 188 { |
| 189 ASSERT(!m_destructionInProgress); | |
| 149 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); | 190 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); |
| 150 m_framesPending = 0; | 191 m_framesPending = 0; |
| 151 } | 192 } |
| 152 | 193 |
| 153 void Canvas2DLayerBridge::skippedPendingDrawCommands() | 194 void Canvas2DLayerBridge::skippedPendingDrawCommands() |
| 154 { | 195 { |
| 196 ASSERT(!m_destructionInProgress); | |
| 155 // Stop triggering the rate limiter if SkDeferredCanvas is detecting | 197 // Stop triggering the rate limiter if SkDeferredCanvas is detecting |
| 156 // and optimizing overdraw. | 198 // and optimizing overdraw. |
| 157 setRateLimitingEnabled(false); | 199 setRateLimitingEnabled(false); |
| 158 flushedDrawCommands(); | 200 flushedDrawCommands(); |
| 159 } | 201 } |
| 160 | 202 |
| 161 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) | 203 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) |
| 162 { | 204 { |
| 205 ASSERT(!m_destructionInProgress || !enabled); | |
| 163 if (m_rateLimitingEnabled != enabled) { | 206 if (m_rateLimitingEnabled != enabled) { |
| 164 m_rateLimitingEnabled = enabled; | 207 m_rateLimitingEnabled = enabled; |
| 165 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 208 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 166 } | 209 } |
| 167 } | 210 } |
| 168 | 211 |
| 169 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) | 212 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) |
| 170 { | 213 { |
| 214 ASSERT(!m_destructionInProgress); | |
| 171 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); | 215 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); |
| 172 if (bytesFreed) | 216 if (bytesFreed) |
| 173 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed)); | 217 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed)); |
| 174 m_bytesAllocated -= bytesFreed; | 218 m_bytesAllocated -= bytesFreed; |
| 175 return bytesFreed; | 219 return bytesFreed; |
| 176 } | 220 } |
| 177 | 221 |
| 178 void Canvas2DLayerBridge::flush() | 222 void Canvas2DLayerBridge::flush() |
| 179 { | 223 { |
| 224 ASSERT(!m_destructionInProgress); | |
| 180 if (m_canvas->hasPendingCommands()) { | 225 if (m_canvas->hasPendingCommands()) { |
| 181 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); | 226 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); |
| 182 m_canvas->flush(); | 227 m_canvas->flush(); |
| 183 } | 228 } |
| 184 } | 229 } |
| 185 | 230 |
| 186 WebGraphicsContext3D* Canvas2DLayerBridge::context() | 231 WebGraphicsContext3D* Canvas2DLayerBridge::context() |
| 187 { | 232 { |
| 188 // Check on m_layer is necessary because context() may be called during | 233 // Check on m_layer is necessary because context() may be called during |
| 189 // the destruction of m_layer | 234 // the destruction of m_layer |
| 190 if (m_layer) { | 235 if (m_layer) { |
| 191 isValid(); // To ensure rate limiter is disabled if context is lost. | 236 isValid(); // To ensure rate limiter is disabled if context is lost. |
| 192 } | 237 } |
| 193 return m_context->webContext(); | 238 return m_context->webContext(); |
| 194 } | 239 } |
| 195 | 240 |
| 196 bool Canvas2DLayerBridge::isValid() | 241 bool Canvas2DLayerBridge::isValid() |
| 197 { | 242 { |
| 198 ASSERT(m_layer); | 243 ASSERT(m_layer); |
| 244 if (m_destructionInProgress) | |
| 245 return false; | |
| 199 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { | 246 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { |
| 200 // Attempt to recover. | 247 // Attempt to recover. |
| 201 m_layer->clearTexture(); | 248 m_layer->clearTexture(); |
| 202 m_mailboxes.clear(); | 249 m_mailboxes.clear(); |
| 203 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ; | 250 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ; |
| 204 if (!sharedContext || sharedContext->webContext()->isContextLost()) { | 251 if (!sharedContext || sharedContext->webContext()->isContextLost()) { |
| 205 m_surfaceIsValid = false; | 252 m_surfaceIsValid = false; |
| 206 } else { | 253 } else { |
| 207 m_context = sharedContext; | 254 m_context = sharedContext; |
| 208 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); | 255 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); |
| 209 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) ); | 256 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) ); |
| 210 if (surface.get()) { | 257 if (surface.get()) { |
| 211 m_canvas->setSurface(surface.get()); | 258 m_canvas->setSurface(surface.get()); |
| 212 m_surfaceIsValid = true; | 259 m_surfaceIsValid = true; |
| 213 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 | 260 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 |
| 214 } else { | 261 } else { |
| 215 // Surface allocation failed. Set m_surfaceIsValid to false to | 262 // Surface allocation failed. Set m_surfaceIsValid to false to |
| 216 // trigger subsequent retry. | 263 // trigger subsequent retry. |
| 217 m_surfaceIsValid = false; | 264 m_surfaceIsValid = false; |
| 218 } | 265 } |
| 219 } | 266 } |
| 220 } | 267 } |
| 221 if (!m_surfaceIsValid) | 268 if (!m_surfaceIsValid) |
| 222 setRateLimitingEnabled(false); | 269 setRateLimitingEnabled(false); |
| 223 return m_surfaceIsValid; | 270 return m_surfaceIsValid; |
| 224 | |
| 225 } | 271 } |
| 226 | 272 |
| 227 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap) | 273 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap) |
| 228 { | 274 { |
| 275 if (m_destructionInProgress) { | |
| 276 const WebKit::WebExternalTextureMailbox emptyMailbox; | |
| 277 *outMailbox = emptyMailbox; | |
| 278 return true; | |
| 279 } | |
| 229 ASSERT(!bitmap); | 280 ASSERT(!bitmap); |
| 230 if (!isValid()) | 281 if (!isValid()) |
| 231 return false; | 282 return false; |
| 232 // Release to skia textures that were previouosly released by the | 283 // Release to skia textures that were previouosly released by the |
| 233 // compositor. We do this before acquiring the next snapshot in | 284 // compositor. We do this before acquiring the next snapshot in |
| 234 // order to cap maximum gpu memory consumption. | 285 // order to cap maximum gpu memory consumption. |
| 235 m_context->makeContextCurrent(); | 286 m_context->makeContextCurrent(); |
| 236 flush(); | 287 flush(); |
| 237 Vector<MailboxInfo>::iterator mailboxInfo; | 288 Vector<MailboxInfo>::iterator mailboxInfo; |
| 238 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 289 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); | 322 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); |
| 272 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); | 323 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); |
| 273 context()->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, mailboxInfo ->m_mailbox.name); | 324 context()->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, mailboxInfo ->m_mailbox.name); |
| 274 context()->flush(); | 325 context()->flush(); |
| 275 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint(); | 326 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint(); |
| 276 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); | 327 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); |
| 277 // Because we are changing the texture binding without going through skia, | 328 // Because we are changing the texture binding without going through skia, |
| 278 // we must dirty the context. | 329 // we must dirty the context. |
| 279 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 330 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 280 | 331 |
| 332 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has | |
| 333 // live mailboxes | |
| 334 ASSERT(!mailboxInfo->m_parentLayerBridge); | |
| 335 this->ref(); // Because we are adopting an already referenced object | |
|
Stephen White
2013/08/26 21:15:44
I think you could avoid doing this explicit ref()
| |
| 336 mailboxInfo->m_parentLayerBridge = adoptRef(this); | |
| 281 *outMailbox = mailboxInfo->m_mailbox; | 337 *outMailbox = mailboxInfo->m_mailbox; |
| 282 return true; | 338 return true; |
| 283 } | 339 } |
| 284 | 340 |
| 285 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { | 341 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { |
| 342 ASSERT(!m_destructionInProgress); | |
| 286 MailboxInfo* mailboxInfo; | 343 MailboxInfo* mailboxInfo; |
| 287 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 344 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| 288 if (mailboxInfo->m_status == MailboxAvailable) { | 345 if (mailboxInfo->m_status == MailboxAvailable) { |
| 289 return mailboxInfo; | 346 return mailboxInfo; |
| 290 } | 347 } |
| 291 } | 348 } |
| 292 | 349 |
| 293 // No available mailbox: create one. | 350 // No available mailbox: create one. |
| 294 m_mailboxes.grow(m_mailboxes.size() + 1); | 351 m_mailboxes.grow(m_mailboxes.size() + 1); |
| 295 mailboxInfo = &m_mailboxes.last(); | 352 mailboxInfo = &m_mailboxes.last(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 306 } | 363 } |
| 307 | 364 |
| 308 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo x& mailbox) | 365 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo x& mailbox) |
| 309 { | 366 { |
| 310 Vector<MailboxInfo>::iterator mailboxInfo; | 367 Vector<MailboxInfo>::iterator mailboxInfo; |
| 311 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 368 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| 312 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) { | 369 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) { |
| 313 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; | 370 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; |
| 314 ASSERT(mailboxInfo->m_status == MailboxInUse); | 371 ASSERT(mailboxInfo->m_status == MailboxInUse); |
| 315 mailboxInfo->m_status = MailboxReleased; | 372 mailboxInfo->m_status = MailboxReleased; |
| 373 // Trigger Canvas2DLayerBridge self-destruction if this is the | |
| 374 // last live mailbox and the layer bridge is not externally | |
| 375 // referenced. | |
| 376 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); | |
| 377 mailboxInfo->m_parentLayerBridge.clear(); | |
| 316 return; | 378 return; |
| 317 } | 379 } |
| 318 } | 380 } |
| 319 } | 381 } |
| 320 | 382 |
| 321 WebKit::WebLayer* Canvas2DLayerBridge::layer() | 383 WebKit::WebLayer* Canvas2DLayerBridge::layer() |
| 322 { | 384 { |
| 323 ASSERT(m_layer); | 385 ASSERT(m_layer); |
| 324 return m_layer->layer(); | 386 return m_layer->layer(); |
| 325 } | 387 } |
| 326 | 388 |
| 327 void Canvas2DLayerBridge::contextAcquired() | 389 void Canvas2DLayerBridge::contextAcquired() |
| 328 { | 390 { |
| 391 ASSERT(!m_destructionInProgress); | |
| 329 Canvas2DLayerManager::get().layerDidDraw(this); | 392 Canvas2DLayerManager::get().layerDidDraw(this); |
| 330 m_didRecordDrawCommand = true; | 393 m_didRecordDrawCommand = true; |
| 331 } | 394 } |
| 332 | 395 |
| 333 unsigned Canvas2DLayerBridge::backBufferTexture() | 396 unsigned Canvas2DLayerBridge::backBufferTexture() |
| 334 { | 397 { |
| 398 ASSERT(!m_destructionInProgress); | |
| 335 if (!isValid()) | 399 if (!isValid()) |
| 336 return 0; | 400 return 0; |
| 337 contextAcquired(); | 401 contextAcquired(); |
| 338 m_canvas->flush(); | 402 m_canvas->flush(); |
| 339 m_context->flush(); | 403 m_context->flush(); |
| 340 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); | 404 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); |
| 341 if (renderTarget) { | 405 if (renderTarget) { |
| 342 return renderTarget->asTexture()->getTextureHandle(); | 406 return renderTarget->asTexture()->getTextureHandle(); |
| 343 } | 407 } |
| 344 return 0; | 408 return 0; |
| 345 } | 409 } |
| 346 | 410 |
| 347 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 411 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 348 // This copy constructor should only be used for Vector reallocation | 412 // This copy constructor should only be used for Vector reallocation |
| 349 // Assuming 'other' is to be destroyed, we swap m_image ownership | 413 // Assuming 'other' is to be destroyed, we swap m_image ownership |
| 350 // rather than do a refcount dance. | 414 // rather than do a refcount dance. |
| 351 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 415 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 352 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); | 416 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); |
| 353 m_status = other.m_status; | 417 m_status = other.m_status; |
| 354 } | 418 } |
| 355 | 419 |
| 356 } | 420 } |
| OLD | NEW |