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 "platform/graphics/RecordingImageBufferSurface.h" | 5 #include "platform/graphics/RecordingImageBufferSurface.h" |
6 | 6 |
7 #include "platform/graphics/CanvasMetrics.h" | 7 #include "platform/graphics/CanvasMetrics.h" |
8 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 8 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
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 "platform/graphics/StaticBitmapImage.h" |
11 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "third_party/skia/include/core/SkColorFilter.h" |
13 #include "third_party/skia/include/core/SkPictureRecorder.h" | 15 #include "third_party/skia/include/core/SkPictureRecorder.h" |
14 #include "wtf/PassOwnPtr.h" | 16 #include "wtf/PassOwnPtr.h" |
15 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Pa
ssOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMod
e opacityMode) | 21 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Pa
ssOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMod
e opacityMode) |
20 : ImageBufferSurface(size, opacityMode) | 22 : ImageBufferSurface(size, opacityMode) |
21 , m_imageBuffer(0) | 23 , m_imageBuffer(0) |
22 , m_currentFramePixelCount(0) | 24 , m_currentFramePixelCount(0) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 198 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
197 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; | 199 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; |
198 m_previousFramePixelCount = m_currentFramePixelCount; | 200 m_previousFramePixelCount = m_currentFramePixelCount; |
199 if (!initializeCurrentFrame()) | 201 if (!initializeCurrentFrame()) |
200 return false; | 202 return false; |
201 | 203 |
202 m_frameWasCleared = false; | 204 m_frameWasCleared = false; |
203 return true; | 205 return true; |
204 } | 206 } |
205 | 207 |
206 void RecordingImageBufferSurface::draw(GraphicsContext& context, const FloatRect
& destRect, const FloatRect& srcRect, SkXfermode::Mode op) | 208 void RecordingImageBufferSurface::draw(GraphicsContext& context, const FloatRect
& destRect, const FloatRect& srcRect, SkXfermode::Mode op, SkColorFilter* transf
orm) |
207 { | 209 { |
208 if (m_fallbackSurface) { | 210 if (m_fallbackSurface) { |
209 m_fallbackSurface->draw(context, destRect, srcRect, op); | 211 m_fallbackSurface->draw(context, destRect, srcRect, op, transform); |
210 return; | 212 return; |
211 } | 213 } |
212 | 214 |
213 RefPtr<SkPicture> picture = getPicture(); | 215 RefPtr<SkPicture> picture = getPicture(); |
214 if (picture) { | 216 if (!picture) { |
215 context.compositePicture(picture.get(), destRect, srcRect, op); | 217 ImageBufferSurface::draw(context, destRect, srcRect, op, transform); |
216 } else { | 218 return; |
217 ImageBufferSurface::draw(context, destRect, srcRect, op); | |
218 } | 219 } |
| 220 |
| 221 const SkISize size = SkISize::Make(width(), height()); |
| 222 RefPtr<SkImage> snapshot = adoptRef(SkImage::NewFromPicture(picture.get(), s
ize, nullptr, nullptr)); |
| 223 |
| 224 // FIXME: why was this alternative path being used to draw the picture? Does
it draw |
| 225 // differently to the context.drawImage path that other surfaces use to draw
? |
| 226 // context.compositePicture(picture.get(), destRect, srcRect, op); |
| 227 |
| 228 if (!transform) { |
| 229 RefPtr<Image> image = StaticBitmapImage::create(snapshot.release()); |
| 230 context.drawImage(image.get(), destRect, srcRect, op); |
| 231 return; |
| 232 } |
| 233 |
| 234 SkPaint transformPaint; |
| 235 transformPaint.setColorFilter(transform); |
| 236 transformPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 237 |
| 238 SkPictureRecorder recorder; |
| 239 FloatRect sourceRect = IntRect(0, 0, width(), height()); |
| 240 SkCanvas* canvas = recorder.beginRecording(sourceRect); |
| 241 canvas->drawImage(snapshot.get(), 0, 0, &transformPaint); |
| 242 RefPtr<SkPicture> recorded = adoptRef(recorder.endRecordingAsPicture()); |
| 243 |
| 244 snapshot = adoptRef(SkImage::NewFromPicture(recorded.get(), size, nullptr, n
ullptr)); |
| 245 |
| 246 RefPtr<Image> image = StaticBitmapImage::create(snapshot.release()); |
| 247 context.drawImage(image.get(), destRect, srcRect, op); |
219 } | 248 } |
220 | 249 |
221 bool RecordingImageBufferSurface::isExpensiveToPaint() | 250 bool RecordingImageBufferSurface::isExpensiveToPaint() |
222 { | 251 { |
223 if (m_fallbackSurface) | 252 if (m_fallbackSurface) |
224 return m_fallbackSurface->isExpensiveToPaint(); | 253 return m_fallbackSurface->isExpensiveToPaint(); |
225 | 254 |
226 if (m_didRecordDrawCommandsInCurrentFrame) { | 255 if (m_didRecordDrawCommandsInCurrentFrame) { |
227 if (m_currentFrameHasExpensiveOp) | 256 if (m_currentFrameHasExpensiveOp) |
228 return true; | 257 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 299 |
271 void RecordingImageBufferSurface::setIsHidden(bool hidden) | 300 void RecordingImageBufferSurface::setIsHidden(bool hidden) |
272 { | 301 { |
273 if (m_fallbackSurface) | 302 if (m_fallbackSurface) |
274 m_fallbackSurface->setIsHidden(hidden); | 303 m_fallbackSurface->setIsHidden(hidden); |
275 else | 304 else |
276 ImageBufferSurface::setIsHidden(hidden); | 305 ImageBufferSurface::setIsHidden(hidden); |
277 } | 306 } |
278 | 307 |
279 } // namespace blink | 308 } // namespace blink |
OLD | NEW |