Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 17 | #include "SkiaCanvas.h" |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 18 | |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 19 | #include "CanvasProperty.h" |
Matt Sarett | 7de7385 | 2016-10-25 18:36:39 -0400 | [diff] [blame] | 20 | #include "NinePatchUtils.h" |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 21 | #include "VectorDrawable.h" |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 22 | #include "hwui/Bitmap.h" |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 23 | #include "hwui/MinikinUtils.h" |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 24 | #include "hwui/PaintFilter.h" |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 25 | #include "pipeline/skia/AnimatedDrawables.h" |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 26 | |
Derek Sollenberger | 24fc901 | 2018-12-07 14:12:12 -0500 | [diff] [blame] | 27 | #include <SkAndroidFrameworkUtils.h> |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 28 | #include <SkAnimatedImage.h> |
Derek Sollenberger | ac33a48 | 2019-04-22 16:28:09 -0400 | [diff] [blame] | 29 | #include <SkCanvasPriv.h> |
Matt Sarett | d0814db | 2017-04-13 09:33:18 -0400 | [diff] [blame] | 30 | #include <SkCanvasStateUtils.h> |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 31 | #include <SkColorFilter.h> |
John Reck | 849911a | 2015-01-20 07:51:14 -0800 | [diff] [blame] | 32 | #include <SkDeque.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 33 | #include <SkDrawable.h> |
Mike Reed | 1c79eab | 2018-11-21 11:01:57 -0500 | [diff] [blame] | 34 | #include <SkFont.h> |
John Reck | 849911a | 2015-01-20 07:51:14 -0800 | [diff] [blame] | 35 | #include <SkGraphics.h> |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 36 | #include <SkImage.h> |
Matt Sarett | 62feb3a | 2016-09-20 10:34:11 -0400 | [diff] [blame] | 37 | #include <SkImagePriv.h> |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 38 | #include <SkPicture.h> |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 39 | #include <SkRSXform.h> |
John Reck | 849911a | 2015-01-20 07:51:14 -0800 | [diff] [blame] | 40 | #include <SkShader.h> |
John Reck | 849911a | 2015-01-20 07:51:14 -0800 | [diff] [blame] | 41 | #include <SkTemplates.h> |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 42 | #include <SkTextBlob.h> |
Brian Osman | e3b9a12 | 2020-04-01 12:24:19 -0400 | [diff] [blame] | 43 | #include <SkVertices.h> |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 44 | |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 45 | #include <memory> |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 46 | #include <optional> |
| 47 | #include <utility> |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 48 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 49 | namespace android { |
| 50 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 51 | using uirenderer::PaintUtils; |
| 52 | |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 53 | Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 54 | return new SkiaCanvas(bitmap); |
| 55 | } |
| 56 | |
Derek Sollenberger | fa3e340 | 2017-08-04 08:35:10 -0400 | [diff] [blame] | 57 | Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) { |
| 58 | return new SkiaCanvas(skiaCanvas); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 61 | SkiaCanvas::SkiaCanvas() {} |
| 62 | |
Derek Sollenberger | fa3e340 | 2017-08-04 08:35:10 -0400 | [diff] [blame] | 63 | SkiaCanvas::SkiaCanvas(SkCanvas* canvas) : mCanvas(canvas) {} |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 64 | |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 65 | SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { |
Derek Sollenberger | d01b591 | 2018-10-19 15:55:33 -0400 | [diff] [blame] | 66 | mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap)); |
| 67 | mCanvas = mCanvasOwned.get(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 70 | SkiaCanvas::~SkiaCanvas() {} |
| 71 | |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 72 | void SkiaCanvas::reset(SkCanvas* skiaCanvas) { |
Mike Reed | 6acfe16 | 2016-11-18 17:21:09 -0500 | [diff] [blame] | 73 | if (mCanvas != skiaCanvas) { |
| 74 | mCanvas = skiaCanvas; |
| 75 | mCanvasOwned.reset(); |
| 76 | } |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 77 | mSaveStack.reset(nullptr); |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 78 | } |
| 79 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 80 | // ---------------------------------------------------------------------------- |
| 81 | // Canvas state operations: Replace Bitmap |
| 82 | // ---------------------------------------------------------------------------- |
| 83 | |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 84 | void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { |
Tony Mantler | 4f641d1 | 2017-03-14 22:36:14 +0000 | [diff] [blame] | 85 | // deletes the previously owned canvas (if any) |
Derek Sollenberger | d01b591 | 2018-10-19 15:55:33 -0400 | [diff] [blame] | 86 | mCanvasOwned.reset(new SkCanvas(bitmap)); |
| 87 | mCanvas = mCanvasOwned.get(); |
Tony Mantler | 4f641d1 | 2017-03-14 22:36:14 +0000 | [diff] [blame] | 88 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 89 | // clean up the old save stack |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 90 | mSaveStack.reset(nullptr); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // ---------------------------------------------------------------------------- |
| 94 | // Canvas state operations |
| 95 | // ---------------------------------------------------------------------------- |
| 96 | |
| 97 | bool SkiaCanvas::isOpaque() { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 98 | return mCanvas->imageInfo().isOpaque(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int SkiaCanvas::width() { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 102 | return mCanvas->imageInfo().width(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int SkiaCanvas::height() { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 106 | return mCanvas->imageInfo().height(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // ---------------------------------------------------------------------------- |
| 110 | // Canvas state operations: Save (layer) |
| 111 | // ---------------------------------------------------------------------------- |
| 112 | |
| 113 | int SkiaCanvas::getSaveCount() const { |
| 114 | return mCanvas->getSaveCount(); |
| 115 | } |
| 116 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 117 | int SkiaCanvas::save(SaveFlags::Flags flags) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 118 | int count = mCanvas->save(); |
| 119 | recordPartialSave(flags); |
| 120 | return count; |
| 121 | } |
| 122 | |
Florin Malita | 5e27140 | 2015-11-04 14:36:02 -0500 | [diff] [blame] | 123 | // The SkiaCanvas::restore operation layers on the capability to preserve |
| 124 | // either (or both) the matrix and/or clip state after a SkCanvas::restore |
| 125 | // operation. It does this by explicitly saving off the clip & matrix state |
| 126 | // when requested and playing it back after the SkCanvas::restore. |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 127 | void SkiaCanvas::restore() { |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 128 | const auto* rec = this->currentSaveRec(); |
| 129 | if (!rec) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 130 | // Fast path - no record for this frame. |
| 131 | mCanvas->restore(); |
| 132 | return; |
| 133 | } |
| 134 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 135 | bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 136 | bool preserveClip = !(rec->saveFlags & SaveFlags::Clip); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 137 | |
| 138 | SkMatrix savedMatrix; |
| 139 | if (preserveMatrix) { |
| 140 | savedMatrix = mCanvas->getTotalMatrix(); |
| 141 | } |
| 142 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 143 | const size_t clipIndex = rec->clipIndex; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 144 | |
| 145 | mCanvas->restore(); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 146 | mSaveStack->pop_back(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 147 | |
| 148 | if (preserveMatrix) { |
| 149 | mCanvas->setMatrix(savedMatrix); |
| 150 | } |
| 151 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 152 | if (preserveClip) { |
| 153 | this->applyPersistentClips(clipIndex); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 154 | } |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void SkiaCanvas::restoreToCount(int restoreCount) { |
| 158 | while (mCanvas->getSaveCount() > restoreCount) { |
| 159 | this->restore(); |
| 160 | } |
| 161 | } |
| 162 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 163 | static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) { |
| 164 | SkCanvas::SaveLayerFlags layerFlags = 0; |
| 165 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 166 | if (!(flags & SaveFlags::ClipToLayer)) { |
Mike Reed | 93b7120 | 2019-09-03 16:45:12 -0400 | [diff] [blame] | 167 | layerFlags |= SkCanvasPriv::kDontClipToLayer_SaveLayerFlag; |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return layerFlags; |
| 171 | } |
| 172 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 173 | int SkiaCanvas::saveLayer(float left, float top, float right, float bottom, const SkPaint* paint, |
| 174 | SaveFlags::Flags flags) { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 175 | const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); |
Derek Sollenberger | b820119 | 2017-01-09 16:11:59 -0500 | [diff] [blame] | 176 | const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags)); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 177 | |
Stan Iliev | 68885e3 | 2016-12-14 11:18:34 -0500 | [diff] [blame] | 178 | return mCanvas->saveLayer(rec); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 179 | } |
| 180 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 181 | int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom, int alpha, |
| 182 | SaveFlags::Flags flags) { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 183 | if (static_cast<unsigned>(alpha) < 0xFF) { |
Yuqian Li | fd92ee4 | 2016-04-27 17:03:38 -0400 | [diff] [blame] | 184 | SkPaint alphaPaint; |
| 185 | alphaPaint.setAlpha(alpha); |
| 186 | return this->saveLayer(left, top, right, bottom, &alphaPaint, flags); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 187 | } |
Yuqian Li | fd92ee4 | 2016-04-27 17:03:38 -0400 | [diff] [blame] | 188 | return this->saveLayer(left, top, right, bottom, nullptr, flags); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Derek Sollenberger | 24fc901 | 2018-12-07 14:12:12 -0500 | [diff] [blame] | 191 | int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) { |
| 192 | SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); |
| 193 | return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds); |
| 194 | } |
| 195 | |
Derek Sollenberger | ac33a48 | 2019-04-22 16:28:09 -0400 | [diff] [blame] | 196 | void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const SkPaint& paint) { |
| 197 | |
| 198 | while (mCanvas->getSaveCount() > restoreCount + 1) { |
| 199 | this->restore(); |
| 200 | } |
| 201 | |
| 202 | if (mCanvas->getSaveCount() == restoreCount + 1) { |
| 203 | SkCanvasPriv::DrawBehind(mCanvas, *filterPaint(paint)); |
| 204 | this->restore(); |
| 205 | } |
| 206 | } |
| 207 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 208 | class SkiaCanvas::Clip { |
| 209 | public: |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 210 | Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 211 | : mType(Type::Rect), mOp(op), mMatrix(m), mRRect(SkRRect::MakeRect(rect)) {} |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 212 | Clip(const SkRRect& rrect, SkClipOp op, const SkMatrix& m) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 213 | : mType(Type::RRect), mOp(op), mMatrix(m), mRRect(rrect) {} |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 214 | Clip(const SkPath& path, SkClipOp op, const SkMatrix& m) |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 215 | : mType(Type::Path), mOp(op), mMatrix(m), mPath(std::in_place, path) {} |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 216 | |
| 217 | void apply(SkCanvas* canvas) const { |
| 218 | canvas->setMatrix(mMatrix); |
| 219 | switch (mType) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 220 | case Type::Rect: |
Nader Jawad | e431e31 | 2019-12-04 14:13:18 -0800 | [diff] [blame] | 221 | // Don't anti-alias rectangular clips |
| 222 | canvas->clipRect(mRRect.rect(), mOp, false); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 223 | break; |
| 224 | case Type::RRect: |
Nader Jawad | e431e31 | 2019-12-04 14:13:18 -0800 | [diff] [blame] | 225 | // Ensure rounded rectangular clips are anti-aliased |
| 226 | canvas->clipRRect(mRRect, mOp, true); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 227 | break; |
| 228 | case Type::Path: |
Nader Jawad | e431e31 | 2019-12-04 14:13:18 -0800 | [diff] [blame] | 229 | // Ensure path clips are anti-aliased |
| 230 | canvas->clipPath(mPath.value(), mOp, true); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 231 | break; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | private: |
| 236 | enum class Type { |
| 237 | Rect, |
| 238 | RRect, |
| 239 | Path, |
| 240 | }; |
| 241 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 242 | Type mType; |
| 243 | SkClipOp mOp; |
| 244 | SkMatrix mMatrix; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 245 | |
| 246 | // These are logically a union (tracked separately due to non-POD path). |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 247 | std::optional<SkPath> mPath; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 248 | SkRRect mRRect; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 252 | const SaveRec* rec = mSaveStack ? static_cast<const SaveRec*>(mSaveStack->back()) : nullptr; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 253 | int currentSaveCount = mCanvas->getSaveCount(); |
| 254 | SkASSERT(!rec || currentSaveCount >= rec->saveCount); |
| 255 | |
| 256 | return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr; |
| 257 | } |
| 258 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 259 | // ---------------------------------------------------------------------------- |
| 260 | // functions to emulate legacy SaveFlags (i.e. independent matrix/clip flags) |
| 261 | // ---------------------------------------------------------------------------- |
| 262 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 263 | void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 264 | // A partial save is a save operation which doesn't capture the full canvas state. |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 265 | // (either SaveFlags::Matrix or SaveFlags::Clip is missing). |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 266 | |
| 267 | // Mask-out non canvas state bits. |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 268 | flags &= SaveFlags::MatrixClip; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 269 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 270 | if (flags == SaveFlags::MatrixClip) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 271 | // not a partial save. |
| 272 | return; |
| 273 | } |
| 274 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 275 | if (!mSaveStack) { |
Ben Wagner | d1cbc16 | 2015-08-19 12:45:09 -0400 | [diff] [blame] | 276 | mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8)); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | SaveRec* rec = static_cast<SaveRec*>(mSaveStack->push_back()); |
Florin Malita | 5e27140 | 2015-11-04 14:36:02 -0500 | [diff] [blame] | 280 | rec->saveCount = mCanvas->getSaveCount(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 281 | rec->saveFlags = flags; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 282 | rec->clipIndex = mClipStack.size(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 285 | template <typename T> |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 286 | void SkiaCanvas::recordClip(const T& clip, SkClipOp op) { |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 287 | // Only need tracking when in a partial save frame which |
| 288 | // doesn't restore the clip. |
| 289 | const SaveRec* rec = this->currentSaveRec(); |
| 290 | if (rec && !(rec->saveFlags & SaveFlags::Clip)) { |
| 291 | mClipStack.emplace_back(clip, op, mCanvas->getTotalMatrix()); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 295 | // Applies and optionally removes all clips >= index. |
| 296 | void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) { |
| 297 | SkASSERT(clipStartIndex <= mClipStack.size()); |
| 298 | const auto begin = mClipStack.cbegin() + clipStartIndex; |
| 299 | const auto end = mClipStack.cend(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 300 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 301 | // Clip application mutates the CTM. |
| 302 | const SkMatrix saveMatrix = mCanvas->getTotalMatrix(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 303 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 304 | for (auto clip = begin; clip != end; ++clip) { |
Mike Reed | 6acfe16 | 2016-11-18 17:21:09 -0500 | [diff] [blame] | 305 | clip->apply(mCanvas); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 308 | mCanvas->setMatrix(saveMatrix); |
| 309 | |
| 310 | // If the current/post-restore save rec is also persisting clips, we |
| 311 | // leave them on the stack to be reapplied part of the next restore(). |
| 312 | // Otherwise we're done and just pop them. |
| 313 | const auto* rec = this->currentSaveRec(); |
| 314 | if (!rec || (rec->saveFlags & SaveFlags::Clip)) { |
| 315 | mClipStack.erase(begin, end); |
| 316 | } |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // ---------------------------------------------------------------------------- |
| 320 | // Canvas state operations: Matrix |
| 321 | // ---------------------------------------------------------------------------- |
| 322 | |
| 323 | void SkiaCanvas::getMatrix(SkMatrix* outMatrix) const { |
| 324 | *outMatrix = mCanvas->getTotalMatrix(); |
| 325 | } |
| 326 | |
| 327 | void SkiaCanvas::setMatrix(const SkMatrix& matrix) { |
| 328 | mCanvas->setMatrix(matrix); |
| 329 | } |
| 330 | |
| 331 | void SkiaCanvas::concat(const SkMatrix& matrix) { |
| 332 | mCanvas->concat(matrix); |
| 333 | } |
| 334 | |
| 335 | void SkiaCanvas::rotate(float degrees) { |
| 336 | mCanvas->rotate(degrees); |
| 337 | } |
| 338 | |
| 339 | void SkiaCanvas::scale(float sx, float sy) { |
| 340 | mCanvas->scale(sx, sy); |
| 341 | } |
| 342 | |
| 343 | void SkiaCanvas::skew(float sx, float sy) { |
| 344 | mCanvas->skew(sx, sy); |
| 345 | } |
| 346 | |
| 347 | void SkiaCanvas::translate(float dx, float dy) { |
| 348 | mCanvas->translate(dx, dy); |
| 349 | } |
| 350 | |
| 351 | // ---------------------------------------------------------------------------- |
| 352 | // Canvas state operations: Clips |
| 353 | // ---------------------------------------------------------------------------- |
| 354 | |
| 355 | // This function is a mirror of SkCanvas::getClipBounds except that it does |
| 356 | // not outset the edge of the clip to account for anti-aliasing. There is |
| 357 | // a skia bug to investigate pushing this logic into back into skia. |
| 358 | // (see https://code.google.com/p/skia/issues/detail?id=1303) |
| 359 | bool SkiaCanvas::getClipBounds(SkRect* outRect) const { |
| 360 | SkIRect ibounds; |
Mike Reed | 5e43898 | 2017-01-25 08:23:25 -0500 | [diff] [blame] | 361 | if (!mCanvas->getDeviceClipBounds(&ibounds)) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 362 | return false; |
| 363 | } |
| 364 | |
| 365 | SkMatrix inverse; |
| 366 | // if we can't invert the CTM, we can't return local clip bounds |
| 367 | if (!mCanvas->getTotalMatrix().invert(&inverse)) { |
| 368 | if (outRect) { |
| 369 | outRect->setEmpty(); |
| 370 | } |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | if (NULL != outRect) { |
| 375 | SkRect r = SkRect::Make(ibounds); |
| 376 | inverse.mapRect(outRect, r); |
| 377 | } |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | bool SkiaCanvas::quickRejectRect(float left, float top, float right, float bottom) const { |
| 382 | SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); |
| 383 | return mCanvas->quickReject(bounds); |
| 384 | } |
| 385 | |
| 386 | bool SkiaCanvas::quickRejectPath(const SkPath& path) const { |
| 387 | return mCanvas->quickReject(path); |
| 388 | } |
| 389 | |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 390 | bool SkiaCanvas::clipRect(float left, float top, float right, float bottom, SkClipOp op) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 391 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 392 | this->recordClip(rect, op); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 393 | mCanvas->clipRect(rect, op); |
Chris Craik | 5ec6a28 | 2015-06-23 15:42:12 -0700 | [diff] [blame] | 394 | return !mCanvas->isClipEmpty(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 397 | bool SkiaCanvas::clipPath(const SkPath* path, SkClipOp op) { |
Derek Sollenberger | f7d98f4 | 2017-04-17 11:27:36 -0400 | [diff] [blame] | 398 | this->recordClip(*path, op); |
Nader Jawad | e431e31 | 2019-12-04 14:13:18 -0800 | [diff] [blame] | 399 | mCanvas->clipPath(*path, op, true); |
Chris Craik | 5ec6a28 | 2015-06-23 15:42:12 -0700 | [diff] [blame] | 400 | return !mCanvas->isClipEmpty(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 403 | // ---------------------------------------------------------------------------- |
| 404 | // Canvas state operations: Filters |
| 405 | // ---------------------------------------------------------------------------- |
| 406 | |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 407 | PaintFilter* SkiaCanvas::getPaintFilter() { |
| 408 | return mPaintFilter.get(); |
Derek Sollenberger | acb4099 | 2014-07-21 15:22:10 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 411 | void SkiaCanvas::setPaintFilter(sk_sp<PaintFilter> paintFilter) { |
| 412 | mPaintFilter = std::move(paintFilter); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | // ---------------------------------------------------------------------------- |
Matt Sarett | d0814db | 2017-04-13 09:33:18 -0400 | [diff] [blame] | 416 | // Canvas state operations: Capture |
| 417 | // ---------------------------------------------------------------------------- |
| 418 | |
| 419 | SkCanvasState* SkiaCanvas::captureCanvasState() const { |
| 420 | SkCanvas* canvas = mCanvas; |
| 421 | if (mCanvasOwned) { |
| 422 | // Important to use the underlying SkCanvas, not the wrapper. |
| 423 | canvas = mCanvasOwned.get(); |
| 424 | } |
| 425 | |
| 426 | // Workarounds for http://crbug.com/271096: SW draw only supports |
| 427 | // translate & scale transforms, and a simple rectangular clip. |
| 428 | // (This also avoids significant wasted time in calling |
| 429 | // SkCanvasStateUtils::CaptureCanvasState when the clip is complex). |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 430 | if (!canvas->isClipRect() || (canvas->getTotalMatrix().getType() & |
| 431 | ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) { |
| 432 | return nullptr; |
Matt Sarett | d0814db | 2017-04-13 09:33:18 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | return SkCanvasStateUtils::CaptureCanvasState(canvas); |
| 436 | } |
| 437 | |
| 438 | // ---------------------------------------------------------------------------- |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 439 | // Canvas draw operations |
| 440 | // ---------------------------------------------------------------------------- |
| 441 | |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 442 | void SkiaCanvas::drawColor(int color, SkBlendMode mode) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 443 | mCanvas->drawColor(color, mode); |
| 444 | } |
| 445 | |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 446 | SkiaCanvas::PaintCoW&& SkiaCanvas::filterPaint(PaintCoW&& paint) const { |
| 447 | if (mPaintFilter) { |
| 448 | mPaintFilter->filter(&paint.writeable()); |
| 449 | } |
| 450 | return std::move(paint); |
| 451 | } |
| 452 | |
Derek Sollenberger | acb4099 | 2014-07-21 15:22:10 -0400 | [diff] [blame] | 453 | void SkiaCanvas::drawPaint(const SkPaint& paint) { |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 454 | mCanvas->drawPaint(*filterPaint(paint)); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | // ---------------------------------------------------------------------------- |
| 458 | // Canvas draw operations: Geometry |
| 459 | // ---------------------------------------------------------------------------- |
| 460 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 461 | void SkiaCanvas::drawPoints(const float* points, int count, const Paint& paint, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 462 | SkCanvas::PointMode mode) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 463 | if (CC_UNLIKELY(count < 2 || paint.nothingToDraw())) return; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 464 | // convert the floats into SkPoints |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 465 | count >>= 1; // now it is the number of points |
Ben Wagner | 6bbf68d | 2015-08-19 11:26:06 -0400 | [diff] [blame] | 466 | std::unique_ptr<SkPoint[]> pts(new SkPoint[count]); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 467 | for (int i = 0; i < count; i++) { |
| 468 | pts[i].set(points[0], points[1]); |
| 469 | points += 2; |
| 470 | } |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 471 | |
| 472 | apply_looper(&paint, [&](const SkPaint& p) { |
| 473 | mCanvas->drawPoints(mode, count, pts.get(), p); |
| 474 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 477 | void SkiaCanvas::drawPoint(float x, float y, const Paint& paint) { |
| 478 | apply_looper(&paint, [&](const SkPaint& p) { |
| 479 | mCanvas->drawPoint(x, y, p); |
| 480 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 483 | void SkiaCanvas::drawPoints(const float* points, int count, const Paint& paint) { |
| 484 | this->drawPoints(points, count, paint, SkCanvas::kPoints_PointMode); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 488 | const Paint& paint) { |
| 489 | apply_looper(&paint, [&](const SkPaint& p) { |
| 490 | mCanvas->drawLine(startX, startY, stopX, stopY, p); |
| 491 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 494 | void SkiaCanvas::drawLines(const float* points, int count, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 495 | if (CC_UNLIKELY(count < 4 || paint.nothingToDraw())) return; |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 496 | this->drawPoints(points, count, paint, SkCanvas::kLines_PointMode); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 499 | void SkiaCanvas::drawRect(float left, float top, float right, float bottom, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 500 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 501 | apply_looper(&paint, [&](const SkPaint& p) { |
| 502 | mCanvas->drawRect({left, top, right, bottom}, p); |
| 503 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 504 | } |
| 505 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 506 | void SkiaCanvas::drawRegion(const SkRegion& region, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 507 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 508 | apply_looper(&paint, [&](const SkPaint& p) { |
| 509 | mCanvas->drawRegion(region, p); |
| 510 | }); |
Derek Sollenberger | 94394b3 | 2015-07-10 09:58:41 -0400 | [diff] [blame] | 511 | } |
| 512 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 513 | void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 514 | const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 515 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 516 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 517 | apply_looper(&paint, [&](const SkPaint& p) { |
| 518 | mCanvas->drawRoundRect(rect, rx, ry, p); |
| 519 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 520 | } |
| 521 | |
Nader Jawad | adfe1d9 | 2018-09-27 12:27:36 -0700 | [diff] [blame] | 522 | void SkiaCanvas::drawDoubleRoundRect(const SkRRect& outer, const SkRRect& inner, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 523 | const Paint& paint) { |
| 524 | apply_looper(&paint, [&](const SkPaint& p) { |
| 525 | mCanvas->drawDRRect(outer, inner, p); |
| 526 | }); |
Nader Jawad | adfe1d9 | 2018-09-27 12:27:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 529 | void SkiaCanvas::drawCircle(float x, float y, float radius, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 530 | if (CC_UNLIKELY(radius <= 0 || paint.nothingToDraw())) return; |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 531 | apply_looper(&paint, [&](const SkPaint& p) { |
| 532 | mCanvas->drawCircle(x, y, radius, p); |
| 533 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 536 | void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 537 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 538 | SkRect oval = SkRect::MakeLTRB(left, top, right, bottom); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 539 | apply_looper(&paint, [&](const SkPaint& p) { |
| 540 | mCanvas->drawOval(oval, p); |
| 541 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 542 | } |
| 543 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 544 | void SkiaCanvas::drawArc(float left, float top, float right, float bottom, float startAngle, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 545 | float sweepAngle, bool useCenter, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 546 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 547 | SkRect arc = SkRect::MakeLTRB(left, top, right, bottom); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 548 | apply_looper(&paint, [&](const SkPaint& p) { |
| 549 | if (fabs(sweepAngle) >= 360.0f) { |
| 550 | mCanvas->drawOval(arc, p); |
| 551 | } else { |
| 552 | mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, p); |
| 553 | } |
| 554 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 557 | void SkiaCanvas::drawPath(const SkPath& path, const Paint& paint) { |
Derek Sollenberger | 792fb32 | 2017-03-03 14:02:09 -0500 | [diff] [blame] | 558 | if (CC_UNLIKELY(paint.nothingToDraw())) return; |
Stan Iliev | 6dcfdec | 2017-08-15 16:42:05 -0400 | [diff] [blame] | 559 | if (CC_UNLIKELY(path.isEmpty() && (!path.isInverseFillType()))) { |
| 560 | return; |
| 561 | } |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 562 | apply_looper(&paint, [&](const SkPaint& p) { |
| 563 | mCanvas->drawPath(path, p); |
| 564 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 567 | void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const Paint& paint) { |
| 568 | apply_looper(&paint, [&](const SkPaint& p) { |
| 569 | mCanvas->drawVertices(vertices, mode, p); |
| 570 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | // ---------------------------------------------------------------------------- |
| 574 | // Canvas draw operations: Bitmaps |
| 575 | // ---------------------------------------------------------------------------- |
| 576 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 577 | void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) { |
| 578 | auto image = bitmap.makeImage(); |
| 579 | apply_looper(paint, [&](const SkPaint& p) { |
| 580 | mCanvas->drawImage(image, left, top, &p); |
| 581 | }); |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 584 | void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const Paint* paint) { |
| 585 | auto image = bitmap.makeImage(); |
Mike Reed | 6acfe16 | 2016-11-18 17:21:09 -0500 | [diff] [blame] | 586 | SkAutoCanvasRestore acr(mCanvas, true); |
Mike Reed | 70ffbf9 | 2014-12-08 17:03:30 -0500 | [diff] [blame] | 587 | mCanvas->concat(matrix); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 588 | apply_looper(paint, [&](const SkPaint& p) { |
| 589 | mCanvas->drawImage(image, 0, 0, &p); |
| 590 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 591 | } |
| 592 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 593 | void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight, |
| 594 | float srcBottom, float dstLeft, float dstTop, float dstRight, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 595 | float dstBottom, const Paint* paint) { |
| 596 | auto image = bitmap.makeImage(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 597 | SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom); |
| 598 | SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 599 | |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 600 | apply_looper(paint, [&](const SkPaint& p) { |
| 601 | mCanvas->drawImageRect(image, srcRect, dstRect, &p, SkCanvas::kFast_SrcRectConstraint); |
| 602 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 605 | void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 606 | const float* vertices, const int* colors, const Paint* paint) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 607 | const int ptCount = (meshWidth + 1) * (meshHeight + 1); |
| 608 | const int indexCount = meshWidth * meshHeight * 6; |
Mike Reed | 871cd2d | 2017-03-17 10:15:52 -0400 | [diff] [blame] | 609 | uint32_t flags = SkVertices::kHasTexCoords_BuilderFlag; |
| 610 | if (colors) { |
| 611 | flags |= SkVertices::kHasColors_BuilderFlag; |
| 612 | } |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 613 | SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags); |
Mike Reed | 871cd2d | 2017-03-17 10:15:52 -0400 | [diff] [blame] | 614 | memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint)); |
| 615 | if (colors) { |
| 616 | memcpy(builder.colors(), colors, ptCount * sizeof(SkColor)); |
| 617 | } |
| 618 | SkPoint* texs = builder.texCoords(); |
| 619 | uint16_t* indices = builder.indices(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 620 | |
| 621 | // cons up texture coordinates and indices |
| 622 | { |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 623 | const SkScalar w = SkIntToScalar(bitmap.width()); |
| 624 | const SkScalar h = SkIntToScalar(bitmap.height()); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 625 | const SkScalar dx = w / meshWidth; |
| 626 | const SkScalar dy = h / meshHeight; |
| 627 | |
| 628 | SkPoint* texsPtr = texs; |
| 629 | SkScalar y = 0; |
| 630 | for (int i = 0; i <= meshHeight; i++) { |
| 631 | if (i == meshHeight) { |
| 632 | y = h; // to ensure numerically we hit h exactly |
| 633 | } |
| 634 | SkScalar x = 0; |
| 635 | for (int j = 0; j < meshWidth; j++) { |
| 636 | texsPtr->set(x, y); |
| 637 | texsPtr += 1; |
| 638 | x += dx; |
| 639 | } |
| 640 | texsPtr->set(w, y); |
| 641 | texsPtr += 1; |
| 642 | y += dy; |
| 643 | } |
| 644 | SkASSERT(texsPtr - texs == ptCount); |
| 645 | } |
| 646 | |
| 647 | // cons up indices |
| 648 | { |
| 649 | uint16_t* indexPtr = indices; |
| 650 | int index = 0; |
| 651 | for (int i = 0; i < meshHeight; i++) { |
| 652 | for (int j = 0; j < meshWidth; j++) { |
| 653 | // lower-left triangle |
| 654 | *indexPtr++ = index; |
| 655 | *indexPtr++ = index + meshWidth + 1; |
| 656 | *indexPtr++ = index + meshWidth + 2; |
| 657 | // upper-right triangle |
| 658 | *indexPtr++ = index; |
| 659 | *indexPtr++ = index + meshWidth + 2; |
| 660 | *indexPtr++ = index + 1; |
| 661 | // bump to the next cell |
| 662 | index += 1; |
| 663 | } |
| 664 | // bump to the next row |
| 665 | index += 1; |
| 666 | } |
| 667 | SkASSERT(indexPtr - indices == indexCount); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 668 | } |
| 669 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 670 | // double-check that we have legal indices |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 671 | #ifdef SK_DEBUG |
| 672 | { |
| 673 | for (int i = 0; i < indexCount; i++) { |
| 674 | SkASSERT((unsigned)indices[i] < (unsigned)ptCount); |
| 675 | } |
| 676 | } |
| 677 | #endif |
| 678 | |
| 679 | // cons-up a shader for the bitmap |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 680 | Paint pnt; |
| 681 | if (paint) { |
| 682 | pnt = *paint; |
| 683 | } |
Nader Jawad | 5bed1f5 | 2020-09-25 00:27:29 -0700 | [diff] [blame] | 684 | pnt.setShader(bitmap.makeImage()->makeShader()); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 685 | auto v = builder.detach(); |
| 686 | apply_looper(&pnt, [&](const SkPaint& p) { |
| 687 | mCanvas->drawVertices(v, SkBlendMode::kModulate, p); |
| 688 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 689 | } |
| 690 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 691 | void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, float dstLeft, |
| 692 | float dstTop, float dstRight, float dstBottom, |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 693 | const Paint* paint) { |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 694 | SkCanvas::Lattice lattice; |
Derek Sollenberger | fb0c8fc | 2017-07-26 13:53:27 -0400 | [diff] [blame] | 695 | NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height()); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 696 | |
Stan Iliev | e12d731 | 2017-12-04 14:48:27 -0500 | [diff] [blame] | 697 | lattice.fRectTypes = nullptr; |
| 698 | lattice.fColors = nullptr; |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 699 | int numFlags = 0; |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 700 | if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) { |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 701 | // We can expect the framework to give us a color for every distinct rect. |
| 702 | // Skia requires a flag for every rect. |
| 703 | numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1); |
| 704 | } |
| 705 | |
Stan Iliev | e12d731 | 2017-12-04 14:48:27 -0500 | [diff] [blame] | 706 | SkAutoSTMalloc<25, SkCanvas::Lattice::RectType> flags(numFlags); |
| 707 | SkAutoSTMalloc<25, SkColor> colors(numFlags); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 708 | if (numFlags > 0) { |
Stan Iliev | e12d731 | 2017-12-04 14:48:27 -0500 | [diff] [blame] | 709 | NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk, colors.get()); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | lattice.fBounds = nullptr; |
| 713 | SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); |
Mike Reed | c2dbc03 | 2019-07-25 12:28:29 -0400 | [diff] [blame] | 714 | auto image = bitmap.makeImage(); |
| 715 | apply_looper(paint, [&](const SkPaint& p) { |
| 716 | mCanvas->drawImageLattice(image.get(), lattice, dst, &p); |
| 717 | }); |
Derek Sollenberger | edca320 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 718 | } |
| 719 | |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 720 | double SkiaCanvas::drawAnimatedImage(AnimatedImageDrawable* imgDrawable) { |
| 721 | return imgDrawable->drawStaging(mCanvas); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 722 | } |
| 723 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 724 | void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 725 | vectorDrawable->drawStaging(this); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 728 | // ---------------------------------------------------------------------------- |
| 729 | // Canvas draw operations: Text |
| 730 | // ---------------------------------------------------------------------------- |
| 731 | |
Mike Reed | 2dfd55d | 2019-01-08 16:19:03 -0500 | [diff] [blame] | 732 | void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const Paint& paint, float x, |
Seigo Nonaka | 63af7ba | 2020-09-21 23:07:43 -0700 | [diff] [blame] | 733 | float y, float totalAdvance) { |
Stan Iliev | 0b58d99 | 2017-03-30 18:22:27 -0400 | [diff] [blame] | 734 | if (count <= 0 || paint.nothingToDraw()) return; |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 735 | Paint paintCopy(paint); |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 736 | if (mPaintFilter) { |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 737 | mPaintFilter->filterFullPaint(&paintCopy); |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 738 | } |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 739 | const SkFont& font = paintCopy.getSkFont(); |
Stan Iliev | 7717e22 | 2018-02-05 18:04:11 -0500 | [diff] [blame] | 740 | // Stroke with a hairline is drawn on HW with a fill style for compatibility with Android O and |
| 741 | // older. |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 742 | if (!mCanvasOwned && sApiLevel <= 27 && paintCopy.getStrokeWidth() <= 0 && |
| 743 | paintCopy.getStyle() == SkPaint::kStroke_Style) { |
Stan Iliev | 7717e22 | 2018-02-05 18:04:11 -0500 | [diff] [blame] | 744 | paintCopy.setStyle(SkPaint::kFill_Style); |
| 745 | } |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 746 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 747 | SkTextBlobBuilder builder; |
Mike Reed | 2e204fc | 2019-01-28 13:31:36 -0500 | [diff] [blame] | 748 | const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(font, count); |
Stan Iliev | 0b58d99 | 2017-03-30 18:22:27 -0400 | [diff] [blame] | 749 | glyphFunc(buffer.glyphs, buffer.pos); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 750 | |
| 751 | sk_sp<SkTextBlob> textBlob(builder.make()); |
Nathaniel Nifong | 52d3777 | 2020-01-10 16:12:41 -0500 | [diff] [blame] | 752 | |
| 753 | apply_looper(&paintCopy, [&](const SkPaint& p) { |
| 754 | mCanvas->drawTextBlob(textBlob, 0, 0, p); |
| 755 | }); |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 756 | drawTextDecorations(x, y, totalAdvance, paintCopy); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 759 | void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset, |
Mike Reed | 2dfd55d | 2019-01-08 16:19:03 -0500 | [diff] [blame] | 760 | const Paint& paint, const SkPath& path, size_t start, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 761 | size_t end) { |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 762 | Paint paintCopy(paint); |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 763 | if (mPaintFilter) { |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 764 | mPaintFilter->filterFullPaint(&paintCopy); |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 765 | } |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 766 | const SkFont& font = paintCopy.getSkFont(); |
Derek Sollenberger | 415a74b | 2018-03-14 15:03:13 -0400 | [diff] [blame] | 767 | |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 768 | const int N = end - start; |
Mike Reed | 4a4b1be | 2019-01-01 15:43:06 -0500 | [diff] [blame] | 769 | SkTextBlobBuilder builder; |
| 770 | auto rec = builder.allocRunRSXform(font, N); |
| 771 | SkRSXform* xform = (SkRSXform*)rec.pos; |
| 772 | uint16_t* glyphs = rec.glyphs; |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 773 | SkPathMeasure meas(path, false); |
| 774 | |
| 775 | for (size_t i = start; i < end; i++) { |
| 776 | glyphs[i - start] = layout.getGlyphId(i); |
Stan Iliev | c6c96dd | 2018-01-10 16:06:04 -0500 | [diff] [blame] | 777 | float halfWidth = layout.getCharAdvance(i) * 0.5f; |
| 778 | float x = hOffset + layout.getX(i) + halfWidth; |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 779 | float y = vOffset + layout.getY(i); |
| 780 | |
| 781 | SkPoint pos; |
| 782 | SkVector tan; |
| 783 | if (!meas.getPosTan(x, &pos, &tan)) { |
| 784 | pos.set(x, y); |
| 785 | tan.set(1, 0); |
| 786 | } |
| 787 | xform[i - start].fSCos = tan.x(); |
| 788 | xform[i - start].fSSin = tan.y(); |
Stan Iliev | c6c96dd | 2018-01-10 16:06:04 -0500 | [diff] [blame] | 789 | xform[i - start].fTx = pos.x() - tan.y() * y - halfWidth * tan.x(); |
| 790 | xform[i - start].fTy = pos.y() + tan.x() * y - halfWidth * tan.y(); |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 791 | } |
Leon Scroggins III | 950f2aa | 2020-04-29 13:46:00 -0400 | [diff] [blame] | 792 | |
| 793 | sk_sp<SkTextBlob> textBlob(builder.make()); |
| 794 | |
Nathaniel Nifong | 52d3777 | 2020-01-10 16:12:41 -0500 | [diff] [blame] | 795 | apply_looper(&paintCopy, [&](const SkPaint& p) { |
Leon Scroggins III | 950f2aa | 2020-04-29 13:46:00 -0400 | [diff] [blame] | 796 | mCanvas->drawTextBlob(textBlob, 0, 0, p); |
Nathaniel Nifong | 52d3777 | 2020-01-10 16:12:41 -0500 | [diff] [blame] | 797 | }); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 798 | } |
| 799 | |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 800 | // ---------------------------------------------------------------------------- |
| 801 | // Canvas draw operations: Animations |
| 802 | // ---------------------------------------------------------------------------- |
| 803 | |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 804 | void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 805 | uirenderer::CanvasPropertyPrimitive* top, |
| 806 | uirenderer::CanvasPropertyPrimitive* right, |
| 807 | uirenderer::CanvasPropertyPrimitive* bottom, |
| 808 | uirenderer::CanvasPropertyPrimitive* rx, |
| 809 | uirenderer::CanvasPropertyPrimitive* ry, |
| 810 | uirenderer::CanvasPropertyPaint* paint) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 811 | sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable( |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 812 | new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry, |
| 813 | paint)); |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 814 | mCanvas->drawDrawable(drawable.get()); |
| 815 | } |
| 816 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 817 | void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, |
| 818 | uirenderer::CanvasPropertyPrimitive* y, |
| 819 | uirenderer::CanvasPropertyPrimitive* radius, |
| 820 | uirenderer::CanvasPropertyPaint* paint) { |
| 821 | sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable( |
| 822 | new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint)); |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 823 | mCanvas->drawDrawable(drawable.get()); |
| 824 | } |
| 825 | |
John Reck | 894e85a | 2019-07-15 16:16:44 -0700 | [diff] [blame] | 826 | void SkiaCanvas::drawPicture(const SkPicture& picture) { |
| 827 | // TODO: Change to mCanvas->drawPicture()? SkCanvas::drawPicture seems to be |
| 828 | // where the logic is for playback vs. ref picture. Using picture.playback here |
| 829 | // to stay behavior-identical for now, but should revisit this at some point. |
| 830 | picture.playback(mCanvas); |
| 831 | } |
| 832 | |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 833 | // ---------------------------------------------------------------------------- |
| 834 | // Canvas draw operations: View System |
| 835 | // ---------------------------------------------------------------------------- |
| 836 | |
Stan Iliev | f50806a | 2016-10-24 10:40:39 -0400 | [diff] [blame] | 837 | void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) { |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 838 | LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers"); |
| 839 | } |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 840 | |
Derek Sollenberger | c190813 | 2016-07-15 10:28:16 -0400 | [diff] [blame] | 841 | void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) { |
| 842 | LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes"); |
| 843 | } |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 844 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 845 | } // namespace android |