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 19 matching lines...) Expand all Loading... | |
| 30 #include "GrContext.h" | 30 #include "GrContext.h" |
| 31 #include "SkDevice.h" | 31 #include "SkDevice.h" |
| 32 #include "SkSurface.h" | 32 #include "SkSurface.h" |
| 33 #include "platform/TraceEvent.h" | 33 #include "platform/TraceEvent.h" |
| 34 #include "platform/graphics/Canvas2DLayerManager.h" | 34 #include "platform/graphics/Canvas2DLayerManager.h" |
| 35 #include "platform/graphics/GraphicsLayer.h" | 35 #include "platform/graphics/GraphicsLayer.h" |
| 36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "public/platform/WebCompositorSupport.h" | 37 #include "public/platform/WebCompositorSupport.h" |
| 38 #include "public/platform/WebGraphicsContext3D.h" | 38 #include "public/platform/WebGraphicsContext3D.h" |
| 39 #include "public/platform/WebGraphicsContext3DProvider.h" | 39 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 40 #include "wtf/MainThread.h" | |
| 40 #include "wtf/RefCountedLeakCounter.h" | 41 #include "wtf/RefCountedLeakCounter.h" |
| 41 | 42 |
| 42 using blink::WebExternalTextureLayer; | 43 using blink::WebExternalTextureLayer; |
| 43 using blink::WebGraphicsContext3D; | 44 using blink::WebGraphicsContext3D; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 enum { | 47 enum { |
| 47 InvalidMailboxIndex = -1, | 48 InvalidMailboxIndex = -1, |
| 48 }; | 49 }; |
| 49 | 50 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 return hasReleasedMailbox() ? &m_mailboxes[m_releasedMailboxInfoIndex] : 0; | 281 return hasReleasedMailbox() ? &m_mailboxes[m_releasedMailboxInfoIndex] : 0; |
| 281 } | 282 } |
| 282 | 283 |
| 283 bool Canvas2DLayerBridge::hasReleasedMailbox() const | 284 bool Canvas2DLayerBridge::hasReleasedMailbox() const |
| 284 { | 285 { |
| 285 return m_releasedMailboxInfoIndex != InvalidMailboxIndex; | 286 return m_releasedMailboxInfoIndex != InvalidMailboxIndex; |
| 286 } | 287 } |
| 287 | 288 |
| 288 void Canvas2DLayerBridge::freeReleasedMailbox() | 289 void Canvas2DLayerBridge::freeReleasedMailbox() |
| 289 { | 290 { |
| 291 if (!isValid()) | |
| 292 return; | |
| 290 MailboxInfo* mailboxInfo = releasedMailboxInfo(); | 293 MailboxInfo* mailboxInfo = releasedMailboxInfo(); |
| 291 if (!mailboxInfo) | 294 if (!mailboxInfo) |
| 292 return; | 295 return; |
| 293 | 296 |
| 294 ASSERT(mailboxInfo->m_status == MailboxReleased); | 297 ASSERT(mailboxInfo->m_status == MailboxReleased); |
| 295 if (mailboxInfo->m_mailbox.syncPoint) { | 298 if (mailboxInfo->m_mailbox.syncPoint) { |
| 296 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint); | 299 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint); |
| 297 mailboxInfo->m_mailbox.syncPoint = 0; | 300 mailboxInfo->m_mailbox.syncPoint = 0; |
| 298 } | 301 } |
| 299 // Invalidate texture state in case the compositor altered it since the copy -on-write. | 302 // Invalidate texture state in case the compositor altered it since the copy -on-write. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 314 // the destruction of m_layer | 317 // the destruction of m_layer |
| 315 if (m_layer) { | 318 if (m_layer) { |
| 316 isValid(); // To ensure rate limiter is disabled if context is lost. | 319 isValid(); // To ensure rate limiter is disabled if context is lost. |
| 317 } | 320 } |
| 318 return m_contextProvider->context3d(); | 321 return m_contextProvider->context3d(); |
| 319 } | 322 } |
| 320 | 323 |
| 321 bool Canvas2DLayerBridge::isValid() | 324 bool Canvas2DLayerBridge::isValid() |
| 322 { | 325 { |
| 323 ASSERT(m_layer); | 326 ASSERT(m_layer); |
| 324 if (m_destructionInProgress) | 327 ASSERT(isMainThread()); |
| 328 // guard against reentry | |
| 329 static bool inIsValid = false; | |
| 330 if (inIsValid || m_destructionInProgress) | |
| 325 return false; | 331 return false; |
| 332 inIsValid = true; | |
| 326 if (m_contextProvider->context3d()->isContextLost() || !m_surfaceIsValid) { | 333 if (m_contextProvider->context3d()->isContextLost() || !m_surfaceIsValid) { |
| 327 // Attempt to recover. | 334 // Attempt to recover. |
|
Stephen White
2014/03/03 21:43:11
Maybe we should just not be doing context recovery
| |
| 328 blink::WebGraphicsContext3D* sharedContext = 0; | 335 blink::WebGraphicsContext3D* sharedContext = 0; |
| 329 m_layer->clearTexture(); | 336 m_layer->clearTexture(); |
| 330 m_mailboxes.clear(); | 337 m_mailboxes.clear(); |
| 331 m_releasedMailboxInfoIndex = InvalidMailboxIndex; | 338 m_releasedMailboxInfoIndex = InvalidMailboxIndex; |
| 332 m_contextProvider = adoptPtr(blink::Platform::current()->createSharedOff screenGraphicsContext3DProvider()); | 339 m_contextProvider = adoptPtr(blink::Platform::current()->createSharedOff screenGraphicsContext3DProvider()); |
| 333 if (m_contextProvider) | 340 if (m_contextProvider) |
| 334 sharedContext = m_contextProvider->context3d(); | 341 sharedContext = m_contextProvider->context3d(); |
| 335 | 342 |
| 336 if (!sharedContext || sharedContext->isContextLost()) { | 343 if (!sharedContext || sharedContext->isContextLost()) { |
| 337 m_surfaceIsValid = false; | 344 m_surfaceIsValid = false; |
| 338 } else { | 345 } else { |
| 339 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); | 346 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi ce()->height()); |
| 340 RefPtr<SkSurface> surface(createSkSurface(m_contextProvider->grConte xt(), size, m_msaaSampleCount)); | 347 RefPtr<SkSurface> surface(createSkSurface(m_contextProvider->grConte xt(), size, m_msaaSampleCount)); |
| 341 if (surface.get()) { | 348 if (surface.get()) { |
| 342 m_canvas->setSurface(surface.get()); | 349 m_canvas->setSurface(surface.get()); |
| 343 m_surfaceIsValid = true; | 350 m_surfaceIsValid = true; |
| 344 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 | 351 // FIXME: draw sad canvas picture into new buffer crbug.com/2438 42 |
| 345 } else { | 352 } else { |
| 346 // Surface allocation failed. Set m_surfaceIsValid to false to | 353 // Surface allocation failed. Set m_surfaceIsValid to false to |
| 347 // trigger subsequent retry. | 354 // trigger subsequent retry. |
| 348 m_surfaceIsValid = false; | 355 m_surfaceIsValid = false; |
| 349 } | 356 } |
| 350 } | 357 } |
| 351 } | 358 } |
| 352 if (!m_surfaceIsValid) | 359 if (!m_surfaceIsValid) |
| 353 setRateLimitingEnabled(false); | 360 setRateLimitingEnabled(false); |
| 361 inIsValid = false; | |
| 354 return m_surfaceIsValid; | 362 return m_surfaceIsValid; |
| 355 } | 363 } |
| 356 | 364 |
| 357 bool Canvas2DLayerBridge::prepareMailbox(blink::WebExternalTextureMailbox* outMa ilbox, blink::WebExternalBitmap* bitmap) | 365 bool Canvas2DLayerBridge::prepareMailbox(blink::WebExternalTextureMailbox* outMa ilbox, blink::WebExternalBitmap* bitmap) |
| 358 { | 366 { |
| 359 if (bitmap) { | 367 if (bitmap) { |
| 360 // Using accelerated 2d canvas with software renderer, which | 368 // Using accelerated 2d canvas with software renderer, which |
| 361 // should only happen in tests that use fake graphics contexts | 369 // should only happen in tests that use fake graphics contexts |
| 362 // or in Android WebView in software mode. In this case, we do | 370 // or in Android WebView in software mode. In this case, we do |
| 363 // not care about producing any results for this canvas. | 371 // not care about producing any results for this canvas. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 513 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 506 // This copy constructor should only be used for Vector reallocation | 514 // This copy constructor should only be used for Vector reallocation |
| 507 // Assuming 'other' is to be destroyed, we transfer m_image ownership | 515 // Assuming 'other' is to be destroyed, we transfer m_image ownership |
| 508 // rather than do a refcount dance. | 516 // rather than do a refcount dance. |
| 509 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 517 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 510 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 518 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
| 511 m_status = other.m_status; | 519 m_status = other.m_status; |
| 512 } | 520 } |
| 513 | 521 |
| 514 } | 522 } |
| OLD | NEW |