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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const SkPaint* paint) { | 111 const SkPaint* paint) { |
112 canvas->drawBitmap(fBitmap, x, y, paint); | 112 canvas->drawBitmap(fBitmap, x, y, paint); |
113 } | 113 } |
114 | 114 |
115 SkImage* SkSurface_Raster::onNewImageSnapshot() { | 115 SkImage* SkSurface_Raster::onNewImageSnapshot() { |
116 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); | 116 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); |
117 } | 117 } |
118 | 118 |
119 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { | 119 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
120 // are we sharing pixelrefs with the image? | 120 // are we sharing pixelrefs with the image? |
121 SkASSERT(NULL != this->getCachedImage()); | 121 SkASSERT(this->getCachedImage()); |
122 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ | 122 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ |
123 SkASSERT(fWeOwnThePixels); | 123 SkASSERT(fWeOwnThePixels); |
124 if (kDiscard_ContentChangeMode == mode) { | 124 if (kDiscard_ContentChangeMode == mode) { |
125 fBitmap.setPixelRef(NULL); | 125 fBitmap.setPixelRef(NULL); |
126 fBitmap.allocPixels(); | 126 fBitmap.allocPixels(); |
127 } else { | 127 } else { |
128 SkBitmap prev(fBitmap); | 128 SkBitmap prev(fBitmap); |
129 prev.deepCopyTo(&fBitmap); | 129 prev.deepCopyTo(&fBitmap); |
130 } | 130 } |
131 // Now fBitmap is a deep copy of itself (and therefore different from | 131 // Now fBitmap is a deep copy of itself (and therefore different from |
132 // what is being used by the image. Next we update the canvas to use | 132 // what is being used by the image. Next we update the canvas to use |
133 // this as its backend, so we can't modify the image's pixels anymore. | 133 // this as its backend, so we can't modify the image's pixels anymore. |
134 SkASSERT(NULL != this->getCachedCanvas()); | 134 SkASSERT(this->getCachedCanvas()); |
135 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); | 135 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 /////////////////////////////////////////////////////////////////////////////// | 139 /////////////////////////////////////////////////////////////////////////////// |
140 | 140 |
141 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void*
pixels, size_t rb, | 141 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void*
pixels, size_t rb, |
142 void (*releaseProc)(void* pixel
s, void* context), | 142 void (*releaseProc)(void* pixel
s, void* context), |
143 void* context) { | 143 void* context) { |
144 if (NULL == releaseProc) { | 144 if (NULL == releaseProc) { |
(...skipping 17 matching lines...) Expand all Loading... |
162 if (!SkSurface_Raster::Valid(info)) { | 162 if (!SkSurface_Raster::Valid(info)) { |
163 return NULL; | 163 return NULL; |
164 } | 164 } |
165 | 165 |
166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
167 if (NULL == pr.get()) { | 167 if (NULL == pr.get()) { |
168 return NULL; | 168 return NULL; |
169 } | 169 } |
170 return SkNEW_ARGS(SkSurface_Raster, (pr)); | 170 return SkNEW_ARGS(SkSurface_Raster, (pr)); |
171 } | 171 } |
OLD | NEW |