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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

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

Powered by Google App Engine
This is Rietveld 408576698