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" |
| 11 #include "SkImageFilter.h" |
11 #include "SkImageFilterCache.h" | 12 #include "SkImageFilterCache.h" |
12 #include "SkMallocPixelRef.h" | 13 #include "SkMallocPixelRef.h" |
13 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
14 #include "SkPaint.h" | 15 #include "SkPaint.h" |
15 #include "SkPath.h" | 16 #include "SkPath.h" |
16 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
17 #include "SkPixmap.h" | 18 #include "SkPixmap.h" |
| 19 #include "SkRasterClip.h" |
18 #include "SkShader.h" | 20 #include "SkShader.h" |
| 21 #include "SkSpecialImage.h" |
19 #include "SkSurface.h" | 22 #include "SkSurface.h" |
20 #include "SkXfermode.h" | 23 #include "SkXfermode.h" |
21 | 24 |
22 class SkColorTable; | 25 class SkColorTable; |
23 | 26 |
24 static bool valid_for_bitmap_device(const SkImageInfo& info, | 27 static bool valid_for_bitmap_device(const SkImageInfo& info, |
25 SkAlphaType* newAlphaType) { | 28 SkAlphaType* newAlphaType) { |
26 if (info.width() < 0 || info.height() < 0) { | 29 if (info.width() < 0 || info.height() < 0) { |
27 return false; | 30 return false; |
28 } | 31 } |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 const SkPaint& paint) { | 360 const SkPaint& paint) { |
358 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, | 361 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, |
359 indices, indexCount, paint); | 362 indices, indexCount, paint); |
360 } | 363 } |
361 | 364 |
362 void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 365 void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
363 int x, int y, const SkPaint& paint) { | 366 int x, int y, const SkPaint& paint) { |
364 draw.drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint); | 367 draw.drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint); |
365 } | 368 } |
366 | 369 |
| 370 /////////////////////////////////////////////////////////////////////////////// |
| 371 |
| 372 void SkBitmapDevice::drawSpecial(const SkDraw& draw, SkSpecialImage* srcImg, int
x, int y, |
| 373 const SkPaint& paint) { |
| 374 SkASSERT(!srcImg->isTextureBacked()); |
| 375 |
| 376 SkBitmap resultBM; |
| 377 |
| 378 SkImageFilter* filter = paint.getImageFilter(); |
| 379 if (filter) { |
| 380 SkIPoint offset = SkIPoint::Make(0, 0); |
| 381 SkMatrix matrix = *draw.fMatrix; |
| 382 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| 383 const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y); |
| 384 SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache()); |
| 385 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
| 386 |
| 387 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset
)); |
| 388 if (resultImg) { |
| 389 SkPaint tmpUnfiltered(paint); |
| 390 tmpUnfiltered.setImageFilter(nullptr); |
| 391 if (resultImg->getROPixels(&resultBM)) { |
| 392 this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(),
tmpUnfiltered); |
| 393 } |
| 394 } |
| 395 } else { |
| 396 if (srcImg->getROPixels(&resultBM)) { |
| 397 this->drawSprite(draw, resultBM, x, y, paint); |
| 398 } |
| 399 } |
| 400 } |
| 401 |
| 402 sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkBitmap& bitmap) { |
| 403 return SkSpecialImage::MakeFromRaster(bitmap.bounds(), bitmap); |
| 404 } |
| 405 |
| 406 sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkImage* image) { |
| 407 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), |
| 408 image->makeNonTextureImage()); |
| 409 } |
| 410 |
| 411 sk_sp<SkSpecialImage> SkBitmapDevice::snapSpecial() { |
| 412 return this->makeSpecial(fBitmap); |
| 413 } |
| 414 |
| 415 /////////////////////////////////////////////////////////////////////////////// |
| 416 |
367 sk_sp<SkSurface> SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSu
rfaceProps& props) { | 417 sk_sp<SkSurface> SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSu
rfaceProps& props) { |
368 return SkSurface::MakeRaster(info, &props); | 418 return SkSurface::MakeRaster(info, &props); |
369 } | 419 } |
370 | 420 |
371 SkImageFilterCache* SkBitmapDevice::getImageFilterCache() { | 421 SkImageFilterCache* SkBitmapDevice::getImageFilterCache() { |
372 SkImageFilterCache* cache = SkImageFilterCache::Get(); | 422 SkImageFilterCache* cache = SkImageFilterCache::Get(); |
373 cache->ref(); | 423 cache->ref(); |
374 return cache; | 424 return cache; |
375 } | 425 } |
376 | 426 |
377 /////////////////////////////////////////////////////////////////////////////// | 427 /////////////////////////////////////////////////////////////////////////////// |
378 | 428 |
379 bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const { | 429 bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const { |
380 if (kN32_SkColorType != fBitmap.colorType() || | 430 if (kN32_SkColorType != fBitmap.colorType() || |
381 paint.getRasterizer() || | 431 paint.getRasterizer() || |
382 paint.getPathEffect() || | 432 paint.getPathEffect() || |
383 paint.isFakeBoldText() || | 433 paint.isFakeBoldText() || |
384 paint.getStyle() != SkPaint::kFill_Style || | 434 paint.getStyle() != SkPaint::kFill_Style || |
385 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 435 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
386 { | 436 { |
387 return true; | 437 return true; |
388 } | 438 } |
389 return false; | 439 return false; |
390 } | 440 } |
OLD | NEW |