Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp

Issue 22929012: Change Canvas2DLayerBridge to stay alive until last mailbox is returned. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixing unit tests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC ontext3D> 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 return PassRefPtr<Canvas2DLayerBridge>();
68 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get()); 68 SkDeferredCanvas* canvas = SkDeferredCanvas::Create(surface.get());
69 OwnPtr<Canvas2DLayerBridge> layerBridge = adoptPtr(new Canvas2DLayerBridge(c ontext, canvas, opacityMode)); 69 RefPtr<Canvas2DLayerBridge> layerBridge = adoptRef(new Canvas2DLayerBridge(c ontext, canvas, opacityMode));
70 return layerBridge.release(); 70 return layerBridge.release();
71 } 71 }
72 72
73 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) 73 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode)
74 : m_canvas(canvas) 74 : m_canvas(canvas)
75 , m_context(context) 75 , m_context(context)
76 , m_bytesAllocated(0) 76 , m_bytesAllocated(0)
77 , m_didRecordDrawCommand(false) 77 , m_didRecordDrawCommand(false)
78 , m_surfaceIsValid(true) 78 , m_surfaceIsValid(true)
79 , m_framesPending(0) 79 , m_framesPending(0)
80 , m_liveMailboxCount(0)
81 , m_destructionInProgress(false)
80 , m_rateLimitingEnabled(false) 82 , m_rateLimitingEnabled(false)
81 , m_next(0) 83 , m_next(0)
82 , m_prev(0) 84 , m_prev(0)
83 , m_lastImageId(0) 85 , m_lastImageId(0)
84 { 86 {
85 ASSERT(m_canvas); 87 ASSERT(m_canvas);
86 // Used by browser tests to detect the use of a Canvas2DLayerBridge. 88 // Used by browser tests to detect the use of a Canvas2DLayerBridge.
87 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); 89 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation");
88 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this)); 90 m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createE xternalTextureLayer(this));
89 m_layer->setOpaque(opacityMode == Opaque); 91 m_layer->setOpaque(opacityMode == Opaque);
90 m_layer->setBlendBackgroundColor(opacityMode != Opaque); 92 m_layer->setBlendBackgroundColor(opacityMode != Opaque);
91 GraphicsLayer::registerContentsLayer(m_layer->layer()); 93 GraphicsLayer::registerContentsLayer(m_layer->layer());
92 m_layer->setRateLimitContext(m_rateLimitingEnabled); 94 m_layer->setRateLimitContext(m_rateLimitingEnabled);
93 m_canvas->setNotificationClient(this); 95 m_canvas->setNotificationClient(this);
94 } 96 }
95 97
96 Canvas2DLayerBridge::~Canvas2DLayerBridge() 98 Canvas2DLayerBridge::~Canvas2DLayerBridge()
97 { 99 {
98 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); 100 ASSERT(m_destructionInProgress);
99 Canvas2DLayerManager::get().layerToBeDestroyed(this); 101 m_layer.clear();
100 m_canvas->setNotificationClient(0); 102 Vector<MailboxInfo>::iterator mailboxInfo;
103 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
104 ASSERT(mailboxInfo->m_status != MailboxInUse);
105 if (mailboxInfo->m_status == MailboxReleased) {
106 if (mailboxInfo->m_mailbox.syncPoint) {
107 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint);
108 mailboxInfo->m_mailbox.syncPoint = 0;
109 }
110 // Invalidate texture state in case the compositor altered it since the copy-on-write.
111 mailboxInfo->m_image->getTexture()->invalidateCachedState();
112 }
113 }
101 m_mailboxes.clear(); 114 m_mailboxes.clear();
102 m_layer->clearTexture(); 115 }
103 m_layer.clear(); 116
117 void Canvas2DLayerBridge::deref()
118 {
119 if (this->refCount() == m_liveMailboxCount + 1 && !m_destructionInProgress) {
120 // removing last external reference -> initiate destruction
121 m_destructionInProgress = true;
122 GraphicsLayer::unregisterContentsLayer(m_layer->layer());
123 m_canvas->setNotificationClient(0);
124 m_layer->clearTexture();
125 Canvas2DLayerManager::get().layerToBeDestroyed(this);
126 }
127 RefCounted<Canvas2DLayerBridge>::deref();
104 } 128 }
105 129
106 void Canvas2DLayerBridge::limitPendingFrames() 130 void Canvas2DLayerBridge::limitPendingFrames()
107 { 131 {
132 ASSERT(!m_destructionInProgress);
108 if (m_didRecordDrawCommand) { 133 if (m_didRecordDrawCommand) {
109 m_framesPending++; 134 m_framesPending++;
110 m_didRecordDrawCommand = false; 135 m_didRecordDrawCommand = false;
111 if (m_framesPending > 1) { 136 if (m_framesPending > 1) {
112 // Turn on the rate limiter if this layer tends to accumulate a 137 // Turn on the rate limiter if this layer tends to accumulate a
113 // non-discardable multi-frame backlog of draw commands. 138 // non-discardable multi-frame backlog of draw commands.
114 setRateLimitingEnabled(true); 139 setRateLimitingEnabled(true);
115 } 140 }
116 if (m_rateLimitingEnabled) { 141 if (m_rateLimitingEnabled) {
117 flush(); 142 flush();
118 } 143 }
119 } 144 }
120 } 145 }
121 146
122 void Canvas2DLayerBridge::prepareForDraw() 147 void Canvas2DLayerBridge::prepareForDraw()
123 { 148 {
149 ASSERT(!m_destructionInProgress);
124 ASSERT(m_layer); 150 ASSERT(m_layer);
125 if (!isValid()) { 151 if (!isValid()) {
126 if (m_canvas) { 152 if (m_canvas) {
127 // drop pending commands because there is no surface to draw to 153 // drop pending commands because there is no surface to draw to
128 m_canvas->silentFlush(); 154 m_canvas->silentFlush();
129 } 155 }
130 return; 156 return;
131 } 157 }
132 m_context->makeContextCurrent(); 158 m_context->makeContextCurrent();
133 } 159 }
134 160
135 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) 161 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted)
136 { 162 {
163 ASSERT(!m_destructionInProgress);
137 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; 164 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated;
138 m_bytesAllocated = bytesAllocated; 165 m_bytesAllocated = bytesAllocated;
139 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta); 166 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, delta);
140 } 167 }
141 168
142 size_t Canvas2DLayerBridge::storageAllocatedForRecording() 169 size_t Canvas2DLayerBridge::storageAllocatedForRecording()
143 { 170 {
171 ASSERT(!m_destructionInProgress);
144 return m_canvas->storageAllocatedForRecording(); 172 return m_canvas->storageAllocatedForRecording();
145 } 173 }
146 174
147 void Canvas2DLayerBridge::flushedDrawCommands() 175 void Canvas2DLayerBridge::flushedDrawCommands()
148 { 176 {
177 ASSERT(!m_destructionInProgress);
149 storageAllocatedForRecordingChanged(storageAllocatedForRecording()); 178 storageAllocatedForRecordingChanged(storageAllocatedForRecording());
150 m_framesPending = 0; 179 m_framesPending = 0;
151 } 180 }
152 181
153 void Canvas2DLayerBridge::skippedPendingDrawCommands() 182 void Canvas2DLayerBridge::skippedPendingDrawCommands()
154 { 183 {
184 ASSERT(!m_destructionInProgress);
155 // Stop triggering the rate limiter if SkDeferredCanvas is detecting 185 // Stop triggering the rate limiter if SkDeferredCanvas is detecting
156 // and optimizing overdraw. 186 // and optimizing overdraw.
157 setRateLimitingEnabled(false); 187 setRateLimitingEnabled(false);
158 flushedDrawCommands(); 188 flushedDrawCommands();
159 } 189 }
160 190
161 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled) 191 void Canvas2DLayerBridge::setRateLimitingEnabled(bool enabled)
162 { 192 {
193 ASSERT(!m_destructionInProgress || !enabled);
163 if (m_rateLimitingEnabled != enabled) { 194 if (m_rateLimitingEnabled != enabled) {
164 m_rateLimitingEnabled = enabled; 195 m_rateLimitingEnabled = enabled;
165 m_layer->setRateLimitContext(m_rateLimitingEnabled); 196 m_layer->setRateLimitContext(m_rateLimitingEnabled);
166 } 197 }
167 } 198 }
168 199
169 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree) 200 size_t Canvas2DLayerBridge::freeMemoryIfPossible(size_t bytesToFree)
170 { 201 {
202 ASSERT(!m_destructionInProgress);
171 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree); 203 size_t bytesFreed = m_canvas->freeMemoryIfPossible(bytesToFree);
172 if (bytesFreed) 204 if (bytesFreed)
173 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed)); 205 Canvas2DLayerManager::get().layerAllocatedStorageChanged(this, -((intptr _t)bytesFreed));
174 m_bytesAllocated -= bytesFreed; 206 m_bytesAllocated -= bytesFreed;
175 return bytesFreed; 207 return bytesFreed;
176 } 208 }
177 209
178 void Canvas2DLayerBridge::flush() 210 void Canvas2DLayerBridge::flush()
179 { 211 {
212 ASSERT(!m_destructionInProgress);
180 if (m_canvas->hasPendingCommands()) { 213 if (m_canvas->hasPendingCommands()) {
181 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush"); 214 TRACE_EVENT0("cc", "Canvas2DLayerBridge::flush");
182 m_canvas->flush(); 215 m_canvas->flush();
183 } 216 }
184 } 217 }
185 218
186 WebGraphicsContext3D* Canvas2DLayerBridge::context() 219 WebGraphicsContext3D* Canvas2DLayerBridge::context()
187 { 220 {
188 // Check on m_layer is necessary because context() may be called during 221 // Check on m_layer is necessary because context() may be called during
189 // the destruction of m_layer 222 // the destruction of m_layer
190 if (m_layer) { 223 if (m_layer) {
191 isValid(); // To ensure rate limiter is disabled if context is lost. 224 isValid(); // To ensure rate limiter is disabled if context is lost.
192 } 225 }
193 return m_context->webContext(); 226 return m_context->webContext();
194 } 227 }
195 228
196 bool Canvas2DLayerBridge::isValid() 229 bool Canvas2DLayerBridge::isValid()
197 { 230 {
198 ASSERT(m_layer); 231 ASSERT(m_layer);
232 if (m_destructionInProgress)
233 return false;
199 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { 234 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) {
200 // Attempt to recover. 235 // Attempt to recover.
201 m_layer->clearTexture(); 236 m_layer->clearTexture();
202 m_mailboxes.clear(); 237 m_mailboxes.clear();
203 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ; 238 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get() ;
204 if (!sharedContext || sharedContext->webContext()->isContextLost()) { 239 if (!sharedContext || sharedContext->webContext()->isContextLost()) {
205 m_surfaceIsValid = false; 240 m_surfaceIsValid = false;
206 } else { 241 } else {
207 m_context = sharedContext; 242 m_context = sharedContext;
208 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); 243 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height());
209 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) ); 244 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size) );
210 if (surface.get()) { 245 if (surface.get()) {
211 m_canvas->setSurface(surface.get()); 246 m_canvas->setSurface(surface.get());
212 m_surfaceIsValid = true; 247 m_surfaceIsValid = true;
213 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 248 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42
214 } else { 249 } else {
215 // Surface allocation failed. Set m_surfaceIsValid to false to 250 // Surface allocation failed. Set m_surfaceIsValid to false to
216 // trigger subsequent retry. 251 // trigger subsequent retry.
217 m_surfaceIsValid = false; 252 m_surfaceIsValid = false;
218 } 253 }
219 } 254 }
220 } 255 }
221 if (!m_surfaceIsValid) 256 if (!m_surfaceIsValid)
222 setRateLimitingEnabled(false); 257 setRateLimitingEnabled(false);
223 return m_surfaceIsValid; 258 return m_surfaceIsValid;
224
225 } 259 }
226 260
227 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap) 261 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox, WebKit::WebExternalBitmap* bitmap)
228 { 262 {
263 if (m_destructionInProgress) {
264 const WebKit::WebExternalTextureMailbox emptyMailbox;
265 *outMailbox = emptyMailbox;
266 return true;
danakj 2013/08/20 21:45:17 Should this be false, re piman's earlier comment?
danakj 2013/08/20 21:46:15 Actually I'm not sure why this should be false, th
267 }
229 ASSERT(!bitmap); 268 ASSERT(!bitmap);
230 if (!isValid()) 269 if (!isValid())
231 return false; 270 return false;
232 // Release to skia textures that were previouosly released by the 271 // Release to skia textures that were previouosly released by the
233 // compositor. We do this before acquiring the next snapshot in 272 // compositor. We do this before acquiring the next snapshot in
234 // order to cap maximum gpu memory consumption. 273 // order to cap maximum gpu memory consumption.
235 m_context->makeContextCurrent(); 274 m_context->makeContextCurrent();
236 flush(); 275 flush();
237 Vector<MailboxInfo>::iterator mailboxInfo; 276 Vector<MailboxInfo>::iterator mailboxInfo;
238 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { 277 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); 310 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); 311 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); 312 context()->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, mailboxInfo ->m_mailbox.name);
274 context()->flush(); 313 context()->flush();
275 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint(); 314 mailboxInfo->m_mailbox.syncPoint = context()->insertSyncPoint();
276 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); 315 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
277 // Because we are changing the texture binding without going through skia, 316 // Because we are changing the texture binding without going through skia,
278 // we must dirty the context. 317 // we must dirty the context.
279 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState); 318 m_context->grContext()->resetContext(kTextureBinding_GrGLBackendState);
280 319
320 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has
321 // live mailboxes
322 ASSERT(!mailboxInfo->m_parentLayerBridge);
323 this->ref(); // Because we are adopting an already referenced object
324 mailboxInfo->m_parentLayerBridge = adoptRef(this);
325 m_liveMailboxCount++;
281 *outMailbox = mailboxInfo->m_mailbox; 326 *outMailbox = mailboxInfo->m_mailbox;
282 return true; 327 return true;
283 } 328 }
284 329
285 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { 330 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() {
331 ASSERT(!m_destructionInProgress);
286 MailboxInfo* mailboxInfo; 332 MailboxInfo* mailboxInfo;
287 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { 333 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
288 if (mailboxInfo->m_status == MailboxAvailable) { 334 if (mailboxInfo->m_status == MailboxAvailable) {
289 return mailboxInfo; 335 return mailboxInfo;
290 } 336 }
291 } 337 }
292 338
293 // No available mailbox: create one. 339 // No available mailbox: create one.
294 m_mailboxes.grow(m_mailboxes.size() + 1); 340 m_mailboxes.grow(m_mailboxes.size() + 1);
295 mailboxInfo = &m_mailboxes.last(); 341 mailboxInfo = &m_mailboxes.last();
(...skipping 10 matching lines...) Expand all
306 } 352 }
307 353
308 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo x& mailbox) 354 void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo x& mailbox)
309 { 355 {
310 Vector<MailboxInfo>::iterator mailboxInfo; 356 Vector<MailboxInfo>::iterator mailboxInfo;
311 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { 357 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
312 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) { 358 if (!memcmp(mailboxInfo->m_mailbox.name, mailbox.name, sizeof(mailbox.na me))) {
313 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; 359 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint;
314 ASSERT(mailboxInfo->m_status == MailboxInUse); 360 ASSERT(mailboxInfo->m_status == MailboxInUse);
315 mailboxInfo->m_status = MailboxReleased; 361 mailboxInfo->m_status = MailboxReleased;
362 // Trigger Canvas2DLayerBridge self-destruction if this is the
363 // last live mailbox and the layer bridge is not externally
364 // referenced.
365 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this);
366 m_liveMailboxCount--;
367 mailboxInfo->m_parentLayerBridge.clear();
316 return; 368 return;
317 } 369 }
318 } 370 }
319 } 371 }
320 372
321 WebKit::WebLayer* Canvas2DLayerBridge::layer() 373 WebKit::WebLayer* Canvas2DLayerBridge::layer()
322 { 374 {
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698