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 27 matching lines...) Expand all Loading... |
38 #include "public/platform/WebCompositorSupport.h" | 38 #include "public/platform/WebCompositorSupport.h" |
39 #include "public/platform/WebGraphicsContext3DProvider.h" | 39 #include "public/platform/WebGraphicsContext3DProvider.h" |
40 #include "public/platform/WebScheduler.h" | 40 #include "public/platform/WebScheduler.h" |
41 #include "public/platform/WebTraceLocation.h" | 41 #include "public/platform/WebTraceLocation.h" |
42 #include "skia/ext/texture_handle.h" | 42 #include "skia/ext/texture_handle.h" |
43 #include "third_party/skia/include/core/SkData.h" | 43 #include "third_party/skia/include/core/SkData.h" |
44 #include "third_party/skia/include/core/SkPictureRecorder.h" | 44 #include "third_party/skia/include/core/SkPictureRecorder.h" |
45 #include "third_party/skia/include/core/SkSurface.h" | 45 #include "third_party/skia/include/core/SkSurface.h" |
46 #include "third_party/skia/include/gpu/GrContext.h" | 46 #include "third_party/skia/include/gpu/GrContext.h" |
47 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 47 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
48 #include "wtf/PtrUtil.h" | |
49 #include <memory> | |
50 | 48 |
51 namespace { | 49 namespace { |
52 enum { | 50 enum { |
53 InvalidMailboxIndex = -1, | 51 InvalidMailboxIndex = -1, |
54 MaxCanvasAnimationBacklog = 2, // Make sure the the GPU is never more than t
wo animation frames behind. | 52 MaxCanvasAnimationBacklog = 2, // Make sure the the GPU is never more than t
wo animation frames behind. |
55 }; | 53 }; |
56 } // namespace | 54 } // namespace |
57 | 55 |
58 namespace blink { | 56 namespace blink { |
59 | 57 |
(...skipping 23 matching lines...) Expand all Loading... |
83 } else { | 81 } else { |
84 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 82 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
85 } | 83 } |
86 } | 84 } |
87 return fromSkSp(surface); | 85 return fromSkSp(surface); |
88 } | 86 } |
89 | 87 |
90 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, AccelerationMode accelerationMode
) | 88 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, AccelerationMode accelerationMode
) |
91 { | 89 { |
92 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", TRACE_EVENT_
SCOPE_GLOBAL); | 90 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", TRACE_EVENT_
SCOPE_GLOBAL); |
93 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P
latform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 91 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu
rrent()->createSharedOffscreenGraphicsContext3DProvider()); |
94 if (!contextProvider) | 92 if (!contextProvider) |
95 return nullptr; | 93 return nullptr; |
96 RefPtr<Canvas2DLayerBridge> layerBridge; | 94 RefPtr<Canvas2DLayerBridge> layerBridge; |
97 layerBridge = adoptRef(new Canvas2DLayerBridge(std::move(contextProvider), s
ize, msaaSampleCount, opacityMode, accelerationMode)); | 95 layerBridge = adoptRef(new Canvas2DLayerBridge(std::move(contextProvider), s
ize, msaaSampleCount, opacityMode, accelerationMode)); |
98 return layerBridge.release(); | 96 return layerBridge.release(); |
99 } | 97 } |
100 | 98 |
101 Canvas2DLayerBridge::Canvas2DLayerBridge(std::unique_ptr<WebGraphicsContext3DPro
vider> contextProvider, const IntSize& size, int msaaSampleCount, OpacityMode op
acityMode, AccelerationMode accelerationMode) | 99 Canvas2DLayerBridge::Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider
> contextProvider, const IntSize& size, int msaaSampleCount, OpacityMode opacity
Mode, AccelerationMode accelerationMode) |
102 : m_contextProvider(std::move(contextProvider)) | 100 : m_contextProvider(std::move(contextProvider)) |
103 , m_logger(wrapUnique(new Logger)) | 101 , m_logger(adoptPtr(new Logger)) |
104 , m_weakPtrFactory(this) | 102 , m_weakPtrFactory(this) |
105 , m_imageBuffer(0) | 103 , m_imageBuffer(0) |
106 , m_msaaSampleCount(msaaSampleCount) | 104 , m_msaaSampleCount(msaaSampleCount) |
107 , m_bytesAllocated(0) | 105 , m_bytesAllocated(0) |
108 , m_haveRecordedDrawCommands(false) | 106 , m_haveRecordedDrawCommands(false) |
109 , m_destructionInProgress(false) | 107 , m_destructionInProgress(false) |
110 , m_filterQuality(kLow_SkFilterQuality) | 108 , m_filterQuality(kLow_SkFilterQuality) |
111 , m_isHidden(false) | 109 , m_isHidden(false) |
112 , m_isDeferralEnabled(true) | 110 , m_isDeferralEnabled(true) |
113 , m_isRegisteredTaskObserver(false) | 111 , m_isRegisteredTaskObserver(false) |
(...skipping 18 matching lines...) Expand all Loading... |
132 clearCHROMIUMImageCache(); | 130 clearCHROMIUMImageCache(); |
133 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 131 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
134 | 132 |
135 m_layer.reset(); | 133 m_layer.reset(); |
136 DCHECK_EQ(0u, m_mailboxes.size()); | 134 DCHECK_EQ(0u, m_mailboxes.size()); |
137 } | 135 } |
138 | 136 |
139 void Canvas2DLayerBridge::startRecording() | 137 void Canvas2DLayerBridge::startRecording() |
140 { | 138 { |
141 DCHECK(m_isDeferralEnabled); | 139 DCHECK(m_isDeferralEnabled); |
142 m_recorder = wrapUnique(new SkPictureRecorder); | 140 m_recorder = adoptPtr(new SkPictureRecorder); |
143 m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr); | 141 m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr); |
144 if (m_imageBuffer) { | 142 if (m_imageBuffer) { |
145 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); | 143 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); |
146 } | 144 } |
147 m_recordingPixelCount = 0; | 145 m_recordingPixelCount = 0; |
148 } | 146 } |
149 | 147 |
150 void Canvas2DLayerBridge::setLoggerForTesting(std::unique_ptr<Logger> logger) | 148 void Canvas2DLayerBridge::setLoggerForTesting(PassOwnPtr<Logger> logger) |
151 { | 149 { |
152 m_logger = std::move(logger); | 150 m_logger = std::move(logger); |
153 } | 151 } |
154 | 152 |
155 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const | 153 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const |
156 { | 154 { |
157 bool accelerate; | 155 bool accelerate; |
158 if (m_softwareRenderingWhileHidden) | 156 if (m_softwareRenderingWhileHidden) |
159 accelerate = false; | 157 accelerate = false; |
160 else if (m_accelerationMode == ForceAccelerationForTesting) | 158 else if (m_accelerationMode == ForceAccelerationForTesting) |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 wantAcceleration = false; | 477 wantAcceleration = false; |
480 m_softwareRenderingWhileHidden = true; | 478 m_softwareRenderingWhileHidden = true; |
481 } | 479 } |
482 | 480 |
483 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); | 481 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); |
484 | 482 |
485 if (!m_surface) | 483 if (!m_surface) |
486 reportSurfaceCreationFailure(); | 484 reportSurfaceCreationFailure(); |
487 | 485 |
488 if (m_surface && surfaceIsAccelerated && !m_layer) { | 486 if (m_surface && surfaceIsAccelerated && !m_layer) { |
489 m_layer = wrapUnique(Platform::current()->compositorSupport()->createExt
ernalTextureLayer(this)); | 487 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter
nalTextureLayer(this)); |
490 m_layer->setOpaque(m_opacityMode == Opaque); | 488 m_layer->setOpaque(m_opacityMode == Opaque); |
491 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); | 489 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); |
492 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 490 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
493 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); | 491 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); |
494 } | 492 } |
495 | 493 |
496 if (m_surface && isHibernating()) { | 494 if (m_surface && isHibernating()) { |
497 if (surfaceIsAccelerated) { | 495 if (surfaceIsAccelerated) { |
498 m_logger->reportHibernationEvent(HibernationEndedNormally); | 496 m_logger->reportHibernationEvent(HibernationEndedNormally); |
499 } else { | 497 } else { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 741 |
744 bool Canvas2DLayerBridge::restoreSurface() | 742 bool Canvas2DLayerBridge::restoreSurface() |
745 { | 743 { |
746 DCHECK(!m_destructionInProgress); | 744 DCHECK(!m_destructionInProgress); |
747 if (m_destructionInProgress) | 745 if (m_destructionInProgress) |
748 return false; | 746 return false; |
749 DCHECK(isAccelerated() && !m_surface); | 747 DCHECK(isAccelerated() && !m_surface); |
750 | 748 |
751 gpu::gles2::GLES2Interface* sharedGL = nullptr; | 749 gpu::gles2::GLES2Interface* sharedGL = nullptr; |
752 m_layer->clearTexture(); | 750 m_layer->clearTexture(); |
753 m_contextProvider = wrapUnique(Platform::current()->createSharedOffscreenGra
phicsContext3DProvider()); | 751 m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraph
icsContext3DProvider()); |
754 if (m_contextProvider) | 752 if (m_contextProvider) |
755 sharedGL = m_contextProvider->contextGL(); | 753 sharedGL = m_contextProvider->contextGL(); |
756 | 754 |
757 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { | 755 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
758 GrContext* grCtx = m_contextProvider->grContext(); | 756 GrContext* grCtx = m_contextProvider->grContext(); |
759 bool surfaceIsAccelerated; | 757 bool surfaceIsAccelerated; |
760 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou
nt, m_opacityMode, &surfaceIsAccelerated)); | 758 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou
nt, m_opacityMode, &surfaceIsAccelerated)); |
761 | 759 |
762 if (!m_surface) | 760 if (!m_surface) |
763 reportSurfaceCreationFailure(); | 761 reportSurfaceCreationFailure(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 994 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
997 } | 995 } |
998 | 996 |
999 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 997 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
1000 { | 998 { |
1001 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); | 999 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); |
1002 hibernationHistogram.count(event); | 1000 hibernationHistogram.count(event); |
1003 } | 1001 } |
1004 | 1002 |
1005 } // namespace blink | 1003 } // namespace blink |
OLD | NEW |