Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/utils/SkDeferredCanvas.cpp

Issue 20628005: Fixing SkDeferredCanvas::writePixels to trigger appropriate change notifications to SkSurface (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/DeferredCanvasTest.cpp » ('j') | tests/DeferredCanvasTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int indexCount, const SkPaint& paint) SK_OVERRID E 235 int indexCount, const SkPaint& paint) SK_OVERRID E
236 {SkASSERT(0);} 236 {SkASSERT(0);}
237 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, 237 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
238 const SkPaint&) SK_OVERRIDE 238 const SkPaint&) SK_OVERRIDE
239 {SkASSERT(0);} 239 {SkASSERT(0);}
240 private: 240 private:
241 virtual void flush() SK_OVERRIDE; 241 virtual void flush() SK_OVERRIDE;
242 242
243 void beginRecording(); 243 void beginRecording();
244 void init(); 244 void init();
245 void aboutToDraw();
246 void prepareForImmediatePixelWrite();
245 247
246 DeferredPipeController fPipeController; 248 DeferredPipeController fPipeController;
247 SkGPipeWriter fPipeWriter; 249 SkGPipeWriter fPipeWriter;
248 SkCanvas* fImmediateCanvas; 250 SkCanvas* fImmediateCanvas;
249 SkCanvas* fRecordingCanvas; 251 SkCanvas* fRecordingCanvas;
250 SkSurface* fSurface; 252 SkSurface* fSurface;
251 SkDeferredCanvas::NotificationClient* fNotificationClient; 253 SkDeferredCanvas::NotificationClient* fNotificationClient;
252 bool fFreshFrame; 254 bool fFreshFrame;
253 bool fCanDiscardCanvasContents; 255 bool fCanDiscardCanvasContents;
254 size_t fMaxRecordingStorageBytes; 256 size_t fMaxRecordingStorageBytes;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 bool DeferredDevice::isFreshFrame() { 338 bool DeferredDevice::isFreshFrame() {
337 bool ret = fFreshFrame; 339 bool ret = fFreshFrame;
338 fFreshFrame = false; 340 fFreshFrame = false;
339 return ret; 341 return ret;
340 } 342 }
341 343
342 bool DeferredDevice::hasPendingCommands() { 344 bool DeferredDevice::hasPendingCommands() {
343 return fPipeController.hasPendingCommands(); 345 return fPipeController.hasPendingCommands();
344 } 346 }
345 347
348 void DeferredDevice::aboutToDraw()
Justin Novosad 2013/08/01 18:48:01 Code factored-out to avoid duplication
349 {
350 if (NULL != fNotificationClient) {
351 fNotificationClient->prepareForDraw();
352 }
353 if (fCanDiscardCanvasContents) {
354 if (NULL != fSurface) {
355 fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeM ode);
356 }
357 fCanDiscardCanvasContents = false;
358 }
359 }
360
346 void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) { 361 void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) {
347 if (!fPipeController.hasPendingCommands()) { 362 if (!fPipeController.hasPendingCommands()) {
348 return; 363 return;
349 } 364 }
350 if (playbackMode == kNormal_PlaybackMode) { 365 if (playbackMode == kNormal_PlaybackMode) {
351 if (NULL != fNotificationClient) { 366 aboutToDraw();
352 fNotificationClient->prepareForDraw();
353 }
354 if (fCanDiscardCanvasContents) {
355 if (NULL != fSurface) {
356 // Pre-empt notifyContentChanged(false) calls that will happen
357 // during flush
358 fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentCha ngeMode);
359 }
360 fCanDiscardCanvasContents = false;
361 }
362 } 367 }
363 fPipeWriter.flushRecording(true); 368 fPipeWriter.flushRecording(true);
364 fPipeController.playback(kSilent_PlaybackMode == playbackMode); 369 fPipeController.playback(kSilent_PlaybackMode == playbackMode);
365 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) { 370 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) {
366 fNotificationClient->flushedDrawCommands(); 371 fNotificationClient->flushedDrawCommands();
367 } 372 }
368 fPreviousStorageAllocated = storageAllocatedForRecording(); 373 fPreviousStorageAllocated = storageAllocatedForRecording();
369 } 374 }
370 375
371 void DeferredDevice::flush() { 376 void DeferredDevice::flush() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 439
435 int DeferredDevice::height() const { 440 int DeferredDevice::height() const {
436 return immediateDevice()->height(); 441 return immediateDevice()->height();
437 } 442 }
438 443
439 GrRenderTarget* DeferredDevice::accessRenderTarget() { 444 GrRenderTarget* DeferredDevice::accessRenderTarget() {
440 this->flushPendingCommands(kNormal_PlaybackMode); 445 this->flushPendingCommands(kNormal_PlaybackMode);
441 return immediateDevice()->accessRenderTarget(); 446 return immediateDevice()->accessRenderTarget();
442 } 447 }
443 448
449 void DeferredDevice::prepareForImmediatePixelWrite() {
450 // The purpose of the following code is to make sure commands are flushed, t hat
451 // aboutToDraw() is called and that notifyContentWillChange is called, witho ut
452 // calling anything redundantly.
453 if (fPipeController.hasPendingCommands()) {
454 this->flushPendingCommands(kNormal_PlaybackMode);
455 } else {
456 bool mustNotifyDirectly = !fCanDiscardCanvasContents;
457 this->aboutToDraw();
458 if (mustNotifyDirectly) {
459 fSurface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMo de);
460 }
461 }
462
463 fImmediateCanvas->flush();
464 }
465
444 void DeferredDevice::writePixels(const SkBitmap& bitmap, 466 void DeferredDevice::writePixels(const SkBitmap& bitmap,
445 int x, int y, SkCanvas::Config8888 config8888) { 467 int x, int y, SkCanvas::Config8888 config8888) {
446 468
447 if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() && 469 if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() &&
448 (y + bitmap.height()) >= height()) { 470 (y + bitmap.height()) >= height()) {
449 this->skipPendingCommands(); 471 this->skipPendingCommands();
450 } 472 }
451 473
452 if (SkBitmap::kARGB_8888_Config == bitmap.config() && 474 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
453 SkCanvas::kNative_Premul_Config8888 != config8888 && 475 SkCanvas::kNative_Premul_Config8888 != config8888 &&
454 kPMColorAlias != config8888) { 476 kPMColorAlias != config8888) {
455 //Special case config: no deferral 477 //Special case config: no deferral
456 this->flushPendingCommands(kNormal_PlaybackMode); 478 prepareForImmediatePixelWrite();
457 immediateDevice()->writePixels(bitmap, x, y, config8888); 479 immediateDevice()->writePixels(bitmap, x, y, config8888);
458 return; 480 return;
459 } 481 }
460 482
461 SkPaint paint; 483 SkPaint paint;
462 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 484 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
463 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) { 485 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) {
464 this->flushPendingCommands(kNormal_PlaybackMode); 486 prepareForImmediatePixelWrite();
465 fImmediateCanvas->drawSprite(bitmap, x, y, &paint); 487 fImmediateCanvas->drawSprite(bitmap, x, y, &paint);
466 } else { 488 } else {
467 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint); 489 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint);
468 this->recordedDrawCommand(); 490 this->recordedDrawCommand();
469 491
470 } 492 }
471 } 493 }
472 494
473 const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) { 495 const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) {
474 this->flushPendingCommands(kNormal_PlaybackMode); 496 this->flushPendingCommands(kNormal_PlaybackMode);
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 1029 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
1008 this->drawingCanvas()->setDrawFilter(filter); 1030 this->drawingCanvas()->setDrawFilter(filter);
1009 this->INHERITED::setDrawFilter(filter); 1031 this->INHERITED::setDrawFilter(filter);
1010 this->recordedDrawCommand(); 1032 this->recordedDrawCommand();
1011 return filter; 1033 return filter;
1012 } 1034 }
1013 1035
1014 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 1036 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
1015 return this->drawingCanvas(); 1037 return this->drawingCanvas();
1016 } 1038 }
OLDNEW
« no previous file with comments | « no previous file | tests/DeferredCanvasTest.cpp » ('j') | tests/DeferredCanvasTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698