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

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

Issue 1372153006: SkImage doesn't use props, so don't need to store it (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | src/image/SkSurface_Gpu.cpp » ('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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (0 == size) { 56 if (0 == size) {
57 return false; 57 return false;
58 } 58 }
59 59
60 if (minSize) { 60 if (minSize) {
61 *minSize = size; 61 *minSize = size;
62 } 62 }
63 return true; 63 return true;
64 } 64 }
65 65
66 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const SkSurfaceProps*); 66 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*);
67 virtual ~SkImage_Raster(); 67 virtual ~SkImage_Raster();
68 68
69 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st override; 69 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st override;
70 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; 70 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
71 SkData* onRefEncoded() const override; 71 SkData* onRefEncoded() const override;
72 bool getROPixels(SkBitmap*) const override; 72 bool getROPixels(SkBitmap*) const override;
73 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; 73 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override;
74 SkImage* onNewSubset(const SkIRect&) const override; 74 SkImage* onNewSubset(const SkIRect&) const override;
75 75
76 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 76 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
77 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes, 77 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size _t rowBytes);
78 const SkSurfaceProps*);
79 78
80 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 79 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
81 80
82 bool isOpaque() const override; 81 bool isOpaque() const override;
83 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; 82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
84 83
85 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) 84 SkImage_Raster(const SkBitmap& bm)
86 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) 85 : INHERITED(bm.width(), bm.height(), bm.getGenerationID())
87 , fBitmap(bm) 86 , fBitmap(bm)
88 { 87 {
89 if (bm.pixelRef()->isPreLocked()) { 88 if (bm.pixelRef()->isPreLocked()) {
90 // we only preemptively lock if there is no chance of triggering som ething expensive 89 // we only preemptively lock if there is no chance of triggering som ething expensive
91 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already. 90 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already.
92 fBitmap.lockPixels(); 91 fBitmap.lockPixels();
93 } 92 }
94 SkASSERT(fBitmap.isImmutable()); 93 SkASSERT(fBitmap.isImmutable());
95 } 94 }
96 95
97 bool onIsLazyGenerated() const override { 96 bool onIsLazyGenerated() const override {
98 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated(); 97 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
99 } 98 }
100 99
101 private: 100 private:
102 SkImage_Raster() : INHERITED(0, 0, kNeedNewImageUniqueID, nullptr) { 101 SkBitmap fBitmap;
103 fBitmap.setImmutable();
104 }
105
106 SkBitmap fBitmap;
107 102
108 typedef SkImage_Base INHERITED; 103 typedef SkImage_Base INHERITED;
109 }; 104 };
110 105
111 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
112 107
113 static void release_data(void* addr, void* context) { 108 static void release_data(void* addr, void* context) {
114 SkData* data = static_cast<SkData*>(context); 109 SkData* data = static_cast<SkData*>(context);
115 data->unref(); 110 data->unref();
116 } 111 }
117 112
118 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes, 113 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
119 SkColorTable* ctable, const SkSurfaceProps* props ) 114 SkColorTable* ctable)
120 : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID, props) 115 : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID)
121 { 116 {
122 data->ref(); 117 data->ref();
123 void* addr = const_cast<void*>(data->data()); 118 void* addr = const_cast<void*>(data->data());
124 119
125 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data); 120 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data);
126 fBitmap.setImmutable(); 121 fBitmap.setImmutable();
127 fBitmap.lockPixels(); 122 fBitmap.lockPixels();
128 } 123 }
129 124
130 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin, 125 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin,
131 size_t rowBytes, const SkSurfaceProps* props) 126 size_t rowBytes)
132 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) 127 : INHERITED(info.width(), info.height(), pr->getGenerationID())
133 { 128 {
134 fBitmap.setInfo(info, rowBytes); 129 fBitmap.setInfo(info, rowBytes);
135 fBitmap.setPixelRef(pr, pixelRefOrigin); 130 fBitmap.setPixelRef(pr, pixelRefOrigin);
136 fBitmap.lockPixels(); 131 fBitmap.lockPixels();
137 SkASSERT(fBitmap.isImmutable()); 132 SkASSERT(fBitmap.isImmutable());
138 } 133 }
139 134
140 SkImage_Raster::~SkImage_Raster() {} 135 SkImage_Raster::~SkImage_Raster() {}
141 136
142 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes, 137 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 211
217 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes, 212 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes,
218 SkColorTable* ctable) { 213 SkColorTable* ctable) {
219 size_t size; 214 size_t size;
220 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable != nullptr, &size) || !pixels) { 215 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable != nullptr, &size) || !pixels) {
221 return nullptr; 216 return nullptr;
222 } 217 }
223 218
224 // Here we actually make a copy of the caller's pixel data 219 // Here we actually make a copy of the caller's pixel data
225 SkAutoDataUnref data(SkData::NewWithCopy(pixels, size)); 220 SkAutoDataUnref data(SkData::NewWithCopy(pixels, size));
226 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); 221 return new SkImage_Raster(info, data, rowBytes, ctable);
227 } 222 }
228 223
229 224
230 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) { 225 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) {
231 size_t size; 226 size_t size;
232 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) { 227 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) {
233 return nullptr; 228 return nullptr;
234 } 229 }
235 230
236 // did they give us enough data? 231 // did they give us enough data?
237 if (data->size() < size) { 232 if (data->size() < size) {
238 return nullptr; 233 return nullptr;
239 } 234 }
240 235
241 SkColorTable* ctable = nullptr; 236 SkColorTable* ctable = nullptr;
242 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); 237 return new SkImage_Raster(info, data, rowBytes, ctable);
243 } 238 }
244 239
245 SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz e_t rowBytes, 240 SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz e_t rowBytes,
246 RasterReleaseProc proc, ReleaseContext ctx) { 241 RasterReleaseProc proc, ReleaseContext ctx) {
247 size_t size; 242 size_t size;
248 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !pixels) { 243 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !pixels) {
249 return nullptr; 244 return nullptr;
250 } 245 }
251 246
252 SkColorTable* ctable = nullptr; 247 SkColorTable* ctable = nullptr;
253 SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx)); 248 SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx));
254 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); 249 return new SkImage_Raster(info, data, rowBytes, ctable);
255 } 250 }
256 251
257 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 252 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
258 const SkIPoint& pixelRefOrigin, size_t rowBytes, 253 const SkIPoint& pixelRefOrigin, size_t rowBytes) {
259 const SkSurfaceProps* props) {
260 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) { 254 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) {
261 return nullptr; 255 return nullptr;
262 } 256 }
263 return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes, props); 257 return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes);
264 } 258 }
265 259
266 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr ops, 260 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
267 ForceCopyMode forceCopy) {
268 SkASSERT(nullptr == bm.getTexture()); 261 SkASSERT(nullptr == bm.getTexture());
269 262
270 bool hasColorTable = false; 263 bool hasColorTable = false;
271 if (kIndex_8_SkColorType == bm.colorType()) { 264 if (kIndex_8_SkColorType == bm.colorType()) {
272 SkAutoLockPixels autoLockPixels(bm); 265 SkAutoLockPixels autoLockPixels(bm);
273 hasColorTable = bm.getColorTable() != nullptr; 266 hasColorTable = bm.getColorTable() != nullptr;
274 } 267 }
275 268
276 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), hasColorTable, null ptr)) { 269 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), hasColorTable, null ptr)) {
277 return nullptr; 270 return nullptr;
278 } 271 }
279 272
280 SkImage* image = nullptr; 273 SkImage* image = nullptr;
281 if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) { 274 if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
282 SkBitmap tmp(bm); 275 SkBitmap tmp(bm);
283 tmp.lockPixels(); 276 tmp.lockPixels();
284 if (tmp.getPixels()) { 277 if (tmp.getPixels()) {
285 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(), 278 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(),
286 tmp.getColorTable()); 279 tmp.getColorTable());
287 } 280 }
288
289 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here
290 if (image && props) {
291 as_IB(image)->initWithProps(*props);
292 }
293 } else { 281 } else {
294 image = new SkImage_Raster(bm, props); 282 image = new SkImage_Raster(bm);
295 } 283 }
296 return image; 284 return image;
297 } 285 }
298 286
299 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { 287 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
300 return ((const SkImage_Raster*)image)->getPixelRef(); 288 return ((const SkImage_Raster*)image)->getPixelRef();
301 } 289 }
302 290
303 bool SkImage_Raster::isOpaque() const { 291 bool SkImage_Raster::isOpaque() const {
304 return fBitmap.isOpaque(); 292 return fBitmap.isOpaque();
305 } 293 }
306 294
307 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c onst { 295 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c onst {
308 if (kRO_LegacyBitmapMode == mode) { 296 if (kRO_LegacyBitmapMode == mode) {
309 // When we're a snapshot from a surface, our bitmap may not be marked im mutable 297 // When we're a snapshot from a surface, our bitmap may not be marked im mutable
310 // even though logically always we are, but in that case we can't physic ally share our 298 // even though logically always we are, but in that case we can't physic ally share our
311 // pixelref since the caller might call setImmutable() themselves 299 // pixelref since the caller might call setImmutable() themselves
312 // (thus changing our state). 300 // (thus changing our state).
313 if (fBitmap.isImmutable()) { 301 if (fBitmap.isImmutable()) {
314 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 302 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
315 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 303 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
316 return true; 304 return true;
317 } 305 }
318 } 306 }
319 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 307 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
320 } 308 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698