| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 enum { | 55 enum { |
| 56 InvalidMailboxIndex = -1, | 56 InvalidMailboxIndex = -1, |
| 57 MaxCanvasAnimationBacklog = 2, // Make sure the the GPU is never more than t
wo animation frames behind. | 57 MaxCanvasAnimationBacklog = 2, // Make sure the the GPU is never more than t
wo animation frames behind. |
| 58 }; | 58 }; |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 namespace blink { | 61 namespace blink { |
| 62 | 62 |
| 63 static PassRefPtr<SkSurface> createSkSurface(GrContext* gr, const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace, b
ool* surfaceIsAccelerated) | 63 static sk_sp<SkSurface> createSkSurface(GrContext* gr, const IntSize& size, int
msaaSampleCount, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace, bool*
surfaceIsAccelerated) |
| 64 { | 64 { |
| 65 if (gr) | 65 if (gr) |
| 66 gr->resetContext(); | 66 gr->resetContext(); |
| 67 | 67 |
| 68 SkAlphaType alphaType = (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; | 68 SkAlphaType alphaType = (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; |
| 69 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe, colorSpace); | 69 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe, colorSpace); |
| 70 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); | 70 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); |
| 71 sk_sp<SkSurface> surface; | 71 sk_sp<SkSurface> surface; |
| 72 | 72 |
| 73 if (gr) { | 73 if (gr) { |
| 74 *surfaceIsAccelerated = true; | 74 *surfaceIsAccelerated = true; |
| 75 surface = SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, info, msaaSam
pleCount, Opaque == opacityMode ? 0 : &disableLCDProps); | 75 surface = SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, info, msaaSam
pleCount, Opaque == opacityMode ? 0 : &disableLCDProps); |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!surface) { | 78 if (!surface) { |
| 79 *surfaceIsAccelerated = false; | 79 *surfaceIsAccelerated = false; |
| 80 surface = SkSurface::MakeRaster(info, Opaque == opacityMode ? 0 : &disab
leLCDProps); | 80 surface = SkSurface::MakeRaster(info, Opaque == opacityMode ? 0 : &disab
leLCDProps); |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (surface) { | 83 if (surface) { |
| 84 if (opacityMode == Opaque) { | 84 if (opacityMode == Opaque) { |
| 85 surface->getCanvas()->clear(SK_ColorBLACK); | 85 surface->getCanvas()->clear(SK_ColorBLACK); |
| 86 } else { | 86 } else { |
| 87 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 87 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 return fromSkSp(surface); | 90 return surface; |
| 91 } | 91 } |
| 92 | 92 |
| 93 Canvas2DLayerBridge::Canvas2DLayerBridge(std::unique_ptr<WebGraphicsContext3DPro
vider> contextProvider, const IntSize& size, int msaaSampleCount, OpacityMode op
acityMode, AccelerationMode accelerationMode, sk_sp<SkColorSpace> colorSpace) | 93 Canvas2DLayerBridge::Canvas2DLayerBridge(std::unique_ptr<WebGraphicsContext3DPro
vider> contextProvider, const IntSize& size, int msaaSampleCount, OpacityMode op
acityMode, AccelerationMode accelerationMode, sk_sp<SkColorSpace> colorSpace) |
| 94 : m_contextProvider(std::move(contextProvider)) | 94 : m_contextProvider(std::move(contextProvider)) |
| 95 , m_logger(wrapUnique(new Logger)) | 95 , m_logger(wrapUnique(new Logger)) |
| 96 , m_weakPtrFactory(this) | 96 , m_weakPtrFactory(this) |
| 97 , m_imageBuffer(0) | 97 , m_imageBuffer(0) |
| 98 , m_msaaSampleCount(msaaSampleCount) | 98 , m_msaaSampleCount(msaaSampleCount) |
| 99 , m_bytesAllocated(0) | 99 , m_bytesAllocated(0) |
| 100 , m_haveRecordedDrawCommands(false) | 100 , m_haveRecordedDrawCommands(false) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 285 } |
| 286 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 286 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 287 | 287 |
| 288 void Canvas2DLayerBridge::createMailboxInfo() | 288 void Canvas2DLayerBridge::createMailboxInfo() |
| 289 { | 289 { |
| 290 MailboxInfo tmp; | 290 MailboxInfo tmp; |
| 291 tmp.m_parentLayerBridge = this; | 291 tmp.m_parentLayerBridge = this; |
| 292 m_mailboxes.prepend(tmp); | 292 m_mailboxes.prepend(tmp); |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool Canvas2DLayerBridge::prepareMailboxFromImage(PassRefPtr<SkImage> image, | 295 bool Canvas2DLayerBridge::prepareMailboxFromImage(sk_sp<SkImage> image, |
| 296 cc::TextureMailbox* outMailbox) | 296 cc::TextureMailbox* outMailbox) |
| 297 { | 297 { |
| 298 createMailboxInfo(); | 298 createMailboxInfo(); |
| 299 MailboxInfo& mailboxInfo = m_mailboxes.first(); | 299 MailboxInfo& mailboxInfo = m_mailboxes.first(); |
| 300 | 300 |
| 301 GrContext* grContext = m_contextProvider->grContext(); | 301 GrContext* grContext = m_contextProvider->grContext(); |
| 302 if (!grContext) { | 302 if (!grContext) { |
| 303 mailboxInfo.m_image = image; | 303 mailboxInfo.m_image = std::move(image); |
| 304 return true; // for testing: skip gl stuff when using a mock graphics co
ntext. | 304 return true; // for testing: skip gl stuff when using a mock graphics co
ntext. |
| 305 } | 305 } |
| 306 | 306 |
| 307 #if USE_IOSURFACE_FOR_2D_CANVAS | 307 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 308 if (RuntimeEnabledFeatures::canvas2dImageChromiumEnabled()) { | 308 if (RuntimeEnabledFeatures::canvas2dImageChromiumEnabled()) { |
| 309 if (prepareIOSurfaceMailboxFromImage(image.get(), outMailbox)) | 309 if (prepareIOSurfaceMailboxFromImage(image.get(), outMailbox)) |
| 310 return true; | 310 return true; |
| 311 // Note: if IOSurface backed texture creation failed we fall back to the | 311 // Note: if IOSurface backed texture creation failed we fall back to the |
| 312 // non-IOSurface path. | 312 // non-IOSurface path. |
| 313 } | 313 } |
| 314 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 314 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 315 | 315 |
| 316 mailboxInfo.m_image = image; | 316 mailboxInfo.m_image = std::move(image); |
| 317 | 317 |
| 318 if (RuntimeEnabledFeatures::forceDisable2dCanvasCopyOnWriteEnabled()) | 318 if (RuntimeEnabledFeatures::forceDisable2dCanvasCopyOnWriteEnabled()) |
| 319 m_surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode)
; | 319 m_surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode)
; |
| 320 | 320 |
| 321 // Need to flush skia's internal queue because texture is about to be access
ed directly | 321 // Need to flush skia's internal queue because texture is about to be access
ed directly |
| 322 grContext->flush(); | 322 grContext->flush(); |
| 323 | 323 |
| 324 // Because of texture sharing with the compositor, we must invalidate | 324 // Because of texture sharing with the compositor, we must invalidate |
| 325 // the state cached in skia so that the deferred copy on write | 325 // the state cached in skia so that the deferred copy on write |
| 326 // in SkSurface_Gpu does not make any false assumptions. | 326 // in SkSurface_Gpu does not make any false assumptions. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 338 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 338 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 339 | 339 |
| 340 gpu::Mailbox mailbox; | 340 gpu::Mailbox mailbox; |
| 341 gl->GenMailboxCHROMIUM(mailbox.name); | 341 gl->GenMailboxCHROMIUM(mailbox.name); |
| 342 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 342 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 343 | 343 |
| 344 gpu::SyncToken syncToken; | 344 gpu::SyncToken syncToken; |
| 345 if (isHidden()) { | 345 if (isHidden()) { |
| 346 // With hidden canvases, we release the SkImage immediately because | 346 // With hidden canvases, we release the SkImage immediately because |
| 347 // there is no need for animations to be double buffered. | 347 // there is no need for animations to be double buffered. |
| 348 mailboxInfo.m_image.clear(); | 348 mailboxInfo.m_image.reset(); |
| 349 } else { | 349 } else { |
| 350 // FIXME: We'd rather insert a syncpoint than perform a flush here, | 350 // FIXME: We'd rather insert a syncpoint than perform a flush here, |
| 351 // but currently the canvas will flicker if we don't flush here. | 351 // but currently the canvas will flicker if we don't flush here. |
| 352 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 352 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 353 gl->Flush(); | 353 gl->Flush(); |
| 354 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); | 354 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); |
| 355 } | 355 } |
| 356 mailboxInfo.m_mailbox = mailbox; | 356 mailboxInfo.m_mailbox = mailbox; |
| 357 *outMailbox = cc::TextureMailbox(mailbox, syncToken, GL_TEXTURE_2D); | 357 *outMailbox = cc::TextureMailbox(mailbox, syncToken, GL_TEXTURE_2D); |
| 358 | 358 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // exactly one failure or exit event. | 423 // exactly one failure or exit event. |
| 424 flushRecordingOnly(); | 424 flushRecordingOnly(); |
| 425 // The following checks that the flush succeeded, which should always be the | 425 // The following checks that the flush succeeded, which should always be the |
| 426 // case because flushRecordingOnly should only fail it it fails to allocate | 426 // case because flushRecordingOnly should only fail it it fails to allocate |
| 427 // a surface, and we have an early exit at the top of this function for when | 427 // a surface, and we have an early exit at the top of this function for when |
| 428 // 'this' does not already have a surface. | 428 // 'this' does not already have a surface. |
| 429 DCHECK(!m_haveRecordedDrawCommands); | 429 DCHECK(!m_haveRecordedDrawCommands); |
| 430 SkPaint copyPaint; | 430 SkPaint copyPaint; |
| 431 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 431 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 432 m_surface->draw(tempHibernationSurface->getCanvas(), 0, 0, ©Paint); // G
PU readback | 432 m_surface->draw(tempHibernationSurface->getCanvas(), 0, 0, ©Paint); // G
PU readback |
| 433 m_hibernationImage = fromSkSp(tempHibernationSurface->makeImageSnapshot()); | 433 m_hibernationImage = tempHibernationSurface->makeImageSnapshot(); |
| 434 m_surface.clear(); // destroy the GPU-backed buffer | 434 m_surface.reset(); // destroy the GPU-backed buffer |
| 435 m_layer->clearTexture(); | 435 m_layer->clearTexture(); |
| 436 #if USE_IOSURFACE_FOR_2D_CANVAS | 436 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 437 clearCHROMIUMImageCache(); | 437 clearCHROMIUMImageCache(); |
| 438 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 438 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 439 m_logger->didStartHibernating(); | 439 m_logger->didStartHibernating(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void Canvas2DLayerBridge::reportSurfaceCreationFailure() | 442 void Canvas2DLayerBridge::reportSurfaceCreationFailure() |
| 443 { | 443 { |
| 444 if (!m_surfaceCreationFailedAtLeastOnce) { | 444 if (!m_surfaceCreationFailedAtLeastOnce) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } else { | 485 } else { |
| 486 if (isHidden()) | 486 if (isHidden()) |
| 487 m_logger->reportHibernationEvent(HibernationEndedWithSwitchToBac
kgroundRendering); | 487 m_logger->reportHibernationEvent(HibernationEndedWithSwitchToBac
kgroundRendering); |
| 488 else | 488 else |
| 489 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToS
W); | 489 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToS
W); |
| 490 } | 490 } |
| 491 | 491 |
| 492 SkPaint copyPaint; | 492 SkPaint copyPaint; |
| 493 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 493 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 494 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, ©P
aint); | 494 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, ©P
aint); |
| 495 m_hibernationImage.clear(); | 495 m_hibernationImage.reset(); |
| 496 | 496 |
| 497 if (m_imageBuffer) | 497 if (m_imageBuffer) |
| 498 m_imageBuffer->updateGPUMemoryUsage(); | 498 m_imageBuffer->updateGPUMemoryUsage(); |
| 499 | 499 |
| 500 if (m_imageBuffer && !m_isDeferralEnabled) | 500 if (m_imageBuffer && !m_isDeferralEnabled) |
| 501 m_imageBuffer->resetCanvas(m_surface->getCanvas()); | 501 m_imageBuffer->resetCanvas(m_surface->getCanvas()); |
| 502 } | 502 } |
| 503 | 503 |
| 504 return m_surface.get(); | 504 return m_surface.get(); |
| 505 } | 505 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); | 550 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); |
| 551 } | 551 } |
| 552 } | 552 } |
| 553 | 553 |
| 554 void Canvas2DLayerBridge::beginDestruction() | 554 void Canvas2DLayerBridge::beginDestruction() |
| 555 { | 555 { |
| 556 if (m_destructionInProgress) | 556 if (m_destructionInProgress) |
| 557 return; | 557 return; |
| 558 if (isHibernating()) | 558 if (isHibernating()) |
| 559 m_logger->reportHibernationEvent(HibernationEndedWithTeardown); | 559 m_logger->reportHibernationEvent(HibernationEndedWithTeardown); |
| 560 m_hibernationImage.clear(); | 560 m_hibernationImage.reset(); |
| 561 m_recorder.reset(); | 561 m_recorder.reset(); |
| 562 m_imageBuffer = nullptr; | 562 m_imageBuffer = nullptr; |
| 563 m_destructionInProgress = true; | 563 m_destructionInProgress = true; |
| 564 setIsHidden(true); | 564 setIsHidden(true); |
| 565 m_surface.clear(); | 565 m_surface.reset(); |
| 566 | 566 |
| 567 unregisterTaskObserver(); | 567 unregisterTaskObserver(); |
| 568 | 568 |
| 569 if (m_layer && m_accelerationMode != DisableAcceleration) { | 569 if (m_layer && m_accelerationMode != DisableAcceleration) { |
| 570 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 570 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 571 m_layer->clearTexture(); | 571 m_layer->clearTexture(); |
| 572 // Orphaning the layer is required to trigger the recration of a new lay
er | 572 // Orphaning the layer is required to trigger the recration of a new lay
er |
| 573 // in the case where destruction is caused by a canvas resize. Test: | 573 // in the case where destruction is caused by a canvas resize. Test: |
| 574 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html | 574 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
| 575 m_layer->layer()->removeFromParent(); | 575 m_layer->layer()->removeFromParent(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 605 if (m_layer) | 605 if (m_layer) |
| 606 m_layer->clearTexture(); | 606 m_layer->clearTexture(); |
| 607 m_logger->reportHibernationEvent(HibernationScheduled); | 607 m_logger->reportHibernationEvent(HibernationScheduled); |
| 608 m_hibernationScheduled = true; | 608 m_hibernationScheduled = true; |
| 609 Platform::current()->currentThread()->scheduler()->postIdleTask(BLINK_FR
OM_HERE, WTF::bind(&hibernateWrapper, m_weakPtrFactory.createWeakPtr())); | 609 Platform::current()->currentThread()->scheduler()->postIdleTask(BLINK_FR
OM_HERE, WTF::bind(&hibernateWrapper, m_weakPtrFactory.createWeakPtr())); |
| 610 } | 610 } |
| 611 if (!isHidden() && m_softwareRenderingWhileHidden) { | 611 if (!isHidden() && m_softwareRenderingWhileHidden) { |
| 612 flushRecordingOnly(); | 612 flushRecordingOnly(); |
| 613 SkPaint copyPaint; | 613 SkPaint copyPaint; |
| 614 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 614 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 615 RefPtr<SkSurface> oldSurface = m_surface.release(); | 615 |
| 616 sk_sp<SkSurface> oldSurface = std::move(m_surface); |
| 617 m_surface.reset(); |
| 618 |
| 616 m_softwareRenderingWhileHidden = false; | 619 m_softwareRenderingWhileHidden = false; |
| 617 SkSurface* newSurface = getOrCreateSurface(PreferAccelerationAfterVisibi
lityChange); | 620 SkSurface* newSurface = getOrCreateSurface(PreferAccelerationAfterVisibi
lityChange); |
| 618 if (newSurface) { | 621 if (newSurface) { |
| 619 if (oldSurface) | 622 if (oldSurface) |
| 620 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); | 623 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); |
| 621 if (m_imageBuffer && !m_isDeferralEnabled) { | 624 if (m_imageBuffer && !m_isDeferralEnabled) { |
| 622 m_imageBuffer->resetCanvas(m_surface->getCanvas()); | 625 m_imageBuffer->resetCanvas(m_surface->getCanvas()); |
| 623 } | 626 } |
| 624 } | 627 } |
| 625 } | 628 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 DCHECK(!m_destructionInProgress); | 711 DCHECK(!m_destructionInProgress); |
| 709 if (m_destructionInProgress) | 712 if (m_destructionInProgress) |
| 710 return false; | 713 return false; |
| 711 if (isHibernating()) | 714 if (isHibernating()) |
| 712 return true; | 715 return true; |
| 713 if (!m_layer || m_accelerationMode == DisableAcceleration) | 716 if (!m_layer || m_accelerationMode == DisableAcceleration) |
| 714 return true; | 717 return true; |
| 715 if (!m_surface) | 718 if (!m_surface) |
| 716 return false; | 719 return false; |
| 717 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR
OR) { | 720 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR
OR) { |
| 718 m_surface.clear(); | 721 m_surface.reset(); |
| 719 for (auto mailboxInfo = m_mailboxes.begin(); mailboxInfo != m_mailboxes.
end(); ++mailboxInfo) { | 722 for (auto mailboxInfo = m_mailboxes.begin(); mailboxInfo != m_mailboxes.
end(); ++mailboxInfo) { |
| 720 if (mailboxInfo->m_image) | 723 if (mailboxInfo->m_image) |
| 721 mailboxInfo->m_image.clear(); | 724 mailboxInfo->m_image.reset(); |
| 722 } | 725 } |
| 723 if (m_imageBuffer) | 726 if (m_imageBuffer) |
| 724 m_imageBuffer->notifySurfaceInvalid(); | 727 m_imageBuffer->notifySurfaceInvalid(); |
| 725 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva
sGPUContextLost); | 728 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva
sGPUContextLost); |
| 726 } | 729 } |
| 727 return m_surface.get(); | 730 return m_surface.get(); |
| 728 } | 731 } |
| 729 | 732 |
| 730 bool Canvas2DLayerBridge::restoreSurface() | 733 bool Canvas2DLayerBridge::restoreSurface() |
| 731 { | 734 { |
| 732 DCHECK(!m_destructionInProgress); | 735 DCHECK(!m_destructionInProgress); |
| 733 if (m_destructionInProgress) | 736 if (m_destructionInProgress) |
| 734 return false; | 737 return false; |
| 735 DCHECK(isAccelerated() && !m_surface); | 738 DCHECK(isAccelerated() && !m_surface); |
| 736 | 739 |
| 737 gpu::gles2::GLES2Interface* sharedGL = nullptr; | 740 gpu::gles2::GLES2Interface* sharedGL = nullptr; |
| 738 m_layer->clearTexture(); | 741 m_layer->clearTexture(); |
| 739 m_contextProvider = wrapUnique(Platform::current()->createSharedOffscreenGra
phicsContext3DProvider()); | 742 m_contextProvider = wrapUnique(Platform::current()->createSharedOffscreenGra
phicsContext3DProvider()); |
| 740 if (m_contextProvider) | 743 if (m_contextProvider) |
| 741 sharedGL = m_contextProvider->contextGL(); | 744 sharedGL = m_contextProvider->contextGL(); |
| 742 | 745 |
| 743 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { | 746 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
| 744 GrContext* grCtx = m_contextProvider->grContext(); | 747 GrContext* grCtx = m_contextProvider->grContext(); |
| 745 bool surfaceIsAccelerated; | 748 bool surfaceIsAccelerated; |
| 746 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou
nt, m_opacityMode, m_colorSpace, &surfaceIsAccelerated)); | 749 sk_sp<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCoun
t, m_opacityMode, m_colorSpace, &surfaceIsAccelerated)); |
| 747 | 750 |
| 748 if (!m_surface) | 751 if (!m_surface) |
| 749 reportSurfaceCreationFailure(); | 752 reportSurfaceCreationFailure(); |
| 750 | 753 |
| 751 // Current paradigm does support switching from accelerated to non-accel
erated, which would be tricky | 754 // Current paradigm does support switching from accelerated to non-accel
erated, which would be tricky |
| 752 // due to changes to the layer tree, which can only happen at specific t
imes during the document lifecycle. | 755 // due to changes to the layer tree, which can only happen at specific t
imes during the document lifecycle. |
| 753 // Therefore, we can only accept the restored surface if it is accelerat
ed. | 756 // Therefore, we can only accept the restored surface if it is accelerat
ed. |
| 754 if (surface && surfaceIsAccelerated) { | 757 if (surface && surfaceIsAccelerated) { |
| 755 m_surface = surface.release(); | 758 m_surface = std::move(surface); |
| 756 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 | 759 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 |
| 757 } | 760 } |
| 758 } | 761 } |
| 759 if (m_imageBuffer) | 762 if (m_imageBuffer) |
| 760 m_imageBuffer->updateGPUMemoryUsage(); | 763 m_imageBuffer->updateGPUMemoryUsage(); |
| 761 | 764 |
| 762 return m_surface.get(); | 765 return m_surface.get(); |
| 763 } | 766 } |
| 764 | 767 |
| 765 static gfx::ColorSpace SkColorSpaceToColorSpace(const SkColorSpace* skColorSpace
) | 768 static gfx::ColorSpace SkColorSpaceToColorSpace(const SkColorSpace* skColorSpace
) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 // hibernation | 808 // hibernation |
| 806 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) | 809 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) |
| 807 return false; | 810 return false; |
| 808 | 811 |
| 809 // If the context is lost, we don't know if we should be producing GPU or | 812 // If the context is lost, we don't know if we should be producing GPU or |
| 810 // software frames, until we get a new context, since the compositor will | 813 // software frames, until we get a new context, since the compositor will |
| 811 // be trying to get a new context and may change modes. | 814 // be trying to get a new context and may change modes. |
| 812 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR
OR) | 815 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR
OR) |
| 813 return false; | 816 return false; |
| 814 | 817 |
| 815 RefPtr<SkImage> image = newImageSnapshot(PreferAcceleration, SnapshotReasonU
nknown); | 818 sk_sp<SkImage> image = newImageSnapshot(PreferAcceleration, SnapshotReasonUn
known); |
| 816 if (!image || !image->getTexture()) | 819 if (!image || !image->getTexture()) |
| 817 return false; | 820 return false; |
| 818 | 821 |
| 819 // Early exit if canvas was not drawn to since last prepareMailbox. | 822 // Early exit if canvas was not drawn to since last prepareMailbox. |
| 820 GLenum filter = getGLFilter(); | 823 GLenum filter = getGLFilter(); |
| 821 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) | 824 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) |
| 822 return false; | 825 return false; |
| 823 m_lastImageId = image->uniqueID(); | 826 m_lastImageId = image->uniqueID(); |
| 824 m_lastFilter = filter; | 827 m_lastFilter = filter; |
| 825 | 828 |
| 826 if (!prepareMailboxFromImage(image.release(), outMailbox)) | 829 if (!prepareMailboxFromImage(std::move(image), outMailbox)) |
| 827 return false; | 830 return false; |
| 828 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST); | 831 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST); |
| 829 gfx::ColorSpace colorSpace = SkColorSpaceToColorSpace(m_colorSpace.get()); | 832 gfx::ColorSpace colorSpace = SkColorSpaceToColorSpace(m_colorSpace.get()); |
| 830 outMailbox->set_color_space(colorSpace); | 833 outMailbox->set_color_space(colorSpace); |
| 831 | 834 |
| 832 auto func = WTF::bind(&Canvas2DLayerBridge::mailboxReleased, | 835 auto func = WTF::bind(&Canvas2DLayerBridge::mailboxReleased, |
| 833 m_weakPtrFactory.createWeakPtr(), | 836 m_weakPtrFactory.createWeakPtr(), |
| 834 outMailbox->mailbox()); | 837 outMailbox->mailbox()); |
| 835 *outReleaseCallback = cc::SingleReleaseCallback::Create( | 838 *outReleaseCallback = cc::SingleReleaseCallback::Create( |
| 836 convertToBaseCallback(std::move(func))); | 839 convertToBaseCallback(std::move(func))); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 | 971 |
| 969 m_renderingTaskCompletedForCurrentFrame = true; | 972 m_renderingTaskCompletedForCurrentFrame = true; |
| 970 unregisterTaskObserver(); | 973 unregisterTaskObserver(); |
| 971 } | 974 } |
| 972 | 975 |
| 973 void Canvas2DLayerBridge::willProcessTask() | 976 void Canvas2DLayerBridge::willProcessTask() |
| 974 { | 977 { |
| 975 NOTREACHED(); | 978 NOTREACHED(); |
| 976 } | 979 } |
| 977 | 980 |
| 978 PassRefPtr<SkImage> Canvas2DLayerBridge::newImageSnapshot(AccelerationHint hint,
SnapshotReason) | 981 sk_sp<SkImage> Canvas2DLayerBridge::newImageSnapshot(AccelerationHint hint, Snap
shotReason) |
| 979 { | 982 { |
| 980 if (isHibernating()) | 983 if (isHibernating()) |
| 981 return m_hibernationImage; | 984 return m_hibernationImage; |
| 982 if (!checkSurfaceValid()) | 985 if (!checkSurfaceValid()) |
| 983 return nullptr; | 986 return nullptr; |
| 984 if (!getOrCreateSurface(hint)) | 987 if (!getOrCreateSurface(hint)) |
| 985 return nullptr; | 988 return nullptr; |
| 986 flush(); | 989 flush(); |
| 987 // A readback operation may alter the texture parameters, which may affect | 990 // A readback operation may alter the texture parameters, which may affect |
| 988 // the compositor's behavior. Therefore, we must trigger copy-on-write | 991 // the compositor's behavior. Therefore, we must trigger copy-on-write |
| 989 // even though we are not technically writing to the texture, only to its | 992 // even though we are not technically writing to the texture, only to its |
| 990 // parameters. | 993 // parameters. |
| 991 getOrCreateSurface()->notifyContentWillChange(SkSurface::kRetain_ContentChan
geMode); | 994 getOrCreateSurface()->notifyContentWillChange(SkSurface::kRetain_ContentChan
geMode); |
| 992 return fromSkSp(m_surface->makeImageSnapshot()); | 995 return m_surface->makeImageSnapshot(); |
| 993 } | 996 } |
| 994 | 997 |
| 995 void Canvas2DLayerBridge::willOverwriteCanvas() | 998 void Canvas2DLayerBridge::willOverwriteCanvas() |
| 996 { | 999 { |
| 997 skipQueuedDrawCommands(); | 1000 skipQueuedDrawCommands(); |
| 998 } | 1001 } |
| 999 | 1002 |
| 1000 #if USE_IOSURFACE_FOR_2D_CANVAS | 1003 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 1001 Canvas2DLayerBridge::ImageInfo::ImageInfo(GLuint imageId, GLuint textureId) : m_
imageId(imageId), m_textureId(textureId) | 1004 Canvas2DLayerBridge::ImageInfo::ImageInfo(GLuint imageId, GLuint textureId) : m_
imageId(imageId), m_textureId(textureId) |
| 1002 { | 1005 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1013 Canvas2DLayerBridge::MailboxInfo::MailboxInfo() = default; | 1016 Canvas2DLayerBridge::MailboxInfo::MailboxInfo() = default; |
| 1014 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) = defaul
t; | 1017 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) = defaul
t; |
| 1015 | 1018 |
| 1016 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 1019 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
| 1017 { | 1020 { |
| 1018 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); | 1021 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); |
| 1019 hibernationHistogram.count(event); | 1022 hibernationHistogram.count(event); |
| 1020 } | 1023 } |
| 1021 | 1024 |
| 1022 } // namespace blink | 1025 } // namespace blink |
| OLD | NEW |