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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 void beginRecording(); | 241 void beginRecording(); |
242 void init(); | 242 void init(); |
243 | 243 |
244 DeferredPipeController fPipeController; | 244 DeferredPipeController fPipeController; |
245 SkGPipeWriter fPipeWriter; | 245 SkGPipeWriter fPipeWriter; |
246 SkCanvas* fImmediateCanvas; | 246 SkCanvas* fImmediateCanvas; |
247 SkCanvas* fRecordingCanvas; | 247 SkCanvas* fRecordingCanvas; |
248 SkSurface* fSurface; | 248 SkSurface* fSurface; |
249 SkDeferredCanvas::NotificationClient* fNotificationClient; | 249 SkDeferredCanvas::NotificationClient* fNotificationClient; |
250 bool fFreshFrame; | 250 bool fFreshFrame; |
| 251 bool fCanDiscardCanvasContents; |
251 size_t fMaxRecordingStorageBytes; | 252 size_t fMaxRecordingStorageBytes; |
252 size_t fPreviousStorageAllocated; | 253 size_t fPreviousStorageAllocated; |
253 size_t fBitmapSizeThreshold; | 254 size_t fBitmapSizeThreshold; |
254 }; | 255 }; |
255 | 256 |
256 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) | 257 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) |
257 : SkDevice(SkBitmap::kNo_Config, | 258 : SkDevice(SkBitmap::kNo_Config, |
258 immediateDevice->width(), immediateDevice->height(), | 259 immediateDevice->width(), immediateDevice->height(), |
259 immediateDevice->isOpaque(), | 260 immediateDevice->isOpaque(), |
260 immediateDevice->getDeviceProperties()) { | 261 immediateDevice->getDeviceProperties()) { |
(...skipping 13 matching lines...) Expand all Loading... |
274 fImmediateCanvas = surface->getCanvas(); | 275 fImmediateCanvas = surface->getCanvas(); |
275 SkSafeRef(fImmediateCanvas); | 276 SkSafeRef(fImmediateCanvas); |
276 fSurface = surface; | 277 fSurface = surface; |
277 SkSafeRef(fSurface); | 278 SkSafeRef(fSurface); |
278 this->init(); | 279 this->init(); |
279 } | 280 } |
280 | 281 |
281 void DeferredDevice::init() { | 282 void DeferredDevice::init() { |
282 fRecordingCanvas = NULL; | 283 fRecordingCanvas = NULL; |
283 fFreshFrame = true; | 284 fFreshFrame = true; |
| 285 fCanDiscardCanvasContents = false; |
284 fPreviousStorageAllocated = 0; | 286 fPreviousStorageAllocated = 0; |
285 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; | 287 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; |
286 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 288 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
287 fNotificationClient = NULL; | 289 fNotificationClient = NULL; |
288 fPipeController.setPlaybackCanvas(fImmediateCanvas); | 290 fPipeController.setPlaybackCanvas(fImmediateCanvas); |
289 this->beginRecording(); | 291 this->beginRecording(); |
290 } | 292 } |
291 | 293 |
292 DeferredDevice::~DeferredDevice() { | 294 DeferredDevice::~DeferredDevice() { |
293 this->flushPendingCommands(kSilent_PlaybackMode); | 295 this->flushPendingCommands(kSilent_PlaybackMode); |
(...skipping 11 matching lines...) Expand all Loading... |
305 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, | 307 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, |
306 immediateDevice()->width(), immediateDevice()->height()); | 308 immediateDevice()->width(), immediateDevice()->height()); |
307 } | 309 } |
308 | 310 |
309 void DeferredDevice::setNotificationClient( | 311 void DeferredDevice::setNotificationClient( |
310 SkDeferredCanvas::NotificationClient* notificationClient) { | 312 SkDeferredCanvas::NotificationClient* notificationClient) { |
311 fNotificationClient = notificationClient; | 313 fNotificationClient = notificationClient; |
312 } | 314 } |
313 | 315 |
314 void DeferredDevice::skipPendingCommands() { | 316 void DeferredDevice::skipPendingCommands() { |
315 if (!fRecordingCanvas->isDrawingToLayer() && fPipeController.hasPendingComma
nds()) { | 317 if (!fRecordingCanvas->isDrawingToLayer()) { |
316 fFreshFrame = true; | 318 fCanDiscardCanvasContents = true; |
317 flushPendingCommands(kSilent_PlaybackMode); | 319 if (fPipeController.hasPendingCommands()) { |
318 if (fNotificationClient) { | 320 fFreshFrame = true; |
319 fNotificationClient->skippedPendingDrawCommands(); | 321 flushPendingCommands(kSilent_PlaybackMode); |
| 322 if (fNotificationClient) { |
| 323 fNotificationClient->skippedPendingDrawCommands(); |
| 324 } |
320 } | 325 } |
321 } | 326 } |
322 } | 327 } |
323 | 328 |
324 bool DeferredDevice::isFreshFrame() { | 329 bool DeferredDevice::isFreshFrame() { |
325 bool ret = fFreshFrame; | 330 bool ret = fFreshFrame; |
326 fFreshFrame = false; | 331 fFreshFrame = false; |
327 return ret; | 332 return ret; |
328 } | 333 } |
329 | 334 |
330 bool DeferredDevice::hasPendingCommands() { | 335 bool DeferredDevice::hasPendingCommands() { |
331 return fPipeController.hasPendingCommands(); | 336 return fPipeController.hasPendingCommands(); |
332 } | 337 } |
333 | 338 |
334 void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) { | 339 void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) { |
335 if (!fPipeController.hasPendingCommands()) { | 340 if (!fPipeController.hasPendingCommands()) { |
336 return; | 341 return; |
337 } | 342 } |
338 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) { | 343 if (playbackMode == kNormal_PlaybackMode) { |
339 fNotificationClient->prepareForDraw(); | 344 if (NULL != fNotificationClient) { |
| 345 fNotificationClient->prepareForDraw(); |
| 346 } |
| 347 if (fCanDiscardCanvasContents) { |
| 348 if (NULL != fSurface) { |
| 349 // Pre-empt notifyContentChanged(false) calls that will happen |
| 350 // during flush |
| 351 fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentCha
ngeMode); |
| 352 } |
| 353 fCanDiscardCanvasContents = false; |
| 354 } |
340 } | 355 } |
341 fPipeWriter.flushRecording(true); | 356 fPipeWriter.flushRecording(true); |
342 fPipeController.playback(kSilent_PlaybackMode == playbackMode); | 357 fPipeController.playback(kSilent_PlaybackMode == playbackMode); |
343 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) { | 358 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) { |
344 fNotificationClient->flushedDrawCommands(); | 359 fNotificationClient->flushedDrawCommands(); |
345 } | 360 } |
346 fPreviousStorageAllocated = storageAllocatedForRecording(); | 361 fPreviousStorageAllocated = storageAllocatedForRecording(); |
347 } | 362 } |
348 | 363 |
349 void DeferredDevice::flush() { | 364 void DeferredDevice::flush() { |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 969 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
955 this->drawingCanvas()->setDrawFilter(filter); | 970 this->drawingCanvas()->setDrawFilter(filter); |
956 this->INHERITED::setDrawFilter(filter); | 971 this->INHERITED::setDrawFilter(filter); |
957 this->recordedDrawCommand(); | 972 this->recordedDrawCommand(); |
958 return filter; | 973 return filter; |
959 } | 974 } |
960 | 975 |
961 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 976 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
962 return this->drawingCanvas(); | 977 return this->drawingCanvas(); |
963 } | 978 } |
OLD | NEW |