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