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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); |
| 151 void setSurface(SkSurface* surface); |
151 bool isFreshFrame(); | 152 bool isFreshFrame(); |
152 bool hasPendingCommands(); | 153 bool hasPendingCommands(); |
153 size_t storageAllocatedForRecording() const; | 154 size_t storageAllocatedForRecording() const; |
154 size_t freeMemoryIfPossible(size_t bytesToFree); | 155 size_t freeMemoryIfPossible(size_t bytesToFree); |
155 size_t getBitmapSizeThreshold() const; | 156 size_t getBitmapSizeThreshold() const; |
156 void setBitmapSizeThreshold(size_t sizeThreshold); | 157 void setBitmapSizeThreshold(size_t sizeThreshold); |
157 void flushPendingCommands(PlaybackMode); | 158 void flushPendingCommands(PlaybackMode); |
158 void skipPendingCommands(); | 159 void skipPendingCommands(); |
159 void setMaxRecordingStorage(size_t); | 160 void setMaxRecordingStorage(size_t); |
160 void recordedDrawCommand(); | 161 void recordedDrawCommand(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 size_t fBitmapSizeThreshold; | 255 size_t fBitmapSizeThreshold; |
255 }; | 256 }; |
256 | 257 |
257 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) | 258 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) |
258 : SkDevice(SkBitmap::kNo_Config, | 259 : SkDevice(SkBitmap::kNo_Config, |
259 immediateDevice->width(), immediateDevice->height(), | 260 immediateDevice->width(), immediateDevice->height(), |
260 immediateDevice->isOpaque(), | 261 immediateDevice->isOpaque(), |
261 immediateDevice->getDeviceProperties()) { | 262 immediateDevice->getDeviceProperties()) { |
262 fSurface = NULL; | 263 fSurface = NULL; |
263 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); | 264 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); |
| 265 fPipeController.setPlaybackCanvas(fImmediateCanvas); |
264 this->init(); | 266 this->init(); |
265 } | 267 } |
266 | 268 |
267 DeferredDevice::DeferredDevice(SkSurface* surface) | 269 DeferredDevice::DeferredDevice(SkSurface* surface) |
268 : SkDevice(SkBitmap::kNo_Config, | 270 : SkDevice(SkBitmap::kNo_Config, |
269 surface->getCanvas()->getDevice()->width(), | 271 surface->getCanvas()->getDevice()->width(), |
270 surface->getCanvas()->getDevice()->height(), | 272 surface->getCanvas()->getDevice()->height(), |
271 surface->getCanvas()->getDevice()->isOpaque(), | 273 surface->getCanvas()->getDevice()->isOpaque(), |
272 surface->getCanvas()->getDevice()->getDeviceProperties()) { | 274 surface->getCanvas()->getDevice()->getDeviceProperties()) { |
273 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 275 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
274 fNotificationClient = NULL; | 276 fNotificationClient = NULL; |
275 fImmediateCanvas = surface->getCanvas(); | 277 fImmediateCanvas = NULL; |
276 SkSafeRef(fImmediateCanvas); | 278 fSurface = NULL; |
277 fSurface = surface; | 279 this->setSurface(surface); |
278 SkSafeRef(fSurface); | |
279 this->init(); | 280 this->init(); |
280 } | 281 } |
281 | 282 |
| 283 void DeferredDevice::setSurface(SkSurface* surface) { |
| 284 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); |
| 285 SkRefCnt_SafeAssign(fSurface, surface); |
| 286 fPipeController.setPlaybackCanvas(fImmediateCanvas); |
| 287 } |
| 288 |
282 void DeferredDevice::init() { | 289 void DeferredDevice::init() { |
283 fRecordingCanvas = NULL; | 290 fRecordingCanvas = NULL; |
284 fFreshFrame = true; | 291 fFreshFrame = true; |
285 fCanDiscardCanvasContents = false; | 292 fCanDiscardCanvasContents = false; |
286 fPreviousStorageAllocated = 0; | 293 fPreviousStorageAllocated = 0; |
287 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; | 294 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; |
288 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 295 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
289 fNotificationClient = NULL; | 296 fNotificationClient = NULL; |
290 fPipeController.setPlaybackCanvas(fImmediateCanvas); | |
291 this->beginRecording(); | 297 this->beginRecording(); |
292 } | 298 } |
293 | 299 |
294 DeferredDevice::~DeferredDevice() { | 300 DeferredDevice::~DeferredDevice() { |
295 this->flushPendingCommands(kSilent_PlaybackMode); | 301 this->flushPendingCommands(kSilent_PlaybackMode); |
296 SkSafeUnref(fImmediateCanvas); | 302 SkSafeUnref(fImmediateCanvas); |
297 SkSafeUnref(fSurface); | 303 SkSafeUnref(fSurface); |
298 } | 304 } |
299 | 305 |
300 void DeferredDevice::setMaxRecordingStorage(size_t maxStorage) { | 306 void DeferredDevice::setMaxRecordingStorage(size_t maxStorage) { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 } | 619 } |
614 | 620 |
615 SkDeferredCanvas::~SkDeferredCanvas() { | 621 SkDeferredCanvas::~SkDeferredCanvas() { |
616 } | 622 } |
617 | 623 |
618 SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) { | 624 SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) { |
619 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref(); | 625 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref(); |
620 return device; | 626 return device; |
621 } | 627 } |
622 | 628 |
| 629 SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) { |
| 630 DeferredDevice* deferredDevice = this->getDeferredDevice(); |
| 631 if (NULL != deferredDevice) { |
| 632 // By swapping the surface into the existing device, we preserve |
| 633 // all pending commands, which can help to seamlessly recover from |
| 634 // a lost accelerated graphics context. |
| 635 deferredDevice->setSurface(surface); |
| 636 } else { |
| 637 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref
(); |
| 638 } |
| 639 return surface; |
| 640 } |
| 641 |
623 SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient( | 642 SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient( |
624 NotificationClient* notificationClient) { | 643 NotificationClient* notificationClient) { |
625 | 644 |
626 DeferredDevice* deferredDevice = this->getDeferredDevice(); | 645 DeferredDevice* deferredDevice = this->getDeferredDevice(); |
627 SkASSERT(deferredDevice); | 646 SkASSERT(deferredDevice); |
628 if (deferredDevice) { | 647 if (deferredDevice) { |
629 deferredDevice->setNotificationClient(notificationClient); | 648 deferredDevice->setNotificationClient(notificationClient); |
630 } | 649 } |
631 return notificationClient; | 650 return notificationClient; |
632 } | 651 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 987 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
969 this->drawingCanvas()->setDrawFilter(filter); | 988 this->drawingCanvas()->setDrawFilter(filter); |
970 this->INHERITED::setDrawFilter(filter); | 989 this->INHERITED::setDrawFilter(filter); |
971 this->recordedDrawCommand(); | 990 this->recordedDrawCommand(); |
972 return filter; | 991 return filter; |
973 } | 992 } |
974 | 993 |
975 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 994 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
976 return this->drawingCanvas(); | 995 return this->drawingCanvas(); |
977 } | 996 } |
OLD | NEW |