OLD | NEW |
---|---|
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 Loading... | |
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->onNewImageShapshot(); | 56 fCachedImage = this->onNewImageShapshot(); |
57 this->installIntoCanvasForDirtyNotification(); | 57 this->installIntoCanvasForDirtyNotification(); |
58 } | 58 } |
59 return fCachedImage; | 59 return fCachedImage; |
60 } | 60 } |
61 | 61 |
62 void SkSurface_Base::aboutToDraw(SkCanvas* canvas) { | 62 void SkSurface_Base::aboutToDraw(SkCanvas* canvas, bool canDiscardContents) { |
63 this->dirtyGenerationID(); | 63 this->dirtyGenerationID(); |
64 | 64 |
65 if (canvas) { | 65 SkASSERT(canvas == fCachedCanvas); |
66 SkASSERT(canvas == fCachedCanvas); | 66 SkASSERT(canvas->getSurfaceBase() == this || NULL == fCachedImage); |
reed1
2013/03/27 15:31:43
Why this || clause?
I presume it is because the p
| |
67 SkASSERT(canvas->getSurfaceBase() == this); | 67 canvas->setSurfaceBase(NULL); |
68 canvas->setSurfaceBase(NULL); | |
69 } | |
70 | 68 |
71 if (fCachedImage) { | 69 if (fCachedImage) { |
72 // the surface may need to fork its backend, if its sharing it with | 70 // the surface may need to fork its backend, if it's sharing it with |
73 // the cached image. Note: we only call if there is an outstanding owner | 71 // the cached image. Note: we only call if there is an outstanding owner |
74 // on the image (besides us). | 72 // on the image (besides us). |
75 if (fCachedImage->getRefCnt() > 1) { | 73 if (fCachedImage->getRefCnt() > 1) { |
76 this->onCopyOnWrite(fCachedImage, canvas); | 74 this->onCopyOnWrite(fCachedImage, canvas, canDiscardContents); |
77 } | 75 } |
78 | 76 |
79 // regardless of copy-on-write, we must drop our cached image now, so | 77 // regardless of copy-on-write, we must drop our cached image now, so |
80 // that the next request will get our new contents. | 78 // that the next request will get our new contents. |
81 fCachedImage->unref(); | 79 fCachedImage->unref(); |
82 fCachedImage = NULL; | 80 fCachedImage = NULL; |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
86 uint32_t SkSurface_Base::newGenerationID() { | 84 uint32_t SkSurface_Base::newGenerationID() { |
(...skipping 15 matching lines...) Expand all Loading... | |
102 fGenerationID = 0; | 100 fGenerationID = 0; |
103 } | 101 } |
104 | 102 |
105 uint32_t SkSurface::generationID() { | 103 uint32_t SkSurface::generationID() { |
106 if (0 == fGenerationID) { | 104 if (0 == fGenerationID) { |
107 fGenerationID = asSB(this)->newGenerationID(); | 105 fGenerationID = asSB(this)->newGenerationID(); |
108 } | 106 } |
109 return fGenerationID; | 107 return fGenerationID; |
110 } | 108 } |
111 | 109 |
112 void SkSurface::notifyContentChanged() { | 110 void SkSurface::notifyContentChanged(bool canDiscardContents) { |
113 asSB(this)->aboutToDraw(NULL); | 111 asSB(this)->aboutToDraw(this->getCanvas(), canDiscardContents); |
114 } | 112 } |
115 | 113 |
116 SkCanvas* SkSurface::getCanvas() { | 114 SkCanvas* SkSurface::getCanvas() { |
117 return asSB(this)->getCachedCanvas(); | 115 return asSB(this)->getCachedCanvas(); |
118 } | 116 } |
119 | 117 |
120 SkImage* SkSurface::newImageShapshot() { | 118 SkImage* SkSurface::newImageShapshot() { |
121 SkImage* image = asSB(this)->getCachedImage(); | 119 SkImage* image = asSB(this)->getCachedImage(); |
122 SkSafeRef(image); // the caller will call unref() to balance this | 120 SkSafeRef(image); // the caller will call unref() to balance this |
123 return image; | 121 return image; |
124 } | 122 } |
125 | 123 |
126 SkSurface* SkSurface::newSurface(const SkImage::Info& info) { | 124 SkSurface* SkSurface::newSurface(const SkImage::Info& info) { |
127 return asSB(this)->onNewSurface(info); | 125 return asSB(this)->onNewSurface(info); |
128 } | 126 } |
129 | 127 |
130 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, | 128 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, |
131 const SkPaint* paint) { | 129 const SkPaint* paint) { |
132 return asSB(this)->onDraw(canvas, x, y, paint); | 130 return asSB(this)->onDraw(canvas, x, y, paint); |
133 } | 131 } |
OLD | NEW |