OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "platform/graphics/RecordingImageBufferSurface.h" | 7 #include "platform/graphics/RecordingImageBufferSurface.h" |
8 | 8 |
9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
10 #include "platform/graphics/ImageBuffer.h" | 10 #include "platform/graphics/ImageBuffer.h" |
11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkPictureRecorder.h" | 13 #include "third_party/skia/include/core/SkPictureRecorder.h" |
14 #include "wtf/PassOwnPtr.h" | 14 #include "wtf/PassOwnPtr.h" |
15 #include "wtf/PassRefPtr.h" | 15 #include "wtf/PassRefPtr.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Op
acityMode opacityMode) | 19 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Pa
ssOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMod
e opacityMode) |
20 : ImageBufferSurface(size, opacityMode) | 20 : ImageBufferSurface(size, opacityMode) |
21 , m_imageBuffer(0) | 21 , m_imageBuffer(0) |
22 , m_initialSaveCount(0) | 22 , m_initialSaveCount(0) |
23 , m_frameWasCleared(true) | 23 , m_frameWasCleared(true) |
| 24 , m_fallbackFactory(fallbackFactory) |
24 { | 25 { |
25 initializeCurrentFrame(); | 26 initializeCurrentFrame(); |
26 } | 27 } |
27 | 28 |
28 RecordingImageBufferSurface::~RecordingImageBufferSurface() | 29 RecordingImageBufferSurface::~RecordingImageBufferSurface() |
29 { } | 30 { } |
30 | 31 |
31 bool RecordingImageBufferSurface::initializeCurrentFrame() | 32 bool RecordingImageBufferSurface::initializeCurrentFrame() |
32 { | 33 { |
33 StateStack stateStack; | 34 StateStack stateStack; |
(...skipping 19 matching lines...) Expand all Loading... |
53 return true; | 54 return true; |
54 } | 55 } |
55 | 56 |
56 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) | 57 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) |
57 { | 58 { |
58 m_imageBuffer = imageBuffer; | 59 m_imageBuffer = imageBuffer; |
59 if (m_currentFrame && m_imageBuffer) { | 60 if (m_currentFrame && m_imageBuffer) { |
60 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); | 61 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); |
61 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); | 62 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); |
62 } | 63 } |
| 64 if (m_fallbackSurface) { |
| 65 m_fallbackSurface->setImageBuffer(imageBuffer); |
| 66 } |
63 } | 67 } |
64 | 68 |
65 void RecordingImageBufferSurface::willAccessPixels() | 69 void RecordingImageBufferSurface::willAccessPixels() |
66 { | 70 { |
67 fallBackToRasterCanvas(); | 71 if (m_fallbackSurface) |
| 72 m_fallbackSurface->willAccessPixels(); |
| 73 else |
| 74 fallBackToRasterCanvas(); |
68 } | 75 } |
69 | 76 |
70 void RecordingImageBufferSurface::fallBackToRasterCanvas() | 77 void RecordingImageBufferSurface::fallBackToRasterCanvas() |
71 { | 78 { |
72 if (m_rasterCanvas) { | 79 if (m_fallbackSurface) { |
73 ASSERT(!m_currentFrame); | 80 ASSERT(!m_currentFrame); |
74 return; | 81 return; |
75 } | 82 } |
76 | 83 |
77 m_rasterCanvas = adoptPtr(SkCanvas::NewRasterN32(size().width(), size().heig
ht())); | 84 m_fallbackSurface = m_fallbackFactory->createSurface(size(), opacityMode()); |
| 85 m_fallbackSurface->setImageBuffer(m_imageBuffer); |
78 | 86 |
79 if (m_previousFrame) { | 87 if (m_previousFrame) { |
80 m_previousFrame->draw(m_rasterCanvas.get()); | 88 m_previousFrame->draw(m_fallbackSurface->canvas()); |
81 m_previousFrame.clear(); | 89 m_previousFrame.clear(); |
82 } | 90 } |
83 if (m_currentFrame) { | 91 if (m_currentFrame) { |
84 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording
()); | 92 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording
()); |
85 currentPicture->draw(m_rasterCanvas.get()); | 93 currentPicture->draw(m_fallbackSurface->canvas()); |
86 m_currentFrame.clear(); | 94 m_currentFrame.clear(); |
87 } | 95 } |
88 | 96 |
89 if (m_imageBuffer) { | 97 if (m_imageBuffer) { |
90 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingDisabled); | 98 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingDisabled); |
91 m_imageBuffer->context()->resetCanvas(m_rasterCanvas.get()); | 99 m_imageBuffer->context()->resetCanvas(m_fallbackSurface->canvas()); |
92 } | 100 } |
93 } | 101 } |
94 | 102 |
95 SkCanvas* RecordingImageBufferSurface::canvas() const | 103 SkCanvas* RecordingImageBufferSurface::canvas() const |
96 { | 104 { |
97 if (m_rasterCanvas) | 105 if (m_fallbackSurface) |
98 return m_rasterCanvas.get(); | 106 return m_fallbackSurface->canvas(); |
99 | 107 |
100 ASSERT(m_currentFrame->getRecordingCanvas()); | 108 ASSERT(m_currentFrame->getRecordingCanvas()); |
101 return m_currentFrame->getRecordingCanvas(); | 109 return m_currentFrame->getRecordingCanvas(); |
102 } | 110 } |
103 | 111 |
104 PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture() | 112 PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture() |
105 { | 113 { |
| 114 if (m_fallbackSurface) |
| 115 return nullptr; |
| 116 |
106 bool canUsePicture = finalizeFrameInternal(); | 117 bool canUsePicture = finalizeFrameInternal(); |
107 m_imageBuffer->didFinalizeFrame(); | 118 m_imageBuffer->didFinalizeFrame(); |
108 | 119 |
109 if (canUsePicture) { | 120 if (canUsePicture) { |
110 return m_previousFrame; | 121 return m_previousFrame; |
111 } | 122 } |
112 | 123 |
113 if (!m_rasterCanvas) | 124 if (!m_fallbackSurface) |
114 fallBackToRasterCanvas(); | 125 fallBackToRasterCanvas(); |
115 return nullptr; | 126 return nullptr; |
116 } | 127 } |
117 | 128 |
118 void RecordingImageBufferSurface::finalizeFrame(const FloatRect &) | 129 void RecordingImageBufferSurface::finalizeFrame(const FloatRect &dirtyRect) |
119 { | 130 { |
120 if (!finalizeFrameInternal() && !m_rasterCanvas) { | 131 if (m_fallbackSurface) { |
| 132 m_fallbackSurface->finalizeFrame(dirtyRect); |
| 133 return; |
| 134 } |
| 135 |
| 136 if (!finalizeFrameInternal()) |
121 fallBackToRasterCanvas(); | 137 fallBackToRasterCanvas(); |
122 } | |
123 } | 138 } |
124 | 139 |
125 void RecordingImageBufferSurface::didClearCanvas() | 140 void RecordingImageBufferSurface::didClearCanvas() |
126 { | 141 { |
| 142 if (m_fallbackSurface) { |
| 143 m_fallbackSurface->didClearCanvas(); |
| 144 return; |
| 145 } |
127 m_frameWasCleared = true; | 146 m_frameWasCleared = true; |
128 } | 147 } |
129 | 148 |
130 bool RecordingImageBufferSurface::finalizeFrameInternal() | 149 bool RecordingImageBufferSurface::finalizeFrameInternal() |
131 { | 150 { |
| 151 ASSERT(!m_fallbackSurface); |
| 152 |
132 if (!m_imageBuffer->isDirty()) { | 153 if (!m_imageBuffer->isDirty()) { |
133 if (m_currentFrame && !m_previousFrame) { | 154 if (m_currentFrame && !m_previousFrame) { |
134 // Create an initial blank frame | 155 // Create an initial blank frame |
135 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 156 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
136 initializeCurrentFrame(); | 157 initializeCurrentFrame(); |
137 } | 158 } |
138 return m_currentFrame; | 159 return m_currentFrame; |
139 } | 160 } |
140 | 161 |
141 if (!m_currentFrame) { | |
142 return false; | |
143 } | |
144 | |
145 IntRect canvasRect(IntPoint(0, 0), size()); | 162 IntRect canvasRect(IntPoint(0, 0), size()); |
146 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect()
.contains(canvasRect)) { | 163 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect()
.contains(canvasRect)) { |
147 return false; | 164 return false; |
148 } | 165 } |
149 | 166 |
150 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 167 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
151 if (!initializeCurrentFrame()) | 168 if (!initializeCurrentFrame()) |
152 return false; | 169 return false; |
153 | 170 |
154 | 171 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 dstCanvas->setMatrix(stateStack->peek().m_ctm); | 204 dstCanvas->setMatrix(stateStack->peek().m_ctm); |
188 dstCanvas->save(); | 205 dstCanvas->save(); |
189 stateStack->pop(); | 206 stateStack->pop(); |
190 } | 207 } |
191 | 208 |
192 dstCanvas->resetMatrix(); | 209 dstCanvas->resetMatrix(); |
193 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); | 210 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); |
194 dstCanvas->setMatrix(stateStack->peek().m_ctm); | 211 dstCanvas->setMatrix(stateStack->peek().m_ctm); |
195 } | 212 } |
196 | 213 |
| 214 // Fallback passthroughs |
| 215 |
| 216 const SkBitmap& RecordingImageBufferSurface::bitmap() |
| 217 { |
| 218 if (m_fallbackSurface) |
| 219 return m_fallbackSurface->bitmap(); |
| 220 return ImageBufferSurface::bitmap(); |
| 221 } |
| 222 |
| 223 bool RecordingImageBufferSurface::restore() |
| 224 { |
| 225 if (m_fallbackSurface) |
| 226 return m_fallbackSurface->restore(); |
| 227 return ImageBufferSurface::restore(); |
| 228 } |
| 229 |
| 230 WebLayer* RecordingImageBufferSurface::layer() const |
| 231 { |
| 232 if (m_fallbackSurface) |
| 233 return m_fallbackSurface->layer(); |
| 234 return ImageBufferSurface::layer(); |
| 235 } |
| 236 |
| 237 bool RecordingImageBufferSurface::isAccelerated() const |
| 238 { |
| 239 if (m_fallbackSurface) |
| 240 return m_fallbackSurface->isAccelerated(); |
| 241 return ImageBufferSurface::isAccelerated(); |
| 242 } |
| 243 |
| 244 Platform3DObject RecordingImageBufferSurface::getBackingTexture() const |
| 245 { |
| 246 if (m_fallbackSurface) |
| 247 return m_fallbackSurface->getBackingTexture(); |
| 248 return ImageBufferSurface::getBackingTexture(); |
| 249 } |
| 250 |
| 251 bool RecordingImageBufferSurface::cachedBitmapEnabled() const |
| 252 { |
| 253 if (m_fallbackSurface) |
| 254 return m_fallbackSurface->cachedBitmapEnabled(); |
| 255 return ImageBufferSurface::cachedBitmapEnabled(); |
| 256 } |
| 257 |
| 258 const SkBitmap& RecordingImageBufferSurface::cachedBitmap() const |
| 259 { |
| 260 if (m_fallbackSurface) |
| 261 return m_fallbackSurface->cachedBitmap(); |
| 262 return ImageBufferSurface::cachedBitmap(); |
| 263 } |
| 264 |
| 265 void RecordingImageBufferSurface::invalidateCachedBitmap() |
| 266 { |
| 267 if (m_fallbackSurface) |
| 268 m_fallbackSurface->invalidateCachedBitmap(); |
| 269 else |
| 270 ImageBufferSurface::invalidateCachedBitmap(); |
| 271 } |
| 272 |
| 273 void RecordingImageBufferSurface::updateCachedBitmapIfNeeded() |
| 274 { |
| 275 if (m_fallbackSurface) |
| 276 m_fallbackSurface->updateCachedBitmapIfNeeded(); |
| 277 else |
| 278 ImageBufferSurface::updateCachedBitmapIfNeeded(); |
| 279 } |
| 280 |
| 281 void RecordingImageBufferSurface::setIsHidden(bool hidden) |
| 282 { |
| 283 if (m_fallbackSurface) |
| 284 m_fallbackSurface->setIsHidden(hidden); |
| 285 else |
| 286 ImageBufferSurface::setIsHidden(hidden); |
| 287 } |
| 288 |
197 } // namespace blink | 289 } // namespace blink |
OLD | NEW |