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 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { | 111 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { |
112 return SkSurface::NewRaster(info, &this->props()); | 112 return SkSurface::NewRaster(info, &this->props()); |
113 } | 113 } |
114 | 114 |
115 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 115 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
116 const SkPaint* paint) { | 116 const SkPaint* paint) { |
117 canvas->drawBitmap(fBitmap, x, y, paint); | 117 canvas->drawBitmap(fBitmap, x, y, paint); |
118 } | 118 } |
119 | 119 |
120 SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { | 120 SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { |
121 return SkNewImageFromRasterBitmap(fBitmap, fWeOwnThePixels, &this->props()); | 121 // Our pixels are in memory, so read access on the snapshot SkImage could be
cheap. |
| 122 // Lock the shared pixel ref to ensure peekPixels() is usable. |
| 123 return SkNewImageFromRasterBitmap(fBitmap, fWeOwnThePixels, &this->props(), |
| 124 kLocked_SharedPixelRefMode); |
122 } | 125 } |
123 | 126 |
124 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { | 127 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
125 // are we sharing pixelrefs with the image? | 128 // are we sharing pixelrefs with the image? |
126 SkASSERT(this->getCachedImage(kNo_Budgeted)); | 129 SkASSERT(this->getCachedImage(kNo_Budgeted)); |
127 if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.
pixelRef()) { | 130 if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.
pixelRef()) { |
128 SkASSERT(fWeOwnThePixels); | 131 SkASSERT(fWeOwnThePixels); |
129 if (kDiscard_ContentChangeMode == mode) { | 132 if (kDiscard_ContentChangeMode == mode) { |
130 fBitmap.setPixelRef(NULL); | 133 fBitmap.setPixelRef(NULL); |
131 fBitmap.allocPixels(); | 134 fBitmap.allocPixels(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (!SkSurface_Raster::Valid(info)) { | 171 if (!SkSurface_Raster::Valid(info)) { |
169 return NULL; | 172 return NULL; |
170 } | 173 } |
171 | 174 |
172 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 175 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
173 if (NULL == pr.get()) { | 176 if (NULL == pr.get()) { |
174 return NULL; | 177 return NULL; |
175 } | 178 } |
176 return SkNEW_ARGS(SkSurface_Raster, (pr, props)); | 179 return SkNEW_ARGS(SkSurface_Raster, (pr, props)); |
177 } | 180 } |
OLD | NEW |