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

Side by Side Diff: src/image/SkSurface.cpp

Issue 14063015: Adding optimization to avoid image copy in SkSurface copy on write when content is discardable (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « src/core/SkCanvas.cpp ('k') | src/image/SkSurface_Base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 SkImage* SkSurface_Base::getCachedImage() { 54 SkImage* SkSurface_Base::getCachedImage() {
55 if (NULL == fCachedImage) { 55 if (NULL == fCachedImage) {
56 fCachedImage = this->onNewImageSnapshot(); 56 fCachedImage = this->onNewImageSnapshot();
57 this->installIntoCanvasForDirtyNotification(); 57 this->installIntoCanvasForDirtyNotification();
58 } 58 }
59 return fCachedImage; 59 return fCachedImage;
60 } 60 }
61 61
62 void SkSurface_Base::aboutToDraw() { 62 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) {
63 this->dirtyGenerationID(); 63 this->dirtyGenerationID();
64 64
65 if (NULL != fCachedCanvas) { 65 if (NULL != fCachedCanvas) {
66 SkASSERT(fCachedCanvas->getSurfaceBase() == this || \ 66 SkASSERT(fCachedCanvas->getSurfaceBase() == this || \
67 NULL == fCachedCanvas->getSurfaceBase()); 67 NULL == fCachedCanvas->getSurfaceBase());
68 fCachedCanvas->setSurfaceBase(NULL); 68 fCachedCanvas->setSurfaceBase(NULL);
69 } 69 }
70 70
71 if (NULL != fCachedImage) { 71 if (NULL != fCachedImage) {
72 // the surface may need to fork its backend, if its sharing it with 72 // the surface may need to fork its backend, if its sharing it with
73 // the cached image. Note: we only call if there is an outstanding owner 73 // the cached image. Note: we only call if there is an outstanding owner
74 // on the image (besides us). 74 // on the image (besides us).
75 if (fCachedImage->getRefCnt() > 1) { 75 if (fCachedImage->getRefCnt() > 1) {
76 this->onCopyOnWrite(); 76 this->onCopyOnWrite(mode);
77 } 77 }
78 78
79 // regardless of copy-on-write, we must drop our cached image now, so 79 // regardless of copy-on-write, we must drop our cached image now, so
80 // that the next request will get our new contents. 80 // that the next request will get our new contents.
81 fCachedImage->unref(); 81 fCachedImage->unref();
82 fCachedImage = NULL; 82 fCachedImage = NULL;
83 } 83 }
84 } 84 }
85 85
86 uint32_t SkSurface_Base::newGenerationID() { 86 uint32_t SkSurface_Base::newGenerationID() {
(...skipping 15 matching lines...) Expand all
102 fGenerationID = 0; 102 fGenerationID = 0;
103 } 103 }
104 104
105 uint32_t SkSurface::generationID() { 105 uint32_t SkSurface::generationID() {
106 if (0 == fGenerationID) { 106 if (0 == fGenerationID) {
107 fGenerationID = asSB(this)->newGenerationID(); 107 fGenerationID = asSB(this)->newGenerationID();
108 } 108 }
109 return fGenerationID; 109 return fGenerationID;
110 } 110 }
111 111
112 void SkSurface::notifyContentChanged() { 112 void SkSurface::notifyContentWillChange(ContentChangeMode mode) {
113 asSB(this)->aboutToDraw(); 113 asSB(this)->aboutToDraw(mode);
114 } 114 }
115 115
116 SkCanvas* SkSurface::getCanvas() { 116 SkCanvas* SkSurface::getCanvas() {
117 return asSB(this)->getCachedCanvas(); 117 return asSB(this)->getCachedCanvas();
118 } 118 }
119 119
120 SkImage* SkSurface::newImageSnapshot() { 120 SkImage* SkSurface::newImageSnapshot() {
121 SkImage* image = asSB(this)->getCachedImage(); 121 SkImage* image = asSB(this)->getCachedImage();
122 SkSafeRef(image); // the caller will call unref() to balance this 122 SkSafeRef(image); // the caller will call unref() to balance this
123 return image; 123 return image;
124 } 124 }
125 125
126 SkSurface* SkSurface::newSurface(const SkImage::Info& info) { 126 SkSurface* SkSurface::newSurface(const SkImage::Info& info) {
127 return asSB(this)->onNewSurface(info); 127 return asSB(this)->onNewSurface(info);
128 } 128 }
129 129
130 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, 130 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
131 const SkPaint* paint) { 131 const SkPaint* paint) {
132 return asSB(this)->onDraw(canvas, x, y, paint); 132 return asSB(this)->onDraw(canvas, x, y, paint);
133 } 133 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/image/SkSurface_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698