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