| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 std::unique_ptr<gfx::GpuMemoryBuffer> m_gpuMemoryBuffer; | 75 std::unique_ptr<gfx::GpuMemoryBuffer> m_gpuMemoryBuffer; |
| 76 | 76 |
| 77 // The id of the CHROMIUM image. | 77 // The id of the CHROMIUM image. |
| 78 const GLuint m_imageId; | 78 const GLuint m_imageId; |
| 79 | 79 |
| 80 // The id of the texture bound to the CHROMIUM image. | 80 // The id of the texture bound to the CHROMIUM image. |
| 81 const GLuint m_textureId; | 81 const GLuint m_textureId; |
| 82 }; | 82 }; |
| 83 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 83 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 84 | 84 |
| 85 static sk_sp<PaintSurface> createSkSurface(GrContext* gr, | 85 static sk_sp<SkSurface> createSkSurface(GrContext* gr, |
| 86 const IntSize& size, | 86 const IntSize& size, |
| 87 int msaaSampleCount, | 87 int msaaSampleCount, |
| 88 OpacityMode opacityMode, | 88 OpacityMode opacityMode, |
| 89 sk_sp<SkColorSpace> colorSpace, | 89 sk_sp<SkColorSpace> colorSpace, |
| 90 SkColorType colorType, | 90 SkColorType colorType, |
| 91 bool* surfaceIsAccelerated) { | 91 bool* surfaceIsAccelerated) { |
| 92 if (gr) | 92 if (gr) |
| 93 gr->resetContext(); | 93 gr->resetContext(); |
| 94 | 94 |
| 95 SkAlphaType alphaType = | 95 SkAlphaType alphaType = |
| 96 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 96 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 97 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, | 97 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, |
| 98 alphaType, colorSpace); | 98 alphaType, colorSpace); |
| 99 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); | 99 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); |
| 100 sk_sp<PaintSurface> surface; | 100 sk_sp<SkSurface> surface; |
| 101 | 101 |
| 102 if (gr) { | 102 if (gr) { |
| 103 *surfaceIsAccelerated = true; | 103 *surfaceIsAccelerated = true; |
| 104 surface = PaintSurface::MakeRenderTarget( | 104 surface = SkSurface::MakeRenderTarget( |
| 105 gr, SkBudgeted::kNo, info, msaaSampleCount, | 105 gr, SkBudgeted::kNo, info, msaaSampleCount, |
| 106 Opaque == opacityMode ? 0 : &disableLCDProps); | 106 Opaque == opacityMode ? 0 : &disableLCDProps); |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (!surface) { | 109 if (!surface) { |
| 110 *surfaceIsAccelerated = false; | 110 *surfaceIsAccelerated = false; |
| 111 surface = PaintSurface::MakeRaster( | 111 surface = SkSurface::MakeRaster( |
| 112 info, Opaque == opacityMode ? 0 : &disableLCDProps); | 112 info, Opaque == opacityMode ? 0 : &disableLCDProps); |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (surface) { | 115 if (surface) { |
| 116 if (opacityMode == Opaque) { | 116 if (opacityMode == Opaque) { |
| 117 surface->getCanvas()->clear(SK_ColorBLACK); | 117 surface->getCanvas()->clear(SK_ColorBLACK); |
| 118 } else { | 118 } else { |
| 119 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 119 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| 120 } | 120 } |
| 121 } | 121 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 167 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 168 | 168 |
| 169 m_layer.reset(); | 169 m_layer.reset(); |
| 170 DCHECK_EQ(0u, m_mailboxes.size()); | 170 DCHECK_EQ(0u, m_mailboxes.size()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void Canvas2DLayerBridge::startRecording() { | 173 void Canvas2DLayerBridge::startRecording() { |
| 174 DCHECK(m_isDeferralEnabled); | 174 DCHECK(m_isDeferralEnabled); |
| 175 m_recorder = WTF::wrapUnique(new PaintRecorder); | 175 m_recorder = WTF::wrapUnique(new PaintRecorder); |
| 176 PaintCanvas* canvas = | 176 PaintCanvas* canvas = |
| 177 m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr); | 177 m_recorder->beginRecording(m_size.width(), m_size.height()); |
| 178 // Always save an initial frame, to support resetting the top level matrix | 178 // Always save an initial frame, to support resetting the top level matrix |
| 179 // and clip. | 179 // and clip. |
| 180 canvas->save(); | 180 canvas->save(); |
| 181 | 181 |
| 182 if (m_imageBuffer) { | 182 if (m_imageBuffer) { |
| 183 m_imageBuffer->resetCanvas(canvas); | 183 m_imageBuffer->resetCanvas(canvas); |
| 184 } | 184 } |
| 185 m_recordingPixelCount = 0; | 185 m_recordingPixelCount = 0; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void Canvas2DLayerBridge::setLoggerForTesting(std::unique_ptr<Logger> logger) { | 188 void Canvas2DLayerBridge::setLoggerForTesting(std::unique_ptr<Logger> logger) { |
| 189 m_logger = std::move(logger); | 189 m_logger = std::move(logger); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void Canvas2DLayerBridge::ResetSurface() { |
| 193 m_surfacePaintCanvas.reset(); |
| 194 m_surface.reset(); |
| 195 } |
| 196 |
| 192 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const { | 197 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const { |
| 193 bool accelerate; | 198 bool accelerate; |
| 194 if (m_softwareRenderingWhileHidden) | 199 if (m_softwareRenderingWhileHidden) |
| 195 accelerate = false; | 200 accelerate = false; |
| 196 else if (m_accelerationMode == ForceAccelerationForTesting) | 201 else if (m_accelerationMode == ForceAccelerationForTesting) |
| 197 accelerate = true; | 202 accelerate = true; |
| 198 else if (m_accelerationMode == DisableAcceleration) | 203 else if (m_accelerationMode == DisableAcceleration) |
| 199 accelerate = false; | 204 accelerate = false; |
| 200 else | 205 else |
| 201 accelerate = hint == PreferAcceleration || | 206 accelerate = hint == PreferAcceleration || |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 return; | 495 return; |
| 491 } | 496 } |
| 492 | 497 |
| 493 if (!isAccelerated()) { | 498 if (!isAccelerated()) { |
| 494 m_logger->reportHibernationEvent( | 499 m_logger->reportHibernationEvent( |
| 495 HibernationAbortedDueToSwitchToUnacceleratedRendering); | 500 HibernationAbortedDueToSwitchToUnacceleratedRendering); |
| 496 return; | 501 return; |
| 497 } | 502 } |
| 498 | 503 |
| 499 TRACE_EVENT0("blink", "Canvas2DLayerBridge::hibernate"); | 504 TRACE_EVENT0("blink", "Canvas2DLayerBridge::hibernate"); |
| 500 sk_sp<PaintSurface> tempHibernationSurface = | 505 sk_sp<SkSurface> tempHibernationSurface = |
| 501 PaintSurface::MakeRasterN32Premul(m_size.width(), m_size.height()); | 506 SkSurface::MakeRasterN32Premul(m_size.width(), m_size.height()); |
| 502 if (!tempHibernationSurface) { | 507 if (!tempHibernationSurface) { |
| 503 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailure); | 508 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailure); |
| 504 return; | 509 return; |
| 505 } | 510 } |
| 506 // No HibernationEvent reported on success. This is on purppose to avoid | 511 // No HibernationEvent reported on success. This is on purppose to avoid |
| 507 // non-complementary stats. Each HibernationScheduled event is paired with | 512 // non-complementary stats. Each HibernationScheduled event is paired with |
| 508 // exactly one failure or exit event. | 513 // exactly one failure or exit event. |
| 509 flushRecordingOnly(); | 514 flushRecordingOnly(); |
| 510 // The following checks that the flush succeeded, which should always be the | 515 // The following checks that the flush succeeded, which should always be the |
| 511 // case because flushRecordingOnly should only fail it it fails to allocate | 516 // case because flushRecordingOnly should only fail it it fails to allocate |
| 512 // a surface, and we have an early exit at the top of this function for when | 517 // a surface, and we have an early exit at the top of this function for when |
| 513 // 'this' does not already have a surface. | 518 // 'this' does not already have a surface. |
| 514 DCHECK(!m_haveRecordedDrawCommands); | 519 DCHECK(!m_haveRecordedDrawCommands); |
| 515 PaintFlags copyPaint; | 520 SkPaint copyPaint; |
| 516 copyPaint.setBlendMode(SkBlendMode::kSrc); | 521 copyPaint.setBlendMode(SkBlendMode::kSrc); |
| 517 m_surface->draw(tempHibernationSurface->getCanvas(), 0, 0, | 522 m_surface->draw(tempHibernationSurface->getCanvas(), 0, 0, |
| 518 ©Paint); // GPU readback | 523 ©Paint); // GPU readback |
| 519 m_hibernationImage = tempHibernationSurface->makeImageSnapshot(); | 524 m_hibernationImage = tempHibernationSurface->makeImageSnapshot(); |
| 520 m_surface.reset(); // destroy the GPU-backed buffer | 525 ResetSurface(); |
| 521 m_layer->clearTexture(); | 526 m_layer->clearTexture(); |
| 522 #if USE_IOSURFACE_FOR_2D_CANVAS | 527 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 523 clearCHROMIUMImageCache(); | 528 clearCHROMIUMImageCache(); |
| 524 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 529 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 525 m_logger->didStartHibernating(); | 530 m_logger->didStartHibernating(); |
| 526 } | 531 } |
| 527 | 532 |
| 528 sk_sp<SkColorSpace> Canvas2DLayerBridge::skSurfaceColorSpace() const { | 533 sk_sp<SkColorSpace> Canvas2DLayerBridge::skSurfaceColorSpace() const { |
| 529 if (m_skSurfacesUseColorSpace) | 534 if (m_skSurfacesUseColorSpace) |
| 530 return m_colorSpace.ToSkColorSpace(); | 535 return m_colorSpace.ToSkColorSpace(); |
| 531 return nullptr; | 536 return nullptr; |
| 532 } | 537 } |
| 533 | 538 |
| 534 void Canvas2DLayerBridge::reportSurfaceCreationFailure() { | 539 void Canvas2DLayerBridge::reportSurfaceCreationFailure() { |
| 535 if (!m_surfaceCreationFailedAtLeastOnce) { | 540 if (!m_surfaceCreationFailedAtLeastOnce) { |
| 536 // Only count the failure once per instance so that the histogram may | 541 // Only count the failure once per instance so that the histogram may |
| 537 // reflect the proportion of Canvas2DLayerBridge instances with surface | 542 // reflect the proportion of Canvas2DLayerBridge instances with surface |
| 538 // allocation failures. | 543 // allocation failures. |
| 539 CanvasMetrics::countCanvasContextUsage( | 544 CanvasMetrics::countCanvasContextUsage( |
| 540 CanvasMetrics::GPUAccelerated2DCanvasSurfaceCreationFailed); | 545 CanvasMetrics::GPUAccelerated2DCanvasSurfaceCreationFailed); |
| 541 m_surfaceCreationFailedAtLeastOnce = true; | 546 m_surfaceCreationFailedAtLeastOnce = true; |
| 542 } | 547 } |
| 543 } | 548 } |
| 544 | 549 |
| 545 PaintSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) { | 550 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) { |
| 546 if (m_surface) | 551 if (m_surface) |
| 547 return m_surface.get(); | 552 return m_surface.get(); |
| 548 | 553 |
| 549 if (m_layer && !isHibernating() && hint == PreferAcceleration && | 554 if (m_layer && !isHibernating() && hint == PreferAcceleration && |
| 550 m_accelerationMode != DisableAcceleration) { | 555 m_accelerationMode != DisableAcceleration) { |
| 551 return nullptr; // re-creation will happen through restore() | 556 return nullptr; // re-creation will happen through restore() |
| 552 } | 557 } |
| 553 | 558 |
| 554 bool wantAcceleration = shouldAccelerate(hint); | 559 bool wantAcceleration = shouldAccelerate(hint); |
| 555 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && | 560 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && |
| 556 wantAcceleration) { | 561 wantAcceleration) { |
| 557 wantAcceleration = false; | 562 wantAcceleration = false; |
| 558 m_softwareRenderingWhileHidden = true; | 563 m_softwareRenderingWhileHidden = true; |
| 559 } | 564 } |
| 560 | 565 |
| 561 bool surfaceIsAccelerated; | 566 bool surfaceIsAccelerated; |
| 562 m_surface = createSkSurface( | 567 m_surface = createSkSurface( |
| 563 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, | 568 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, |
| 564 m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), m_colorType, | 569 m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), m_colorType, |
| 565 &surfaceIsAccelerated); | 570 &surfaceIsAccelerated); |
| 571 m_surfacePaintCanvas = |
| 572 WTF::wrapUnique(new PaintCanvas(m_surface->getCanvas())); |
| 566 | 573 |
| 567 if (m_surface) { | 574 if (m_surface) { |
| 568 // Always save an initial frame, to support resetting the top level matrix | 575 // Always save an initial frame, to support resetting the top level matrix |
| 569 // and clip. | 576 // and clip. |
| 570 m_surface->getCanvas()->save(); | 577 m_surfacePaintCanvas->save(); |
| 571 } else { | 578 } else { |
| 572 reportSurfaceCreationFailure(); | 579 reportSurfaceCreationFailure(); |
| 573 } | 580 } |
| 574 | 581 |
| 575 if (m_surface && surfaceIsAccelerated && !m_layer) { | 582 if (m_surface && surfaceIsAccelerated && !m_layer) { |
| 576 m_layer = | 583 m_layer = |
| 577 Platform::current()->compositorSupport()->createExternalTextureLayer( | 584 Platform::current()->compositorSupport()->createExternalTextureLayer( |
| 578 this); | 585 this); |
| 579 m_layer->setOpaque(m_opacityMode == Opaque); | 586 m_layer->setOpaque(m_opacityMode == Opaque); |
| 580 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); | 587 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); |
| 581 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 588 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 582 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); | 589 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); |
| 583 } | 590 } |
| 584 | 591 |
| 585 if (m_surface && isHibernating()) { | 592 if (m_surface && isHibernating()) { |
| 586 if (surfaceIsAccelerated) { | 593 if (surfaceIsAccelerated) { |
| 587 m_logger->reportHibernationEvent(HibernationEndedNormally); | 594 m_logger->reportHibernationEvent(HibernationEndedNormally); |
| 588 } else { | 595 } else { |
| 589 if (isHidden()) | 596 if (isHidden()) |
| 590 m_logger->reportHibernationEvent( | 597 m_logger->reportHibernationEvent( |
| 591 HibernationEndedWithSwitchToBackgroundRendering); | 598 HibernationEndedWithSwitchToBackgroundRendering); |
| 592 else | 599 else |
| 593 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToSW); | 600 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToSW); |
| 594 } | 601 } |
| 595 | 602 |
| 596 PaintFlags copyPaint; | 603 SkPaint copyPaint; |
| 597 copyPaint.setBlendMode(SkBlendMode::kSrc); | 604 copyPaint.setBlendMode(SkBlendMode::kSrc); |
| 598 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, | 605 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, |
| 599 ©Paint); | 606 ©Paint); |
| 600 m_hibernationImage.reset(); | 607 m_hibernationImage.reset(); |
| 601 | 608 |
| 602 if (m_imageBuffer) | 609 if (m_imageBuffer) |
| 603 m_imageBuffer->updateGPUMemoryUsage(); | 610 m_imageBuffer->updateGPUMemoryUsage(); |
| 604 | 611 |
| 605 if (m_imageBuffer && !m_isDeferralEnabled) | 612 if (m_imageBuffer && !m_isDeferralEnabled) |
| 606 m_imageBuffer->resetCanvas(m_surface->getCanvas()); | 613 m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get()); |
| 607 } | 614 } |
| 608 | 615 |
| 609 return m_surface.get(); | 616 return m_surface.get(); |
| 610 } | 617 } |
| 611 | 618 |
| 612 PaintCanvas* Canvas2DLayerBridge::canvas() { | 619 PaintCanvas* Canvas2DLayerBridge::canvas() { |
| 613 if (!m_isDeferralEnabled) { | 620 if (!m_isDeferralEnabled) { |
| 614 PaintSurface* s = getOrCreateSurface(); | 621 getOrCreateSurface(); |
| 615 return s ? s->getCanvas() : nullptr; | 622 return m_surfacePaintCanvas.get(); |
| 616 } | 623 } |
| 617 return m_recorder->getRecordingCanvas(); | 624 return m_recorder->getRecordingCanvas(); |
| 618 } | 625 } |
| 619 | 626 |
| 620 void Canvas2DLayerBridge::disableDeferral(DisableDeferralReason reason) { | 627 void Canvas2DLayerBridge::disableDeferral(DisableDeferralReason reason) { |
| 621 // Disabling deferral is permanent: once triggered by disableDeferral() | 628 // Disabling deferral is permanent: once triggered by disableDeferral() |
| 622 // we stay in immediate mode indefinitely. This is a performance heuristic | 629 // we stay in immediate mode indefinitely. This is a performance heuristic |
| 623 // that significantly helps a number of use cases. The rationale is that if | 630 // that significantly helps a number of use cases. The rationale is that if |
| 624 // immediate rendering was needed once, it is likely to be needed at least | 631 // immediate rendering was needed once, it is likely to be needed at least |
| 625 // once per frame, which eliminates the possibility for inter-frame | 632 // once per frame, which eliminates the possibility for inter-frame |
| (...skipping 11 matching lines...) Expand all Loading... |
| 637 CanvasMetrics::countCanvasContextUsage( | 644 CanvasMetrics::countCanvasContextUsage( |
| 638 CanvasMetrics::GPUAccelerated2DCanvasDeferralDisabled); | 645 CanvasMetrics::GPUAccelerated2DCanvasDeferralDisabled); |
| 639 flushRecordingOnly(); | 646 flushRecordingOnly(); |
| 640 // Because we will be discarding the recorder, if the flush failed | 647 // Because we will be discarding the recorder, if the flush failed |
| 641 // content will be lost -> force m_haveRecordedDrawCommands to false | 648 // content will be lost -> force m_haveRecordedDrawCommands to false |
| 642 m_haveRecordedDrawCommands = false; | 649 m_haveRecordedDrawCommands = false; |
| 643 | 650 |
| 644 m_isDeferralEnabled = false; | 651 m_isDeferralEnabled = false; |
| 645 m_recorder.reset(); | 652 m_recorder.reset(); |
| 646 // install the current matrix/clip stack onto the immediate canvas | 653 // install the current matrix/clip stack onto the immediate canvas |
| 647 PaintSurface* surface = getOrCreateSurface(); | 654 getOrCreateSurface(); |
| 648 if (m_imageBuffer && surface) | 655 if (m_imageBuffer && m_surfacePaintCanvas) |
| 649 m_imageBuffer->resetCanvas(surface->getCanvas()); | 656 m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get()); |
| 650 } | 657 } |
| 651 | 658 |
| 652 void Canvas2DLayerBridge::setImageBuffer(ImageBuffer* imageBuffer) { | 659 void Canvas2DLayerBridge::setImageBuffer(ImageBuffer* imageBuffer) { |
| 653 m_imageBuffer = imageBuffer; | 660 m_imageBuffer = imageBuffer; |
| 654 if (m_imageBuffer && m_isDeferralEnabled) { | 661 if (m_imageBuffer && m_isDeferralEnabled) { |
| 655 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); | 662 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); |
| 656 } | 663 } |
| 657 } | 664 } |
| 658 | 665 |
| 659 void Canvas2DLayerBridge::beginDestruction() { | 666 void Canvas2DLayerBridge::beginDestruction() { |
| 660 if (m_destructionInProgress) | 667 if (m_destructionInProgress) |
| 661 return; | 668 return; |
| 662 if (isHibernating()) | 669 if (isHibernating()) |
| 663 m_logger->reportHibernationEvent(HibernationEndedWithTeardown); | 670 m_logger->reportHibernationEvent(HibernationEndedWithTeardown); |
| 664 m_hibernationImage.reset(); | 671 m_hibernationImage.reset(); |
| 665 m_recorder.reset(); | 672 m_recorder.reset(); |
| 666 m_imageBuffer = nullptr; | 673 m_imageBuffer = nullptr; |
| 667 m_destructionInProgress = true; | 674 m_destructionInProgress = true; |
| 668 setIsHidden(true); | 675 setIsHidden(true); |
| 669 m_surface.reset(); | 676 ResetSurface(); |
| 670 | 677 |
| 671 if (m_layer && m_accelerationMode != DisableAcceleration) { | 678 if (m_layer && m_accelerationMode != DisableAcceleration) { |
| 672 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 679 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 673 m_layer->clearTexture(); | 680 m_layer->clearTexture(); |
| 674 // Orphaning the layer is required to trigger the recration of a new layer | 681 // Orphaning the layer is required to trigger the recration of a new layer |
| 675 // in the case where destruction is caused by a canvas resize. Test: | 682 // in the case where destruction is caused by a canvas resize. Test: |
| 676 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html | 683 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
| 677 m_layer->layer()->removeFromParent(); | 684 m_layer->layer()->removeFromParent(); |
| 678 } | 685 } |
| 679 | 686 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 704 BLINK_FROM_HERE, WTF::bind(&hibernateWrapperForTesting, | 711 BLINK_FROM_HERE, WTF::bind(&hibernateWrapperForTesting, |
| 705 m_weakPtrFactory.createWeakPtr())); | 712 m_weakPtrFactory.createWeakPtr())); |
| 706 } else { | 713 } else { |
| 707 Platform::current()->currentThread()->scheduler()->postIdleTask( | 714 Platform::current()->currentThread()->scheduler()->postIdleTask( |
| 708 BLINK_FROM_HERE, | 715 BLINK_FROM_HERE, |
| 709 WTF::bind(&hibernateWrapper, m_weakPtrFactory.createWeakPtr())); | 716 WTF::bind(&hibernateWrapper, m_weakPtrFactory.createWeakPtr())); |
| 710 } | 717 } |
| 711 } | 718 } |
| 712 if (!isHidden() && m_softwareRenderingWhileHidden) { | 719 if (!isHidden() && m_softwareRenderingWhileHidden) { |
| 713 flushRecordingOnly(); | 720 flushRecordingOnly(); |
| 714 PaintFlags copyPaint; | 721 SkPaint copyPaint; |
| 715 copyPaint.setBlendMode(SkBlendMode::kSrc); | 722 copyPaint.setBlendMode(SkBlendMode::kSrc); |
| 716 | 723 |
| 717 sk_sp<PaintSurface> oldSurface = std::move(m_surface); | 724 sk_sp<SkSurface> oldSurface = std::move(m_surface); |
| 718 m_surface.reset(); | 725 ResetSurface(); |
| 719 | 726 |
| 720 m_softwareRenderingWhileHidden = false; | 727 m_softwareRenderingWhileHidden = false; |
| 721 PaintSurface* newSurface = | 728 SkSurface* newSurface = |
| 722 getOrCreateSurface(PreferAccelerationAfterVisibilityChange); | 729 getOrCreateSurface(PreferAccelerationAfterVisibilityChange); |
| 723 if (newSurface) { | 730 if (newSurface) { |
| 724 if (oldSurface) | 731 if (oldSurface) |
| 725 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); | 732 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); |
| 726 if (m_imageBuffer && !m_isDeferralEnabled) { | 733 if (m_imageBuffer && !m_isDeferralEnabled) { |
| 727 m_imageBuffer->resetCanvas(m_surface->getCanvas()); | 734 m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get()); |
| 728 } | 735 } |
| 729 } | 736 } |
| 730 } | 737 } |
| 731 if (!isHidden() && isHibernating()) { | 738 if (!isHidden() && isHibernating()) { |
| 732 getOrCreateSurface(); // Rude awakening | 739 getOrCreateSurface(); // Rude awakening |
| 733 } | 740 } |
| 734 } | 741 } |
| 735 | 742 |
| 736 bool Canvas2DLayerBridge::writePixels(const SkImageInfo& origInfo, | 743 bool Canvas2DLayerBridge::writePixels(const SkImageInfo& origInfo, |
| 737 const void* pixels, | 744 const void* pixels, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 if (m_destructionInProgress) | 826 if (m_destructionInProgress) |
| 820 return false; | 827 return false; |
| 821 if (isHibernating()) | 828 if (isHibernating()) |
| 822 return true; | 829 return true; |
| 823 if (!m_layer || m_accelerationMode == DisableAcceleration) | 830 if (!m_layer || m_accelerationMode == DisableAcceleration) |
| 824 return true; | 831 return true; |
| 825 if (!m_surface) | 832 if (!m_surface) |
| 826 return false; | 833 return false; |
| 827 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != | 834 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != |
| 828 GL_NO_ERROR) { | 835 GL_NO_ERROR) { |
| 829 m_surface.reset(); | 836 ResetSurface(); |
| 830 for (auto mailboxInfo = m_mailboxes.begin(); | 837 for (auto mailboxInfo = m_mailboxes.begin(); |
| 831 mailboxInfo != m_mailboxes.end(); ++mailboxInfo) { | 838 mailboxInfo != m_mailboxes.end(); ++mailboxInfo) { |
| 832 if (mailboxInfo->m_image) | 839 if (mailboxInfo->m_image) |
| 833 mailboxInfo->m_image.reset(); | 840 mailboxInfo->m_image.reset(); |
| 834 } | 841 } |
| 835 if (m_imageBuffer) | 842 if (m_imageBuffer) |
| 836 m_imageBuffer->notifySurfaceInvalid(); | 843 m_imageBuffer->notifySurfaceInvalid(); |
| 837 CanvasMetrics::countCanvasContextUsage( | 844 CanvasMetrics::countCanvasContextUsage( |
| 838 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 845 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
| 839 } | 846 } |
| 840 return m_surface.get(); | 847 return m_surface.get(); |
| 841 } | 848 } |
| 842 | 849 |
| 843 bool Canvas2DLayerBridge::restoreSurface() { | 850 bool Canvas2DLayerBridge::restoreSurface() { |
| 844 DCHECK(!m_destructionInProgress); | 851 DCHECK(!m_destructionInProgress); |
| 845 if (m_destructionInProgress || !isAccelerated()) | 852 if (m_destructionInProgress || !isAccelerated()) |
| 846 return false; | 853 return false; |
| 847 DCHECK(!m_surface); | 854 DCHECK(!m_surface); |
| 848 | 855 |
| 849 gpu::gles2::GLES2Interface* sharedGL = nullptr; | 856 gpu::gles2::GLES2Interface* sharedGL = nullptr; |
| 850 m_layer->clearTexture(); | 857 m_layer->clearTexture(); |
| 851 m_contextProvider = WTF::wrapUnique( | 858 m_contextProvider = WTF::wrapUnique( |
| 852 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 859 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| 853 if (m_contextProvider) | 860 if (m_contextProvider) |
| 854 sharedGL = m_contextProvider->contextGL(); | 861 sharedGL = m_contextProvider->contextGL(); |
| 855 | 862 |
| 856 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { | 863 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
| 857 GrContext* grCtx = m_contextProvider->grContext(); | 864 GrContext* grCtx = m_contextProvider->grContext(); |
| 858 bool surfaceIsAccelerated; | 865 bool surfaceIsAccelerated; |
| 859 sk_sp<PaintSurface> surface(createSkSurface( | 866 sk_sp<SkSurface> surface(createSkSurface( |
| 860 grCtx, m_size, m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), | 867 grCtx, m_size, m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), |
| 861 m_colorType, &surfaceIsAccelerated)); | 868 m_colorType, &surfaceIsAccelerated)); |
| 862 if (!m_surface) | 869 if (!m_surface) |
| 863 reportSurfaceCreationFailure(); | 870 reportSurfaceCreationFailure(); |
| 864 | 871 |
| 865 // The current paradigm does not support switching from accelerated to | 872 // The current paradigm does not support switching from accelerated to |
| 866 // non-accelerated, which would be tricky due to changes to the layer tree, | 873 // non-accelerated, which would be tricky due to changes to the layer tree, |
| 867 // which can only happen at specific times during the document lifecycle. | 874 // which can only happen at specific times during the document lifecycle. |
| 868 // Therefore, we can only accept the restored surface if it is accelerated. | 875 // Therefore, we can only accept the restored surface if it is accelerated. |
| 869 if (surface && surfaceIsAccelerated) { | 876 if (surface && surfaceIsAccelerated) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 default; | 1116 default; |
| 1110 | 1117 |
| 1111 void Canvas2DLayerBridge::Logger::reportHibernationEvent( | 1118 void Canvas2DLayerBridge::Logger::reportHibernationEvent( |
| 1112 HibernationEvent event) { | 1119 HibernationEvent event) { |
| 1113 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, | 1120 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, |
| 1114 ("Canvas.HibernationEvents", HibernationEventCount)); | 1121 ("Canvas.HibernationEvents", HibernationEventCount)); |
| 1115 hibernationHistogram.count(event); | 1122 hibernationHistogram.count(event); |
| 1116 } | 1123 } |
| 1117 | 1124 |
| 1118 } // namespace blink | 1125 } // namespace blink |
| OLD | NEW |