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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return false; | 46 return false; |
47 } | 47 } |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
51 static SkImage* NewEmpty(); | 51 static SkImage* NewEmpty(); |
52 | 52 |
53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); | 53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); |
54 virtual ~SkImage_Raster(); | 54 virtual ~SkImage_Raster(); |
55 | 55 |
56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRI
DE; | 56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) const SK_
OVERRIDE; |
57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const
SkPaint*) SK_OVERRIDE; | 57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, |
| 58 const SkPaint*) const SK_OVERRIDE; |
58 virtual bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; | 59 virtual bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; |
59 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const S
K_OVERRIDE; | 60 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const S
K_OVERRIDE; |
60 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 61 virtual 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); | 64 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes); |
64 | 65 |
65 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 66 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
66 | 67 |
67 virtual SkShader* onNewShader(SkShader::TileMode, | 68 virtual SkShader* onNewShader(SkShader::TileMode, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
) | 109 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
) |
109 : INHERITED(info.fWidth, info.fHeight) | 110 : INHERITED(info.fWidth, info.fHeight) |
110 { | 111 { |
111 fBitmap.setInfo(info, rowBytes); | 112 fBitmap.setInfo(info, rowBytes); |
112 fBitmap.setPixelRef(pr); | 113 fBitmap.setPixelRef(pr); |
113 fBitmap.lockPixels(); | 114 fBitmap.lockPixels(); |
114 } | 115 } |
115 | 116 |
116 SkImage_Raster::~SkImage_Raster() {} | 117 SkImage_Raster::~SkImage_Raster() {} |
117 | 118 |
118 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, | 119 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, |
119 SkShader::TileMode tileY, | 120 const SkMatrix* localMatrix) const { |
120 const SkMatrix* localMatrix) const | |
121 { | |
122 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 121 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
123 } | 122 } |
124 | 123 |
125 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) { | 124 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) const { |
126 canvas->drawBitmap(fBitmap, x, y, paint); | 125 canvas->drawBitmap(fBitmap, x, y, paint); |
127 } | 126 } |
128 | 127 |
129 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, | 128 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const
SkRect& dst, |
130 const SkRect& dst, const SkPaint* paint) { | 129 const SkPaint* paint) const { |
131 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | 130 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
132 } | 131 } |
133 | 132 |
134 bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { | 133 bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { |
135 if (dst->pixelRef()) { | 134 if (dst->pixelRef()) { |
136 return this->INHERITED::onReadPixels(dst, subset); | 135 return this->INHERITED::onReadPixels(dst, subset); |
137 } else { | 136 } else { |
138 SkBitmap src; | 137 SkBitmap src; |
139 if (!fBitmap.extractSubset(&src, subset)) { | 138 if (!fBitmap.extractSubset(&src, subset)) { |
140 return false; | 139 return false; |
141 } | 140 } |
142 return src.copyTo(dst, src.colorType()); | 141 return src.copyTo(dst, src.colorType()); |
143 } | 142 } |
144 } | 143 } |
145 | 144 |
146 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, | 145 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP
tr) const { |
147 size_t* rowBytesPtr) const { | |
148 const SkImageInfo info = fBitmap.info(); | 146 const SkImageInfo info = fBitmap.info(); |
149 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { | 147 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { |
150 return NULL; | 148 return NULL; |
151 } | 149 } |
152 *infoPtr = info; | 150 *infoPtr = info; |
153 *rowBytesPtr = fBitmap.rowBytes(); | 151 *rowBytesPtr = fBitmap.rowBytes(); |
154 return fBitmap.getPixels(); | 152 return fBitmap.getPixels(); |
155 } | 153 } |
156 | 154 |
157 bool SkImage_Raster::getROPixels(SkBitmap* dst) const { | 155 bool SkImage_Raster::getROPixels(SkBitmap* dst) const { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 199 } |
202 | 200 |
203 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, | 201 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, |
204 size_t rowBytes) { | 202 size_t rowBytes) { |
205 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); | 203 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); |
206 } | 204 } |
207 | 205 |
208 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { | 206 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { |
209 return ((SkImage_Raster*)image)->getPixelRef(); | 207 return ((SkImage_Raster*)image)->getPixelRef(); |
210 } | 208 } |
OLD | NEW |