blob: 1f5f733188de0877e8316068f6db483101fac0bf [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);
Derek Sollenbergerc1908132016-07-15 10:28:16 -040088}
89
Derek Sollenberger8872b382014-06-23 14:13:53 -040090// ----------------------------------------------------------------------------
91// Canvas state operations: Replace Bitmap
92// ----------------------------------------------------------------------------
93
John Reckc1b33d62015-04-22 09:04:45 -070094void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
Romain Guy82426562017-04-04 19:38:50 -070095 sk_sp<SkColorSpace> cs = bitmap.refColorSpace();
Matt Sarettca9b7032017-04-13 12:18:47 -040096 std::unique_ptr<SkCanvas> newCanvas =
97 std::unique_ptr<SkCanvas>(new SkCanvas(bitmap, SkCanvas::ColorBehavior::kLegacy));
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -040098 std::unique_ptr<SkCanvas> newCanvasWrapper;
99 if (cs.get() != nullptr && !cs->isSRGB()) {
100 newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), std::move(cs));
101 }
102 else if(!uirenderer::Properties::isSkiaEnabled()) {
103 newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), SkColorSpace::MakeSRGB());
104 }
Tony Mantler4f641d12017-03-14 22:36:14 +0000105
Tony Mantler4f641d12017-03-14 22:36:14 +0000106 // deletes the previously owned canvas (if any)
Matt Sarettea70d222017-03-29 16:25:10 -0400107 mCanvasOwned = std::move(newCanvas);
108 mCanvasWrapper = std::move(newCanvasWrapper);
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400109 mCanvas = mCanvasWrapper ? mCanvasWrapper.get() : mCanvasOwned.get();
Tony Mantler4f641d12017-03-14 22:36:14 +0000110
Derek Sollenberger8872b382014-06-23 14:13:53 -0400111 // clean up the old save stack
Stan Ilievf50806a2016-10-24 10:40:39 -0400112 mSaveStack.reset(nullptr);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400113}
114
115// ----------------------------------------------------------------------------
116// Canvas state operations
117// ----------------------------------------------------------------------------
118
119bool SkiaCanvas::isOpaque() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400120 return mCanvas->imageInfo().isOpaque();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400121}
122
123int SkiaCanvas::width() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400124 return mCanvas->imageInfo().width();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400125}
126
127int SkiaCanvas::height() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400128 return mCanvas->imageInfo().height();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400129}
130
131// ----------------------------------------------------------------------------
132// Canvas state operations: Save (layer)
133// ----------------------------------------------------------------------------
134
135int SkiaCanvas::getSaveCount() const {
136 return mCanvas->getSaveCount();
137}
138
Florin Malitaeecff562015-12-21 10:43:01 -0500139int SkiaCanvas::save(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400140 int count = mCanvas->save();
141 recordPartialSave(flags);
142 return count;
143}
144
Florin Malita5e271402015-11-04 14:36:02 -0500145// The SkiaCanvas::restore operation layers on the capability to preserve
146// either (or both) the matrix and/or clip state after a SkCanvas::restore
147// operation. It does this by explicitly saving off the clip & matrix state
148// when requested and playing it back after the SkCanvas::restore.
Derek Sollenberger8872b382014-06-23 14:13:53 -0400149void SkiaCanvas::restore() {
Stan Ilievf50806a2016-10-24 10:40:39 -0400150 const auto* rec = this->currentSaveRec();
151 if (!rec) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400152 // Fast path - no record for this frame.
153 mCanvas->restore();
154 return;
155 }
156
Florin Malitaeecff562015-12-21 10:43:01 -0500157 bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix);
158 bool preserveClip = !(rec->saveFlags & SaveFlags::Clip);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400159
160 SkMatrix savedMatrix;
161 if (preserveMatrix) {
162 savedMatrix = mCanvas->getTotalMatrix();
163 }
164
Stan Ilievf50806a2016-10-24 10:40:39 -0400165 const size_t clipIndex = rec->clipIndex;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400166
167 mCanvas->restore();
Stan Ilievf50806a2016-10-24 10:40:39 -0400168 mSaveStack->pop_back();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400169
170 if (preserveMatrix) {
171 mCanvas->setMatrix(savedMatrix);
172 }
173
Stan Ilievf50806a2016-10-24 10:40:39 -0400174 if (preserveClip) {
175 this->applyPersistentClips(clipIndex);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400176 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400177}
178
179void SkiaCanvas::restoreToCount(int restoreCount) {
180 while (mCanvas->getSaveCount() > restoreCount) {
181 this->restore();
182 }
183}
184
Florin Malitaeecff562015-12-21 10:43:01 -0500185static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) {
186 SkCanvas::SaveLayerFlags layerFlags = 0;
187
Yuqian Li83427ff2016-09-14 11:14:06 -0400188 // We intentionally ignore the SaveFlags::HasAlphaLayer and
189 // SkCanvas::kIsOpaque_SaveLayerFlag flags because HWUI ignores it
190 // and our Android client may use it incorrectly.
191 // In Skia, this flag is purely for performance optimization.
Florin Malitaeecff562015-12-21 10:43:01 -0500192
193 if (!(flags & SaveFlags::ClipToLayer)) {
194 layerFlags |= SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
195 }
196
197 return layerFlags;
198}
199
Derek Sollenberger8872b382014-06-23 14:13:53 -0400200int SkiaCanvas::saveLayer(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500201 const SkPaint* paint, SaveFlags::Flags flags) {
202 const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
Derek Sollenbergerb8201192017-01-09 16:11:59 -0500203 const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags));
Florin Malitaeecff562015-12-21 10:43:01 -0500204
Stan Iliev68885e32016-12-14 11:18:34 -0500205 return mCanvas->saveLayer(rec);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400206}
207
208int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500209 int alpha, SaveFlags::Flags flags) {
Florin Malitaeecff562015-12-21 10:43:01 -0500210 if (static_cast<unsigned>(alpha) < 0xFF) {
Yuqian Lifd92ee42016-04-27 17:03:38 -0400211 SkPaint alphaPaint;
212 alphaPaint.setAlpha(alpha);
213 return this->saveLayer(left, top, right, bottom, &alphaPaint, flags);
Florin Malitaeecff562015-12-21 10:43:01 -0500214 }
Yuqian Lifd92ee42016-04-27 17:03:38 -0400215 return this->saveLayer(left, top, right, bottom, nullptr, flags);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400216}
217
Stan Ilievf50806a2016-10-24 10:40:39 -0400218class SkiaCanvas::Clip {
219public:
Mike Reed6e49c9f2016-12-02 15:36:59 -0500220 Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400221 : mType(Type::Rect), mOp(op), mMatrix(m), mRRect(SkRRect::MakeRect(rect)) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500222 Clip(const SkRRect& rrect, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400223 : mType(Type::RRect), mOp(op), mMatrix(m), mRRect(rrect) {}
Mike Reed6e49c9f2016-12-02 15:36:59 -0500224 Clip(const SkPath& path, SkClipOp op, const SkMatrix& m)
Stan Ilievf50806a2016-10-24 10:40:39 -0400225 : mType(Type::Path), mOp(op), mMatrix(m), mPath(&path) {}
226
227 void apply(SkCanvas* canvas) const {
228 canvas->setMatrix(mMatrix);
229 switch (mType) {
230 case Type::Rect:
231 canvas->clipRect(mRRect.rect(), mOp);
232 break;
233 case Type::RRect:
234 canvas->clipRRect(mRRect, mOp);
235 break;
236 case Type::Path:
237 canvas->clipPath(*mPath.get(), mOp);
238 break;
239 }
240 }
241
242private:
243 enum class Type {
244 Rect,
245 RRect,
246 Path,
247 };
248
Mike Reed6e49c9f2016-12-02 15:36:59 -0500249 Type mType;
250 SkClipOp mOp;
251 SkMatrix mMatrix;
Stan Ilievf50806a2016-10-24 10:40:39 -0400252
253 // These are logically a union (tracked separately due to non-POD path).
254 SkTLazy<SkPath> mPath;
255 SkRRect mRRect;
256};
257
258const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const {
259 const SaveRec* rec = mSaveStack
260 ? static_cast<const SaveRec*>(mSaveStack->back())
261 : nullptr;
262 int currentSaveCount = mCanvas->getSaveCount();
263 SkASSERT(!rec || currentSaveCount >= rec->saveCount);
264
265 return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr;
266}
267
Derek Sollenberger8872b382014-06-23 14:13:53 -0400268// ----------------------------------------------------------------------------
269// functions to emulate legacy SaveFlags (i.e. independent matrix/clip flags)
270// ----------------------------------------------------------------------------
271
Florin Malitaeecff562015-12-21 10:43:01 -0500272void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400273 // A partial save is a save operation which doesn't capture the full canvas state.
Florin Malitaeecff562015-12-21 10:43:01 -0500274 // (either SaveFlags::Matrix or SaveFlags::Clip is missing).
Derek Sollenberger8872b382014-06-23 14:13:53 -0400275
276 // Mask-out non canvas state bits.
Florin Malitaeecff562015-12-21 10:43:01 -0500277 flags &= SaveFlags::MatrixClip;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400278
Florin Malitaeecff562015-12-21 10:43:01 -0500279 if (flags == SaveFlags::MatrixClip) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400280 // not a partial save.
281 return;
282 }
283
Stan Ilievf50806a2016-10-24 10:40:39 -0400284 if (!mSaveStack) {
Ben Wagnerd1cbc162015-08-19 12:45:09 -0400285 mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400286 }
287
288 SaveRec* rec = static_cast<SaveRec*>(mSaveStack->push_back());
Florin Malita5e271402015-11-04 14:36:02 -0500289 rec->saveCount = mCanvas->getSaveCount();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400290 rec->saveFlags = flags;
Stan Ilievf50806a2016-10-24 10:40:39 -0400291 rec->clipIndex = mClipStack.size();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400292}
293
Stan Ilievf50806a2016-10-24 10:40:39 -0400294template <typename T>
Mike Reed6e49c9f2016-12-02 15:36:59 -0500295void SkiaCanvas::recordClip(const T& clip, SkClipOp op) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400296 // 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 Sollenberger8872b382014-06-23 14:13:53 -0400301 }
302}
303
Stan Ilievf50806a2016-10-24 10:40:39 -0400304// Applies and optionally removes all clips >= index.
305void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) {
306 SkASSERT(clipStartIndex <= mClipStack.size());
307 const auto begin = mClipStack.cbegin() + clipStartIndex;
308 const auto end = mClipStack.cend();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400309
Stan Ilievf50806a2016-10-24 10:40:39 -0400310 // Clip application mutates the CTM.
311 const SkMatrix saveMatrix = mCanvas->getTotalMatrix();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400312
Stan Ilievf50806a2016-10-24 10:40:39 -0400313 for (auto clip = begin; clip != end; ++clip) {
Mike Reed6acfe162016-11-18 17:21:09 -0500314 clip->apply(mCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400315 }
316
Stan Ilievf50806a2016-10-24 10:40:39 -0400317 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 Sollenberger8872b382014-06-23 14:13:53 -0400326}
327
328// ----------------------------------------------------------------------------
329// Canvas state operations: Matrix
330// ----------------------------------------------------------------------------
331
332void SkiaCanvas::getMatrix(SkMatrix* outMatrix) const {
333 *outMatrix = mCanvas->getTotalMatrix();
334}
335
336void SkiaCanvas::setMatrix(const SkMatrix& matrix) {
337 mCanvas->setMatrix(matrix);
338}
339
340void SkiaCanvas::concat(const SkMatrix& matrix) {
341 mCanvas->concat(matrix);
342}
343
344void SkiaCanvas::rotate(float degrees) {
345 mCanvas->rotate(degrees);
346}
347
348void SkiaCanvas::scale(float sx, float sy) {
349 mCanvas->scale(sx, sy);
350}
351
352void SkiaCanvas::skew(float sx, float sy) {
353 mCanvas->skew(sx, sy);
354}
355
356void 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)
368bool SkiaCanvas::getClipBounds(SkRect* outRect) const {
369 SkIRect ibounds;
Mike Reed5e438982017-01-25 08:23:25 -0500370 if (!mCanvas->getDeviceClipBounds(&ibounds)) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400371 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
390bool 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
395bool SkiaCanvas::quickRejectPath(const SkPath& path) const {
396 return mCanvas->quickReject(path);
397}
398
Mike Reed6e49c9f2016-12-02 15:36:59 -0500399bool SkiaCanvas::clipRect(float left, float top, float right, float bottom, SkClipOp op) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400400 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
Stan Ilievf50806a2016-10-24 10:40:39 -0400401 this->recordClip(rect, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400402 mCanvas->clipRect(rect, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700403 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400404}
405
Mike Reed6e49c9f2016-12-02 15:36:59 -0500406bool SkiaCanvas::clipPath(const SkPath* path, SkClipOp op) {
Derek Sollenbergerf7d98f42017-04-17 11:27:36 -0400407 this->recordClip(*path, op);
408 mCanvas->clipPath(*path, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700409 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400410}
411
Derek Sollenberger8872b382014-06-23 14:13:53 -0400412// ----------------------------------------------------------------------------
413// Canvas state operations: Filters
414// ----------------------------------------------------------------------------
415
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400416SkDrawFilter* SkiaCanvas::getDrawFilter() {
417 return mCanvas->getDrawFilter();
418}
419
Derek Sollenberger8872b382014-06-23 14:13:53 -0400420void SkiaCanvas::setDrawFilter(SkDrawFilter* drawFilter) {
421 mCanvas->setDrawFilter(drawFilter);
422}
423
424// ----------------------------------------------------------------------------
Matt Sarettd0814db2017-04-13 09:33:18 -0400425// Canvas state operations: Capture
426// ----------------------------------------------------------------------------
427
428SkCanvasState* 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).
439 if (!canvas->isClipRect() ||
440 (canvas->getTotalMatrix().getType() &
441 ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask))) {
442 return nullptr;
443 }
444
445 return SkCanvasStateUtils::CaptureCanvasState(canvas);
446}
447
448// ----------------------------------------------------------------------------
Derek Sollenberger8872b382014-06-23 14:13:53 -0400449// Canvas draw operations
450// ----------------------------------------------------------------------------
451
Mike Reed260ab722016-10-07 15:59:20 -0400452void SkiaCanvas::drawColor(int color, SkBlendMode mode) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400453 mCanvas->drawColor(color, mode);
454}
455
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400456void SkiaCanvas::drawPaint(const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400457 mCanvas->drawPaint(paint);
458}
459
460// ----------------------------------------------------------------------------
461// Canvas draw operations: Geometry
462// ----------------------------------------------------------------------------
463
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400464void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400465 SkCanvas::PointMode mode) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500466 if (CC_UNLIKELY(count < 2 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400467 // convert the floats into SkPoints
468 count >>= 1; // now it is the number of points
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400469 std::unique_ptr<SkPoint[]> pts(new SkPoint[count]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400470 for (int i = 0; i < count; i++) {
471 pts[i].set(points[0], points[1]);
472 points += 2;
473 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400474 mCanvas->drawPoints(mode, count, pts.get(), paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400475}
476
477
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400478void SkiaCanvas::drawPoint(float x, float y, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400479 mCanvas->drawPoint(x, y, paint);
480}
481
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400482void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400483 this->drawPoints(points, count, paint, SkCanvas::kPoints_PointMode);
484}
485
486void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400487 const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400488 mCanvas->drawLine(startX, startY, stopX, stopY, paint);
489}
490
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400491void SkiaCanvas::drawLines(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500492 if (CC_UNLIKELY(count < 4 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400493 this->drawPoints(points, count, paint, SkCanvas::kLines_PointMode);
494}
495
496void SkiaCanvas::drawRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400497 const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500498 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Mike Reed6c9bb242017-04-04 09:15:37 -0400499 mCanvas->drawRect({left, top, right, bottom}, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400500
501}
502
Derek Sollenberger94394b32015-07-10 09:58:41 -0400503void SkiaCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500504 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400505 mCanvas->drawRegion(region, paint);
Derek Sollenberger94394b32015-07-10 09:58:41 -0400506}
507
Derek Sollenberger8872b382014-06-23 14:13:53 -0400508void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400509 float rx, float ry, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500510 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400511 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
512 mCanvas->drawRoundRect(rect, rx, ry, paint);
513}
514
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400515void SkiaCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500516 if (CC_UNLIKELY(radius <= 0 || paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400517 mCanvas->drawCircle(x, y, radius, paint);
518}
519
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400520void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500521 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400522 SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
523 mCanvas->drawOval(oval, paint);
524}
525
526void SkiaCanvas::drawArc(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400527 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500528 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400529 SkRect arc = SkRect::MakeLTRB(left, top, right, bottom);
530 mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, paint);
531}
532
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400533void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
Derek Sollenberger792fb322017-03-03 14:02:09 -0500534 if (CC_UNLIKELY(paint.nothingToDraw())) return;
Stan Iliev6dcfdec2017-08-15 16:42:05 -0400535 if (CC_UNLIKELY(path.isEmpty() && (!path.isInverseFillType()))) {
536 return;
537 }
Derek Sollenbergerd7f13f82017-03-09 13:08:27 -0500538 mCanvas->drawPath(path, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400539}
540
Mike Reed826deef2017-04-04 15:32:04 -0400541void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
542 mCanvas->drawVertices(vertices, mode, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400543}
544
545// ----------------------------------------------------------------------------
546// Canvas draw operations: Bitmaps
547// ----------------------------------------------------------------------------
548
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400549const SkPaint* SkiaCanvas::addFilter(const SkPaint* origPaint, SkPaint* tmpPaint,
550 sk_sp<SkColorFilter> colorSpaceFilter) {
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 Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400558 if (origPaint) {
559 *tmpPaint = *origPaint;
560 }
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400561
562 if (tmpPaint->getColorFilter()) {
563 tmpPaint->setColorFilter(SkColorFilter::MakeComposeFilter(
564 tmpPaint->refColorFilter(), colorSpaceFilter));
565 LOG_ALWAYS_FATAL_IF(!tmpPaint->getColorFilter());
566 } else {
567 tmpPaint->setColorFilter(colorSpaceFilter);
568 }
569
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400570 return tmpPaint;
571 } else {
572 return origPaint;
573 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400574}
575
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400576void 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
583void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) {
Mike Reed6acfe162016-11-18 17:21:09 -0500584 SkAutoCanvasRestore acr(mCanvas, true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500585 mCanvas->concat(matrix);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400586
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 Sollenberger8872b382014-06-23 14:13:53 -0400591}
592
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400593void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400594 float srcRight, float srcBottom, float dstLeft, float dstTop,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400595 float dstRight, float dstBottom, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400596 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
597 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400598
599 SkPaint tmpPaint;
600 sk_sp<SkColorFilter> colorFilter;
601 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
Derek Sollenberger6c2a9e22017-08-15 16:23:01 -0400602 mCanvas->drawImageRect(image, srcRect, dstRect, addFilter(paint, &tmpPaint, colorFilter),
603 SkCanvas::kFast_SrcRectConstraint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400604}
605
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400606void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400607 const float* vertices, const int* colors, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400608 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
609 const int indexCount = meshWidth * meshHeight * 6;
Mike Reed871cd2d2017-03-17 10:15:52 -0400610 uint32_t flags = SkVertices::kHasTexCoords_BuilderFlag;
611 if (colors) {
612 flags |= SkVertices::kHasColors_BuilderFlag;
613 }
Mike Reed826deef2017-04-04 15:32:04 -0400614 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
Mike Reed871cd2d2017-03-17 10:15:52 -0400615 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 Sollenberger8872b382014-06-23 14:13:53 -0400621
622 // cons up texture coordinates and indices
623 {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400624 const SkScalar w = SkIntToScalar(bitmap.width());
625 const SkScalar h = SkIntToScalar(bitmap.height());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400626 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 Sollenberger8872b382014-06-23 14:13:53 -0400669 }
670
671 // double-check that we have legal indices
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 Sollenbergeracb40992014-07-21 15:22:10 -0400681 SkPaint tmpPaint;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400682 if (paint) {
683 tmpPaint = *paint;
684 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400685
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400686 sk_sp<SkColorFilter> colorFilter;
687 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
688 sk_sp<SkShader> shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
689 if(colorFilter) {
690 shader = shader->makeWithColorFilter(colorFilter);
691 }
692 tmpPaint.setShader(shader);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400693
Mike Reed871cd2d2017-03-17 10:15:52 -0400694 mCanvas->drawVertices(builder.detach(), SkBlendMode::kModulate, tmpPaint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400695}
696
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400697void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk,
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400698 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400699
Stan Ilievf50806a2016-10-24 10:40:39 -0400700 SkCanvas::Lattice lattice;
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400701 NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height());
Stan Ilievf50806a2016-10-24 10:40:39 -0400702
703 lattice.fFlags = nullptr;
704 int numFlags = 0;
Stan Iliev021693b2016-10-17 16:26:15 -0400705 if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400706 // We can expect the framework to give us a color for every distinct rect.
707 // Skia requires a flag for every rect.
708 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
709 }
710
711 SkAutoSTMalloc<25, SkCanvas::Lattice::Flags> flags(numFlags);
712 if (numFlags > 0) {
Stan Iliev021693b2016-10-17 16:26:15 -0400713 NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk);
Stan Ilievf50806a2016-10-24 10:40:39 -0400714 }
715
716 lattice.fBounds = nullptr;
717 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400718
719 SkPaint tmpPaint;
720 sk_sp<SkColorFilter> colorFilter;
721 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
722 mCanvas->drawImageLattice(image.get(), lattice, dst, addFilter(paint, &tmpPaint, colorFilter));
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400723}
724
Doris Liu766431a2016-02-04 22:17:11 +0000725void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800726 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000727}
728
Derek Sollenberger8872b382014-06-23 14:13:53 -0400729// ----------------------------------------------------------------------------
730// Canvas draw operations: Text
731// ----------------------------------------------------------------------------
732
Stan Iliev0b58d992017-03-30 18:22:27 -0400733void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& paint, float x,
734 float y, float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500735 float totalAdvance) {
Stan Iliev0b58d992017-03-30 18:22:27 -0400736 if (count <= 0 || paint.nothingToDraw()) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400737 // Set align to left for drawing, as we don't want individual
738 // glyphs centered or right-aligned; the offset above takes
739 // care of all alignment.
740 SkPaint paintCopy(paint);
741 paintCopy.setTextAlign(SkPaint::kLeft_Align);
742
743 SkRect bounds = SkRect::MakeLTRB(boundsLeft + x, boundsTop + y,
744 boundsRight + x, boundsBottom + y);
745
746 SkTextBlobBuilder builder;
747 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
Stan Iliev0b58d992017-03-30 18:22:27 -0400748 glyphFunc(buffer.glyphs, buffer.pos);
Stan Ilievf50806a2016-10-24 10:40:39 -0400749
750 sk_sp<SkTextBlob> textBlob(builder.make());
751 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
752 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400753}
754
Yuqian Liafc221492016-07-18 13:07:42 -0400755void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
756 const SkPaint& paint, const SkPath& path, size_t start, size_t end) {
757 const int N = end - start;
Derek Sollenbergere547dd02016-11-09 11:55:59 -0500758 SkAutoSTMalloc<1024, uint8_t> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
Yuqian Liafc221492016-07-18 13:07:42 -0400759 SkRSXform* xform = (SkRSXform*)storage.get();
760 uint16_t* glyphs = (uint16_t*)(xform + N);
761 SkPathMeasure meas(path, false);
762
763 for (size_t i = start; i < end; i++) {
764 glyphs[i - start] = layout.getGlyphId(i);
765 float x = hOffset + layout.getX(i);
766 float y = vOffset + layout.getY(i);
767
768 SkPoint pos;
769 SkVector tan;
770 if (!meas.getPosTan(x, &pos, &tan)) {
771 pos.set(x, y);
772 tan.set(1, 0);
773 }
774 xform[i - start].fSCos = tan.x();
775 xform[i - start].fSSin = tan.y();
776 xform[i - start].fTx = pos.x() - tan.y() * y;
777 xform[i - start].fTy = pos.y() + tan.x() * y;
778 }
779
780 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400781}
782
Derek Sollenberger6f485562015-07-30 10:00:39 -0400783// ----------------------------------------------------------------------------
784// Canvas draw operations: Animations
785// ----------------------------------------------------------------------------
786
Derek Sollenberger6f485562015-07-30 10:00:39 -0400787void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
788 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
789 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
790 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400791 sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable(
792 new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400793 mCanvas->drawDrawable(drawable.get());
794}
795
796void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
797 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400798 sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable(new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400799 mCanvas->drawDrawable(drawable.get());
800}
801
802// ----------------------------------------------------------------------------
803// Canvas draw operations: View System
804// ----------------------------------------------------------------------------
805
Stan Ilievf50806a2016-10-24 10:40:39 -0400806void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400807 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
808}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400809
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400810void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
811 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
812}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400813
John Reckcd1c3eb2016-04-14 10:38:54 -0700814void SkiaCanvas::callDrawGLFunction(Functor* functor,
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400815 uirenderer::GlFunctorLifecycleListener* listener) {
816 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
817}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400818
Derek Sollenberger8872b382014-06-23 14:13:53 -0400819} // namespace android