OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkDeferredCanvas.h" | 9 #include "SkDeferredCanvas.h" |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 fBlock = NULL; | 130 fBlock = NULL; |
131 } | 131 } |
132 | 132 |
133 // Release all allocated blocks | 133 // Release all allocated blocks |
134 fAllocator.reset(); | 134 fAllocator.reset(); |
135 } | 135 } |
136 | 136 |
137 //----------------------------------------------------------------------------- | 137 //----------------------------------------------------------------------------- |
138 // DeferredDevice | 138 // DeferredDevice |
139 //----------------------------------------------------------------------------- | 139 //----------------------------------------------------------------------------- |
140 class DeferredDevice : public SkDevice { | 140 class DeferredDevice : public SkRasterDevice { |
141 public: | 141 public: |
142 explicit DeferredDevice(SkDevice* immediateDevice); | 142 explicit DeferredDevice(SkDevice* immediateDevice); |
143 explicit DeferredDevice(SkSurface* surface); | 143 explicit DeferredDevice(SkSurface* surface); |
144 ~DeferredDevice(); | 144 ~DeferredDevice(); |
145 | 145 |
146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); | 146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); |
147 SkCanvas* recordingCanvas(); | 147 SkCanvas* recordingCanvas(); |
148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} | 148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} |
149 SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} | 149 SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} |
150 SkImage* newImageSnapshot(); | 150 SkImage* newImageSnapshot(); |
(...skipping 16 matching lines...) Expand all Loading... |
167 | 167 |
168 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, | 168 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
169 int width, int height, | 169 int width, int height, |
170 bool isOpaque, | 170 bool isOpaque, |
171 Usage usage) SK_OVERRIDE; | 171 Usage usage) SK_OVERRIDE; |
172 | 172 |
173 virtual void writePixels(const SkBitmap& bitmap, int x, int y, | 173 virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
174 SkCanvas::Config8888 config8888) SK_OVERRIDE; | 174 SkCanvas::Config8888 config8888) SK_OVERRIDE; |
175 | 175 |
176 protected: | 176 protected: |
177 virtual const SkBitmap& onAccessBitmap(SkBitmap*) SK_OVERRIDE; | 177 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; |
178 virtual bool onReadPixels(const SkBitmap& bitmap, | 178 virtual bool onReadPixels(const SkBitmap& bitmap, |
179 int x, int y, | 179 int x, int y, |
180 SkCanvas::Config8888 config8888) SK_OVERRIDE; | 180 SkCanvas::Config8888 config8888) SK_OVERRIDE; |
181 | 181 |
182 // The following methods are no-ops on a deferred device | 182 // The following methods are no-ops on a deferred device |
183 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) | 183 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { |
184 SK_OVERRIDE | 184 return false; |
185 {return false;} | 185 } |
186 | 186 |
187 // None of the following drawing methods should ever get called on the | 187 // None of the following drawing methods should ever get called on the |
188 // deferred device | 188 // deferred device |
189 virtual void clear(SkColor color) SK_OVERRIDE | 189 virtual void clear(SkColor color) SK_OVERRIDE |
190 {SkASSERT(0);} | 190 {SkASSERT(0);} |
191 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE | 191 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE |
192 {SkASSERT(0);} | 192 {SkASSERT(0);} |
193 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 193 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
194 size_t count, const SkPoint[], | 194 size_t count, const SkPoint[], |
195 const SkPaint& paint) SK_OVERRIDE | 195 const SkPaint& paint) SK_OVERRIDE |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 SkSurface* fSurface; | 252 SkSurface* fSurface; |
253 SkDeferredCanvas::NotificationClient* fNotificationClient; | 253 SkDeferredCanvas::NotificationClient* fNotificationClient; |
254 bool fFreshFrame; | 254 bool fFreshFrame; |
255 bool fCanDiscardCanvasContents; | 255 bool fCanDiscardCanvasContents; |
256 size_t fMaxRecordingStorageBytes; | 256 size_t fMaxRecordingStorageBytes; |
257 size_t fPreviousStorageAllocated; | 257 size_t fPreviousStorageAllocated; |
258 size_t fBitmapSizeThreshold; | 258 size_t fBitmapSizeThreshold; |
259 }; | 259 }; |
260 | 260 |
261 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) | 261 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) |
262 : SkDevice(SkBitmap::kNo_Config, | 262 : SkRasterDevice(SkBitmap::kNo_Config, |
263 immediateDevice->width(), immediateDevice->height(), | 263 immediateDevice->width(), immediateDevice->height(), |
264 immediateDevice->isOpaque(), | 264 immediateDevice->isOpaque(), |
265 immediateDevice->getDeviceProperties()) { | 265 immediateDevice->getDeviceProperties()) { |
266 fSurface = NULL; | 266 fSurface = NULL; |
267 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); | 267 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); |
268 fPipeController.setPlaybackCanvas(fImmediateCanvas); | 268 fPipeController.setPlaybackCanvas(fImmediateCanvas); |
269 this->init(); | 269 this->init(); |
270 } | 270 } |
271 | 271 |
272 DeferredDevice::DeferredDevice(SkSurface* surface) | 272 DeferredDevice::DeferredDevice(SkSurface* surface) |
273 : SkDevice(SkBitmap::kNo_Config, | 273 : SkRasterDevice(SkBitmap::kNo_Config, |
274 surface->getCanvas()->getDevice()->width(), | 274 surface->getCanvas()->getDevice()->width(), |
275 surface->getCanvas()->getDevice()->height(), | 275 surface->getCanvas()->getDevice()->height(), |
276 surface->getCanvas()->getDevice()->isOpaque(), | 276 surface->getCanvas()->getDevice()->isOpaque(), |
277 surface->getCanvas()->getDevice()->getDeviceProperties()) { | 277 surface->getCanvas()->getDevice()->getDeviceProperties()) { |
278 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 278 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
279 fNotificationClient = NULL; | 279 fNotificationClient = NULL; |
280 fImmediateCanvas = NULL; | 280 fImmediateCanvas = NULL; |
281 fSurface = NULL; | 281 fSurface = NULL; |
282 this->setSurface(surface); | 282 this->setSurface(surface); |
283 this->init(); | 283 this->init(); |
284 } | 284 } |
285 | 285 |
286 void DeferredDevice::setSurface(SkSurface* surface) { | 286 void DeferredDevice::setSurface(SkSurface* surface) { |
287 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); | 287 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) { | 485 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) { |
486 prepareForImmediatePixelWrite(); | 486 prepareForImmediatePixelWrite(); |
487 fImmediateCanvas->drawSprite(bitmap, x, y, &paint); | 487 fImmediateCanvas->drawSprite(bitmap, x, y, &paint); |
488 } else { | 488 } else { |
489 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint); | 489 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint); |
490 this->recordedDrawCommand(); | 490 this->recordedDrawCommand(); |
491 | 491 |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) { | 495 const SkBitmap& DeferredDevice::onAccessBitmap() { |
496 this->flushPendingCommands(kNormal_PlaybackMode); | 496 this->flushPendingCommands(kNormal_PlaybackMode); |
497 return immediateDevice()->accessBitmap(false); | 497 return immediateDevice()->accessBitmap(false); |
498 } | 498 } |
499 | 499 |
500 SkDevice* DeferredDevice::onCreateCompatibleDevice( | 500 SkDevice* DeferredDevice::onCreateCompatibleDevice( |
501 SkBitmap::Config config, int width, int height, bool isOpaque, | 501 SkBitmap::Config config, int width, int height, bool isOpaque, |
502 Usage usage) { | 502 Usage usage) { |
503 | 503 |
504 // Save layer usage not supported, and not required by SkDeferredCanvas. | 504 // Save layer usage not supported, and not required by SkDeferredCanvas. |
505 SkASSERT(usage != kSaveLayer_Usage); | 505 SkASSERT(usage != kSaveLayer_Usage); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 1002 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
1003 this->drawingCanvas()->setDrawFilter(filter); | 1003 this->drawingCanvas()->setDrawFilter(filter); |
1004 this->INHERITED::setDrawFilter(filter); | 1004 this->INHERITED::setDrawFilter(filter); |
1005 this->recordedDrawCommand(); | 1005 this->recordedDrawCommand(); |
1006 return filter; | 1006 return filter; |
1007 } | 1007 } |
1008 | 1008 |
1009 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 1009 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
1010 return this->drawingCanvas(); | 1010 return this->drawingCanvas(); |
1011 } | 1011 } |
OLD | NEW |