blob: eb844cb7894a59b4b106e53c0b9754825872c9e0 [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"
Stan Iliev021693b2016-10-17 16:26:15 -040024#include "pipeline/skia/AnimatedDrawables.h"
Derek Sollenbergerc1908132016-07-15 10:28:16 -040025
Matt Sarettd0814db2017-04-13 09:33:18 -040026#include <SkCanvasStateUtils.h>
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -040027#include <SkColorFilter.h>
Matt Sarettea70d222017-03-29 16:25:10 -040028#include <SkColorSpaceXformCanvas.h>
Derek Sollenberger6f485562015-07-30 10:00:39 -040029#include <SkDrawable.h>
John Reck849911a2015-01-20 07:51:14 -080030#include <SkDeque.h>
31#include <SkDrawFilter.h>
32#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>
Yuqian Liafc221492016-07-18 13:07:42 -040035#include <SkRSXform.h>
John Reck849911a2015-01-20 07:51:14 -080036#include <SkShader.h>
John Reck849911a2015-01-20 07:51:14 -080037#include <SkTemplates.h>
Stan Ilievf50806a2016-10-24 10:40:39 -040038#include <SkTextBlob.h>
Derek Sollenberger8872b382014-06-23 14:13:53 -040039
Ben Wagner60126ef2015-08-07 12:13:48 -040040#include <memory>
41
Derek Sollenberger8872b382014-06-23 14:13:53 -040042namespace android {
43
Stan Ilievf50806a2016-10-24 10:40:39 -040044using uirenderer::PaintUtils;
45
John Reckc1b33d62015-04-22 09:04:45 -070046Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040047 return new SkiaCanvas(bitmap);
48}
49
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040050Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
51 return new SkiaCanvas(skiaCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -040052}
53
Stan Ilievf50806a2016-10-24 10:40:39 -040054SkiaCanvas::SkiaCanvas() {}
55
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040056SkiaCanvas::SkiaCanvas(SkCanvas* canvas) : mCanvas(canvas) {}
Stan Ilievf50806a2016-10-24 10:40:39 -040057
John Reckc1b33d62015-04-22 09:04:45 -070058SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
Romain Guy82426562017-04-04 19:38:50 -070059 sk_sp<SkColorSpace> cs = bitmap.refColorSpace();
Matt Sarettca9b7032017-04-13 12:18:47 -040060 mCanvasOwned =
61 std::unique_ptr<SkCanvas>(new SkCanvas(bitmap, SkCanvas::ColorBehavior::kLegacy));
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040062 if (cs.get() == nullptr || cs->isSRGB()) {
63 if(!uirenderer::Properties::isSkiaEnabled()) {
64 mCanvasWrapper = SkCreateColorSpaceXformCanvas(mCanvasOwned.get(), SkColorSpace::MakeSRGB());
65 mCanvas = mCanvasWrapper.get();
66 } else {
67 mCanvas = mCanvasOwned.get();
68 }
69 } else {
70 /** The wrapper is needed if we are drawing into a non-sRGB destination, since
71 * we need to transform all colors (not just bitmaps via filters) into the
72 * destination's colorspace.
73 */
74 mCanvasWrapper = SkCreateColorSpaceXformCanvas(mCanvasOwned.get(), std::move(cs));
75 mCanvas = mCanvasWrapper.get();
76 }
Derek Sollenberger8872b382014-06-23 14:13:53 -040077}
78
Stan Iliev021693b2016-10-17 16:26:15 -040079SkiaCanvas::~SkiaCanvas() {}
80
Derek Sollenbergerc1908132016-07-15 10:28:16 -040081void SkiaCanvas::reset(SkCanvas* skiaCanvas) {
Mike Reed6acfe162016-11-18 17:21:09 -050082 if (mCanvas != skiaCanvas) {
83 mCanvas = skiaCanvas;
84 mCanvasOwned.reset();
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040085 mCanvasWrapper.reset();
Mike Reed6acfe162016-11-18 17:21:09 -050086 }
Derek Sollenbergerc1908132016-07-15 10:28:16 -040087 mSaveStack.reset(nullptr);
88 mHighContrastText = false;
89}
90
Derek Sollenberger8872b382014-06-23 14:13:53 -040091// ----------------------------------------------------------------------------
92// Canvas state operations: Replace Bitmap
93// ----------------------------------------------------------------------------
94
John Reckc1b33d62015-04-22 09:04:45 -070095void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
Romain Guy82426562017-04-04 19:38:50 -070096 sk_sp<SkColorSpace> cs = bitmap.refColorSpace();
Matt Sarettca9b7032017-04-13 12:18:47 -040097 std::unique_ptr<SkCanvas> newCanvas =
98 std::unique_ptr<SkCanvas>(new SkCanvas(bitmap, SkCanvas::ColorBehavior::kLegacy));
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040099 std::unique_ptr<SkCanvas> newCanvasWrapper;
100 if (cs.get() != nullptr && !cs->isSRGB()) {
101 newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), std::move(cs));
102 }
103 else if(!uirenderer::Properties::isSkiaEnabled()) {
104 newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), SkColorSpace::MakeSRGB());
105 }
Tony Mantler4f641d12017-03-14 22:36:14 +0000106
Tony Mantler4f641d12017-03-14 22:36:14 +0000107 // deletes the previously owned canvas (if any)
Matt Sarettea70d222017-03-29 16:25:10 -0400108 mCanvasOwned = std::move(newCanvas);
109 mCanvasWrapper = std::move(newCanvasWrapper);
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400110 mCanvas = mCanvasWrapper ? mCanvasWrapper.get() : mCanvasOwned.get();
Tony Mantler4f641d12017-03-14 22:36:14 +0000111
Derek Sollenberger8872b382014-06-23 14:13:53 -0400112 // clean up the old save stack
Stan Ilievf50806a2016-10-24 10:40:39 -0400113 mSaveStack.reset(nullptr);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400114}
115
116// ----------------------------------------------------------------------------
117// Canvas state operations
118// ----------------------------------------------------------------------------
119
120bool SkiaCanvas::isOpaque() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400121 return mCanvas->imageInfo().isOpaque();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400122}
123
124int SkiaCanvas::width() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400125 return mCanvas->imageInfo().width();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400126}
127
128int SkiaCanvas::height() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400129 return mCanvas->imageInfo().height();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400130}
131
132// ----------------------------------------------------------------------------
133// Canvas state operations: Save (layer)
134// ----------------------------------------------------------------------------
135
136int SkiaCanvas::getSaveCount() const {
137 return mCanvas->getSaveCount();
138}
139
Florin Malitaeecff562015-12-21 10:43:01 -0500140int SkiaCanvas::save(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400141 int count = mCanvas->save();
142 recordPartialSave(flags);
143 return count;
144}
145
Florin Malita5e271402015-11-04 14:36:02 -0500146// The SkiaCanvas::restore operation layers on the capability to preserve
147// either (or both) the matrix and/or clip state after a SkCanvas::restore
148// operation. It does this by explicitly saving off the clip & matrix state
149// when requested and playing it back after the SkCanvas::restore.
Derek Sollenberger8872b382014-06-23 14:13:53 -0400150void SkiaCanvas::restore() {
Stan Ilievf50806a2016-10-24 10:40:39 -0400151 const auto* rec = this->currentSaveRec();
152 if (!rec) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400153 // Fast path - no record for this frame.
154 mCanvas->restore();
155 return;
156 }
157
Florin Malitaeecff562015-12-21 10:43:01 -0500158 bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix);
159 bool preserveClip = !(rec->saveFlags & SaveFlags::Clip);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400160
161 SkMatrix savedMatrix;
162 if (preserveMatrix) {
163 savedMatrix = mCanvas->getTotalMatrix();
164 }
165
Stan Ilievf50806a2016-10-24 10:40:39 -0400166 const size_t clipIndex = rec->clipIndex;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400167
168 mCanvas->restore();
Stan Ilievf50806a2016-10-24 10:40:39 -0400169 mSaveStack->pop_back();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400170
171 if (preserveMatrix) {
172 mCanvas->setMatrix(savedMatrix);
173 }
174
Stan Ilievf50806a2016-10-24 10:40:39 -0400175 if (preserveClip) {
176 this->applyPersistentClips(clipIndex);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400177 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400178}
179
180void SkiaCanvas::restoreToCount(int restoreCount) {
181 while (mCanvas->getSaveCount() > restoreCount) {
182 this->restore();
183 }
184}
185
Florin Malitaeecff562015-12-21 10:43:01 -0500186static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) {
187 SkCanvas::SaveLayerFlags layerFlags = 0;
188
Yuqian Li83427ff2016-09-14 11:14:06 -0400189 // We intentionally ignore the SaveFlags::HasAlphaLayer and
190 // SkCanvas::kIsOpaque_SaveLayerFlag flags because HWUI ignores it
191 // and our Android client may use it incorrectly.
192 // In Skia, this flag is purely for performance optimization.
Florin Malitaeecff562015-12-21 10:43:01 -0500193
194 if (!(flags & SaveFlags::ClipToLayer)) {
195 layerFlags |= SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
196 }
197
198 return layerFlags;
199}
200
Derek Sollenberger8872b382014-06-23 14:13:53 -0400201int SkiaCanvas::saveLayer(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500202 const SkPaint* paint, SaveFlags::Flags flags) {
203 const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
Derek Sollenbergerb8201192017-01-09 16:11:59 -0500204 const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags));
Florin Malitaeecff562015-12-21 10:43:01 -0500205
Stan Iliev68885e32016-12-14 11:18:34 -0500206 return mCanvas->saveLayer(rec);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400207}
208
209int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500210 int alpha, SaveFlags::Flags flags) {
Florin Malitaeecff562015-12-21 10:43:01 -0500211 if (static_cast<unsigned>(alpha) < 0xFF) {
Yuqian Lifd92ee42016-04-27 17:03:38 -0400212 SkPaint alphaPaint;
213 alphaPaint.setAlpha(alpha);
214 return this->saveLayer(left, top, right, bottom, &alphaPaint, flags);
Florin Malitaeecff562015-12-21 10:43:01 -0500215 }
Yuqian Lifd92ee42016-04-27 17:03:38 -0400216 return this->saveLayer(left, top, right, bottom, nullptr, flags);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400217}
218
Stan Ilievf50806a2016-10-24 10:40:39 -0400219class SkiaCanvas::Clip {
220public:
Mike Reed6e49c9f2016-12-02 15:36:59 -0500221 Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400222 : mType(Type::Rect), mOp(op), mMatrix(m), mRRect(SkRRect::MakeRect(rect)) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500223 Clip(const SkRRect& rrect, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400224 : mType(Type::RRect), mOp(op), mMatrix(m), mRRect(rrect) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500225 Clip(const SkPath& path, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400226 : mType(Type::Path), mOp(op), mMatrix(m), mPath(&path) {}
227
228 void apply(SkCanvas* canvas) const {
229 canvas->setMatrix(mMatrix);
230 switch (mType) {
231 case Type::Rect:
232 canvas->clipRect(mRRect.rect(), mOp);
233 break;
234 case Type::RRect:
235 canvas->clipRRect(mRRect, mOp);
236 break;
237 case Type::Path:
238 canvas->clipPath(*mPath.get(), mOp);
239 break;
240 }
241 }
242
243private:
244 enum class Type {
245 Rect,
246 RRect,
247 Path,
248 };
249
Mike Reed6e49c9f2016-12-02 15:36:59 -0500250 Type mType;
251 SkClipOp mOp;
252 SkMatrix mMatrix;
Stan Ilievf50806a2016-10-24 10:40:39 -0400253
254 // These are logically a union (tracked separately due to non-POD path).
255 SkTLazy<SkPath> mPath;
256 SkRRect mRRect;
257};
258
259const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const {
260 const SaveRec* rec = mSaveStack
261 ? static_cast<const SaveRec*>(mSaveStack->back())
262 : nullptr;
263 int currentSaveCount = mCanvas->getSaveCount();
264 SkASSERT(!rec || currentSaveCount >= rec->saveCount);
265
266 return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr;
267}
268
Derek Sollenberger8872b382014-06-23 14:13:53 -0400269// ----------------------------------------------------------------------------
270// functions to emulate legacy SaveFlags (i.e. independent matrix/clip flags)
271// ----------------------------------------------------------------------------
272
Florin Malitaeecff562015-12-21 10:43:01 -0500273void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400274 // A partial save is a save operation which doesn't capture the full canvas state.
Florin Malitaeecff562015-12-21 10:43:01 -0500275 // (either SaveFlags::Matrix or SaveFlags::Clip is missing).
Derek Sollenberger8872b382014-06-23 14:13:53 -0400276
277 // Mask-out non canvas state bits.
Florin Malitaeecff562015-12-21 10:43:01 -0500278 flags &= SaveFlags::MatrixClip;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400279
Florin Malitaeecff562015-12-21 10:43:01 -0500280 if (flags == SaveFlags::MatrixClip) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400281 // not a partial save.
282 return;
283 }
284
Stan Ilievf50806a2016-10-24 10:40:39 -0400285 if (!mSaveStack) {
Ben Wagnerd1cbc162015-08-19 12:45:09 -0400286 mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400287 }
288
289 SaveRec* rec = static_cast<SaveRec*>(mSaveStack->push_back());
Florin Malita5e271402015-11-04 14:36:02 -0500290 rec->saveCount = mCanvas->getSaveCount();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400291 rec->saveFlags = flags;
Stan Ilievf50806a2016-10-24 10:40:39 -0400292 rec->clipIndex = mClipStack.size();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400293}
294
Stan Ilievf50806a2016-10-24 10:40:39 -0400295template <typename T>
Mike Reed6e49c9f2016-12-02 15:36:59 -0500296void SkiaCanvas::recordClip(const T& clip, SkClipOp op) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400297 // Only need tracking when in a partial save frame which
298 // doesn't restore the clip.
299 const SaveRec* rec = this->currentSaveRec();
300 if (rec && !(rec->saveFlags & SaveFlags::Clip)) {
301 mClipStack.emplace_back(clip, op, mCanvas->getTotalMatrix());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400302 }
303}
304
Stan Ilievf50806a2016-10-24 10:40:39 -0400305// Applies and optionally removes all clips >= index.
306void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) {
307 SkASSERT(clipStartIndex <= mClipStack.size());
308 const auto begin = mClipStack.cbegin() + clipStartIndex;
309 const auto end = mClipStack.cend();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400310
Stan Ilievf50806a2016-10-24 10:40:39 -0400311 // Clip application mutates the CTM.
312 const SkMatrix saveMatrix = mCanvas->getTotalMatrix();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400313
Stan Ilievf50806a2016-10-24 10:40:39 -0400314 for (auto clip = begin; clip != end; ++clip) {
Mike Reed6acfe162016-11-18 17:21:09 -0500315 clip->apply(mCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400316 }
317
Stan Ilievf50806a2016-10-24 10:40:39 -0400318 mCanvas->setMatrix(saveMatrix);
319
320 // If the current/post-restore save rec is also persisting clips, we
321 // leave them on the stack to be reapplied part of the next restore().
322 // Otherwise we're done and just pop them.
323 const auto* rec = this->currentSaveRec();
324 if (!rec || (rec->saveFlags & SaveFlags::Clip)) {
325 mClipStack.erase(begin, end);
326 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400327}
328
329// ----------------------------------------------------------------------------
330// Canvas state operations: Matrix
331// ----------------------------------------------------------------------------
332
333void SkiaCanvas::getMatrix(SkMatrix* outMatrix) const {
334 *outMatrix = mCanvas->getTotalMatrix();
335}
336
337void SkiaCanvas::setMatrix(const SkMatrix& matrix) {
338 mCanvas->setMatrix(matrix);
339}
340
341void SkiaCanvas::concat(const SkMatrix& matrix) {
342 mCanvas->concat(matrix);
343}
344
345void SkiaCanvas::rotate(float degrees) {
346 mCanvas->rotate(degrees);
347}
348
349void SkiaCanvas::scale(float sx, float sy) {
350 mCanvas->scale(sx, sy);
351}
352
353void SkiaCanvas::skew(float sx, float sy) {
354 mCanvas->skew(sx, sy);
355}
356
357void SkiaCanvas::translate(float dx, float dy) {
358 mCanvas->translate(dx, dy);
359}
360
361// ----------------------------------------------------------------------------
362// Canvas state operations: Clips
363// ----------------------------------------------------------------------------
364
365// This function is a mirror of SkCanvas::getClipBounds except that it does
366// not outset the edge of the clip to account for anti-aliasing. There is
367// a skia bug to investigate pushing this logic into back into skia.
368// (see https://code.google.com/p/skia/issues/detail?id=1303)
369bool SkiaCanvas::getClipBounds(SkRect* outRect) const {
370 SkIRect ibounds;
Mike Reed5e438982017-01-25 08:23:25 -0500371 if (!mCanvas->getDeviceClipBounds(&ibounds)) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400372 return false;
373 }
374
375 SkMatrix inverse;
376 // if we can't invert the CTM, we can't return local clip bounds
377 if (!mCanvas->getTotalMatrix().invert(&inverse)) {
378 if (outRect) {
379 outRect->setEmpty();
380 }
381 return false;
382 }
383
384 if (NULL != outRect) {
385 SkRect r = SkRect::Make(ibounds);
386 inverse.mapRect(outRect, r);
387 }
388 return true;
389}
390
391bool SkiaCanvas::quickRejectRect(float left, float top, float right, float bottom) const {
392 SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
393 return mCanvas->quickReject(bounds);
394}
395
396bool SkiaCanvas::quickRejectPath(const SkPath& path) const {
397 return mCanvas->quickReject(path);
398}
399
Mike Reed6e49c9f2016-12-02 15:36:59 -0500400bool SkiaCanvas::clipRect(float left, float top, float right, float bottom, SkClipOp op) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400401 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
Stan Ilievf50806a2016-10-24 10:40:39 -0400402 this->recordClip(rect, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400403 mCanvas->clipRect(rect, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700404 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400405}
406
Mike Reed6e49c9f2016-12-02 15:36:59 -0500407bool SkiaCanvas::clipPath(const SkPath* path, SkClipOp op) {
Derek Sollenbergerf7d98f42017-04-17 11:27:36 -0400408 this->recordClip(*path, op);
409 mCanvas->clipPath(*path, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700410 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400411}
412
Derek Sollenberger8872b382014-06-23 14:13:53 -0400413// ----------------------------------------------------------------------------
414// Canvas state operations: Filters
415// ----------------------------------------------------------------------------
416
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400417SkDrawFilter* SkiaCanvas::getDrawFilter() {
418 return mCanvas->getDrawFilter();
419}
420
Derek Sollenberger8872b382014-06-23 14:13:53 -0400421void SkiaCanvas::setDrawFilter(SkDrawFilter* drawFilter) {
422 mCanvas->setDrawFilter(drawFilter);
423}
424
425// ----------------------------------------------------------------------------
Matt Sarettd0814db2017-04-13 09:33:18 -0400426// Canvas state operations: Capture
427// ----------------------------------------------------------------------------
428
429SkCanvasState* SkiaCanvas::captureCanvasState() const {
430 SkCanvas* canvas = mCanvas;
431 if (mCanvasOwned) {
432 // Important to use the underlying SkCanvas, not the wrapper.
433 canvas = mCanvasOwned.get();
434 }
435
436 // Workarounds for http://crbug.com/271096: SW draw only supports
437 // translate & scale transforms, and a simple rectangular clip.
438 // (This also avoids significant wasted time in calling
439 // SkCanvasStateUtils::CaptureCanvasState when the clip is complex).
440 if (!canvas->isClipRect() ||
441 (canvas->getTotalMatrix().getType() &
442 ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) {
443 return nullptr;
444 }
445
446 return SkCanvasStateUtils::CaptureCanvasState(canvas);
447}
448
449// ----------------------------------------------------------------------------
Derek Sollenberger8872b382014-06-23 14:13:53 -0400450// Canvas draw operations
451// ----------------------------------------------------------------------------
452
Mike Reed260ab722016-10-07 15:59:20 -0400453void SkiaCanvas::drawColor(int color, SkBlendMode mode) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400454 mCanvas->drawColor(color, mode);
455}
456
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400457void SkiaCanvas::drawPaint(const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400458 mCanvas->drawPaint(paint);
459}
460
461// ----------------------------------------------------------------------------
462// Canvas draw operations: Geometry
463// ----------------------------------------------------------------------------
464
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400465void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400466 SkCanvas::PointMode mode) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500467 if (CC_UNLIKELY(count < 2 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400468 // convert the floats into SkPoints
469 count >>= 1; // now it is the number of points
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400470 std::unique_ptr<SkPoint[]> pts(new SkPoint[count]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400471 for (int i = 0; i < count; i++) {
472 pts[i].set(points[0], points[1]);
473 points += 2;
474 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400475 mCanvas->drawPoints(mode, count, pts.get(), paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400476}
477
478
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400479void SkiaCanvas::drawPoint(float x, float y, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400480 mCanvas->drawPoint(x, y, paint);
481}
482
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400483void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400484 this->drawPoints(points, count, paint, SkCanvas::kPoints_PointMode);
485}
486
487void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400488 const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400489 mCanvas->drawLine(startX, startY, stopX, stopY, paint);
490}
491
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400492void SkiaCanvas::drawLines(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500493 if (CC_UNLIKELY(count < 4 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400494 this->drawPoints(points, count, paint, SkCanvas::kLines_PointMode);
495}
496
497void SkiaCanvas::drawRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400498 const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500499 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Mike Reed6c9bb242017-04-04 09:15:37 -0400500 mCanvas->drawRect({left, top, right, bottom}, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400501
502}
503
Derek Sollenberger94394b32015-07-10 09:58:41 -0400504void SkiaCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500505 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400506 mCanvas->drawRegion(region, paint);
Derek Sollenberger94394b32015-07-10 09:58:41 -0400507}
508
Derek Sollenberger8872b382014-06-23 14:13:53 -0400509void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400510 float rx, float ry, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500511 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400512 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
513 mCanvas->drawRoundRect(rect, rx, ry, paint);
514}
515
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400516void SkiaCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500517 if (CC_UNLIKELY(radius <= 0 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400518 mCanvas->drawCircle(x, y, radius, paint);
519}
520
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400521void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500522 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400523 SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
524 mCanvas->drawOval(oval, paint);
525}
526
527void SkiaCanvas::drawArc(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400528 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500529 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400530 SkRect arc = SkRect::MakeLTRB(left, top, right, bottom);
531 mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, paint);
532}
533
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400534void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500535 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Stan Iliev6dcfdec2017-08-15 16:42:05 -0400536 if (CC_UNLIKELY(path.isEmpty() && (!path.isInverseFillType()))) {
537 return;
538 }
Derek Sollenbergerd7f13f82017-03-09 13:08:27 -0500539 mCanvas->drawPath(path, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400540}
541
Mike Reed826deef2017-04-04 15:32:04 -0400542void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
543 mCanvas->drawVertices(vertices, mode, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400544}
545
546// ----------------------------------------------------------------------------
547// Canvas draw operations: Bitmaps
548// ----------------------------------------------------------------------------
549
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400550const SkPaint* SkiaCanvas::addFilter(const SkPaint* origPaint, SkPaint* tmpPaint,
551 sk_sp<SkColorFilter> colorSpaceFilter) {
552 /* We don't apply the colorSpace filter if this canvas is already wrapped with
553 * a SkColorSpaceXformCanvas since it already takes care of converting the
554 * contents of the bitmap into the appropriate colorspace. The mCanvasWrapper
555 * should only be used if this canvas is backed by a surface/bitmap that is known
556 * to have a non-sRGB colorspace.
557 */
558 if (!mCanvasWrapper && colorSpaceFilter) {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400559 if (origPaint) {
560 *tmpPaint = *origPaint;
561 }
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400562
563 if (tmpPaint->getColorFilter()) {
564 tmpPaint->setColorFilter(SkColorFilter::MakeComposeFilter(
565 tmpPaint->refColorFilter(), colorSpaceFilter));
566 LOG_ALWAYS_FATAL_IF(!tmpPaint->getColorFilter());
567 } else {
568 tmpPaint->setColorFilter(colorSpaceFilter);
569 }
570
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400571 return tmpPaint;
572 } else {
573 return origPaint;
574 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400575}
576
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400577void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) {
578 SkPaint tmpPaint;
579 sk_sp<SkColorFilter> colorFilter;
580 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
581 mCanvas->drawImage(image, left, top, addFilter(paint, &tmpPaint, colorFilter));
582}
583
584void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) {
Mike Reed6acfe162016-11-18 17:21:09 -0500585 SkAutoCanvasRestore acr(mCanvas, true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500586 mCanvas->concat(matrix);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400587
588 SkPaint tmpPaint;
589 sk_sp<SkColorFilter> colorFilter;
590 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
591 mCanvas->drawImage(image, 0, 0, addFilter(paint, &tmpPaint, colorFilter));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400592}
593
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400594void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400595 float srcRight, float srcBottom, float dstLeft, float dstTop,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400596 float dstRight, float dstBottom, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400597 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
598 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400599
600 SkPaint tmpPaint;
601 sk_sp<SkColorFilter> colorFilter;
602 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
Derek Sollenberger6c2a9e22017-08-15 16:23:01 -0400603 mCanvas->drawImageRect(image, srcRect, dstRect, addFilter(paint, &tmpPaint, colorFilter),
604 SkCanvas::kFast_SrcRectConstraint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400605}
606
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400607void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400608 const float* vertices, const int* colors, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400609 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
610 const int indexCount = meshWidth * meshHeight * 6;
Mike Reed871cd2d2017-03-17 10:15:52 -0400611 uint32_t flags = SkVertices::kHasTexCoords_BuilderFlag;
612 if (colors) {
613 flags |= SkVertices::kHasColors_BuilderFlag;
614 }
Mike Reed826deef2017-04-04 15:32:04 -0400615 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
Mike Reed871cd2d2017-03-17 10:15:52 -0400616 memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint));
617 if (colors) {
618 memcpy(builder.colors(), colors, ptCount * sizeof(SkColor));
619 }
620 SkPoint* texs = builder.texCoords();
621 uint16_t* indices = builder.indices();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400622
623 // cons up texture coordinates and indices
624 {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400625 const SkScalar w = SkIntToScalar(bitmap.width());
626 const SkScalar h = SkIntToScalar(bitmap.height());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400627 const SkScalar dx = w / meshWidth;
628 const SkScalar dy = h / meshHeight;
629
630 SkPoint* texsPtr = texs;
631 SkScalar y = 0;
632 for (int i = 0; i <= meshHeight; i++) {
633 if (i == meshHeight) {
634 y = h; // to ensure numerically we hit h exactly
635 }
636 SkScalar x = 0;
637 for (int j = 0; j < meshWidth; j++) {
638 texsPtr->set(x, y);
639 texsPtr += 1;
640 x += dx;
641 }
642 texsPtr->set(w, y);
643 texsPtr += 1;
644 y += dy;
645 }
646 SkASSERT(texsPtr - texs == ptCount);
647 }
648
649 // cons up indices
650 {
651 uint16_t* indexPtr = indices;
652 int index = 0;
653 for (int i = 0; i < meshHeight; i++) {
654 for (int j = 0; j < meshWidth; j++) {
655 // lower-left triangle
656 *indexPtr++ = index;
657 *indexPtr++ = index + meshWidth + 1;
658 *indexPtr++ = index + meshWidth + 2;
659 // upper-right triangle
660 *indexPtr++ = index;
661 *indexPtr++ = index + meshWidth + 2;
662 *indexPtr++ = index + 1;
663 // bump to the next cell
664 index += 1;
665 }
666 // bump to the next row
667 index += 1;
668 }
669 SkASSERT(indexPtr - indices == indexCount);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400670 }
671
672 // double-check that we have legal indices
673#ifdef SK_DEBUG
674 {
675 for (int i = 0; i < indexCount; i++) {
676 SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
677 }
678 }
679#endif
680
681 // cons-up a shader for the bitmap
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400682 SkPaint tmpPaint;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400683 if (paint) {
684 tmpPaint = *paint;
685 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400686
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400687 sk_sp<SkColorFilter> colorFilter;
688 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
689 sk_sp<SkShader> shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
690 if(colorFilter) {
691 shader = shader->makeWithColorFilter(colorFilter);
692 }
693 tmpPaint.setShader(shader);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400694
Mike Reed871cd2d2017-03-17 10:15:52 -0400695 mCanvas->drawVertices(builder.detach(), SkBlendMode::kModulate, tmpPaint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400696}
697
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400698void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk,
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400699 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400700
Stan Ilievf50806a2016-10-24 10:40:39 -0400701 SkCanvas::Lattice lattice;
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400702 NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height());
Stan Ilievf50806a2016-10-24 10:40:39 -0400703
704 lattice.fFlags = nullptr;
705 int numFlags = 0;
Stan Iliev021693b2016-10-17 16:26:15 -0400706 if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400707 // We can expect the framework to give us a color for every distinct rect.
708 // Skia requires a flag for every rect.
709 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
710 }
711
712 SkAutoSTMalloc<25, SkCanvas::Lattice::Flags> flags(numFlags);
713 if (numFlags > 0) {
Stan Iliev021693b2016-10-17 16:26:15 -0400714 NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk);
Stan Ilievf50806a2016-10-24 10:40:39 -0400715 }
716
717 lattice.fBounds = nullptr;
718 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400719
720 SkPaint tmpPaint;
721 sk_sp<SkColorFilter> colorFilter;
722 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
723 mCanvas->drawImageLattice(image.get(), lattice, dst, addFilter(paint, &tmpPaint, colorFilter));
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400724}
725
Doris Liu766431a2016-02-04 22:17:11 +0000726void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800727 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000728}
729
Derek Sollenberger8872b382014-06-23 14:13:53 -0400730// ----------------------------------------------------------------------------
731// Canvas draw operations: Text
732// ----------------------------------------------------------------------------
733
Stan Iliev0b58d992017-03-30 18:22:27 -0400734void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& paint, float x,
735 float y, float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500736 float totalAdvance) {
Stan Iliev0b58d992017-03-30 18:22:27 -0400737 if (count <= 0 || paint.nothingToDraw()) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400738 // Set align to left for drawing, as we don't want individual
739 // glyphs centered or right-aligned; the offset above takes
740 // care of all alignment.
741 SkPaint paintCopy(paint);
742 paintCopy.setTextAlign(SkPaint::kLeft_Align);
743
744 SkRect bounds = SkRect::MakeLTRB(boundsLeft + x, boundsTop + y,
745 boundsRight + x, boundsBottom + y);
746
747 SkTextBlobBuilder builder;
748 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
Stan Iliev0b58d992017-03-30 18:22:27 -0400749 glyphFunc(buffer.glyphs, buffer.pos);
Stan Ilievf50806a2016-10-24 10:40:39 -0400750
751 sk_sp<SkTextBlob> textBlob(builder.make());
752 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
753 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400754}
755
Yuqian Liafc221492016-07-18 13:07:42 -0400756void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
757 const SkPaint& paint, const SkPath& path, size_t start, size_t end) {
758 const int N = end - start;
Derek Sollenbergere547dd02016-11-09 11:55:59 -0500759 SkAutoSTMalloc<1024, uint8_t> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
Yuqian Liafc221492016-07-18 13:07:42 -0400760 SkRSXform* xform = (SkRSXform*)storage.get();
761 uint16_t* glyphs = (uint16_t*)(xform + N);
762 SkPathMeasure meas(path, false);
763
764 for (size_t i = start; i < end; i++) {
765 glyphs[i - start] = layout.getGlyphId(i);
766 float x = hOffset + layout.getX(i);
767 float y = vOffset + layout.getY(i);
768
769 SkPoint pos;
770 SkVector tan;
771 if (!meas.getPosTan(x, &pos, &tan)) {
772 pos.set(x, y);
773 tan.set(1, 0);
774 }
775 xform[i - start].fSCos = tan.x();
776 xform[i - start].fSSin = tan.y();
777 xform[i - start].fTx = pos.x() - tan.y() * y;
778 xform[i - start].fTy = pos.y() + tan.x() * y;
779 }
780
781 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400782}
783
Derek Sollenberger6f485562015-07-30 10:00:39 -0400784// ----------------------------------------------------------------------------
785// Canvas draw operations: Animations
786// ----------------------------------------------------------------------------
787
Derek Sollenberger6f485562015-07-30 10:00:39 -0400788void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
789 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
790 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
791 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400792 sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable(
793 new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400794 mCanvas->drawDrawable(drawable.get());
795}
796
797void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
798 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400799 sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable(new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400800 mCanvas->drawDrawable(drawable.get());
801}
802
803// ----------------------------------------------------------------------------
804// Canvas draw operations: View System
805// ----------------------------------------------------------------------------
806
Stan Ilievf50806a2016-10-24 10:40:39 -0400807void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400808 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
809}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400810
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400811void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
812 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
813}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400814
John Reckcd1c3eb2016-04-14 10:38:54 -0700815void SkiaCanvas::callDrawGLFunction(Functor* functor,
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400816 uirenderer::GlFunctorLifecycleListener* listener) {
817 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
818}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400819
Derek Sollenberger8872b382014-06-23 14:13:53 -0400820} // namespace android