Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/core/SkCanvas.cpp

Issue 2205273003: Add onDrawBitmapLattice(), avoid unnecessary bitmap->image copy (Closed) Base URL: https://skia.googlesource.com/skia.git@copypaste
Patch Set: Add support for SkLiteRecorder Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 if (dst.isEmpty()) { 2050 if (dst.isEmpty()) {
2051 return; 2051 return;
2052 } 2052 }
2053 if (SkLatticeIter::Valid(image->width(), image->height(), center)) { 2053 if (SkLatticeIter::Valid(image->width(), image->height(), center)) {
2054 this->onDrawImageNine(image, center, dst, paint); 2054 this->onDrawImageNine(image, center, dst, paint);
2055 } else { 2055 } else {
2056 this->drawImageRect(image, dst, paint); 2056 this->drawImageRect(image, dst, paint);
2057 } 2057 }
2058 } 2058 }
2059 2059
2060 void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co nst SkRect& dst,
2061 const SkPaint* paint) {
2062 RETURN_ON_NULL(image);
2063 if (dst.isEmpty()) {
2064 return;
2065 }
2066 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) {
2067 this->onDrawImageLattice(image, lattice, dst, paint);
2068 } else {
2069 this->drawImageRect(image, dst, paint);
2070 }
2071 }
2072
2060 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) { 2073 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) {
2061 if (bitmap.drawsNothing()) { 2074 if (bitmap.drawsNothing()) {
2062 return; 2075 return;
2063 } 2076 }
2064 this->onDrawBitmap(bitmap, dx, dy, paint); 2077 this->onDrawBitmap(bitmap, dx, dy, paint);
2065 } 2078 }
2066 2079
2067 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S kRect& dst, 2080 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S kRect& dst,
2068 const SkPaint* paint, SrcRectConstraint constraint ) { 2081 const SkPaint* paint, SrcRectConstraint constraint ) {
2069 if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { 2082 if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) {
(...skipping 16 matching lines...) Expand all
2086 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con st SkRect& dst, 2099 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con st SkRect& dst,
2087 const SkPaint* paint) { 2100 const SkPaint* paint) {
2088 if (bitmap.drawsNothing() || dst.isEmpty()) { 2101 if (bitmap.drawsNothing() || dst.isEmpty()) {
2089 return; 2102 return;
2090 } 2103 }
2091 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { 2104 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) {
2092 this->onDrawBitmapNine(bitmap, center, dst, paint); 2105 this->onDrawBitmapNine(bitmap, center, dst, paint);
2093 } else { 2106 } else {
2094 this->drawBitmapRect(bitmap, dst, paint); 2107 this->drawBitmapRect(bitmap, dst, paint);
2095 } 2108 }
2096
2097 } 2109 }
2098 2110
2099 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, 2111 void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
2100 const SkPaint* paint) { 2112 const SkPaint* paint) {
2101 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); 2113 if (bitmap.drawsNothing() || dst.isEmpty()) {
2102 this->drawImageLattice(image.get(), lattice, dst, paint);
2103 }
2104
2105 void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co nst SkRect& dst,
2106 const SkPaint* paint) {
2107 RETURN_ON_NULL(image);
2108 if (dst.isEmpty()) {
2109 return; 2114 return;
2110 } 2115 }
2111 if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { 2116 if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) {
2112 this->onDrawImageLattice(image, lattice, dst, paint); 2117 this->onDrawBitmapLattice(bitmap, lattice, dst, paint);
2113 } else { 2118 } else {
2114 this->drawImageRect(image, dst, paint); 2119 this->drawBitmapRect(bitmap, dst, paint);
2115 } 2120 }
2116 } 2121 }
2117 2122
2118 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[], 2123 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[],
2119 const SkColor colors[], int count, SkXfermode::Mode mod e, 2124 const SkColor colors[], int count, SkXfermode::Mode mod e,
2120 const SkRect* cull, const SkPaint* paint) { 2125 const SkRect* cull, const SkPaint* paint) {
2121 RETURN_ON_NULL(atlas); 2126 RETURN_ON_NULL(atlas);
2122 if (count <= 0) { 2127 if (count <= 0) {
2123 return; 2128 return;
2124 } 2129 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 SkScalarRoundToInt(pt.fX), 2417 SkScalarRoundToInt(pt.fX),
2413 SkScalarRoundToInt(pt.fY), pnt); 2418 SkScalarRoundToInt(pt.fY), pnt);
2414 } else { 2419 } else {
2415 iter.fDevice->drawImage(iter, image, x, y, pnt); 2420 iter.fDevice->drawImage(iter, image, x, y, pnt);
2416 } 2421 }
2417 } 2422 }
2418 2423
2419 LOOPER_END 2424 LOOPER_END
2420 } 2425 }
2421 2426
2422 void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
2423 const SkPaint* paint) {
2424 if (nullptr == paint || paint->canComputeFastBounds()) {
2425 SkRect storage;
2426 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2427 return;
2428 }
2429 }
2430
2431 SkLazyPaint lazy;
2432 if (nullptr == paint) {
2433 paint = lazy.init();
2434 }
2435
2436 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
2437
2438 while (iter.next()) {
2439 iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint() );
2440 }
2441
2442 LOOPER_END
2443 }
2444
2445 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, 2427 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst,
2446 const SkPaint* paint, SrcRectConstraint constrain t) { 2428 const SkPaint* paint, SrcRectConstraint constrain t) {
2447 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); 2429 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()");
2448 if (nullptr == paint || paint->canComputeFastBounds()) { 2430 if (nullptr == paint || paint->canComputeFastBounds()) {
2449 SkRect storage = dst; 2431 SkRect storage = dst;
2450 if (paint) { 2432 if (paint) {
2451 paint->computeFastBounds(dst, &storage); 2433 paint->computeFastBounds(dst, &storage);
2452 } 2434 }
2453 if (this->quickReject(storage)) { 2435 if (this->quickReject(storage)) {
2454 return; 2436 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 2587
2606 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) 2588 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
2607 2589
2608 while (iter.next()) { 2590 while (iter.next()) {
2609 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); 2591 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint());
2610 } 2592 }
2611 2593
2612 LOOPER_END 2594 LOOPER_END
2613 } 2595 }
2614 2596
2597 void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
2598 const SkPaint* paint) {
2599 if (nullptr == paint || paint->canComputeFastBounds()) {
2600 SkRect storage;
2601 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2602 return;
2603 }
2604 }
2605
2606 SkLazyPaint lazy;
2607 if (nullptr == paint) {
2608 paint = lazy.init();
2609 }
2610
2611 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
2612
2613 while (iter.next()) {
2614 iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint() );
2615 }
2616
2617 LOOPER_END
2618 }
2619
2620 void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattic e,
2621 const SkRect& dst, const SkPaint* paint) {
2622 if (nullptr == paint || paint->canComputeFastBounds()) {
2623 SkRect storage;
2624 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2625 return;
2626 }
2627 }
2628
2629 SkLazyPaint lazy;
2630 if (nullptr == paint) {
2631 paint = lazy.init();
2632 }
2633
2634 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
2635
2636 while (iter.next()) {
2637 iter.fDevice->drawBitmapLattice(iter, bitmap, lattice, dst, looper.paint ());
2638 }
2639
2640 LOOPER_END
2641 }
2642
2615 class SkDeviceFilteredPaint { 2643 class SkDeviceFilteredPaint {
2616 public: 2644 public:
2617 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { 2645 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) {
2618 uint32_t filteredFlags = device->filterTextFlags(paint); 2646 uint32_t filteredFlags = device->filterTextFlags(paint);
2619 if (filteredFlags != paint.getFlags()) { 2647 if (filteredFlags != paint.getFlags()) {
2620 SkPaint* newPaint = fLazy.set(paint); 2648 SkPaint* newPaint = fLazy.set(paint);
2621 newPaint->setFlags(filteredFlags); 2649 newPaint->setFlags(filteredFlags);
2622 fPaint = newPaint; 2650 fPaint = newPaint;
2623 } else { 2651 } else {
2624 fPaint = &paint; 2652 fPaint = &paint;
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
3359 3387
3360 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3388 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3361 fCanvas->restoreToCount(fSaveCount); 3389 fCanvas->restoreToCount(fSaveCount);
3362 } 3390 }
3363 3391
3364 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API 3392 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
3365 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 3393 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
3366 return this->makeSurface(info, props).release(); 3394 return this->makeSurface(info, props).release();
3367 } 3395 }
3368 #endif 3396 #endif
OLDNEW
« no previous file with comments | « include/core/SkDevice.h ('k') | src/core/SkDevice.cpp » ('j') | src/core/SkLiteDL.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698