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 | |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 8 | #include "SkBitmapDevice.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 10 | #include "SkCanvasPriv.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 11 | #include "SkClipStack.h" |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 12 | #include "SkColorFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkDraw.h" |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 14 | #include "SkDrawable.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkDrawFilter.h" |
| 16 | #include "SkDrawLooper.h" |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 17 | #include "SkErrorInternals.h" |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 18 | #include "SkImage.h" |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 19 | #include "SkImage_Base.h" |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 20 | #include "SkImageFilter.h" |
| 21 | #include "SkImageFilterCache.h" |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 22 | #include "SkLatticeIter.h" |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 23 | #include "SkMatrixUtils.h" |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 24 | #include "SkMetaData.h" |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 25 | #include "SkNx.h" |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 26 | #include "SkPaintPriv.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 27 | #include "SkPatchUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | #include "SkPicture.h" |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 29 | #include "SkRasterClip.h" |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 30 | #include "SkReadPixelsRec.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 31 | #include "SkRRect.h" |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 32 | #include "SkShadowPaintFilterCanvas.h" |
| 33 | #include "SkShadowShader.h" |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 34 | #include "SkSmallAllocator.h" |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 35 | #include "SkSpecialImage.h" |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 36 | #include "SkSurface_Base.h" |
fmalita | 7ba7aa7 | 2014-08-29 09:46:36 -0700 | [diff] [blame] | 37 | #include "SkTextBlob.h" |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 38 | #include "SkTextFormatParams.h" |
reed@google.com | a076e9b | 2011-04-06 20:17:29 +0000 | [diff] [blame] | 39 | #include "SkTLazy.h" |
danakj | 8f757f5 | 2014-11-04 11:48:43 -0800 | [diff] [blame] | 40 | #include "SkTraceEvent.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 41 | #include <new> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 43 | #if SK_SUPPORT_GPU |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 44 | #include "GrContext.h" |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 45 | #include "GrRenderTarget.h" |
bsalomon | 614d8f9 | 2016-07-13 15:42:40 -0700 | [diff] [blame] | 46 | #include "SkGrPriv.h" |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 50 | #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
| 51 | |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 52 | //#define SK_SUPPORT_PRECHECK_CLIPRECT |
| 53 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Return true if the drawing this rect would hit every pixels in the canvas. |
| 56 | * |
| 57 | * Returns false if |
| 58 | * - rect does not contain the canvas' bounds |
| 59 | * - paint is not fill |
| 60 | * - paint would blur or otherwise change the coverage of the rect |
| 61 | */ |
| 62 | bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* paint, |
| 63 | ShaderOverrideOpacity overrideOpacity) const { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 64 | static_assert((int)SkPaintPriv::kNone_ShaderOverrideOpacity == |
| 65 | (int)kNone_ShaderOverrideOpacity, |
| 66 | "need_matching_enums0"); |
| 67 | static_assert((int)SkPaintPriv::kOpaque_ShaderOverrideOpacity == |
| 68 | (int)kOpaque_ShaderOverrideOpacity, |
| 69 | "need_matching_enums1"); |
| 70 | static_assert((int)SkPaintPriv::kNotOpaque_ShaderOverrideOpacity == |
| 71 | (int)kNotOpaque_ShaderOverrideOpacity, |
| 72 | "need_matching_enums2"); |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 73 | |
| 74 | const SkISize size = this->getBaseLayerSize(); |
| 75 | const SkRect bounds = SkRect::MakeIWH(size.width(), size.height()); |
| 76 | if (!this->getClipStack()->quickContains(bounds)) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | if (rect) { |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 81 | if (!this->getTotalMatrix().isScaleTranslate()) { |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 82 | return false; // conservative |
| 83 | } |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 84 | |
| 85 | SkRect devRect; |
| 86 | this->getTotalMatrix().mapRectScaleTranslate(&devRect, *rect); |
| 87 | if (!devRect.contains(bounds)) { |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (paint) { |
| 93 | SkPaint::Style paintStyle = paint->getStyle(); |
| 94 | if (!(paintStyle == SkPaint::kFill_Style || |
| 95 | paintStyle == SkPaint::kStrokeAndFill_Style)) { |
| 96 | return false; |
| 97 | } |
| 98 | if (paint->getMaskFilter() || paint->getLooper() |
| 99 | || paint->getPathEffect() || paint->getImageFilter()) { |
| 100 | return false; // conservative |
| 101 | } |
| 102 | } |
| 103 | return SkPaintPriv::Overwrites(paint, (SkPaintPriv::ShaderOverrideOpacity)overrideOpacity); |
| 104 | } |
| 105 | |
| 106 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | |
reed | d990e2f | 2014-12-22 11:58:30 -0800 | [diff] [blame] | 108 | static bool gIgnoreSaveLayerBounds; |
| 109 | void SkCanvas::Internal_Private_SetIgnoreSaveLayerBounds(bool ignore) { |
| 110 | gIgnoreSaveLayerBounds = ignore; |
| 111 | } |
| 112 | bool SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds() { |
| 113 | return gIgnoreSaveLayerBounds; |
| 114 | } |
| 115 | |
reed | 0acf1b4 | 2014-12-22 16:12:38 -0800 | [diff] [blame] | 116 | static bool gTreatSpriteAsBitmap; |
| 117 | void SkCanvas::Internal_Private_SetTreatSpriteAsBitmap(bool spriteAsBitmap) { |
| 118 | gTreatSpriteAsBitmap = spriteAsBitmap; |
| 119 | } |
| 120 | bool SkCanvas::Internal_Private_GetTreatSpriteAsBitmap() { |
| 121 | return gTreatSpriteAsBitmap; |
| 122 | } |
| 123 | |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 124 | // experimental for faster tiled drawing... |
| 125 | //#define SK_ENABLE_CLIP_QUICKREJECT |
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 { |
| 186 | DeviceCM* fNext; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 187 | SkBaseDevice* fDevice; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 188 | SkRasterClip fClip; |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 189 | SkPaint* fPaint; // may be null (in the future) |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 190 | const SkMatrix* fMatrix; |
| 191 | SkMatrix fMatrixStorage; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 192 | SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 193 | |
reed | 96e657d | 2015-03-10 17:30:07 -0700 | [diff] [blame] | 194 | DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 195 | bool conservativeRasterClip, const SkMatrix& stashed) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 196 | : fNext(nullptr) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 197 | , fClip(conservativeRasterClip) |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 198 | , fStashedMatrix(stashed) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 199 | { |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 200 | SkSafeRef(device); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 201 | fDevice = device; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 202 | fPaint = paint ? new SkPaint(*paint) : nullptr; |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 203 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 204 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 205 | ~DeviceCM() { |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 206 | SkSafeUnref(fDevice); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 207 | delete fPaint; |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 208 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 209 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 210 | void reset(const SkIRect& bounds) { |
| 211 | SkASSERT(!fPaint); |
| 212 | SkASSERT(!fNext); |
| 213 | SkASSERT(fDevice); |
| 214 | fClip.setRect(bounds); |
| 215 | } |
| 216 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 217 | void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip, |
reed | de6c531 | 2016-09-02 12:10:07 -0700 | [diff] [blame^] | 218 | SkRasterClip* updateClip) { |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 219 | int x = fDevice->getOrigin().x(); |
| 220 | int y = fDevice->getOrigin().y(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | int width = fDevice->width(); |
| 222 | int height = fDevice->height(); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 223 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 224 | if ((x | y) == 0) { |
| 225 | fMatrix = &totalMatrix; |
| 226 | fClip = totalClip; |
| 227 | } else { |
| 228 | fMatrixStorage = totalMatrix; |
| 229 | fMatrixStorage.postTranslate(SkIntToScalar(-x), |
| 230 | SkIntToScalar(-y)); |
| 231 | fMatrix = &fMatrixStorage; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 232 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 233 | totalClip.translate(-x, -y, &fClip); |
| 234 | } |
| 235 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 236 | fClip.op(SkIRect::MakeWH(width, height), SkRegion::kIntersect_Op); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 237 | |
| 238 | // intersect clip, but don't translate it (yet) |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 239 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 240 | if (updateClip) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 241 | updateClip->op(SkIRect::MakeXYWH(x, y, width, height), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 242 | SkRegion::kDifference_Op); |
| 243 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 244 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 245 | #ifdef SK_DEBUG |
| 246 | if (!fClip.isEmpty()) { |
| 247 | SkIRect deviceR; |
| 248 | deviceR.set(0, 0, width, height); |
| 249 | SkASSERT(deviceR.contains(fClip.getBounds())); |
| 250 | } |
| 251 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 252 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | /* This is the record we keep for each save/restore level in the stack. |
| 256 | Since a level optionally copies the matrix and/or stack, we have pointers |
| 257 | for these fields. If the value is copied for this level, the copy is |
| 258 | stored in the ...Storage field, and the pointer points to that. If the |
| 259 | value is not copied for this level, we ignore ...Storage, and just point |
| 260 | at the corresponding value in the previous level in the stack. |
| 261 | */ |
| 262 | class SkCanvas::MCRec { |
| 263 | public: |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 264 | SkDrawFilter* fFilter; // the current filter (or null) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 265 | DeviceCM* fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 266 | /* If there are any layers in the stack, this points to the top-most |
| 267 | one that is at or below this level in the stack (so we know what |
| 268 | bitmap/device to draw into from this level. This value is NOT |
| 269 | reference counted, since the real owner is either our fLayer field, |
| 270 | or a previous one in a lower level.) |
| 271 | */ |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 272 | DeviceCM* fTopLayer; |
| 273 | SkRasterClip fRasterClip; |
| 274 | SkMatrix fMatrix; |
| 275 | int fDeferredSaveCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 276 | |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 277 | // This is the current cumulative depth (aggregate of all done translateZ calls) |
| 278 | SkScalar fCurDrawDepth; |
| 279 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 280 | MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 281 | fFilter = nullptr; |
| 282 | fLayer = nullptr; |
| 283 | fTopLayer = nullptr; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 284 | fMatrix.reset(); |
| 285 | fDeferredSaveCount = 0; |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 286 | fCurDrawDepth = 0; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 287 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 288 | // don't bother initializing fNext |
| 289 | inc_rec(); |
| 290 | } |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 291 | MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix), |
| 292 | fCurDrawDepth(prev.fCurDrawDepth) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 293 | fFilter = SkSafeRef(prev.fFilter); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 294 | fLayer = nullptr; |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 295 | fTopLayer = prev.fTopLayer; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 296 | fDeferredSaveCount = 0; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 297 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 298 | // don't bother initializing fNext |
| 299 | inc_rec(); |
| 300 | } |
| 301 | ~MCRec() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 302 | SkSafeUnref(fFilter); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 303 | delete fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 304 | dec_rec(); |
| 305 | } |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 306 | |
| 307 | void reset(const SkIRect& bounds) { |
| 308 | SkASSERT(fLayer); |
| 309 | SkASSERT(fDeferredSaveCount == 0); |
| 310 | |
| 311 | fMatrix.reset(); |
| 312 | fRasterClip.setRect(bounds); |
| 313 | fLayer->reset(bounds); |
| 314 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 315 | }; |
| 316 | |
| 317 | class SkDrawIter : public SkDraw { |
| 318 | public: |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 319 | SkDrawIter(SkCanvas* canvas) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 320 | canvas = canvas->canvasForDrawIter(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 321 | canvas->updateDeviceCMCache(); |
| 322 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 323 | fClipStack = canvas->fClipStack; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 324 | fCurrLayer = canvas->fMCRec->fTopLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 325 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 326 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 327 | bool next() { |
| 328 | // skip over recs with empty clips |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 329 | while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { |
| 330 | fCurrLayer = fCurrLayer->fNext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 331 | } |
| 332 | |
reed@google.com | f68c5e2 | 2012-02-24 16:38:58 +0000 | [diff] [blame] | 333 | const DeviceCM* rec = fCurrLayer; |
| 334 | if (rec && rec->fDevice) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | |
| 336 | fMatrix = rec->fMatrix; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 337 | fRC = &rec->fClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | fDevice = rec->fDevice; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 339 | if (!fDevice->accessPixels(&fDst)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 340 | fDst.reset(fDevice->imageInfo(), nullptr, 0); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 341 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 342 | fPaint = rec->fPaint; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 343 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 344 | |
| 345 | fCurrLayer = rec->fNext; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 346 | // fCurrLayer may be nullptr now |
reed@android.com | 199f108 | 2009-06-10 02:12:47 +0000 | [diff] [blame] | 347 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | return true; |
| 349 | } |
| 350 | return false; |
| 351 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 352 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 353 | SkBaseDevice* getDevice() const { return fDevice; } |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 354 | const SkRasterClip& getClip() const { return *fRC; } |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 355 | int getX() const { return fDevice->getOrigin().x(); } |
| 356 | int getY() const { return fDevice->getOrigin().y(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 357 | const SkMatrix& getMatrix() const { return *fMatrix; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 358 | const SkPaint* getPaint() const { return fPaint; } |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 359 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 360 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 361 | const DeviceCM* fCurrLayer; |
| 362 | const SkPaint* fPaint; // May be null. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 363 | |
| 364 | typedef SkDraw INHERITED; |
| 365 | }; |
| 366 | |
| 367 | ///////////////////////////////////////////////////////////////////////////// |
| 368 | |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 369 | static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { |
| 370 | return lazy->isValid() ? lazy->get() : lazy->set(orig); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * 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] | 375 | * colorfilter, else return nullptr. |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 376 | */ |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 377 | static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) { |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 378 | SkImageFilter* imgf = paint.getImageFilter(); |
| 379 | if (!imgf) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 380 | return nullptr; |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 381 | } |
| 382 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 383 | SkColorFilter* imgCFPtr; |
| 384 | if (!imgf->asAColorFilter(&imgCFPtr)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 385 | return nullptr; |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 386 | } |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 387 | sk_sp<SkColorFilter> imgCF(imgCFPtr); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 388 | |
| 389 | SkColorFilter* paintCF = paint.getColorFilter(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 390 | if (nullptr == paintCF) { |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 391 | // there is no existing paint colorfilter, so we can just return the imagefilter's |
| 392 | return imgCF; |
| 393 | } |
| 394 | |
| 395 | // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF) |
| 396 | // and we need to combine them into a single colorfilter. |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 397 | return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF)); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 398 | } |
| 399 | |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 400 | /** |
| 401 | * There are many bounds in skia. A circle's bounds is just its center extended by its radius. |
| 402 | * However, if we stroke a circle, then the "bounds" of that is larger, since it will now draw |
| 403 | * outside of its raw-bounds by 1/2 the stroke width. SkPaint has lots of optional |
| 404 | * effects/attributes that can modify the effective bounds of a given primitive -- maskfilters, |
| 405 | * patheffects, stroking, etc. This function takes a raw bounds and a paint, and returns the |
| 406 | * conservative "effective" bounds based on the settings in the paint... with one exception. This |
| 407 | * function does *not* look at the imagefilter, which can also modify the effective bounds. It is |
| 408 | * deliberately ignored. |
| 409 | */ |
| 410 | static const SkRect& apply_paint_to_bounds_sans_imagefilter(const SkPaint& paint, |
| 411 | const SkRect& rawBounds, |
| 412 | SkRect* storage) { |
| 413 | SkPaint tmpUnfiltered(paint); |
| 414 | tmpUnfiltered.setImageFilter(nullptr); |
| 415 | if (tmpUnfiltered.canComputeFastBounds()) { |
| 416 | return tmpUnfiltered.computeFastBounds(rawBounds, storage); |
| 417 | } else { |
| 418 | return rawBounds; |
| 419 | } |
| 420 | } |
| 421 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 422 | class AutoDrawLooper { |
| 423 | public: |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 424 | // "rawBounds" is the original bounds of the primitive about to be drawn, unmodified by the |
| 425 | // paint. It's used to determine the size of the offscreen layer for filters. |
| 426 | // If null, the clip will be used instead. |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 427 | AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, bool skipLayerForImageFilter = false, |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 428 | const SkRect* rawBounds = nullptr) : fOrigPaint(paint) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 429 | fCanvas = canvas; |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 430 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 431 | fFilter = canvas->getDrawFilter(); |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 432 | #else |
| 433 | fFilter = nullptr; |
| 434 | #endif |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 435 | fPaint = &fOrigPaint; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 436 | fSaveCount = canvas->getSaveCount(); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 437 | fTempLayerForImageFilter = false; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 438 | fDone = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 439 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 440 | auto simplifiedCF = image_to_color_filter(fOrigPaint); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 441 | if (simplifiedCF) { |
| 442 | SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 443 | paint->setColorFilter(std::move(simplifiedCF)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 444 | paint->setImageFilter(nullptr); |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 445 | fPaint = paint; |
| 446 | } |
| 447 | |
| 448 | if (!skipLayerForImageFilter && fPaint->getImageFilter()) { |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 449 | /** |
| 450 | * We implement ImageFilters for a given draw by creating a layer, then applying the |
| 451 | * imagefilter to the pixels of that layer (its backing surface/image), and then |
| 452 | * we call restore() to xfer that layer to the main canvas. |
| 453 | * |
| 454 | * 1. SaveLayer (with a paint containing the current imagefilter and xfermode) |
| 455 | * 2. Generate the src pixels: |
| 456 | * Remove the imagefilter and the xfermode from the paint that we (AutoDrawLooper) |
| 457 | * return (fPaint). We then draw the primitive (using srcover) into a cleared |
| 458 | * buffer/surface. |
| 459 | * 3. Restore the layer created in #1 |
| 460 | * The imagefilter is passed the buffer/surface from the layer (now filled with the |
| 461 | * src pixels of the primitive). It returns a new "filtered" buffer, which we |
| 462 | * draw onto the previous layer using the xfermode from the original paint. |
| 463 | */ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 464 | SkPaint tmp; |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 465 | tmp.setImageFilter(fPaint->getImageFilter()); |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 466 | tmp.setXfermode(sk_ref_sp(fPaint->getXfermode())); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 467 | SkRect storage; |
| 468 | if (rawBounds) { |
| 469 | // Make rawBounds include all paint outsets except for those due to image filters. |
| 470 | rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *rawBounds, &storage); |
| 471 | } |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 472 | (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &tmp), |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 473 | SkCanvas::kFullLayer_SaveLayerStrategy); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 474 | fTempLayerForImageFilter = true; |
| 475 | // we remove the imagefilter/xfermode inside doNext() |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 476 | } |
| 477 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 478 | if (SkDrawLooper* looper = paint.getLooper()) { |
| 479 | void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Context>( |
| 480 | looper->contextSize()); |
| 481 | fLooperContext = looper->createContext(canvas, buffer); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 482 | fIsSimple = false; |
| 483 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 484 | fLooperContext = nullptr; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 485 | // can we be marked as simple? |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 486 | fIsSimple = !fFilter && !fTempLayerForImageFilter; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 487 | } |
| 488 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 489 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 490 | ~AutoDrawLooper() { |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 491 | if (fTempLayerForImageFilter) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 492 | fCanvas->internalRestore(); |
| 493 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 494 | SkASSERT(fCanvas->getSaveCount() == fSaveCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 495 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 496 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 497 | const SkPaint& paint() const { |
| 498 | SkASSERT(fPaint); |
| 499 | return *fPaint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 500 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 501 | |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 502 | bool next(SkDrawFilter::Type drawType) { |
| 503 | if (fDone) { |
| 504 | return false; |
| 505 | } else if (fIsSimple) { |
| 506 | fDone = true; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 507 | return !fPaint->nothingToDraw(); |
| 508 | } else { |
| 509 | return this->doNext(drawType); |
| 510 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 511 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 512 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 513 | private: |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 514 | SkLazyPaint fLazyPaintInit; // base paint storage in case we need to modify it |
| 515 | 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] | 516 | SkCanvas* fCanvas; |
| 517 | const SkPaint& fOrigPaint; |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 518 | SkDrawFilter* fFilter; |
| 519 | const SkPaint* fPaint; |
| 520 | int fSaveCount; |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 521 | bool fTempLayerForImageFilter; |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 522 | bool fDone; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 523 | bool fIsSimple; |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 524 | SkDrawLooper::Context* fLooperContext; |
| 525 | SkSmallAllocator<1, 32> fLooperContextAllocator; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 526 | |
| 527 | bool doNext(SkDrawFilter::Type drawType); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 528 | }; |
| 529 | |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 530 | bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 531 | fPaint = nullptr; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 532 | SkASSERT(!fIsSimple); |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 533 | SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 534 | |
reed | dbc3cef | 2015-04-29 12:18:57 -0700 | [diff] [blame] | 535 | SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? |
| 536 | *fLazyPaintInit.get() : fOrigPaint); |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 537 | |
reed | 5c476fb | 2015-04-20 08:04:21 -0700 | [diff] [blame] | 538 | if (fTempLayerForImageFilter) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 539 | paint->setImageFilter(nullptr); |
| 540 | paint->setXfermode(nullptr); |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 541 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 542 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 543 | if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 544 | fDone = true; |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | if (fFilter) { |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 548 | if (!fFilter->filter(paint, drawType)) { |
| 549 | fDone = true; |
| 550 | return false; |
| 551 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 552 | if (nullptr == fLooperContext) { |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 553 | // no looper means we only draw once |
| 554 | fDone = true; |
| 555 | } |
| 556 | } |
| 557 | fPaint = paint; |
| 558 | |
| 559 | // if we only came in here for the imagefilter, mark us as done |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 560 | if (!fLooperContext && !fFilter) { |
reed@google.com | 129ec22 | 2012-05-15 13:24:09 +0000 | [diff] [blame] | 561 | fDone = true; |
reed@google.com | 632e1a2 | 2011-10-06 12:37:00 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // call this after any possible paint modifiers |
| 565 | if (fPaint->nothingToDraw()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 566 | fPaint = nullptr; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 567 | return false; |
| 568 | } |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 569 | return true; |
| 570 | } |
| 571 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 572 | ////////// macros to place around the internal draw calls ////////////////// |
| 573 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 574 | #define LOOPER_BEGIN_DRAWBITMAP(paint, skipLayerForFilter, bounds) \ |
| 575 | this->predrawNotify(); \ |
| 576 | AutoDrawLooper looper(this, paint, skipLayerForFilter, bounds); \ |
| 577 | while (looper.next(SkDrawFilter::kBitmap_Type)) { \ |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 578 | SkDrawIter iter(this); |
| 579 | |
| 580 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 581 | #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 582 | this->predrawNotify(); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 583 | AutoDrawLooper looper(this, paint, true); \ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 584 | while (looper.next(type)) { \ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 585 | SkDrawIter iter(this); |
| 586 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 587 | #define LOOPER_BEGIN(paint, type, bounds) \ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 588 | this->predrawNotify(); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 589 | AutoDrawLooper looper(this, paint, false, bounds); \ |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 590 | while (looper.next(type)) { \ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 591 | SkDrawIter iter(this); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 592 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 593 | #define LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, type, bounds, auxOpaque) \ |
| 594 | this->predrawNotify(bounds, &paint, auxOpaque); \ |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 595 | AutoDrawLooper looper(this, paint, false, bounds); \ |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 596 | while (looper.next(type)) { \ |
| 597 | SkDrawIter iter(this); |
| 598 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 599 | #define LOOPER_END } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 600 | |
| 601 | //////////////////////////////////////////////////////////////////////////// |
| 602 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 603 | static inline SkRect qr_clip_bounds(const SkIRect& bounds) { |
| 604 | if (bounds.isEmpty()) { |
| 605 | return SkRect::MakeEmpty(); |
| 606 | } |
| 607 | |
| 608 | // Expand bounds out by 1 in case we are anti-aliasing. We store the |
| 609 | // bounds as floats to enable a faster quick reject implementation. |
| 610 | SkRect dst; |
| 611 | SkNx_cast<float>(Sk4i::Load(&bounds.fLeft) + Sk4i(-1,-1,1,1)).store(&dst.fLeft); |
| 612 | return dst; |
| 613 | } |
| 614 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 615 | void SkCanvas::resetForNextPicture(const SkIRect& bounds) { |
| 616 | this->restoreToCount(1); |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 617 | fClipStack->reset(); |
| 618 | fMCRec->reset(bounds); |
| 619 | |
| 620 | // We're peering through a lot of structs here. Only at this scope do we |
| 621 | // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevice). |
| 622 | static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.size()); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 623 | fDeviceClipBounds = qr_clip_bounds(bounds); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 624 | fIsScaleTranslate = true; |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 625 | } |
| 626 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 627 | SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 628 | if (device && device->forceConservativeRasterClip()) { |
| 629 | flags = InitFlags(flags | kConservativeRasterClip_InitFlag); |
| 630 | } |
| 631 | // Since init() is only called once by our constructors, it is safe to perform this |
| 632 | // const-cast. |
| 633 | *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativeRasterClip_InitFlag); |
| 634 | |
caryclark@google.com | 8f0a7b8 | 2012-11-07 14:54:49 +0000 | [diff] [blame] | 635 | fAllowSoftClip = true; |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 636 | fAllowSimplifyClip = false; |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 637 | fDeviceCMDirty = true; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 638 | fSaveCount = 1; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 639 | fMetaData = nullptr; |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 640 | #ifdef SK_EXPERIMENTAL_SHADOWING |
| 641 | fLights = nullptr; |
| 642 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 643 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 644 | fClipStack.reset(new SkClipStack); |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 645 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 646 | fMCRec = (MCRec*)fMCStack.push_back(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 647 | new (fMCRec) MCRec(fConservativeRasterClip); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 648 | fIsScaleTranslate = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 649 | |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 650 | SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); |
| 651 | fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 652 | new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRasterClip, |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 653 | fMCRec->fMatrix); |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 654 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 655 | fMCRec->fTopLayer = fMCRec->fLayer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 656 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 657 | fSurfaceBase = nullptr; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 658 | |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 659 | if (device) { |
robertphillips | efbffed | 2015-06-22 12:06:08 -0700 | [diff] [blame] | 660 | // The root device and the canvas should always have the same pixel geometry |
| 661 | SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry()); |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 662 | fMCRec->fLayer->fDevice = SkRef(device); |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 663 | fMCRec->fRasterClip.setRect(device->getGlobalBounds()); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 664 | fDeviceClipBounds = qr_clip_bounds(device->getGlobalBounds()); |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 665 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 666 | |
reed | f92c866 | 2014-08-18 08:02:43 -0700 | [diff] [blame] | 667 | return device; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 668 | } |
| 669 | |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 670 | SkCanvas::SkCanvas() |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 671 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 672 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 673 | , fConservativeRasterClip(false) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 674 | { |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 675 | inc_canvas(); |
skia.committer@gmail.com | ba12448 | 2014-02-01 03:01:57 +0000 | [diff] [blame] | 676 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 677 | this->init(nullptr, kDefault_InitFlags); |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 678 | } |
| 679 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 680 | static SkBitmap make_nopixels(int width, int height) { |
| 681 | SkBitmap bitmap; |
| 682 | bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
| 683 | return bitmap; |
| 684 | } |
| 685 | |
| 686 | class SkNoPixelsBitmapDevice : public SkBitmapDevice { |
| 687 | public: |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 688 | SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceProps) |
| 689 | : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps) |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 690 | { |
| 691 | this->setOrigin(bounds.x(), bounds.y()); |
| 692 | } |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 693 | |
| 694 | private: |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 695 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 696 | typedef SkBitmapDevice INHERITED; |
| 697 | }; |
| 698 | |
reed | 96a857e | 2015-01-25 10:33:58 -0800 | [diff] [blame] | 699 | SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 700 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 96a857e | 2015-01-25 10:33:58 -0800 | [diff] [blame] | 701 | , fProps(SkSurfacePropsCopyOrDefault(props)) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 702 | , fConservativeRasterClip(false) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 703 | { |
| 704 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 705 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 706 | this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps), |
| 707 | kDefault_InitFlags)->unref(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 708 | } |
skia.committer@gmail.com | ba12448 | 2014-02-01 03:01:57 +0000 | [diff] [blame] | 709 | |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 710 | SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 711 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 712 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 713 | , fConservativeRasterClip(false) |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 714 | { |
| 715 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 716 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 717 | this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags)->unref(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 718 | } |
| 719 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 720 | SkCanvas::SkCanvas(SkBaseDevice* device) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 721 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
robertphillips | 7b05ff1 | 2015-06-19 14:14:54 -0700 | [diff] [blame] | 722 | , fProps(device->surfaceProps()) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 723 | , fConservativeRasterClip(false) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 724 | { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 725 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 726 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 727 | this->init(device, kDefault_InitFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 728 | } |
| 729 | |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 730 | SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) |
| 731 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
robertphillips | 7b05ff1 | 2015-06-19 14:14:54 -0700 | [diff] [blame] | 732 | , fProps(device->surfaceProps()) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 733 | , fConservativeRasterClip(false) |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 734 | { |
| 735 | inc_canvas(); |
| 736 | |
| 737 | this->init(device, flags); |
| 738 | } |
| 739 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 740 | SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame] | 741 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 742 | , fProps(props) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 743 | , fConservativeRasterClip(false) |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame] | 744 | { |
| 745 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 746 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 747 | SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 748 | this->init(device, kDefault_InitFlags); |
| 749 | } |
reed | 29c857d | 2014-09-21 10:25:07 -0700 | [diff] [blame] | 750 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 751 | SkCanvas::SkCanvas(const SkBitmap& bitmap) |
| 752 | : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 753 | , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
reed | 42b73eb | 2015-11-20 13:42:42 -0800 | [diff] [blame] | 754 | , fConservativeRasterClip(false) |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 755 | { |
| 756 | inc_canvas(); |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 757 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 758 | SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 759 | this->init(device, kDefault_InitFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | SkCanvas::~SkCanvas() { |
| 763 | // free up the contents of our deque |
| 764 | this->restoreToCount(1); // restore everything but the last |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 765 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 766 | this->internalRestore(); // restore the last, since we're going away |
| 767 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 768 | delete fMetaData; |
vandebo@chromium.org | b70ae31 | 2010-10-15 18:58:19 +0000 | [diff] [blame] | 769 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 770 | dec_canvas(); |
| 771 | } |
| 772 | |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 773 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 774 | SkDrawFilter* SkCanvas::getDrawFilter() const { |
| 775 | return fMCRec->fFilter; |
| 776 | } |
| 777 | |
| 778 | SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 779 | this->checkForDeferredSave(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 780 | SkRefCnt_SafeAssign(fMCRec->fFilter, filter); |
| 781 | return filter; |
| 782 | } |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 783 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 784 | |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 785 | SkMetaData& SkCanvas::getMetaData() { |
| 786 | // metadata users are rare, so we lazily allocate it. If that changes we |
| 787 | // 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] | 788 | if (nullptr == fMetaData) { |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 789 | fMetaData = new SkMetaData; |
| 790 | } |
| 791 | return *fMetaData; |
| 792 | } |
| 793 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 794 | /////////////////////////////////////////////////////////////////////////////// |
| 795 | |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 796 | void SkCanvas::flush() { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 797 | this->onFlush(); |
| 798 | } |
| 799 | |
| 800 | void SkCanvas::onFlush() { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 801 | SkBaseDevice* device = this->getDevice(); |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 802 | if (device) { |
| 803 | device->flush(); |
| 804 | } |
| 805 | } |
| 806 | |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 807 | SkISize SkCanvas::getBaseLayerSize() const { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 808 | SkBaseDevice* d = this->getDevice(); |
reed@google.com | 210ce00 | 2011-11-01 14:24:23 +0000 | [diff] [blame] | 809 | return d ? SkISize::Make(d->width(), d->height()) : SkISize::Make(0, 0); |
| 810 | } |
| 811 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 812 | SkIRect SkCanvas::getTopLayerBounds() const { |
| 813 | SkBaseDevice* d = this->getTopDevice(); |
| 814 | if (!d) { |
| 815 | return SkIRect::MakeEmpty(); |
| 816 | } |
| 817 | return SkIRect::MakeXYWH(d->getOrigin().x(), d->getOrigin().y(), d->width(), d->height()); |
| 818 | } |
| 819 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 820 | SkBaseDevice* SkCanvas::getDevice() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 821 | // return root device |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 822 | MCRec* rec = (MCRec*) fMCStack.front(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 823 | SkASSERT(rec && rec->fLayer); |
| 824 | return rec->fLayer->fDevice; |
| 825 | } |
| 826 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 827 | SkBaseDevice* SkCanvas::getTopDevice(bool updateMatrixClip) const { |
reed@google.com | 0b53d59 | 2012-03-19 18:26:34 +0000 | [diff] [blame] | 828 | if (updateMatrixClip) { |
| 829 | const_cast<SkCanvas*>(this)->updateDeviceCMCache(); |
| 830 | } |
reed@google.com | 9266fed | 2011-03-30 00:18:03 +0000 | [diff] [blame] | 831 | return fMCRec->fTopLayer->fDevice; |
| 832 | } |
| 833 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 834 | bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 835 | if (kUnknown_SkColorType == bitmap->colorType()) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 836 | return false; |
| 837 | } |
| 838 | |
| 839 | bool weAllocated = false; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 840 | if (nullptr == bitmap->pixelRef()) { |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 841 | if (!bitmap->tryAllocPixels()) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 842 | return false; |
| 843 | } |
| 844 | weAllocated = true; |
| 845 | } |
| 846 | |
reed | cf01e31 | 2015-05-23 19:14:51 -0700 | [diff] [blame] | 847 | SkAutoPixmapUnlock unlocker; |
| 848 | if (bitmap->requestLock(&unlocker)) { |
| 849 | const SkPixmap& pm = unlocker.pixmap(); |
| 850 | if (this->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), x, y)) { |
| 851 | return true; |
| 852 | } |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if (weAllocated) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 856 | bitmap->setPixelRef(nullptr); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 857 | } |
| 858 | return false; |
| 859 | } |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 860 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 861 | bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 862 | SkIRect r = srcRect; |
| 863 | const SkISize size = this->getBaseLayerSize(); |
| 864 | if (!r.intersect(0, 0, size.width(), size.height())) { |
| 865 | bitmap->reset(); |
| 866 | return false; |
| 867 | } |
| 868 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 869 | if (!bitmap->tryAllocN32Pixels(r.width(), r.height())) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 870 | // bitmap will already be reset. |
| 871 | return false; |
| 872 | } |
| 873 | if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), r.x(), r.y())) { |
| 874 | bitmap->reset(); |
| 875 | return false; |
| 876 | } |
| 877 | return true; |
| 878 | } |
| 879 | |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 880 | bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 881 | SkBaseDevice* device = this->getDevice(); |
djsollen@google.com | ccfee2a | 2012-05-01 16:50:10 +0000 | [diff] [blame] | 882 | if (!device) { |
| 883 | return false; |
| 884 | } |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 885 | const SkISize size = this->getBaseLayerSize(); |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 886 | |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 887 | SkReadPixelsRec rec(dstInfo, dstP, rowBytes, x, y); |
| 888 | if (!rec.trim(size.width(), size.height())) { |
bsalomon@google.com | daba14b | 2011-11-02 20:10:48 +0000 | [diff] [blame] | 889 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 890 | } |
skia.committer@gmail.com | db0c875 | 2014-03-18 03:02:11 +0000 | [diff] [blame] | 891 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 892 | // The device can assert that the requested area is always contained in its bounds |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 893 | return device->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY); |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 894 | } |
| 895 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 896 | bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { |
reed | cf01e31 | 2015-05-23 19:14:51 -0700 | [diff] [blame] | 897 | SkAutoPixmapUnlock unlocker; |
| 898 | if (bitmap.requestLock(&unlocker)) { |
| 899 | const SkPixmap& pm = unlocker.pixmap(); |
| 900 | 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] | 901 | } |
| 902 | return false; |
| 903 | } |
| 904 | |
| 905 | bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size_t rowBytes, |
| 906 | int x, int y) { |
| 907 | switch (origInfo.colorType()) { |
| 908 | case kUnknown_SkColorType: |
| 909 | case kIndex_8_SkColorType: |
| 910 | return false; |
| 911 | default: |
| 912 | break; |
| 913 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 914 | if (nullptr == pixels || rowBytes < origInfo.minRowBytes()) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 915 | return false; |
| 916 | } |
| 917 | |
| 918 | const SkISize size = this->getBaseLayerSize(); |
| 919 | SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height()); |
| 920 | if (!target.intersect(0, 0, size.width(), size.height())) { |
| 921 | return false; |
| 922 | } |
| 923 | |
| 924 | SkBaseDevice* device = this->getDevice(); |
| 925 | if (!device) { |
| 926 | return false; |
| 927 | } |
| 928 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 929 | // the intersect may have shrunk info's logical size |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 930 | const SkImageInfo info = origInfo.makeWH(target.width(), target.height()); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 931 | |
| 932 | // if x or y are negative, then we have to adjust pixels |
| 933 | if (x > 0) { |
| 934 | x = 0; |
| 935 | } |
| 936 | if (y > 0) { |
| 937 | y = 0; |
| 938 | } |
| 939 | // here x,y are either 0 or negative |
| 940 | pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel()); |
| 941 | |
reed | 4af35f3 | 2014-06-27 17:47:49 -0700 | [diff] [blame] | 942 | // Tell our owning surface to bump its generation ID |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 943 | const bool completeOverwrite = info.dimensions() == size; |
| 944 | this->predrawNotify(completeOverwrite); |
reed | 4af35f3 | 2014-06-27 17:47:49 -0700 | [diff] [blame] | 945 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 946 | // The device can assert that the requested area is always contained in its bounds |
commit-bot@chromium.org | 4ef54f8 | 2014-03-17 17:03:18 +0000 | [diff] [blame] | 947 | return device->writePixels(info, pixels, rowBytes, target.x(), target.y()); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 948 | } |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 949 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 950 | SkCanvas* SkCanvas::canvasForDrawIter() { |
| 951 | return this; |
| 952 | } |
| 953 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 954 | ////////////////////////////////////////////////////////////////////////////// |
| 955 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 956 | void SkCanvas::updateDeviceCMCache() { |
| 957 | if (fDeviceCMDirty) { |
| 958 | const SkMatrix& totalMatrix = this->getTotalMatrix(); |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 959 | const SkRasterClip& totalClip = fMCRec->fRasterClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 960 | DeviceCM* layer = fMCRec->fTopLayer; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 961 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 962 | if (nullptr == layer->fNext) { // only one layer |
reed | de6c531 | 2016-09-02 12:10:07 -0700 | [diff] [blame^] | 963 | layer->updateMC(totalMatrix, totalClip, nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 964 | } else { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 965 | SkRasterClip clip(totalClip); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 966 | do { |
reed | de6c531 | 2016-09-02 12:10:07 -0700 | [diff] [blame^] | 967 | layer->updateMC(totalMatrix, clip, &clip); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 968 | } while ((layer = layer->fNext) != nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 969 | } |
| 970 | fDeviceCMDirty = false; |
| 971 | } |
| 972 | } |
| 973 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 974 | /////////////////////////////////////////////////////////////////////////////// |
| 975 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 976 | void SkCanvas::checkForDeferredSave() { |
| 977 | if (fMCRec->fDeferredSaveCount > 0) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 978 | this->doSave(); |
| 979 | } |
| 980 | } |
| 981 | |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 982 | int SkCanvas::getSaveCount() const { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 983 | #ifdef SK_DEBUG |
| 984 | int count = 0; |
| 985 | SkDeque::Iter iter(fMCStack, SkDeque::Iter::kFront_IterStart); |
| 986 | for (;;) { |
| 987 | const MCRec* rec = (const MCRec*)iter.next(); |
| 988 | if (!rec) { |
| 989 | break; |
| 990 | } |
| 991 | count += 1 + rec->fDeferredSaveCount; |
| 992 | } |
| 993 | SkASSERT(count == fSaveCount); |
| 994 | #endif |
| 995 | return fSaveCount; |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | int SkCanvas::save() { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 999 | fSaveCount += 1; |
| 1000 | fMCRec->fDeferredSaveCount += 1; |
| 1001 | return this->getSaveCount() - 1; // return our prev value |
| 1002 | } |
| 1003 | |
| 1004 | void SkCanvas::doSave() { |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 1005 | this->willSave(); |
fmalita | a62d32d | 2015-04-28 08:08:57 -0700 | [diff] [blame] | 1006 | |
| 1007 | SkASSERT(fMCRec->fDeferredSaveCount > 0); |
| 1008 | fMCRec->fDeferredSaveCount -= 1; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1009 | this->internalSave(); |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | void SkCanvas::restore() { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1013 | if (fMCRec->fDeferredSaveCount > 0) { |
| 1014 | SkASSERT(fSaveCount > 1); |
| 1015 | fSaveCount -= 1; |
| 1016 | fMCRec->fDeferredSaveCount -= 1; |
| 1017 | } else { |
| 1018 | // check for underflow |
| 1019 | if (fMCStack.count() > 1) { |
| 1020 | this->willRestore(); |
| 1021 | SkASSERT(fSaveCount > 1); |
reed | a644116 | 2015-03-26 13:40:09 -0700 | [diff] [blame] | 1022 | fSaveCount -= 1; |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1023 | this->internalRestore(); |
| 1024 | this->didRestore(); |
| 1025 | } |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | void SkCanvas::restoreToCount(int count) { |
| 1030 | // sanity check |
| 1031 | if (count < 1) { |
| 1032 | count = 1; |
| 1033 | } |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 1034 | |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 1035 | int n = this->getSaveCount() - count; |
| 1036 | for (int i = 0; i < n; ++i) { |
| 1037 | this->restore(); |
| 1038 | } |
| 1039 | } |
| 1040 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1041 | void SkCanvas::internalSave() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1042 | MCRec* newTop = (MCRec*)fMCStack.push_back(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 1043 | new (newTop) MCRec(*fMCRec); // balanced in restore() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1044 | fMCRec = newTop; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1045 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1046 | fClipStack->save(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1049 | bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) { |
reed@google.com | b93ba45 | 2014-03-10 19:47:58 +0000 | [diff] [blame] | 1050 | #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1051 | return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag); |
reed@google.com | b93ba45 | 2014-03-10 19:47:58 +0000 | [diff] [blame] | 1052 | #else |
| 1053 | return true; |
| 1054 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1057 | bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlags, |
reed | 9b3aa54 | 2015-03-11 08:47:12 -0700 | [diff] [blame] | 1058 | SkIRect* intersection, const SkImageFilter* imageFilter) { |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1059 | SkIRect clipBounds; |
| 1060 | if (!this->getClipDeviceBounds(&clipBounds)) { |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1061 | return false; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1062 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1063 | |
reed | 96e657d | 2015-03-10 17:30:07 -0700 | [diff] [blame] | 1064 | const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix() |
| 1065 | |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1066 | if (imageFilter) { |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 1067 | clipBounds = imageFilter->filterBounds(clipBounds, ctm); |
senorblanco | db64af3 | 2015-12-09 10:11:43 -0800 | [diff] [blame] | 1068 | if (bounds && !imageFilter->canComputeFastBounds()) { |
| 1069 | bounds = nullptr; |
| 1070 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1071 | } |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1072 | SkIRect ir; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1073 | if (bounds) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1074 | SkRect r; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1075 | |
reed | 96e657d | 2015-03-10 17:30:07 -0700 | [diff] [blame] | 1076 | ctm.mapRect(&r, *bounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1077 | r.roundOut(&ir); |
| 1078 | // early exit if the layer's bounds are clipped out |
| 1079 | if (!ir.intersect(clipBounds)) { |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1080 | if (BoundsAffectsClip(saveLayerFlags)) { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1081 | fMCRec->fRasterClip.setEmpty(); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1082 | fDeviceClipBounds.setEmpty(); |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1083 | } |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1084 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1085 | } |
| 1086 | } else { // no user bounds, so just use the clip |
| 1087 | ir = clipBounds; |
| 1088 | } |
reed | 180aec4 | 2015-03-11 10:39:04 -0700 | [diff] [blame] | 1089 | SkASSERT(!ir.isEmpty()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1090 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1091 | if (BoundsAffectsClip(saveLayerFlags)) { |
reed | 180aec4 | 2015-03-11 10:39:04 -0700 | [diff] [blame] | 1092 | // Simplify the current clips since they will be applied properly during restore() |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1093 | fClipStack->clipDevRect(ir, SkRegion::kReplace_Op); |
reed | 180aec4 | 2015-03-11 10:39:04 -0700 | [diff] [blame] | 1094 | fMCRec->fRasterClip.setRect(ir); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1095 | fDeviceClipBounds = qr_clip_bounds(ir); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | if (intersection) { |
| 1099 | *intersection = ir; |
| 1100 | } |
| 1101 | return true; |
| 1102 | } |
| 1103 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1104 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1105 | int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { |
| 1106 | return this->saveLayer(SaveLayerRec(bounds, paint, 0)); |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1109 | int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) { |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1110 | return this->saveLayer(SaveLayerRec(bounds, paint, kPreserveLCDText_SaveLayerFlag)); |
| 1111 | } |
| 1112 | |
| 1113 | int SkCanvas::saveLayer(const SaveLayerRec& origRec) { |
| 1114 | SaveLayerRec rec(origRec); |
| 1115 | if (gIgnoreSaveLayerBounds) { |
| 1116 | rec.fBounds = nullptr; |
| 1117 | } |
| 1118 | SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); |
| 1119 | fSaveCount += 1; |
| 1120 | this->internalSaveLayer(rec, strategy); |
| 1121 | return this->getSaveCount() - 1; |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1124 | void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter, |
| 1125 | SkBaseDevice* dst, const SkMatrix& ctm, |
| 1126 | const SkClipStack* clipStack) { |
| 1127 | SkDraw draw; |
| 1128 | SkRasterClip rc; |
| 1129 | rc.setRect(SkIRect::MakeWH(dst->width(), dst->height())); |
| 1130 | if (!dst->accessPixels(&draw.fDst)) { |
| 1131 | draw.fDst.reset(dst->imageInfo(), nullptr, 0); |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 1132 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1133 | draw.fMatrix = &SkMatrix::I(); |
| 1134 | draw.fRC = &rc; |
| 1135 | draw.fClipStack = clipStack; |
| 1136 | draw.fDevice = dst; |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 1137 | |
| 1138 | SkPaint p; |
robertphillips | 372177e | 2016-03-30 07:32:28 -0700 | [diff] [blame] | 1139 | p.setImageFilter(filter->makeWithLocalMatrix(ctm)); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1140 | |
| 1141 | int x = src->getOrigin().x() - dst->getOrigin().x(); |
| 1142 | int y = src->getOrigin().y() - dst->getOrigin().y(); |
| 1143 | auto special = src->snapSpecial(); |
| 1144 | if (special) { |
| 1145 | dst->drawSpecial(draw, special.get(), x, y, p); |
| 1146 | } |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 1147 | } |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1148 | |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1149 | static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool isOpaque, |
| 1150 | const SkPaint* paint) { |
| 1151 | // need to force L32 for now if we have an image filter. Once filters support other colortypes |
| 1152 | // e.g. sRGB or F16, we can remove this check |
brianosman | 52ede1d | 2016-06-20 08:25:02 -0700 | [diff] [blame] | 1153 | // SRGBTODO: Can we remove this check now? |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1154 | const bool hasImageFilter = paint && paint->getImageFilter(); |
| 1155 | |
| 1156 | SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 1157 | if ((prev.bytesPerPixel() < 4) || hasImageFilter) { |
| 1158 | // force to L32 |
| 1159 | return SkImageInfo::MakeN32(w, h, alphaType); |
| 1160 | } else { |
| 1161 | // keep the same characteristics as the prev |
brianosman | 52ede1d | 2016-06-20 08:25:02 -0700 | [diff] [blame] | 1162 | return SkImageInfo::Make(w, h, prev.colorType(), alphaType, sk_ref_sp(prev.colorSpace())); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1166 | void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy strategy) { |
| 1167 | const SkRect* bounds = rec.fBounds; |
| 1168 | const SkPaint* paint = rec.fPaint; |
| 1169 | SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; |
| 1170 | |
reed@google.com | b93ba45 | 2014-03-10 19:47:58 +0000 | [diff] [blame] | 1171 | #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1172 | saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; |
reed@google.com | b93ba45 | 2014-03-10 19:47:58 +0000 | [diff] [blame] | 1173 | #endif |
| 1174 | |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1175 | SkLazyPaint lazyP; |
| 1176 | SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; |
| 1177 | SkMatrix stashedMatrix = fMCRec->fMatrix; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1178 | SkMatrix remainder; |
| 1179 | SkSize scale; |
| 1180 | /* |
| 1181 | * ImageFilters (so far) do not correctly handle matrices (CTM) that contain rotation/skew/etc. |
| 1182 | * but they do handle scaling. To accommodate this, we do the following: |
| 1183 | * |
| 1184 | * 1. Stash off the current CTM |
| 1185 | * 2. Decompose the CTM into SCALE and REMAINDER |
| 1186 | * 3. Wack the CTM to be just SCALE, and wrap the imagefilter with a MatrixImageFilter that |
| 1187 | * contains the REMAINDER |
| 1188 | * 4. Proceed as usual, allowing the client to draw into the layer (now with a scale-only CTM) |
| 1189 | * 5. During restore, we process the MatrixImageFilter, which applies REMAINDER to the output |
| 1190 | * of the original imagefilter, and draw that (via drawSprite) |
| 1191 | * 6. Unwack the CTM to its original state (i.e. stashedMatrix) |
| 1192 | * |
| 1193 | * Perhaps in the future we could augment #5 to apply REMAINDER as part of the draw (no longer |
| 1194 | * a sprite operation) to avoid the extra buffer/overhead of MatrixImageFilter. |
| 1195 | */ |
reed | 96a04f3 | 2016-04-25 09:25:15 -0700 | [diff] [blame] | 1196 | if (imageFilter && !stashedMatrix.isScaleTranslate() && !imageFilter->canHandleComplexCTM() && |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1197 | stashedMatrix.decomposeScale(&scale, &remainder)) |
| 1198 | { |
| 1199 | // We will restore the matrix (which we are overwriting here) in restore via fStashedMatrix |
| 1200 | this->internalSetMatrix(SkMatrix::MakeScale(scale.width(), scale.height())); |
| 1201 | SkPaint* p = lazyP.set(*paint); |
| 1202 | p->setImageFilter(SkImageFilter::MakeMatrixFilter(remainder, |
| 1203 | SkFilterQuality::kLow_SkFilterQuality, |
| 1204 | sk_ref_sp(imageFilter))); |
| 1205 | imageFilter = p->getImageFilter(); |
| 1206 | paint = p; |
| 1207 | } |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1208 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1209 | // do this before we create the layer. We don't call the public save() since |
| 1210 | // that would invoke a possibly overridden virtual |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1211 | this->internalSave(); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1212 | |
| 1213 | fDeviceCMDirty = true; |
| 1214 | |
| 1215 | SkIRect ir; |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1216 | if (!this->clipRectBounds(bounds, saveLayerFlags, &ir, imageFilter)) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1217 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1220 | // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about |
| 1221 | // the clipRectBounds() call above? |
| 1222 | if (kNoLayer_SaveLayerStrategy == strategy) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1223 | return; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1226 | bool isOpaque = SkToBool(saveLayerFlags & kIsOpaque_SaveLayerFlag); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 1227 | SkPixelGeometry geo = fProps.pixelGeometry(); |
| 1228 | if (paint) { |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1229 | // TODO: perhaps add a query to filters so we might preserve opaqueness... |
reed | daa57bf | 2015-05-15 10:39:17 -0700 | [diff] [blame] | 1230 | if (paint->getImageFilter() || paint->getColorFilter()) { |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1231 | isOpaque = false; |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 1232 | geo = kUnknown_SkPixelGeometry; |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 1233 | } |
| 1234 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1235 | |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1236 | SkBaseDevice* priorDevice = this->getTopDevice(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1237 | if (nullptr == priorDevice) { |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1238 | SkDebugf("Unable to find device for layer."); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1239 | return; |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1240 | } |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1241 | |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1242 | SkImageInfo info = make_layer_info(priorDevice->imageInfo(), ir.width(), ir.height(), isOpaque, |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1243 | paint); |
| 1244 | |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1245 | SkAutoTUnref<SkBaseDevice> newDevice; |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 1246 | { |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1247 | const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() || |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1248 | (saveLayerFlags & kPreserveLCDText_SaveLayerFlag); |
reed | daa57bf | 2015-05-15 10:39:17 -0700 | [diff] [blame] | 1249 | const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 1250 | const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo, |
reed | cd4051e | 2016-07-15 09:41:26 -0700 | [diff] [blame] | 1251 | preserveLCDText); |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1252 | newDevice.reset(priorDevice->onCreateDevice(createInfo, paint)); |
| 1253 | if (!newDevice) { |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 1254 | SkErrorInternals::SetError(kInternalError_SkError, |
| 1255 | "Unable to create device for layer."); |
| 1256 | return; |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 1257 | } |
bungeman@google.com | e25c684 | 2011-08-17 14:53:54 +0000 | [diff] [blame] | 1258 | } |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1259 | newDevice->setOrigin(ir.fLeft, ir.fTop); |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 1260 | |
robertphillips | 5139e50 | 2016-07-19 05:10:40 -0700 | [diff] [blame] | 1261 | DeviceCM* layer = new DeviceCM(newDevice, paint, this, fConservativeRasterClip, stashedMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1262 | |
| 1263 | layer->fNext = fMCRec->fTopLayer; |
| 1264 | fMCRec->fLayer = layer; |
| 1265 | fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1266 | |
| 1267 | if (rec.fBackdrop) { |
| 1268 | DrawDeviceWithFilter(priorDevice, rec.fBackdrop, newDevice, |
| 1269 | fMCRec->fMatrix, this->getClipStack()); |
| 1270 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 1273 | int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 1274 | if (0xFF == alpha) { |
| 1275 | return this->saveLayer(bounds, nullptr); |
| 1276 | } else { |
| 1277 | SkPaint tmpPaint; |
| 1278 | tmpPaint.setAlpha(alpha); |
| 1279 | return this->saveLayer(bounds, &tmpPaint); |
| 1280 | } |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1283 | void SkCanvas::internalRestore() { |
| 1284 | SkASSERT(fMCStack.count() != 0); |
| 1285 | |
| 1286 | fDeviceCMDirty = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1287 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1288 | fClipStack->restore(); |
commit-bot@chromium.org | 6c15764 | 2013-08-16 00:53:34 +0000 | [diff] [blame] | 1289 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 1290 | // reserve our layer (if any) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1291 | DeviceCM* layer = fMCRec->fLayer; // may be null |
| 1292 | // 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] | 1293 | fMCRec->fLayer = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1294 | |
| 1295 | // now do the normal restore() |
| 1296 | fMCRec->~MCRec(); // balanced in save() |
| 1297 | fMCStack.pop_back(); |
| 1298 | fMCRec = (MCRec*)fMCStack.back(); |
| 1299 | |
| 1300 | /* Time to draw the layer's offscreen. We can't call the public drawSprite, |
| 1301 | since if we're being recorded, we don't want to record this (the |
| 1302 | recorder will have already recorded the restore). |
| 1303 | */ |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1304 | if (layer) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1305 | if (layer->fNext) { |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 1306 | const SkIPoint& origin = layer->fDevice->getOrigin(); |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 1307 | this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), layer->fPaint); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1308 | // restore what we smashed in internalSaveLayer |
| 1309 | fMCRec->fMatrix = layer->fStashedMatrix; |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1310 | // reset this, since internalDrawDevice will have set it to true |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1311 | fDeviceCMDirty = true; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1312 | delete layer; |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1313 | } else { |
| 1314 | // we're at the root |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 1315 | SkASSERT(layer == (void*)fDeviceCMStorage); |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1316 | layer->~DeviceCM(); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1317 | // no need to update fMCRec, 'cause we're killing the canvas |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1318 | } |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 1319 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1320 | |
| 1321 | if (fMCRec) { |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1322 | fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1323 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
| 1324 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1327 | sk_sp<SkSurface> SkCanvas::makeSurface(const SkImageInfo& info, const SkSurfaceProps* props) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1328 | if (nullptr == props) { |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1329 | props = &fProps; |
| 1330 | } |
| 1331 | return this->onNewSurface(info, *props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1334 | sk_sp<SkSurface> SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1335 | SkBaseDevice* dev = this->getDevice(); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1336 | return dev ? dev->makeSurface(info, props) : nullptr; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1339 | SkImageInfo SkCanvas::imageInfo() const { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 1340 | return this->onImageInfo(); |
| 1341 | } |
| 1342 | |
| 1343 | SkImageInfo SkCanvas::onImageInfo() const { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1344 | SkBaseDevice* dev = this->getDevice(); |
| 1345 | if (dev) { |
| 1346 | return dev->imageInfo(); |
| 1347 | } else { |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1348 | return SkImageInfo::MakeUnknown(0, 0); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 1352 | bool SkCanvas::getProps(SkSurfaceProps* props) const { |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 1353 | return this->onGetProps(props); |
| 1354 | } |
| 1355 | |
| 1356 | bool SkCanvas::onGetProps(SkSurfaceProps* props) const { |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 1357 | SkBaseDevice* dev = this->getDevice(); |
| 1358 | if (dev) { |
| 1359 | if (props) { |
| 1360 | *props = fProps; |
| 1361 | } |
| 1362 | return true; |
| 1363 | } else { |
| 1364 | return false; |
| 1365 | } |
| 1366 | } |
| 1367 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 1368 | #ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1369 | const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) { |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1370 | SkPixmap pmap; |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 1371 | if (this->peekPixels(&pmap)) { |
| 1372 | if (info) { |
| 1373 | *info = pmap.info(); |
| 1374 | } |
| 1375 | if (rowBytes) { |
| 1376 | *rowBytes = pmap.rowBytes(); |
| 1377 | } |
| 1378 | return pmap.addr(); |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1379 | } |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 1380 | return nullptr; |
| 1381 | } |
| 1382 | #endif |
| 1383 | |
| 1384 | bool SkCanvas::peekPixels(SkPixmap* pmap) { |
| 1385 | return this->onPeekPixels(pmap); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1388 | bool SkCanvas::onPeekPixels(SkPixmap* pmap) { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1389 | SkBaseDevice* dev = this->getDevice(); |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1390 | return dev && dev->peekPixels(pmap); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 1393 | void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin) { |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1394 | SkPixmap pmap; |
| 1395 | if (!this->onAccessTopLayerPixels(&pmap)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1396 | return nullptr; |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1397 | } |
| 1398 | if (info) { |
| 1399 | *info = pmap.info(); |
| 1400 | } |
| 1401 | if (rowBytes) { |
| 1402 | *rowBytes = pmap.rowBytes(); |
| 1403 | } |
| 1404 | if (origin) { |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 1405 | *origin = this->getTopDevice(false)->getOrigin(); |
| 1406 | } |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1407 | return pmap.writable_addr(); |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1410 | bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1411 | SkBaseDevice* dev = this->getTopDevice(); |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1412 | return dev && dev->accessPixels(pmap); |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1415 | ///////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1416 | |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 1417 | void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPaint* paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1418 | SkPaint tmp; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1419 | if (nullptr == paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1420 | paint = &tmp; |
| 1421 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1422 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1423 | LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1424 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1425 | while (iter.next()) { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1426 | SkBaseDevice* dstDev = iter.fDevice; |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1427 | paint = &looper.paint(); |
| 1428 | SkImageFilter* filter = paint->getImageFilter(); |
| 1429 | SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
senorblanco | f35566e | 2016-04-18 10:32:02 -0700 | [diff] [blame] | 1430 | if (filter) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1431 | dstDev->drawSpecial(iter, srcDev->snapSpecial().get(), pos.x(), pos.y(), *paint); |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1432 | } else { |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 1433 | dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 1434 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1435 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1436 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 1437 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
reed | 3270467 | 2015-12-16 08:27:10 -0800 | [diff] [blame] | 1440 | ///////////////////////////////////////////////////////////////////////////// |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1441 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1442 | void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 1443 | this->checkForDeferredSave(); |
| 1444 | fDeviceCMDirty = true; |
| 1445 | fMCRec->fMatrix.preTranslate(dx,dy); |
| 1446 | |
| 1447 | // Translate shouldn't affect the is-scale-translateness of the matrix. |
| 1448 | SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate()); |
| 1449 | |
| 1450 | this->didTranslate(dx,dy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1453 | void SkCanvas::scale(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1454 | SkMatrix m; |
| 1455 | m.setScale(sx, sy); |
| 1456 | this->concat(m); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1459 | void SkCanvas::rotate(SkScalar degrees) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1460 | SkMatrix m; |
| 1461 | m.setRotate(degrees); |
| 1462 | this->concat(m); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 1465 | void SkCanvas::rotate(SkScalar degrees, SkScalar px, SkScalar py) { |
| 1466 | SkMatrix m; |
| 1467 | m.setRotate(degrees, px, py); |
| 1468 | this->concat(m); |
| 1469 | } |
| 1470 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1471 | void SkCanvas::skew(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1472 | SkMatrix m; |
| 1473 | m.setSkew(sx, sy); |
| 1474 | this->concat(m); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1477 | void SkCanvas::concat(const SkMatrix& matrix) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 1478 | if (matrix.isIdentity()) { |
| 1479 | return; |
| 1480 | } |
| 1481 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1482 | this->checkForDeferredSave(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1483 | fDeviceCMDirty = true; |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1484 | fMCRec->fMatrix.preConcat(matrix); |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1485 | fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1486 | this->didConcat(matrix); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1489 | void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1490 | fDeviceCMDirty = true; |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1491 | fMCRec->fMatrix = matrix; |
msarett | 9da5a5a | 2016-08-19 08:38:36 -0700 | [diff] [blame] | 1492 | fIsScaleTranslate = matrix.isScaleTranslate(); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | void SkCanvas::setMatrix(const SkMatrix& matrix) { |
| 1496 | this->checkForDeferredSave(); |
| 1497 | this->internalSetMatrix(matrix); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1498 | this->didSetMatrix(matrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1501 | void SkCanvas::resetMatrix() { |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1502 | this->setMatrix(SkMatrix::I()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1505 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 1506 | void SkCanvas::translateZ(SkScalar z) { |
| 1507 | this->checkForDeferredSave(); |
| 1508 | this->fMCRec->fCurDrawDepth += z; |
| 1509 | this->didTranslateZ(z); |
| 1510 | } |
| 1511 | |
| 1512 | SkScalar SkCanvas::getZ() const { |
| 1513 | return this->fMCRec->fCurDrawDepth; |
| 1514 | } |
| 1515 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1516 | void SkCanvas::setLights(sk_sp<SkLights> lights) { |
| 1517 | this->fLights = lights; |
| 1518 | } |
| 1519 | |
| 1520 | sk_sp<SkLights> SkCanvas::getLights() const { |
| 1521 | return this->fLights; |
| 1522 | } |
| 1523 | #endif |
| 1524 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1525 | ////////////////////////////////////////////////////////////////////////////// |
| 1526 | |
commit-bot@chromium.org | 759cf48 | 2014-03-06 13:18:07 +0000 | [diff] [blame] | 1527 | void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1528 | if (!fAllowSoftClip) { |
| 1529 | doAA = false; |
| 1530 | } |
| 1531 | |
| 1532 | #ifdef SK_SUPPORT_PRECHECK_CLIPRECT |
| 1533 | // Check if we can quick-accept the clip call (and do nothing) |
| 1534 | // |
reed | 7446716 | 2016-06-30 08:15:35 -0700 | [diff] [blame] | 1535 | if (SkRegion::kIntersect_Op == op && !doAA && fMCRec->fMatrix.isScaleTranslate()) { |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 1536 | SkRect devR; |
| 1537 | fMCRec->fMatrix.mapRectScaleTranslate(&devR, rect); |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1538 | // NOTE: this check is CTM specific, since we might round differently with a different |
| 1539 | // CTM. Thus this is only 100% reliable if there is not global CTM scale to be |
| 1540 | // applied later (i.e. if this is going into a picture). |
| 1541 | if (devR.round().contains(fMCRec->fRasterClip.getBounds())) { |
| 1542 | #if 0 |
| 1543 | SkDebugf("ignored clipRect [%g %g %g %g]\n", |
| 1544 | rect.left(), rect.top(), rect.right(), rect.bottom()); |
| 1545 | #endif |
| 1546 | return; |
| 1547 | } |
| 1548 | } |
| 1549 | #endif |
| 1550 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1551 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1552 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
| 1553 | this->onClipRect(rect, op, edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1557 | #ifdef SK_ENABLE_CLIP_QUICKREJECT |
| 1558 | if (SkRegion::kIntersect_Op == op) { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1559 | if (fMCRec->fRasterClip.isEmpty()) { |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1560 | return; |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1563 | if (this->quickReject(rect)) { |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1564 | fDeviceCMDirty = true; |
reed@google.com | c0784db | 2013-12-13 21:16:12 +0000 | [diff] [blame] | 1565 | fCachedLocalClipBoundsDirty = true; |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1566 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1567 | fClipStack->clipEmpty(); |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1568 | (void)fMCRec->fRasterClip.setEmpty(); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1569 | fDeviceClipBounds.setEmpty(); |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1570 | return; |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | #endif |
| 1574 | |
reed | 7446716 | 2016-06-30 08:15:35 -0700 | [diff] [blame] | 1575 | const bool isScaleTrans = fMCRec->fMatrix.isScaleTranslate(); |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1576 | SkRect devR; |
reed | 7446716 | 2016-06-30 08:15:35 -0700 | [diff] [blame] | 1577 | if (isScaleTrans) { |
halcanary | c5769b2 | 2016-08-10 07:13:21 -0700 | [diff] [blame] | 1578 | fMCRec->fMatrix.mapRectScaleTranslate(&devR, rect); |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1579 | } |
bsalomon | ac8cabd | 2015-11-20 18:53:07 -0800 | [diff] [blame] | 1580 | |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1581 | #ifndef SK_SUPPORT_PRECHECK_CLIPRECT |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1582 | if (SkRegion::kIntersect_Op == op && |
| 1583 | kHard_ClipEdgeStyle == edgeStyle |
reed | 7446716 | 2016-06-30 08:15:35 -0700 | [diff] [blame] | 1584 | && isScaleTrans) |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1585 | { |
| 1586 | if (devR.round().contains(fMCRec->fRasterClip.getBounds())) { |
| 1587 | #if 0 |
| 1588 | SkDebugf("------- ignored clipRect [%g %g %g %g]\n", |
| 1589 | rect.left(), rect.top(), rect.right(), rect.bottom()); |
| 1590 | #endif |
| 1591 | return; |
| 1592 | } |
| 1593 | } |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1594 | #endif |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1595 | |
| 1596 | AutoValidateClip avc(this); |
| 1597 | |
| 1598 | fDeviceCMDirty = true; |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1599 | |
reed | 7446716 | 2016-06-30 08:15:35 -0700 | [diff] [blame] | 1600 | if (isScaleTrans) { |
reed | c64eff5 | 2015-11-21 12:39:45 -0800 | [diff] [blame] | 1601 | const bool isAA = kSoft_ClipEdgeStyle == edgeStyle; |
| 1602 | fClipStack->clipDevRect(devR, op, isAA); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1603 | fMCRec->fRasterClip.op(devR, this->getTopLayerBounds(), op, isAA); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1604 | } else { |
robertphillips@google.com | 1236719 | 2013-10-20 13:11:16 +0000 | [diff] [blame] | 1605 | // since we're rotated or some such thing, we convert the rect to a path |
reed@android.com | 98de2bd | 2009-03-02 19:41:36 +0000 | [diff] [blame] | 1606 | // and clip against that, since it can handle any matrix. However, to |
| 1607 | // avoid recursion in the case where we are subclassed (e.g. Pictures) |
| 1608 | // we explicitly call "our" version of clipPath. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1609 | SkPath path; |
| 1610 | |
| 1611 | path.addRect(rect); |
bsalomon | bdc335f | 2016-08-22 13:42:17 -0700 | [diff] [blame] | 1612 | path.setIsVolatile(true); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1613 | this->SkCanvas::onClipPath(path, op, edgeStyle); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1614 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1615 | |
| 1616 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
commit-bot@chromium.org | 759cf48 | 2014-03-06 13:18:07 +0000 | [diff] [blame] | 1619 | void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1620 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1621 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1622 | if (rrect.isRect()) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1623 | this->onClipRect(rrect.getBounds(), op, edgeStyle); |
| 1624 | } else { |
| 1625 | this->onClipRRect(rrect, op, edgeStyle); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1626 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1627 | } |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1628 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1629 | void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1630 | SkRRect transformedRRect; |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1631 | if (rrect.transform(fMCRec->fMatrix, &transformedRRect)) { |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1632 | AutoValidateClip avc(this); |
| 1633 | |
| 1634 | fDeviceCMDirty = true; |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1635 | if (!fAllowSoftClip) { |
| 1636 | edgeStyle = kHard_ClipEdgeStyle; |
| 1637 | } |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1638 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1639 | fClipStack->clipDevRRect(transformedRRect, op, kSoft_ClipEdgeStyle == edgeStyle); |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1640 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1641 | fMCRec->fRasterClip.op(transformedRRect, this->getTopLayerBounds(), op, |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 1642 | kSoft_ClipEdgeStyle == edgeStyle); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1643 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1644 | return; |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | SkPath path; |
| 1648 | path.addRRect(rrect); |
bsalomon | bdc335f | 2016-08-22 13:42:17 -0700 | [diff] [blame] | 1649 | path.setIsVolatile(true); |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 1650 | // call the non-virtual version |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1651 | this->SkCanvas::onClipPath(path, op, edgeStyle); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
commit-bot@chromium.org | 759cf48 | 2014-03-06 13:18:07 +0000 | [diff] [blame] | 1654 | void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1655 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1656 | ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
robertphillips | 39f0538 | 2015-11-24 09:30:12 -0800 | [diff] [blame] | 1657 | |
| 1658 | if (!path.isInverseFillType() && fMCRec->fMatrix.rectStaysRect()) { |
| 1659 | SkRect r; |
| 1660 | if (path.isRect(&r)) { |
| 1661 | this->onClipRect(r, op, edgeStyle); |
| 1662 | return; |
| 1663 | } |
| 1664 | SkRRect rrect; |
| 1665 | if (path.isOval(&r)) { |
| 1666 | rrect.setOval(r); |
| 1667 | this->onClipRRect(rrect, op, edgeStyle); |
| 1668 | return; |
| 1669 | } |
| 1670 | if (path.isRRect(&rrect)) { |
| 1671 | this->onClipRRect(rrect, op, edgeStyle); |
| 1672 | return; |
| 1673 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1674 | } |
robertphillips | 39f0538 | 2015-11-24 09:30:12 -0800 | [diff] [blame] | 1675 | |
| 1676 | this->onClipPath(path, op, edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1680 | #ifdef SK_ENABLE_CLIP_QUICKREJECT |
| 1681 | if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1682 | if (fMCRec->fRasterClip.isEmpty()) { |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1683 | return; |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1684 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1685 | |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1686 | if (this->quickReject(path.getBounds())) { |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1687 | fDeviceCMDirty = true; |
reed@google.com | c0784db | 2013-12-13 21:16:12 +0000 | [diff] [blame] | 1688 | fCachedLocalClipBoundsDirty = true; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1689 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1690 | fClipStack->clipEmpty(); |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1691 | (void)fMCRec->fRasterClip.setEmpty(); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1692 | fDeviceClipBounds.setEmpty(); |
reed | 2d1afab | 2016-06-29 14:33:11 -0700 | [diff] [blame] | 1693 | return; |
reed@google.com | da17f75 | 2012-08-16 18:27:05 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | #endif |
| 1697 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1698 | AutoValidateClip avc(this); |
| 1699 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1700 | fDeviceCMDirty = true; |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1701 | if (!fAllowSoftClip) { |
| 1702 | edgeStyle = kHard_ClipEdgeStyle; |
| 1703 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1704 | |
| 1705 | SkPath devPath; |
bsalomon | bdc335f | 2016-08-22 13:42:17 -0700 | [diff] [blame] | 1706 | if (fMCRec->fMatrix.isIdentity()) { |
| 1707 | devPath = path; |
| 1708 | } else { |
| 1709 | path.transform(fMCRec->fMatrix, &devPath); |
| 1710 | devPath.setIsVolatile(true); |
| 1711 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1712 | |
reed@google.com | fe70112 | 2011-11-08 19:41:23 +0000 | [diff] [blame] | 1713 | // Check if the transfomation, or the original path itself |
| 1714 | // made us empty. Note this can also happen if we contained NaN |
| 1715 | // values. computing the bounds detects this, and will set our |
| 1716 | // bounds to empty if that is the case. (see SkRect::set(pts, count)) |
| 1717 | if (devPath.getBounds().isEmpty()) { |
| 1718 | // resetting the path will remove any NaN or other wanky values |
| 1719 | // that might upset our scan converter. |
| 1720 | devPath.reset(); |
| 1721 | } |
| 1722 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1723 | // if we called path.swap() we could avoid a deep copy of this path |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1724 | fClipStack->clipDevPath(devPath, op, kSoft_ClipEdgeStyle == edgeStyle); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1725 | |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 1726 | if (fAllowSimplifyClip) { |
fmalita | 1a481fe | 2015-02-04 07:39:34 -0800 | [diff] [blame] | 1727 | bool clipIsAA = getClipStack()->asPath(&devPath); |
| 1728 | if (clipIsAA) { |
| 1729 | edgeStyle = kSoft_ClipEdgeStyle; |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 1730 | } |
fmalita | 1a481fe | 2015-02-04 07:39:34 -0800 | [diff] [blame] | 1731 | |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 1732 | op = SkRegion::kReplace_Op; |
| 1733 | } |
| 1734 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1735 | fMCRec->fRasterClip.op(devPath, this->getTopLayerBounds(), op, edgeStyle); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1736 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
commit-bot@chromium.org | 759cf48 | 2014-03-06 13:18:07 +0000 | [diff] [blame] | 1739 | void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1740 | this->checkForDeferredSave(); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1741 | this->onClipRegion(rgn, op); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1745 | AutoValidateClip avc(this); |
| 1746 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1747 | fDeviceCMDirty = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1748 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1749 | // todo: signal fClipStack that we have a region, and therefore (I guess) |
| 1750 | // we have to ignore it, and use the region directly? |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1751 | fClipStack->clipDevRect(rgn.getBounds(), op); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1752 | |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1753 | fMCRec->fRasterClip.op(rgn, op); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1754 | fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1757 | #ifdef SK_DEBUG |
| 1758 | void SkCanvas::validateClip() const { |
| 1759 | // construct clipRgn from the clipstack |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1760 | const SkBaseDevice* device = this->getDevice(); |
djsollen@google.com | ccfee2a | 2012-05-01 16:50:10 +0000 | [diff] [blame] | 1761 | if (!device) { |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1762 | SkASSERT(this->isClipEmpty()); |
djsollen@google.com | ccfee2a | 2012-05-01 16:50:10 +0000 | [diff] [blame] | 1763 | return; |
| 1764 | } |
| 1765 | |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1766 | SkIRect ir; |
| 1767 | ir.set(0, 0, device->width(), device->height()); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 1768 | SkRasterClip tmpClip(ir, fConservativeRasterClip); |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1769 | |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1770 | SkClipStack::B2TIter iter(*fClipStack); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1771 | const SkClipStack::Element* element; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1772 | while ((element = iter.next()) != nullptr) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1773 | switch (element->getType()) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1774 | case SkClipStack::Element::kRect_Type: |
| 1775 | element->getRect().round(&ir); |
| 1776 | tmpClip.op(ir, element->getOp()); |
| 1777 | break; |
| 1778 | case SkClipStack::Element::kEmpty_Type: |
| 1779 | tmpClip.setEmpty(); |
| 1780 | break; |
commit-bot@chromium.org | 9cb671a | 2014-02-16 14:45:45 +0000 | [diff] [blame] | 1781 | default: { |
| 1782 | SkPath path; |
| 1783 | element->asPath(&path); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1784 | tmpClip.op(path, this->getTopLayerBounds(), element->getOp(), element->isAA()); |
commit-bot@chromium.org | 9cb671a | 2014-02-16 14:45:45 +0000 | [diff] [blame] | 1785 | break; |
| 1786 | } |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1787 | } |
| 1788 | } |
reed@google.com | 819c921 | 2011-02-23 18:56:55 +0000 | [diff] [blame] | 1789 | } |
| 1790 | #endif |
| 1791 | |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 1792 | void SkCanvas::replayClips(ClipVisitor* visitor) const { |
reed | 687fa1c | 2015-04-07 08:00:56 -0700 | [diff] [blame] | 1793 | SkClipStack::B2TIter iter(*fClipStack); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1794 | const SkClipStack::Element* element; |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 1795 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1796 | while ((element = iter.next()) != nullptr) { |
fmalita | c3b589a | 2014-06-05 12:40:07 -0700 | [diff] [blame] | 1797 | element->replay(visitor); |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1801 | /////////////////////////////////////////////////////////////////////////////// |
| 1802 | |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1803 | bool SkCanvas::isClipEmpty() const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1804 | return fMCRec->fRasterClip.isEmpty(); |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1807 | bool SkCanvas::isClipRect() const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1808 | return fMCRec->fRasterClip.isRect(); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1811 | static inline bool is_nan_or_clipped(const Sk4f& devRect, const Sk4f& devClip) { |
| 1812 | #if !defined(SKNX_NO_SIMD) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 1813 | __m128 lLtT = _mm_unpacklo_ps(devRect.fVec, devClip.fVec); |
| 1814 | __m128 RrBb = _mm_unpackhi_ps(devClip.fVec, devRect.fVec); |
| 1815 | __m128 mask = _mm_cmplt_ps(lLtT, RrBb); |
| 1816 | return 0xF != _mm_movemask_ps(mask); |
| 1817 | #elif !defined(SKNX_NO_SIMD) && defined(SK_ARM_HAS_NEON) |
| 1818 | float32x4_t lLtT = vzipq_f32(devRect.fVec, devClip.fVec).val[0]; |
| 1819 | float32x4_t RrBb = vzipq_f32(devClip.fVec, devRect.fVec).val[1]; |
| 1820 | uint32x4_t mask = vcltq_f32(lLtT, RrBb); |
| 1821 | return 0xFFFFFFFFFFFFFFFF != (uint64_t) vmovn_u32(mask); |
| 1822 | #else |
| 1823 | SkRect devRectAsRect; |
| 1824 | SkRect devClipAsRect; |
| 1825 | devRect.store(&devRectAsRect.fLeft); |
| 1826 | devClip.store(&devClipAsRect.fLeft); |
| 1827 | return !devRectAsRect.isFinite() || !devRectAsRect.intersect(devClipAsRect); |
| 1828 | #endif |
| 1829 | } |
wjmaclean@chromium.org | 116b2bc | 2011-02-07 17:48:37 +0000 | [diff] [blame] | 1830 | |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1831 | // It's important for this function to not be inlined. Otherwise the compiler will share code |
| 1832 | // between the fast path and the slow path, resulting in two slow paths. |
| 1833 | static SK_NEVER_INLINE bool quick_reject_slow_path(const SkRect& src, const SkRect& deviceClip, |
| 1834 | const SkMatrix& matrix) { |
| 1835 | SkRect deviceRect; |
| 1836 | matrix.mapRect(&deviceRect, src); |
| 1837 | return !deviceRect.isFinite() || !deviceRect.intersect(deviceClip); |
| 1838 | } |
| 1839 | |
| 1840 | bool SkCanvas::quickReject(const SkRect& src) const { |
| 1841 | #ifdef SK_DEBUG |
| 1842 | // Verify that fDeviceClipBounds are set properly. |
| 1843 | SkRect tmp = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1844 | if (fMCRec->fRasterClip.isEmpty()) { |
msarett | 0c685ee | 2016-08-14 13:51:16 -0700 | [diff] [blame] | 1845 | SkASSERT(fDeviceClipBounds.isEmpty()); |
reed@android.com | a380ae4 | 2009-07-21 01:17:02 +0000 | [diff] [blame] | 1846 | } else { |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1847 | SkASSERT(tmp == fDeviceClipBounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1848 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1849 | |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1850 | // Verify that fIsScaleTranslate is set properly. |
| 1851 | SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate()); |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1852 | #endif |
| 1853 | |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1854 | if (!fIsScaleTranslate) { |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1855 | return quick_reject_slow_path(src, fDeviceClipBounds, fMCRec->fMatrix); |
| 1856 | } |
| 1857 | |
| 1858 | // We inline the implementation of mapScaleTranslate() for the fast path. |
| 1859 | float sx = fMCRec->fMatrix.getScaleX(); |
| 1860 | float sy = fMCRec->fMatrix.getScaleY(); |
| 1861 | float tx = fMCRec->fMatrix.getTranslateX(); |
| 1862 | float ty = fMCRec->fMatrix.getTranslateY(); |
| 1863 | Sk4f scale(sx, sy, sx, sy); |
| 1864 | Sk4f trans(tx, ty, tx, ty); |
| 1865 | |
| 1866 | // Apply matrix. |
| 1867 | Sk4f ltrb = Sk4f::Load(&src.fLeft) * scale + trans; |
| 1868 | |
| 1869 | // Make sure left < right, top < bottom. |
| 1870 | Sk4f rblt(ltrb[2], ltrb[3], ltrb[0], ltrb[1]); |
| 1871 | Sk4f min = Sk4f::Min(ltrb, rblt); |
| 1872 | Sk4f max = Sk4f::Max(ltrb, rblt); |
| 1873 | // We can extract either pair [0,1] or [2,3] from min and max and be correct, but on |
| 1874 | // ARM this sequence generates the fastest (a single instruction). |
| 1875 | Sk4f devRect = Sk4f(min[2], min[3], max[0], max[1]); |
| 1876 | |
| 1877 | // Check if the device rect is NaN or outside the clip. |
| 1878 | return is_nan_or_clipped(devRect, Sk4f::Load(&fDeviceClipBounds.fLeft)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1881 | bool SkCanvas::quickReject(const SkPath& path) const { |
| 1882 | return path.isEmpty() || this->quickReject(path.getBounds()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1885 | bool SkCanvas::getClipBounds(SkRect* bounds) const { |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1886 | SkIRect ibounds; |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1887 | if (!this->getClipDeviceBounds(&ibounds)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
| 1890 | |
reed@android.com | d9c0f0b | 2009-02-06 22:39:37 +0000 | [diff] [blame] | 1891 | SkMatrix inverse; |
| 1892 | // 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] | 1893 | if (!fMCRec->fMatrix.invert(&inverse)) { |
reed@android.com | 72dcd3a | 2009-05-18 15:46:29 +0000 | [diff] [blame] | 1894 | if (bounds) { |
| 1895 | bounds->setEmpty(); |
| 1896 | } |
reed@android.com | d9c0f0b | 2009-02-06 22:39:37 +0000 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1899 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1900 | if (bounds) { |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1901 | SkRect r; |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 1902 | // adjust it outwards in case we are antialiasing |
| 1903 | const int inset = 1; |
reed@google.com | fa4d5bd | 2012-01-30 17:36:27 +0000 | [diff] [blame] | 1904 | |
reed@google.com | 8f4d230 | 2013-12-17 16:44:46 +0000 | [diff] [blame] | 1905 | r.iset(ibounds.fLeft - inset, ibounds.fTop - inset, |
| 1906 | ibounds.fRight + inset, ibounds.fBottom + inset); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1907 | inverse.mapRect(bounds, r); |
| 1908 | } |
| 1909 | return true; |
| 1910 | } |
| 1911 | |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1912 | bool SkCanvas::getClipDeviceBounds(SkIRect* bounds) const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1913 | const SkRasterClip& clip = fMCRec->fRasterClip; |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1914 | if (clip.isEmpty()) { |
| 1915 | if (bounds) { |
| 1916 | bounds->setEmpty(); |
| 1917 | } |
| 1918 | return false; |
| 1919 | } |
| 1920 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1921 | if (bounds) { |
tomhudson@google.com | bcb671c | 2011-09-13 15:07:58 +0000 | [diff] [blame] | 1922 | *bounds = clip.getBounds(); |
| 1923 | } |
| 1924 | return true; |
| 1925 | } |
| 1926 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1927 | const SkMatrix& SkCanvas::getTotalMatrix() const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1928 | return fMCRec->fMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1931 | const SkRegion& SkCanvas::internal_private_getTotalClip() const { |
reed | 1f836ee | 2014-07-07 07:49:34 -0700 | [diff] [blame] | 1932 | return fMCRec->fRasterClip.forceGetBW(); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 1935 | GrDrawContext* SkCanvas::internal_private_accessTopLayerDrawContext() { |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1936 | SkBaseDevice* dev = this->getTopDevice(); |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 1937 | return dev ? dev->accessDrawContext() : nullptr; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1940 | GrContext* SkCanvas::getGrContext() { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1941 | SkBaseDevice* device = this->getTopDevice(); |
reed | 86ae3d1 | 2016-04-26 06:57:31 -0700 | [diff] [blame] | 1942 | return device ? device->context() : nullptr; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1943 | } |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 1944 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1945 | void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 1946 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 1947 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawDRRect()"); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1948 | if (outer.isEmpty()) { |
| 1949 | return; |
| 1950 | } |
| 1951 | if (inner.isEmpty()) { |
| 1952 | this->drawRRect(outer, paint); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | // We don't have this method (yet), but technically this is what we should |
| 1957 | // be able to assert... |
| 1958 | // SkASSERT(outer.contains(inner)); |
| 1959 | // |
| 1960 | // For now at least check for containment of bounds |
| 1961 | SkASSERT(outer.getBounds().contains(inner.getBounds())); |
| 1962 | |
| 1963 | this->onDrawDRRect(outer, inner, paint); |
| 1964 | } |
| 1965 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1966 | // These need to stop being virtual -- clients need to override the onDraw... versions |
| 1967 | |
| 1968 | void SkCanvas::drawPaint(const SkPaint& paint) { |
| 1969 | this->onDrawPaint(paint); |
| 1970 | } |
| 1971 | |
| 1972 | void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { |
| 1973 | this->onDrawRect(r, paint); |
| 1974 | } |
| 1975 | |
msarett | dca352e | 2016-08-26 06:37:45 -0700 | [diff] [blame] | 1976 | void SkCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) { |
| 1977 | if (region.isEmpty()) { |
| 1978 | return; |
| 1979 | } |
| 1980 | |
| 1981 | if (region.isRect()) { |
| 1982 | return this->drawIRect(region.getBounds(), paint); |
| 1983 | } |
| 1984 | |
| 1985 | this->onDrawRegion(region, paint); |
| 1986 | } |
| 1987 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1988 | void SkCanvas::drawOval(const SkRect& r, const SkPaint& paint) { |
| 1989 | this->onDrawOval(r, paint); |
| 1990 | } |
| 1991 | |
| 1992 | void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 1993 | this->onDrawRRect(rrect, paint); |
| 1994 | } |
| 1995 | |
| 1996 | void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { |
| 1997 | this->onDrawPoints(mode, count, pts, paint); |
| 1998 | } |
| 1999 | |
| 2000 | void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], |
| 2001 | const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, |
| 2002 | const uint16_t indices[], int indexCount, const SkPaint& paint) { |
| 2003 | this->onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode, |
| 2004 | indices, indexCount, paint); |
| 2005 | } |
| 2006 | |
| 2007 | void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 2008 | this->onDrawPath(path, paint); |
| 2009 | } |
| 2010 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2011 | void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2012 | RETURN_ON_NULL(image); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2013 | this->onDrawImage(image, x, y, paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2016 | void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 2017 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2018 | RETURN_ON_NULL(image); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2019 | if (dst.isEmpty() || src.isEmpty()) { |
| 2020 | return; |
| 2021 | } |
| 2022 | this->onDrawImageRect(image, &src, dst, paint, constraint); |
| 2023 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2024 | |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 2025 | void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 2026 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2027 | RETURN_ON_NULL(image); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2028 | this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2031 | void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 2032 | SrcRectConstraint constraint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2033 | RETURN_ON_NULL(image); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2034 | this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint, |
| 2035 | constraint); |
| 2036 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2037 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2038 | void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 2039 | const SkPaint* paint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2040 | RETURN_ON_NULL(image); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2041 | if (dst.isEmpty()) { |
| 2042 | return; |
| 2043 | } |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 2044 | if (SkLatticeIter::Valid(image->width(), image->height(), center)) { |
| 2045 | this->onDrawImageNine(image, center, dst, paint); |
| 2046 | } else { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2047 | this->drawImageRect(image, dst, paint); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2048 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2051 | void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 2052 | const SkPaint* paint) { |
| 2053 | RETURN_ON_NULL(image); |
| 2054 | if (dst.isEmpty()) { |
| 2055 | return; |
| 2056 | } |
| 2057 | if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { |
| 2058 | this->onDrawImageLattice(image, lattice, dst, paint); |
| 2059 | } else { |
| 2060 | this->drawImageRect(image, dst, paint); |
| 2061 | } |
| 2062 | } |
| 2063 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2064 | void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, const SkPaint* paint) { |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2065 | if (bitmap.drawsNothing()) { |
tomhudson | 2df6fd6 | 2015-04-09 09:20:19 -0700 | [diff] [blame] | 2066 | return; |
| 2067 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2068 | this->onDrawBitmap(bitmap, dx, dy, paint); |
| 2069 | } |
| 2070 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2071 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2072 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2073 | if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2074 | return; |
| 2075 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2076 | this->onDrawBitmapRect(bitmap, &src, dst, paint, constraint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2077 | } |
| 2078 | |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 2079 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 2080 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2081 | this->drawBitmapRect(bitmap, SkRect::Make(isrc), dst, paint, constraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2084 | void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 2085 | SrcRectConstraint constraint) { |
| 2086 | this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), dst, paint, |
| 2087 | constraint); |
| 2088 | } |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2089 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2090 | void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 2091 | const SkPaint* paint) { |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2092 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
tomhudson | 2df6fd6 | 2015-04-09 09:20:19 -0700 | [diff] [blame] | 2093 | return; |
| 2094 | } |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 2095 | if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) { |
| 2096 | this->onDrawBitmapNine(bitmap, center, dst, paint); |
| 2097 | } else { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2098 | this->drawBitmapRect(bitmap, dst, paint); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2099 | } |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 2102 | void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 2103 | const SkPaint* paint) { |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2104 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 2105 | return; |
| 2106 | } |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2107 | if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { |
| 2108 | this->onDrawBitmapLattice(bitmap, lattice, dst, paint); |
msarett | 552bca9 | 2016-08-03 06:53:26 -0700 | [diff] [blame] | 2109 | } else { |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2110 | this->drawBitmapRect(bitmap, dst, paint); |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 2111 | } |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2114 | void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 2115 | const SkColor colors[], int count, SkXfermode::Mode mode, |
| 2116 | const SkRect* cull, const SkPaint* paint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2117 | RETURN_ON_NULL(atlas); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 2118 | if (count <= 0) { |
| 2119 | return; |
| 2120 | } |
| 2121 | SkASSERT(atlas); |
| 2122 | SkASSERT(xform); |
| 2123 | SkASSERT(tex); |
| 2124 | this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint); |
| 2125 | } |
| 2126 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 2127 | void SkCanvas::drawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 2128 | if (key) { |
| 2129 | this->onDrawAnnotation(rect, key, value); |
| 2130 | } |
| 2131 | } |
| 2132 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2133 | void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 2134 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 2135 | if (src) { |
| 2136 | this->drawImageRect(image, *src, dst, paint, constraint); |
| 2137 | } else { |
| 2138 | this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), |
| 2139 | dst, paint, constraint); |
| 2140 | } |
| 2141 | } |
| 2142 | void SkCanvas::legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
| 2143 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 2144 | if (src) { |
| 2145 | this->drawBitmapRect(bitmap, *src, dst, paint, constraint); |
| 2146 | } else { |
| 2147 | this->drawBitmapRect(bitmap, SkRect::MakeIWH(bitmap.width(), bitmap.height()), |
| 2148 | dst, paint, constraint); |
| 2149 | } |
| 2150 | } |
| 2151 | |
tomhudson | cb3bd18 | 2016-05-18 07:24:16 -0700 | [diff] [blame] | 2152 | void SkCanvas::temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds) { |
| 2153 | SkIRect layer_bounds = this->getTopLayerBounds(); |
| 2154 | if (matrix) { |
| 2155 | *matrix = this->getTotalMatrix(); |
| 2156 | matrix->preTranslate(-layer_bounds.left(), -layer_bounds.top()); |
| 2157 | } |
| 2158 | if (clip_bounds) { |
| 2159 | this->getClipDeviceBounds(clip_bounds); |
| 2160 | clip_bounds->offset(-layer_bounds.left(), -layer_bounds.top()); |
| 2161 | } |
| 2162 | } |
| 2163 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2164 | ////////////////////////////////////////////////////////////////////////////// |
| 2165 | // These are the virtual drawing methods |
| 2166 | ////////////////////////////////////////////////////////////////////////////// |
| 2167 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 2168 | void SkCanvas::onDiscard() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2169 | if (fSurfaceBase) { |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 2170 | fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
| 2171 | } |
| 2172 | } |
| 2173 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2174 | void SkCanvas::onDrawPaint(const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2175 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPaint()"); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2176 | this->internalDrawPaint(paint); |
| 2177 | } |
| 2178 | |
| 2179 | void SkCanvas::internalDrawPaint(const SkPaint& paint) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2180 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kPaint_Type, nullptr, false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2181 | |
| 2182 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2183 | iter.fDevice->drawPaint(iter, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2186 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2189 | void SkCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 2190 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2191 | TRACE_EVENT1("disabled-by-default-skia", "SkCanvas::drawPoints()", "count", static_cast<uint64_t>(count)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2192 | if ((long)count <= 0) { |
| 2193 | return; |
| 2194 | } |
| 2195 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2196 | SkRect r, storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2197 | const SkRect* bounds = nullptr; |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 2198 | if (paint.canComputeFastBounds()) { |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 2199 | // special-case 2 points (common for drawing a single line) |
| 2200 | if (2 == count) { |
| 2201 | r.set(pts[0], pts[1]); |
| 2202 | } else { |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 2203 | r.set(pts, SkToInt(count)); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 2204 | } |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2205 | if (this->quickReject(paint.computeFastStrokeBounds(r, &storage))) { |
| 2206 | return; |
| 2207 | } |
| 2208 | bounds = &r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 2209 | } |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 2210 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2211 | SkASSERT(pts != nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2212 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2213 | LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2214 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2215 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2216 | iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2217 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2218 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2219 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2222 | static bool needs_autodrawlooper(SkCanvas* canvas, const SkPaint& paint) { |
| 2223 | return ((intptr_t)paint.getImageFilter() | |
| 2224 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 2225 | (intptr_t)canvas->getDrawFilter() | |
| 2226 | #endif |
| 2227 | (intptr_t)paint.getLooper() ) != 0; |
| 2228 | } |
| 2229 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2230 | void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2231 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRect()"); |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2232 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2233 | const SkRect* bounds = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2234 | if (paint.canComputeFastBounds()) { |
reed | 8432808 | 2015-02-10 14:18:09 -0800 | [diff] [blame] | 2235 | // Skia will draw an inverted rect, because it explicitly "sorts" it downstream. |
| 2236 | // To prevent accidental rejecting at this stage, we have to sort it before we check. |
| 2237 | SkRect tmp(r); |
| 2238 | tmp.sort(); |
| 2239 | |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2240 | if (this->quickReject(paint.computeFastBounds(tmp, &storage))) { |
| 2241 | return; |
| 2242 | } |
| 2243 | bounds = &r; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2244 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2245 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2246 | if (needs_autodrawlooper(this, paint)) { |
| 2247 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, bounds, false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2248 | |
reed | 4a16717 | 2016-08-18 17:15:25 -0700 | [diff] [blame] | 2249 | while (iter.next()) { |
| 2250 | iter.fDevice->drawRect(iter, r, looper.paint()); |
| 2251 | } |
| 2252 | |
| 2253 | LOOPER_END |
| 2254 | } else { |
| 2255 | this->predrawNotify(bounds, &paint, false); |
| 2256 | SkDrawIter iter(this); |
| 2257 | while (iter.next()) { |
| 2258 | iter.fDevice->drawRect(iter, r, paint); |
| 2259 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2260 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 2263 | void SkCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
| 2264 | SkRect storage; |
| 2265 | SkRect regionRect = SkRect::Make(region.getBounds()); |
| 2266 | const SkRect* bounds = nullptr; |
| 2267 | if (paint.canComputeFastBounds()) { |
| 2268 | if (this->quickReject(paint.computeFastBounds(regionRect, &storage))) { |
| 2269 | return; |
| 2270 | } |
| 2271 | bounds = ®ionRect; |
| 2272 | } |
| 2273 | |
| 2274 | LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) |
| 2275 | |
| 2276 | while (iter.next()) { |
| 2277 | iter.fDevice->drawRegion(iter, region, looper.paint()); |
| 2278 | } |
| 2279 | |
| 2280 | LOOPER_END |
| 2281 | } |
| 2282 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2283 | void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2284 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawOval()"); |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2285 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2286 | const SkRect* bounds = nullptr; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2287 | if (paint.canComputeFastBounds()) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2288 | if (this->quickReject(paint.computeFastBounds(oval, &storage))) { |
| 2289 | return; |
| 2290 | } |
| 2291 | bounds = &oval; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2292 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 2293 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2294 | LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 2295 | |
| 2296 | while (iter.next()) { |
| 2297 | iter.fDevice->drawOval(iter, oval, looper.paint()); |
| 2298 | } |
| 2299 | |
| 2300 | LOOPER_END |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2303 | void SkCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, |
| 2304 | SkScalar sweepAngle, bool useCenter, |
| 2305 | const SkPaint& paint) { |
| 2306 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawArc()"); |
| 2307 | const SkRect* bounds = nullptr; |
| 2308 | if (paint.canComputeFastBounds()) { |
| 2309 | SkRect storage; |
| 2310 | // Note we're using the entire oval as the bounds. |
| 2311 | if (this->quickReject(paint.computeFastBounds(oval, &storage))) { |
| 2312 | return; |
| 2313 | } |
| 2314 | bounds = &oval; |
| 2315 | } |
| 2316 | |
| 2317 | LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) |
| 2318 | |
| 2319 | while (iter.next()) { |
| 2320 | iter.fDevice->drawArc(iter, oval, startAngle, sweepAngle, useCenter, looper.paint()); |
| 2321 | } |
| 2322 | |
| 2323 | LOOPER_END |
| 2324 | } |
| 2325 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2326 | void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2327 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRRect()"); |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2328 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2329 | const SkRect* bounds = nullptr; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2330 | if (paint.canComputeFastBounds()) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2331 | if (this->quickReject(paint.computeFastBounds(rrect.getBounds(), &storage))) { |
| 2332 | return; |
| 2333 | } |
| 2334 | bounds = &rrect.getBounds(); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | if (rrect.isRect()) { |
| 2338 | // call the non-virtual version |
| 2339 | this->SkCanvas::drawRect(rrect.getBounds(), paint); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2340 | return; |
| 2341 | } else if (rrect.isOval()) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2342 | // call the non-virtual version |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2343 | this->SkCanvas::drawOval(rrect.getBounds(), paint); |
| 2344 | return; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2345 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2346 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2347 | LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2348 | |
| 2349 | while (iter.next()) { |
| 2350 | iter.fDevice->drawRRect(iter, rrect, looper.paint()); |
| 2351 | } |
| 2352 | |
| 2353 | LOOPER_END |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2356 | void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 2357 | const SkPaint& paint) { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2358 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2359 | const SkRect* bounds = nullptr; |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2360 | if (paint.canComputeFastBounds()) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2361 | if (this->quickReject(paint.computeFastBounds(outer.getBounds(), &storage))) { |
| 2362 | return; |
| 2363 | } |
| 2364 | bounds = &outer.getBounds(); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2365 | } |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2366 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2367 | LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2368 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2369 | while (iter.next()) { |
| 2370 | iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); |
| 2371 | } |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 2372 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 2373 | LOOPER_END |
| 2374 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 2375 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2376 | void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2377 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPath()"); |
reed@google.com | 9364511 | 2012-07-26 16:11:47 +0000 | [diff] [blame] | 2378 | if (!path.isFinite()) { |
| 2379 | return; |
| 2380 | } |
| 2381 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2382 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2383 | const SkRect* bounds = nullptr; |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2384 | if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2385 | const SkRect& pathBounds = path.getBounds(); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2386 | if (this->quickReject(paint.computeFastBounds(pathBounds, &storage))) { |
| 2387 | return; |
| 2388 | } |
| 2389 | bounds = &pathBounds; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2390 | } |
commit-bot@chromium.org | 0b45dc4 | 2014-02-21 05:42:57 +0000 | [diff] [blame] | 2391 | |
| 2392 | const SkRect& r = path.getBounds(); |
| 2393 | if (r.width() <= 0 && r.height() <= 0) { |
commit-bot@chromium.org | 6803c21 | 2014-05-04 18:08:27 +0000 | [diff] [blame] | 2394 | if (path.isInverseFillType()) { |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2395 | this->internalDrawPaint(paint); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 2396 | return; |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2397 | } |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 2398 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2399 | |
senorblanco@chromium.org | 78cf119 | 2014-01-28 19:22:35 +0000 | [diff] [blame] | 2400 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2401 | |
| 2402 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2403 | iter.fDevice->drawPath(iter, path, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2406 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2409 | 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] | 2410 | if (!paint.getImageFilter()) { |
| 2411 | return false; |
| 2412 | } |
| 2413 | |
| 2414 | const SkMatrix& ctm = this->getTotalMatrix(); |
fmalita | c7e211a | 2016-01-07 10:34:46 -0800 | [diff] [blame] | 2415 | if (!SkTreatAsSprite(ctm, SkISize::Make(w, h), paint)) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2416 | return false; |
| 2417 | } |
| 2418 | |
| 2419 | // Currently we can only use the filterSprite code if we are clipped to the bitmap's bounds. |
| 2420 | // Once we can filter and the filter will return a result larger than itself, we should be |
| 2421 | // able to remove this constraint. |
| 2422 | // skbug.com/4526 |
| 2423 | // |
| 2424 | SkPoint pt; |
| 2425 | ctm.mapXY(x, y, &pt); |
| 2426 | SkIRect ir = SkIRect::MakeXYWH(SkScalarRoundToInt(pt.x()), SkScalarRoundToInt(pt.y()), w, h); |
| 2427 | return ir.contains(fMCRec->fRasterClip.getBounds()); |
| 2428 | } |
| 2429 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2430 | void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2431 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2432 | SkRect bounds = SkRect::MakeXYWH(x, y, |
| 2433 | SkIntToScalar(image->width()), SkIntToScalar(image->height())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2434 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2435 | SkRect tmp = bounds; |
| 2436 | if (paint) { |
| 2437 | paint->computeFastBounds(tmp, &tmp); |
| 2438 | } |
| 2439 | if (this->quickReject(tmp)) { |
| 2440 | return; |
| 2441 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2442 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2443 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2444 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2445 | if (nullptr == paint) { |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2446 | paint = lazy.init(); |
| 2447 | } |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2448 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2449 | sk_sp<SkSpecialImage> special; |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2450 | bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image->height(), |
| 2451 | *paint); |
| 2452 | if (drawAsSprite && paint->getImageFilter()) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2453 | special = this->getDevice()->makeSpecial(image); |
| 2454 | if (!special) { |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2455 | drawAsSprite = false; |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2459 | LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) |
| 2460 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2461 | while (iter.next()) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2462 | const SkPaint& pnt = looper.paint(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2463 | if (special) { |
| 2464 | SkPoint pt; |
| 2465 | iter.fMatrix->mapXY(x, y, &pt); |
| 2466 | iter.fDevice->drawSpecial(iter, special.get(), |
| 2467 | SkScalarRoundToInt(pt.fX), |
| 2468 | SkScalarRoundToInt(pt.fY), pnt); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2469 | } else { |
| 2470 | iter.fDevice->drawImage(iter, image, x, y, pnt); |
| 2471 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2472 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2473 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2474 | LOOPER_END |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2477 | void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2478 | const SkPaint* paint, SrcRectConstraint constraint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2479 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2480 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2481 | SkRect storage = dst; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2482 | if (paint) { |
| 2483 | paint->computeFastBounds(dst, &storage); |
| 2484 | } |
| 2485 | if (this->quickReject(storage)) { |
| 2486 | return; |
| 2487 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2488 | } |
| 2489 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2490 | if (nullptr == paint) { |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2491 | paint = lazy.init(); |
| 2492 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2493 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2494 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, &dst, |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 2495 | image->isOpaque()) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2496 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2497 | while (iter.next()) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2498 | iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint(), constraint); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2499 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2500 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 2501 | LOOPER_END |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2504 | void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, const SkPaint* paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2505 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2506 | SkDEBUGCODE(bitmap.validate();) |
| 2507 | |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2508 | if (bitmap.drawsNothing()) { |
| 2509 | return; |
| 2510 | } |
| 2511 | |
| 2512 | SkLazyPaint lazy; |
| 2513 | if (nullptr == paint) { |
| 2514 | paint = lazy.init(); |
| 2515 | } |
| 2516 | |
| 2517 | const SkMatrix matrix = SkMatrix::MakeTrans(x, y); |
| 2518 | |
| 2519 | SkRect storage; |
| 2520 | const SkRect* bounds = nullptr; |
| 2521 | if (paint->canComputeFastBounds()) { |
| 2522 | bitmap.getBounds(&storage); |
| 2523 | matrix.mapRect(&storage); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2524 | SkRect tmp = storage; |
| 2525 | if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { |
| 2526 | return; |
| 2527 | } |
| 2528 | bounds = &storage; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2529 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2530 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2531 | sk_sp<SkSpecialImage> special; |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2532 | bool drawAsSprite = bounds && this->canDrawBitmapAsSprite(x, y, bitmap.width(), bitmap.height(), |
| 2533 | *paint); |
| 2534 | if (drawAsSprite && paint->getImageFilter()) { |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2535 | special = this->getDevice()->makeSpecial(bitmap); |
| 2536 | if (!special) { |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 2537 | drawAsSprite = false; |
| 2538 | } |
| 2539 | } |
| 2540 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2541 | LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds) |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2542 | |
| 2543 | while (iter.next()) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2544 | const SkPaint& pnt = looper.paint(); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2545 | if (special) { |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2546 | SkPoint pt; |
| 2547 | iter.fMatrix->mapXY(x, y, &pt); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 2548 | iter.fDevice->drawSpecial(iter, special.get(), |
| 2549 | SkScalarRoundToInt(pt.fX), |
| 2550 | SkScalarRoundToInt(pt.fY), pnt); |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 2551 | } else { |
| 2552 | iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); |
| 2553 | } |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2554 | } |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 2555 | |
reed | 3336697 | 2015-10-08 09:22:02 -0700 | [diff] [blame] | 2556 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2559 | // 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] | 2560 | void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 2561 | const SkRect& dst, const SkPaint* paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2562 | SrcRectConstraint constraint) { |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 2563 | if (bitmap.drawsNothing() || dst.isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2564 | return; |
| 2565 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2566 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2567 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2568 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2569 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2570 | return; |
| 2571 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2572 | } |
reed@google.com | 3d60812 | 2011-11-21 15:16:16 +0000 | [diff] [blame] | 2573 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2574 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2575 | if (nullptr == paint) { |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2576 | paint = lazy.init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2577 | } |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2578 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2579 | LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, &dst, |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 2580 | bitmap.isOpaque()) |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2581 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2582 | while (iter.next()) { |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2583 | iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), constraint); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2584 | } |
skia.committer@gmail.com | 7064e9a | 2012-09-26 02:01:18 +0000 | [diff] [blame] | 2585 | |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 2586 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2589 | void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2590 | const SkPaint* paint, SrcRectConstraint constraint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2591 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()"); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2592 | SkDEBUGCODE(bitmap.validate();) |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 2593 | this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2596 | void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 2597 | const SkPaint* paint) { |
| 2598 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2599 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2600 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2601 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2602 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2603 | return; |
| 2604 | } |
reed@google.com | 3d60812 | 2011-11-21 15:16:16 +0000 | [diff] [blame] | 2605 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2606 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2607 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2608 | if (nullptr == paint) { |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2609 | paint = lazy.init(); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2610 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2611 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2612 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2613 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2614 | while (iter.next()) { |
| 2615 | iter.fDevice->drawImageNine(iter, image, center, dst, looper.paint()); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2616 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2617 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2618 | LOOPER_END |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2621 | void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 2622 | const SkPaint* paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2623 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapNine()"); |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2624 | SkDEBUGCODE(bitmap.validate();) |
| 2625 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2626 | if (nullptr == paint || paint->canComputeFastBounds()) { |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2627 | SkRect storage; |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2628 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2629 | return; |
| 2630 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2631 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2632 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2633 | SkLazyPaint lazy; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2634 | if (nullptr == paint) { |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2635 | paint = lazy.init(); |
| 2636 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2637 | |
senorblanco | c41e7e1 | 2015-12-07 12:51:30 -0800 | [diff] [blame] | 2638 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2639 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2640 | while (iter.next()) { |
| 2641 | iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); |
| 2642 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2643 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 2644 | LOOPER_END |
reed@google.com | 9987ec3 | 2011-09-07 11:57:52 +0000 | [diff] [blame] | 2645 | } |
| 2646 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 2647 | void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 2648 | const SkPaint* paint) { |
| 2649 | if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2650 | SkRect storage; |
| 2651 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2652 | return; |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | SkLazyPaint lazy; |
| 2657 | if (nullptr == paint) { |
| 2658 | paint = lazy.init(); |
| 2659 | } |
| 2660 | |
| 2661 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2662 | |
| 2663 | while (iter.next()) { |
| 2664 | iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint()); |
| 2665 | } |
| 2666 | |
| 2667 | LOOPER_END |
| 2668 | } |
| 2669 | |
| 2670 | void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, |
| 2671 | const SkRect& dst, const SkPaint* paint) { |
| 2672 | if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2673 | SkRect storage; |
| 2674 | if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) { |
| 2675 | return; |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | SkLazyPaint lazy; |
| 2680 | if (nullptr == paint) { |
| 2681 | paint = lazy.init(); |
| 2682 | } |
| 2683 | |
| 2684 | LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst) |
| 2685 | |
| 2686 | while (iter.next()) { |
| 2687 | iter.fDevice->drawBitmapLattice(iter, bitmap, lattice, dst, looper.paint()); |
| 2688 | } |
| 2689 | |
| 2690 | LOOPER_END |
| 2691 | } |
| 2692 | |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2693 | class SkDeviceFilteredPaint { |
| 2694 | public: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 2695 | SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { |
fmalita | 112e7e2 | 2014-11-13 14:05:58 -0800 | [diff] [blame] | 2696 | uint32_t filteredFlags = device->filterTextFlags(paint); |
| 2697 | if (filteredFlags != paint.getFlags()) { |
reed@google.com | a076e9b | 2011-04-06 20:17:29 +0000 | [diff] [blame] | 2698 | SkPaint* newPaint = fLazy.set(paint); |
fmalita | 112e7e2 | 2014-11-13 14:05:58 -0800 | [diff] [blame] | 2699 | newPaint->setFlags(filteredFlags); |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2700 | fPaint = newPaint; |
| 2701 | } else { |
| 2702 | fPaint = &paint; |
| 2703 | } |
| 2704 | } |
| 2705 | |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2706 | const SkPaint& paint() const { return *fPaint; } |
| 2707 | |
| 2708 | private: |
mike@reedtribe.org | 2c8fc5a | 2011-04-10 00:35:29 +0000 | [diff] [blame] | 2709 | const SkPaint* fPaint; |
| 2710 | SkLazyPaint fLazy; |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2711 | }; |
| 2712 | |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2713 | void SkCanvas::DrawRect(const SkDraw& draw, const SkPaint& paint, |
| 2714 | const SkRect& r, SkScalar textSize) { |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 2715 | if (paint.getStyle() == SkPaint::kFill_Style) { |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2716 | draw.fDevice->drawRect(draw, r, paint); |
| 2717 | } else { |
| 2718 | SkPaint p(paint); |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 2719 | p.setStrokeWidth(SkScalarMul(textSize, paint.getStrokeWidth())); |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2720 | draw.fDevice->drawRect(draw, r, p); |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | void SkCanvas::DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
| 2725 | const char text[], size_t byteLength, |
| 2726 | SkScalar x, SkScalar y) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2727 | SkASSERT(byteLength == 0 || text != nullptr); |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2728 | |
| 2729 | // nothing to draw |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2730 | if (text == nullptr || byteLength == 0 || |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 2731 | draw.fRC->isEmpty() || |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2732 | (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) { |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2733 | return; |
| 2734 | } |
| 2735 | |
| 2736 | SkScalar width = 0; |
| 2737 | SkPoint start; |
| 2738 | |
| 2739 | start.set(0, 0); // to avoid warning |
| 2740 | if (paint.getFlags() & (SkPaint::kUnderlineText_Flag | |
| 2741 | SkPaint::kStrikeThruText_Flag)) { |
| 2742 | width = paint.measureText(text, byteLength); |
| 2743 | |
| 2744 | SkScalar offsetX = 0; |
| 2745 | if (paint.getTextAlign() == SkPaint::kCenter_Align) { |
| 2746 | offsetX = SkScalarHalf(width); |
| 2747 | } else if (paint.getTextAlign() == SkPaint::kRight_Align) { |
| 2748 | offsetX = width; |
| 2749 | } |
| 2750 | start.set(x - offsetX, y); |
| 2751 | } |
| 2752 | |
| 2753 | if (0 == width) { |
| 2754 | return; |
| 2755 | } |
| 2756 | |
| 2757 | uint32_t flags = paint.getFlags(); |
| 2758 | |
| 2759 | if (flags & (SkPaint::kUnderlineText_Flag | |
| 2760 | SkPaint::kStrikeThruText_Flag)) { |
| 2761 | SkScalar textSize = paint.getTextSize(); |
| 2762 | SkScalar height = SkScalarMul(textSize, kStdUnderline_Thickness); |
| 2763 | SkRect r; |
| 2764 | |
| 2765 | r.fLeft = start.fX; |
| 2766 | r.fRight = start.fX + width; |
| 2767 | |
| 2768 | if (flags & SkPaint::kUnderlineText_Flag) { |
| 2769 | SkScalar offset = SkScalarMulAdd(textSize, kStdUnderline_Offset, |
| 2770 | start.fY); |
| 2771 | r.fTop = offset; |
| 2772 | r.fBottom = offset + height; |
caryclark | fb56218 | 2015-12-21 08:35:51 -0800 | [diff] [blame] | 2773 | DrawRect(draw, paint, r, 1); |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2774 | } |
| 2775 | if (flags & SkPaint::kStrikeThruText_Flag) { |
| 2776 | SkScalar offset = SkScalarMulAdd(textSize, kStdStrikeThru_Offset, |
| 2777 | start.fY); |
| 2778 | r.fTop = offset; |
| 2779 | r.fBottom = offset + height; |
caryclark | fb56218 | 2015-12-21 08:35:51 -0800 | [diff] [blame] | 2780 | DrawRect(draw, paint, r, 1); |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | } |
| 2784 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2785 | void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 2786 | const SkPaint& paint) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2787 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2788 | |
| 2789 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2790 | SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2791 | iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 2792 | DrawTextDecorations(iter, dfp.paint(), |
| 2793 | static_cast<const char*>(text), byteLength, x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2796 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2797 | } |
| 2798 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2799 | void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 2800 | const SkPaint& paint) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2801 | SkPoint textOffset = SkPoint::Make(0, 0); |
| 2802 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2803 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2804 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2805 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2806 | SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2807 | iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 2, textOffset, |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2808 | dfp.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2809 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2810 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2811 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2814 | void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 2815 | SkScalar constY, const SkPaint& paint) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2816 | |
| 2817 | SkPoint textOffset = SkPoint::Make(0, constY); |
| 2818 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2819 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2820 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2821 | while (iter.next()) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2822 | SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2823 | iter.fDevice->drawPosText(iter, text, byteLength, xpos, 1, textOffset, |
reed@google.com | f67e4cf | 2011-03-15 20:56:58 +0000 | [diff] [blame] | 2824 | dfp.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2825 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2826 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2827 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2830 | void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 2831 | const SkMatrix* matrix, const SkPaint& paint) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2832 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2833 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2834 | while (iter.next()) { |
| 2835 | iter.fDevice->drawTextOnPath(iter, text, byteLength, path, |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2836 | matrix, looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2837 | } |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 2838 | |
commit-bot@chromium.org | 945ec3a | 2014-04-22 20:07:30 +0000 | [diff] [blame] | 2839 | LOOPER_END |
commit-bot@chromium.org | 4325d11 | 2014-04-22 19:03:02 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2842 | void SkCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 2843 | const SkRect* cullRect, const SkPaint& paint) { |
| 2844 | if (cullRect && this->quickReject(*cullRect)) { |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr) |
| 2849 | |
| 2850 | while (iter.next()) { |
| 2851 | iter.fDevice->drawTextRSXform(iter, text, byteLength, xform, looper.paint()); |
| 2852 | } |
| 2853 | |
| 2854 | LOOPER_END |
| 2855 | } |
| 2856 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2857 | void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2858 | const SkPaint& paint) { |
fmalita | 7ba7aa7 | 2014-08-29 09:46:36 -0700 | [diff] [blame] | 2859 | |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2860 | SkRect storage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2861 | const SkRect* bounds = nullptr; |
fmalita | 19653d1 | 2014-10-16 11:53:30 -0700 | [diff] [blame] | 2862 | if (paint.canComputeFastBounds()) { |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2863 | storage = blob->bounds().makeOffset(x, y); |
senorblanco | 87e066e | 2015-10-28 11:23:36 -0700 | [diff] [blame] | 2864 | SkRect tmp; |
| 2865 | if (this->quickReject(paint.computeFastBounds(storage, &tmp))) { |
| 2866 | return; |
| 2867 | } |
| 2868 | bounds = &storage; |
fmalita | 7ba7aa7 | 2014-08-29 09:46:36 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2871 | // We cannot filter in the looper as we normally do, because the paint is |
| 2872 | // incomplete at this point (text-related attributes are embedded within blob run paints). |
| 2873 | SkDrawFilter* drawFilter = fMCRec->fFilter; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2874 | fMCRec->fFilter = nullptr; |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2875 | |
fmalita | 85d5eb9 | 2015-03-04 11:20:12 -0800 | [diff] [blame] | 2876 | LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds) |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2877 | |
fmalita | aa1b912 | 2014-08-28 14:32:24 -0700 | [diff] [blame] | 2878 | while (iter.next()) { |
| 2879 | SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2880 | iter.fDevice->drawTextBlob(iter, blob, x, y, dfp.paint(), drawFilter); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
fmalita | aa1b912 | 2014-08-28 14:32:24 -0700 | [diff] [blame] | 2883 | LOOPER_END |
fmalita | 024f996 | 2015-03-03 19:08:17 -0800 | [diff] [blame] | 2884 | |
| 2885 | fMCRec->fFilter = drawFilter; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2886 | } |
| 2887 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2888 | // These will become non-virtual, so they always call the (virtual) onDraw... method |
| 2889 | void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 2890 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2891 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawText()"); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2892 | if (byteLength) { |
| 2893 | this->onDrawText(text, byteLength, x, y, paint); |
| 2894 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2895 | } |
| 2896 | void SkCanvas::drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 2897 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2898 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPosText()"); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2899 | if (byteLength) { |
| 2900 | this->onDrawPosText(text, byteLength, pos, paint); |
| 2901 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2902 | } |
| 2903 | void SkCanvas::drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 2904 | SkScalar constY, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2905 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPosTextH()"); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2906 | if (byteLength) { |
| 2907 | this->onDrawPosTextH(text, byteLength, xpos, constY, paint); |
| 2908 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2909 | } |
| 2910 | void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 2911 | const SkMatrix* matrix, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2912 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextOnPath()"); |
reed | ac09554 | 2016-08-04 15:54:41 -0700 | [diff] [blame] | 2913 | if (byteLength) { |
| 2914 | this->onDrawTextOnPath(text, byteLength, path, matrix, paint); |
| 2915 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2916 | } |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 2917 | void SkCanvas::drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 2918 | const SkRect* cullRect, const SkPaint& paint) { |
| 2919 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextRSXform()"); |
| 2920 | if (byteLength) { |
| 2921 | this->onDrawTextRSXform(text, byteLength, xform, cullRect, paint); |
| 2922 | } |
| 2923 | } |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2924 | void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2925 | const SkPaint& paint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2926 | RETURN_ON_NULL(blob); |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2927 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextBlob()"); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2928 | this->onDrawTextBlob(blob, x, y, paint); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 2929 | } |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 2930 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 2931 | void SkCanvas::onDrawVertices(VertexMode vmode, int vertexCount, |
| 2932 | const SkPoint verts[], const SkPoint texs[], |
| 2933 | const SkColor colors[], SkXfermode* xmode, |
| 2934 | const uint16_t indices[], int indexCount, |
| 2935 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2936 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawVertices()"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2937 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2938 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2939 | while (iter.next()) { |
| 2940 | iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2941 | colors, xmode, indices, indexCount, |
| 2942 | looper.paint()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2943 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 2944 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 2945 | LOOPER_END |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2948 | void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 2949 | const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 2950 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPatch()"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2951 | if (nullptr == cubics) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2952 | return; |
| 2953 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2954 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2955 | // Since a patch is always within the convex hull of the control points, we discard it when its |
| 2956 | // bounding rectangle is completely outside the current clip. |
| 2957 | SkRect bounds; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2958 | bounds.set(cubics, SkPatchUtils::kNumCtrlPts); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2959 | if (this->quickReject(bounds)) { |
| 2960 | return; |
| 2961 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2962 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2963 | this->onDrawPatch(cubics, colors, texCoords, xmode, paint); |
| 2964 | } |
| 2965 | |
| 2966 | void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 2967 | const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { |
| 2968 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2969 | LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2970 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2971 | while (iter.next()) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 2972 | iter.fDevice->drawPatch(iter, cubics, colors, texCoords, xmode, paint); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2973 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 2974 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 2975 | LOOPER_END |
| 2976 | } |
| 2977 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2978 | void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2979 | RETURN_ON_NULL(dr); |
| 2980 | if (x || y) { |
| 2981 | SkMatrix matrix = SkMatrix::MakeTrans(x, y); |
| 2982 | this->onDrawDrawable(dr, &matrix); |
| 2983 | } else { |
| 2984 | this->onDrawDrawable(dr, nullptr); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2988 | void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2989 | RETURN_ON_NULL(dr); |
| 2990 | if (matrix && matrix->isIdentity()) { |
| 2991 | matrix = nullptr; |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2992 | } |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 2993 | this->onDrawDrawable(dr, matrix); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) { |
| 2997 | SkRect bounds = dr->getBounds(); |
| 2998 | if (matrix) { |
| 2999 | matrix->mapRect(&bounds); |
| 3000 | } |
| 3001 | if (this->quickReject(bounds)) { |
| 3002 | return; |
| 3003 | } |
| 3004 | dr->draw(this, matrix); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 3005 | } |
| 3006 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 3007 | void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 3008 | const SkColor colors[], int count, SkXfermode::Mode mode, |
| 3009 | const SkRect* cull, const SkPaint* paint) { |
| 3010 | if (cull && this->quickReject(*cull)) { |
| 3011 | return; |
| 3012 | } |
| 3013 | |
| 3014 | SkPaint pnt; |
| 3015 | if (paint) { |
| 3016 | pnt = *paint; |
| 3017 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3018 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3019 | LOOPER_BEGIN(pnt, SkDrawFilter::kPath_Type, nullptr) |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 3020 | while (iter.next()) { |
| 3021 | iter.fDevice->drawAtlas(iter, atlas, xform, tex, colors, count, mode, pnt); |
| 3022 | } |
| 3023 | LOOPER_END |
| 3024 | } |
| 3025 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 3026 | void SkCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 3027 | SkASSERT(key); |
| 3028 | |
| 3029 | SkPaint paint; |
| 3030 | LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, nullptr) |
| 3031 | while (iter.next()) { |
| 3032 | iter.fDevice->drawAnnotation(iter, rect, key, value); |
| 3033 | } |
| 3034 | LOOPER_END |
| 3035 | } |
| 3036 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3037 | ////////////////////////////////////////////////////////////////////////////// |
| 3038 | // These methods are NOT virtual, and therefore must call back into virtual |
| 3039 | // methods, rather than actually drawing themselves. |
| 3040 | ////////////////////////////////////////////////////////////////////////////// |
| 3041 | |
| 3042 | void SkCanvas::drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 3043 | SkXfermode::Mode mode) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3044 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawARGB()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3045 | SkPaint paint; |
| 3046 | |
| 3047 | paint.setARGB(a, r, g, b); |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 3048 | if (SkXfermode::kSrcOver_Mode != mode) { |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 3049 | paint.setXfermodeMode(mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3050 | } |
| 3051 | this->drawPaint(paint); |
| 3052 | } |
| 3053 | |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 3054 | void SkCanvas::drawColor(SkColor c, SkXfermode::Mode mode) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3055 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawColor()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3056 | SkPaint paint; |
| 3057 | |
| 3058 | paint.setColor(c); |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 3059 | if (SkXfermode::kSrcOver_Mode != mode) { |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 3060 | paint.setXfermodeMode(mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3061 | } |
| 3062 | this->drawPaint(paint); |
| 3063 | } |
| 3064 | |
| 3065 | void SkCanvas::drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3066 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPoint(SkPaint)"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3067 | SkPoint pt; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 3068 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3069 | pt.set(x, y); |
| 3070 | this->drawPoints(kPoints_PointMode, 1, &pt, paint); |
| 3071 | } |
| 3072 | |
| 3073 | void SkCanvas::drawPoint(SkScalar x, SkScalar y, SkColor color) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3074 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPoint(SkColor)"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3075 | SkPoint pt; |
| 3076 | SkPaint paint; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 3077 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3078 | pt.set(x, y); |
| 3079 | paint.setColor(color); |
| 3080 | this->drawPoints(kPoints_PointMode, 1, &pt, paint); |
| 3081 | } |
| 3082 | |
| 3083 | void SkCanvas::drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, |
| 3084 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3085 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawLine()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3086 | SkPoint pts[2]; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 3087 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3088 | pts[0].set(x0, y0); |
| 3089 | pts[1].set(x1, y1); |
| 3090 | this->drawPoints(kLines_PointMode, 2, pts, paint); |
| 3091 | } |
| 3092 | |
| 3093 | void SkCanvas::drawRectCoords(SkScalar left, SkScalar top, |
| 3094 | SkScalar right, SkScalar bottom, |
| 3095 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3096 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRectCoords()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3097 | SkRect r; |
| 3098 | |
| 3099 | r.set(left, top, right, bottom); |
| 3100 | this->drawRect(r, paint); |
| 3101 | } |
| 3102 | |
| 3103 | void SkCanvas::drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, |
| 3104 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3105 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawCircle()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3106 | if (radius < 0) { |
| 3107 | radius = 0; |
| 3108 | } |
| 3109 | |
| 3110 | SkRect r; |
| 3111 | r.set(cx - radius, cy - radius, cx + radius, cy + radius); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 3112 | this->drawOval(r, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, |
| 3116 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3117 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRoundRect()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3118 | if (rx > 0 && ry > 0) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 3119 | SkRRect rrect; |
| 3120 | rrect.setRectXY(r, rx, ry); |
| 3121 | this->drawRRect(rrect, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3122 | } else { |
| 3123 | this->drawRect(r, paint); |
| 3124 | } |
| 3125 | } |
| 3126 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3127 | void SkCanvas::drawArc(const SkRect& oval, SkScalar startAngle, |
| 3128 | SkScalar sweepAngle, bool useCenter, |
| 3129 | const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3130 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawArc()"); |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 3131 | if (oval.isEmpty() || !sweepAngle) { |
| 3132 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3133 | } |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 3134 | this->onDrawArc(oval, startAngle, sweepAngle, useCenter, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength, |
| 3138 | const SkPath& path, SkScalar hOffset, |
| 3139 | SkScalar vOffset, const SkPaint& paint) { |
danakj | 9881d63 | 2014-11-26 12:41:06 -0800 | [diff] [blame] | 3140 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextOnPathHV()"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3141 | SkMatrix matrix; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 3142 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3143 | matrix.setTranslate(hOffset, vOffset); |
| 3144 | this->drawTextOnPath(text, byteLength, path, &matrix, paint); |
| 3145 | } |
| 3146 | |
reed@android.com | f76bacf | 2009-05-13 14:00:33 +0000 | [diff] [blame] | 3147 | /////////////////////////////////////////////////////////////////////////////// |
reed | 1c2c441 | 2015-04-30 13:09:24 -0700 | [diff] [blame] | 3148 | |
| 3149 | /** |
| 3150 | * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture, |
| 3151 | * against the playback cost of recursing into the subpicture to get at its actual ops. |
| 3152 | * |
| 3153 | * For now we pick a conservatively small value, though measurement (and other heuristics like |
| 3154 | * the type of ops contained) may justify changing this value. |
| 3155 | */ |
| 3156 | #define kMaxPictureOpsToUnrollInsteadOfRef 1 |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 3157 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3158 | void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) { |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 3159 | RETURN_ON_NULL(picture); |
| 3160 | |
reed | 1c2c441 | 2015-04-30 13:09:24 -0700 | [diff] [blame] | 3161 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPicture()"); |
reed | e3b38ce | 2016-01-08 09:18:44 -0800 | [diff] [blame] | 3162 | if (matrix && matrix->isIdentity()) { |
| 3163 | matrix = nullptr; |
| 3164 | } |
| 3165 | if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) { |
| 3166 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 3167 | picture->playback(this); |
| 3168 | } else { |
| 3169 | this->onDrawPicture(picture, matrix, paint); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3170 | } |
| 3171 | } |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 3172 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3173 | void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 3174 | const SkPaint* paint) { |
fmalita | d028180 | 2015-08-20 12:08:18 -0700 | [diff] [blame] | 3175 | if (!paint || paint->canComputeFastBounds()) { |
| 3176 | SkRect bounds = picture->cullRect(); |
| 3177 | if (paint) { |
| 3178 | paint->computeFastBounds(bounds, &bounds); |
| 3179 | } |
| 3180 | if (matrix) { |
| 3181 | matrix->mapRect(&bounds); |
| 3182 | } |
| 3183 | if (this->quickReject(bounds)) { |
| 3184 | return; |
| 3185 | } |
| 3186 | } |
| 3187 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 3188 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 3189 | picture->playback(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 3192 | #ifdef SK_EXPERIMENTAL_SHADOWING |
| 3193 | void SkCanvas::drawShadowedPicture(const SkPicture* picture, |
| 3194 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3195 | const SkPaint* paint, |
| 3196 | const SkShadowParams& params) { |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 3197 | RETURN_ON_NULL(picture); |
| 3198 | |
| 3199 | TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); |
| 3200 | |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3201 | this->onDrawShadowedPicture(picture, matrix, paint, params); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| 3205 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3206 | const SkPaint* paint, |
| 3207 | const SkShadowParams& params) { |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3208 | if (!paint || paint->canComputeFastBounds()) { |
| 3209 | SkRect bounds = picture->cullRect(); |
| 3210 | if (paint) { |
| 3211 | paint->computeFastBounds(bounds, &bounds); |
| 3212 | } |
| 3213 | if (matrix) { |
| 3214 | matrix->mapRect(&bounds); |
| 3215 | } |
| 3216 | if (this->quickReject(bounds)) { |
| 3217 | return; |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 3222 | |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3223 | sk_sp<SkImage> povDepthMap; |
| 3224 | sk_sp<SkImage> diffuseMap; |
| 3225 | |
| 3226 | // TODO: pass the depth to the shader in vertices, or uniforms |
| 3227 | // so we don't have to render depth and color separately |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3228 | for (int i = 0; i < fLights->numLights(); ++i) { |
| 3229 | // skip over ambient lights; they don't cast shadows |
| 3230 | // lights that have shadow maps do not need updating (because lights are immutable) |
| 3231 | |
vjiaoblack | a8eabc4 | 2016-08-29 10:22:09 -0700 | [diff] [blame] | 3232 | if (fLights->light(i).getShadowMap() != nullptr) { |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3233 | continue; |
| 3234 | } |
| 3235 | |
| 3236 | // TODO: compute the correct size of the depth map from the light properties |
| 3237 | // TODO: maybe add a kDepth_8_SkColorType |
| 3238 | // TODO: find actual max depth of picture |
| 3239 | SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize( |
| 3240 | fLights->light(i), 255, |
| 3241 | picture->cullRect().width(), |
| 3242 | picture->cullRect().height()); |
| 3243 | |
| 3244 | SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
| 3245 | kBGRA_8888_SkColorType, |
| 3246 | kOpaque_SkAlphaType); |
| 3247 | |
| 3248 | // Create a new surface (that matches the backend of canvas) |
| 3249 | // for each shadow map |
| 3250 | sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3251 | |
| 3252 | // Wrap another SPFCanvas around the surface |
| 3253 | sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| 3254 | sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3255 | depthMapCanvas->setShadowParams(params); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3256 | |
| 3257 | // set the depth map canvas to have the light we're drawing. |
| 3258 | SkLights::Builder builder; |
| 3259 | builder.add(fLights->light(i)); |
| 3260 | sk_sp<SkLights> curLight = builder.finish(); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3261 | depthMapCanvas->setLights(std::move(curLight)); |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3262 | |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3263 | depthMapCanvas->drawPicture(picture); |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3264 | sk_sp<SkImage> depthMap = surf->makeImageSnapshot(); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3265 | |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3266 | if (params.fType == SkShadowParams::kNoBlur_ShadowType) { |
| 3267 | fLights->light(i).setShadowMap(std::move(depthMap)); |
| 3268 | } else if (params.fType == SkShadowParams::kVariance_ShadowType) { |
| 3269 | // we blur the variance map |
| 3270 | SkPaint blurPaint; |
| 3271 | blurPaint.setImageFilter(SkImageFilter::MakeBlur(params.fShadowRadius, |
| 3272 | params.fShadowRadius, nullptr)); |
| 3273 | |
| 3274 | SkImageInfo blurInfo = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
| 3275 | kBGRA_8888_SkColorType, |
| 3276 | kOpaque_SkAlphaType); |
| 3277 | |
| 3278 | sk_sp<SkSurface> blurSurf(this->makeSurface(blurInfo)); |
| 3279 | |
| 3280 | blurSurf->getCanvas()->drawImage(std::move(depthMap), 0, 0, &blurPaint); |
| 3281 | |
| 3282 | fLights->light(i).setShadowMap(blurSurf->makeImageSnapshot()); |
| 3283 | } |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3286 | // povDepthMap |
| 3287 | { |
| 3288 | SkLights::Builder builder; |
vjiaoblack | 772b5ee | 2016-08-12 11:38:47 -0700 | [diff] [blame] | 3289 | builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f), |
| 3290 | SkVector3::Make(0.0f, 0.0f, 1.0f))); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3291 | sk_sp<SkLights> povLight = builder.finish(); |
| 3292 | |
| 3293 | SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), |
| 3294 | picture->cullRect().height(), |
| 3295 | kBGRA_8888_SkColorType, |
| 3296 | kOpaque_SkAlphaType); |
| 3297 | |
| 3298 | // Create a new surface (that matches the backend of canvas) |
| 3299 | // to create the povDepthMap |
| 3300 | sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3301 | |
| 3302 | // Wrap another SPFCanvas around the surface |
| 3303 | sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| 3304 | sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| 3305 | |
| 3306 | // set the depth map canvas to have the light as the user's POV |
| 3307 | depthMapCanvas->setLights(std::move(povLight)); |
| 3308 | |
| 3309 | depthMapCanvas->drawPicture(picture); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3310 | povDepthMap = surf->makeImageSnapshot(); |
| 3311 | } |
| 3312 | |
| 3313 | // diffuseMap |
| 3314 | { |
| 3315 | SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), |
| 3316 | picture->cullRect().height(), |
| 3317 | kBGRA_8888_SkColorType, |
| 3318 | kOpaque_SkAlphaType); |
| 3319 | |
| 3320 | sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3321 | surf->getCanvas()->drawPicture(picture); |
| 3322 | |
| 3323 | diffuseMap = surf->makeImageSnapshot(); |
| 3324 | } |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3325 | SkPaint shadowPaint; |
| 3326 | |
| 3327 | sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode, |
| 3328 | SkShader::kClamp_TileMode); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3329 | sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_TileMode, |
| 3330 | SkShader::kClamp_TileMode); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3331 | sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader), |
| 3332 | std::move(diffuseShader), |
| 3333 | std::move(fLights), |
| 3334 | diffuseMap->width(), |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 3335 | diffuseMap->height(), |
| 3336 | params); |
vjiaoblack | 904527d | 2016-08-09 09:32:09 -0700 | [diff] [blame] | 3337 | |
| 3338 | shadowPaint.setShader(shadowShader); |
| 3339 | |
| 3340 | this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), shadowPaint); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 3341 | } |
| 3342 | #endif |
| 3343 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3344 | /////////////////////////////////////////////////////////////////////////////// |
| 3345 | /////////////////////////////////////////////////////////////////////////////// |
| 3346 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 3347 | SkCanvas::LayerIter::LayerIter(SkCanvas* canvas) { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 3348 | static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3349 | |
| 3350 | SkASSERT(canvas); |
| 3351 | |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 3352 | fImpl = new (fStorage) SkDrawIter(canvas); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3353 | fDone = !fImpl->next(); |
| 3354 | } |
| 3355 | |
| 3356 | SkCanvas::LayerIter::~LayerIter() { |
| 3357 | fImpl->~SkDrawIter(); |
| 3358 | } |
| 3359 | |
| 3360 | void SkCanvas::LayerIter::next() { |
| 3361 | fDone = !fImpl->next(); |
| 3362 | } |
| 3363 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 3364 | SkBaseDevice* SkCanvas::LayerIter::device() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3365 | return fImpl->getDevice(); |
| 3366 | } |
| 3367 | |
| 3368 | const SkMatrix& SkCanvas::LayerIter::matrix() const { |
| 3369 | return fImpl->getMatrix(); |
| 3370 | } |
| 3371 | |
| 3372 | const SkPaint& SkCanvas::LayerIter::paint() const { |
| 3373 | const SkPaint* paint = fImpl->getPaint(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3374 | if (nullptr == paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3375 | paint = &fDefaultPaint; |
| 3376 | } |
| 3377 | return *paint; |
| 3378 | } |
| 3379 | |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 3380 | const SkRasterClip& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3381 | int SkCanvas::LayerIter::x() const { return fImpl->getX(); } |
| 3382 | int SkCanvas::LayerIter::y() const { return fImpl->getY(); } |
justinlin@google.com | 20a550c | 2012-07-27 17:37:12 +0000 | [diff] [blame] | 3383 | |
| 3384 | /////////////////////////////////////////////////////////////////////////////// |
| 3385 | |
fmalita | c3b589a | 2014-06-05 12:40:07 -0700 | [diff] [blame] | 3386 | SkCanvasClipVisitor::~SkCanvasClipVisitor() { } |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 3387 | |
| 3388 | /////////////////////////////////////////////////////////////////////////////// |
| 3389 | |
| 3390 | static bool supported_for_raster_canvas(const SkImageInfo& info) { |
| 3391 | switch (info.alphaType()) { |
| 3392 | case kPremul_SkAlphaType: |
| 3393 | case kOpaque_SkAlphaType: |
| 3394 | break; |
| 3395 | default: |
| 3396 | return false; |
| 3397 | } |
| 3398 | |
| 3399 | switch (info.colorType()) { |
| 3400 | case kAlpha_8_SkColorType: |
| 3401 | case kRGB_565_SkColorType: |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 3402 | case kN32_SkColorType: |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 3403 | break; |
| 3404 | default: |
| 3405 | return false; |
| 3406 | } |
| 3407 | |
| 3408 | return true; |
| 3409 | } |
| 3410 | |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 3411 | SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
| 3412 | if (!supported_for_raster_canvas(info)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3413 | return nullptr; |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 3414 | } |
skia.committer@gmail.com | eb849e5 | 2014-03-17 03:02:17 +0000 | [diff] [blame] | 3415 | |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 3416 | SkBitmap bitmap; |
| 3417 | if (!bitmap.installPixels(info, pixels, rowBytes)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3418 | return nullptr; |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 3419 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 3420 | return new SkCanvas(bitmap); |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 3421 | } |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3422 | |
| 3423 | /////////////////////////////////////////////////////////////////////////////// |
| 3424 | |
| 3425 | SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatrix* matrix, |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 3426 | const SkPaint* paint, const SkRect& bounds) |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3427 | : fCanvas(canvas) |
| 3428 | , fSaveCount(canvas->getSaveCount()) |
| 3429 | { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 3430 | if (paint) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 3431 | SkRect newBounds = bounds; |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3432 | if (matrix) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 3433 | matrix->mapRect(&newBounds); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3434 | } |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 3435 | canvas->saveLayer(&newBounds, paint); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 3436 | } else if (matrix) { |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3437 | canvas->save(); |
| 3438 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 3439 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 3440 | if (matrix) { |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 3441 | canvas->concat(*matrix); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 3446 | fCanvas->restoreToCount(fSaveCount); |
| 3447 | } |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 3448 | |
| 3449 | #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
| 3450 | SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* props) { |
| 3451 | return this->makeSurface(info, props).release(); |
| 3452 | } |
| 3453 | #endif |