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

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

Issue 465823003: SkImage::NewFromGenerator(SkImageGenerator*), and a unit test. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix ARGB/AGBR byte order bug (edit) Created 6 years, 4 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 | « include/core/SkImage.h ('k') | tests/CachedDecodingPixelRefTest.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 "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkDecodingImageGenerator.h"
13 #include "SkMallocPixelRef.h" 14 #include "SkMallocPixelRef.h"
14 15
15 class SkImage_Raster : public SkImage_Base { 16 class SkImage_Raster : public SkImage_Base {
16 public: 17 public:
17 static bool ValidArgs(const Info& info, size_t rowBytes) { 18 static bool ValidArgs(const Info& info, size_t rowBytes) {
18 const int maxDimension = SK_MaxS32 >> 2; 19 const int maxDimension = SK_MaxS32 >> 2;
19 const size_t kMaxPixelByteSize = SK_MaxS32; 20 const size_t kMaxPixelByteSize = SK_MaxS32;
20 21
21 if (info.fWidth < 0 || info.fHeight < 0) { 22 if (info.fWidth < 0 || info.fHeight < 0) {
22 return false; 23 return false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 64 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
64 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes); 65 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes);
65 66
66 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 67 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
67 68
68 virtual SkShader* onNewShader(SkShader::TileMode, 69 virtual SkShader* onNewShader(SkShader::TileMode,
69 SkShader::TileMode, 70 SkShader::TileMode,
70 const SkMatrix* localMatrix) const SK_OVERRIDE ; 71 const SkMatrix* localMatrix) const SK_OVERRIDE ;
71 72
73 SkImage_Raster(const SkBitmap& bm)
74 : INHERITED(bm.width(), bm.height())
75 , fBitmap(bm) {}
76
72 private: 77 private:
73 SkImage_Raster() : INHERITED(0, 0) {} 78 SkImage_Raster() : INHERITED(0, 0) {}
74 79
75 SkBitmap fBitmap; 80 SkBitmap fBitmap;
76 81
77 typedef SkImage_Base INHERITED; 82 typedef SkImage_Base INHERITED;
78 }; 83 };
79 84
80 /////////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////////
81 86
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 196
192 // did they give us enough data? 197 // did they give us enough data?
193 size_t size = info.fHeight * rowBytes; 198 size_t size = info.fHeight * rowBytes;
194 if (data->size() < size) { 199 if (data->size() < size) {
195 return NULL; 200 return NULL;
196 } 201 }
197 202
198 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); 203 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes));
199 } 204 }
200 205
206 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator) {
207 SkBitmap bitmap;
208 if (!SkInstallDiscardablePixelRef(generator, &bitmap)) {
209 return NULL;
210 }
211 return SkNEW_ARGS(SkImage_Raster, (bitmap));
212 }
213
201 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 214 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
202 size_t rowBytes) { 215 size_t rowBytes) {
203 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); 216 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
204 } 217 }
205 218
206 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 219 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
207 return ((SkImage_Raster*)image)->getPixelRef(); 220 return ((SkImage_Raster*)image)->getPixelRef();
208 } 221 }
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698