reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 8 | #include "SkCanvas.h" |
| 9 | |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 10 | #include "SkArenaAlloc.h" |
Mike Reed | 986480a | 2017-01-13 22:43:16 +0000 | [diff] [blame] | 11 | #include "SkBitmapDevice.h" |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 12 | #include "SkCanvasPriv.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 13 | #include "SkClipOpPriv.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 14 | #include "SkClipStack.h" |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 15 | #include "SkColorFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkDraw.h" |
| 17 | #include "SkDrawFilter.h" |
| 18 | #include "SkDrawLooper.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 19 | #include "SkDrawable.h" |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 20 | #include "SkGlyphCache.h" |
| 21 | #include "SkGlyphRun.h" |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 22 | #include "SkImage.h" |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 23 | #include "SkImageFilter.h" |
| 24 | #include "SkImageFilterCache.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 25 | #include "SkImage_Base.h" |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 26 | #include "SkLatticeIter.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 27 | #include "SkMSAN.h" |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 28 | #include "SkMakeUnique.h" |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 29 | #include "SkMatrixUtils.h" |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 30 | #include "SkMetaData.h" |
Florin Malita | ee424ac | 2016-12-01 12:47:59 -0500 | [diff] [blame] | 31 | #include "SkNoDrawCanvas.h" |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 32 | #include "SkNx.h" |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 33 | #include "SkPaintPriv.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 34 | #include "SkPatchUtils.h" |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 35 | #include "SkPathEffect.h" |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 36 | #include "SkPicture.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 37 | #include "SkRRect.h" |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 38 | #include "SkRasterClip.h" |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 39 | #include "SkRasterHandleAllocator.h" |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 40 | #include "SkSpecialImage.h" |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 41 | #include "SkStrikeCache.h" |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 42 | #include "SkString.h" |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 43 | #include "SkSurface_Base.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 44 | #include "SkTLazy.h" |
fmalita | 7ba7aa7 | 2014-08-29 09:46:36 -0700 | [diff] [blame] | 45 | #include "SkTextBlob.h" |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 46 | #include "SkTextFormatParams.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 47 | #include "SkTo.h" |
danakj | 8f757f5 | 2014-11-04 11:48:43 -0800 | [diff] [blame] | 48 | #include "SkTraceEvent.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 49 | #include "SkVertices.h" |
| 50 | |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 51 | #include <new> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 53 | #if SK_SUPPORT_GPU |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 54 | #include "GrContext.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 55 | #include "SkGr.h" |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 58 | #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
Mike Reed | 74d6e11 | 2018-01-23 13:06:12 -0500 | [diff] [blame] | 59 | #define RETURN_ON_FALSE(pred) do { if (!(pred)) return; } while (0) |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 60 | |
Mike Reed | 139e5e0 | 2017-03-08 11:29:33 -0500 | [diff] [blame] | 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 62 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Return true if the drawing this rect would hit every pixels in the canvas. |
| 65 | * |
| 66 | * Returns false if |
| 67 | * - rect does not contain the canvas' bounds |
| 68 | * - paint is not fill |
| 69 | * - paint would blur or otherwise change the coverage of the rect |
| 70 | */ |
| 71 | bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* paint, |
| 72 | ShaderOverrideOpacity overrideOpacity) const { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 73 | static_assert((int)SkPaintPriv::kNone_ShaderOverrideOpacity == |
| 74 | (int)kNone_ShaderOverrideOpacity, |
| 75 | "need_matching_enums0"); |
| 76 | static_assert((int)SkPaintPriv::kOpaque_ShaderOverrideOpacity == |
| 77 | (int)kOpaque_ShaderOverrideOpacity, |
| 78 | "need_matching_enums1"); |
| 79 | static_assert((int)SkPaintPriv::kNotOpaque_ShaderOverrideOpacity == |
| 80 | (int)kNotOpaque_ShaderOverrideOpacity, |
| 81 | "need_matching_enums2"); |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 82 | |
| 83 | const SkISize size = this->getBaseLayerSize(); |
| 84 | const SkRect bounds = SkRect::MakeIWH(size.width(), size.height()); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 85 | |
| 86 | // if we're clipped at all, we can't overwrite the entire surface |
| 87 | { |
| 88 | SkBaseDevice* base = this->getDevice(); |
| 89 | SkBaseDevice* top = this->getTopDevice(); |
| 90 | if (base != top) { |
| 91 | return false; // we're in a saveLayer, so conservatively don't assume we'll overwrite |
| 92 | } |
| 93 | if (!base->clipIsWideOpen()) { |
| 94 | return false; |
| 95 | } |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | if (rect) { |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 99 | if (!this->getTotalMatrix().isScaleTranslate()) { |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 100 | return false; // conservative |
| 101 | } |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 102 | |
| 103 | SkRect devRect; |
| 104 | this->getTotalMatrix().mapRectScaleTranslate(&devRect, *rect); |
| 105 | if (!devRect.contains(bounds)) { |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (paint) { |
| 111 | SkPaint::Style paintStyle = paint->getStyle(); |
| 112 | if (!(paintStyle == SkPaint::kFill_Style || |
| 113 | paintStyle == SkPaint::kStrokeAndFill_Style)) { |
| 114 | return false; |
| 115 | } |
| 116 | if (paint->getMaskFilter() || paint->getLooper() |
| 117 | || paint->getPathEffect() || paint->getImageFilter()) { |
| 118 | return false; // conservative |
| 119 | } |
| 120 | } |
| 121 | return SkPaintPriv::Overwrites(paint, (SkPaintPriv::ShaderOverrideOpacity)overrideOpacity); |
| 122 | } |
| 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 125 | |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 126 | // experimental for faster tiled drawing... |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | //#define SK_TRACE_SAVERESTORE |
| 128 | |
| 129 | #ifdef SK_TRACE_SAVERESTORE |
| 130 | static int gLayerCounter; |
| 131 | static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gLayerCounter); } |
| 132 | static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gLayerCounter); } |
| 133 | |
| 134 | static int gRecCounter; |
| 135 | static void inc_rec() { ++gRecCounter; printf("----- inc rec %d\n", gRecCounter); } |
| 136 | static void dec_rec() { --gRecCounter; printf("----- dec rec %d\n", gRecCounter); } |
| 137 | |
| 138 | static int gCanvasCounter; |
| 139 | static void inc_canvas() { ++gCanvasCounter; printf("----- inc canvas %d\n", gCanvasCounter); } |
| 140 | static void dec_canvas() { --gCanvasCounter; printf("----- dec canvas %d\n", gCanvasCounter); } |
| 141 | #else |
| 142 | #define inc_layer() |
| 143 | #define dec_layer() |
| 144 | #define inc_rec() |
| 145 | #define dec_rec() |
| 146 | #define inc_canvas() |
| 147 | #define dec_canvas() |
| 148 | #endif |
| 149 | |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 150 | typedef SkTLazy<SkPaint> SkLazyPaint; |
| 151 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 152 | void SkCanvas::predrawNotify(bool willOverwritesEntireSurface) { |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 153 | if (fSurfaceBase) { |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 154 | fSurfaceBase->aboutToDraw(willOverwritesEntireSurface |
| 155 | ? SkSurface::kDiscard_ContentChangeMode |
| 156 | : SkSurface::kRetain_ContentChangeMode); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | void SkCanvas::predrawNotify(const SkRect* rect, const SkPaint* paint, |
| 161 | ShaderOverrideOpacity overrideOpacity) { |
| 162 | if (fSurfaceBase) { |
| 163 | SkSurface::ContentChangeMode mode = SkSurface::kRetain_ContentChangeMode; |
| 164 | // Since willOverwriteAllPixels() may not be complete free to call, we only do so if |
| 165 | // there is an outstanding snapshot, since w/o that, there will be no copy-on-write |
| 166 | // and therefore we don't care which mode we're in. |
| 167 | // |
| 168 | if (fSurfaceBase->outstandingImageSnapshot()) { |
| 169 | if (this->wouldOverwriteEntireSurface(rect, paint, overrideOpacity)) { |
| 170 | mode = SkSurface::kDiscard_ContentChangeMode; |
| 171 | } |
| 172 | } |
| 173 | fSurfaceBase->aboutToDraw(mode); |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 177 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 178 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 179 | /* This is the record we keep for each SkBaseDevice that the user installs. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | The clip/matrix/proc are fields that reflect the top of the save/restore |
| 181 | stack. Whenever the canvas changes, it marks a dirty flag, and then before |
| 182 | these are used (assuming we're not on a layer) we rebuild these cache |
| 183 | values: they reflect the top of the save stack, but translated and clipped |
| 184 | by the device's XY offset and bitmap-bounds. |
| 185 | */ |
| 186 | struct DeviceCM { |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 187 | DeviceCM* fNext; |
| 188 | sk_sp<SkBaseDevice> fDevice; |
| 189 | SkRasterClip fClip; |
| 190 | std::unique_ptr<const SkPaint> fPaint; // may be null (in the future) |
| 191 | SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 192 | sk_sp<SkImage> fClipImage; |
| 193 | SkMatrix fClipMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 194 | |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 195 | DeviceCM(sk_sp<SkBaseDevice> device, const SkPaint* paint, const SkMatrix& stashed, |
Mike Klein | b34ab04 | 2017-05-01 21:34:14 +0000 | [diff] [blame] | 196 | const SkImage* clipImage, const SkMatrix* clipMatrix) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 197 | : fNext(nullptr) |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 198 | , fDevice(std::move(device)) |
| 199 | , fPaint(paint ? skstd::make_unique<SkPaint>(*paint) : nullptr) |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 200 | , fStashedMatrix(stashed) |
Mike Klein | b34ab04 | 2017-05-01 21:34:14 +0000 | [diff] [blame] | 201 | , fClipImage(sk_ref_sp(const_cast<SkImage*>(clipImage))) |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 202 | , fClipMatrix(clipMatrix ? *clipMatrix : SkMatrix::I()) |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 203 | {} |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 204 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 205 | void reset(const SkIRect& bounds) { |
| 206 | SkASSERT(!fPaint); |
| 207 | SkASSERT(!fNext); |
| 208 | SkASSERT(fDevice); |
| 209 | fClip.setRect(bounds); |
| 210 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | /* This is the record we keep for each save/restore level in the stack. |
| 214 | Since a level optionally copies the matrix and/or stack, we have pointers |
| 215 | for these fields. If the value is copied for this level, the copy is |
| 216 | stored in the ...Storage field, and the pointer points to that. If the |
| 217 | value is not copied for this level, we ignore ...Storage, and just point |
| 218 | at the corresponding value in the previous level in the stack. |
| 219 | */ |
| 220 | class SkCanvas::MCRec { |
| 221 | public: |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 222 | SkDrawFilter* fFilter; // the current filter (or null) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 223 | DeviceCM* fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 224 | /* If there are any layers in the stack, this points to the top-most |
| 225 | one that is at or below this level in the stack (so we know what |
| 226 | bitmap/device to draw into from this level. This value is NOT |
| 227 | reference counted, since the real owner is either our fLayer field, |
| 228 | or a previous one in a lower level.) |
| 229 | */ |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 230 | DeviceCM* fTopLayer; |
| 231 | SkConservativeClip fRasterClip; |
| 232 | SkMatrix fMatrix; |
| 233 | int fDeferredSaveCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 234 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 235 | MCRec() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 236 | fFilter = nullptr; |
| 237 | fLayer = nullptr; |
| 238 | fTopLayer = nullptr; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 239 | fMatrix.reset(); |
| 240 | fDeferredSaveCount = 0; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 241 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 242 | // don't bother initializing fNext |
| 243 | inc_rec(); |
| 244 | } |
Jim Van Verth | 343fe49 | 2017-05-02 16:49:24 -0400 | [diff] [blame] | 245 | MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 246 | fFilter = SkSafeRef(prev.fFilter); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 247 | fLayer = nullptr; |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 248 | fTopLayer = prev.fTopLayer; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 249 | fDeferredSaveCount = 0; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 250 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 251 | // don't bother initializing fNext |
| 252 | inc_rec(); |
| 253 | } |
| 254 | ~MCRec() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 255 | SkSafeUnref(fFilter); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 256 | delete fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 257 | dec_rec(); |
| 258 | } |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 259 | |
| 260 | void reset(const SkIRect& bounds) { |
| 261 | SkASSERT(fLayer); |
| 262 | SkASSERT(fDeferredSaveCount == 0); |
| 263 | |
| 264 | fMatrix.reset(); |
| 265 | fRasterClip.setRect(bounds); |
| 266 | fLayer->reset(bounds); |
| 267 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 268 | }; |
| 269 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 270 | class SkDrawIter { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 271 | public: |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 272 | SkDrawIter(SkCanvas* canvas) |
| 273 | : fDevice(nullptr), fCurrLayer(canvas->fMCRec->fTopLayer), fPaint(nullptr) |
| 274 | {} |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 275 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 276 | bool next() { |
reed@google.com | f68c5e2 | 2012-02-24 16:38:58 +0000 | [diff] [blame] | 277 | const DeviceCM* rec = fCurrLayer; |
| 278 | if (rec && rec->fDevice) { |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 279 | fDevice = rec->fDevice.get(); |
| 280 | fPaint = rec->fPaint.get(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | fCurrLayer = rec->fNext; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 282 | // fCurrLayer may be nullptr now |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 283 | return true; |
| 284 | } |
| 285 | return false; |
| 286 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 287 | |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 288 | int getX() const { return fDevice->getOrigin().x(); } |
| 289 | int getY() const { return fDevice->getOrigin().y(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 290 | const SkPaint* getPaint() const { return fPaint; } |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 291 | |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 292 | SkBaseDevice* fDevice; |
| 293 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 294 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 295 | const DeviceCM* fCurrLayer; |
| 296 | const SkPaint* fPaint; // May be null. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 299 | #define FOR_EACH_TOP_DEVICE( code ) \ |
| 300 | do { \ |
| 301 | DeviceCM* layer = fMCRec->fTopLayer; \ |
| 302 | while (layer) { \ |
| 303 | SkBaseDevice* device = layer->fDevice.get(); \ |
| 304 | if (device) { \ |
| 305 | code; \ |
| 306 | } \ |
| 307 | layer = layer->fNext; \ |
| 308 | } \ |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 309 | } while (0) |
| 310 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 311 | ///////////////////////////////////////////////////////////////////////////// |
| 312 | |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 313 | static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { |
| 314 | return lazy->isValid() ? lazy->get() : lazy->set(orig); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * If the paint has an imagefilter, but it can be simplified to just a colorfilter, return that |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 319 | * colorfilter, else return nullptr. |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 320 | */ |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 321 | static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) { |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 322 | SkImageFilter* imgf = paint.getImageFilter(); |
| 323 | if (!imgf) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 324 | return nullptr; |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 325 | } |
| 326 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 327 | SkColorFilter* imgCFPtr; |
| 328 | if (!imgf->asAColorFilter(&imgCFPtr)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 329 | return nullptr; |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 330 | } |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 331 | sk_sp<SkColorFilter> imgCF(imgCFPtr); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 332 | |
| 333 | SkColorFilter* paintCF = paint.getColorFilter(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 334 | if (nullptr == paintCF) { |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 335 | // there is no existing paint colorfilter, so we can just return the imagefilter's |
| 336 | return imgCF; |
| 337 | } |
| 338 | |
| 339 | // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF) |
| 340 | // and we need to combine them into a single colorfilter. |
Mike Reed | 19d7bd6 | 2018-02-19 14:10:57 -0500 | [diff] [blame] | 341 | return imgCF->makeComposed(sk_ref_sp(paintCF)); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 342 | } |
| 343 | |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 344 | /** |
| 345 | * There are many bounds in skia. A circle's bounds is just its center extended by its radius. |
| 346 | * However, if we stroke a circle, then the "bounds" of that is larger, since it will now draw |
| 347 | * outside of its raw-bounds by 1/2 the stroke width. SkPaint has lots of optional |
| 348 | * effects/attributes that can modify the effective bounds of a given primitive -- maskfilters, |
| 349 | * patheffects, stroking, etc. This function takes a raw bounds and a paint, and returns the |
| 350 | * conservative "effective" bounds based on the settings in the paint... with one exception. This |
| 351 | * function does *not* look at the imagefilter, which can also modify the effective bounds. It is |
| 352 | * deliberately ignored. |
| 353 | */ |
| 354 | static const SkRect& apply_paint_to_bounds_sans_imagefilter(const SkPaint& paint, |
| 355 | const SkRect& rawBounds, |
| 356 | SkRect* storage) { |
| 357 | SkPaint tmpUnfiltered(paint); |
| 358 | tmpUnfiltered.setImageFilter(nullptr); |
| 359 | if (tmpUnfiltered.canComputeFastBounds()) { |
| 360 | return tmpUnfiltered.computeFastBounds(rawBounds, storage); |
| 361 | } else { |
| 362 | return rawBounds; |
| 363 | } |
| 364 | } |
| 365 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 366 | class AutoDrawLooper { |
| 367 | public: |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 368 | // "rawBounds" is the original bounds of the primitive about to be drawn, unmodified by the |
| 369 | // paint. It's used to determine the size of the offscreen layer for filters. |
| 370 | // If null, the clip will be used instead. |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 371 | AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, bool skipLayerForImageFilter = false, |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 372 | const SkRect* rawBounds = nullptr) : fOrigPaint(paint) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 373 | fCanvas = canvas; |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 374 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 375 | fFilter = canvas->getDrawFilter(); |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 376 | #else |
| 377 | fFilter = nullptr; |
| 378 | #endif |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 379 | fPaint = &fOrigPaint; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 380 | fSaveCount = canvas->getSaveCount(); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 381 | fTempLayerForImageFilter = false; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 382 | fDone = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 383 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 384 | auto simplifiedCF = image_to_color_filter(fOrigPaint); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 385 | if (simplifiedCF) { |
| 386 | SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 387 | paint->setColorFilter(std::move(simplifiedCF)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 388 | paint->setImageFilter(nullptr); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 389 | fPaint = paint; |
| 390 | } |
| 391 | |
| 392 | if (!skipLayerForImageFilter && fPaint->getImageFilter()) { |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 393 | /** |
| 394 | * We implement ImageFilters for a given draw by creating a layer, then applying the |
| 395 | * imagefilter to the pixels of that layer (its backing surface/image), and then |
| 396 | * we call restore() to xfer that layer to the main canvas. |
| 397 | * |
| 398 | * 1. SaveLayer (with a paint containing the current imagefilter and xfermode) |
| 399 | * 2. Generate the src pixels: |
| 400 | * Remove the imagefilter and the xfermode from the paint that we (AutoDrawLooper) |
| 401 | * return (fPaint). We then draw the primitive (using srcover) into a cleared |
| 402 | * buffer/surface. |
| 403 | * 3. Restore the layer created in #1 |
| 404 | * The imagefilter is passed the buffer/surface from the layer (now filled with the |
| 405 | * src pixels of the primitive). It returns a new "filtered" buffer, which we |
| 406 | * draw onto the previous layer using the xfermode from the original paint. |
| 407 | */ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 408 | SkPaint tmp; |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 409 | tmp.setImageFilter(fPaint->refImageFilter()); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 410 | tmp.setBlendMode(fPaint->getBlendMode()); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 411 | SkRect storage; |
| 412 | if (rawBounds) { |
| 413 | // Make rawBounds include all paint outsets except for those due to image filters. |
| 414 | rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *rawBounds, &storage); |
| 415 | } |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 416 | (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &tmp), |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 417 | SkCanvas::kFullLayer_SaveLayerStrategy); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 418 | fTempLayerForImageFilter = true; |
| 419 | // we remove the imagefilter/xfermode inside doNext() |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 420 | } |
| 421 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 422 | if (SkDrawLooper* looper = paint.getLooper()) { |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 423 | fLooperContext = looper->makeContext(canvas, &fAlloc); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 424 | fIsSimple = false; |
| 425 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 426 | fLooperContext = nullptr; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 427 | // can we be marked as simple? |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 428 | fIsSimple = !fFilter && !fTempLayerForImageFilter; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 431 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 432 | ~AutoDrawLooper() { |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 433 | if (fTempLayerForImageFilter) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 434 | fCanvas->internalRestore(); |
| 435 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 436 | SkASSERT(fCanvas->getSaveCount() == fSaveCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 437 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 438 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 439 | const SkPaint& paint() const { |
| 440 | SkASSERT(fPaint); |
Mike Reed | dd8ae14 | 2018-04-12 11:05:01 -0400 | [diff] [blame] | 441 | SkASSERT(fPaint->getDrawLooper() == nullptr); // we should have cleared this |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 442 | return *fPaint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 443 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 444 | |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 445 | bool next(SkDrawFilter::Type drawType) { |
| 446 | if (fDone) { |
| 447 | return false; |
| 448 | } else if (fIsSimple) { |
| 449 | fDone = true; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 450 | return !fPaint->nothingToDraw(); |
| 451 | } else { |
| 452 | return this->doNext(drawType); |
| 453 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 454 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 455 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 456 | private: |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 457 | SkLazyPaint fLazyPaintInit; // base paint storage in case we need to modify it |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 458 | SkLazyPaint fLazyPaintPerLooper; // per-draw-looper storage, so the looper can modify it |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 459 | SkCanvas* fCanvas; |
| 460 | const SkPaint& fOrigPaint; |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 461 | SkDrawFilter* fFilter; |
| 462 | const SkPaint* fPaint; |
| 463 | int fSaveCount; |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 464 | bool fTempLayerForImageFilter; |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 465 | bool fDone; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 466 | bool fIsSimple; |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 467 | SkDrawLooper::Context* fLooperContext; |
Florin Malita | 14a6430 | 2017-05-24 14:53:44 -0400 | [diff] [blame] | 468 | SkSTArenaAlloc<48> fAlloc; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 469 | |
| 470 | bool doNext(SkDrawFilter::Type drawType); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 471 | }; |
| 472 | |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 473 | bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 474 | fPaint = nullptr; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 475 | SkASSERT(!fIsSimple); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 476 | SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 477 | |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 478 | SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? |
| 479 | *fLazyPaintInit.get() : fOrigPaint); |
Mike Reed | dd8ae14 | 2018-04-12 11:05:01 -0400 | [diff] [blame] | 480 | // never want our downstream clients (i.e. devices) to see loopers |
| 481 | paint->setDrawLooper(nullptr); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 482 | |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 483 | if (fTempLayerForImageFilter) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 484 | paint->setImageFilter(nullptr); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 485 | paint->setBlendMode(SkBlendMode::kSrcOver); |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 486 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 487 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 488 | if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 489 | fDone = true; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 490 | return false; |
| 491 | } |
| 492 | if (fFilter) { |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 493 | if (!fFilter->filter(paint, drawType)) { |
| 494 | fDone = true; |
Mike Reed | 59af19f | 2018-04-12 17:26:40 -0400 | [diff] [blame] | 495 | return false; // can we really do this, if we haven't finished fLooperContext? |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 496 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 497 | if (nullptr == fLooperContext) { |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 498 | // no looper means we only draw once |
| 499 | fDone = true; |
| 500 | } |
| 501 | } |
| 502 | fPaint = paint; |
| 503 | |
| 504 | // if we only came in here for the imagefilter, mark us as done |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 505 | if (!fLooperContext && !fFilter) { |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 506 | fDone = true; |
reed@google.com | 632e1a2 | 2011-10-06 12:37:00 +0000 | [diff] [blame] | 507 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 508 | return true; |
| 509 | } |
| 510 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 511 | ////////// macros to place around the internal draw calls ////////////////// |
| 512 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 513 | #define LOOPER_BEGIN_DRAWBITMAP(paint, skipLayerForFilter, bounds) \ |
| 514 | this->predrawNotify(); \ |
| 515 | AutoDrawLooper looper(this, paint, skipLayerForFilter, bounds); \ |
| 516 | while (looper.next(SkDrawFilter::kBitmap_Type)) { \ |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 517 | SkDrawIter iter(this); |
| 518 | |
| 519 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 520 | #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 521 | this->predrawNotify(); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 522 | AutoDrawLooper looper(this, paint, true); \ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 523 | while (looper.next(type)) { \ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 524 | SkDrawIter iter(this); |
| 525 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 526 | #define LOOPER_BEGIN(paint, type, bounds) \ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 527 | this->predrawNotify(); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 528 | AutoDrawLooper looper(this, paint, false, bounds); \ |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 529 | while (looper.next(type)) { \ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 530 | SkDrawIter iter(this); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 531 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 532 | #define LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, type, bounds, auxOpaque) \ |
| 533 | this->predrawNotify(bounds, &paint, auxOpaque); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 534 | AutoDrawLooper looper(this, paint, false, bounds); \ |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 535 | while (looper.next(type)) { \ |
| 536 | SkDrawIter iter(this); |
| 537 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 538 | #define LOOPER_END } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 539 | |
| 540 | //////////////////////////////////////////////////////////////////////////// |
| 541 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 542 | static inline SkRect qr_clip_bounds(const SkIRect& bounds) { |
| 543 | if (bounds.isEmpty()) { |
| 544 | return SkRect::MakeEmpty(); |
| 545 | } |
| 546 | |
| 547 | // Expand bounds out by 1 in case we are anti-aliasing. We store the |
| 548 | // bounds as floats to enable a faster quick reject implementation. |
| 549 | SkRect dst; |
| 550 | SkNx_cast<float>(Sk4i::Load(&bounds.fLeft) + Sk4i(-1,-1,1,1)).store(&dst.fLeft); |
| 551 | return dst; |
| 552 | } |
| 553 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 554 | void SkCanvas::resetForNextPicture(const SkIRect& bounds) { |
| 555 | this->restoreToCount(1); |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 556 | fMCRec->reset(bounds); |
| 557 | |
| 558 | // We're peering through a lot of structs here. Only at this scope do we |
Mike Reed | 139e5e0 | 2017-03-08 11:29:33 -0500 | [diff] [blame] | 559 | // know that the device is a SkNoPixelsDevice. |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 560 | static_cast<SkNoPixelsDevice*>(fMCRec->fLayer->fDevice.get())->resetForNextPicture(bounds); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 561 | fDeviceClipBounds = qr_clip_bounds(bounds); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 562 | fIsScaleTranslate = true; |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 565 | void SkCanvas::init(sk_sp<SkBaseDevice> device, InitFlags flags) { |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 566 | if (device && device->forceConservativeRasterClip()) { |
| 567 | flags = InitFlags(flags | kConservativeRasterClip_InitFlag); |
| 568 | } |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 569 | |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 570 | fAllowSimplifyClip = false; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 571 | fSaveCount = 1; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 572 | fMetaData = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 573 | |
| 574 | fMCRec = (MCRec*)fMCStack.push_back(); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 575 | new (fMCRec) MCRec; |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 576 | fMCRec->fRasterClip.setDeviceClipRestriction(&fClipRestrictionRect); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 577 | fIsScaleTranslate = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 578 | |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 579 | SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); |
| 580 | fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 581 | new (fDeviceCMStorage) DeviceCM(device, nullptr, fMCRec->fMatrix, nullptr, nullptr); |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 582 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 583 | fMCRec->fTopLayer = fMCRec->fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 584 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 585 | fSurfaceBase = nullptr; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 586 | |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 587 | if (device) { |
robertphillips | efbffed | 2015-06-22 12:06:08 -0700 | [diff] [blame] | 588 | // The root device and the canvas should always have the same pixel geometry |
| 589 | SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry()); |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 590 | fMCRec->fRasterClip.setRect(device->getGlobalBounds()); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 591 | fDeviceClipBounds = qr_clip_bounds(device->getGlobalBounds()); |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 592 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 593 | device->androidFramework_setDeviceClipRestriction(&fClipRestrictionRect); |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 594 | } |
Herb Derby | 4ffa027 | 2018-06-04 15:49:15 -0400 | [diff] [blame] | 595 | |
Herb Derby | 59d997a | 2018-06-07 12:44:09 -0400 | [diff] [blame] | 596 | fScratchGlyphRunBuilder = skstd::make_unique<SkGlyphRunBuilder>(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 597 | } |
| 598 | |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 599 | SkCanvas::SkCanvas() |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 600 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 601 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 602 | { |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 603 | inc_canvas(); |
skia.committer@gmail.com | ba12448 | 2014-02-01 03:01:57 +0000 | [diff] [blame] | 604 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 605 | this->init(nullptr, kDefault_InitFlags); |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 606 | } |
| 607 | |
reed | 96a857e | 2015-01-25 10:33:58 -0800 | [diff] [blame] | 608 | SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 609 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 96a857e | 2015-01-25 10:33:58 -0800 | [diff] [blame] | 610 | , fProps(SkSurfacePropsCopyOrDefault(props)) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 611 | { |
| 612 | inc_canvas(); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 613 | this->init(sk_make_sp<SkNoPixelsDevice>( |
| 614 | SkIRect::MakeWH(SkTMax(width, 0), SkTMax(height, 0)), fProps), kDefault_InitFlags); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 615 | } |
skia.committer@gmail.com | ba12448 | 2014-02-01 03:01:57 +0000 | [diff] [blame] | 616 | |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 617 | SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 618 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 619 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 620 | { |
| 621 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 622 | |
Mike Reed | 566e53c | 2017-03-10 10:49:45 -0500 | [diff] [blame] | 623 | SkIRect r = bounds.isEmpty() ? SkIRect::MakeEmpty() : bounds; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 624 | this->init(sk_make_sp<SkNoPixelsDevice>(r, fProps), flags); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 627 | SkCanvas::SkCanvas(sk_sp<SkBaseDevice> device) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 628 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
robertphillips | 7b05ff1 | 2015-06-19 14:14:54 -0700 | [diff] [blame] | 629 | , fProps(device->surfaceProps()) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 630 | { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 631 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 632 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 633 | this->init(device, kDefault_InitFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 636 | SkCanvas::SkCanvas(sk_sp<SkBaseDevice> device, InitFlags flags) |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 637 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
robertphillips | 7b05ff1 | 2015-06-19 14:14:54 -0700 | [diff] [blame] | 638 | , fProps(device->surfaceProps()) |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 639 | { |
| 640 | inc_canvas(); |
| 641 | |
| 642 | this->init(device, flags); |
| 643 | } |
| 644 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 645 | SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame] | 646 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 647 | , fProps(props) |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame] | 648 | { |
| 649 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 650 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 651 | sk_sp<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps, nullptr, nullptr)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 652 | this->init(device, kDefault_InitFlags); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 653 | } |
reed | 29c857d | 2014-09-21 10:25:07 -0700 | [diff] [blame] | 654 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 655 | SkCanvas::SkCanvas(const SkBitmap& bitmap, std::unique_ptr<SkRasterHandleAllocator> alloc, |
| 656 | SkRasterHandleAllocator::Handle hndl) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 657 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 658 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 659 | , fAllocator(std::move(alloc)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 660 | { |
| 661 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 662 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 663 | sk_sp<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps, hndl, nullptr)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 664 | this->init(device, kDefault_InitFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 667 | SkCanvas::SkCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap, nullptr, nullptr) {} |
| 668 | |
Matt Sarett | 31f99ce | 2017-04-11 08:46:01 -0400 | [diff] [blame] | 669 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 670 | SkCanvas::SkCanvas(const SkBitmap& bitmap, ColorBehavior) |
| 671 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 672 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
| 673 | , fAllocator(nullptr) |
| 674 | { |
| 675 | inc_canvas(); |
| 676 | |
| 677 | SkBitmap tmp(bitmap); |
| 678 | *const_cast<SkImageInfo*>(&tmp.info()) = tmp.info().makeColorSpace(nullptr); |
Mike Reed | c247a4e | 2018-04-25 15:40:09 -0400 | [diff] [blame] | 679 | sk_sp<SkBaseDevice> device(new SkBitmapDevice(tmp, fProps, nullptr, nullptr)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 680 | this->init(device, kDefault_InitFlags); |
Matt Sarett | 31f99ce | 2017-04-11 08:46:01 -0400 | [diff] [blame] | 681 | } |
| 682 | #endif |
| 683 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 684 | SkCanvas::~SkCanvas() { |
| 685 | // free up the contents of our deque |
| 686 | this->restoreToCount(1); // restore everything but the last |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 687 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 688 | this->internalRestore(); // restore the last, since we're going away |
| 689 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 690 | delete fMetaData; |
vandebo@chromium.org | b70ae31 | 2010-10-15 18:58:19 +0000 | [diff] [blame] | 691 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 692 | dec_canvas(); |
| 693 | } |
| 694 | |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 695 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 696 | SkDrawFilter* SkCanvas::getDrawFilter() const { |
| 697 | return fMCRec->fFilter; |
| 698 | } |
| 699 | |
| 700 | SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 701 | this->checkForDeferredSave(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 702 | SkRefCnt_SafeAssign(fMCRec->fFilter, filter); |
| 703 | return filter; |
| 704 | } |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 705 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 706 | |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 707 | SkMetaData& SkCanvas::getMetaData() { |
| 708 | // metadata users are rare, so we lazily allocate it. If that changes we |
| 709 | // can decide to just make it a field in the device (rather than a ptr) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 710 | if (nullptr == fMetaData) { |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 711 | fMetaData = new SkMetaData; |
| 712 | } |
| 713 | return *fMetaData; |
| 714 | } |
| 715 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 716 | /////////////////////////////////////////////////////////////////////////////// |
| 717 | |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 718 | void SkCanvas::flush() { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 719 | this->onFlush(); |
| 720 | } |
| 721 | |
| 722 | void SkCanvas::onFlush() { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 723 | SkBaseDevice* device = this->getDevice(); |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 724 | if (device) { |
| 725 | device->flush(); |
| 726 | } |
| 727 | } |
| 728 | |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 729 | SkISize SkCanvas::getBaseLayerSize() const { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 730 | SkBaseDevice* d = this->getDevice(); |
reed@google.com | 210ce00 | 2011-11-01 14:24:23 +0000 | [diff] [blame] | 731 | return d ? SkISize::Make(d->width(), d->height()) : SkISize::Make(0, 0); |
| 732 | } |
| 733 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 734 | SkIRect SkCanvas::getTopLayerBounds() const { |
| 735 | SkBaseDevice* d = this->getTopDevice(); |
| 736 | if (!d) { |
| 737 | return SkIRect::MakeEmpty(); |
| 738 | } |
| 739 | return SkIRect::MakeXYWH(d->getOrigin().x(), d->getOrigin().y(), d->width(), d->height()); |
| 740 | } |
| 741 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 742 | SkBaseDevice* SkCanvas::getDevice() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 743 | // return root device |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 744 | MCRec* rec = (MCRec*) fMCStack.front(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 745 | SkASSERT(rec && rec->fLayer); |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 746 | return rec->fLayer->fDevice.get(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Florin Malita | 0ed3b64 | 2017-01-13 16:56:38 +0000 | [diff] [blame] | 749 | SkBaseDevice* SkCanvas::getTopDevice() const { |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 750 | return fMCRec->fTopLayer->fDevice.get(); |
reed@google.com | 9266fed | 2011-03-30 00:18:03 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 753 | bool SkCanvas::readPixels(const SkPixmap& pm, int x, int y) { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 754 | SkBaseDevice* device = this->getDevice(); |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 755 | return device && pm.addr() && device->readPixels(pm, x, y); |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 758 | bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) { |
| 759 | return this->readPixels({ dstInfo, dstP, rowBytes}, x, y); |
Mike Reed | 12e946b | 2017-04-17 10:53:29 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | bool SkCanvas::readPixels(const SkBitmap& bm, int x, int y) { |
| 763 | SkPixmap pm; |
| 764 | return bm.peekPixels(&pm) && this->readPixels(pm, x, y); |
| 765 | } |
| 766 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 767 | bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { |
Mike Reed | 4edb5d2 | 2017-04-17 11:02:51 -0400 | [diff] [blame] | 768 | SkPixmap pm; |
| 769 | if (bitmap.peekPixels(&pm)) { |
reed | cf01e31 | 2015-05-23 19:14:51 -0700 | [diff] [blame] | 770 | return this->writePixels(pm.info(), pm.addr(), pm.rowBytes(), x, y); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 771 | } |
| 772 | return false; |
| 773 | } |
| 774 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 775 | bool SkCanvas::writePixels(const SkImageInfo& srcInfo, const void* pixels, size_t rowBytes, |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 776 | int x, int y) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 777 | SkBaseDevice* device = this->getDevice(); |
| 778 | if (!device) { |
| 779 | return false; |
| 780 | } |
| 781 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 782 | // This check gives us an early out and prevents generation ID churn on the surface. |
| 783 | // This is purely optional: it is a subset of the checks performed by SkWritePixelsRec. |
| 784 | SkIRect srcRect = SkIRect::MakeXYWH(x, y, srcInfo.width(), srcInfo.height()); |
| 785 | if (!srcRect.intersect(0, 0, device->width(), device->height())) { |
| 786 | return false; |
Matt Sarett | 26ecfe0 | 2017-01-23 15:51:01 +0000 | [diff] [blame] | 787 | } |
Matt Sarett | 26ecfe0 | 2017-01-23 15:51:01 +0000 | [diff] [blame] | 788 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 789 | // Tell our owning surface to bump its generation ID. |
| 790 | const bool completeOverwrite = |
| 791 | srcRect.size() == SkISize::Make(device->width(), device->height()); |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 792 | this->predrawNotify(completeOverwrite); |
reed | 4af35f3 | 2014-06-27 17:47:49 -0700 | [diff] [blame] | 793 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 794 | // This can still fail, most notably in the case of a invalid color type or alpha type |
| 795 | // conversion. We could pull those checks into this function and avoid the unnecessary |
| 796 | // generation ID bump. But then we would be performing those checks twice, since they |
| 797 | // are also necessary at the bitmap/pixmap entry points. |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 798 | return device->writePixels({srcInfo, pixels, rowBytes}, x, y); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 799 | } |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 800 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 801 | ////////////////////////////////////////////////////////////////////////////// |
| 802 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 803 | void SkCanvas::checkForDeferredSave() { |
| 804 | if (fMCRec->fDeferredSaveCount > 0) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 805 | this->doSave(); |
| 806 | } |
| 807 | } |
| 808 | |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 809 | int SkCanvas::getSaveCount() const { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 810 | #ifdef SK_DEBUG |
| 811 | int count = 0; |
| 812 | SkDeque::Iter iter(fMCStack, SkDeque::Iter::kFront_IterStart); |
| 813 | for (;;) { |
| 814 | const MCRec* rec = (const MCRec*)iter.next(); |
| 815 | if (!rec) { |
| 816 | break; |
| 817 | } |
| 818 | count += 1 + rec->fDeferredSaveCount; |
| 819 | } |
| 820 | SkASSERT(count == fSaveCount); |
| 821 | #endif |
| 822 | return fSaveCount; |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | int SkCanvas::save() { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 826 | fSaveCount += 1; |
| 827 | fMCRec->fDeferredSaveCount += 1; |
| 828 | return this->getSaveCount() - 1; // return our prev value |
| 829 | } |
| 830 | |
| 831 | void SkCanvas::doSave() { |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 832 | this->willSave(); |
fmalita | a62d32d | 2015-04-28 08:08:57 -0700 | [diff] [blame] | 833 | |
| 834 | SkASSERT(fMCRec->fDeferredSaveCount > 0); |
| 835 | fMCRec->fDeferredSaveCount -= 1; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 836 | this->internalSave(); |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | void SkCanvas::restore() { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 840 | if (fMCRec->fDeferredSaveCount > 0) { |
| 841 | SkASSERT(fSaveCount > 1); |
| 842 | fSaveCount -= 1; |
| 843 | fMCRec->fDeferredSaveCount -= 1; |
| 844 | } else { |
| 845 | // check for underflow |
| 846 | if (fMCStack.count() > 1) { |
| 847 | this->willRestore(); |
| 848 | SkASSERT(fSaveCount > 1); |
reed | a644116 | 2015-03-26 13:40:09 -0700 | [diff] [blame] | 849 | fSaveCount -= 1; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 850 | this->internalRestore(); |
| 851 | this->didRestore(); |
| 852 | } |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
| 856 | void SkCanvas::restoreToCount(int count) { |
| 857 | // sanity check |
| 858 | if (count < 1) { |
| 859 | count = 1; |
| 860 | } |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 861 | |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 862 | int n = this->getSaveCount() - count; |
| 863 | for (int i = 0; i < n; ++i) { |
| 864 | this->restore(); |
| 865 | } |
| 866 | } |
| 867 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 868 | void SkCanvas::internalSave() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 869 | MCRec* newTop = (MCRec*)fMCStack.push_back(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 870 | new (newTop) MCRec(*fMCRec); // balanced in restore() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 871 | fMCRec = newTop; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 872 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 873 | FOR_EACH_TOP_DEVICE(device->save()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 874 | } |
| 875 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 876 | bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) { |
Cary Clark | 7eddfb8 | 2018-03-13 14:41:10 -0400 | [diff] [blame] | 877 | return !(saveLayerFlags & SkCanvasPriv::kDontClipToLayer_SaveLayerFlag); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 878 | } |
| 879 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 880 | bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlags, |
reed | 9b3aa54 | 2015-03-11 08:47:12 -0700 | [diff] [blame] | 881 | SkIRect* intersection, const SkImageFilter* imageFilter) { |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 882 | SkIRect clipBounds = this->getDeviceClipBounds(); |
| 883 | if (clipBounds.isEmpty()) { |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 884 | return false; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 885 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 886 | |
reed | 96e657d | 2015-03-10 17:30:07 -0700 | [diff] [blame] | 887 | const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix() |
| 888 | |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 889 | if (imageFilter && bounds && !imageFilter->canComputeFastBounds()) { |
| 890 | // If the image filter DAG affects transparent black then we will need to render |
| 891 | // out to the clip bounds |
| 892 | bounds = nullptr; |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 893 | } |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 894 | |
| 895 | SkIRect inputSaveLayerBounds; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 896 | if (bounds) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 897 | SkRect r; |
reed | 96e657d | 2015-03-10 17:30:07 -0700 | [diff] [blame] | 898 | ctm.mapRect(&r, *bounds); |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 899 | r.roundOut(&inputSaveLayerBounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 900 | } else { // no user bounds, so just use the clip |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 901 | inputSaveLayerBounds = clipBounds; |
| 902 | } |
| 903 | |
| 904 | if (imageFilter) { |
| 905 | // expand the clip bounds by the image filter DAG to include extra content that might |
| 906 | // be required by the image filters. |
| 907 | clipBounds = imageFilter->filterBounds(clipBounds, ctm, |
| 908 | SkImageFilter::kReverse_MapDirection, |
| 909 | &inputSaveLayerBounds); |
| 910 | } |
| 911 | |
| 912 | SkIRect clippedSaveLayerBounds; |
| 913 | if (bounds) { |
| 914 | // For better or for worse, user bounds currently act as a hard clip on the layer's |
| 915 | // extent (i.e., they implement the CSS filter-effects 'filter region' feature). |
| 916 | clippedSaveLayerBounds = inputSaveLayerBounds; |
| 917 | } else { |
| 918 | // If there are no user bounds, we don't want to artificially restrict the resulting |
| 919 | // layer bounds, so allow the expanded clip bounds free reign. |
| 920 | clippedSaveLayerBounds = clipBounds; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 921 | } |
Xianzhu Wang | 3b428cb | 2018-01-22 09:51:13 -0800 | [diff] [blame] | 922 | |
| 923 | // early exit if the layer's bounds are clipped out |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 924 | if (!clippedSaveLayerBounds.intersect(clipBounds)) { |
Xianzhu Wang | 3b428cb | 2018-01-22 09:51:13 -0800 | [diff] [blame] | 925 | if (BoundsAffectsClip(saveLayerFlags)) { |
| 926 | fMCRec->fTopLayer->fDevice->clipRegion(SkRegion(), SkClipOp::kIntersect); // empty |
| 927 | fMCRec->fRasterClip.setEmpty(); |
| 928 | fDeviceClipBounds.setEmpty(); |
| 929 | } |
| 930 | return false; |
| 931 | } |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 932 | SkASSERT(!clippedSaveLayerBounds.isEmpty()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 933 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 934 | if (BoundsAffectsClip(saveLayerFlags)) { |
reed | 180aec4 | 2015-03-11 10:39:04 -0700 | [diff] [blame] | 935 | // Simplify the current clips since they will be applied properly during restore() |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 936 | fMCRec->fRasterClip.setRect(clippedSaveLayerBounds); |
| 937 | fDeviceClipBounds = qr_clip_bounds(clippedSaveLayerBounds); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | if (intersection) { |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 941 | *intersection = clippedSaveLayerBounds; |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 942 | } |
Robert Phillips | 1207843 | 2018-05-17 11:17:39 -0400 | [diff] [blame] | 943 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 944 | return true; |
| 945 | } |
| 946 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 947 | int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { |
| 948 | return this->saveLayer(SaveLayerRec(bounds, paint, 0)); |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 949 | } |
| 950 | |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 951 | int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) { |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 952 | return this->saveLayer(SaveLayerRec(bounds, paint, kPreserveLCDText_SaveLayerFlag)); |
| 953 | } |
| 954 | |
Cary Clark | e041e31 | 2018-03-06 13:00:52 -0500 | [diff] [blame] | 955 | int SkCanvas::saveLayer(const SaveLayerRec& rec) { |
| 956 | SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 957 | fSaveCount += 1; |
Cary Clark | e041e31 | 2018-03-06 13:00:52 -0500 | [diff] [blame] | 958 | this->internalSaveLayer(rec, strategy); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 959 | return this->getSaveCount() - 1; |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 960 | } |
| 961 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 962 | void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter, |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 963 | SkBaseDevice* dst, const SkIPoint& dstOrigin, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 964 | const SkMatrix& ctm) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 965 | SkDraw draw; |
| 966 | SkRasterClip rc; |
| 967 | rc.setRect(SkIRect::MakeWH(dst->width(), dst->height())); |
| 968 | if (!dst->accessPixels(&draw.fDst)) { |
| 969 | draw.fDst.reset(dst->imageInfo(), nullptr, 0); |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 970 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 971 | draw.fMatrix = &SkMatrix::I(); |
| 972 | draw.fRC = &rc; |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 973 | |
| 974 | SkPaint p; |
Mike Reed | c61abee | 2017-02-28 17:45:27 -0500 | [diff] [blame] | 975 | if (filter) { |
| 976 | p.setImageFilter(filter->makeWithLocalMatrix(ctm)); |
| 977 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 978 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 979 | int x = src->getOrigin().x() - dstOrigin.x(); |
| 980 | int y = src->getOrigin().y() - dstOrigin.y(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 981 | auto special = src->snapSpecial(); |
| 982 | if (special) { |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 983 | dst->drawSpecial(special.get(), x, y, p, nullptr, SkMatrix::I()); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 984 | } |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 985 | } |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 986 | |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 987 | static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, const SkPaint* paint) { |
Mike Klein | 649fb73 | 2018-02-26 15:09:16 -0500 | [diff] [blame] | 988 | // Need to force L32 for now if we have an image filter. |
| 989 | // If filters ever support other colortypes, e.g. sRGB or F16, we can remove this check. |
| 990 | if (paint && paint->getImageFilter()) { |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 991 | return SkImageInfo::MakeN32Premul(w, h); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 992 | } |
Mike Klein | 649fb73 | 2018-02-26 15:09:16 -0500 | [diff] [blame] | 993 | |
| 994 | SkColorType ct = prev.colorType(); |
| 995 | if (prev.bytesPerPixel() <= 4) { |
| 996 | // "Upgrade" A8, G8, 565, 4444, 1010102, 101010x, and 888x to 8888, |
| 997 | // ensuring plenty of alpha bits for the layer, perhaps losing some color bits in return. |
| 998 | ct = kN32_SkColorType; |
| 999 | } |
| 1000 | return SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType, prev.refColorSpace()); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1003 | void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy strategy) { |
| 1004 | const SkRect* bounds = rec.fBounds; |
| 1005 | const SkPaint* paint = rec.fPaint; |
| 1006 | SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; |
| 1007 | |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1008 | SkLazyPaint lazyP; |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 1009 | SkImageFilter* imageFilter = paint ? paint->getImageFilter() : nullptr; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1010 | SkMatrix stashedMatrix = fMCRec->fMatrix; |
Robert Phillips | 3d0e850 | 2018-04-20 10:27:27 -0400 | [diff] [blame] | 1011 | MCRec* modifiedRec = nullptr; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1012 | SkMatrix remainder; |
| 1013 | SkSize scale; |
| 1014 | /* |
| 1015 | * ImageFilters (so far) do not correctly handle matrices (CTM) that contain rotation/skew/etc. |
| 1016 | * but they do handle scaling. To accommodate this, we do the following: |
| 1017 | * |
| 1018 | * 1. Stash off the current CTM |
| 1019 | * 2. Decompose the CTM into SCALE and REMAINDER |
| 1020 | * 3. Wack the CTM to be just SCALE, and wrap the imagefilter with a MatrixImageFilter that |
| 1021 | * contains the REMAINDER |
| 1022 | * 4. Proceed as usual, allowing the client to draw into the layer (now with a scale-only CTM) |
| 1023 | * 5. During restore, we process the MatrixImageFilter, which applies REMAINDER to the output |
| 1024 | * of the original imagefilter, and draw that (via drawSprite) |
| 1025 | * 6. Unwack the CTM to its original state (i.e. stashedMatrix) |
| 1026 | * |
| 1027 | * Perhaps in the future we could augment #5 to apply REMAINDER as part of the draw (no longer |
| 1028 | * a sprite operation) to avoid the extra buffer/overhead of MatrixImageFilter. |
| 1029 | */ |
reed | 96a04f3 | 2016-04-25 09:25:15 -0700 | [diff] [blame] | 1030 | if (imageFilter && !stashedMatrix.isScaleTranslate() && !imageFilter->canHandleComplexCTM() && |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1031 | stashedMatrix.decomposeScale(&scale, &remainder)) |
| 1032 | { |
| 1033 | // We will restore the matrix (which we are overwriting here) in restore via fStashedMatrix |
Robert Phillips | 3d0e850 | 2018-04-20 10:27:27 -0400 | [diff] [blame] | 1034 | modifiedRec = fMCRec; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1035 | this->internalSetMatrix(SkMatrix::MakeScale(scale.width(), scale.height())); |
| 1036 | SkPaint* p = lazyP.set(*paint); |
| 1037 | p->setImageFilter(SkImageFilter::MakeMatrixFilter(remainder, |
| 1038 | SkFilterQuality::kLow_SkFilterQuality, |
| 1039 | sk_ref_sp(imageFilter))); |
| 1040 | imageFilter = p->getImageFilter(); |
| 1041 | paint = p; |
| 1042 | } |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1043 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1044 | // do this before we create the layer. We don't call the public save() since |
| 1045 | // that would invoke a possibly overridden virtual |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1046 | this->internalSave(); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1047 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1048 | SkIRect ir; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1049 | if (!this->clipRectBounds(bounds, saveLayerFlags, &ir, imageFilter)) { |
Robert Phillips | 3d0e850 | 2018-04-20 10:27:27 -0400 | [diff] [blame] | 1050 | if (modifiedRec) { |
| 1051 | // In this case there will be no layer in which to stash the matrix so we need to |
| 1052 | // revert the prior MCRec to its earlier state. |
| 1053 | modifiedRec->fMatrix = stashedMatrix; |
| 1054 | } |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1055 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1058 | // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about |
| 1059 | // the clipRectBounds() call above? |
| 1060 | if (kNoLayer_SaveLayerStrategy == strategy) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1061 | return; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 1064 | SkPixelGeometry geo = fProps.pixelGeometry(); |
| 1065 | if (paint) { |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1066 | // TODO: perhaps add a query to filters so we might preserve opaqueness... |
reed | daa57bf | 2015-05-15 10:39:17 -0700 | [diff] [blame] | 1067 | if (paint->getImageFilter() || paint->getColorFilter()) { |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 1068 | geo = kUnknown_SkPixelGeometry; |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1071 | |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1072 | SkBaseDevice* priorDevice = this->getTopDevice(); |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1073 | if (nullptr == priorDevice) { // Do we still need this check??? |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1074 | SkDebugf("Unable to find device for layer."); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1075 | return; |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1076 | } |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1077 | |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1078 | SkImageInfo info = make_layer_info(priorDevice->imageInfo(), ir.width(), ir.height(), paint); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1079 | |
Hal Canary | 704cd32 | 2016-11-07 14:13:52 -0500 | [diff] [blame] | 1080 | sk_sp<SkBaseDevice> newDevice; |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 1081 | { |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1082 | const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() || |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1083 | (saveLayerFlags & kPreserveLCDText_SaveLayerFlag); |
reed | daa57bf | 2015-05-15 10:39:17 -0700 | [diff] [blame] | 1084 | const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 1085 | const bool trackCoverage = |
| 1086 | SkToBool(saveLayerFlags & kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag); |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1087 | const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo, |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 1088 | preserveLCDText, |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1089 | trackCoverage, |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 1090 | fAllocator.get()); |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1091 | newDevice.reset(priorDevice->onCreateDevice(createInfo, paint)); |
| 1092 | if (!newDevice) { |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 1093 | return; |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 1094 | } |
bungeman@google.com | e25c684 | 2011-08-17 14:53:54 +0000 | [diff] [blame] | 1095 | } |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1096 | DeviceCM* layer = new DeviceCM(newDevice, paint, stashedMatrix, rec.fClipMask, rec.fClipMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1097 | |
Mike Reed | b43a3e0 | 2017-02-11 10:18:58 -0500 | [diff] [blame] | 1098 | // only have a "next" if this new layer doesn't affect the clip (rare) |
| 1099 | layer->fNext = BoundsAffectsClip(saveLayerFlags) ? nullptr : fMCRec->fTopLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1100 | fMCRec->fLayer = layer; |
| 1101 | fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1102 | |
Mike Reed | c61abee | 2017-02-28 17:45:27 -0500 | [diff] [blame] | 1103 | if ((rec.fSaveLayerFlags & kInitWithPrevious_SaveLayerFlag) || rec.fBackdrop) { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1104 | DrawDeviceWithFilter(priorDevice, rec.fBackdrop, newDevice.get(), { ir.fLeft, ir.fTop }, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1105 | fMCRec->fMatrix); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1106 | } |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1107 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1108 | newDevice->setOrigin(fMCRec->fMatrix, ir.fLeft, ir.fTop); |
| 1109 | |
| 1110 | newDevice->androidFramework_setDeviceClipRestriction(&fClipRestrictionRect); |
| 1111 | if (layer->fNext) { |
| 1112 | // need to punch a hole in the previous device, so we don't draw there, given that |
| 1113 | // the new top-layer will allow drawing to happen "below" it. |
| 1114 | SkRegion hole(ir); |
| 1115 | do { |
| 1116 | layer = layer->fNext; |
| 1117 | layer->fDevice->clipRegion(hole, SkClipOp::kDifference); |
| 1118 | } while (layer->fNext); |
| 1119 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 1122 | int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 1123 | if (0xFF == alpha) { |
| 1124 | return this->saveLayer(bounds, nullptr); |
| 1125 | } else { |
| 1126 | SkPaint tmpPaint; |
| 1127 | tmpPaint.setAlpha(alpha); |
| 1128 | return this->saveLayer(bounds, &tmpPaint); |
| 1129 | } |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1132 | void SkCanvas::internalRestore() { |
| 1133 | SkASSERT(fMCStack.count() != 0); |
| 1134 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 1135 | // reserve our layer (if any) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1136 | DeviceCM* layer = fMCRec->fLayer; // may be null |
| 1137 | // now detach it from fMCRec so we can pop(). Gets freed after its drawn |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1138 | fMCRec->fLayer = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1139 | |
| 1140 | // now do the normal restore() |
| 1141 | fMCRec->~MCRec(); // balanced in save() |
| 1142 | fMCStack.pop_back(); |
| 1143 | fMCRec = (MCRec*)fMCStack.back(); |
| 1144 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1145 | if (fMCRec) { |
| 1146 | FOR_EACH_TOP_DEVICE(device->restore(fMCRec->fMatrix)); |
| 1147 | } |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1148 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1149 | /* Time to draw the layer's offscreen. We can't call the public drawSprite, |
| 1150 | since if we're being recorded, we don't want to record this (the |
| 1151 | recorder will have already recorded the restore). |
| 1152 | */ |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1153 | if (layer) { |
Mike Reed | b43a3e0 | 2017-02-11 10:18:58 -0500 | [diff] [blame] | 1154 | if (fMCRec) { |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 1155 | const SkIPoint& origin = layer->fDevice->getOrigin(); |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 1156 | this->internalDrawDevice(layer->fDevice.get(), origin.x(), origin.y(), |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1157 | layer->fPaint.get(), |
| 1158 | layer->fClipImage.get(), layer->fClipMatrix); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1159 | // restore what we smashed in internalSaveLayer |
Ben Wagner | 738a256 | 2018-04-23 17:23:30 -0400 | [diff] [blame] | 1160 | this->internalSetMatrix(layer->fStashedMatrix); |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1161 | // reset this, since internalDrawDevice will have set it to true |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1162 | delete layer; |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1163 | } else { |
| 1164 | // we're at the root |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 1165 | SkASSERT(layer == (void*)fDeviceCMStorage); |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1166 | layer->~DeviceCM(); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1167 | // no need to update fMCRec, 'cause we're killing the canvas |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1168 | } |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 1169 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1170 | |
| 1171 | if (fMCRec) { |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1172 | fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1173 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
| 1174 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1177 | sk_sp<SkSurface> SkCanvas::makeSurface(const SkImageInfo& info, const SkSurfaceProps* props) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1178 | if (nullptr == props) { |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1179 | props = &fProps; |
| 1180 | } |
| 1181 | return this->onNewSurface(info, *props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1184 | sk_sp<SkSurface> SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1185 | SkBaseDevice* dev = this->getDevice(); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1186 | return dev ? dev->makeSurface(info, props) : nullptr; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1189 | SkImageInfo SkCanvas::imageInfo() const { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 1190 | return this->onImageInfo(); |
| 1191 | } |
| 1192 | |
| 1193 | SkImageInfo SkCanvas::onImageInfo() const { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1194 | SkBaseDevice* dev = this->getDevice(); |
| 1195 | if (dev) { |
| 1196 | return dev->imageInfo(); |
| 1197 | } else { |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1198 | return SkImageInfo::MakeUnknown(0, 0); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 1202 | bool SkCanvas::getProps(SkSurfaceProps* props) const { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 1203 | return this->onGetProps(props); |
| 1204 | } |
| 1205 | |
| 1206 | bool SkCanvas::onGetProps(SkSurfaceProps* props) const { |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 1207 | SkBaseDevice* dev = this->getDevice(); |
| 1208 | if (dev) { |
| 1209 | if (props) { |
| 1210 | *props = fProps; |
| 1211 | } |
| 1212 | return true; |
| 1213 | } else { |
| 1214 | return false; |
| 1215 | } |
| 1216 | } |
| 1217 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 1218 | bool SkCanvas::peekPixels(SkPixmap* pmap) { |
| 1219 | return this->onPeekPixels(pmap); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1222 | bool SkCanvas::onPeekPixels(SkPixmap* pmap) { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1223 | SkBaseDevice* dev = this->getDevice(); |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1224 | return dev && dev->peekPixels(pmap); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 1227 | void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin) { |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1228 | SkPixmap pmap; |
| 1229 | if (!this->onAccessTopLayerPixels(&pmap)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1230 | return nullptr; |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1231 | } |
| 1232 | if (info) { |
| 1233 | *info = pmap.info(); |
| 1234 | } |
| 1235 | if (rowBytes) { |
| 1236 | *rowBytes = pmap.rowBytes(); |
| 1237 | } |
| 1238 | if (origin) { |
Florin Malita | 0ed3b64 | 2017-01-13 16:56:38 +0000 | [diff] [blame] | 1239 | *origin = this->getTopDevice()->getOrigin(); |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 1240 | } |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1241 | return pmap.writable_addr(); |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1244 | bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1245 | SkBaseDevice* dev = this->getTopDevice(); |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1246 | return dev && dev->accessPixels(pmap); |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1249 | ///////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1250 | |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1251 | void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPaint* paint, |
| 1252 | SkImage* clipImage, const SkMatrix& clipMatrix) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1253 | SkPaint tmp; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1254 | if (nullptr == paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1255 | paint = &tmp; |
| 1256 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1257 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1258 | LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1259 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1260 | while (iter.next()) { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1261 | SkBaseDevice* dstDev = iter.fDevice; |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1262 | paint = &looper.paint(); |
| 1263 | SkImageFilter* filter = paint->getImageFilter(); |
| 1264 | SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1265 | if (filter || clipImage) { |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 1266 | sk_sp<SkSpecialImage> specialImage = srcDev->snapSpecial(); |
| 1267 | if (specialImage) { |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1268 | dstDev->drawSpecial(specialImage.get(), pos.x(), pos.y(), *paint, |
| 1269 | clipImage, clipMatrix); |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 1270 | } |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1271 | } else { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1272 | dstDev->drawDevice(srcDev, pos.x(), pos.y(), *paint); |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1273 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1274 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1275 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 1276 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
reed | 3270467 | 2015-12-16 08:27:10 -0800 | [diff] [blame] | 1279 | ///////////////////////////////////////////////////////////////////////////// |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1280 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1281 | void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
reed | fe69b50 | 2016-09-12 06:31:48 -0700 | [diff] [blame] | 1282 | if (dx || dy) { |
| 1283 | this->checkForDeferredSave(); |
reed | fe69b50 | 2016-09-12 06:31:48 -0700 | [diff] [blame] | 1284 | fMCRec->fMatrix.preTranslate(dx,dy); |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 1285 | |
reed | fe69b50 | 2016-09-12 06:31:48 -0700 | [diff] [blame] | 1286 | // Translate shouldn't affect the is-scale-translateness of the matrix. |
| 1287 | SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate()); |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 1288 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1289 | FOR_EACH_TOP_DEVICE(device->setGlobalCTM(fMCRec->fMatrix)); |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1290 | |
reed | fe69b50 | 2016-09-12 06:31:48 -0700 | [diff] [blame] | 1291 | this->didTranslate(dx,dy); |
| 1292 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1295 | void SkCanvas::scale(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1296 | SkMatrix m; |
| 1297 | m.setScale(sx, sy); |
| 1298 | this->concat(m); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1301 | void SkCanvas::rotate(SkScalar degrees) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1302 | SkMatrix m; |
| 1303 | m.setRotate(degrees); |
| 1304 | this->concat(m); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 1307 | void SkCanvas::rotate(SkScalar degrees, SkScalar px, SkScalar py) { |
| 1308 | SkMatrix m; |
| 1309 | m.setRotate(degrees, px, py); |
| 1310 | this->concat(m); |
| 1311 | } |
| 1312 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1313 | void SkCanvas::skew(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1314 | SkMatrix m; |
| 1315 | m.setSkew(sx, sy); |
| 1316 | this->concat(m); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1319 | void SkCanvas::concat(const SkMatrix& matrix) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1320 | if (matrix.isIdentity()) { |
| 1321 | return; |
| 1322 | } |
| 1323 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1324 | this->checkForDeferredSave(); |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1325 | fMCRec->fMatrix.preConcat(matrix); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1326 | fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1327 | |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1328 | FOR_EACH_TOP_DEVICE(device->setGlobalCTM(fMCRec->fMatrix)); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1329 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1330 | this->didConcat(matrix); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1333 | void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1334 | fMCRec->fMatrix = matrix; |
msarett | 9da5a5a | 2016-08-19 08:38:36 -0700 | [diff] [blame] | 1335 | fIsScaleTranslate = matrix.isScaleTranslate(); |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1336 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1337 | FOR_EACH_TOP_DEVICE(device->setGlobalCTM(fMCRec->fMatrix)); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void SkCanvas::setMatrix(const SkMatrix& matrix) { |
| 1341 | this->checkForDeferredSave(); |
| 1342 | this->internalSetMatrix(matrix); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1343 | this->didSetMatrix(matrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1346 | void SkCanvas::resetMatrix() { |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1347 | this->setMatrix(SkMatrix::I()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | ////////////////////////////////////////////////////////////////////////////// |
| 1351 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1352 | void SkCanvas::clipRect(const SkRect& rect, SkClipOp op, bool doAA) { |
Mike Reed | 9cec1bc | 2018-01-19 12:57:01 -0500 | [diff] [blame] | 1353 | if (!rect.isFinite()) { |
| 1354 | return; |
| 1355 | } |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1356 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1357 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
| 1358 | this->onClipRect(rect, op, edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1361 | void SkCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1362 | const bool isAA = kSoft_ClipEdgeStyle == edgeStyle; |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1363 | |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1364 | FOR_EACH_TOP_DEVICE(device->clipRect(rect, op, isAA)); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1365 | |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1366 | AutoValidateClip avc(this); |
Mike Reed | 20800c8 | 2017-11-15 16:09:04 -0500 | [diff] [blame] | 1367 | fMCRec->fRasterClip.opRect(rect, fMCRec->fMatrix, this->getTopLayerBounds(), (SkRegion::Op)op, |
| 1368 | isAA); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1369 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1372 | void SkCanvas::androidFramework_setDeviceClipRestriction(const SkIRect& rect) { |
| 1373 | fClipRestrictionRect = rect; |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 1374 | if (fClipRestrictionRect.isEmpty()) { |
| 1375 | // we notify the device, but we *dont* resolve deferred saves (since we're just |
| 1376 | // removing the restriction if the rect is empty. how I hate this api. |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 1377 | FOR_EACH_TOP_DEVICE(device->androidFramework_setDeviceClipRestriction(&fClipRestrictionRect)); |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 1378 | } else { |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1379 | this->checkForDeferredSave(); |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 1380 | FOR_EACH_TOP_DEVICE(device->androidFramework_setDeviceClipRestriction(&fClipRestrictionRect)); |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1381 | AutoValidateClip avc(this); |
Mike Reed | 20800c8 | 2017-11-15 16:09:04 -0500 | [diff] [blame] | 1382 | fMCRec->fRasterClip.opIRect(fClipRestrictionRect, SkRegion::kIntersect_Op); |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1383 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
| 1384 | } |
| 1385 | } |
| 1386 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1387 | void SkCanvas::clipRRect(const SkRRect& rrect, SkClipOp op, bool doAA) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1388 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1389 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1390 | if (rrect.isRect()) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1391 | this->onClipRect(rrect.getBounds(), op, edgeStyle); |
| 1392 | } else { |
| 1393 | this->onClipRRect(rrect, op, edgeStyle); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1394 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1395 | } |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1396 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1397 | void SkCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1398 | AutoValidateClip avc(this); |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1399 | |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1400 | bool isAA = kSoft_ClipEdgeStyle == edgeStyle; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 1401 | |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1402 | FOR_EACH_TOP_DEVICE(device->clipRRect(rrect, op, isAA)); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1403 | |
Mike Reed | 20800c8 | 2017-11-15 16:09:04 -0500 | [diff] [blame] | 1404 | fMCRec->fRasterClip.opRRect(rrect, fMCRec->fMatrix, this->getTopLayerBounds(), (SkRegion::Op)op, |
| 1405 | isAA); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1406 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1409 | void SkCanvas::clipPath(const SkPath& path, SkClipOp op, bool doAA) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1410 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1411 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
robertphillips | 39f0538 | 2015-11-24 09:30:12 -0800 | [diff] [blame] | 1412 | |
| 1413 | if (!path.isInverseFillType() && fMCRec->fMatrix.rectStaysRect()) { |
| 1414 | SkRect r; |
| 1415 | if (path.isRect(&r)) { |
| 1416 | this->onClipRect(r, op, edgeStyle); |
| 1417 | return; |
| 1418 | } |
| 1419 | SkRRect rrect; |
| 1420 | if (path.isOval(&r)) { |
| 1421 | rrect.setOval(r); |
| 1422 | this->onClipRRect(rrect, op, edgeStyle); |
| 1423 | return; |
| 1424 | } |
| 1425 | if (path.isRRect(&rrect)) { |
| 1426 | this->onClipRRect(rrect, op, edgeStyle); |
| 1427 | return; |
| 1428 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1429 | } |
robertphillips | 39f0538 | 2015-11-24 09:30:12 -0800 | [diff] [blame] | 1430 | |
| 1431 | this->onClipPath(path, op, edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1434 | void SkCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1435 | AutoValidateClip avc(this); |
| 1436 | |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1437 | bool isAA = kSoft_ClipEdgeStyle == edgeStyle; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 1438 | |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1439 | FOR_EACH_TOP_DEVICE(device->clipPath(path, op, isAA)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1440 | |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1441 | const SkPath* rasterClipPath = &path; |
| 1442 | const SkMatrix* matrix = &fMCRec->fMatrix; |
Mike Reed | 20800c8 | 2017-11-15 16:09:04 -0500 | [diff] [blame] | 1443 | fMCRec->fRasterClip.opPath(*rasterClipPath, *matrix, this->getTopLayerBounds(), |
| 1444 | (SkRegion::Op)op, isAA); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1445 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1448 | void SkCanvas::clipRegion(const SkRegion& rgn, SkClipOp op) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1449 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1450 | this->onClipRegion(rgn, op); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1453 | void SkCanvas::onClipRegion(const SkRegion& rgn, SkClipOp op) { |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 1454 | FOR_EACH_TOP_DEVICE(device->clipRegion(rgn, op)); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1455 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1456 | AutoValidateClip avc(this); |
| 1457 | |
Mike Reed | 20800c8 | 2017-11-15 16:09:04 -0500 | [diff] [blame] | 1458 | fMCRec->fRasterClip.opRegion(rgn, (SkRegion::Op)op); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1459 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1462 | #ifdef SK_DEBUG |
| 1463 | void SkCanvas::validateClip() const { |
| 1464 | // construct clipRgn from the clipstack |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1465 | const SkBaseDevice* device = this->getDevice(); |
djsollen@google.com | ccfee2a | 2012-05-01 16:50:10 +0000 | [diff] [blame] | 1466 | if (!device) { |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1467 | SkASSERT(this->isClipEmpty()); |
djsollen@google.com | ccfee2a | 2012-05-01 16:50:10 +0000 | [diff] [blame] | 1468 | return; |
| 1469 | } |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1470 | } |
| 1471 | #endif |
| 1472 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1473 | bool SkCanvas::androidFramework_isClipAA() const { |
| 1474 | bool containsAA = false; |
| 1475 | |
| 1476 | FOR_EACH_TOP_DEVICE(containsAA |= device->onClipIsAA()); |
| 1477 | |
| 1478 | return containsAA; |
| 1479 | } |
| 1480 | |
| 1481 | class RgnAccumulator { |
| 1482 | SkRegion* fRgn; |
| 1483 | public: |
| 1484 | RgnAccumulator(SkRegion* total) : fRgn(total) {} |
| 1485 | void accumulate(SkBaseDevice* device, SkRegion* rgn) { |
| 1486 | SkIPoint origin = device->getOrigin(); |
| 1487 | if (origin.x() | origin.y()) { |
| 1488 | rgn->translate(origin.x(), origin.y()); |
| 1489 | } |
| 1490 | fRgn->op(*rgn, SkRegion::kUnion_Op); |
| 1491 | } |
| 1492 | }; |
| 1493 | |
| 1494 | void SkCanvas::temporary_internal_getRgnClip(SkRegion* rgn) { |
| 1495 | RgnAccumulator accum(rgn); |
| 1496 | SkRegion tmp; |
| 1497 | |
| 1498 | rgn->setEmpty(); |
| 1499 | FOR_EACH_TOP_DEVICE(device->onAsRgnClip(&tmp); accum.accumulate(device, &tmp)); |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1502 | /////////////////////////////////////////////////////////////////////////////// |
| 1503 | |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1504 | bool SkCanvas::isClipEmpty() const { |
Mike Reed | 02be3c1 | 2017-03-23 12:34:15 -0400 | [diff] [blame] | 1505 | return fMCRec->fRasterClip.isEmpty(); |
| 1506 | |
| 1507 | // TODO: should we only use the conservative answer in a recording canvas? |
| 1508 | #if 0 |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1509 | SkBaseDevice* dev = this->getTopDevice(); |
| 1510 | // if no device we return true |
| 1511 | return !dev || dev->onGetClipType() == SkBaseDevice::kEmpty_ClipType; |
Mike Reed | 02be3c1 | 2017-03-23 12:34:15 -0400 | [diff] [blame] | 1512 | #endif |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1515 | bool SkCanvas::isClipRect() const { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1516 | SkBaseDevice* dev = this->getTopDevice(); |
| 1517 | // if no device we return false |
| 1518 | return dev && dev->onGetClipType() == SkBaseDevice::kRect_ClipType; |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1521 | static inline bool is_nan_or_clipped(const Sk4f& devRect, const Sk4f& devClip) { |
| 1522 | #if !defined(SKNX_NO_SIMD) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 1523 | __m128 lLtT = _mm_unpacklo_ps(devRect.fVec, devClip.fVec); |
| 1524 | __m128 RrBb = _mm_unpackhi_ps(devClip.fVec, devRect.fVec); |
| 1525 | __m128 mask = _mm_cmplt_ps(lLtT, RrBb); |
| 1526 | return 0xF != _mm_movemask_ps(mask); |
| 1527 | #elif !defined(SKNX_NO_SIMD) && defined(SK_ARM_HAS_NEON) |
| 1528 | float32x4_t lLtT = vzipq_f32(devRect.fVec, devClip.fVec).val[0]; |
| 1529 | float32x4_t RrBb = vzipq_f32(devClip.fVec, devRect.fVec).val[1]; |
| 1530 | uint32x4_t mask = vcltq_f32(lLtT, RrBb); |
| 1531 | return 0xFFFFFFFFFFFFFFFF != (uint64_t) vmovn_u32(mask); |
| 1532 | #else |
| 1533 | SkRect devRectAsRect; |
| 1534 | SkRect devClipAsRect; |
| 1535 | devRect.store(&devRectAsRect.fLeft); |
| 1536 | devClip.store(&devClipAsRect.fLeft); |
| 1537 | return !devRectAsRect.isFinite() || !devRectAsRect.intersect(devClipAsRect); |
| 1538 | #endif |
| 1539 | } |
wjmaclean@chromium.org | 116b2bc | 2011-02-07 17:48:37 +0000 | [diff] [blame] | 1540 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1541 | // It's important for this function to not be inlined. Otherwise the compiler will share code |
| 1542 | // between the fast path and the slow path, resulting in two slow paths. |
| 1543 | static SK_NEVER_INLINE bool quick_reject_slow_path(const SkRect& src, const SkRect& deviceClip, |
| 1544 | const SkMatrix& matrix) { |
| 1545 | SkRect deviceRect; |
| 1546 | matrix.mapRect(&deviceRect, src); |
| 1547 | return !deviceRect.isFinite() || !deviceRect.intersect(deviceClip); |
| 1548 | } |
| 1549 | |
| 1550 | bool SkCanvas::quickReject(const SkRect& src) const { |
| 1551 | #ifdef SK_DEBUG |
| 1552 | // Verify that fDeviceClipBounds are set properly. |
| 1553 | SkRect tmp = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1554 | if (fMCRec->fRasterClip.isEmpty()) { |
msarett | 0c685ee | 2016-08-14 13:51:16 -0700 | [diff] [blame] | 1555 | SkASSERT(fDeviceClipBounds.isEmpty()); |
reed@android.com | a380ae4 | 2009-07-21 01:17:02 +0000 | [diff] [blame] | 1556 | } else { |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1557 | SkASSERT(tmp == fDeviceClipBounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1558 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1559 | |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1560 | // Verify that fIsScaleTranslate is set properly. |
| 1561 | SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate()); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1562 | #endif |
| 1563 | |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1564 | if (!fIsScaleTranslate) { |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1565 | return quick_reject_slow_path(src, fDeviceClipBounds, fMCRec->fMatrix); |
| 1566 | } |
| 1567 | |
| 1568 | // We inline the implementation of mapScaleTranslate() for the fast path. |
| 1569 | float sx = fMCRec->fMatrix.getScaleX(); |
| 1570 | float sy = fMCRec->fMatrix.getScaleY(); |
| 1571 | float tx = fMCRec->fMatrix.getTranslateX(); |
| 1572 | float ty = fMCRec->fMatrix.getTranslateY(); |
| 1573 | Sk4f scale(sx, sy, sx, sy); |
| 1574 | Sk4f trans(tx, ty, tx, ty); |
| 1575 | |
| 1576 | // Apply matrix. |
| 1577 | Sk4f ltrb = Sk4f::Load(&src.fLeft) * scale + trans; |
| 1578 | |
| 1579 | // Make sure left < right, top < bottom. |
| 1580 | Sk4f rblt(ltrb[2], ltrb[3], ltrb[0], ltrb[1]); |
| 1581 | Sk4f min = Sk4f::Min(ltrb, rblt); |
| 1582 | Sk4f max = Sk4f::Max(ltrb, rblt); |
| 1583 | // We can extract either pair [0,1] or [2,3] from min and max and be correct, but on |
| 1584 | // ARM this sequence generates the fastest (a single instruction). |
| 1585 | Sk4f devRect = Sk4f(min[2], min[3], max[0], max[1]); |
| 1586 | |
| 1587 | // Check if the device rect is NaN or outside the clip. |
| 1588 | return is_nan_or_clipped(devRect, Sk4f::Load(&fDeviceClipBounds.fLeft)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1591 | bool SkCanvas::quickReject(const SkPath& path) const { |
| 1592 | return path.isEmpty() || this->quickReject(path.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Mike Klein | 83c8dd9 | 2017-11-28 17:08:45 -0500 | [diff] [blame] | 1595 | SkRect SkCanvas::getLocalClipBounds() const { |
| 1596 | SkIRect ibounds = this->getDeviceClipBounds(); |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 1597 | if (ibounds.isEmpty()) { |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1598 | return SkRect::MakeEmpty(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
reed@android.com | d9c0f0b | 2009-02-06 22:39:37 +0000 | [diff] [blame] | 1601 | SkMatrix inverse; |
| 1602 | // if we can't invert the CTM, we can't return local clip bounds |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1603 | if (!fMCRec->fMatrix.invert(&inverse)) { |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1604 | return SkRect::MakeEmpty(); |
reed@android.com | d9c0f0b | 2009-02-06 22:39:37 +0000 | [diff] [blame] | 1605 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1606 | |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1607 | SkRect bounds; |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1608 | // adjust it outwards in case we are antialiasing |
Mike Reed | b57b931 | 2018-04-23 12:12:54 -0400 | [diff] [blame] | 1609 | const int margin = 1; |
reed@google.com | fa4d5bd | 2012-01-30 17:36:27 +0000 | [diff] [blame] | 1610 | |
Mike Reed | b57b931 | 2018-04-23 12:12:54 -0400 | [diff] [blame] | 1611 | SkRect r = SkRect::Make(ibounds.makeOutset(margin, margin)); |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1612 | inverse.mapRect(&bounds, r); |
| 1613 | return bounds; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
Mike Klein | 83c8dd9 | 2017-11-28 17:08:45 -0500 | [diff] [blame] | 1616 | SkIRect SkCanvas::getDeviceClipBounds() const { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1617 | return fMCRec->fRasterClip.getBounds(); |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1620 | const SkMatrix& SkCanvas::getTotalMatrix() const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1621 | return fMCRec->fMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1624 | GrRenderTargetContext* SkCanvas::internal_private_accessTopLayerRenderTargetContext() { |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1625 | SkBaseDevice* dev = this->getTopDevice(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1626 | return dev ? dev->accessRenderTargetContext() : nullptr; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1629 | GrContext* SkCanvas::getGrContext() { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1630 | SkBaseDevice* device = this->getTopDevice(); |
reed | 86ae3d1 | 2016-04-26 06:57:31 -0700 | [diff] [blame] | 1631 | return device ? device->context() : nullptr; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1632 | } |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 1633 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1634 | void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 1635 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 1636 | TRACE_EVENT0("skia", TRACE_FUNC); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1637 | if (outer.isEmpty()) { |
| 1638 | return; |
| 1639 | } |
| 1640 | if (inner.isEmpty()) { |
| 1641 | this->drawRRect(outer, paint); |
| 1642 | return; |
| 1643 | } |
| 1644 | |
| 1645 | // We don't have this method (yet), but technically this is what we should |
Cary Clark | e0b7287 | 2017-04-12 12:03:15 -0400 | [diff] [blame] | 1646 | // be able to return ... |
| 1647 | // if (!outer.contains(inner))) { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1648 | // |
| 1649 | // For now at least check for containment of bounds |
Cary Clark | e0b7287 | 2017-04-12 12:03:15 -0400 | [diff] [blame] | 1650 | if (!outer.getBounds().contains(inner.getBounds())) { |
| 1651 | return; |
| 1652 | } |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1653 | |
| 1654 | this->onDrawDRRect(outer, inner, paint); |
| 1655 | } |
| 1656 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1657 | void SkCanvas::drawPaint(const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1658 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1659 | this->onDrawPaint(paint); |
| 1660 | } |
| 1661 | |
| 1662 | void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1663 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 1664 | // To avoid redundant logic in our culling code and various backends, we always sort rects |
| 1665 | // before passing them along. |
| 1666 | this->onDrawRect(r.makeSorted(), paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1667 | } |
| 1668 | |
msarett | dca352e | 2016-08-26 06:37:45 -0700 | [diff] [blame] | 1669 | void SkCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1670 | TRACE_EVENT0("skia", TRACE_FUNC); |
msarett | dca352e | 2016-08-26 06:37:45 -0700 | [diff] [blame] | 1671 | if (region.isEmpty()) { |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | if (region.isRect()) { |
| 1676 | return this->drawIRect(region.getBounds(), paint); |
| 1677 | } |
| 1678 | |
| 1679 | this->onDrawRegion(region, paint); |
| 1680 | } |
| 1681 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1682 | void SkCanvas::drawOval(const SkRect& r, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1683 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 1684 | // To avoid redundant logic in our culling code and various backends, we always sort rects |
| 1685 | // before passing them along. |
| 1686 | this->onDrawOval(r.makeSorted(), paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1690 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1691 | this->onDrawRRect(rrect, paint); |
| 1692 | } |
| 1693 | |
| 1694 | void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1695 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1696 | this->onDrawPoints(mode, count, pts, paint); |
| 1697 | } |
| 1698 | |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 1699 | void SkCanvas::drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, |
| 1700 | const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1701 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1702 | RETURN_ON_NULL(vertices); |
Brian Salomon | cccafe8 | 2018-04-28 16:13:08 -0400 | [diff] [blame] | 1703 | // We expect fans to be converted to triangles when building or deserializing SkVertices. |
| 1704 | SkASSERT(vertices->mode() != SkVertices::kTriangleFan_VertexMode); |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame^] | 1705 | this->onDrawVerticesObject(vertices.get(), nullptr, 0, mode, paint); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | void SkCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1709 | TRACE_EVENT0("skia", TRACE_FUNC); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 1710 | RETURN_ON_NULL(vertices); |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame^] | 1711 | this->onDrawVerticesObject(vertices, nullptr, 0, mode, paint); |
| 1712 | } |
| 1713 | |
| 1714 | void SkCanvas::drawVertices(const sk_sp<SkVertices> vertices, const SkMatrix* bones, int boneCount, |
| 1715 | SkBlendMode mode, const SkPaint& paint) { |
| 1716 | TRACE_EVENT0("skia", TRACE_FUNC); |
| 1717 | RETURN_ON_NULL(vertices); |
| 1718 | this->onDrawVerticesObject(vertices.get(), bones, boneCount, mode, paint); |
| 1719 | } |
| 1720 | |
| 1721 | void SkCanvas::drawVertices(const SkVertices* vertices, const SkMatrix* bones, int boneCount, |
| 1722 | SkBlendMode mode, const SkPaint& paint) { |
| 1723 | TRACE_EVENT0("skia", TRACE_FUNC); |
| 1724 | RETURN_ON_NULL(vertices); |
| 1725 | this->onDrawVerticesObject(vertices, bones, boneCount, mode, paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1729 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1730 | this->onDrawPath(path, paint); |
| 1731 | } |
| 1732 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1733 | void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1734 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1735 | RETURN_ON_NULL(image); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1736 | this->onDrawImage(image, x, y, paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1737 | } |
| 1738 | |
Mike Reed | c4e3109 | 2018-01-30 11:15:27 -0500 | [diff] [blame] | 1739 | // Returns true if the rect can be "filled" : non-empty and finite |
| 1740 | static bool fillable(const SkRect& r) { |
| 1741 | SkScalar w = r.width(); |
| 1742 | SkScalar h = r.height(); |
| 1743 | return SkScalarIsFinite(w) && w > 0 && SkScalarIsFinite(h) && h > 0; |
| 1744 | } |
| 1745 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1746 | void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 1747 | const SkPaint* paint, SrcRectConstraint constraint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1748 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1749 | RETURN_ON_NULL(image); |
Mike Reed | c4e3109 | 2018-01-30 11:15:27 -0500 | [diff] [blame] | 1750 | if (!fillable(dst) || !fillable(src)) { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1751 | return; |
| 1752 | } |
| 1753 | this->onDrawImageRect(image, &src, dst, paint, constraint); |
| 1754 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1755 | |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 1756 | void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 1757 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1758 | RETURN_ON_NULL(image); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1759 | this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1762 | void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 1763 | SrcRectConstraint constraint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1764 | RETURN_ON_NULL(image); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1765 | this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint, |
| 1766 | constraint); |
| 1767 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1768 | |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1769 | namespace { |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1770 | class LatticePaint : SkNoncopyable { |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1771 | public: |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1772 | LatticePaint(const SkPaint* origPaint) : fPaint(origPaint) { |
| 1773 | if (!origPaint) { |
| 1774 | return; |
| 1775 | } |
| 1776 | if (origPaint->getFilterQuality() > kLow_SkFilterQuality) { |
| 1777 | fPaint.writable()->setFilterQuality(kLow_SkFilterQuality); |
| 1778 | } |
| 1779 | if (origPaint->getMaskFilter()) { |
| 1780 | fPaint.writable()->setMaskFilter(nullptr); |
| 1781 | } |
| 1782 | if (origPaint->isAntiAlias()) { |
| 1783 | fPaint.writable()->setAntiAlias(false); |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | const SkPaint* get() const { |
| 1788 | return fPaint; |
| 1789 | } |
| 1790 | |
| 1791 | private: |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1792 | SkTCopyOnFirstWrite<SkPaint> fPaint; |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1793 | }; |
| 1794 | } // namespace |
| 1795 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1796 | void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 1797 | const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1798 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1799 | RETURN_ON_NULL(image); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1800 | if (dst.isEmpty()) { |
| 1801 | return; |
| 1802 | } |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 1803 | if (SkLatticeIter::Valid(image->width(), image->height(), center)) { |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1804 | LatticePaint latticePaint(paint); |
| 1805 | this->onDrawImageNine(image, center, dst, latticePaint.get()); |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 1806 | } else { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1807 | this->drawImageRect(image, dst, paint); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1808 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1811 | void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 1812 | const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1813 | TRACE_EVENT0("skia", TRACE_FUNC); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1814 | RETURN_ON_NULL(image); |
| 1815 | if (dst.isEmpty()) { |
| 1816 | return; |
| 1817 | } |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 1818 | |
| 1819 | SkIRect bounds; |
| 1820 | Lattice latticePlusBounds = lattice; |
| 1821 | if (!latticePlusBounds.fBounds) { |
| 1822 | bounds = SkIRect::MakeWH(image->width(), image->height()); |
| 1823 | latticePlusBounds.fBounds = &bounds; |
| 1824 | } |
| 1825 | |
| 1826 | if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) { |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1827 | LatticePaint latticePaint(paint); |
| 1828 | this->onDrawImageLattice(image, latticePlusBounds, dst, latticePaint.get()); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1829 | } else { |
| 1830 | this->drawImageRect(image, dst, paint); |
| 1831 | } |
| 1832 | } |
| 1833 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1834 | void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1835 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1836 | if (bitmap.drawsNothing()) { |
tomhudson | 2df6fd6 | 2015-04-09 09:20:19 -0700 | [diff] [blame] | 1837 | return; |
| 1838 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1839 | this->onDrawBitmap(bitmap, dx, dy, paint); |
| 1840 | } |
| 1841 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1842 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1843 | const SkPaint* paint, SrcRectConstraint constraint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1844 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1845 | if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1846 | return; |
| 1847 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1848 | this->onDrawBitmapRect(bitmap, &src, dst, paint, constraint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1849 | } |
| 1850 | |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 1851 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 1852 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1853 | this->drawBitmapRect(bitmap, SkRect::Make(isrc), dst, paint, constraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1856 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 1857 | SrcRectConstraint constraint) { |
| 1858 | this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), dst, paint, |
| 1859 | constraint); |
| 1860 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1861 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1862 | void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 1863 | const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1864 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1865 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
tomhudson | 2df6fd6 | 2015-04-09 09:20:19 -0700 | [diff] [blame] | 1866 | return; |
| 1867 | } |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 1868 | if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1869 | LatticePaint latticePaint(paint); |
| 1870 | this->onDrawBitmapNine(bitmap, center, dst, latticePaint.get()); |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 1871 | } else { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1872 | this->drawBitmapRect(bitmap, dst, paint); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1873 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1874 | } |
| 1875 | |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 1876 | void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 1877 | const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1878 | TRACE_EVENT0("skia", TRACE_FUNC); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1879 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 1880 | return; |
| 1881 | } |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 1882 | |
| 1883 | SkIRect bounds; |
| 1884 | Lattice latticePlusBounds = lattice; |
| 1885 | if (!latticePlusBounds.fBounds) { |
| 1886 | bounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1887 | latticePlusBounds.fBounds = &bounds; |
| 1888 | } |
| 1889 | |
| 1890 | if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), latticePlusBounds)) { |
Brian Salomon | 969be1c | 2018-05-21 14:37:49 -0400 | [diff] [blame] | 1891 | LatticePaint latticePaint(paint); |
| 1892 | this->onDrawBitmapLattice(bitmap, latticePlusBounds, dst, latticePaint.get()); |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 1893 | } else { |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1894 | this->drawBitmapRect(bitmap, dst, paint); |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 1895 | } |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1898 | void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1899 | const SkColor colors[], int count, SkBlendMode mode, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1900 | const SkRect* cull, const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1901 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 1902 | RETURN_ON_NULL(atlas); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1903 | if (count <= 0) { |
| 1904 | return; |
| 1905 | } |
Joe Gregorio | c485907 | 2017-01-20 14:21:27 +0000 | [diff] [blame] | 1906 | SkASSERT(atlas); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1907 | SkASSERT(tex); |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 1908 | this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 1911 | void SkCanvas::drawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1912 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 1913 | if (key) { |
| 1914 | this->onDrawAnnotation(rect, key, value); |
| 1915 | } |
| 1916 | } |
| 1917 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 1918 | void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 1919 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 1920 | if (src) { |
| 1921 | this->drawImageRect(image, *src, dst, paint, constraint); |
| 1922 | } else { |
| 1923 | this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), |
| 1924 | dst, paint, constraint); |
| 1925 | } |
| 1926 | } |
| 1927 | void SkCanvas::legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
| 1928 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 1929 | if (src) { |
| 1930 | this->drawBitmapRect(bitmap, *src, dst, paint, constraint); |
| 1931 | } else { |
| 1932 | this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), |
| 1933 | dst, paint, constraint); |
| 1934 | } |
| 1935 | } |
| 1936 | |
Mike Reed | 4204da2 | 2017-05-17 08:53:36 -0400 | [diff] [blame] | 1937 | void SkCanvas::private_draw_shadow_rec(const SkPath& path, const SkDrawShadowRec& rec) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 1938 | TRACE_EVENT0("skia", TRACE_FUNC); |
Mike Reed | 4204da2 | 2017-05-17 08:53:36 -0400 | [diff] [blame] | 1939 | this->onDrawShadowRec(path, rec); |
| 1940 | } |
| 1941 | |
| 1942 | void SkCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { |
| 1943 | SkPaint paint; |
| 1944 | const SkRect& pathBounds = path.getBounds(); |
| 1945 | |
| 1946 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, &pathBounds) |
| 1947 | while (iter.next()) { |
| 1948 | iter.fDevice->drawShadow(path, rec); |
| 1949 | } |
| 1950 | LOOPER_END |
| 1951 | } |
| 1952 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1953 | ////////////////////////////////////////////////////////////////////////////// |
| 1954 | // These are the virtual drawing methods |
| 1955 | ////////////////////////////////////////////////////////////////////////////// |
| 1956 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1957 | void SkCanvas::onDiscard() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1958 | if (fSurfaceBase) { |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1959 | fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
| 1960 | } |
| 1961 | } |
| 1962 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1963 | void SkCanvas::onDrawPaint(const SkPaint& paint) { |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1964 | this->internalDrawPaint(paint); |
| 1965 | } |
| 1966 | |
| 1967 | void SkCanvas::internalDrawPaint(const SkPaint& paint) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1968 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kPaint_Type, nullptr, false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1969 | |
| 1970 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1971 | iter.fDevice->drawPaint(looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 1974 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1977 | void SkCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 1978 | const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1979 | if ((long)count <= 0) { |
| 1980 | return; |
| 1981 | } |
| 1982 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 1983 | SkRect r; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1984 | const SkRect* bounds = nullptr; |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1985 | if (paint.canComputeFastBounds()) { |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1986 | // special-case 2 points (common for drawing a single line) |
| 1987 | if (2 == count) { |
| 1988 | r.set(pts[0], pts[1]); |
| 1989 | } else { |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 1990 | r.set(pts, SkToInt(count)); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1991 | } |
Jim Van Verth | 5d32b83 | 2018-02-21 11:14:32 -0500 | [diff] [blame] | 1992 | if (!r.isFinite()) { |
| 1993 | return; |
| 1994 | } |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 1995 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 1996 | if (this->quickReject(paint.computeFastStrokeBounds(r, &storage))) { |
| 1997 | return; |
| 1998 | } |
| 1999 | bounds = &r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 2000 | } |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 2001 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2002 | SkASSERT(pts != nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2003 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2004 | LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2005 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2006 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2007 | iter.fDevice->drawPoints(mode, count, pts, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2008 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2009 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2010 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2013 | static bool needs_autodrawlooper(SkCanvas* canvas, const SkPaint& paint) { |
| 2014 | return ((intptr_t)paint.getImageFilter() | |
| 2015 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 2016 | (intptr_t)canvas->getDrawFilter() | |
| 2017 | #endif |
| 2018 | (intptr_t)paint.getLooper() ) != 0; |
| 2019 | } |
| 2020 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2021 | void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2022 | SkASSERT(r.isSorted()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2023 | if (paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2024 | SkRect storage; |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2025 | if (this->quickReject(paint.computeFastBounds(r, &storage))) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2026 | return; |
| 2027 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2028 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2029 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2030 | if (needs_autodrawlooper(this, paint)) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2031 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, &r, false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2032 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2033 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2034 | iter.fDevice->drawRect(r, looper.paint()); |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | LOOPER_END |
| 2038 | } else { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2039 | this->predrawNotify(&r, &paint, false); |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2040 | SkDrawIter iter(this); |
| 2041 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2042 | iter.fDevice->drawRect(r, paint); |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2043 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2044 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2047 | void SkCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2048 | SkRect regionRect = SkRect::Make(region.getBounds()); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2049 | if (paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2050 | SkRect storage; |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2051 | if (this->quickReject(paint.computeFastBounds(regionRect, &storage))) { |
| 2052 | return; |
| 2053 | } |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2056 | LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, ®ionRect) |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2057 | |
| 2058 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2059 | iter.fDevice->drawRegion(region, looper.paint()); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | LOOPER_END |
| 2063 | } |
| 2064 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2065 | void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2066 | SkASSERT(oval.isSorted()); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2067 | if (paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2068 | SkRect storage; |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2069 | if (this->quickReject(paint.computeFastBounds(oval, &storage))) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2070 | return; |
| 2071 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2072 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 2073 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2074 | LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, &oval) |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 2075 | |
| 2076 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2077 | iter.fDevice->drawOval(oval, looper.paint()); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | LOOPER_END |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2083 | void SkCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, |
| 2084 | SkScalar sweepAngle, bool useCenter, |
| 2085 | const SkPaint& paint) { |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2086 | SkASSERT(oval.isSorted()); |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2087 | if (paint.canComputeFastBounds()) { |
| 2088 | SkRect storage; |
| 2089 | // Note we're using the entire oval as the bounds. |
Brian Osman | 6e3ce40 | 2017-05-17 15:10:18 -0400 | [diff] [blame] | 2090 | if (this->quickReject(paint.computeFastBounds(oval, &storage))) { |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2091 | return; |
| 2092 | } |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2095 | LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, &oval) |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2096 | |
| 2097 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2098 | iter.fDevice->drawArc(oval, startAngle, sweepAngle, useCenter, looper.paint()); |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | LOOPER_END |
| 2102 | } |
| 2103 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2104 | void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2105 | if (paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2106 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2107 | if (this->quickReject(paint.computeFastBounds(rrect.getBounds(), &storage))) { |
| 2108 | return; |
| 2109 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | if (rrect.isRect()) { |
| 2113 | // call the non-virtual version |
| 2114 | this->SkCanvas::drawRect(rrect.getBounds(), paint); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2115 | return; |
| 2116 | } else if (rrect.isOval()) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2117 | // call the non-virtual version |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2118 | this->SkCanvas::drawOval(rrect.getBounds(), paint); |
| 2119 | return; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2120 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2121 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2122 | LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, &rrect.getBounds()) |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2123 | |
| 2124 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2125 | iter.fDevice->drawRRect(rrect, looper.paint()); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | LOOPER_END |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2131 | void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2132 | if (paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2133 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2134 | if (this->quickReject(paint.computeFastBounds(outer.getBounds(), &storage))) { |
| 2135 | return; |
| 2136 | } |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2137 | } |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2138 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2139 | LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, &outer.getBounds()) |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2140 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2141 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2142 | iter.fDevice->drawDRRect(outer, inner, looper.paint()); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2143 | } |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2144 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2145 | LOOPER_END |
| 2146 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2147 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2148 | void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
reed@google.com | 9364511 | 2012-07-26 16:11:47 +0000 | [diff] [blame] | 2149 | if (!path.isFinite()) { |
| 2150 | return; |
| 2151 | } |
| 2152 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2153 | const SkRect& pathBounds = path.getBounds(); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2154 | if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2155 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2156 | if (this->quickReject(paint.computeFastBounds(pathBounds, &storage))) { |
| 2157 | return; |
| 2158 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2159 | } |
commit-bot@chromium.org | 0b45dc4 | 2014-02-21 05:42:57 +0000 | [diff] [blame] | 2160 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2161 | if (pathBounds.width() <= 0 && pathBounds.height() <= 0) { |
commit-bot@chromium.org | 6803c21 | 2014-05-04 18:08:27 +0000 | [diff] [blame] | 2162 | if (path.isInverseFillType()) { |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2163 | this->internalDrawPaint(paint); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 2164 | return; |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2165 | } |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2166 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2167 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2168 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, &pathBounds) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2169 | |
| 2170 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2171 | iter.fDevice->drawPath(path, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2174 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2177 | bool SkCanvas::canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint& paint) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2178 | if (!paint.getImageFilter()) { |
| 2179 | return false; |
| 2180 | } |
| 2181 | |
| 2182 | const SkMatrix& ctm = this->getTotalMatrix(); |
fmalita | c7e211a | 2016-01-07 10:34:46 -0800 | [diff] [blame] | 2183 | if (!SkTreatAsSprite(ctm, SkISize::Make(w, h), paint)) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2184 | return false; |
| 2185 | } |
| 2186 | |
| 2187 | // Currently we can only use the filterSprite code if we are clipped to the bitmap's bounds. |
| 2188 | // Once we can filter and the filter will return a result larger than itself, we should be |
| 2189 | // able to remove this constraint. |
| 2190 | // skbug.com/4526 |
| 2191 | // |
| 2192 | SkPoint pt; |
| 2193 | ctm.mapXY(x, y, &pt); |
| 2194 | SkIRect ir = SkIRect::MakeXYWH(SkScalarRoundToInt(pt.x()), SkScalarRoundToInt(pt.y()), w, h); |
| 2195 | return ir.contains(fMCRec->fRasterClip.getBounds()); |
| 2196 | } |
| 2197 | |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2198 | // Given storage for a real paint, and an optional paint parameter, clean-up the param (if non-null) |
| 2199 | // given the drawing semantics for drawImage/bitmap (skbug.com/7804) and return it, or the original |
| 2200 | // null. |
| 2201 | static const SkPaint* init_image_paint(SkPaint* real, const SkPaint* paintParam) { |
| 2202 | if (paintParam) { |
| 2203 | *real = *paintParam; |
| 2204 | real->setStyle(SkPaint::kFill_Style); |
| 2205 | real->setPathEffect(nullptr); |
| 2206 | paintParam = real; |
| 2207 | } |
| 2208 | return paintParam; |
| 2209 | } |
| 2210 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2211 | void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2212 | SkPaint realPaint; |
| 2213 | paint = init_image_paint(&realPaint, paint); |
| 2214 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2215 | SkRect bounds = SkRect::MakeXYWH(x, y, |
| 2216 | SkIntToScalar(image->width()), SkIntToScalar(image->height())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2217 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2218 | SkRect tmp = bounds; |
| 2219 | if (paint) { |
| 2220 | paint->computeFastBounds(tmp, &tmp); |
| 2221 | } |
| 2222 | if (this->quickReject(tmp)) { |
| 2223 | return; |
| 2224 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2225 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2226 | // At this point we need a real paint object. If the caller passed null, then we should |
| 2227 | // use realPaint (in its default state). If the caller did pass a paint, then we have copied |
| 2228 | // (and modified) it in realPaint. Thus either way, "realPaint" is what we want to use. |
| 2229 | paint = &realPaint; |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2230 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2231 | sk_sp<SkSpecialImage> special; |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2232 | bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image->height(), |
| 2233 | *paint); |
| 2234 | if (drawAsSprite && paint->getImageFilter()) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2235 | special = this->getDevice()->makeSpecial(image); |
| 2236 | if (!special) { |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2237 | drawAsSprite = false; |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2238 | } |
| 2239 | } |
| 2240 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2241 | LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) |
| 2242 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2243 | while (iter.next()) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2244 | const SkPaint& pnt = looper.paint(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2245 | if (special) { |
| 2246 | SkPoint pt; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2247 | iter.fDevice->ctm().mapXY(x, y, &pt); |
| 2248 | iter.fDevice->drawSpecial(special.get(), |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2249 | SkScalarRoundToInt(pt.fX), |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 2250 | SkScalarRoundToInt(pt.fY), pnt, |
| 2251 | nullptr, SkMatrix::I()); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2252 | } else { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2253 | iter.fDevice->drawImage(image, x, y, pnt); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2254 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2255 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2256 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2257 | LOOPER_END |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2260 | void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2261 | const SkPaint* paint, SrcRectConstraint constraint) { |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2262 | SkPaint realPaint; |
| 2263 | paint = init_image_paint(&realPaint, paint); |
| 2264 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2265 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2266 | SkRect storage = dst; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2267 | if (paint) { |
| 2268 | paint->computeFastBounds(dst, &storage); |
| 2269 | } |
| 2270 | if (this->quickReject(storage)) { |
| 2271 | return; |
| 2272 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2273 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2274 | paint = &realPaint; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2275 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2276 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, &dst, |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 2277 | image->isOpaque()) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2278 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2279 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2280 | iter.fDevice->drawImageRect(image, src, dst, looper.paint(), constraint); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2281 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2282 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2283 | LOOPER_END |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2286 | void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, const SkPaint* paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2287 | SkDEBUGCODE(bitmap.validate();) |
| 2288 | |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2289 | if (bitmap.drawsNothing()) { |
| 2290 | return; |
| 2291 | } |
| 2292 | |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2293 | SkPaint realPaint; |
| 2294 | init_image_paint(&realPaint, paint); |
| 2295 | paint = &realPaint; |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2296 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2297 | SkRect bounds; |
| 2298 | bitmap.getBounds(&bounds); |
| 2299 | bounds.offset(x, y); |
| 2300 | bool canFastBounds = paint->canComputeFastBounds(); |
| 2301 | if (canFastBounds) { |
| 2302 | SkRect storage; |
| 2303 | if (this->quickReject(paint->computeFastBounds(bounds, &storage))) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2304 | return; |
| 2305 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2306 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2307 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2308 | sk_sp<SkSpecialImage> special; |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2309 | bool drawAsSprite = canFastBounds && this->canDrawBitmapAsSprite(x, y, bitmap.width(), |
| 2310 | bitmap.height(), *paint); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2311 | if (drawAsSprite && paint->getImageFilter()) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2312 | special = this->getDevice()->makeSpecial(bitmap); |
| 2313 | if (!special) { |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2314 | drawAsSprite = false; |
| 2315 | } |
| 2316 | } |
| 2317 | |
Mike Reed | 822128b | 2017-02-28 16:41:03 -0500 | [diff] [blame] | 2318 | LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2319 | |
| 2320 | while (iter.next()) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2321 | const SkPaint& pnt = looper.paint(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2322 | if (special) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2323 | SkPoint pt; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2324 | iter.fDevice->ctm().mapXY(x, y, &pt); |
| 2325 | iter.fDevice->drawSpecial(special.get(), |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2326 | SkScalarRoundToInt(pt.fX), |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 2327 | SkScalarRoundToInt(pt.fY), pnt, |
| 2328 | nullptr, SkMatrix::I()); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2329 | } else { |
Hal Canary | b964238 | 2017-06-27 09:58:56 -0400 | [diff] [blame] | 2330 | iter.fDevice->drawBitmap(bitmap, x, y, looper.paint()); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2331 | } |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2332 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 2333 | |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2334 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2337 | // this one is non-virtual, so it can be called safely by other canvas apis |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 2338 | void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 2339 | const SkRect& dst, const SkPaint* paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2340 | SrcRectConstraint constraint) { |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 2341 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2342 | return; |
| 2343 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2344 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2345 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2346 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2347 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2348 | return; |
| 2349 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2350 | } |
reed@google.com | 3d60812 | 2011-11-21 15:16:16 +0000 | [diff] [blame] | 2351 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2352 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2353 | if (nullptr == paint) { |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2354 | paint = lazy.init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2355 | } |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2356 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2357 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, &dst, |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 2358 | bitmap.isOpaque()) |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2359 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2360 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2361 | iter.fDevice->drawBitmapRect(bitmap, src, dst, looper.paint(), constraint); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2362 | } |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2363 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2364 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2367 | void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2368 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2369 | SkDEBUGCODE(bitmap.validate();) |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2370 | this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2373 | void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 2374 | const SkPaint* paint) { |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2375 | SkPaint realPaint; |
| 2376 | paint = init_image_paint(&realPaint, paint); |
| 2377 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2378 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2379 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2380 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2381 | return; |
| 2382 | } |
reed@google.com | 3d60812 | 2011-11-21 15:16:16 +0000 | [diff] [blame] | 2383 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2384 | paint = &realPaint; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2385 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2386 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2387 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2388 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2389 | iter.fDevice->drawImageNine(image, center, dst, looper.paint()); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2390 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2391 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2392 | LOOPER_END |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2395 | void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 2396 | const SkPaint* paint) { |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2397 | SkDEBUGCODE(bitmap.validate();) |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2398 | SkPaint realPaint; |
| 2399 | paint = init_image_paint(&realPaint, paint); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2400 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2401 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2402 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2403 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2404 | return; |
| 2405 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2406 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2407 | paint = &realPaint; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2408 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2409 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2410 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2411 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2412 | iter.fDevice->drawBitmapNine(bitmap, center, dst, looper.paint()); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2413 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2414 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2415 | LOOPER_END |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2418 | void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 2419 | const SkPaint* paint) { |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2420 | SkPaint realPaint; |
| 2421 | paint = init_image_paint(&realPaint, paint); |
| 2422 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2423 | if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2424 | SkRect storage; |
| 2425 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2426 | return; |
| 2427 | } |
| 2428 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2429 | paint = &realPaint; |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2430 | |
| 2431 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2432 | |
| 2433 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2434 | iter.fDevice->drawImageLattice(image, lattice, dst, looper.paint()); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | LOOPER_END |
| 2438 | } |
| 2439 | |
| 2440 | void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, |
| 2441 | const SkRect& dst, const SkPaint* paint) { |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2442 | SkPaint realPaint; |
| 2443 | paint = init_image_paint(&realPaint, paint); |
| 2444 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2445 | if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2446 | SkRect storage; |
| 2447 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2448 | return; |
| 2449 | } |
| 2450 | } |
Mike Reed | f441cfc | 2018-04-11 14:50:16 -0400 | [diff] [blame] | 2451 | paint = &realPaint; |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2452 | |
| 2453 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2454 | |
| 2455 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2456 | iter.fDevice->drawBitmapLattice(bitmap, lattice, dst, looper.paint()); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | LOOPER_END |
| 2460 | } |
| 2461 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2462 | void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 2463 | const SkPaint& paint) { |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 2464 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2465 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2466 | |
| 2467 | while (iter.next()) { |
Herb Derby | 4a44743 | 2018-06-22 11:45:27 -0400 | [diff] [blame] | 2468 | fScratchGlyphRunBuilder->prepareDrawText( |
| 2469 | looper.paint(), text, byteLength, SkPoint::Make(x, y)); |
Robert Phillips | 3858045 | 2018-06-28 12:00:35 +0000 | [diff] [blame] | 2470 | auto glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); |
| 2471 | iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2474 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2477 | void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 2478 | const SkPaint& paint) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2479 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2480 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2481 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2482 | while (iter.next()) { |
Herb Derby | 4a44743 | 2018-06-22 11:45:27 -0400 | [diff] [blame] | 2483 | fScratchGlyphRunBuilder->prepareDrawPosText(looper.paint(), text, byteLength, pos); |
Robert Phillips | 3858045 | 2018-06-28 12:00:35 +0000 | [diff] [blame] | 2484 | auto glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); |
| 2485 | iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2486 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2487 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2488 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2491 | void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 2492 | SkScalar constY, const SkPaint& paint) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2493 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2494 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2495 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2496 | while (iter.next()) { |
Herb Derby | 4a44743 | 2018-06-22 11:45:27 -0400 | [diff] [blame] | 2497 | fScratchGlyphRunBuilder->prepareDrawPosTextH( |
| 2498 | looper.paint(), text, byteLength, xpos, constY); |
Robert Phillips | 3858045 | 2018-06-28 12:00:35 +0000 | [diff] [blame] | 2499 | const auto& glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); |
| 2500 | iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2501 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2502 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2503 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2506 | void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 2507 | const SkMatrix* matrix, const SkPaint& paint) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2508 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2509 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2510 | while (iter.next()) { |
Ben Wagner | d234afd | 2018-04-13 15:50:01 -0400 | [diff] [blame] | 2511 | iter.fDevice->drawTextOnPath(text, byteLength, path, matrix, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2512 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2513 | |
commit-bot@chromium.org | 945ec3a | 2014-04-22 20:07:30 +0000 | [diff] [blame] | 2514 | LOOPER_END |
commit-bot@chromium.org | 4325d11 | 2014-04-22 19:03:02 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2517 | void SkCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 2518 | const SkRect* cullRect, const SkPaint& paint) { |
| 2519 | if (cullRect && this->quickReject(*cullRect)) { |
| 2520 | return; |
| 2521 | } |
| 2522 | |
| 2523 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
| 2524 | |
| 2525 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2526 | iter.fDevice->drawTextRSXform(text, byteLength, xform, looper.paint()); |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | LOOPER_END |
| 2530 | } |
| 2531 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2532 | void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2533 | const SkPaint& paint) { |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2534 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2535 | const SkRect* bounds = nullptr; |
fmalita | 19653d1 | 2014-10-16 11:53:30 -0700 | [diff] [blame] | 2536 | if (paint.canComputeFastBounds()) { |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2537 | storage = blob->bounds().makeOffset(x, y); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2538 | SkRect tmp; |
| 2539 | if (this->quickReject(paint.computeFastBounds(storage, &tmp))) { |
| 2540 | return; |
| 2541 | } |
| 2542 | bounds = &storage; |
fmalita | 7ba7aa7 | 2014-08-29 09:46:36 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2545 | // We cannot filter in the looper as we normally do, because the paint is |
| 2546 | // incomplete at this point (text-related attributes are embedded within blob run paints). |
| 2547 | SkDrawFilter* drawFilter = fMCRec->fFilter; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2548 | fMCRec->fFilter = nullptr; |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2549 | |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2550 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds) |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2551 | |
fmalita | aa1b912 | 2014-08-28 14:32:24 -0700 | [diff] [blame] | 2552 | while (iter.next()) { |
Robert Phillips | 3858045 | 2018-06-28 12:00:35 +0000 | [diff] [blame] | 2553 | iter.fDevice->drawTextBlob(blob, x, y, looper.paint(), drawFilter); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
fmalita | aa1b912 | 2014-08-28 14:32:24 -0700 | [diff] [blame] | 2556 | LOOPER_END |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2557 | |
| 2558 | fMCRec->fFilter = drawFilter; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 2561 | void SkCanvas::drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) { |
| 2562 | this->drawText(string.c_str(), string.size(), x, y, paint); |
| 2563 | } |
| 2564 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2565 | // These will become non-virtual, so they always call the (virtual) onDraw... method |
| 2566 | void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 2567 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2568 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2569 | if (byteLength) { |
Ben Wagner | 4bd3b09 | 2017-08-01 13:22:23 -0400 | [diff] [blame] | 2570 | sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength)); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2571 | this->onDrawText(text, byteLength, x, y, paint); |
| 2572 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2573 | } |
| 2574 | void SkCanvas::drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 2575 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2576 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2577 | if (byteLength) { |
Ben Wagner | 4bd3b09 | 2017-08-01 13:22:23 -0400 | [diff] [blame] | 2578 | sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength)); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2579 | this->onDrawPosText(text, byteLength, pos, paint); |
| 2580 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2581 | } |
| 2582 | void SkCanvas::drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 2583 | SkScalar constY, const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2584 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2585 | if (byteLength) { |
Ben Wagner | 4bd3b09 | 2017-08-01 13:22:23 -0400 | [diff] [blame] | 2586 | sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength)); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2587 | this->onDrawPosTextH(text, byteLength, xpos, constY, paint); |
| 2588 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2589 | } |
| 2590 | void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 2591 | const SkMatrix* matrix, const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2592 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2593 | if (byteLength) { |
Ben Wagner | 4bd3b09 | 2017-08-01 13:22:23 -0400 | [diff] [blame] | 2594 | sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength)); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2595 | this->onDrawTextOnPath(text, byteLength, path, matrix, paint); |
| 2596 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2597 | } |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2598 | void SkCanvas::drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 2599 | const SkRect* cullRect, const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2600 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2601 | if (byteLength) { |
Ben Wagner | 4bd3b09 | 2017-08-01 13:22:23 -0400 | [diff] [blame] | 2602 | sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength)); |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2603 | this->onDrawTextRSXform(text, byteLength, xform, cullRect, paint); |
| 2604 | } |
| 2605 | } |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2606 | void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2607 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2608 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 2609 | RETURN_ON_NULL(blob); |
Mike Reed | 74d6e11 | 2018-01-23 13:06:12 -0500 | [diff] [blame] | 2610 | RETURN_ON_FALSE(blob->bounds().makeOffset(x, y).isFinite()); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2611 | this->onDrawTextBlob(blob, x, y, paint); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2612 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2613 | |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame^] | 2614 | void SkCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkMatrix* bones, |
| 2615 | int boneCount, SkBlendMode bmode, const SkPaint& paint) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 2616 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) |
| 2617 | |
| 2618 | while (iter.next()) { |
| 2619 | // In the common case of one iteration we could std::move vertices here. |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame^] | 2620 | iter.fDevice->drawVertices(vertices, bones, boneCount, bmode, looper.paint()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | LOOPER_END |
| 2624 | } |
| 2625 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2626 | void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 2627 | const SkPoint texCoords[4], SkBlendMode bmode, |
| 2628 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2629 | TRACE_EVENT0("skia", TRACE_FUNC); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2630 | if (nullptr == cubics) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2631 | return; |
| 2632 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2633 | |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 2634 | this->onDrawPatch(cubics, colors, texCoords, bmode, paint); |
msarett | 9340c26 | 2016-09-22 05:20:21 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 2638 | const SkPoint texCoords[4], SkBlendMode bmode, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 2639 | const SkPaint& paint) { |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2640 | // Since a patch is always within the convex hull of the control points, we discard it when its |
| 2641 | // bounding rectangle is completely outside the current clip. |
| 2642 | SkRect bounds; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2643 | bounds.set(cubics, SkPatchUtils::kNumCtrlPts); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2644 | if (this->quickReject(bounds)) { |
| 2645 | return; |
| 2646 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2647 | |
Mike Reed | 435071e | 2017-05-23 11:22:56 -0400 | [diff] [blame] | 2648 | const bool interpColorsLinearly = (this->imageInfo().colorSpace() != nullptr); |
| 2649 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2650 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2651 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2652 | while (iter.next()) { |
Mike Reed | 435071e | 2017-05-23 11:22:56 -0400 | [diff] [blame] | 2653 | iter.fDevice->drawPatch(cubics, colors, texCoords, bmode, interpColorsLinearly, paint); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2654 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2655 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2656 | LOOPER_END |
| 2657 | } |
| 2658 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2659 | void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) { |
Derek Sollenberger | edf3dc0 | 2017-08-16 10:35:28 -0400 | [diff] [blame] | 2660 | #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 2661 | TRACE_EVENT0("skia", TRACE_FUNC); |
Derek Sollenberger | edf3dc0 | 2017-08-16 10:35:28 -0400 | [diff] [blame] | 2662 | #endif |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2663 | RETURN_ON_NULL(dr); |
| 2664 | if (x || y) { |
| 2665 | SkMatrix matrix = SkMatrix::MakeTrans(x, y); |
| 2666 | this->onDrawDrawable(dr, &matrix); |
| 2667 | } else { |
| 2668 | this->onDrawDrawable(dr, nullptr); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 2669 | } |
| 2670 | } |
| 2671 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2672 | void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) { |
Derek Sollenberger | edf3dc0 | 2017-08-16 10:35:28 -0400 | [diff] [blame] | 2673 | #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 2674 | TRACE_EVENT0("skia", TRACE_FUNC); |
Derek Sollenberger | edf3dc0 | 2017-08-16 10:35:28 -0400 | [diff] [blame] | 2675 | #endif |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2676 | RETURN_ON_NULL(dr); |
| 2677 | if (matrix && matrix->isIdentity()) { |
| 2678 | matrix = nullptr; |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2679 | } |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2680 | this->onDrawDrawable(dr, matrix); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) { |
reed | 2a62e85 | 2016-10-03 10:35:37 -0700 | [diff] [blame] | 2684 | // drawable bounds are no longer reliable (e.g. android displaylist) |
| 2685 | // so don't use them for quick-reject |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2686 | dr->draw(this, matrix); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 2687 | } |
| 2688 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2689 | void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 2690 | const SkColor colors[], int count, SkBlendMode bmode, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2691 | const SkRect* cull, const SkPaint* paint) { |
| 2692 | if (cull && this->quickReject(*cull)) { |
| 2693 | return; |
| 2694 | } |
| 2695 | |
| 2696 | SkPaint pnt; |
| 2697 | if (paint) { |
| 2698 | pnt = *paint; |
| 2699 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2700 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2701 | LOOPER_BEGIN(pnt, SkDrawFilter::kPath_Type, nullptr) |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2702 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2703 | iter.fDevice->drawAtlas(atlas, xform, tex, colors, count, bmode, pnt); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2704 | } |
| 2705 | LOOPER_END |
| 2706 | } |
| 2707 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 2708 | void SkCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 2709 | SkASSERT(key); |
| 2710 | |
| 2711 | SkPaint paint; |
| 2712 | LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, nullptr) |
| 2713 | while (iter.next()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2714 | iter.fDevice->drawAnnotation(rect, key, value); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 2715 | } |
| 2716 | LOOPER_END |
| 2717 | } |
| 2718 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2719 | ////////////////////////////////////////////////////////////////////////////// |
| 2720 | // These methods are NOT virtual, and therefore must call back into virtual |
| 2721 | // methods, rather than actually drawing themselves. |
| 2722 | ////////////////////////////////////////////////////////////////////////////// |
| 2723 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 2724 | void SkCanvas::drawColor(SkColor c, SkBlendMode mode) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2725 | SkPaint paint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2726 | paint.setColor(c); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 2727 | paint.setBlendMode(mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2728 | this->drawPaint(paint); |
| 2729 | } |
| 2730 | |
| 2731 | void SkCanvas::drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) { |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 2732 | const SkPoint pt = { x, y }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2733 | this->drawPoints(kPoints_PointMode, 1, &pt, paint); |
| 2734 | } |
| 2735 | |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 2736 | void SkCanvas::drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2737 | SkPoint pts[2]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2738 | pts[0].set(x0, y0); |
| 2739 | pts[1].set(x1, y1); |
| 2740 | this->drawPoints(kLines_PointMode, 2, pts, paint); |
| 2741 | } |
| 2742 | |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 2743 | void SkCanvas::drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2744 | if (radius < 0) { |
| 2745 | radius = 0; |
| 2746 | } |
| 2747 | |
| 2748 | SkRect r; |
| 2749 | r.set(cx - radius, cy - radius, cx + radius, cy + radius); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2750 | this->drawOval(r, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, |
| 2754 | const SkPaint& paint) { |
| 2755 | if (rx > 0 && ry > 0) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2756 | SkRRect rrect; |
| 2757 | rrect.setRectXY(r, rx, ry); |
| 2758 | this->drawRRect(rrect, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2759 | } else { |
| 2760 | this->drawRect(r, paint); |
| 2761 | } |
| 2762 | } |
| 2763 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2764 | void SkCanvas::drawArc(const SkRect& oval, SkScalar startAngle, |
| 2765 | SkScalar sweepAngle, bool useCenter, |
| 2766 | const SkPaint& paint) { |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 2767 | TRACE_EVENT0("skia", TRACE_FUNC); |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 2768 | if (oval.isEmpty() || !sweepAngle) { |
| 2769 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2770 | } |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 2771 | this->onDrawArc(oval, startAngle, sweepAngle, useCenter, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength, |
| 2775 | const SkPath& path, SkScalar hOffset, |
| 2776 | SkScalar vOffset, const SkPaint& paint) { |
| 2777 | SkMatrix matrix; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2778 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2779 | matrix.setTranslate(hOffset, vOffset); |
| 2780 | this->drawTextOnPath(text, byteLength, path, &matrix, paint); |
| 2781 | } |
| 2782 | |
reed@android.com | f76bacf | 2009-05-13 14:00:33 +0000 | [diff] [blame] | 2783 | /////////////////////////////////////////////////////////////////////////////// |
reed | 1c2c441 | 2015-04-30 13:09:24 -0700 | [diff] [blame] | 2784 | |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 2785 | /** |
| 2786 | * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture, |
| 2787 | * against the playback cost of recursing into the subpicture to get at its actual ops. |
| 2788 | * |
| 2789 | * For now we pick a conservatively small value, though measurement (and other heuristics like |
| 2790 | * the type of ops contained) may justify changing this value. |
| 2791 | */ |
| 2792 | #define kMaxPictureOpsToUnrollInsteadOfRef 1 |
| 2793 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 2794 | void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) { |
Brian Osman | 5e035ca | 2017-07-26 10:18:57 -0400 | [diff] [blame] | 2795 | TRACE_EVENT0("skia", TRACE_FUNC); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2796 | RETURN_ON_NULL(picture); |
| 2797 | |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2798 | if (matrix && matrix->isIdentity()) { |
| 2799 | matrix = nullptr; |
| 2800 | } |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 2801 | if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) { |
| 2802 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 2803 | picture->playback(this); |
| 2804 | } else { |
| 2805 | this->onDrawPicture(picture, matrix, paint); |
| 2806 | } |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 2807 | } |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 2808 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 2809 | void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 2810 | const SkPaint* paint) { |
fmalita | d028180 | 2015-08-20 12:08:18 -0700 | [diff] [blame] | 2811 | if (!paint || paint->canComputeFastBounds()) { |
| 2812 | SkRect bounds = picture->cullRect(); |
| 2813 | if (paint) { |
| 2814 | paint->computeFastBounds(bounds, &bounds); |
| 2815 | } |
| 2816 | if (matrix) { |
| 2817 | matrix->mapRect(&bounds); |
| 2818 | } |
| 2819 | if (this->quickReject(bounds)) { |
| 2820 | return; |
| 2821 | } |
| 2822 | } |
| 2823 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 2824 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 2825 | picture->playback(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2828 | /////////////////////////////////////////////////////////////////////////////// |
| 2829 | /////////////////////////////////////////////////////////////////////////////// |
| 2830 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 2831 | SkCanvas::LayerIter::LayerIter(SkCanvas* canvas) { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 2832 | static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2833 | |
| 2834 | SkASSERT(canvas); |
| 2835 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 2836 | fImpl = new (fStorage) SkDrawIter(canvas); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2837 | fDone = !fImpl->next(); |
| 2838 | } |
| 2839 | |
| 2840 | SkCanvas::LayerIter::~LayerIter() { |
| 2841 | fImpl->~SkDrawIter(); |
| 2842 | } |
| 2843 | |
| 2844 | void SkCanvas::LayerIter::next() { |
| 2845 | fDone = !fImpl->next(); |
| 2846 | } |
| 2847 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 2848 | SkBaseDevice* SkCanvas::LayerIter::device() const { |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 2849 | return fImpl->fDevice; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | const SkMatrix& SkCanvas::LayerIter::matrix() const { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2853 | return fImpl->fDevice->ctm(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | const SkPaint& SkCanvas::LayerIter::paint() const { |
| 2857 | const SkPaint* paint = fImpl->getPaint(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2858 | if (nullptr == paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2859 | paint = &fDefaultPaint; |
| 2860 | } |
| 2861 | return *paint; |
| 2862 | } |
| 2863 | |
Mike Reed | ca37f32 | 2018-03-08 13:22:16 -0500 | [diff] [blame] | 2864 | SkIRect SkCanvas::LayerIter::clipBounds() const { |
| 2865 | return fImpl->fDevice->getGlobalBounds(); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 2866 | } |
| 2867 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2868 | int SkCanvas::LayerIter::x() const { return fImpl->getX(); } |
| 2869 | int SkCanvas::LayerIter::y() const { return fImpl->getY(); } |
justinlin@google.com | 20a550c | 2012-07-27 17:37:12 +0000 | [diff] [blame] | 2870 | |
| 2871 | /////////////////////////////////////////////////////////////////////////////// |
| 2872 | |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 2873 | // TODO: This still disagrees with SkSurfaceValidateRasterInfo |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 2874 | static bool supported_for_raster_canvas(const SkImageInfo& info) { |
| 2875 | switch (info.alphaType()) { |
| 2876 | case kPremul_SkAlphaType: |
| 2877 | case kOpaque_SkAlphaType: |
| 2878 | break; |
| 2879 | default: |
| 2880 | return false; |
| 2881 | } |
| 2882 | |
| 2883 | switch (info.colorType()) { |
| 2884 | case kAlpha_8_SkColorType: |
| 2885 | case kRGB_565_SkColorType: |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 2886 | case kN32_SkColorType: |
junov | 9e3dbdf | 2016-10-13 13:14:27 -0700 | [diff] [blame] | 2887 | case kRGBA_F16_SkColorType: |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 2888 | case kRGBA_F32_SkColorType: |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 2889 | case kRGBA_1010102_SkColorType: |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | default: |
| 2892 | return false; |
| 2893 | } |
| 2894 | |
| 2895 | return true; |
| 2896 | } |
| 2897 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 2898 | std::unique_ptr<SkCanvas> SkCanvas::MakeRasterDirect(const SkImageInfo& info, void* pixels, |
Mike Reed | 12f7734 | 2017-11-08 11:19:52 -0500 | [diff] [blame] | 2899 | size_t rowBytes, const SkSurfaceProps* props) { |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 2900 | if (!supported_for_raster_canvas(info)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2901 | return nullptr; |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 2902 | } |
skia.committer@gmail.com | eb849e5 | 2014-03-17 03:02:17 +0000 | [diff] [blame] | 2903 | |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 2904 | SkBitmap bitmap; |
| 2905 | if (!bitmap.installPixels(info, pixels, rowBytes)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2906 | return nullptr; |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 2907 | } |
Mike Reed | 12f7734 | 2017-11-08 11:19:52 -0500 | [diff] [blame] | 2908 | |
| 2909 | return props ? |
| 2910 | skstd::make_unique<SkCanvas>(bitmap, *props) : |
| 2911 | skstd::make_unique<SkCanvas>(bitmap); |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 2912 | } |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 2913 | |
| 2914 | /////////////////////////////////////////////////////////////////////////////// |
| 2915 | |
Florin Malita | ee424ac | 2016-12-01 12:47:59 -0500 | [diff] [blame] | 2916 | SkNoDrawCanvas::SkNoDrawCanvas(int width, int height) |
| 2917 | : INHERITED(SkIRect::MakeWH(width, height), kConservativeRasterClip_InitFlag) {} |
| 2918 | |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 2919 | SkNoDrawCanvas::SkNoDrawCanvas(const SkIRect& bounds) |
| 2920 | : INHERITED(bounds, kConservativeRasterClip_InitFlag) {} |
| 2921 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2922 | SkNoDrawCanvas::SkNoDrawCanvas(sk_sp<SkBaseDevice> device) |
Herb Derby | 76d69b4 | 2018-03-15 17:34:40 -0400 | [diff] [blame] | 2923 | : INHERITED(device) {} |
| 2924 | |
Florin Malita | ee424ac | 2016-12-01 12:47:59 -0500 | [diff] [blame] | 2925 | SkCanvas::SaveLayerStrategy SkNoDrawCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
| 2926 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
| 2927 | return kNoLayer_SaveLayerStrategy; |
| 2928 | } |
| 2929 | |
| 2930 | /////////////////////////////////////////////////////////////////////////////// |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 2931 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 2932 | static_assert((int)SkRegion::kDifference_Op == (int)kDifference_SkClipOp, ""); |
| 2933 | static_assert((int)SkRegion::kIntersect_Op == (int)kIntersect_SkClipOp, ""); |
| 2934 | static_assert((int)SkRegion::kUnion_Op == (int)kUnion_SkClipOp, ""); |
| 2935 | static_assert((int)SkRegion::kXOR_Op == (int)kXOR_SkClipOp, ""); |
| 2936 | static_assert((int)SkRegion::kReverseDifference_Op == (int)kReverseDifference_SkClipOp, ""); |
| 2937 | static_assert((int)SkRegion::kReplace_Op == (int)kReplace_SkClipOp, ""); |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 2938 | |
| 2939 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2940 | |
| 2941 | SkRasterHandleAllocator::Handle SkCanvas::accessTopRasterHandle() const { |
| 2942 | if (fAllocator && fMCRec->fTopLayer->fDevice) { |
Florin Malita | 713b8ef | 2017-04-28 10:57:24 -0400 | [diff] [blame] | 2943 | const auto& dev = fMCRec->fTopLayer->fDevice; |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 2944 | SkRasterHandleAllocator::Handle handle = dev->getRasterHandle(); |
| 2945 | SkIPoint origin = dev->getOrigin(); |
| 2946 | SkMatrix ctm = this->getTotalMatrix(); |
| 2947 | ctm.preTranslate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); |
| 2948 | |
| 2949 | SkIRect clip = fMCRec->fRasterClip.getBounds(); |
| 2950 | clip.offset(-origin.x(), -origin.y()); |
Mike Reed | 108f55e | 2017-01-12 11:28:01 -0500 | [diff] [blame] | 2951 | if (!clip.intersect(0, 0, dev->width(), dev->height())) { |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 2952 | clip.setEmpty(); |
| 2953 | } |
| 2954 | |
| 2955 | fAllocator->updateHandle(handle, ctm, clip); |
| 2956 | return handle; |
| 2957 | } |
| 2958 | return nullptr; |
| 2959 | } |
| 2960 | |
| 2961 | static bool install(SkBitmap* bm, const SkImageInfo& info, |
| 2962 | const SkRasterHandleAllocator::Rec& rec) { |
Mike Reed | 086a427 | 2017-07-18 10:53:11 -0400 | [diff] [blame] | 2963 | return bm->installPixels(info, rec.fPixels, rec.fRowBytes, rec.fReleaseProc, rec.fReleaseCtx); |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | SkRasterHandleAllocator::Handle SkRasterHandleAllocator::allocBitmap(const SkImageInfo& info, |
| 2967 | SkBitmap* bm) { |
| 2968 | SkRasterHandleAllocator::Rec rec; |
| 2969 | if (!this->allocHandle(info, &rec) || !install(bm, info, rec)) { |
| 2970 | return nullptr; |
| 2971 | } |
| 2972 | return rec.fHandle; |
| 2973 | } |
| 2974 | |
| 2975 | std::unique_ptr<SkCanvas> |
| 2976 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<SkRasterHandleAllocator> alloc, |
| 2977 | const SkImageInfo& info, const Rec* rec) { |
| 2978 | if (!alloc || !supported_for_raster_canvas(info)) { |
| 2979 | return nullptr; |
| 2980 | } |
| 2981 | |
| 2982 | SkBitmap bm; |
| 2983 | Handle hndl; |
| 2984 | |
| 2985 | if (rec) { |
| 2986 | hndl = install(&bm, info, *rec) ? rec->fHandle : nullptr; |
| 2987 | } else { |
| 2988 | hndl = alloc->allocBitmap(info, &bm); |
| 2989 | } |
| 2990 | return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl)) : nullptr; |
| 2991 | } |
Mike Reed | 7c9c9e4 | 2018-01-03 09:23:34 -0500 | [diff] [blame] | 2992 | |
| 2993 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2994 | |
| 2995 | |