blob: 1543386046636fff5c2fe800c292cf089159bff8 [file] [log] [blame]
Derek Sollenberger8872b382014-06-23 14:13:53 -04001/*
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 Sollenbergerc1908132016-07-15 10:28:16 -040017#include "SkiaCanvas.h"
Derek Sollenberger8872b382014-06-23 14:13:53 -040018
Derek Sollenbergerc1908132016-07-15 10:28:16 -040019#include "CanvasProperty.h"
Matt Sarett7de73852016-10-25 18:36:39 -040020#include "NinePatchUtils.h"
Derek Sollenbergerc1908132016-07-15 10:28:16 -040021#include "VectorDrawable.h"
sergeyvaed7f582016-10-14 16:30:21 -070022#include "hwui/Bitmap.h"
Yuqian Liafc221492016-07-18 13:07:42 -040023#include "hwui/MinikinUtils.h"
Ben Wagner0ed10be2018-06-28 17:08:16 -040024#include "hwui/PaintFilter.h"
Stan Iliev021693b2016-10-17 16:26:15 -040025#include "pipeline/skia/AnimatedDrawables.h"
Derek Sollenbergerc1908132016-07-15 10:28:16 -040026
Leon Scroggins III671cce22018-01-14 16:52:17 -050027#include <SkAnimatedImage.h>
Matt Sarettd0814db2017-04-13 09:33:18 -040028#include <SkCanvasStateUtils.h>
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -040029#include <SkColorFilter.h>
John Reck849911a2015-01-20 07:51:14 -080030#include <SkDeque.h>
John Reck1bcacfd2017-11-03 10:12:19 -070031#include <SkDrawable.h>
John Reck849911a2015-01-20 07:51:14 -080032#include <SkGraphics.h>
Derek Sollenberger6f485562015-07-30 10:00:39 -040033#include <SkImage.h>
Matt Sarett62feb3a2016-09-20 10:34:11 -040034#include <SkImagePriv.h>
Leon Scroggins III671cce22018-01-14 16:52:17 -050035#include <SkPicture.h>
Yuqian Liafc221492016-07-18 13:07:42 -040036#include <SkRSXform.h>
John Reck849911a2015-01-20 07:51:14 -080037#include <SkShader.h>
John Reck849911a2015-01-20 07:51:14 -080038#include <SkTemplates.h>
Stan Ilievf50806a2016-10-24 10:40:39 -040039#include <SkTextBlob.h>
Derek Sollenberger8872b382014-06-23 14:13:53 -040040
Ben Wagner60126ef2015-08-07 12:13:48 -040041#include <memory>
Ben Wagner0ed10be2018-06-28 17:08:16 -040042#include <optional>
43#include <utility>
Ben Wagner60126ef2015-08-07 12:13:48 -040044
Derek Sollenberger8872b382014-06-23 14:13:53 -040045namespace android {
46
Stan Ilievf50806a2016-10-24 10:40:39 -040047using uirenderer::PaintUtils;
48
John Reckc1b33d62015-04-22 09:04:45 -070049Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040050 return new SkiaCanvas(bitmap);
51}
52
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040053Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
54 return new SkiaCanvas(skiaCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -040055}
56
Stan Ilievf50806a2016-10-24 10:40:39 -040057SkiaCanvas::SkiaCanvas() {}
58
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040059SkiaCanvas::SkiaCanvas(SkCanvas* canvas) : mCanvas(canvas) {}
Stan Ilievf50806a2016-10-24 10:40:39 -040060
John Reckc1b33d62015-04-22 09:04:45 -070061SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040062 mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap));
63 mCanvas = mCanvasOwned.get();
Derek Sollenberger8872b382014-06-23 14:13:53 -040064}
65
Stan Iliev021693b2016-10-17 16:26:15 -040066SkiaCanvas::~SkiaCanvas() {}
67
Derek Sollenbergerc1908132016-07-15 10:28:16 -040068void SkiaCanvas::reset(SkCanvas* skiaCanvas) {
Mike Reed6acfe162016-11-18 17:21:09 -050069 if (mCanvas != skiaCanvas) {
70 mCanvas = skiaCanvas;
71 mCanvasOwned.reset();
72 }
Derek Sollenbergerc1908132016-07-15 10:28:16 -040073 mSaveStack.reset(nullptr);
Derek Sollenbergerc1908132016-07-15 10:28:16 -040074}
75
Derek Sollenberger8872b382014-06-23 14:13:53 -040076// ----------------------------------------------------------------------------
77// Canvas state operations: Replace Bitmap
78// ----------------------------------------------------------------------------
79
John Reckc1b33d62015-04-22 09:04:45 -070080void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
Tony Mantler4f641d12017-03-14 22:36:14 +000081 // deletes the previously owned canvas (if any)
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040082 mCanvasOwned.reset(new SkCanvas(bitmap));
83 mCanvas = mCanvasOwned.get();
Tony Mantler4f641d12017-03-14 22:36:14 +000084
Derek Sollenberger8872b382014-06-23 14:13:53 -040085 // clean up the old save stack
Stan Ilievf50806a2016-10-24 10:40:39 -040086 mSaveStack.reset(nullptr);
Derek Sollenberger8872b382014-06-23 14:13:53 -040087}
88
89// ----------------------------------------------------------------------------
90// Canvas state operations
91// ----------------------------------------------------------------------------
92
93bool SkiaCanvas::isOpaque() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -040094 return mCanvas->imageInfo().isOpaque();
Derek Sollenberger8872b382014-06-23 14:13:53 -040095}
96
97int SkiaCanvas::width() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -040098 return mCanvas->imageInfo().width();
Derek Sollenberger8872b382014-06-23 14:13:53 -040099}
100
101int SkiaCanvas::height() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400102 return mCanvas->imageInfo().height();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400103}
104
105// ----------------------------------------------------------------------------
106// Canvas state operations: Save (layer)
107// ----------------------------------------------------------------------------
108
109int SkiaCanvas::getSaveCount() const {
110 return mCanvas->getSaveCount();
111}
112
Florin Malitaeecff562015-12-21 10:43:01 -0500113int SkiaCanvas::save(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400114 int count = mCanvas->save();
115 recordPartialSave(flags);
116 return count;
117}
118
Florin Malita5e271402015-11-04 14:36:02 -0500119// The SkiaCanvas::restore operation layers on the capability to preserve
120// either (or both) the matrix and/or clip state after a SkCanvas::restore
121// operation. It does this by explicitly saving off the clip & matrix state
122// when requested and playing it back after the SkCanvas::restore.
Derek Sollenberger8872b382014-06-23 14:13:53 -0400123void SkiaCanvas::restore() {
Stan Ilievf50806a2016-10-24 10:40:39 -0400124 const auto* rec = this->currentSaveRec();
125 if (!rec) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400126 // Fast path - no record for this frame.
127 mCanvas->restore();
128 return;
129 }
130
Florin Malitaeecff562015-12-21 10:43:01 -0500131 bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix);
John Reck1bcacfd2017-11-03 10:12:19 -0700132 bool preserveClip = !(rec->saveFlags & SaveFlags::Clip);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400133
134 SkMatrix savedMatrix;
135 if (preserveMatrix) {
136 savedMatrix = mCanvas->getTotalMatrix();
137 }
138
Stan Ilievf50806a2016-10-24 10:40:39 -0400139 const size_t clipIndex = rec->clipIndex;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400140
141 mCanvas->restore();
Stan Ilievf50806a2016-10-24 10:40:39 -0400142 mSaveStack->pop_back();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400143
144 if (preserveMatrix) {
145 mCanvas->setMatrix(savedMatrix);
146 }
147
Stan Ilievf50806a2016-10-24 10:40:39 -0400148 if (preserveClip) {
149 this->applyPersistentClips(clipIndex);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400150 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400151}
152
153void SkiaCanvas::restoreToCount(int restoreCount) {
154 while (mCanvas->getSaveCount() > restoreCount) {
155 this->restore();
156 }
157}
158
Florin Malitaeecff562015-12-21 10:43:01 -0500159static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) {
160 SkCanvas::SaveLayerFlags layerFlags = 0;
161
Florin Malitaeecff562015-12-21 10:43:01 -0500162 if (!(flags & SaveFlags::ClipToLayer)) {
163 layerFlags |= SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
164 }
165
166 return layerFlags;
167}
168
John Reck1bcacfd2017-11-03 10:12:19 -0700169int SkiaCanvas::saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
170 SaveFlags::Flags flags) {
Florin Malitaeecff562015-12-21 10:43:01 -0500171 const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
Derek Sollenbergerb8201192017-01-09 16:11:59 -0500172 const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags));
Florin Malitaeecff562015-12-21 10:43:01 -0500173
Stan Iliev68885e32016-12-14 11:18:34 -0500174 return mCanvas->saveLayer(rec);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400175}
176
John Reck1bcacfd2017-11-03 10:12:19 -0700177int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
178 SaveFlags::Flags flags) {
Florin Malitaeecff562015-12-21 10:43:01 -0500179 if (static_cast<unsigned>(alpha) < 0xFF) {
Yuqian Lifd92ee42016-04-27 17:03:38 -0400180 SkPaint alphaPaint;
181 alphaPaint.setAlpha(alpha);
182 return this->saveLayer(left, top, right, bottom, &alphaPaint, flags);
Florin Malitaeecff562015-12-21 10:43:01 -0500183 }
Yuqian Lifd92ee42016-04-27 17:03:38 -0400184 return this->saveLayer(left, top, right, bottom, nullptr, flags);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400185}
186
Stan Ilievf50806a2016-10-24 10:40:39 -0400187class SkiaCanvas::Clip {
188public:
Mike Reed6e49c9f2016-12-02 15:36:59 -0500189 Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
John Reck1bcacfd2017-11-03 10:12:19 -0700190 : mType(Type::Rect), mOp(op), mMatrix(m), mRRect(SkRRect::MakeRect(rect)) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500191 Clip(const SkRRect& rrect, SkClipOp op, const SkMatrix& m)
John Reck1bcacfd2017-11-03 10:12:19 -0700192 : mType(Type::RRect), mOp(op), mMatrix(m), mRRect(rrect) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500193 Clip(const SkPath& path, SkClipOp op, const SkMatrix& m)
Ben Wagner0ed10be2018-06-28 17:08:16 -0400194 : mType(Type::Path), mOp(op), mMatrix(m), mPath(std::in_place, path) {}
Stan Ilievf50806a2016-10-24 10:40:39 -0400195
196 void apply(SkCanvas* canvas) const {
197 canvas->setMatrix(mMatrix);
198 switch (mType) {
John Reck1bcacfd2017-11-03 10:12:19 -0700199 case Type::Rect:
200 canvas->clipRect(mRRect.rect(), mOp);
201 break;
202 case Type::RRect:
203 canvas->clipRRect(mRRect, mOp);
204 break;
205 case Type::Path:
Ben Wagner0ed10be2018-06-28 17:08:16 -0400206 canvas->clipPath(mPath.value(), mOp);
John Reck1bcacfd2017-11-03 10:12:19 -0700207 break;
Stan Ilievf50806a2016-10-24 10:40:39 -0400208 }
209 }
210
211private:
212 enum class Type {
213 Rect,
214 RRect,
215 Path,
216 };
217
John Reck1bcacfd2017-11-03 10:12:19 -0700218 Type mType;
219 SkClipOp mOp;
220 SkMatrix mMatrix;
Stan Ilievf50806a2016-10-24 10:40:39 -0400221
222 // These are logically a union (tracked separately due to non-POD path).
Ben Wagner0ed10be2018-06-28 17:08:16 -0400223 std::optional<SkPath> mPath;
John Reck1bcacfd2017-11-03 10:12:19 -0700224 SkRRect mRRect;
Stan Ilievf50806a2016-10-24 10:40:39 -0400225};
226
227const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const {
John Reck1bcacfd2017-11-03 10:12:19 -0700228 const SaveRec* rec = mSaveStack ? static_cast<const SaveRec*>(mSaveStack->back()) : nullptr;
Stan Ilievf50806a2016-10-24 10:40:39 -0400229 int currentSaveCount = mCanvas->getSaveCount();
230 SkASSERT(!rec || currentSaveCount >= rec->saveCount);
231
232 return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr;
233}
234
Derek Sollenberger8872b382014-06-23 14:13:53 -0400235// ----------------------------------------------------------------------------
236// functions to emulate legacy SaveFlags (i.e. independent matrix/clip flags)
237// ----------------------------------------------------------------------------
238
Florin Malitaeecff562015-12-21 10:43:01 -0500239void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400240 // A partial save is a save operation which doesn't capture the full canvas state.
Florin Malitaeecff562015-12-21 10:43:01 -0500241 // (either SaveFlags::Matrix or SaveFlags::Clip is missing).
Derek Sollenberger8872b382014-06-23 14:13:53 -0400242
243 // Mask-out non canvas state bits.
Florin Malitaeecff562015-12-21 10:43:01 -0500244 flags &= SaveFlags::MatrixClip;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400245
Florin Malitaeecff562015-12-21 10:43:01 -0500246 if (flags == SaveFlags::MatrixClip) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400247 // not a partial save.
248 return;
249 }
250
Stan Ilievf50806a2016-10-24 10:40:39 -0400251 if (!mSaveStack) {
Ben Wagnerd1cbc162015-08-19 12:45:09 -0400252 mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400253 }
254
255 SaveRec* rec = static_cast<SaveRec*>(mSaveStack->push_back());
Florin Malita5e271402015-11-04 14:36:02 -0500256 rec->saveCount = mCanvas->getSaveCount();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400257 rec->saveFlags = flags;
Stan Ilievf50806a2016-10-24 10:40:39 -0400258 rec->clipIndex = mClipStack.size();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400259}
260
Stan Ilievf50806a2016-10-24 10:40:39 -0400261template <typename T>
Mike Reed6e49c9f2016-12-02 15:36:59 -0500262void SkiaCanvas::recordClip(const T& clip, SkClipOp op) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400263 // Only need tracking when in a partial save frame which
264 // doesn't restore the clip.
265 const SaveRec* rec = this->currentSaveRec();
266 if (rec && !(rec->saveFlags & SaveFlags::Clip)) {
267 mClipStack.emplace_back(clip, op, mCanvas->getTotalMatrix());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400268 }
269}
270
Stan Ilievf50806a2016-10-24 10:40:39 -0400271// Applies and optionally removes all clips >= index.
272void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) {
273 SkASSERT(clipStartIndex <= mClipStack.size());
274 const auto begin = mClipStack.cbegin() + clipStartIndex;
275 const auto end = mClipStack.cend();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400276
Stan Ilievf50806a2016-10-24 10:40:39 -0400277 // Clip application mutates the CTM.
278 const SkMatrix saveMatrix = mCanvas->getTotalMatrix();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400279
Stan Ilievf50806a2016-10-24 10:40:39 -0400280 for (auto clip = begin; clip != end; ++clip) {
Mike Reed6acfe162016-11-18 17:21:09 -0500281 clip->apply(mCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400282 }
283
Stan Ilievf50806a2016-10-24 10:40:39 -0400284 mCanvas->setMatrix(saveMatrix);
285
286 // If the current/post-restore save rec is also persisting clips, we
287 // leave them on the stack to be reapplied part of the next restore().
288 // Otherwise we're done and just pop them.
289 const auto* rec = this->currentSaveRec();
290 if (!rec || (rec->saveFlags & SaveFlags::Clip)) {
291 mClipStack.erase(begin, end);
292 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400293}
294
295// ----------------------------------------------------------------------------
296// Canvas state operations: Matrix
297// ----------------------------------------------------------------------------
298
299void SkiaCanvas::getMatrix(SkMatrix* outMatrix) const {
300 *outMatrix = mCanvas->getTotalMatrix();
301}
302
303void SkiaCanvas::setMatrix(const SkMatrix& matrix) {
304 mCanvas->setMatrix(matrix);
305}
306
307void SkiaCanvas::concat(const SkMatrix& matrix) {
308 mCanvas->concat(matrix);
309}
310
311void SkiaCanvas::rotate(float degrees) {
312 mCanvas->rotate(degrees);
313}
314
315void SkiaCanvas::scale(float sx, float sy) {
316 mCanvas->scale(sx, sy);
317}
318
319void SkiaCanvas::skew(float sx, float sy) {
320 mCanvas->skew(sx, sy);
321}
322
323void SkiaCanvas::translate(float dx, float dy) {
324 mCanvas->translate(dx, dy);
325}
326
327// ----------------------------------------------------------------------------
328// Canvas state operations: Clips
329// ----------------------------------------------------------------------------
330
331// This function is a mirror of SkCanvas::getClipBounds except that it does
332// not outset the edge of the clip to account for anti-aliasing. There is
333// a skia bug to investigate pushing this logic into back into skia.
334// (see https://code.google.com/p/skia/issues/detail?id=1303)
335bool SkiaCanvas::getClipBounds(SkRect* outRect) const {
336 SkIRect ibounds;
Mike Reed5e438982017-01-25 08:23:25 -0500337 if (!mCanvas->getDeviceClipBounds(&ibounds)) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400338 return false;
339 }
340
341 SkMatrix inverse;
342 // if we can't invert the CTM, we can't return local clip bounds
343 if (!mCanvas->getTotalMatrix().invert(&inverse)) {
344 if (outRect) {
345 outRect->setEmpty();
346 }
347 return false;
348 }
349
350 if (NULL != outRect) {
351 SkRect r = SkRect::Make(ibounds);
352 inverse.mapRect(outRect, r);
353 }
354 return true;
355}
356
357bool SkiaCanvas::quickRejectRect(float left, float top, float right, float bottom) const {
358 SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
359 return mCanvas->quickReject(bounds);
360}
361
362bool SkiaCanvas::quickRejectPath(const SkPath& path) const {
363 return mCanvas->quickReject(path);
364}
365
Mike Reed6e49c9f2016-12-02 15:36:59 -0500366bool SkiaCanvas::clipRect(float left, float top, float right, float bottom, SkClipOp op) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400367 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
Stan Ilievf50806a2016-10-24 10:40:39 -0400368 this->recordClip(rect, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400369 mCanvas->clipRect(rect, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700370 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400371}
372
Mike Reed6e49c9f2016-12-02 15:36:59 -0500373bool SkiaCanvas::clipPath(const SkPath* path, SkClipOp op) {
Derek Sollenbergerf7d98f42017-04-17 11:27:36 -0400374 this->recordClip(*path, op);
375 mCanvas->clipPath(*path, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700376 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400377}
378
Derek Sollenberger8872b382014-06-23 14:13:53 -0400379// ----------------------------------------------------------------------------
380// Canvas state operations: Filters
381// ----------------------------------------------------------------------------
382
Ben Wagner0ed10be2018-06-28 17:08:16 -0400383PaintFilter* SkiaCanvas::getPaintFilter() {
384 return mPaintFilter.get();
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400385}
386
Ben Wagner0ed10be2018-06-28 17:08:16 -0400387void SkiaCanvas::setPaintFilter(sk_sp<PaintFilter> paintFilter) {
388 mPaintFilter = std::move(paintFilter);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400389}
390
391// ----------------------------------------------------------------------------
Matt Sarettd0814db2017-04-13 09:33:18 -0400392// Canvas state operations: Capture
393// ----------------------------------------------------------------------------
394
395SkCanvasState* SkiaCanvas::captureCanvasState() const {
396 SkCanvas* canvas = mCanvas;
397 if (mCanvasOwned) {
398 // Important to use the underlying SkCanvas, not the wrapper.
399 canvas = mCanvasOwned.get();
400 }
401
402 // Workarounds for http://crbug.com/271096: SW draw only supports
403 // translate & scale transforms, and a simple rectangular clip.
404 // (This also avoids significant wasted time in calling
405 // SkCanvasStateUtils::CaptureCanvasState when the clip is complex).
John Reck1bcacfd2017-11-03 10:12:19 -0700406 if (!canvas->isClipRect() || (canvas->getTotalMatrix().getType() &
407 ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) {
408 return nullptr;
Matt Sarettd0814db2017-04-13 09:33:18 -0400409 }
410
411 return SkCanvasStateUtils::CaptureCanvasState(canvas);
412}
413
414// ----------------------------------------------------------------------------
Derek Sollenberger8872b382014-06-23 14:13:53 -0400415// Canvas draw operations
416// ----------------------------------------------------------------------------
417
Mike Reed260ab722016-10-07 15:59:20 -0400418void SkiaCanvas::drawColor(int color, SkBlendMode mode) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400419 mCanvas->drawColor(color, mode);
420}
421
Ben Wagner0ed10be2018-06-28 17:08:16 -0400422SkiaCanvas::PaintCoW&& SkiaCanvas::filterPaint(PaintCoW&& paint) const {
423 if (mPaintFilter) {
424 mPaintFilter->filter(&paint.writeable());
425 }
426 return std::move(paint);
427}
428
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400429void SkiaCanvas::drawPaint(const SkPaint& paint) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400430 mCanvas->drawPaint(*filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400431}
432
433// ----------------------------------------------------------------------------
434// Canvas draw operations: Geometry
435// ----------------------------------------------------------------------------
436
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400437void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400438 SkCanvas::PointMode mode) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500439 if (CC_UNLIKELY(count < 2 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400440 // convert the floats into SkPoints
John Reck1bcacfd2017-11-03 10:12:19 -0700441 count >>= 1; // now it is the number of points
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400442 std::unique_ptr<SkPoint[]> pts(new SkPoint[count]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400443 for (int i = 0; i < count; i++) {
444 pts[i].set(points[0], points[1]);
445 points += 2;
446 }
Ben Wagner0ed10be2018-06-28 17:08:16 -0400447 mCanvas->drawPoints(mode, count, pts.get(), *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400448}
449
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400450void SkiaCanvas::drawPoint(float x, float y, const SkPaint& paint) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400451 mCanvas->drawPoint(x, y, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400452}
453
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400454void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400455 this->drawPoints(points, count, *filterPaint(paint), SkCanvas::kPoints_PointMode);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400456}
457
458void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400459 const SkPaint& paint) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400460 mCanvas->drawLine(startX, startY, stopX, stopY, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400461}
462
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400463void SkiaCanvas::drawLines(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500464 if (CC_UNLIKELY(count < 4 || paint.nothingToDraw())) return;
Ben Wagner0ed10be2018-06-28 17:08:16 -0400465 this->drawPoints(points, count, *filterPaint(paint), SkCanvas::kLines_PointMode);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400466}
467
John Reck1bcacfd2017-11-03 10:12:19 -0700468void SkiaCanvas::drawRect(float left, float top, float right, float bottom, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500469 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Ben Wagner0ed10be2018-06-28 17:08:16 -0400470 mCanvas->drawRect({left, top, right, bottom}, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400471}
472
Derek Sollenberger94394b32015-07-10 09:58:41 -0400473void SkiaCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500474 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Ben Wagner0ed10be2018-06-28 17:08:16 -0400475 mCanvas->drawRegion(region, *filterPaint(paint));
Derek Sollenberger94394b32015-07-10 09:58:41 -0400476}
477
John Reck1bcacfd2017-11-03 10:12:19 -0700478void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
479 const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500480 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400481 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
Ben Wagner0ed10be2018-06-28 17:08:16 -0400482 mCanvas->drawRoundRect(rect, rx, ry, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400483}
484
Nader Jawadadfe1d92018-09-27 12:27:36 -0700485void SkiaCanvas::drawDoubleRoundRect(const SkRRect& outer, const SkRRect& inner,
486 const SkPaint& paint) {
487 mCanvas->drawDRRect(outer, inner, *filterPaint(paint));
488}
489
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400490void SkiaCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500491 if (CC_UNLIKELY(radius <= 0 || paint.nothingToDraw())) return;
Ben Wagner0ed10be2018-06-28 17:08:16 -0400492 mCanvas->drawCircle(x, y, radius, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400493}
494
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400495void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500496 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400497 SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
Ben Wagner0ed10be2018-06-28 17:08:16 -0400498 mCanvas->drawOval(oval, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400499}
500
John Reck1bcacfd2017-11-03 10:12:19 -0700501void SkiaCanvas::drawArc(float left, float top, float right, float bottom, float startAngle,
502 float sweepAngle, bool useCenter, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500503 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400504 SkRect arc = SkRect::MakeLTRB(left, top, right, bottom);
Derek Sollenbergeref3b2182017-11-06 13:55:59 -0500505 if (fabs(sweepAngle) >= 360.0f) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400506 mCanvas->drawOval(arc, *filterPaint(paint));
Derek Sollenbergeref3b2182017-11-06 13:55:59 -0500507 } else {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400508 mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, *filterPaint(paint));
Derek Sollenbergeref3b2182017-11-06 13:55:59 -0500509 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400510}
511
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400512void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500513 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Stan Iliev6dcfdec2017-08-15 16:42:05 -0400514 if (CC_UNLIKELY(path.isEmpty() && (!path.isInverseFillType()))) {
515 return;
516 }
Ben Wagner0ed10be2018-06-28 17:08:16 -0400517 mCanvas->drawPath(path, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400518}
519
Mike Reed826deef2017-04-04 15:32:04 -0400520void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
Ben Wagner0ed10be2018-06-28 17:08:16 -0400521 mCanvas->drawVertices(vertices, mode, *filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400522}
523
524// ----------------------------------------------------------------------------
525// Canvas draw operations: Bitmaps
526// ----------------------------------------------------------------------------
527
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400528void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) {
Derek Sollenbergerd01b5912018-10-19 15:55:33 -0400529 mCanvas->drawImage(bitmap.makeImage(), left, top, filterPaint(paint));
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400530}
531
532void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) {
Mike Reed6acfe162016-11-18 17:21:09 -0500533 SkAutoCanvasRestore acr(mCanvas, true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500534 mCanvas->concat(matrix);
Derek Sollenbergerd01b5912018-10-19 15:55:33 -0400535 mCanvas->drawImage(bitmap.makeImage(), 0, 0, filterPaint(paint));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400536}
537
John Reck1bcacfd2017-11-03 10:12:19 -0700538void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight,
539 float srcBottom, float dstLeft, float dstTop, float dstRight,
540 float dstBottom, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400541 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
542 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400543
Derek Sollenbergerd01b5912018-10-19 15:55:33 -0400544 mCanvas->drawImageRect(bitmap.makeImage(), srcRect, dstRect, filterPaint(paint),
John Reck1bcacfd2017-11-03 10:12:19 -0700545 SkCanvas::kFast_SrcRectConstraint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400546}
547
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400548void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
John Reck1bcacfd2017-11-03 10:12:19 -0700549 const float* vertices, const int* colors, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400550 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
551 const int indexCount = meshWidth * meshHeight * 6;
Mike Reed871cd2d2017-03-17 10:15:52 -0400552 uint32_t flags = SkVertices::kHasTexCoords_BuilderFlag;
553 if (colors) {
554 flags |= SkVertices::kHasColors_BuilderFlag;
555 }
Mike Reed826deef2017-04-04 15:32:04 -0400556 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
Mike Reed871cd2d2017-03-17 10:15:52 -0400557 memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint));
558 if (colors) {
559 memcpy(builder.colors(), colors, ptCount * sizeof(SkColor));
560 }
561 SkPoint* texs = builder.texCoords();
562 uint16_t* indices = builder.indices();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400563
564 // cons up texture coordinates and indices
565 {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400566 const SkScalar w = SkIntToScalar(bitmap.width());
567 const SkScalar h = SkIntToScalar(bitmap.height());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400568 const SkScalar dx = w / meshWidth;
569 const SkScalar dy = h / meshHeight;
570
571 SkPoint* texsPtr = texs;
572 SkScalar y = 0;
573 for (int i = 0; i <= meshHeight; i++) {
574 if (i == meshHeight) {
575 y = h; // to ensure numerically we hit h exactly
576 }
577 SkScalar x = 0;
578 for (int j = 0; j < meshWidth; j++) {
579 texsPtr->set(x, y);
580 texsPtr += 1;
581 x += dx;
582 }
583 texsPtr->set(w, y);
584 texsPtr += 1;
585 y += dy;
586 }
587 SkASSERT(texsPtr - texs == ptCount);
588 }
589
590 // cons up indices
591 {
592 uint16_t* indexPtr = indices;
593 int index = 0;
594 for (int i = 0; i < meshHeight; i++) {
595 for (int j = 0; j < meshWidth; j++) {
596 // lower-left triangle
597 *indexPtr++ = index;
598 *indexPtr++ = index + meshWidth + 1;
599 *indexPtr++ = index + meshWidth + 2;
600 // upper-right triangle
601 *indexPtr++ = index;
602 *indexPtr++ = index + meshWidth + 2;
603 *indexPtr++ = index + 1;
604 // bump to the next cell
605 index += 1;
606 }
607 // bump to the next row
608 index += 1;
609 }
610 SkASSERT(indexPtr - indices == indexCount);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400611 }
612
John Reck1bcacfd2017-11-03 10:12:19 -0700613// double-check that we have legal indices
Derek Sollenberger8872b382014-06-23 14:13:53 -0400614#ifdef SK_DEBUG
615 {
616 for (int i = 0; i < indexCount; i++) {
617 SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
618 }
619 }
620#endif
621
622 // cons-up a shader for the bitmap
Ben Wagner0ed10be2018-06-28 17:08:16 -0400623 PaintCoW paintCoW(paint);
624 SkPaint& tmpPaint = paintCoW.writeable();
Stan Ilievf50806a2016-10-24 10:40:39 -0400625
Derek Sollenbergerd01b5912018-10-19 15:55:33 -0400626 sk_sp<SkImage> image = bitmap.makeImage();
John Reck1bcacfd2017-11-03 10:12:19 -0700627 sk_sp<SkShader> shader =
628 image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
Ben Wagner0ed10be2018-06-28 17:08:16 -0400629 tmpPaint.setShader(std::move(shader));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400630
Ben Wagner0ed10be2018-06-28 17:08:16 -0400631 mCanvas->drawVertices(builder.detach(), SkBlendMode::kModulate,
632 *filterPaint(std::move(paintCoW)));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400633}
634
John Reck1bcacfd2017-11-03 10:12:19 -0700635void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, float dstLeft,
636 float dstTop, float dstRight, float dstBottom,
637 const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400638 SkCanvas::Lattice lattice;
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400639 NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height());
Stan Ilievf50806a2016-10-24 10:40:39 -0400640
Stan Ilieve12d7312017-12-04 14:48:27 -0500641 lattice.fRectTypes = nullptr;
642 lattice.fColors = nullptr;
Stan Ilievf50806a2016-10-24 10:40:39 -0400643 int numFlags = 0;
Stan Iliev021693b2016-10-17 16:26:15 -0400644 if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400645 // We can expect the framework to give us a color for every distinct rect.
646 // Skia requires a flag for every rect.
647 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
648 }
649
Stan Ilieve12d7312017-12-04 14:48:27 -0500650 SkAutoSTMalloc<25, SkCanvas::Lattice::RectType> flags(numFlags);
651 SkAutoSTMalloc<25, SkColor> colors(numFlags);
Stan Ilievf50806a2016-10-24 10:40:39 -0400652 if (numFlags > 0) {
Stan Ilieve12d7312017-12-04 14:48:27 -0500653 NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk, colors.get());
Stan Ilievf50806a2016-10-24 10:40:39 -0400654 }
655
656 lattice.fBounds = nullptr;
657 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400658
Derek Sollenbergerd01b5912018-10-19 15:55:33 -0400659 mCanvas->drawImageLattice(bitmap.makeImage().get(), lattice, dst, filterPaint(paint));
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400660}
661
Derek Sollenberger2d142132018-01-22 10:25:26 -0500662double SkiaCanvas::drawAnimatedImage(AnimatedImageDrawable* imgDrawable) {
663 return imgDrawable->drawStaging(mCanvas);
Leon Scroggins III671cce22018-01-14 16:52:17 -0500664}
665
Doris Liu766431a2016-02-04 22:17:11 +0000666void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800667 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000668}
669
Derek Sollenberger8872b382014-06-23 14:13:53 -0400670// ----------------------------------------------------------------------------
671// Canvas draw operations: Text
672// ----------------------------------------------------------------------------
673
Stan Iliev0b58d992017-03-30 18:22:27 -0400674void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& paint, float x,
John Reck1bcacfd2017-11-03 10:12:19 -0700675 float y, float boundsLeft, float boundsTop, float boundsRight,
676 float boundsBottom, float totalAdvance) {
Stan Iliev0b58d992017-03-30 18:22:27 -0400677 if (count <= 0 || paint.nothingToDraw()) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400678 SkPaint paintCopy(paint);
Ben Wagner0ed10be2018-06-28 17:08:16 -0400679 if (mPaintFilter) {
680 mPaintFilter->filter(&paintCopy);
681 }
Stan Ilieva39b7742017-11-29 13:15:45 -0500682 SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
Stan Iliev7717e222018-02-05 18:04:11 -0500683 // Stroke with a hairline is drawn on HW with a fill style for compatibility with Android O and
684 // older.
John Recke170fb62018-05-07 08:12:07 -0700685 if (!mCanvasOwned && sApiLevel <= 27 && paintCopy.getStrokeWidth() <= 0 &&
686 paintCopy.getStyle() == SkPaint::kStroke_Style) {
Stan Iliev7717e222018-02-05 18:04:11 -0500687 paintCopy.setStyle(SkPaint::kFill_Style);
688 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400689
John Reck1bcacfd2017-11-03 10:12:19 -0700690 SkRect bounds =
691 SkRect::MakeLTRB(boundsLeft + x, boundsTop + y, boundsRight + x, boundsBottom + y);
Stan Ilievf50806a2016-10-24 10:40:39 -0400692
693 SkTextBlobBuilder builder;
694 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
Stan Iliev0b58d992017-03-30 18:22:27 -0400695 glyphFunc(buffer.glyphs, buffer.pos);
Stan Ilievf50806a2016-10-24 10:40:39 -0400696
697 sk_sp<SkTextBlob> textBlob(builder.make());
698 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
699 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400700}
701
Yuqian Liafc221492016-07-18 13:07:42 -0400702void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
John Reck1bcacfd2017-11-03 10:12:19 -0700703 const SkPaint& paint, const SkPath& path, size_t start,
704 size_t end) {
Derek Sollenberger415a74b2018-03-14 15:03:13 -0400705 SkPaint paintCopy(paint);
Ben Wagner0ed10be2018-06-28 17:08:16 -0400706 if (mPaintFilter) {
707 mPaintFilter->filter(&paintCopy);
708 }
Derek Sollenberger415a74b2018-03-14 15:03:13 -0400709 SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
710
Yuqian Liafc221492016-07-18 13:07:42 -0400711 const int N = end - start;
Derek Sollenbergere547dd02016-11-09 11:55:59 -0500712 SkAutoSTMalloc<1024, uint8_t> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
Yuqian Liafc221492016-07-18 13:07:42 -0400713 SkRSXform* xform = (SkRSXform*)storage.get();
714 uint16_t* glyphs = (uint16_t*)(xform + N);
715 SkPathMeasure meas(path, false);
716
717 for (size_t i = start; i < end; i++) {
718 glyphs[i - start] = layout.getGlyphId(i);
Stan Ilievc6c96dd2018-01-10 16:06:04 -0500719 float halfWidth = layout.getCharAdvance(i) * 0.5f;
720 float x = hOffset + layout.getX(i) + halfWidth;
Yuqian Liafc221492016-07-18 13:07:42 -0400721 float y = vOffset + layout.getY(i);
722
723 SkPoint pos;
724 SkVector tan;
725 if (!meas.getPosTan(x, &pos, &tan)) {
726 pos.set(x, y);
727 tan.set(1, 0);
728 }
729 xform[i - start].fSCos = tan.x();
730 xform[i - start].fSSin = tan.y();
Stan Ilievc6c96dd2018-01-10 16:06:04 -0500731 xform[i - start].fTx = pos.x() - tan.y() * y - halfWidth * tan.x();
732 xform[i - start].fTy = pos.y() + tan.x() * y - halfWidth * tan.y();
Yuqian Liafc221492016-07-18 13:07:42 -0400733 }
734
Derek Sollenberger415a74b2018-03-14 15:03:13 -0400735 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400736}
737
Derek Sollenberger6f485562015-07-30 10:00:39 -0400738// ----------------------------------------------------------------------------
739// Canvas draw operations: Animations
740// ----------------------------------------------------------------------------
741
Derek Sollenberger6f485562015-07-30 10:00:39 -0400742void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
John Reck1bcacfd2017-11-03 10:12:19 -0700743 uirenderer::CanvasPropertyPrimitive* top,
744 uirenderer::CanvasPropertyPrimitive* right,
745 uirenderer::CanvasPropertyPrimitive* bottom,
746 uirenderer::CanvasPropertyPrimitive* rx,
747 uirenderer::CanvasPropertyPrimitive* ry,
748 uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400749 sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable(
John Reck1bcacfd2017-11-03 10:12:19 -0700750 new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry,
751 paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400752 mCanvas->drawDrawable(drawable.get());
753}
754
John Reck1bcacfd2017-11-03 10:12:19 -0700755void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x,
756 uirenderer::CanvasPropertyPrimitive* y,
757 uirenderer::CanvasPropertyPrimitive* radius,
758 uirenderer::CanvasPropertyPaint* paint) {
759 sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable(
760 new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400761 mCanvas->drawDrawable(drawable.get());
762}
763
764// ----------------------------------------------------------------------------
765// Canvas draw operations: View System
766// ----------------------------------------------------------------------------
767
Stan Ilievf50806a2016-10-24 10:40:39 -0400768void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400769 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
770}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400771
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400772void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
773 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
774}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400775
John Reckcd1c3eb2016-04-14 10:38:54 -0700776void SkiaCanvas::callDrawGLFunction(Functor* functor,
John Reck1bcacfd2017-11-03 10:12:19 -0700777 uirenderer::GlFunctorLifecycleListener* listener) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400778 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
779}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400780
John Reck1bcacfd2017-11-03 10:12:19 -0700781} // namespace android