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" | 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 "SkSurface.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.width() < 0 || info.height() < 0) { | 22 if (info.width() < 0 || info.height() < 0) { |
22 return false; | 23 return false; |
23 } | 24 } |
(...skipping 22 matching lines...) Expand all Loading... |
46 return false; | 47 return false; |
47 } | 48 } |
48 return true; | 49 return true; |
49 } | 50 } |
50 | 51 |
51 static SkImage* NewEmpty(); | 52 static SkImage* NewEmpty(); |
52 | 53 |
53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); | 54 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); |
54 virtual ~SkImage_Raster(); | 55 virtual ~SkImage_Raster(); |
55 | 56 |
56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_
OVERRIDE; | 57 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_OVERRIDE
; |
57 virtual void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, | 58 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con
st SK_OVERRIDE; |
58 const SkPaint*) const SK_OVERRIDE; | 59 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_
OVERRIDE; |
59 virtual bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; | 60 bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; |
60 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const S
K_OVERRIDE; | 61 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRI
DE; |
61 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 62 bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 130 |
130 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) const { | 131 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) const { |
131 canvas->drawBitmap(fBitmap, x, y, paint); | 132 canvas->drawBitmap(fBitmap, x, y, paint); |
132 } | 133 } |
133 | 134 |
134 void SkImage_Raster::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRec
t& dst, | 135 void SkImage_Raster::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRec
t& dst, |
135 const SkPaint* paint) const { | 136 const SkPaint* paint) const { |
136 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | 137 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
137 } | 138 } |
138 | 139 |
| 140 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface
Props& props) const { |
| 141 return SkSurface::NewRaster(info, &props); |
| 142 } |
| 143 |
139 bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { | 144 bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { |
140 if (dst->pixelRef()) { | 145 if (dst->pixelRef()) { |
141 return this->INHERITED::onReadPixels(dst, subset); | 146 return this->INHERITED::onReadPixels(dst, subset); |
142 } else { | 147 } else { |
143 SkBitmap src; | 148 SkBitmap src; |
144 if (!fBitmap.extractSubset(&src, subset)) { | 149 if (!fBitmap.extractSubset(&src, subset)) { |
145 return false; | 150 return false; |
146 } | 151 } |
147 return src.copyTo(dst, src.colorType()); | 152 return src.copyTo(dst, src.colorType()); |
148 } | 153 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); | 222 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); |
218 } | 223 } |
219 | 224 |
220 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { | 225 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { |
221 return ((const SkImage_Raster*)image)->getPixelRef(); | 226 return ((const SkImage_Raster*)image)->getPixelRef(); |
222 } | 227 } |
223 | 228 |
224 bool SkImage_Raster::isOpaque() const { | 229 bool SkImage_Raster::isOpaque() const { |
225 return fBitmap.isOpaque(); | 230 return fBitmap.isOpaque(); |
226 } | 231 } |
OLD | NEW |