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 "SkImagePriv.h" | |
10 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
11 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
12 #include "SkData.h" | 11 #include "SkData.h" |
13 #include "SkImageGenerator.h" | 12 #include "SkImageGenerator.h" |
| 13 #include "SkImagePriv.h" |
| 14 #include "SkPixelRef.h" |
14 #include "SkSurface.h" | 15 #include "SkSurface.h" |
15 | 16 |
16 class SkImage_Raster : public SkImage_Base { | 17 class SkImage_Raster : public SkImage_Base { |
17 public: | 18 public: |
18 static bool ValidArgs(const Info& info, size_t rowBytes) { | 19 static bool ValidArgs(const Info& info, size_t rowBytes) { |
19 const int maxDimension = SK_MaxS32 >> 2; | 20 const int maxDimension = SK_MaxS32 >> 2; |
20 const size_t kMaxPixelByteSize = SK_MaxS32; | 21 const size_t kMaxPixelByteSize = SK_MaxS32; |
21 | 22 |
22 if (info.width() <= 0 || info.height() <= 0) { | 23 if (info.width() <= 0 || info.height() <= 0) { |
23 return false; | 24 return false; |
(...skipping 29 matching lines...) Expand all Loading... |
53 virtual ~SkImage_Raster(); | 54 virtual ~SkImage_Raster(); |
54 | 55 |
55 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE
; | 56 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE
; |
56 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con
st SK_OVERRIDE; | 57 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con
st SK_OVERRIDE; |
57 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_
OVERRIDE; | 58 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_
OVERRIDE; |
58 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st SK_OVERRIDE; | 59 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st SK_OVERRIDE; |
59 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRI
DE; | 60 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRI
DE; |
60 bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 61 bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
61 | 62 |
62 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 63 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
63 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes, const SkSur
faceProps*); | 64 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, |
| 65 const SkSurfaceProps*); |
64 | 66 |
65 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 67 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
66 | 68 |
67 virtual SkShader* onNewShader(SkShader::TileMode, | 69 virtual SkShader* onNewShader(SkShader::TileMode, |
68 SkShader::TileMode, | 70 SkShader::TileMode, |
69 const SkMatrix* localMatrix) const SK_OVERRIDE
; | 71 const SkMatrix* localMatrix) const SK_OVERRIDE
; |
70 | 72 |
71 bool isOpaque() const SK_OVERRIDE; | 73 bool isOpaque() const SK_OVERRIDE; |
72 | 74 |
73 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) | 75 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) |
(...skipping 21 matching lines...) Expand all Loading... |
95 { | 97 { |
96 data->ref(); | 98 data->ref(); |
97 void* addr = const_cast<void*>(data->data()); | 99 void* addr = const_cast<void*>(data->data()); |
98 SkColorTable* ctable = NULL; | 100 SkColorTable* ctable = NULL; |
99 | 101 |
100 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data); | 102 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data); |
101 fBitmap.setImmutable(); | 103 fBitmap.setImmutable(); |
102 fBitmap.lockPixels(); | 104 fBitmap.lockPixels(); |
103 } | 105 } |
104 | 106 |
105 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
, | 107 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint&
pixelRefOrigin, |
106 const SkSurfaceProps* props) | 108 size_t rowBytes, const SkSurfaceProps* props) |
107 : INHERITED(info.width(), info.height(), props) | 109 : INHERITED(info.width(), info.height(), props) |
108 { | 110 { |
109 fBitmap.setInfo(info, rowBytes); | 111 fBitmap.setInfo(info, rowBytes); |
110 fBitmap.setPixelRef(pr); | 112 fBitmap.setPixelRef(pr, pixelRefOrigin); |
111 fBitmap.lockPixels(); | 113 fBitmap.lockPixels(); |
112 } | 114 } |
113 | 115 |
114 SkImage_Raster::~SkImage_Raster() {} | 116 SkImage_Raster::~SkImage_Raster() {} |
115 | 117 |
116 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, | 118 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, |
117 const SkMatrix* localMatrix) const { | 119 const SkMatrix* localMatrix) const { |
118 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 120 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
119 } | 121 } |
120 | 122 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (!SkInstallDiscardablePixelRef(generator, &bitmap)) { | 188 if (!SkInstallDiscardablePixelRef(generator, &bitmap)) { |
187 return NULL; | 189 return NULL; |
188 } | 190 } |
189 if (0 == bitmap.width() || 0 == bitmap.height()) { | 191 if (0 == bitmap.width() || 0 == bitmap.height()) { |
190 return NULL; | 192 return NULL; |
191 } | 193 } |
192 | 194 |
193 return SkNEW_ARGS(SkImage_Raster, (bitmap, NULL)); | 195 return SkNEW_ARGS(SkImage_Raster, (bitmap, NULL)); |
194 } | 196 } |
195 | 197 |
196 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, size_t
rowBytes, | 198 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, |
| 199 const SkIPoint& pixelRefOrigin, size_t rowBytes, |
197 const SkSurfaceProps* props) { | 200 const SkSurfaceProps* props) { |
198 if (!SkImage_Raster::ValidArgs(info, rowBytes)) { | 201 if (!SkImage_Raster::ValidArgs(info, rowBytes)) { |
199 return NULL; | 202 return NULL; |
200 } | 203 } |
201 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes, props)); | 204 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props
)); |
| 205 } |
| 206 |
| 207 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef, |
| 208 const SkSurfaceProps* props) { |
| 209 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes())) { |
| 210 return NULL; |
| 211 } |
| 212 |
| 213 SkImage* image = NULL; |
| 214 if (canSharePixelRef || bm.isImmutable()) { |
| 215 image = SkNEW_ARGS(SkImage_Raster, (bm, props)); |
| 216 } else { |
| 217 bm.lockPixels(); |
| 218 if (bm.getPixels()) { |
| 219 image = SkImage::NewRasterCopy(bm.info(), bm.getPixels(), bm.rowByte
s()); |
| 220 } |
| 221 bm.unlockPixels(); |
| 222 |
| 223 // we don't expose props to NewRasterCopy (need a private vers) so post-
init it here |
| 224 if (image && props) { |
| 225 as_IB(image)->initWithProps(*props); |
| 226 } |
| 227 } |
| 228 return image; |
202 } | 229 } |
203 | 230 |
204 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { | 231 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { |
205 return ((const SkImage_Raster*)image)->getPixelRef(); | 232 return ((const SkImage_Raster*)image)->getPixelRef(); |
206 } | 233 } |
207 | 234 |
208 bool SkImage_Raster::isOpaque() const { | 235 bool SkImage_Raster::isOpaque() const { |
209 return fBitmap.isOpaque(); | 236 return fBitmap.isOpaque(); |
210 } | 237 } |
211 | 238 |
OLD | NEW |