| 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/Histogram.h" | 7 #include "platform/Histogram.h" |
| 8 #include "platform/graphics/CanvasMetrics.h" | 8 #include "platform/graphics/CanvasMetrics.h" |
| 9 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 9 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 10 #include "platform/graphics/GraphicsContext.h" | 10 #include "platform/graphics/GraphicsContext.h" |
| 11 #include "platform/graphics/ImageBuffer.h" | 11 #include "platform/graphics/ImageBuffer.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 "skia/ext/cdl_picture_recorder.h" |
| 14 #include "wtf/PassRefPtr.h" | 14 #include "wtf/PassRefPtr.h" |
| 15 #include "wtf/PtrUtil.h" | 15 #include "wtf/PtrUtil.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 RecordingImageBufferSurface::RecordingImageBufferSurface( | 20 RecordingImageBufferSurface::RecordingImageBufferSurface( |
| 21 const IntSize& size, | 21 const IntSize& size, |
| 22 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, | 22 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, |
| 23 OpacityMode opacityMode, | 23 OpacityMode opacityMode, |
| 24 sk_sp<SkColorSpace> colorSpace, | 24 sk_sp<SkColorSpace> colorSpace, |
| 25 SkColorType colorType) | 25 SkColorType colorType) |
| 26 : ImageBufferSurface(size, opacityMode, std::move(colorSpace), colorType), | 26 : ImageBufferSurface(size, opacityMode, std::move(colorSpace), colorType), |
| 27 m_imageBuffer(0), | 27 m_imageBuffer(0), |
| 28 m_currentFramePixelCount(0), | 28 m_currentFramePixelCount(0), |
| 29 m_previousFramePixelCount(0), | 29 m_previousFramePixelCount(0), |
| 30 m_frameWasCleared(true), | 30 m_frameWasCleared(true), |
| 31 m_didRecordDrawCommandsInCurrentFrame(false), | 31 m_didRecordDrawCommandsInCurrentFrame(false), |
| 32 m_currentFrameHasExpensiveOp(false), | 32 m_currentFrameHasExpensiveOp(false), |
| 33 m_previousFrameHasExpensiveOp(false), | 33 m_previousFrameHasExpensiveOp(false), |
| 34 m_fallbackFactory(std::move(fallbackFactory)) { | 34 m_fallbackFactory(std::move(fallbackFactory)) { |
| 35 initializeCurrentFrame(); | 35 initializeCurrentFrame(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 RecordingImageBufferSurface::~RecordingImageBufferSurface() {} | 38 RecordingImageBufferSurface::~RecordingImageBufferSurface() {} |
| 39 | 39 |
| 40 void RecordingImageBufferSurface::initializeCurrentFrame() { | 40 void RecordingImageBufferSurface::initializeCurrentFrame() { |
| 41 static SkRTreeFactory rTreeFactory; | 41 static SkRTreeFactory rTreeFactory; |
| 42 m_currentFrame = wrapUnique(new SkPictureRecorder); | 42 m_currentFrame = wrapUnique(new CdlPictureRecorder); |
| 43 SkCanvas* canvas = m_currentFrame->beginRecording( | 43 CdlCanvas* canvas = m_currentFrame->beginRecording( |
| 44 size().width(), size().height(), &rTreeFactory); | 44 size().width(), size().height(), &rTreeFactory); |
| 45 // Always save an initial frame, to support resetting the top level matrix | 45 // Always save an initial frame, to support resetting the top level matrix |
| 46 // and clip. | 46 // and clip. |
| 47 canvas->save(); | 47 canvas->save(); |
| 48 | 48 |
| 49 if (m_imageBuffer) { | 49 if (m_imageBuffer) { |
| 50 m_imageBuffer->resetCanvas(canvas); | 50 m_imageBuffer->resetCanvas(canvas); |
| 51 } | 51 } |
| 52 m_didRecordDrawCommandsInCurrentFrame = false; | 52 m_didRecordDrawCommandsInCurrentFrame = false; |
| 53 m_currentFrameHasExpensiveOp = false; | 53 m_currentFrameHasExpensiveOp = false; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 158 } |
| 159 | 159 |
| 160 sk_sp<SkImage> RecordingImageBufferSurface::newImageSnapshot( | 160 sk_sp<SkImage> RecordingImageBufferSurface::newImageSnapshot( |
| 161 AccelerationHint hint, | 161 AccelerationHint hint, |
| 162 SnapshotReason reason) { | 162 SnapshotReason reason) { |
| 163 if (!m_fallbackSurface) | 163 if (!m_fallbackSurface) |
| 164 fallBackToRasterCanvas(snapshotReasonToFallbackReason(reason)); | 164 fallBackToRasterCanvas(snapshotReasonToFallbackReason(reason)); |
| 165 return m_fallbackSurface->newImageSnapshot(hint, reason); | 165 return m_fallbackSurface->newImageSnapshot(hint, reason); |
| 166 } | 166 } |
| 167 | 167 |
| 168 SkCanvas* RecordingImageBufferSurface::canvas() { | 168 CdlCanvas* RecordingImageBufferSurface::canvas() { |
| 169 if (m_fallbackSurface) | 169 if (m_fallbackSurface) |
| 170 return m_fallbackSurface->canvas(); | 170 return m_fallbackSurface->canvas(); |
| 171 | 171 |
| 172 ASSERT(m_currentFrame->getRecordingCanvas()); | 172 ASSERT(m_currentFrame->getRecordingCanvas()); |
| 173 return m_currentFrame->getRecordingCanvas(); | 173 return m_currentFrame->getRecordingCanvas(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 static RecordingImageBufferSurface::FallbackReason | 176 static RecordingImageBufferSurface::FallbackReason |
| 177 disableDeferralReasonToFallbackReason(DisableDeferralReason reason) { | 177 disableDeferralReasonToFallbackReason(DisableDeferralReason reason) { |
| 178 switch (reason) { | 178 switch (reason) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 201 ASSERT_NOT_REACHED(); | 201 ASSERT_NOT_REACHED(); |
| 202 return RecordingImageBufferSurface::FallbackReasonUnknown; | 202 return RecordingImageBufferSurface::FallbackReasonUnknown; |
| 203 } | 203 } |
| 204 | 204 |
| 205 void RecordingImageBufferSurface::disableDeferral( | 205 void RecordingImageBufferSurface::disableDeferral( |
| 206 DisableDeferralReason reason) { | 206 DisableDeferralReason reason) { |
| 207 if (!m_fallbackSurface) | 207 if (!m_fallbackSurface) |
| 208 fallBackToRasterCanvas(disableDeferralReasonToFallbackReason(reason)); | 208 fallBackToRasterCanvas(disableDeferralReasonToFallbackReason(reason)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 sk_sp<SkPicture> RecordingImageBufferSurface::getPicture() { | 211 sk_sp<CdlPicture> RecordingImageBufferSurface::getPicture() { |
| 212 if (m_fallbackSurface) | 212 if (m_fallbackSurface) |
| 213 return nullptr; | 213 return nullptr; |
| 214 | 214 |
| 215 FallbackReason fallbackReason = FallbackReasonUnknown; | 215 FallbackReason fallbackReason = FallbackReasonUnknown; |
| 216 bool canUsePicture = finalizeFrameInternal(&fallbackReason); | 216 bool canUsePicture = finalizeFrameInternal(&fallbackReason); |
| 217 m_imageBuffer->didFinalizeFrame(); | 217 m_imageBuffer->didFinalizeFrame(); |
| 218 | 218 |
| 219 ASSERT(canUsePicture || m_fallbackFactory); | 219 ASSERT(canUsePicture || m_fallbackFactory); |
| 220 | 220 |
| 221 if (canUsePicture) { | 221 if (canUsePicture) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 320 |
| 321 void RecordingImageBufferSurface::draw(GraphicsContext& context, | 321 void RecordingImageBufferSurface::draw(GraphicsContext& context, |
| 322 const FloatRect& destRect, | 322 const FloatRect& destRect, |
| 323 const FloatRect& srcRect, | 323 const FloatRect& srcRect, |
| 324 SkBlendMode op) { | 324 SkBlendMode op) { |
| 325 if (m_fallbackSurface) { | 325 if (m_fallbackSurface) { |
| 326 m_fallbackSurface->draw(context, destRect, srcRect, op); | 326 m_fallbackSurface->draw(context, destRect, srcRect, op); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 sk_sp<SkPicture> picture = getPicture(); | 330 sk_sp<CdlPicture> picture = getPicture(); |
| 331 if (picture) { | 331 if (picture) { |
| 332 context.compositePicture(std::move(picture), destRect, srcRect, op); | 332 context.compositePicture(std::move(picture), destRect, srcRect, op); |
| 333 } else { | 333 } else { |
| 334 ImageBufferSurface::draw(context, destRect, srcRect, op); | 334 ImageBufferSurface::draw(context, destRect, srcRect, op); |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 | 337 |
| 338 bool RecordingImageBufferSurface::isExpensiveToPaint() { | 338 bool RecordingImageBufferSurface::isExpensiveToPaint() { |
| 339 if (m_fallbackSurface) | 339 if (m_fallbackSurface) |
| 340 return m_fallbackSurface->isExpensiveToPaint(); | 340 return m_fallbackSurface->isExpensiveToPaint(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 | 387 |
| 388 void RecordingImageBufferSurface::setIsHidden(bool hidden) { | 388 void RecordingImageBufferSurface::setIsHidden(bool hidden) { |
| 389 if (m_fallbackSurface) | 389 if (m_fallbackSurface) |
| 390 m_fallbackSurface->setIsHidden(hidden); | 390 m_fallbackSurface->setIsHidden(hidden); |
| 391 else | 391 else |
| 392 ImageBufferSurface::setIsHidden(hidden); | 392 ImageBufferSurface::setIsHidden(hidden); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace blink | 395 } // namespace blink |
| OLD | NEW |