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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // FIXME: Derive from SkBaseDevice. | 140 // FIXME: Derive from SkBaseDevice. |
141 class DeferredDevice : public SkBitmapDevice { | 141 class DeferredDevice : public SkBitmapDevice { |
142 public: | 142 public: |
143 explicit DeferredDevice(SkBaseDevice* immediateDevice); | |
144 explicit DeferredDevice(SkSurface* surface); | 143 explicit DeferredDevice(SkSurface* surface); |
145 ~DeferredDevice(); | 144 ~DeferredDevice(); |
146 | 145 |
147 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); | 146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); |
148 SkCanvas* recordingCanvas(); | 147 SkCanvas* recordingCanvas(); |
149 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} | 148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} |
150 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice
();} | 149 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice
();} |
151 SkImage* newImageSnapshot(); | 150 SkImage* newImageSnapshot(); |
152 void setSurface(SkSurface* surface); | 151 void setSurface(SkSurface* surface); |
153 bool isFreshFrame(); | 152 bool isFreshFrame(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 SkCanvas* fRecordingCanvas; | 246 SkCanvas* fRecordingCanvas; |
248 SkSurface* fSurface; | 247 SkSurface* fSurface; |
249 SkDeferredCanvas::NotificationClient* fNotificationClient; | 248 SkDeferredCanvas::NotificationClient* fNotificationClient; |
250 bool fFreshFrame; | 249 bool fFreshFrame; |
251 bool fCanDiscardCanvasContents; | 250 bool fCanDiscardCanvasContents; |
252 size_t fMaxRecordingStorageBytes; | 251 size_t fMaxRecordingStorageBytes; |
253 size_t fPreviousStorageAllocated; | 252 size_t fPreviousStorageAllocated; |
254 size_t fBitmapSizeThreshold; | 253 size_t fBitmapSizeThreshold; |
255 }; | 254 }; |
256 | 255 |
257 DeferredDevice::DeferredDevice(SkBaseDevice* immediateDevice) | |
258 : SkBitmapDevice(SkBitmap::kNo_Config, | |
259 immediateDevice->width(), immediateDevice->height(), | |
260 immediateDevice->isOpaque(), | |
261 immediateDevice->getDeviceProperties()) { | |
262 fSurface = NULL; | |
263 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); | |
264 fPipeController.setPlaybackCanvas(fImmediateCanvas); | |
265 this->init(); | |
266 } | |
267 | |
268 DeferredDevice::DeferredDevice(SkSurface* surface) | 256 DeferredDevice::DeferredDevice(SkSurface* surface) |
269 : SkBitmapDevice(SkBitmap::kNo_Config, | 257 : SkBitmapDevice(SkBitmap::kNo_Config, |
270 surface->getCanvas()->getDevice()->width(), | 258 surface->getCanvas()->getDevice()->width(), |
271 surface->getCanvas()->getDevice()->height(), | 259 surface->getCanvas()->getDevice()->height(), |
272 surface->getCanvas()->getDevice()->isOpaque(), | 260 surface->getCanvas()->getDevice()->isOpaque(), |
273 surface->getCanvas()->getDevice()->getDeviceProperties()) { | 261 surface->getCanvas()->getDevice()->getDeviceProperties()) { |
274 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 262 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
275 fNotificationClient = NULL; | 263 fNotificationClient = NULL; |
276 fImmediateCanvas = NULL; | 264 fImmediateCanvas = NULL; |
277 fSurface = NULL; | 265 fSurface = NULL; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 532 } |
545 | 533 |
546 SkDeferredCanvas* fCanvas; | 534 SkDeferredCanvas* fCanvas; |
547 }; | 535 }; |
548 | 536 |
549 SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { | 537 SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { |
550 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surf
ace))); | 538 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surf
ace))); |
551 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); | 539 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); |
552 } | 540 } |
553 | 541 |
554 SkDeferredCanvas* SkDeferredCanvas::Create(SkBaseDevice* device) { | |
555 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (devi
ce))); | |
556 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); | |
557 } | |
558 | |
559 SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) { | 542 SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) { |
560 this->init(); | 543 this->init(); |
561 } | 544 } |
562 | 545 |
563 void SkDeferredCanvas::init() { | 546 void SkDeferredCanvas::init() { |
564 fDeferredDrawing = true; // On by default | 547 fDeferredDrawing = true; // On by default |
565 } | 548 } |
566 | 549 |
567 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { | 550 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { |
568 this->validate(); | 551 this->validate(); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 982 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
1000 this->drawingCanvas()->setDrawFilter(filter); | 983 this->drawingCanvas()->setDrawFilter(filter); |
1001 this->INHERITED::setDrawFilter(filter); | 984 this->INHERITED::setDrawFilter(filter); |
1002 this->recordedDrawCommand(); | 985 this->recordedDrawCommand(); |
1003 return filter; | 986 return filter; |
1004 } | 987 } |
1005 | 988 |
1006 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 989 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
1007 return this->drawingCanvas(); | 990 return this->drawingCanvas(); |
1008 } | 991 } |
OLD | NEW |