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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 return 0; | 52 return 0; |
| 53 gr->resetContext(); | 53 gr->resetContext(); |
| 54 SkImage::Info info; | 54 SkImage::Info info; |
| 55 info.fWidth = size.width(); | 55 info.fWidth = size.width(); |
| 56 info.fHeight = size.height(); | 56 info.fHeight = size.height(); |
| 57 info.fColorType = SkImage::kPMColor_ColorType; | 57 info.fColorType = SkImage::kPMColor_ColorType; |
| 58 info.fAlphaType = SkImage::kPremul_AlphaType; | 58 info.fAlphaType = SkImage::kPremul_AlphaType; |
| 59 return SkSurface::NewRenderTarget(gr, info); | 59 return SkSurface::NewRenderTarget(gr, info); |
| 60 } | 60 } |
| 61 | 61 |
| 62 PassOwnPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC ontext3D> context, const IntSize& size, OpacityMode opacityMode) | 62 Canvas2DLayerBridgePtr Canvas2DLayerBridge::create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, OpacityMode opacityMode) |
| 63 { | 63 { |
| 64 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 64 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
| 65 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size)); | 65 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size)); |
| 66 if (!surface.get()) | 66 if (!surface.get()) { |
| 67 return PassOwnPtr<Canvas2DLayerBridge>(); | 67 Canvas2DLayerBridgePtr ptr; |
| 68 return ptr; | |
| 69 } | |
| 68 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get()); | 70 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get()); |
| 69 OwnPtr<Canvas2DLayerBridge> layerBridge = adoptPtr(new Canvas2DLayerBridge(c ontext, canvas, opacityMode)); | 71 Canvas2DLayerBridgePtr layerBridge(new Canvas2DLayerBridge(context, canvas, opacityMode)); |
| 70 return layerBridge.release(); | 72 return layerBridge; |
| 71 } | 73 } |
| 72 | 74 |
| 73 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) | 75 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) |
| 74 : m_canvas(canvas) | 76 : m_canvas(canvas) |
| 75 , m_context(context) | 77 , m_context(context) |
| 76 , m_bytesAllocated(0) | 78 , m_bytesAllocated(0) |
| 77 , m_didRecordDrawCommand(false) | 79 , m_didRecordDrawCommand(false) |
| 78 , m_surfaceIsValid(true) | 80 , m_surfaceIsValid(true) |
| 79 , m_framesPending(0) | 81 , m_framesPending(0) |
| 80 , m_rateLimitingEnabled(false) | 82 , m_rateLimitingEnabled(false) |
| 83 , m_destructionInProgress(false) | |
| 81 , m_next(0) | 84 , m_next(0) |
| 82 , m_prev(0) | 85 , m_prev(0) |
| 83 , m_lastImageId(0) | 86 , m_lastImageId(0) |
| 84 { | 87 { |
| 85 ASSERT(m_canvas); | 88 ASSERT(m_canvas); |
| 86 // Used by browser tests to detect the use of a Canvas2DLayerBridge. | 89 // Used by browser tests to detect the use of a Canvas2DLayerBridge. |
| 87 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 90 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
| 88 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this)); | 91 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this)); |
| 89 m_layer->setOpaque(opacityMode == Opaque); | 92 m_layer->setOpaque(opacityMode == Opaque); |
| 90 m_layer->setBlendBackgroundColor(opacityMode != Opaque); | 93 m_layer->setBlendBackgroundColor(opacityMode != Opaque); |
| 91 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 94 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 92 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 95 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 93 m_canvas->setNotificationClient(this); | 96 m_canvas->setNotificationClient(this); |
| 94 } | 97 } |
| 95 | 98 |
| 99 void Canvas2DLayerBridge::destroy() | |
| 100 { | |
| 101 ASSERT(!m_destructionInProgress); | |
| 102 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | |
| 103 m_canvas->setNotificationClient(0); | |
| 104 m_layer->clearTexture(); | |
| 105 // Orphan the layer so the compositor will stop requesting new texture mailb oxes. | |
| 106 m_layer->layer()->removeFromParent(); | |
|
Justin Novosad
2013/08/20 15:51:10
This line appears to be necessary if we want the m
danakj
2013/08/20 16:57:08
You could also set the texture mailbox on the laye
piman
2013/08/20 17:03:07
I'll let the blink experts confirm, but the fact t
| |
| 107 Canvas2DLayerManager::get().layerToBeDestroyed(this); | |
| 108 m_destructionInProgress = true; | |
| 109 deleteIfPossible(); | |
| 110 } | |
| 111 | |
| 112 void Canvas2DLayerBridge::deleteIfPossible() | |
| 113 { | |
| 114 // If we can't delete now, destruction is deferred until mailboxReleased | |
| 115 // is called on all remaining active mailboxes. | |
| 116 ASSERT(m_destructionInProgress); | |
| 117 bool deleteIsPossible = true; | |
| 118 Vector<MailboxInfo>::iterator mailboxInfo; | |
| 119 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | |
| 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 mailboxInfo->m_image.reset(0); | |
| 128 mailboxInfo->m_status = MailboxAvailable; | |
| 129 } else if (mailboxInfo->m_status == MailboxInUse) { | |
| 130 deleteIsPossible = false; | |
| 131 } | |
| 132 } | |
| 133 if (deleteIsPossible) | |
| 134 delete this; | |
|
piman
2013/08/20 17:03:07
Could it make sense to make Canvas2DLayerBridge re
Stephen White
2013/08/20 17:32:18
+1000 to this. This poor-man's refcounting here lo
| |
| 135 } | |
| 136 | |
| 96 Canvas2DLayerBridge::~Canvas2DLayerBridge() | 137 Canvas2DLayerBridge::~Canvas2DLayerBridge() |
| 97 { | 138 { |
| 98 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 139 ASSERT(m_destructionInProgress); |
| 99 Canvas2DLayerManager::get().layerToBeDestroyed(this); | |
| 100 m_canvas->setNotificationClient(0); | |
| 101 m_mailboxes.clear(); | 140 m_mailboxes.clear(); |
| 102 m_layer->clearTexture(); | |
| 103 m_layer.clear(); | 141 m_layer.clear(); |
| 104 } | 142 } |
| 105 | 143 |
| 106 void Canvas2DLayerBridge::limitPendingFrames() | 144 void Canvas2DLayerBridge::limitPendingFrames() |
| 107 { | 145 { |
| 146 ASSERT(!m_destructionInProgress); | |
| 108 if (m_didRecordDrawCommand) { | 147 if (m_didRecordDrawCommand) { |
| 109 m_framesPending++; | 148 m_framesPending++; |
| 110 m_didRecordDrawCommand = false; | 149 m_didRecordDrawCommand = false; |
| 111 if (m_framesPending > 1) { | 150 if (m_framesPending > 1) { |
| 112 // Turn on the rate limiter if this layer tends to accumulate a | 151 // Turn on the rate limiter if this layer tends to accumulate a |
| 113 // non-discardable multi-frame backlog of draw commands. | 152 // non-discardable multi-frame backlog of draw commands. |
| 114 setRateLimitingEnabled(true); | 153 setRateLimitingEnabled(true); |
| 115 } | 154 } |
| 116 if (m_rateLimitingEnabled) { | 155 if (m_rateLimitingEnabled) { |
| 117 flush(); | 156 flush(); |
| 118 } | 157 } |
| 119 } | 158 } |
| 120 } | 159 } |
| 121 | 160 |
| 122 void Canvas2DLayerBridge::prepareForDraw() | 161 void Canvas2DLayerBridge::prepareForDraw() |
| 123 { | 162 { |
| 163 ASSERT(!m_destructionInProgress); | |
| 124 ASSERT(m_layer); | 164 ASSERT(m_layer); |
| 125 if (!isValid()) { | 165 if (!isValid()) { |
| 126 if (m_canvas) { | 166 if (m_canvas) { |
| 127 // drop pending commands because there is no surface to draw to | 167 // drop pending commands because there is no surface to draw to |
| 128 m_canvas->silentFlush(); | 168 m_canvas->silentFlush(); |
| 129 } | 169 } |
| 130 return; | 170 return; |
| 131 } | 171 } |
| 132 m_context->makeContextCurrent(); | 172 m_context->makeContextCurrent(); |
| 133 } | 173 } |
| 134 | 174 |
| 135 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) | 175 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) |
| 136 { | 176 { |
| 177 ASSERT(!m_destructionInProgress); | |
| 137 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; | 178 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; |
| 138 m_bytesAllocated = bytesAllocated; | 179 m_bytesAllocated = bytesAllocated; |
| 139 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); | 180 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); |
| 140 } | 181 } |
| 141 | 182 |
| 142 size_t Canvas2DLayerBridge::storageAllocatedForRecording() | 183 size_t Canvas2DLayerBridge::storageAllocatedForRecording() |
| 143 { | 184 { |
| 185 ASSERT(!m_destructionInProgress); | |
| 144 return m_canvas->storageAllocatedForRecording(); | 186 return m_canvas->storageAllocatedForRecording(); |
| 145 } | 187 } |
| 146 | 188 |
| 147 void Canvas2DLayerBridge::flushedDrawCommands() | 189 void Canvas2DLayerBridge::flushedDrawCommands() |
| 148 { | 190 { |
| 191 ASSERT(!m_destructionInProgress); | |
| 149 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); | 192 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); |
| 150 m_framesPending = 0; | 193 m_framesPending = 0; |
| 151 } | 194 } |
| 152 | 195 |
| 153 void Canvas2DLayerBridge::skippedPendingDrawCommands() | 196 void Canvas2DLayerBridge::skippedPendingDrawCommands() |
| 154 { | 197 { |
| 198 ASSERT(!m_destructionInProgress); | |
| 155 // Stop triggering the rate limiter if SkDeferredCanvas is detecting | 199 // Stop triggering the rate limiter if SkDeferredCanvas is detecting |
| 156 // and optimizing overdraw. | 200 // and optimizing overdraw. |
| 157 setRateLimitingEnabled(false); | 201 setRateLimitingEnabled(false); |
| 158 flushedDrawCommands(); | 202 flushedDrawCommands(); |
| 159 } | 203 } |
| 160 | 204 |
| 161 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) | 205 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) |
| 162 { | 206 { |
| 207 ASSERT(!m_destructionInProgress || !enabled); | |
| 163 if (m_rateLimitingEnabled != enabled) { | 208 if (m_rateLimitingEnabled != enabled) { |
| 164 m_rateLimitingEnabled = enabled; | 209 m_rateLimitingEnabled = enabled; |
| 165 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 210 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 166 } | 211 } |
| 167 } | 212 } |
| 168 | 213 |
| 169 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) | 214 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) |
| 170 { | 215 { |
| 216 ASSERT(!m_destructionInProgress); | |
| 171 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); | 217 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); |
| 172 if (bytesFreed) | 218 if (bytesFreed) |
| 173 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed)); | 219 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed)); |
| 174 m_bytesAllocated -= bytesFreed; | 220 m_bytesAllocated -= bytesFreed; |
| 175 return bytesFreed; | 221 return bytesFreed; |
| 176 } | 222 } |
| 177 | 223 |
| 178 void Canvas2DLayerBridge::flush() | 224 void Canvas2DLayerBridge::flush() |
| 179 { | 225 { |
| 226 ASSERT(!m_destructionInProgress); | |
| 180 if (m_canvas->hasPendingCommands()) { | 227 if (m_canvas->hasPendingCommands()) { |
| 181 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); | 228 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); |
| 182 m_canvas->flush(); | 229 m_canvas->flush(); |
| 183 } | 230 } |
| 184 } | 231 } |
| 185 | 232 |
| 186 WebGraphicsContext3D* Canvas2DLayerBridge::context() | 233 WebGraphicsContext3D* Canvas2DLayerBridge::context() |
| 187 { | 234 { |
| 188 // Check on m_layer is necessary because context() may be called during | 235 // Check on m_layer is necessary because context() may be called during |
| 189 // the destruction of m_layer | 236 // the destruction of m_layer |
| 190 if (m_layer) { | 237 if (m_layer && !m_destructionInProgress) { |
| 191 isValid(); // To ensure rate limiter is disabled if context is lost. | 238 isValid(); // To ensure rate limiter is disabled if context is lost. |
| 192 } | 239 } |
| 193 return m_context->webContext(); | 240 return m_context->webContext(); |
| 194 } | 241 } |
| 195 | 242 |
| 196 bool Canvas2DLayerBridge::isValid() | 243 bool Canvas2DLayerBridge::isValid() |
| 197 { | 244 { |
| 245 ASSERT(!m_destructionInProgress); | |
| 198 ASSERT(m_layer); | 246 ASSERT(m_layer); |
| 199 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { | 247 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { |
| 200 // Attempt to recover. | 248 // Attempt to recover. |
| 201 m_layer->clearTexture(); | 249 m_layer->clearTexture(); |
| 202 m_mailboxes.clear(); | 250 m_mailboxes.clear(); |
| 203 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ; | 251 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ; |
| 204 if (!sharedContext || sharedContext->webContext()->isContextLost()) { | 252 if (!sharedContext || sharedContext->webContext()->isContextLost()) { |
| 205 m_surfaceIsValid = false; | 253 m_surfaceIsValid = false; |
| 206 } else { | 254 } else { |
| 207 m_context = sharedContext; | 255 m_context = sharedContext; |
| 208 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); | 256 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); |
| 209 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) ); | 257 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) ); |
| 210 if (surface.get()) { | 258 if (surface.get()) { |
| 211 m_canvas->setSurface(surface.get()); | 259 m_canvas->setSurface(surface.get()); |
| 212 m_surfaceIsValid = true; | 260 m_surfaceIsValid = true; |
| 213 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 | 261 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 |
| 214 } else { | 262 } else { |
| 215 // Surface allocation failed. Set m_surfaceIsValid to false to | 263 // Surface allocation failed. Set m_surfaceIsValid to false to |
| 216 // trigger subsequent retry. | 264 // trigger subsequent retry. |
| 217 m_surfaceIsValid = false; | 265 m_surfaceIsValid = false; |
| 218 } | 266 } |
| 219 } | 267 } |
| 220 } | 268 } |
| 221 if (!m_surfaceIsValid) | 269 if (!m_surfaceIsValid) |
| 222 setRateLimitingEnabled(false); | 270 setRateLimitingEnabled(false); |
| 223 return m_surfaceIsValid; | 271 return m_surfaceIsValid; |
| 224 | |
| 225 } | 272 } |
| 226 | 273 |
| 227 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap) | 274 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap) |
| 228 { | 275 { |
| 276 ASSERT(!m_destructionInProgress) | |
| 229 ASSERT(!bitmap); | 277 ASSERT(!bitmap); |
| 230 if (!isValid()) | 278 if (!isValid()) |
| 231 return false; | 279 return false; |
| 232 // Release to skia textures that were previouosly released by the | 280 // Release to skia textures that were previouosly released by the |
| 233 // compositor. We do this before acquiring the next snapshot in | 281 // compositor. We do this before acquiring the next snapshot in |
| 234 // order to cap maximum gpu memory consumption. | 282 // order to cap maximum gpu memory consumption. |
| 235 m_context->makeContextCurrent(); | 283 m_context->makeContextCurrent(); |
| 236 flush(); | 284 flush(); |
| 237 Vector<MailboxInfo>::iterator mailboxInfo; | 285 Vector<MailboxInfo>::iterator mailboxInfo; |
| 238 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 286 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); | 324 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); |
| 277 // Because we are changing the texture binding without going through skia, | 325 // Because we are changing the texture binding without going through skia, |
| 278 // we must dirty the context. | 326 // we must dirty the context. |
| 279 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 327 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 280 | 328 |
| 281 *outMailbox = mailboxInfo->m_mailbox; | 329 *outMailbox = mailboxInfo->m_mailbox; |
| 282 return true; | 330 return true; |
| 283 } | 331 } |
| 284 | 332 |
| 285 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { | 333 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { |
| 334 ASSERT(!m_destructionInProgress); | |
| 286 MailboxInfo* mailboxInfo; | 335 MailboxInfo* mailboxInfo; |
| 287 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 336 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| 288 if (mailboxInfo->m_status == MailboxAvailable) { | 337 if (mailboxInfo->m_status == MailboxAvailable) { |
| 289 return mailboxInfo; | 338 return mailboxInfo; |
| 290 } | 339 } |
| 291 } | 340 } |
| 292 | 341 |
| 293 // No available mailbox: create one. | 342 // No available mailbox: create one. |
| 294 m_mailboxes.grow(m_mailboxes.size() + 1); | 343 m_mailboxes.grow(m_mailboxes.size() + 1); |
| 295 mailboxInfo = &m_mailboxes.last(); | 344 mailboxInfo = &m_mailboxes.last(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 309 { | 358 { |
| 310 Vector<MailboxInfo>::iterator mailboxInfo; | 359 Vector<MailboxInfo>::iterator mailboxInfo; |
| 311 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { | 360 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { |
| 312 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) { | 361 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) { |
| 313 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; | 362 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; |
| 314 ASSERT(mailboxInfo->m_status == MailboxInUse); | 363 ASSERT(mailboxInfo->m_status == MailboxInUse); |
| 315 mailboxInfo->m_status = MailboxReleased; | 364 mailboxInfo->m_status = MailboxReleased; |
| 316 return; | 365 return; |
| 317 } | 366 } |
| 318 } | 367 } |
| 368 if (m_destructionInProgress) | |
| 369 deleteIfPossible(); | |
| 319 } | 370 } |
| 320 | 371 |
| 321 WebKit::WebLayer* Canvas2DLayerBridge::layer() | 372 WebKit::WebLayer* Canvas2DLayerBridge::layer() |
| 322 { | 373 { |
| 374 ASSERT(!m_destructionInProgress); | |
| 323 ASSERT(m_layer); | 375 ASSERT(m_layer); |
| 324 return m_layer->layer(); | 376 return m_layer->layer(); |
| 325 } | 377 } |
| 326 | 378 |
| 327 void Canvas2DLayerBridge::contextAcquired() | 379 void Canvas2DLayerBridge::contextAcquired() |
| 328 { | 380 { |
| 381 ASSERT(!m_destructionInProgress); | |
| 329 Canvas2DLayerManager::get().layerDidDraw(this); | 382 Canvas2DLayerManager::get().layerDidDraw(this); |
| 330 m_didRecordDrawCommand = true; | 383 m_didRecordDrawCommand = true; |
| 331 } | 384 } |
| 332 | 385 |
| 333 unsigned Canvas2DLayerBridge::backBufferTexture() | 386 unsigned Canvas2DLayerBridge::backBufferTexture() |
| 334 { | 387 { |
| 388 ASSERT(!m_destructionInProgress); | |
| 335 if (!isValid()) | 389 if (!isValid()) |
| 336 return 0; | 390 return 0; |
| 337 contextAcquired(); | 391 contextAcquired(); |
| 338 m_canvas->flush(); | 392 m_canvas->flush(); |
| 339 m_context->flush(); | 393 m_context->flush(); |
| 340 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); | 394 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); |
| 341 if (renderTarget) { | 395 if (renderTarget) { |
| 342 return renderTarget->asTexture()->getTextureHandle(); | 396 return renderTarget->asTexture()->getTextureHandle(); |
| 343 } | 397 } |
| 344 return 0; | 398 return 0; |
| 345 } | 399 } |
| 346 | 400 |
| 347 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 401 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 348 // This copy constructor should only be used for Vector reallocation | 402 // This copy constructor should only be used for Vector reallocation |
| 349 // Assuming 'other' is to be destroyed, we swap m_image ownership | 403 // Assuming 'other' is to be destroyed, we swap m_image ownership |
| 350 // rather than do a refcount dance. | 404 // rather than do a refcount dance. |
| 351 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 405 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 352 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); | 406 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); |
| 353 m_status = other.m_status; | 407 m_status = other.m_status; |
| 354 } | 408 } |
| 355 | 409 |
| 356 } | 410 } |
| OLD | NEW |