| 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); | 140 // Orphaning the layer is required to trigger the recration of a new layer |
| 101 m_mailboxes.clear(); | 141 // in the case where destruction is caused by a canvas resize. Test: |
| 102 m_layer->clearTexture(); | 142 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
| 103 m_layer.clear(); | 143 m_layer->layer()->removeFromParent(); |
| 104 } | 144 } |
| 105 | 145 |
| 106 void Canvas2DLayerBridge::limitPendingFrames() | 146 void Canvas2DLayerBridge::limitPendingFrames() |
| 107 { | 147 { |
| 148 ASSERT(!m_destructionInProgress); |
| 108 if (m_didRecordDrawCommand) { | 149 if (m_didRecordDrawCommand) { |
| 109 m_framesPending++; | 150 m_framesPending++; |
| 110 m_didRecordDrawCommand = false; | 151 m_didRecordDrawCommand = false; |
| 111 if (m_framesPending > 1) { | 152 if (m_framesPending > 1) { |
| 112 // Turn on the rate limiter if this layer tends to accumulate a | 153 // Turn on the rate limiter if this layer tends to accumulate a |
| 113 // non-discardable multi-frame backlog of draw commands. | 154 // non-discardable multi-frame backlog of draw commands. |
| 114 setRateLimitingEnabled(true); | 155 setRateLimitingEnabled(true); |
| 115 } | 156 } |
| 116 if (m_rateLimitingEnabled) { | 157 if (m_rateLimitingEnabled) { |
| 117 flush(); | 158 flush(); |
| 118 } | 159 } |
| 119 } | 160 } |
| 120 } | 161 } |
| 121 | 162 |
| 122 void Canvas2DLayerBridge::prepareForDraw() | 163 void Canvas2DLayerBridge::prepareForDraw() |
| 123 { | 164 { |
| 165 ASSERT(!m_destructionInProgress); |
| 124 ASSERT(m_layer); | 166 ASSERT(m_layer); |
| 125 if (!isValid()) { | 167 if (!isValid()) { |
| 126 if (m_canvas) { | 168 if (m_canvas) { |
| 127 // drop pending commands because there is no surface to draw to | 169 // drop pending commands because there is no surface to draw to |
| 128 m_canvas->silentFlush(); | 170 m_canvas->silentFlush(); |
| 129 } | 171 } |
| 130 return; | 172 return; |
| 131 } | 173 } |
| 132 m_context->makeContextCurrent(); | 174 m_context->makeContextCurrent(); |
| 133 } | 175 } |
| 134 | 176 |
| 135 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca
ted) | 177 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca
ted) |
| 136 { | 178 { |
| 179 ASSERT(!m_destructionInProgress); |
| 137 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; | 180 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; |
| 138 m_bytesAllocated = bytesAllocated; | 181 m_bytesAllocated = bytesAllocated; |
| 139 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); | 182 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); |
| 140 } | 183 } |
| 141 | 184 |
| 142 size_t Canvas2DLayerBridge::storageAllocatedForRecording() | 185 size_t Canvas2DLayerBridge::storageAllocatedForRecording() |
| 143 { | 186 { |
| 187 ASSERT(!m_destructionInProgress); |
| 144 return m_canvas->storageAllocatedForRecording(); | 188 return m_canvas->storageAllocatedForRecording(); |
| 145 } | 189 } |
| 146 | 190 |
| 147 void Canvas2DLayerBridge::flushedDrawCommands() | 191 void Canvas2DLayerBridge::flushedDrawCommands() |
| 148 { | 192 { |
| 193 ASSERT(!m_destructionInProgress); |
| 149 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); | 194 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); |
| 150 m_framesPending = 0; | 195 m_framesPending = 0; |
| 151 } | 196 } |
| 152 | 197 |
| 153 void Canvas2DLayerBridge::skippedPendingDrawCommands() | 198 void Canvas2DLayerBridge::skippedPendingDrawCommands() |
| 154 { | 199 { |
| 200 ASSERT(!m_destructionInProgress); |
| 155 // Stop triggering the rate limiter if SkDeferredCanvas is detecting | 201 // Stop triggering the rate limiter if SkDeferredCanvas is detecting |
| 156 // and optimizing overdraw. | 202 // and optimizing overdraw. |
| 157 setRateLimitingEnabled(false); | 203 setRateLimitingEnabled(false); |
| 158 flushedDrawCommands(); | 204 flushedDrawCommands(); |
| 159 } | 205 } |
| 160 | 206 |
| 161 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) | 207 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) |
| 162 { | 208 { |
| 209 ASSERT(!m_destructionInProgress || !enabled); |
| 163 if (m_rateLimitingEnabled != enabled) { | 210 if (m_rateLimitingEnabled != enabled) { |
| 164 m_rateLimitingEnabled = enabled; | 211 m_rateLimitingEnabled = enabled; |
| 165 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 212 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 166 } | 213 } |
| 167 } | 214 } |
| 168 | 215 |
| 169 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) | 216 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) |
| 170 { | 217 { |
| 218 ASSERT(!m_destructionInProgress); |
| 171 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); | 219 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); |
| 172 if (bytesFreed) | 220 if (bytesFreed) |
| 173 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr
_t)bytesFreed)); | 221 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr
_t)bytesFreed)); |
| 174 m_bytesAllocated -= bytesFreed; | 222 m_bytesAllocated -= bytesFreed; |
| 175 return bytesFreed; | 223 return bytesFreed; |
| 176 } | 224 } |
| 177 | 225 |
| 178 void Canvas2DLayerBridge::flush() | 226 void Canvas2DLayerBridge::flush() |
| 179 { | 227 { |
| 228 ASSERT(!m_destructionInProgress); |
| 180 if (m_canvas->hasPendingCommands()) { | 229 if (m_canvas->hasPendingCommands()) { |
| 181 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); | 230 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); |
| 182 m_canvas->flush(); | 231 m_canvas->flush(); |
| 183 } | 232 } |
| 184 } | 233 } |
| 185 | 234 |
| 186 WebGraphicsContext3D* Canvas2DLayerBridge::context() | 235 WebGraphicsContext3D* Canvas2DLayerBridge::context() |
| 187 { | 236 { |
| 188 // Check on m_layer is necessary because context() may be called during | 237 // Check on m_layer is necessary because context() may be called during |
| 189 // the destruction of m_layer | 238 // the destruction of m_layer |
| 190 if (m_layer) { | 239 if (m_layer) { |
| 191 isValid(); // To ensure rate limiter is disabled if context is lost. | 240 isValid(); // To ensure rate limiter is disabled if context is lost. |
| 192 } | 241 } |
| 193 return m_context->webContext(); | 242 return m_context->webContext(); |
| 194 } | 243 } |
| 195 | 244 |
| 196 bool Canvas2DLayerBridge::isValid() | 245 bool Canvas2DLayerBridge::isValid() |
| 197 { | 246 { |
| 198 ASSERT(m_layer); | 247 ASSERT(m_layer); |
| 248 if (m_destructionInProgress) |
| 249 return false; |
| 199 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { | 250 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { |
| 200 // Attempt to recover. | 251 // Attempt to recover. |
| 201 m_layer->clearTexture(); | 252 m_layer->clearTexture(); |
| 202 m_mailboxes.clear(); | 253 m_mailboxes.clear(); |
| 203 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get()
; | 254 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get()
; |
| 204 if (!sharedContext || sharedContext->webContext()->isContextLost()) { | 255 if (!sharedContext || sharedContext->webContext()->isContextLost()) { |
| 205 m_surfaceIsValid = false; | 256 m_surfaceIsValid = false; |
| 206 } else { | 257 } else { |
| 207 m_context = sharedContext; | 258 m_context = sharedContext; |
| 208 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi
ce()->height()); | 259 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi
ce()->height()); |
| 209 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size)
); | 260 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size)
); |
| 210 if (surface.get()) { | 261 if (surface.get()) { |
| 211 m_canvas->setSurface(surface.get()); | 262 m_canvas->setSurface(surface.get()); |
| 212 m_surfaceIsValid = true; | 263 m_surfaceIsValid = true; |
| 213 // FIXME: draw sad canvas picture into new buffer crbug.com/2438
42 | 264 // FIXME: draw sad canvas picture into new buffer crbug.com/2438
42 |
| 214 } else { | 265 } else { |
| 215 // Surface allocation failed. Set m_surfaceIsValid to false to | 266 // Surface allocation failed. Set m_surfaceIsValid to false to |
| 216 // trigger subsequent retry. | 267 // trigger subsequent retry. |
| 217 m_surfaceIsValid = false; | 268 m_surfaceIsValid = false; |
| 218 } | 269 } |
| 219 } | 270 } |
| 220 } | 271 } |
| 221 if (!m_surfaceIsValid) | 272 if (!m_surfaceIsValid) |
| 222 setRateLimitingEnabled(false); | 273 setRateLimitingEnabled(false); |
| 223 return m_surfaceIsValid; | 274 return m_surfaceIsValid; |
| 224 | |
| 225 } | 275 } |
| 226 | 276 |
| 227 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM
ailbox, WebKit::WebExternalBitmap* bitmap) | 277 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM
ailbox, WebKit::WebExternalBitmap* bitmap) |
| 228 { | 278 { |
| 229 ASSERT(!bitmap); | 279 ASSERT(!bitmap); |
| 230 if (!isValid()) | 280 if (!isValid()) |
| 231 return false; | 281 return false; |
| 232 // Release to skia textures that were previouosly released by the | 282 // Release to skia textures that were previouosly released by the |
| 233 // compositor. We do this before acquiring the next snapshot in | 283 // compositor. We do this before acquiring the next snapshot in |
| 234 // order to cap maximum gpu memory consumption. | 284 // order to cap maximum gpu memory consumption. |
| (...skipping 36 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); | 321 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); | 322 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); | 323 context()->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, mailboxInfo
->m_mailbox.name); |
| 274 context()->flush(); | 324 context()->flush(); |
| 275 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint(); | 325 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint(); |
| 276 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); | 326 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); |
| 277 // Because we are changing the texture binding without going through skia, | 327 // Because we are changing the texture binding without going through skia, |
| 278 // we must dirty the context. | 328 // we must dirty the context. |
| 279 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 329 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 280 | 330 |
| 331 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has |
| 332 // live mailboxes |
| 333 ASSERT(!mailboxInfo->m_parentLayerBridge); |
| 334 mailboxInfo->m_parentLayerBridge = this; |
| 281 *outMailbox = mailboxInfo->m_mailbox; | 335 *outMailbox = mailboxInfo->m_mailbox; |
| 282 return true; | 336 return true; |
| 283 } | 337 } |
| 284 | 338 |
| 285 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { | 339 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { |
| 340 ASSERT(!m_destructionInProgress); |
| 286 MailboxInfo* mailboxInfo; | 341 MailboxInfo* mailboxInfo; |
| 287 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai
lboxInfo++) { | 342 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai
lboxInfo++) { |
| 288 if (mailboxInfo->m_status == MailboxAvailable) { | 343 if (mailboxInfo->m_status == MailboxAvailable) { |
| 289 return mailboxInfo; | 344 return mailboxInfo; |
| 290 } | 345 } |
| 291 } | 346 } |
| 292 | 347 |
| 293 // No available mailbox: create one. | 348 // No available mailbox: create one. |
| 294 m_mailboxes.grow(m_mailboxes.size() + 1); | 349 m_mailboxes.grow(m_mailboxes.size() + 1); |
| 295 mailboxInfo = &m_mailboxes.last(); | 350 mailboxInfo = &m_mailboxes.last(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 306 } | 361 } |
| 307 | 362 |
| 308 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo
x& mailbox) | 363 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo
x& mailbox) |
| 309 { | 364 { |
| 310 Vector<MailboxInfo>::iterator mailboxInfo; | 365 Vector<MailboxInfo>::iterator mailboxInfo; |
| 311 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai
lboxInfo++) { | 366 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai
lboxInfo++) { |
| 312 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na
me))) { | 367 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na
me))) { |
| 313 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; | 368 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; |
| 314 ASSERT(mailboxInfo->m_status == MailboxInUse); | 369 ASSERT(mailboxInfo->m_status == MailboxInUse); |
| 315 mailboxInfo->m_status = MailboxReleased; | 370 mailboxInfo->m_status = MailboxReleased; |
| 371 // Trigger Canvas2DLayerBridge self-destruction if this is the |
| 372 // last live mailbox and the layer bridge is not externally |
| 373 // referenced. |
| 374 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); |
| 375 mailboxInfo->m_parentLayerBridge.clear(); |
| 316 return; | 376 return; |
| 317 } | 377 } |
| 318 } | 378 } |
| 319 } | 379 } |
| 320 | 380 |
| 321 WebKit::WebLayer* Canvas2DLayerBridge::layer() | 381 WebKit::WebLayer* Canvas2DLayerBridge::layer() |
| 322 { | 382 { |
| 323 ASSERT(m_layer); | 383 ASSERT(m_layer); |
| 324 return m_layer->layer(); | 384 return m_layer->layer(); |
| 325 } | 385 } |
| 326 | 386 |
| 327 void Canvas2DLayerBridge::contextAcquired() | 387 void Canvas2DLayerBridge::contextAcquired() |
| 328 { | 388 { |
| 389 ASSERT(!m_destructionInProgress); |
| 329 Canvas2DLayerManager::get().layerDidDraw(this); | 390 Canvas2DLayerManager::get().layerDidDraw(this); |
| 330 m_didRecordDrawCommand = true; | 391 m_didRecordDrawCommand = true; |
| 331 } | 392 } |
| 332 | 393 |
| 333 unsigned Canvas2DLayerBridge::backBufferTexture() | 394 unsigned Canvas2DLayerBridge::backBufferTexture() |
| 334 { | 395 { |
| 396 ASSERT(!m_destructionInProgress); |
| 335 if (!isValid()) | 397 if (!isValid()) |
| 336 return 0; | 398 return 0; |
| 337 contextAcquired(); | 399 contextAcquired(); |
| 338 m_canvas->flush(); | 400 m_canvas->flush(); |
| 339 m_context->flush(); | 401 m_context->flush(); |
| 340 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g
etDevice()->accessRenderTarget()); | 402 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g
etDevice()->accessRenderTarget()); |
| 341 if (renderTarget) { | 403 if (renderTarget) { |
| 342 return renderTarget->asTexture()->getTextureHandle(); | 404 return renderTarget->asTexture()->getTextureHandle(); |
| 343 } | 405 } |
| 344 return 0; | 406 return 0; |
| 345 } | 407 } |
| 346 | 408 |
| 347 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 409 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 348 // This copy constructor should only be used for Vector reallocation | 410 // This copy constructor should only be used for Vector reallocation |
| 349 // Assuming 'other' is to be destroyed, we swap m_image ownership | 411 // Assuming 'other' is to be destroyed, we swap m_image ownership |
| 350 // rather than do a refcount dance. | 412 // rather than do a refcount dance. |
| 351 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 413 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 352 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); | 414 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); |
| 353 m_status = other.m_status; | 415 m_status = other.m_status; |
| 354 } | 416 } |
| 355 | 417 |
| 356 } | 418 } |
| OLD | NEW |