| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 { | 24 { |
| 25 initializeCurrentFrame(); | 25 initializeCurrentFrame(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 RecordingImageBufferSurface::~RecordingImageBufferSurface() | 28 RecordingImageBufferSurface::~RecordingImageBufferSurface() |
| 29 { } | 29 { } |
| 30 | 30 |
| 31 void RecordingImageBufferSurface::initializeCurrentFrame() | 31 bool RecordingImageBufferSurface::initializeCurrentFrame() |
| 32 { | 32 { |
| 33 StateStack stateStack; |
| 34 bool saved = false; |
| 35 if (m_currentFrame) { |
| 36 saved = saveState(m_currentFrame->getRecordingCanvas(), &stateStack); |
| 37 if (!saved) |
| 38 return false; |
| 39 } |
| 40 |
| 33 static SkRTreeFactory rTreeFactory; | 41 static SkRTreeFactory rTreeFactory; |
| 34 m_currentFrame = adoptPtr(new SkPictureRecorder); | 42 m_currentFrame = adoptPtr(new SkPictureRecorder); |
| 35 m_currentFrame->beginRecording(size().width(), size().height(), &rTreeFactor
y); | 43 m_currentFrame->beginRecording(size().width(), size().height(), &rTreeFactor
y); |
| 36 m_initialSaveCount = m_currentFrame->getRecordingCanvas()->getSaveCount(); | 44 m_initialSaveCount = m_currentFrame->getRecordingCanvas()->getSaveCount(); |
| 37 if (m_imageBuffer) { | 45 if (m_imageBuffer) { |
| 38 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); | 46 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); |
| 39 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); | 47 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); |
| 40 } | 48 } |
| 49 |
| 50 if (saved) |
| 51 setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack); |
| 52 |
| 53 return true; |
| 41 } | 54 } |
| 42 | 55 |
| 43 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) | 56 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) |
| 44 { | 57 { |
| 45 m_imageBuffer = imageBuffer; | 58 m_imageBuffer = imageBuffer; |
| 46 if (m_currentFrame && m_imageBuffer) { | 59 if (m_currentFrame && m_imageBuffer) { |
| 47 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); | 60 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT
rackingOverwrite); |
| 48 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); | 61 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas
()); |
| 49 } | 62 } |
| 50 } | 63 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 140 |
| 128 if (!m_currentFrame) { | 141 if (!m_currentFrame) { |
| 129 return false; | 142 return false; |
| 130 } | 143 } |
| 131 | 144 |
| 132 IntRect canvasRect(IntPoint(0, 0), size()); | 145 IntRect canvasRect(IntPoint(0, 0), size()); |
| 133 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect()
.contains(canvasRect)) { | 146 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect()
.contains(canvasRect)) { |
| 134 return false; | 147 return false; |
| 135 } | 148 } |
| 136 | 149 |
| 137 StateStack stateStack; | |
| 138 | |
| 139 if (!saveState(m_currentFrame->getRecordingCanvas(), &stateStack)) { | |
| 140 return false; | |
| 141 } | |
| 142 | |
| 143 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 150 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
| 144 initializeCurrentFrame(); | 151 if (!initializeCurrentFrame()) |
| 152 return false; |
| 145 | 153 |
| 146 setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack); | |
| 147 | 154 |
| 148 m_frameWasCleared = false; | 155 m_frameWasCleared = false; |
| 149 return true; | 156 return true; |
| 150 } | 157 } |
| 151 | 158 |
| 152 bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* sta
teStack) | 159 bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* sta
teStack) |
| 153 { | 160 { |
| 154 StateRec state; | 161 StateRec state; |
| 155 | 162 |
| 156 // we will remove all the saved state stack in endRecording anyway, so it ma
kes no difference | 163 // we will remove all the saved state stack in endRecording anyway, so it ma
kes no difference |
| (...skipping 24 matching lines...) Expand all Loading... |
| 181 dstCanvas->save(); | 188 dstCanvas->save(); |
| 182 stateStack->pop(); | 189 stateStack->pop(); |
| 183 } | 190 } |
| 184 | 191 |
| 185 dstCanvas->resetMatrix(); | 192 dstCanvas->resetMatrix(); |
| 186 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); | 193 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); |
| 187 dstCanvas->setMatrix(stateStack->peek().m_ctm); | 194 dstCanvas->setMatrix(stateStack->peek().m_ctm); |
| 188 } | 195 } |
| 189 | 196 |
| 190 } // namespace blink | 197 } // namespace blink |
| OLD | NEW |