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