OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& sr
c, | 166 bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& sr
c, |
167 const SkImageFilter::Context& ctx, SkBitmap* re
sult, | 167 const SkImageFilter::Context& ctx, SkBitmap* re
sult, |
168 SkIPoint* offset) { | 168 SkIPoint* offset) { |
169 return false; | 169 return false; |
170 } | 170 } |
171 | 171 |
172 bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { | 172 bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { |
173 return true; | 173 return true; |
174 } | 174 } |
175 | 175 |
| 176 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG |
176 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, | 177 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, |
177 int x, int y, | 178 int x, int y, |
178 SkCanvas::Config8888 config8888) { | 179 SkCanvas::Config8888 config8888) { |
179 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); | 180 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); |
180 SkASSERT(!bitmap.isNull()); | 181 SkASSERT(!bitmap.isNull()); |
181 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma
keXYWH(x, y, | 182 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma
keXYWH(x, y, |
182 bitmap
.width(), | 183 bitmap
.width(), |
183 bitmap
.height()))); | 184 bitmap
.height()))); |
184 | 185 |
185 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height()); | 186 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height()); |
186 const SkBitmap& src = this->accessBitmap(false); | 187 const SkBitmap& src = this->accessBitmap(false); |
187 | 188 |
188 SkBitmap subset; | 189 SkBitmap subset; |
189 if (!src.extractSubset(&subset, srcRect)) { | 190 if (!src.extractSubset(&subset, srcRect)) { |
190 return false; | 191 return false; |
191 } | 192 } |
192 if (kPMColor_SkColorType != subset.colorType()) { | 193 if (kPMColor_SkColorType != subset.colorType()) { |
193 // It'd be preferable to do this directly to bitmap. | 194 // It'd be preferable to do this directly to bitmap. |
194 subset.copyTo(&subset, kPMColor_SkColorType); | 195 subset.copyTo(&subset, kPMColor_SkColorType); |
195 } | 196 } |
196 SkAutoLockPixels alp(bitmap); | 197 SkAutoLockPixels alp(bitmap); |
197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); | 198 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); |
198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); | 199 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); |
199 return true; | 200 return true; |
200 } | 201 } |
| 202 #endif |
201 | 203 |
202 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { | 204 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { |
203 if (fBitmap.getPixels()) { | 205 if (fBitmap.getPixels()) { |
204 *info = fBitmap.info(); | 206 *info = fBitmap.info(); |
205 *rowBytes = fBitmap.rowBytes(); | 207 *rowBytes = fBitmap.rowBytes(); |
206 return fBitmap.getPixels(); | 208 return fBitmap.getPixels(); |
207 } | 209 } |
208 return NULL; | 210 return NULL; |
209 } | 211 } |
210 | 212 |
(...skipping 28 matching lines...) Expand all Loading... |
239 case kBGRA_8888_SkColorType: | 241 case kBGRA_8888_SkColorType: |
240 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_
Unpremul_Config8888; | 242 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_
Unpremul_Config8888; |
241 return true; | 243 return true; |
242 default: | 244 default: |
243 return false; | 245 return false; |
244 } | 246 } |
245 } | 247 } |
246 | 248 |
247 // TODO: make this guy real, and not rely on legacy config8888 utility | 249 // TODO: make this guy real, and not rely on legacy config8888 utility |
248 #include "SkConfig8888.h" | 250 #include "SkConfig8888.h" |
249 static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst
RowBytes, | 251 static bool copy_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstR
owBytes, |
250 const SkImageInfo& srcInfo, const void* srcPixels, size
_t srcRowBytes) { | 252 const SkImageInfo& srcInfo, const void* srcPixels, size_
t srcRowBytes) { |
251 if (srcInfo.dimensions() != dstInfo.dimensions()) { | 253 if (srcInfo.dimensions() != dstInfo.dimensions()) { |
252 return false; | 254 return false; |
253 } | 255 } |
254 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { | 256 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { |
255 SkCanvas::Config8888 srcConfig, dstConfig; | 257 SkCanvas::Config8888 srcConfig, dstConfig; |
256 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, &
dstConfig)) { | 258 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, &
dstConfig)) { |
257 return false; | 259 return false; |
258 } | 260 } |
259 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig, | 261 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig, |
260 (const uint32_t*)srcPixels, srcRowBytes, srcCo
nfig, | 262 (const uint32_t*)srcPixels, srcRowBytes, srcCo
nfig, |
(...skipping 27 matching lines...) Expand all Loading... |
288 return false; | 290 return false; |
289 } | 291 } |
290 | 292 |
291 SkImageInfo dstInfo = fBitmap.info(); | 293 SkImageInfo dstInfo = fBitmap.info(); |
292 dstInfo.fWidth = srcInfo.width(); | 294 dstInfo.fWidth = srcInfo.width(); |
293 dstInfo.fHeight = srcInfo.height(); | 295 dstInfo.fHeight = srcInfo.height(); |
294 | 296 |
295 void* dstPixels = fBitmap.getAddr(x, y); | 297 void* dstPixels = fBitmap.getAddr(x, y); |
296 size_t dstRowBytes = fBitmap.rowBytes(); | 298 size_t dstRowBytes = fBitmap.rowBytes(); |
297 | 299 |
298 if (write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRow
Bytes)) { | 300 if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowB
ytes)) { |
299 fBitmap.notifyPixelsChanged(); | 301 fBitmap.notifyPixelsChanged(); |
300 return true; | 302 return true; |
301 } | 303 } |
302 return false; | 304 return false; |
303 } | 305 } |
304 | 306 |
| 307 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, |
| 308 int x, int y) { |
| 309 // since we don't stop creating un-pixeled devices yet, check for no pixels
here |
| 310 if (NULL == fBitmap.getPixels()) { |
| 311 return false; |
| 312 } |
| 313 |
| 314 SkImageInfo srcInfo = fBitmap.info(); |
| 315 |
| 316 // perhaps can relax these in the future |
| 317 if (4 != dstInfo.bytesPerPixel()) { |
| 318 return false; |
| 319 } |
| 320 if (4 != srcInfo.bytesPerPixel()) { |
| 321 return false; |
| 322 } |
| 323 |
| 324 srcInfo.fWidth = dstInfo.width(); |
| 325 srcInfo.fHeight = dstInfo.height(); |
| 326 |
| 327 const void* srcPixels = fBitmap.getAddr(x, y); |
| 328 const size_t srcRowBytes = fBitmap.rowBytes(); |
| 329 |
| 330 return copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcR
owBytes); |
| 331 } |
| 332 |
305 /////////////////////////////////////////////////////////////////////////////// | 333 /////////////////////////////////////////////////////////////////////////////// |
306 | 334 |
307 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 335 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
308 draw.drawPaint(paint); | 336 draw.drawPaint(paint); |
309 } | 337 } |
310 | 338 |
311 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, | 339 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, |
312 const SkPoint pts[], const SkPaint& paint) { | 340 const SkPoint pts[], const SkPaint& paint) { |
313 CHECK_FOR_ANNOTATION(paint); | 341 CHECK_FOR_ANNOTATION(paint); |
314 draw.drawPoints(mode, count, pts, paint); | 342 draw.drawPoints(mode, count, pts, paint); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 paint.getStyle() != SkPaint::kFill_Style || | 539 paint.getStyle() != SkPaint::kFill_Style || |
512 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 540 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
513 // turn off lcd | 541 // turn off lcd |
514 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 542 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
515 flags->fHinting = paint.getHinting(); | 543 flags->fHinting = paint.getHinting(); |
516 return true; | 544 return true; |
517 } | 545 } |
518 // we're cool with the paint as is | 546 // we're cool with the paint as is |
519 return false; | 547 return false; |
520 } | 548 } |
OLD | NEW |