OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDrawFilter.h" | 10 #include "SkDrawFilter.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 SkRect src, dst; | 346 SkRect src, dst; |
347 SkPaint paint; | 347 SkPaint paint; |
348 SkCanvas::SrcRectConstraint constraint; | 348 SkCanvas::SrcRectConstraint constraint; |
349 void draw(SkCanvas* c, const SkMatrix&) { | 349 void draw(SkCanvas* c, const SkMatrix&) { |
350 c->drawImageRect(image.get(), src, dst, &paint, constraint); | 350 c->drawImageRect(image.get(), src, dst, &paint, constraint); |
351 } | 351 } |
352 }; | 352 }; |
353 struct DrawImageLattice final : Op { | 353 struct DrawImageLattice final : Op { |
354 static const auto kType = Type::DrawImageLattice; | 354 static const auto kType = Type::DrawImageLattice; |
355 DrawImageLattice(sk_sp<const SkImage>&& image, int xs, int ys, int fs, | 355 DrawImageLattice(sk_sp<const SkImage>&& image, int xs, int ys, int fs, |
356 const SkRect& dst, const SkPaint* paint) | 356 const SkIRect& src, const SkRect& dst, const SkPaint* p
aint) |
357 : image(std::move(image)), xs(xs), ys(ys), fs(fs), dst(dst) { | 357 : image(std::move(image)), xs(xs), ys(ys), fs(fs), src(src), dst(dst
) { |
358 if (paint) { this->paint = *paint; } | 358 if (paint) { this->paint = *paint; } |
359 } | 359 } |
360 sk_sp<const SkImage> image; | 360 sk_sp<const SkImage> image; |
361 int xs, ys, fs; | 361 int xs, ys, fs; |
| 362 SkIRect src; |
362 SkRect dst; | 363 SkRect dst; |
363 SkPaint paint; | 364 SkPaint paint; |
364 void draw(SkCanvas* c, const SkMatrix&) { | 365 void draw(SkCanvas* c, const SkMatrix&) { |
365 auto xdivs = pod<int>(this, 0), | 366 auto xdivs = pod<int>(this, 0), |
366 ydivs = pod<int>(this, xs*sizeof(int)); | 367 ydivs = pod<int>(this, xs*sizeof(int)); |
367 auto flags = (0 == fs) ? nullptr : | 368 auto flags = (0 == fs) ? nullptr : |
368 pod<SkCanvas::Lattice::Flags>(this, (xs+ys)
*sizeof(int)); | 369 pod<SkCanvas::Lattice::Flags>(this, (xs+ys)
*sizeof(int)); |
369 c->drawImageLattice(image.get(), {xdivs, ydivs, flags, xs, ys}, dst,
&paint); | 370 c->drawImageLattice(image.get(), {xdivs, ydivs, flags, xs, ys, &src}
, dst, &paint); |
370 } | 371 } |
371 }; | 372 }; |
372 | 373 |
373 struct DrawText final : Op { | 374 struct DrawText final : Op { |
374 static const auto kType = Type::DrawText; | 375 static const auto kType = Type::DrawText; |
375 DrawText(size_t bytes, SkScalar x, SkScalar y, const SkPaint& paint) | 376 DrawText(size_t bytes, SkScalar x, SkScalar y, const SkPaint& paint) |
376 : bytes(bytes), x(x), y(y), paint(paint) {} | 377 : bytes(bytes), x(x), y(y), paint(paint) {} |
377 size_t bytes; | 378 size_t bytes; |
378 SkScalar x,y; | 379 SkScalar x,y; |
379 SkPaint paint; | 380 SkPaint paint; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 } | 663 } |
663 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec
t& dst, | 664 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec
t& dst, |
664 const SkPaint* paint, SkCanvas::SrcRectConstraint
constraint) { | 665 const SkPaint* paint, SkCanvas::SrcRectConstraint
constraint) { |
665 this->push<DrawImageRect>(0, SkImage::MakeFromBitmap(bm), src, dst, paint, c
onstraint); | 666 this->push<DrawImageRect>(0, SkImage::MakeFromBitmap(bm), src, dst, paint, c
onstraint); |
666 } | 667 } |
667 void SkLiteDL::drawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& la
ttice, | 668 void SkLiteDL::drawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& la
ttice, |
668 const SkRect& dst, const SkPaint* paint) { | 669 const SkRect& dst, const SkPaint* paint) { |
669 int xs = lattice.fXCount, ys = lattice.fYCount; | 670 int xs = lattice.fXCount, ys = lattice.fYCount; |
670 int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; | 671 int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; |
671 size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flag
s); | 672 size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flag
s); |
672 void* pod = this->push<DrawImageLattice>(bytes, SkImage::MakeFromBitmap(bm),
xs, ys, fs, dst, | 673 SkASSERT(lattice.fBounds); |
673 paint); | 674 void* pod = this->push<DrawImageLattice>(bytes, SkImage::MakeFromBitmap(bm),
xs, ys, fs, |
| 675 *lattice.fBounds, dst, paint); |
674 copy_v(pod, lattice.fXDivs, xs, | 676 copy_v(pod, lattice.fXDivs, xs, |
675 lattice.fYDivs, ys, | 677 lattice.fYDivs, ys, |
676 lattice.fFlags, fs); | 678 lattice.fFlags, fs); |
677 } | 679 } |
678 | 680 |
679 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { | 681 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { |
680 this->push<DrawImage>(0, sk_ref_sp(image), x,y, paint); | 682 this->push<DrawImage>(0, sk_ref_sp(image), x,y, paint); |
681 } | 683 } |
682 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center, | 684 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center, |
683 const SkRect& dst, const SkPaint* paint) { | 685 const SkRect& dst, const SkPaint* paint) { |
684 this->push<DrawImageNine>(0, sk_ref_sp(image), center, dst, paint); | 686 this->push<DrawImageNine>(0, sk_ref_sp(image), center, dst, paint); |
685 } | 687 } |
686 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, | 688 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, |
687 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { | 689 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { |
688 this->push<DrawImageRect>(0, sk_ref_sp(image), src, dst, paint, constraint); | 690 this->push<DrawImageRect>(0, sk_ref_sp(image), src, dst, paint, constraint); |
689 } | 691 } |
690 void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l
attice, | 692 void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l
attice, |
691 const SkRect& dst, const SkPaint* paint) { | 693 const SkRect& dst, const SkPaint* paint) { |
692 int xs = lattice.fXCount, ys = lattice.fYCount; | 694 int xs = lattice.fXCount, ys = lattice.fYCount; |
693 int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; | 695 int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; |
694 size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flag
s); | 696 size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flag
s); |
695 void* pod = this->push<DrawImageLattice>(bytes, sk_ref_sp(image), xs, ys, fs
, dst, paint); | 697 SkASSERT(lattice.fBounds); |
| 698 void* pod = this->push<DrawImageLattice>(bytes, sk_ref_sp(image), xs, ys, fs
, *lattice.fBounds, |
| 699 dst, paint); |
696 copy_v(pod, lattice.fXDivs, xs, | 700 copy_v(pod, lattice.fXDivs, xs, |
697 lattice.fYDivs, ys, | 701 lattice.fYDivs, ys, |
698 lattice.fFlags, fs); | 702 lattice.fFlags, fs); |
699 } | 703 } |
700 | 704 |
701 void SkLiteDL::drawText(const void* text, size_t bytes, | 705 void SkLiteDL::drawText(const void* text, size_t bytes, |
702 SkScalar x, SkScalar y, const SkPaint& paint) { | 706 SkScalar x, SkScalar y, const SkPaint& paint) { |
703 void* pod = this->push<DrawText>(bytes, bytes, x, y, paint); | 707 void* pod = this->push<DrawText>(bytes, bytes, x, y, paint); |
704 copy_v(pod, (const char*)text,bytes); | 708 copy_v(pod, (const char*)text,bytes); |
705 } | 709 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 }; | 830 }; |
827 | 831 |
828 // TODO: single-draw specializations | 832 // TODO: single-draw specializations |
829 | 833 |
830 return fallback_plan(); | 834 return fallback_plan(); |
831 } | 835 } |
832 | 836 |
833 void SkLiteDL::setBounds(const SkRect& bounds) { | 837 void SkLiteDL::setBounds(const SkRect& bounds) { |
834 fBounds = bounds; | 838 fBounds = bounds; |
835 } | 839 } |
OLD | NEW |