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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/DeferredCanvasTest.cpp » ('j') | tests/DeferredCanvasTest.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkDeferredCanvas.cpp
===================================================================
--- src/utils/SkDeferredCanvas.cpp (revision 10481)
+++ src/utils/SkDeferredCanvas.cpp (working copy)
@@ -242,6 +242,8 @@
void beginRecording();
void init();
+ void aboutToDraw();
+ void prepareForImmediatePixelWrite();
DeferredPipeController fPipeController;
SkGPipeWriter fPipeWriter;
@@ -343,22 +345,25 @@
return fPipeController.hasPendingCommands();
}
+void DeferredDevice::aboutToDraw()
Justin Novosad 2013/08/01 18:48:01 Code factored-out to avoid duplication
+{
+ if (NULL != fNotificationClient) {
+ fNotificationClient->prepareForDraw();
+ }
+ if (fCanDiscardCanvasContents) {
+ if (NULL != fSurface) {
+ fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
+ }
+ fCanDiscardCanvasContents = false;
+ }
+}
+
void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) {
if (!fPipeController.hasPendingCommands()) {
return;
}
if (playbackMode == kNormal_PlaybackMode) {
- if (NULL != fNotificationClient) {
- fNotificationClient->prepareForDraw();
- }
- if (fCanDiscardCanvasContents) {
- if (NULL != fSurface) {
- // Pre-empt notifyContentChanged(false) calls that will happen
- // during flush
- fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
- }
- fCanDiscardCanvasContents = false;
- }
+ aboutToDraw();
}
fPipeWriter.flushRecording(true);
fPipeController.playback(kSilent_PlaybackMode == playbackMode);
@@ -441,6 +446,23 @@
return immediateDevice()->accessRenderTarget();
}
+void DeferredDevice::prepareForImmediatePixelWrite() {
+ // The purpose of the following code is to make sure commands are flushed, that
+ // aboutToDraw() is called and that notifyContentWillChange is called, without
+ // calling anything redundantly.
+ if (fPipeController.hasPendingCommands()) {
+ this->flushPendingCommands(kNormal_PlaybackMode);
+ } else {
+ bool mustNotifyDirectly = !fCanDiscardCanvasContents;
+ this->aboutToDraw();
+ if (mustNotifyDirectly) {
+ fSurface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode);
+ }
+ }
+
+ fImmediateCanvas->flush();
+}
+
void DeferredDevice::writePixels(const SkBitmap& bitmap,
int x, int y, SkCanvas::Config8888 config8888) {
@@ -453,7 +475,7 @@
SkCanvas::kNative_Premul_Config8888 != config8888 &&
kPMColorAlias != config8888) {
//Special case config: no deferral
- this->flushPendingCommands(kNormal_PlaybackMode);
+ prepareForImmediatePixelWrite();
immediateDevice()->writePixels(bitmap, x, y, config8888);
return;
}
@@ -461,7 +483,7 @@
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) {
- this->flushPendingCommands(kNormal_PlaybackMode);
+ prepareForImmediatePixelWrite();
fImmediateCanvas->drawSprite(bitmap, x, y, &paint);
} else {
this->recordingCanvas()->drawSprite(bitmap, x, y, &paint);
« 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