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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 int64_t size = (int64_t)info.height() * rowBytes; | 46 int64_t size = (int64_t)info.height() * rowBytes; |
47 if (size > (int64_t)kMaxPixelByteSize) { | 47 if (size > (int64_t)kMaxPixelByteSize) { |
48 return false; | 48 return false; |
49 } | 49 } |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, const SkSurfaceProps*
); | 53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, const SkSurfaceProps*
); |
54 virtual ~SkImage_Raster(); | 54 virtual ~SkImage_Raster(); |
55 | 55 |
56 void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const override; | |
57 void onDrawRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) con
st override; | |
58 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove
rride; | 56 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove
rride; |
59 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st override; | 57 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st override; |
60 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; | 58 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; |
61 bool getROPixels(SkBitmap*) const override; | 59 bool getROPixels(SkBitmap*) const override; |
62 | 60 |
63 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 61 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
64 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, | 62 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, |
65 const SkSurfaceProps*); | 63 const SkSurfaceProps*); |
66 | 64 |
67 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 65 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 fBitmap.lockPixels(); | 111 fBitmap.lockPixels(); |
114 } | 112 } |
115 | 113 |
116 SkImage_Raster::~SkImage_Raster() {} | 114 SkImage_Raster::~SkImage_Raster() {} |
117 | 115 |
118 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, | 116 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, |
119 const SkMatrix* localMatrix) const { | 117 const SkMatrix* localMatrix) const { |
120 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 118 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
121 } | 119 } |
122 | 120 |
123 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) const { | |
124 SkBitmap shallowCopy(fBitmap); | |
125 canvas->drawBitmap(shallowCopy, x, y, paint); | |
126 } | |
127 | |
128 void SkImage_Raster::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRec
t& dst, | |
129 const SkPaint* paint) const { | |
130 SkBitmap shallowCopy(fBitmap); | |
131 canvas->drawBitmapRectToRect(shallowCopy, src, dst, paint); | |
132 } | |
133 | |
134 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface
Props& props) const { | 121 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface
Props& props) const { |
135 return SkSurface::NewRaster(info, &props); | 122 return SkSurface::NewRaster(info, &props); |
136 } | 123 } |
137 | 124 |
138 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, | 125 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, |
139 int srcX, int srcY) const { | 126 int srcX, int srcY) const { |
140 SkBitmap shallowCopy(fBitmap); | 127 SkBitmap shallowCopy(fBitmap); |
141 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); | 128 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); |
142 } | 129 } |
143 | 130 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 216 } |
230 | 217 |
231 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { | 218 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { |
232 return ((const SkImage_Raster*)image)->getPixelRef(); | 219 return ((const SkImage_Raster*)image)->getPixelRef(); |
233 } | 220 } |
234 | 221 |
235 bool SkImage_Raster::isOpaque() const { | 222 bool SkImage_Raster::isOpaque() const { |
236 return fBitmap.isOpaque(); | 223 return fBitmap.isOpaque(); |
237 } | 224 } |
238 | 225 |
OLD | NEW |