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

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

Issue 793723002: add readPixels to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use better name on test Created 6 years 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_Base.h ('k') | src/image/SkReadPixelsRec.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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 static SkImage* NewEmpty(); 52 static SkImage* NewEmpty();
53 53
54 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, const SkSurfaceProps* ); 54 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, const SkSurfaceProps* );
55 virtual ~SkImage_Raster(); 55 virtual ~SkImage_Raster();
56 56
57 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE ; 57 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE ;
58 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con st SK_OVERRIDE; 58 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con st SK_OVERRIDE;
59 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_ OVERRIDE; 59 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_ OVERRIDE;
60 bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; 60 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st SK_OVERRIDE;
61 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRI DE; 61 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRI DE;
62 bool getROPixels(SkBitmap*) const SK_OVERRIDE; 62 bool getROPixels(SkBitmap*) const SK_OVERRIDE;
63 63
64 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 64 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
65 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes, const SkSur faceProps*); 65 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes, const SkSur faceProps*);
66 66
67 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 67 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
68 68
69 virtual SkShader* onNewShader(SkShader::TileMode, 69 virtual SkShader* onNewShader(SkShader::TileMode,
70 SkShader::TileMode, 70 SkShader::TileMode,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 void SkImage_Raster::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRec t& dst, 137 void SkImage_Raster::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRec t& dst,
138 const SkPaint* paint) const { 138 const SkPaint* paint) const {
139 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 139 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
140 } 140 }
141 141
142 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const { 142 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const {
143 return SkSurface::NewRaster(info, &props); 143 return SkSurface::NewRaster(info, &props);
144 } 144 }
145 145
146 bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { 146 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
147 if (dst->pixelRef()) { 147 int srcX, int srcY) const {
148 return this->INHERITED::onReadPixels(dst, subset); 148 return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
149 } else {
150 SkBitmap src;
151 if (!fBitmap.extractSubset(&src, subset)) {
152 return false;
153 }
154 return src.copyTo(dst, src.colorType());
155 }
156 } 149 }
157 150
158 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const { 151 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const {
159 const SkImageInfo info = fBitmap.info(); 152 const SkImageInfo info = fBitmap.info();
160 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { 153 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) {
161 return NULL; 154 return NULL;
162 } 155 }
163 *infoPtr = info; 156 *infoPtr = info;
164 *rowBytesPtr = fBitmap.rowBytes(); 157 *rowBytesPtr = fBitmap.rowBytes();
165 return fBitmap.getPixels(); 158 return fBitmap.getPixels();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes, props)); 217 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes, props));
225 } 218 }
226 219
227 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { 220 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
228 return ((const SkImage_Raster*)image)->getPixelRef(); 221 return ((const SkImage_Raster*)image)->getPixelRef();
229 } 222 }
230 223
231 bool SkImage_Raster::isOpaque() const { 224 bool SkImage_Raster::isOpaque() const {
232 return fBitmap.isOpaque(); 225 return fBitmap.isOpaque();
233 } 226 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkReadPixelsRec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698