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

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

Issue 536003002: Hide fields in SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix qt Created 6 years, 3 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.cpp ('k') | src/image/SkSurface.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 "SkDecodingImageGenerator.h"
14 #include "SkMallocPixelRef.h" 14 #include "SkMallocPixelRef.h"
15 15
16 class SkImage_Raster : public SkImage_Base { 16 class SkImage_Raster : public SkImage_Base {
17 public: 17 public:
18 static bool ValidArgs(const Info& info, size_t rowBytes) { 18 static bool ValidArgs(const Info& info, size_t rowBytes) {
19 const int maxDimension = SK_MaxS32 >> 2; 19 const int maxDimension = SK_MaxS32 >> 2;
20 const size_t kMaxPixelByteSize = SK_MaxS32; 20 const size_t kMaxPixelByteSize = SK_MaxS32;
21 21
22 if (info.fWidth < 0 || info.fHeight < 0) { 22 if (info.width() < 0 || info.height() < 0) {
23 return false; 23 return false;
24 } 24 }
25 if (info.fWidth > maxDimension || info.fHeight > maxDimension) { 25 if (info.width() > maxDimension || info.height() > maxDimension) {
26 return false; 26 return false;
27 } 27 }
28 if ((unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType) { 28 if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) {
29 return false; 29 return false;
30 } 30 }
31 if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) { 31 if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) {
32 return false; 32 return false;
33 } 33 }
34 34
35 if (kUnknown_SkColorType == info.colorType()) { 35 if (kUnknown_SkColorType == info.colorType()) {
36 return false; 36 return false;
37 } 37 }
38 38
39 // TODO: check colorspace 39 // TODO: check colorspace
40 40
41 if (rowBytes < SkImageMinRowBytes(info)) { 41 if (rowBytes < SkImageMinRowBytes(info)) {
42 return false; 42 return false;
43 } 43 }
44 44
45 int64_t size = (int64_t)info.fHeight * rowBytes; 45 int64_t size = (int64_t)info.height() * rowBytes;
46 if (size > (int64_t)kMaxPixelByteSize) { 46 if (size > (int64_t)kMaxPixelByteSize) {
47 return false; 47 return false;
48 } 48 }
49 return true; 49 return true;
50 } 50 }
51 51
52 static SkImage* NewEmpty(); 52 static SkImage* NewEmpty();
53 53
54 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); 54 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb);
55 virtual ~SkImage_Raster(); 55 virtual ~SkImage_Raster();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 gEmpty->ref(); 95 gEmpty->ref();
96 return gEmpty; 96 return gEmpty;
97 } 97 }
98 98
99 static void release_data(void* addr, void* context) { 99 static void release_data(void* addr, void* context) {
100 SkData* data = static_cast<SkData*>(context); 100 SkData* data = static_cast<SkData*>(context);
101 data->unref(); 101 data->unref();
102 } 102 }
103 103
104 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) 104 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
105 : INHERITED(info.fWidth, info.fHeight) 105 : INHERITED(info.width(), info.height())
106 { 106 {
107 data->ref(); 107 data->ref();
108 void* addr = const_cast<void*>(data->data()); 108 void* addr = const_cast<void*>(data->data());
109 SkColorTable* ctable = NULL; 109 SkColorTable* ctable = NULL;
110 110
111 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data); 111 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data);
112 fBitmap.setImmutable(); 112 fBitmap.setImmutable();
113 fBitmap.lockPixels(); 113 fBitmap.lockPixels();
114 } 114 }
115 115
116 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes ) 116 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes )
117 : INHERITED(info.fWidth, info.fHeight) 117 : INHERITED(info.width(), info.height())
118 { 118 {
119 fBitmap.setInfo(info, rowBytes); 119 fBitmap.setInfo(info, rowBytes);
120 fBitmap.setPixelRef(pr); 120 fBitmap.setPixelRef(pr);
121 fBitmap.lockPixels(); 121 fBitmap.lockPixels();
122 } 122 }
123 123
124 SkImage_Raster::~SkImage_Raster() {} 124 SkImage_Raster::~SkImage_Raster() {}
125 125
126 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY, 126 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY,
127 const SkMatrix* localMatrix) const { 127 const SkMatrix* localMatrix) const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 *dst = fBitmap; 163 *dst = fBitmap;
164 return true; 164 return true;
165 } 165 }
166 166
167 /////////////////////////////////////////////////////////////////////////////// 167 ///////////////////////////////////////////////////////////////////////////////
168 168
169 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes) { 169 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes) {
170 if (!SkImage_Raster::ValidArgs(info, rowBytes)) { 170 if (!SkImage_Raster::ValidArgs(info, rowBytes)) {
171 return NULL; 171 return NULL;
172 } 172 }
173 if (0 == info.fWidth && 0 == info.fHeight) { 173 if (0 == info.width() && 0 == info.height()) {
174 return SkImage_Raster::NewEmpty(); 174 return SkImage_Raster::NewEmpty();
175 } 175 }
176 // check this after empty-check 176 // check this after empty-check
177 if (NULL == pixels) { 177 if (NULL == pixels) {
178 return NULL; 178 return NULL;
179 } 179 }
180 180
181 // Here we actually make a copy of the caller's pixel data 181 // Here we actually make a copy of the caller's pixel data
182 SkAutoDataUnref data(SkData::NewWithCopy(pixels, info.fHeight * rowBytes)); 182 SkAutoDataUnref data(SkData::NewWithCopy(pixels, info.height() * rowBytes));
183 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); 183 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes));
184 } 184 }
185 185
186 186
187 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) { 187 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) {
188 if (!SkImage_Raster::ValidArgs(info, rowBytes)) { 188 if (!SkImage_Raster::ValidArgs(info, rowBytes)) {
189 return NULL; 189 return NULL;
190 } 190 }
191 if (0 == info.fWidth && 0 == info.fHeight) { 191 if (0 == info.width() && 0 == info.height()) {
192 return SkImage_Raster::NewEmpty(); 192 return SkImage_Raster::NewEmpty();
193 } 193 }
194 // check this after empty-check 194 // check this after empty-check
195 if (NULL == data) { 195 if (NULL == data) {
196 return NULL; 196 return NULL;
197 } 197 }
198 198
199 // did they give us enough data? 199 // did they give us enough data?
200 size_t size = info.fHeight * rowBytes; 200 size_t size = info.height() * rowBytes;
201 if (data->size() < size) { 201 if (data->size() < size) {
202 return NULL; 202 return NULL;
203 } 203 }
204 204
205 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); 205 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes));
206 } 206 }
207 207
208 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator) { 208 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator) {
209 SkBitmap bitmap; 209 SkBitmap bitmap;
210 if (!SkInstallDiscardablePixelRef(generator, &bitmap)) { 210 if (!SkInstallDiscardablePixelRef(generator, &bitmap)) {
211 return NULL; 211 return NULL;
212 } 212 }
213 return SkNEW_ARGS(SkImage_Raster, (bitmap)); 213 return SkNEW_ARGS(SkImage_Raster, (bitmap));
214 } 214 }
215 215
216 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 216 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
217 size_t rowBytes) { 217 size_t rowBytes) {
218 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); 218 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
219 } 219 }
220 220
221 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 221 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
222 return ((SkImage_Raster*)image)->getPixelRef(); 222 return ((SkImage_Raster*)image)->getPixelRef();
223 } 223 }
224 224
225 bool SkImage_Raster::isOpaque() const { 225 bool SkImage_Raster::isOpaque() const {
226 return fBitmap.isOpaque(); 226 return fBitmap.isOpaque();
227 } 227 }
OLDNEW
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698