| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (kPMColor_SkColorType != subset.colorType()) { | 192 if (kPMColor_SkColorType != subset.colorType()) { |
| 193 // It'd be preferable to do this directly to bitmap. | 193 // It'd be preferable to do this directly to bitmap. |
| 194 subset.copyTo(&subset, kPMColor_SkColorType); | 194 subset.copyTo(&subset, kPMColor_SkColorType); |
| 195 } | 195 } |
| 196 SkAutoLockPixels alp(bitmap); | 196 SkAutoLockPixels alp(bitmap); |
| 197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); | 197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); |
| 198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); | 198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG | |
| 203 void SkBitmapDevice::writePixels(const SkBitmap& bitmap, | |
| 204 int x, int y, | |
| 205 SkCanvas::Config8888 config8888) { | |
| 206 if (bitmap.isNull() || bitmap.getTexture()) { | |
| 207 return; | |
| 208 } | |
| 209 const SkBitmap* sprite = &bitmap; | |
| 210 // check whether we have to handle a config8888 that doesn't match SkPMColor | |
| 211 if (SkBitmap::kARGB_8888_Config == bitmap.config() && | |
| 212 SkCanvas::kNative_Premul_Config8888 != config8888 && | |
| 213 kPMColorAlias != config8888) { | |
| 214 | |
| 215 // We're going to have to convert from a config8888 to the native config | |
| 216 // First we clip to the device bounds. | |
| 217 SkBitmap dstBmp = this->accessBitmap(true); | |
| 218 SkIRect spriteRect = SkIRect::MakeXYWH(x, y, | |
| 219 bitmap.width(), bitmap.height()); | |
| 220 SkIRect devRect = SkIRect::MakeWH(dstBmp.width(), dstBmp.height()); | |
| 221 if (!spriteRect.intersect(devRect)) { | |
| 222 return; | |
| 223 } | |
| 224 | |
| 225 // write directly to the device if it has pixels and is SkPMColor | |
| 226 bool drawSprite; | |
| 227 if (SkBitmap::kARGB_8888_Config == dstBmp.config() && !dstBmp.isNull())
{ | |
| 228 // we can write directly to the dst when doing the conversion | |
| 229 dstBmp.extractSubset(&dstBmp, spriteRect); | |
| 230 drawSprite = false; | |
| 231 } else { | |
| 232 // we convert to a temporary bitmap and draw that as a sprite | |
| 233 if (!dstBmp.allocPixels(SkImageInfo::MakeN32Premul(spriteRect.width(
), | |
| 234 spriteRect.height
()))) { | |
| 235 return; | |
| 236 } | |
| 237 drawSprite = true; | |
| 238 } | |
| 239 | |
| 240 // copy pixels to dstBmp and convert from config8888 to native config. | |
| 241 SkAutoLockPixels alp(bitmap); | |
| 242 uint32_t* srcPixels = bitmap.getAddr32(spriteRect.fLeft - x, | |
| 243 spriteRect.fTop - y); | |
| 244 SkCopyConfig8888ToBitmap(dstBmp, | |
| 245 srcPixels, | |
| 246 bitmap.rowBytes(), | |
| 247 config8888); | |
| 248 | |
| 249 if (drawSprite) { | |
| 250 // we've clipped the sprite when we made a copy | |
| 251 x = spriteRect.fLeft; | |
| 252 y = spriteRect.fTop; | |
| 253 sprite = &dstBmp; | |
| 254 } else { | |
| 255 return; | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 SkPaint paint; | |
| 260 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 261 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height())); | |
| 262 SkDraw draw; | |
| 263 draw.fRC = &clip; | |
| 264 draw.fClip = &clip.bwRgn(); | |
| 265 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap | |
| 266 draw.fMatrix = &SkMatrix::I(); | |
| 267 this->drawSprite(draw, *sprite, x, y, paint); | |
| 268 } | |
| 269 #endif | |
| 270 | |
| 271 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { | 202 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { |
| 272 if (fBitmap.getPixels()) { | 203 if (fBitmap.getPixels()) { |
| 273 *info = fBitmap.info(); | 204 *info = fBitmap.info(); |
| 274 *rowBytes = fBitmap.rowBytes(); | 205 *rowBytes = fBitmap.rowBytes(); |
| 275 return fBitmap.getPixels(); | 206 return fBitmap.getPixels(); |
| 276 } | 207 } |
| 277 return NULL; | 208 return NULL; |
| 278 } | 209 } |
| 279 | 210 |
| 280 static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB,
size_t bytesPerRow, | 211 static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB,
size_t bytesPerRow, |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 paint.getStyle() != SkPaint::kFill_Style || | 511 paint.getStyle() != SkPaint::kFill_Style || |
| 581 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 512 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
| 582 // turn off lcd | 513 // turn off lcd |
| 583 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 514 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 584 flags->fHinting = paint.getHinting(); | 515 flags->fHinting = paint.getHinting(); |
| 585 return true; | 516 return true; |
| 586 } | 517 } |
| 587 // we're cool with the paint as is | 518 // we're cool with the paint as is |
| 588 return false; | 519 return false; |
| 589 } | 520 } |
| OLD | NEW |