| 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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 m_fallbackSurface = m_fallbackFactory->createSurface(size(), getOpacityMode(
)); | 81 m_fallbackSurface = m_fallbackFactory->createSurface(size(), getOpacityMode(
)); |
| 82 m_fallbackSurface->setImageBuffer(m_imageBuffer); | 82 m_fallbackSurface->setImageBuffer(m_imageBuffer); |
| 83 | 83 |
| 84 if (m_previousFrame) { | 84 if (m_previousFrame) { |
| 85 m_previousFrame->playback(m_fallbackSurface->canvas()); | 85 m_previousFrame->playback(m_fallbackSurface->canvas()); |
| 86 m_previousFrame.clear(); | 86 m_previousFrame.clear(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (m_currentFrame) { | 89 if (m_currentFrame) { |
| 90 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording
()); | 90 m_currentFrame->finishRecordingAsPicture()->playback(m_fallbackSurface->
canvas()); |
| 91 currentPicture->playback(m_fallbackSurface->canvas()); | |
| 92 m_currentFrame.clear(); | 91 m_currentFrame.clear(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 if (m_imageBuffer) { | 94 if (m_imageBuffer) { |
| 96 m_imageBuffer->resetCanvas(m_fallbackSurface->canvas()); | 95 m_imageBuffer->resetCanvas(m_fallbackSurface->canvas()); |
| 97 } | 96 } |
| 98 | 97 |
| 99 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DCanvasFal
lbackToRaster); | 98 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DCanvasFal
lbackToRaster); |
| 100 } | 99 } |
| 101 | 100 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 221 } |
| 223 | 222 |
| 224 void RecordingImageBufferSurface::willOverwriteCanvas() | 223 void RecordingImageBufferSurface::willOverwriteCanvas() |
| 225 { | 224 { |
| 226 m_frameWasCleared = true; | 225 m_frameWasCleared = true; |
| 227 m_previousFrame.clear(); | 226 m_previousFrame.clear(); |
| 228 m_previousFrameHasExpensiveOp = false; | 227 m_previousFrameHasExpensiveOp = false; |
| 229 m_previousFramePixelCount = 0; | 228 m_previousFramePixelCount = 0; |
| 230 if (m_didRecordDrawCommandsInCurrentFrame) { | 229 if (m_didRecordDrawCommandsInCurrentFrame) { |
| 231 // Discard previous draw commands | 230 // Discard previous draw commands |
| 232 adoptRef(m_currentFrame->endRecording()); | 231 m_currentFrame->finishRecordingAsPicture(); |
| 233 initializeCurrentFrame(); | 232 initializeCurrentFrame(); |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 void RecordingImageBufferSurface::didDraw(const FloatRect& rect) | 236 void RecordingImageBufferSurface::didDraw(const FloatRect& rect) |
| 238 { | 237 { |
| 239 m_didRecordDrawCommandsInCurrentFrame = true; | 238 m_didRecordDrawCommandsInCurrentFrame = true; |
| 240 IntRect pixelBounds = enclosingIntRect(rect); | 239 IntRect pixelBounds = enclosingIntRect(rect); |
| 241 m_currentFramePixelCount += pixelBounds.width() * pixelBounds.height(); | 240 m_currentFramePixelCount += pixelBounds.width() * pixelBounds.height(); |
| 242 } | 241 } |
| 243 | 242 |
| 244 bool RecordingImageBufferSurface::finalizeFrameInternal(FallbackReason* fallback
Reason) | 243 bool RecordingImageBufferSurface::finalizeFrameInternal(FallbackReason* fallback
Reason) |
| 245 { | 244 { |
| 246 ASSERT(!m_fallbackSurface); | 245 ASSERT(!m_fallbackSurface); |
| 247 ASSERT(m_currentFrame); | 246 ASSERT(m_currentFrame); |
| 248 ASSERT(m_currentFrame->getRecordingCanvas()); | 247 ASSERT(m_currentFrame->getRecordingCanvas()); |
| 249 ASSERT(fallbackReason); | 248 ASSERT(fallbackReason); |
| 250 ASSERT(*fallbackReason == FallbackReasonUnknown); | 249 ASSERT(*fallbackReason == FallbackReasonUnknown); |
| 251 | 250 |
| 252 if (!m_imageBuffer->isDirty()) { | 251 if (!m_imageBuffer->isDirty()) { |
| 253 if (!m_previousFrame) { | 252 if (!m_previousFrame) { |
| 254 // Create an initial blank frame | 253 // Create an initial blank frame |
| 255 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 254 m_previousFrame = fromSkSp(m_currentFrame->finishRecordingAsPicture(
)); |
| 256 initializeCurrentFrame(); | 255 initializeCurrentFrame(); |
| 257 } | 256 } |
| 258 return m_currentFrame; | 257 return m_currentFrame; |
| 259 } | 258 } |
| 260 | 259 |
| 261 if (!m_frameWasCleared) { | 260 if (!m_frameWasCleared) { |
| 262 *fallbackReason = FallbackReasonCanvasNotClearedBetweenFrames; | 261 *fallbackReason = FallbackReasonCanvasNotClearedBetweenFrames; |
| 263 return false; | 262 return false; |
| 264 } | 263 } |
| 265 | 264 |
| 266 if (m_currentFrame->getRecordingCanvas()->getSaveCount() > ExpensiveCanvasHe
uristicParameters::ExpensiveRecordingStackDepth) { | 265 if (m_currentFrame->getRecordingCanvas()->getSaveCount() > ExpensiveCanvasHe
uristicParameters::ExpensiveRecordingStackDepth) { |
| 267 *fallbackReason = FallbackReasonRunawayStateStack; | 266 *fallbackReason = FallbackReasonRunawayStateStack; |
| 268 return false; | 267 return false; |
| 269 } | 268 } |
| 270 | 269 |
| 271 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 270 m_previousFrame = fromSkSp(m_currentFrame->finishRecordingAsPicture()); |
| 272 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; | 271 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; |
| 273 m_previousFramePixelCount = m_currentFramePixelCount; | 272 m_previousFramePixelCount = m_currentFramePixelCount; |
| 274 initializeCurrentFrame(); | 273 initializeCurrentFrame(); |
| 275 | 274 |
| 276 m_frameWasCleared = false; | 275 m_frameWasCleared = false; |
| 277 return true; | 276 return true; |
| 278 } | 277 } |
| 279 | 278 |
| 280 void RecordingImageBufferSurface::draw(GraphicsContext& context, const FloatRect
& destRect, const FloatRect& srcRect, SkXfermode::Mode op) | 279 void RecordingImageBufferSurface::draw(GraphicsContext& context, const FloatRect
& destRect, const FloatRect& srcRect, SkXfermode::Mode op) |
| 281 { | 280 { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 343 |
| 345 void RecordingImageBufferSurface::setIsHidden(bool hidden) | 344 void RecordingImageBufferSurface::setIsHidden(bool hidden) |
| 346 { | 345 { |
| 347 if (m_fallbackSurface) | 346 if (m_fallbackSurface) |
| 348 m_fallbackSurface->setIsHidden(hidden); | 347 m_fallbackSurface->setIsHidden(hidden); |
| 349 else | 348 else |
| 350 ImageBufferSurface::setIsHidden(hidden); | 349 ImageBufferSurface::setIsHidden(hidden); |
| 351 } | 350 } |
| 352 | 351 |
| 353 } // namespace blink | 352 } // namespace blink |
| OLD | NEW |