blob: 76d1166e978e79b0deb76efc75261351ef79c3fc [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;
Derek Sollenbergerd7f13f82017-03-09 13:08:27 -0500536 mCanvas->drawPath(path, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400537}
538
Mike Reed826deef2017-04-04 15:32:04 -0400539void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
540 mCanvas->drawVertices(vertices, mode, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400541}
542
543// ----------------------------------------------------------------------------
544// Canvas draw operations: Bitmaps
545// ----------------------------------------------------------------------------
546
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400547const SkPaint* SkiaCanvas::addFilter(const SkPaint* origPaint, SkPaint* tmpPaint,
548 sk_sp<SkColorFilter> colorSpaceFilter) {
549 /* We don't apply the colorSpace filter if this canvas is already wrapped with
550 * a SkColorSpaceXformCanvas since it already takes care of converting the
551 * contents of the bitmap into the appropriate colorspace. The mCanvasWrapper
552 * should only be used if this canvas is backed by a surface/bitmap that is known
553 * to have a non-sRGB colorspace.
554 */
555 if (!mCanvasWrapper && colorSpaceFilter) {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400556 if (origPaint) {
557 *tmpPaint = *origPaint;
558 }
Derek Sollenbergerfa3e3402017-08-04 08:35:10 -0400559
560 if (tmpPaint->getColorFilter()) {
561 tmpPaint->setColorFilter(SkColorFilter::MakeComposeFilter(
562 tmpPaint->refColorFilter(), colorSpaceFilter));
563 LOG_ALWAYS_FATAL_IF(!tmpPaint->getColorFilter());
564 } else {
565 tmpPaint->setColorFilter(colorSpaceFilter);
566 }
567
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400568 return tmpPaint;
569 } else {
570 return origPaint;
571 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400572}
573
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400574void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) {
575 SkPaint tmpPaint;
576 sk_sp<SkColorFilter> colorFilter;
577 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
578 mCanvas->drawImage(image, left, top, addFilter(paint, &tmpPaint, colorFilter));
579}
580
581void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) {
Mike Reed6acfe162016-11-18 17:21:09 -0500582 SkAutoCanvasRestore acr(mCanvas, true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500583 mCanvas->concat(matrix);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400584
585 SkPaint tmpPaint;
586 sk_sp<SkColorFilter> colorFilter;
587 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
588 mCanvas->drawImage(image, 0, 0, addFilter(paint, &tmpPaint, colorFilter));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400589}
590
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400591void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400592 float srcRight, float srcBottom, float dstLeft, float dstTop,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400593 float dstRight, float dstBottom, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400594 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
595 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400596
597 SkPaint tmpPaint;
598 sk_sp<SkColorFilter> colorFilter;
599 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
Derek Sollenberger6c2a9e22017-08-15 16:23:01 -0400600 mCanvas->drawImageRect(image, srcRect, dstRect, addFilter(paint, &tmpPaint, colorFilter),
601 SkCanvas::kFast_SrcRectConstraint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400602}
603
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400604void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400605 const float* vertices, const int* colors, const SkPaint* paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400606 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
607 const int indexCount = meshWidth * meshHeight * 6;
Mike Reed871cd2d2017-03-17 10:15:52 -0400608 uint32_t flags = SkVertices::kHasTexCoords_BuilderFlag;
609 if (colors) {
610 flags |= SkVertices::kHasColors_BuilderFlag;
611 }
Mike Reed826deef2017-04-04 15:32:04 -0400612 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
Mike Reed871cd2d2017-03-17 10:15:52 -0400613 memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint));
614 if (colors) {
615 memcpy(builder.colors(), colors, ptCount * sizeof(SkColor));
616 }
617 SkPoint* texs = builder.texCoords();
618 uint16_t* indices = builder.indices();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400619
620 // cons up texture coordinates and indices
621 {
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400622 const SkScalar w = SkIntToScalar(bitmap.width());
623 const SkScalar h = SkIntToScalar(bitmap.height());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400624 const SkScalar dx = w / meshWidth;
625 const SkScalar dy = h / meshHeight;
626
627 SkPoint* texsPtr = texs;
628 SkScalar y = 0;
629 for (int i = 0; i <= meshHeight; i++) {
630 if (i == meshHeight) {
631 y = h; // to ensure numerically we hit h exactly
632 }
633 SkScalar x = 0;
634 for (int j = 0; j < meshWidth; j++) {
635 texsPtr->set(x, y);
636 texsPtr += 1;
637 x += dx;
638 }
639 texsPtr->set(w, y);
640 texsPtr += 1;
641 y += dy;
642 }
643 SkASSERT(texsPtr - texs == ptCount);
644 }
645
646 // cons up indices
647 {
648 uint16_t* indexPtr = indices;
649 int index = 0;
650 for (int i = 0; i < meshHeight; i++) {
651 for (int j = 0; j < meshWidth; j++) {
652 // lower-left triangle
653 *indexPtr++ = index;
654 *indexPtr++ = index + meshWidth + 1;
655 *indexPtr++ = index + meshWidth + 2;
656 // upper-right triangle
657 *indexPtr++ = index;
658 *indexPtr++ = index + meshWidth + 2;
659 *indexPtr++ = index + 1;
660 // bump to the next cell
661 index += 1;
662 }
663 // bump to the next row
664 index += 1;
665 }
666 SkASSERT(indexPtr - indices == indexCount);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400667 }
668
669 // double-check that we have legal indices
670#ifdef SK_DEBUG
671 {
672 for (int i = 0; i < indexCount; i++) {
673 SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
674 }
675 }
676#endif
677
678 // cons-up a shader for the bitmap
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400679 SkPaint tmpPaint;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400680 if (paint) {
681 tmpPaint = *paint;
682 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400683
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400684 sk_sp<SkColorFilter> colorFilter;
685 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
686 sk_sp<SkShader> shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
687 if(colorFilter) {
688 shader = shader->makeWithColorFilter(colorFilter);
689 }
690 tmpPaint.setShader(shader);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400691
Mike Reed871cd2d2017-03-17 10:15:52 -0400692 mCanvas->drawVertices(builder.detach(), SkBlendMode::kModulate, tmpPaint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400693}
694
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400695void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk,
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400696 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400697
Stan Ilievf50806a2016-10-24 10:40:39 -0400698 SkCanvas::Lattice lattice;
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400699 NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height());
Stan Ilievf50806a2016-10-24 10:40:39 -0400700
701 lattice.fFlags = nullptr;
702 int numFlags = 0;
Stan Iliev021693b2016-10-17 16:26:15 -0400703 if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400704 // We can expect the framework to give us a color for every distinct rect.
705 // Skia requires a flag for every rect.
706 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
707 }
708
709 SkAutoSTMalloc<25, SkCanvas::Lattice::Flags> flags(numFlags);
710 if (numFlags > 0) {
Stan Iliev021693b2016-10-17 16:26:15 -0400711 NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk);
Stan Ilievf50806a2016-10-24 10:40:39 -0400712 }
713
714 lattice.fBounds = nullptr;
715 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Derek Sollenbergerfb0c8fc2017-07-26 13:53:27 -0400716
717 SkPaint tmpPaint;
718 sk_sp<SkColorFilter> colorFilter;
719 sk_sp<SkImage> image = bitmap.makeImage(&colorFilter);
720 mCanvas->drawImageLattice(image.get(), lattice, dst, addFilter(paint, &tmpPaint, colorFilter));
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400721}
722
Doris Liu766431a2016-02-04 22:17:11 +0000723void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800724 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000725}
726
Derek Sollenberger8872b382014-06-23 14:13:53 -0400727// ----------------------------------------------------------------------------
728// Canvas draw operations: Text
729// ----------------------------------------------------------------------------
730
Stan Iliev0b58d992017-03-30 18:22:27 -0400731void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& paint, float x,
732 float y, float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500733 float totalAdvance) {
Stan Iliev0b58d992017-03-30 18:22:27 -0400734 if (count <= 0 || paint.nothingToDraw()) return;
Stan Ilievf50806a2016-10-24 10:40:39 -0400735 // Set align to left for drawing, as we don't want individual
736 // glyphs centered or right-aligned; the offset above takes
737 // care of all alignment.
738 SkPaint paintCopy(paint);
739 paintCopy.setTextAlign(SkPaint::kLeft_Align);
740
741 SkRect bounds = SkRect::MakeLTRB(boundsLeft + x, boundsTop + y,
742 boundsRight + x, boundsBottom + y);
743
744 SkTextBlobBuilder builder;
745 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
Stan Iliev0b58d992017-03-30 18:22:27 -0400746 glyphFunc(buffer.glyphs, buffer.pos);
Stan Ilievf50806a2016-10-24 10:40:39 -0400747
748 sk_sp<SkTextBlob> textBlob(builder.make());
749 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
750 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400751}
752
Yuqian Liafc221492016-07-18 13:07:42 -0400753void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
754 const SkPaint& paint, const SkPath& path, size_t start, size_t end) {
755 const int N = end - start;
Derek Sollenbergere547dd02016-11-09 11:55:59 -0500756 SkAutoSTMalloc<1024, uint8_t> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
Yuqian Liafc221492016-07-18 13:07:42 -0400757 SkRSXform* xform = (SkRSXform*)storage.get();
758 uint16_t* glyphs = (uint16_t*)(xform + N);
759 SkPathMeasure meas(path, false);
760
761 for (size_t i = start; i < end; i++) {
762 glyphs[i - start] = layout.getGlyphId(i);
763 float x = hOffset + layout.getX(i);
764 float y = vOffset + layout.getY(i);
765
766 SkPoint pos;
767 SkVector tan;
768 if (!meas.getPosTan(x, &pos, &tan)) {
769 pos.set(x, y);
770 tan.set(1, 0);
771 }
772 xform[i - start].fSCos = tan.x();
773 xform[i - start].fSSin = tan.y();
774 xform[i - start].fTx = pos.x() - tan.y() * y;
775 xform[i - start].fTy = pos.y() + tan.x() * y;
776 }
777
778 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400779}
780
Derek Sollenberger6f485562015-07-30 10:00:39 -0400781// ----------------------------------------------------------------------------
782// Canvas draw operations: Animations
783// ----------------------------------------------------------------------------
784
Derek Sollenberger6f485562015-07-30 10:00:39 -0400785void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
786 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
787 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
788 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400789 sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable(
790 new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400791 mCanvas->drawDrawable(drawable.get());
792}
793
794void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
795 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400796 sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable(new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400797 mCanvas->drawDrawable(drawable.get());
798}
799
800// ----------------------------------------------------------------------------
801// Canvas draw operations: View System
802// ----------------------------------------------------------------------------
803
Stan Ilievf50806a2016-10-24 10:40:39 -0400804void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400805 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
806}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400807
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400808void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
809 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
810}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400811
John Reckcd1c3eb2016-04-14 10:38:54 -0700812void SkiaCanvas::callDrawGLFunction(Functor* functor,
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400813 uirenderer::GlFunctorLifecycleListener* listener) {
814 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
815}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400816
Derek Sollenberger8872b382014-06-23 14:13:53 -0400817} // namespace android