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