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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
12 #include "SkData.h" | 12 #include "SkData.h" |
13 #include "SkImageGeneratorPriv.h" | |
14 #include "SkImagePriv.h" | 13 #include "SkImagePriv.h" |
15 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
16 #include "SkSurface.h" | 15 #include "SkSurface.h" |
17 | 16 |
| 17 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" |
| 19 #include "SkGr.h" |
| 20 #include "SkGrPriv.h" |
| 21 #endif |
| 22 |
18 class SkImage_Raster : public SkImage_Base { | 23 class SkImage_Raster : public SkImage_Base { |
19 public: | 24 public: |
20 static bool ValidArgs(const Info& info, size_t rowBytes, SkColorTable* ctabl
e, | 25 static bool ValidArgs(const Info& info, size_t rowBytes, SkColorTable* ctabl
e, |
21 size_t* minSize) { | 26 size_t* minSize) { |
22 const int maxDimension = SK_MaxS32 >> 2; | 27 const int maxDimension = SK_MaxS32 >> 2; |
23 | 28 |
24 if (info.width() <= 0 || info.height() <= 0) { | 29 if (info.width() <= 0 || info.height() <= 0) { |
25 return false; | 30 return false; |
26 } | 31 } |
27 if (info.width() > maxDimension || info.height() > maxDimension) { | 32 if (info.width() > maxDimension || info.height() > maxDimension) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 65 } |
61 | 66 |
62 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const
SkSurfaceProps*); | 67 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const
SkSurfaceProps*); |
63 virtual ~SkImage_Raster(); | 68 virtual ~SkImage_Raster(); |
64 | 69 |
65 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove
rride; | 70 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove
rride; |
66 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st override; | 71 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st override; |
67 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; | 72 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; |
68 SkData* onRefEncoded() const override; | 73 SkData* onRefEncoded() const override; |
69 bool getROPixels(SkBitmap*) const override; | 74 bool getROPixels(SkBitmap*) const override; |
| 75 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; |
70 | 76 |
71 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 77 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
72 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, | 78 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, |
73 const SkSurfaceProps*); | 79 const SkSurfaceProps*); |
74 | 80 |
75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 81 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
76 | 82 |
77 SkShader* onNewShader(SkShader::TileMode, | 83 SkShader* onNewShader(SkShader::TileMode, |
78 SkShader::TileMode, | 84 SkShader::TileMode, |
79 const SkMatrix* localMatrix) const override; | 85 const SkMatrix* localMatrix) const override; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return pr->refEncodedData(); | 179 return pr->refEncodedData(); |
174 } | 180 } |
175 return nullptr; | 181 return nullptr; |
176 } | 182 } |
177 | 183 |
178 bool SkImage_Raster::getROPixels(SkBitmap* dst) const { | 184 bool SkImage_Raster::getROPixels(SkBitmap* dst) const { |
179 *dst = fBitmap; | 185 *dst = fBitmap; |
180 return true; | 186 return true; |
181 } | 187 } |
182 | 188 |
| 189 GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, SkImageUsageType usage)
const { |
| 190 #if SK_SUPPORT_GPU |
| 191 if (!ctx) { |
| 192 return nullptr; |
| 193 } |
| 194 |
| 195 // textures (at least the texture-key) only support 16bit dimensions, so abo
rt early |
| 196 // if we're too big. |
| 197 if (fBitmap.width() > 0xFFFF || fBitmap.height() > 0xFFFF) { |
| 198 return nullptr; |
| 199 } |
| 200 |
| 201 GrUniqueKey key; |
| 202 GrMakeKeyFromImageID(&key, fBitmap.getGenerationID(), |
| 203 SkIRect::MakeWH(fBitmap.width(), fBitmap.height()), |
| 204 *ctx->caps(), usage); |
| 205 |
| 206 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(ke
y)) { |
| 207 return tex; |
| 208 } |
| 209 return GrRefCachedBitmapTexture(ctx, fBitmap, usage); |
| 210 #endif |
| 211 |
| 212 return nullptr; |
| 213 } |
| 214 |
183 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
184 | 216 |
185 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, | 217 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, |
186 SkColorTable* ctable) { | 218 SkColorTable* ctable) { |
187 size_t size; | 219 size_t size; |
188 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable, &size) || !pixels) { | 220 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable, &size) || !pixels) { |
189 return nullptr; | 221 return nullptr; |
190 } | 222 } |
191 | 223 |
192 // Here we actually make a copy of the caller's pixel data | 224 // Here we actually make a copy of the caller's pixel data |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // pixelref since the caller might call setImmutable() themselves | 305 // pixelref since the caller might call setImmutable() themselves |
274 // (thus changing our state). | 306 // (thus changing our state). |
275 if (fBitmap.isImmutable()) { | 307 if (fBitmap.isImmutable()) { |
276 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 308 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
277 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 309 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
278 return true; | 310 return true; |
279 } | 311 } |
280 } | 312 } |
281 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 313 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
282 } | 314 } |
OLD | NEW |