Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
| 11 #include "SkClipStack.h" | 11 #include "SkClipStack.h" |
| 12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
| 13 #include "SkDraw.h" | 13 #include "SkDraw.h" |
| 14 #include "SkDrawable.h" | 14 #include "SkDrawable.h" |
| 15 #include "SkDrawFilter.h" | 15 #include "SkDrawFilter.h" |
| 16 #include "SkDrawLooper.h" | 16 #include "SkDrawLooper.h" |
| 17 #include "SkErrorInternals.h" | 17 #include "SkErrorInternals.h" |
| 18 #include "SkImage.h" | 18 #include "SkImage.h" |
| 19 #include "SkImage_Base.h" | 19 #include "SkImage_Base.h" |
| 20 #include "SkImage_Raster.h" | |
| 20 #include "SkImageFilter.h" | 21 #include "SkImageFilter.h" |
| 21 #include "SkImageFilterCache.h" | 22 #include "SkImageFilterCache.h" |
| 22 #include "SkLatticeIter.h" | 23 #include "SkLatticeIter.h" |
| 23 #include "SkMatrixUtils.h" | 24 #include "SkMatrixUtils.h" |
| 24 #include "SkMetaData.h" | 25 #include "SkMetaData.h" |
| 25 #include "SkPaintPriv.h" | 26 #include "SkPaintPriv.h" |
| 26 #include "SkPatchUtils.h" | 27 #include "SkPatchUtils.h" |
| 27 #include "SkPicture.h" | 28 #include "SkPicture.h" |
| 28 #include "SkRasterClip.h" | 29 #include "SkRasterClip.h" |
| 29 #include "SkReadPixelsRec.h" | 30 #include "SkReadPixelsRec.h" |
| (...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1985 if (dst.isEmpty()) { | 1986 if (dst.isEmpty()) { |
| 1986 return; | 1987 return; |
| 1987 } | 1988 } |
| 1988 if (SkLatticeIter::Valid(image->width(), image->height(), center)) { | 1989 if (SkLatticeIter::Valid(image->width(), image->height(), center)) { |
| 1989 this->onDrawImageNine(image, center, dst, paint); | 1990 this->onDrawImageNine(image, center, dst, paint); |
| 1990 } else { | 1991 } else { |
| 1991 this->drawImageRect(image, dst, paint); | 1992 this->drawImageRect(image, dst, paint); |
| 1992 } | 1993 } |
| 1993 } | 1994 } |
| 1994 | 1995 |
| 1996 void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co nst SkRect& dst, | |
|
msarett
2016/08/03 15:07:57
Just moved this.
| |
| 1997 const SkPaint* paint) { | |
| 1998 RETURN_ON_NULL(image); | |
| 1999 if (dst.isEmpty()) { | |
| 2000 return; | |
| 2001 } | |
| 2002 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { | |
| 2003 this->onDrawImageLattice(image, lattice, dst, paint); | |
| 2004 } else { | |
| 2005 this->drawImageRect(image, dst, paint); | |
| 2006 } | |
| 2007 } | |
| 2008 | |
| 1995 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) { | 2009 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) { |
| 1996 if (bitmap.drawsNothing()) { | 2010 if (bitmap.drawsNothing()) { |
| 1997 return; | 2011 return; |
| 1998 } | 2012 } |
| 1999 this->onDrawBitmap(bitmap, dx, dy, paint); | 2013 this->onDrawBitmap(bitmap, dx, dy, paint); |
| 2000 } | 2014 } |
| 2001 | 2015 |
| 2002 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S kRect& dst, | 2016 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S kRect& dst, |
| 2003 const SkPaint* paint, SrcRectConstraint constraint ) { | 2017 const SkPaint* paint, SrcRectConstraint constraint ) { |
| 2004 if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { | 2018 if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2021 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con st SkRect& dst, | 2035 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con st SkRect& dst, |
| 2022 const SkPaint* paint) { | 2036 const SkPaint* paint) { |
| 2023 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2037 if (bitmap.drawsNothing() || dst.isEmpty()) { |
| 2024 return; | 2038 return; |
| 2025 } | 2039 } |
| 2026 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { | 2040 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { |
| 2027 this->onDrawBitmapNine(bitmap, center, dst, paint); | 2041 this->onDrawBitmapNine(bitmap, center, dst, paint); |
| 2028 } else { | 2042 } else { |
| 2029 this->drawBitmapRect(bitmap, dst, paint); | 2043 this->drawBitmapRect(bitmap, dst, paint); |
| 2030 } | 2044 } |
| 2031 | |
| 2032 } | 2045 } |
| 2033 | 2046 |
| 2034 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, | 2047 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 2035 const SkPaint* paint) { | 2048 const SkPaint* paint) { |
| 2036 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 2049 if (bitmap.drawsNothing() || dst.isEmpty()) { |
| 2037 this->drawImageLattice(image.get(), lattice, dst, paint); | |
| 2038 } | |
| 2039 | |
| 2040 void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co nst SkRect& dst, | |
| 2041 const SkPaint* paint) { | |
| 2042 RETURN_ON_NULL(image); | |
| 2043 if (dst.isEmpty()) { | |
| 2044 return; | 2050 return; |
| 2045 } | 2051 } |
| 2046 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { | 2052 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { |
| 2047 this->onDrawImageLattice(image, lattice, dst, paint); | 2053 this->onDrawBitmapLattice(bitmap, lattice, dst, paint); |
| 2048 } else { | 2054 } else { |
| 2049 this->drawImageRect(image, dst, paint); | 2055 this->drawBitmapRect(bitmap, dst, paint); |
| 2050 } | 2056 } |
| 2051 } | 2057 } |
| 2052 | 2058 |
| 2053 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[], | 2059 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[], |
| 2054 const SkColor colors[], int count, SkXfermode::Mode mod e, | 2060 const SkColor colors[], int count, SkXfermode::Mode mod e, |
| 2055 const SkRect* cull, const SkPaint* paint) { | 2061 const SkRect* cull, const SkPaint* paint) { |
| 2056 RETURN_ON_NULL(atlas); | 2062 RETURN_ON_NULL(atlas); |
| 2057 if (count <= 0) { | 2063 if (count <= 0) { |
| 2058 return; | 2064 return; |
| 2059 } | 2065 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2347 SkScalarRoundToInt(pt.fX), | 2353 SkScalarRoundToInt(pt.fX), |
| 2348 SkScalarRoundToInt(pt.fY), pnt); | 2354 SkScalarRoundToInt(pt.fY), pnt); |
| 2349 } else { | 2355 } else { |
| 2350 iter.fDevice->drawImage(iter, image, x, y, pnt); | 2356 iter.fDevice->drawImage(iter, image, x, y, pnt); |
| 2351 } | 2357 } |
| 2352 } | 2358 } |
| 2353 | 2359 |
| 2354 LOOPER_END | 2360 LOOPER_END |
| 2355 } | 2361 } |
| 2356 | 2362 |
| 2357 void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, | |
| 2358 const SkPaint* paint) { | |
| 2359 if (nullptr == paint || paint->canComputeFastBounds()) { | |
| 2360 SkRect storage; | |
| 2361 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { | |
| 2362 return; | |
| 2363 } | |
| 2364 } | |
| 2365 | |
| 2366 SkLazyPaint lazy; | |
| 2367 if (nullptr == paint) { | |
| 2368 paint = lazy.init(); | |
| 2369 } | |
| 2370 | |
| 2371 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) | |
| 2372 | |
| 2373 while (iter.next()) { | |
| 2374 iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint() ); | |
| 2375 } | |
| 2376 | |
| 2377 LOOPER_END | |
| 2378 } | |
| 2379 | |
| 2380 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, | 2363 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, |
| 2381 const SkPaint* paint, SrcRectConstraint constrain t) { | 2364 const SkPaint* paint, SrcRectConstraint constrain t) { |
| 2382 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2365 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
| 2383 if (nullptr == paint || paint->canComputeFastBounds()) { | 2366 if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2384 SkRect storage = dst; | 2367 SkRect storage = dst; |
| 2385 if (paint) { | 2368 if (paint) { |
| 2386 paint->computeFastBounds(dst, &storage); | 2369 paint->computeFastBounds(dst, &storage); |
| 2387 } | 2370 } |
| 2388 if (this->quickReject(storage)) { | 2371 if (this->quickReject(storage)) { |
| 2389 return; | 2372 return; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2540 | 2523 |
| 2541 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) | 2524 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2542 | 2525 |
| 2543 while (iter.next()) { | 2526 while (iter.next()) { |
| 2544 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); | 2527 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); |
| 2545 } | 2528 } |
| 2546 | 2529 |
| 2547 LOOPER_END | 2530 LOOPER_END |
| 2548 } | 2531 } |
| 2549 | 2532 |
| 2533 void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, | |
|
msarett
2016/08/03 15:07:57
Also moved.
| |
| 2534 const SkPaint* paint) { | |
| 2535 if (nullptr == paint || paint->canComputeFastBounds()) { | |
| 2536 SkRect storage; | |
| 2537 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { | |
| 2538 return; | |
| 2539 } | |
| 2540 } | |
| 2541 | |
| 2542 SkLazyPaint lazy; | |
| 2543 if (nullptr == paint) { | |
| 2544 paint = lazy.init(); | |
| 2545 } | |
| 2546 | |
| 2547 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) | |
| 2548 | |
| 2549 while (iter.next()) { | |
| 2550 iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint() ); | |
| 2551 } | |
| 2552 | |
| 2553 LOOPER_END | |
| 2554 } | |
| 2555 | |
| 2556 void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattic e, | |
|
msarett
2016/08/03 15:07:57
This is new. Could we also use this implementatio
mtklein
2016/08/03 15:11:51
They need to copy if immutable (though I think SkP
mtklein
2016/08/03 15:12:19
They need to copy if *mutable...
msarett
2016/08/03 15:49:23
Gotcha, I think the Picture/Record impls are as th
| |
| 2557 const SkRect& dst, const SkPaint* paint) { | |
| 2558 sk_sp<SkImage> image = sk_sp<SkImage>((SkImage*) new SkImage_Raster(bitmap, true)); | |
|
mtklein
2016/08/03 15:11:51
I think we spell this,
sk_sp<SkImage> image =
reed1
2016/08/03 15:21:05
I had suggested this point in the pipeline to comm
msarett
2016/08/03 15:49:23
Changed to use SkMakeImageFromRasterBitmap. Pushi
| |
| 2559 this->onDrawImageLattice(image.get(), lattice, dst, paint); | |
| 2560 } | |
| 2561 | |
| 2550 class SkDeviceFilteredPaint { | 2562 class SkDeviceFilteredPaint { |
| 2551 public: | 2563 public: |
| 2552 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { | 2564 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { |
| 2553 uint32_t filteredFlags = device->filterTextFlags(paint); | 2565 uint32_t filteredFlags = device->filterTextFlags(paint); |
| 2554 if (filteredFlags != paint.getFlags()) { | 2566 if (filteredFlags != paint.getFlags()) { |
| 2555 SkPaint* newPaint = fLazy.set(paint); | 2567 SkPaint* newPaint = fLazy.set(paint); |
| 2556 newPaint->setFlags(filteredFlags); | 2568 newPaint->setFlags(filteredFlags); |
| 2557 fPaint = newPaint; | 2569 fPaint = newPaint; |
| 2558 } else { | 2570 } else { |
| 2559 fPaint = &paint; | 2571 fPaint = &paint; |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3168 | 3180 |
| 3169 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3181 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 3170 fCanvas->restoreToCount(fSaveCount); | 3182 fCanvas->restoreToCount(fSaveCount); |
| 3171 } | 3183 } |
| 3172 | 3184 |
| 3173 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3185 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
| 3174 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 3186 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
| 3175 return this->makeSurface(info, props).release(); | 3187 return this->makeSurface(info, props).release(); |
| 3176 } | 3188 } |
| 3177 #endif | 3189 #endif |
| OLD | NEW |