halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 8 | #include "SkLatticeIter.h" |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 9 | #include "SkPDFCanvas.h" |
| 10 | #include "SkPDFDevice.h" |
| 11 | |
| 12 | SkPDFCanvas::SkPDFCanvas(const sk_sp<SkPDFDevice>& dev) |
| 13 | : SkCanvas(dev.get()) {} |
| 14 | |
| 15 | SkPDFCanvas::~SkPDFCanvas() {} |
| 16 | |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 17 | /* |
| 18 | * PDF's impl sometimes wants to access the raster clip as a SkRegion. To keep this valid, |
| 19 | * we intercept all clip calls to ensure that the clip stays BW (i.e. never antialiased), since |
| 20 | * an antialiased clip won't build a SkRegion (it builds SkAAClip). |
| 21 | */ |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 22 | void SkPDFCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 23 | this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); |
| 24 | } |
| 25 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 26 | void SkPDFCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 27 | this->INHERITED::onClipRRect(rrect, op, kHard_ClipEdgeStyle); |
| 28 | } |
| 29 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 30 | void SkPDFCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 31 | this->INHERITED::onClipPath(path, op, kHard_ClipEdgeStyle); |
| 32 | } |
| 33 | |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 34 | void SkPDFCanvas::onDrawBitmapNine(const SkBitmap& bitmap, |
| 35 | const SkIRect& center, |
| 36 | const SkRect& dst, |
| 37 | const SkPaint* paint) { |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 38 | SkLatticeIter iter(bitmap.width(), bitmap.height(), center, dst); |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 39 | SkRect srcR, dstR; |
| 40 | while (iter.next(&srcR, &dstR)) { |
| 41 | this->drawBitmapRect(bitmap, srcR, dstR, paint); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void SkPDFCanvas::onDrawImageNine(const SkImage* image, |
| 46 | const SkIRect& center, |
| 47 | const SkRect& dst, |
| 48 | const SkPaint* paint) { |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 49 | SkLatticeIter iter(image->width(), image->height(), center, dst); |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 50 | SkRect srcR, dstR; |
| 51 | while (iter.next(&srcR, &dstR)) { |
| 52 | this->drawImageRect(image, srcR, dstR, paint); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void SkPDFCanvas::onDrawImageRect(const SkImage* image, |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 57 | const SkRect* src, |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 58 | const SkRect& dst, |
| 59 | const SkPaint* paint, |
| 60 | SkCanvas::SrcRectConstraint constraint) { |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 61 | SkAutoCanvasRestore autoCanvasRestore(this, true); |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 62 | this->clipRect(dst); |
| 63 | this->SkCanvas::onDrawImageRect(image, src, dst, paint, constraint); |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void SkPDFCanvas::onDrawBitmapRect(const SkBitmap& bitmap, |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 67 | const SkRect* src, |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 68 | const SkRect& dst, |
| 69 | const SkPaint* paint, |
| 70 | SkCanvas::SrcRectConstraint constraint) { |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 71 | SkAutoCanvasRestore autoCanvasRestore(this, true); |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 72 | this->clipRect(dst); |
| 73 | this->SkCanvas::onDrawBitmapRect(bitmap, src, dst, paint, constraint); |
halcanary | 66be626 | 2016-03-21 13:01:34 -0700 | [diff] [blame] | 74 | } |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 75 | |
| 76 | void SkPDFCanvas::onDrawImageLattice(const SkImage* image, |
| 77 | const Lattice& lattice, |
| 78 | const SkRect& dst, |
| 79 | const SkPaint* paint) { |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 80 | SkLatticeIter iter(lattice, dst); |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 81 | SkRect srcR, dstR; |
| 82 | while (iter.next(&srcR, &dstR)) { |
| 83 | this->drawImageRect(image, srcR, dstR, paint); |
| 84 | } |
| 85 | } |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 86 | |
| 87 | void SkPDFCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, |
| 88 | const Lattice& lattice, |
| 89 | const SkRect& dst, |
| 90 | const SkPaint* paint) { |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 91 | SkLatticeIter iter(lattice, dst); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 92 | SkRect srcR, dstR; |
| 93 | while (iter.next(&srcR, &dstR)) { |
| 94 | this->drawBitmapRect(bitmap, srcR, dstR, paint); |
| 95 | } |
| 96 | } |
| 97 | |