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" |
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 if (dst.isEmpty()) { | 1985 if (dst.isEmpty()) { |
1986 return; | 1986 return; |
1987 } | 1987 } |
1988 if (SkLatticeIter::Valid(image->width(), image->height(), center)) { | 1988 if (SkLatticeIter::Valid(image->width(), image->height(), center)) { |
1989 this->onDrawImageNine(image, center, dst, paint); | 1989 this->onDrawImageNine(image, center, dst, paint); |
1990 } else { | 1990 } else { |
1991 this->drawImageRect(image, dst, paint); | 1991 this->drawImageRect(image, dst, paint); |
1992 } | 1992 } |
1993 } | 1993 } |
1994 | 1994 |
| 1995 void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co
nst SkRect& dst, |
| 1996 const SkPaint* paint) { |
| 1997 RETURN_ON_NULL(image); |
| 1998 if (dst.isEmpty()) { |
| 1999 return; |
| 2000 } |
| 2001 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { |
| 2002 this->onDrawImageLattice(image, lattice, dst, paint); |
| 2003 } else { |
| 2004 this->drawImageRect(image, dst, paint); |
| 2005 } |
| 2006 } |
| 2007 |
1995 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons
t SkPaint* paint) { | 2008 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons
t SkPaint* paint) { |
1996 if (bitmap.drawsNothing()) { | 2009 if (bitmap.drawsNothing()) { |
1997 return; | 2010 return; |
1998 } | 2011 } |
1999 this->onDrawBitmap(bitmap, dx, dy, paint); | 2012 this->onDrawBitmap(bitmap, dx, dy, paint); |
2000 } | 2013 } |
2001 | 2014 |
2002 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S
kRect& dst, | 2015 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S
kRect& dst, |
2003 const SkPaint* paint, SrcRectConstraint constraint
) { | 2016 const SkPaint* paint, SrcRectConstraint constraint
) { |
2004 if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { | 2017 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, | 2034 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, |
2022 const SkPaint* paint) { | 2035 const SkPaint* paint) { |
2023 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2036 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2024 return; | 2037 return; |
2025 } | 2038 } |
2026 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { | 2039 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { |
2027 this->onDrawBitmapNine(bitmap, center, dst, paint); | 2040 this->onDrawBitmapNine(bitmap, center, dst, paint); |
2028 } else { | 2041 } else { |
2029 this->drawBitmapRect(bitmap, dst, paint); | 2042 this->drawBitmapRect(bitmap, dst, paint); |
2030 } | 2043 } |
2031 | |
2032 } | 2044 } |
2033 | 2045 |
2034 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
const SkRect& dst, | 2046 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
const SkRect& dst, |
2035 const SkPaint* paint) { | 2047 const SkPaint* paint) { |
2036 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 2048 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; | 2049 return; |
2045 } | 2050 } |
2046 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { | 2051 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { |
2047 this->onDrawImageLattice(image, lattice, dst, paint); | 2052 this->onDrawBitmapLattice(bitmap, lattice, dst, paint); |
2048 } else { | 2053 } else { |
2049 this->drawImageRect(image, dst, paint); | 2054 this->drawBitmapRect(bitmap, dst, paint); |
2050 } | 2055 } |
2051 } | 2056 } |
2052 | 2057 |
2053 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk
Rect tex[], | 2058 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk
Rect tex[], |
2054 const SkColor colors[], int count, SkXfermode::Mode mod
e, | 2059 const SkColor colors[], int count, SkXfermode::Mode mod
e, |
2055 const SkRect* cull, const SkPaint* paint) { | 2060 const SkRect* cull, const SkPaint* paint) { |
2056 RETURN_ON_NULL(atlas); | 2061 RETURN_ON_NULL(atlas); |
2057 if (count <= 0) { | 2062 if (count <= 0) { |
2058 return; | 2063 return; |
2059 } | 2064 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 SkScalarRoundToInt(pt.fX), | 2352 SkScalarRoundToInt(pt.fX), |
2348 SkScalarRoundToInt(pt.fY), pnt); | 2353 SkScalarRoundToInt(pt.fY), pnt); |
2349 } else { | 2354 } else { |
2350 iter.fDevice->drawImage(iter, image, x, y, pnt); | 2355 iter.fDevice->drawImage(iter, image, x, y, pnt); |
2351 } | 2356 } |
2352 } | 2357 } |
2353 | 2358 |
2354 LOOPER_END | 2359 LOOPER_END |
2355 } | 2360 } |
2356 | 2361 |
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, | 2362 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
Rect& dst, |
2381 const SkPaint* paint, SrcRectConstraint constrain
t) { | 2363 const SkPaint* paint, SrcRectConstraint constrain
t) { |
2382 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2364 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
2383 if (nullptr == paint || paint->canComputeFastBounds()) { | 2365 if (nullptr == paint || paint->canComputeFastBounds()) { |
2384 SkRect storage = dst; | 2366 SkRect storage = dst; |
2385 if (paint) { | 2367 if (paint) { |
2386 paint->computeFastBounds(dst, &storage); | 2368 paint->computeFastBounds(dst, &storage); |
2387 } | 2369 } |
2388 if (this->quickReject(storage)) { | 2370 if (this->quickReject(storage)) { |
2389 return; | 2371 return; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2540 | 2522 |
2541 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) | 2523 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
2542 | 2524 |
2543 while (iter.next()) { | 2525 while (iter.next()) { |
2544 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); | 2526 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); |
2545 } | 2527 } |
2546 | 2528 |
2547 LOOPER_END | 2529 LOOPER_END |
2548 } | 2530 } |
2549 | 2531 |
| 2532 void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
const SkRect& dst, |
| 2533 const SkPaint* paint) { |
| 2534 if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2535 SkRect storage; |
| 2536 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) :
dst)) { |
| 2537 return; |
| 2538 } |
| 2539 } |
| 2540 |
| 2541 SkLazyPaint lazy; |
| 2542 if (nullptr == paint) { |
| 2543 paint = lazy.init(); |
| 2544 } |
| 2545 |
| 2546 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2547 |
| 2548 while (iter.next()) { |
| 2549 iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint()
); |
| 2550 } |
| 2551 |
| 2552 LOOPER_END |
| 2553 } |
| 2554 |
| 2555 void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattic
e, |
| 2556 const SkRect& dst, const SkPaint* paint) { |
| 2557 if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2558 SkRect storage; |
| 2559 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) :
dst)) { |
| 2560 return; |
| 2561 } |
| 2562 } |
| 2563 |
| 2564 SkLazyPaint lazy; |
| 2565 if (nullptr == paint) { |
| 2566 paint = lazy.init(); |
| 2567 } |
| 2568 |
| 2569 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2570 |
| 2571 while (iter.next()) { |
| 2572 iter.fDevice->drawBitmapLattice(iter, bitmap, lattice, dst, looper.paint
()); |
| 2573 } |
| 2574 |
| 2575 LOOPER_END |
| 2576 } |
| 2577 |
2550 class SkDeviceFilteredPaint { | 2578 class SkDeviceFilteredPaint { |
2551 public: | 2579 public: |
2552 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { | 2580 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { |
2553 uint32_t filteredFlags = device->filterTextFlags(paint); | 2581 uint32_t filteredFlags = device->filterTextFlags(paint); |
2554 if (filteredFlags != paint.getFlags()) { | 2582 if (filteredFlags != paint.getFlags()) { |
2555 SkPaint* newPaint = fLazy.set(paint); | 2583 SkPaint* newPaint = fLazy.set(paint); |
2556 newPaint->setFlags(filteredFlags); | 2584 newPaint->setFlags(filteredFlags); |
2557 fPaint = newPaint; | 2585 fPaint = newPaint; |
2558 } else { | 2586 } else { |
2559 fPaint = &paint; | 2587 fPaint = &paint; |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3168 | 3196 |
3169 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3197 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3170 fCanvas->restoreToCount(fSaveCount); | 3198 fCanvas->restoreToCount(fSaveCount); |
3171 } | 3199 } |
3172 | 3200 |
3173 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3201 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3174 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3202 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
3175 return this->makeSurface(info, props).release(); | 3203 return this->makeSurface(info, props).release(); |
3176 } | 3204 } |
3177 #endif | 3205 #endif |
OLD | NEW |