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 21 matching lines...) Expand all Loading... |
32 m_previousFrameHasExpensiveOp(false), | 32 m_previousFrameHasExpensiveOp(false), |
33 m_fallbackFactory(std::move(fallbackFactory)) { | 33 m_fallbackFactory(std::move(fallbackFactory)) { |
34 initializeCurrentFrame(); | 34 initializeCurrentFrame(); |
35 } | 35 } |
36 | 36 |
37 RecordingImageBufferSurface::~RecordingImageBufferSurface() {} | 37 RecordingImageBufferSurface::~RecordingImageBufferSurface() {} |
38 | 38 |
39 void RecordingImageBufferSurface::initializeCurrentFrame() { | 39 void RecordingImageBufferSurface::initializeCurrentFrame() { |
40 static SkRTreeFactory rTreeFactory; | 40 static SkRTreeFactory rTreeFactory; |
41 m_currentFrame = wrapUnique(new SkPictureRecorder); | 41 m_currentFrame = wrapUnique(new SkPictureRecorder); |
42 m_currentFrame->beginRecording(size().width(), size().height(), | 42 SkCanvas* canvas = m_currentFrame->beginRecording( |
43 &rTreeFactory); | 43 size().width(), size().height(), &rTreeFactory); |
| 44 // Always save an initial frame, to support resetting the top level matrix |
| 45 // and clip. |
| 46 canvas->save(); |
| 47 |
44 if (m_imageBuffer) { | 48 if (m_imageBuffer) { |
45 m_imageBuffer->resetCanvas(m_currentFrame->getRecordingCanvas()); | 49 m_imageBuffer->resetCanvas(canvas); |
46 } | 50 } |
47 m_didRecordDrawCommandsInCurrentFrame = false; | 51 m_didRecordDrawCommandsInCurrentFrame = false; |
48 m_currentFrameHasExpensiveOp = false; | 52 m_currentFrameHasExpensiveOp = false; |
49 m_currentFramePixelCount = 0; | 53 m_currentFramePixelCount = 0; |
50 } | 54 } |
51 | 55 |
52 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) { | 56 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) { |
53 m_imageBuffer = imageBuffer; | 57 m_imageBuffer = imageBuffer; |
54 if (m_currentFrame && m_imageBuffer) { | 58 if (m_currentFrame && m_imageBuffer) { |
55 m_imageBuffer->resetCanvas(m_currentFrame->getRecordingCanvas()); | 59 m_imageBuffer->resetCanvas(m_currentFrame->getRecordingCanvas()); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 CHECK(m_currentFrame); | 293 CHECK(m_currentFrame); |
290 return true; | 294 return true; |
291 } | 295 } |
292 | 296 |
293 if (!m_frameWasCleared) { | 297 if (!m_frameWasCleared) { |
294 *fallbackReason = FallbackReasonCanvasNotClearedBetweenFrames; | 298 *fallbackReason = FallbackReasonCanvasNotClearedBetweenFrames; |
295 return false; | 299 return false; |
296 } | 300 } |
297 | 301 |
298 if (m_fallbackFactory && | 302 if (m_fallbackFactory && |
299 m_currentFrame->getRecordingCanvas()->getSaveCount() > | 303 m_currentFrame->getRecordingCanvas()->getSaveCount() - 1 > |
300 ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth) { | 304 ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth) { |
| 305 // (getSaveCount() decremented to account for the intial recording canvas |
| 306 // save frame.) |
301 *fallbackReason = FallbackReasonRunawayStateStack; | 307 *fallbackReason = FallbackReasonRunawayStateStack; |
302 return false; | 308 return false; |
303 } | 309 } |
304 | 310 |
305 m_previousFrame = m_currentFrame->finishRecordingAsPicture(); | 311 m_previousFrame = m_currentFrame->finishRecordingAsPicture(); |
306 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; | 312 m_previousFrameHasExpensiveOp = m_currentFrameHasExpensiveOp; |
307 m_previousFramePixelCount = m_currentFramePixelCount; | 313 m_previousFramePixelCount = m_currentFramePixelCount; |
308 initializeCurrentFrame(); | 314 initializeCurrentFrame(); |
309 | 315 |
310 m_frameWasCleared = false; | 316 m_frameWasCleared = false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 385 } |
380 | 386 |
381 void RecordingImageBufferSurface::setIsHidden(bool hidden) { | 387 void RecordingImageBufferSurface::setIsHidden(bool hidden) { |
382 if (m_fallbackSurface) | 388 if (m_fallbackSurface) |
383 m_fallbackSurface->setIsHidden(hidden); | 389 m_fallbackSurface->setIsHidden(hidden); |
384 else | 390 else |
385 ImageBufferSurface::setIsHidden(hidden); | 391 ImageBufferSurface::setIsHidden(hidden); |
386 } | 392 } |
387 | 393 |
388 } // namespace blink | 394 } // namespace blink |
OLD | NEW |