blob: 11aaebd3e8b4df8870e26ca771e5c3fff461cdad [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"
20#include "VectorDrawable.h"
sergeyvaed7f582016-10-14 16:30:21 -070021#include "hwui/Bitmap.h"
Yuqian Liafc221492016-07-18 13:07:42 -040022#include "hwui/MinikinUtils.h"
Derek Sollenbergerc1908132016-07-15 10:28:16 -040023
Derek Sollenberger6f485562015-07-30 10:00:39 -040024#include <SkDrawable.h>
John Reck849911a2015-01-20 07:51:14 -080025#include <SkDevice.h>
26#include <SkDeque.h>
27#include <SkDrawFilter.h>
28#include <SkGraphics.h>
Derek Sollenberger6f485562015-07-30 10:00:39 -040029#include <SkImage.h>
Matt Sarett62feb3a2016-09-20 10:34:11 -040030#include <SkImagePriv.h>
Yuqian Liafc221492016-07-18 13:07:42 -040031#include <SkRSXform.h>
John Reck849911a2015-01-20 07:51:14 -080032#include <SkShader.h>
John Reck849911a2015-01-20 07:51:14 -080033#include <SkTemplates.h>
Stan Ilievf50806a2016-10-24 10:40:39 -040034#include <SkTextBlob.h>
Derek Sollenberger8872b382014-06-23 14:13:53 -040035
Ben Wagner60126ef2015-08-07 12:13:48 -040036#include <memory>
37
Derek Sollenberger8872b382014-06-23 14:13:53 -040038namespace android {
39
Stan Ilievf50806a2016-10-24 10:40:39 -040040using uirenderer::PaintUtils;
41
John Reckc1b33d62015-04-22 09:04:45 -070042Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040043 return new SkiaCanvas(bitmap);
44}
45
46Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
47 return new SkiaCanvas(skiaCanvas);
48}
49
Stan Ilievf50806a2016-10-24 10:40:39 -040050SkiaCanvas::SkiaCanvas() {}
51
52SkiaCanvas::SkiaCanvas(SkCanvas* canvas)
53 : mCanvas(SkRef(canvas)) {}
54
John Reckc1b33d62015-04-22 09:04:45 -070055SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
56 mCanvas.reset(new SkCanvas(bitmap));
Derek Sollenberger8872b382014-06-23 14:13:53 -040057}
58
Derek Sollenbergerc1908132016-07-15 10:28:16 -040059void SkiaCanvas::reset(SkCanvas* skiaCanvas) {
Derek Sollenberger86cbf882016-07-20 11:53:05 -040060 mCanvas.reset(SkRef(skiaCanvas));
Derek Sollenbergerc1908132016-07-15 10:28:16 -040061 mSaveStack.reset(nullptr);
62 mHighContrastText = false;
63}
64
Derek Sollenberger8872b382014-06-23 14:13:53 -040065// ----------------------------------------------------------------------------
66// Canvas state operations: Replace Bitmap
67// ----------------------------------------------------------------------------
68
69class ClipCopier : public SkCanvas::ClipVisitor {
70public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -070071 explicit ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {}
Derek Sollenberger8872b382014-06-23 14:13:53 -040072
73 virtual void clipRect(const SkRect& rect, SkRegion::Op op, bool antialias) {
74 m_dstCanvas->clipRect(rect, op, antialias);
75 }
76 virtual void clipRRect(const SkRRect& rrect, SkRegion::Op op, bool antialias) {
77 m_dstCanvas->clipRRect(rrect, op, antialias);
78 }
79 virtual void clipPath(const SkPath& path, SkRegion::Op op, bool antialias) {
80 m_dstCanvas->clipPath(path, op, antialias);
81 }
82
83private:
84 SkCanvas* m_dstCanvas;
85};
86
John Reckc1b33d62015-04-22 09:04:45 -070087void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
Stan Ilievf50806a2016-10-24 10:40:39 -040088 SkCanvas* newCanvas = new SkCanvas(bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -040089
John Reckc1b33d62015-04-22 09:04:45 -070090 if (!bitmap.isNull()) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040091 // Copy the canvas matrix & clip state.
92 newCanvas->setMatrix(mCanvas->getTotalMatrix());
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -040093
Stan Ilievf50806a2016-10-24 10:40:39 -040094 ClipCopier copier(newCanvas);
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -040095 mCanvas->replayClips(&copier);
Derek Sollenberger8872b382014-06-23 14:13:53 -040096 }
97
98 // unrefs the existing canvas
Stan Ilievf50806a2016-10-24 10:40:39 -040099 mCanvas.reset(newCanvas);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400100
101 // clean up the old save stack
Stan Ilievf50806a2016-10-24 10:40:39 -0400102 mSaveStack.reset(nullptr);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400103}
104
105// ----------------------------------------------------------------------------
106// Canvas state operations
107// ----------------------------------------------------------------------------
108
109bool SkiaCanvas::isOpaque() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400110 return mCanvas->imageInfo().isOpaque();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400111}
112
113int SkiaCanvas::width() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400114 return mCanvas->imageInfo().width();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400115}
116
117int SkiaCanvas::height() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400118 return mCanvas->imageInfo().height();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400119}
120
121// ----------------------------------------------------------------------------
122// Canvas state operations: Save (layer)
123// ----------------------------------------------------------------------------
124
125int SkiaCanvas::getSaveCount() const {
126 return mCanvas->getSaveCount();
127}
128
Florin Malitaeecff562015-12-21 10:43:01 -0500129int SkiaCanvas::save(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400130 int count = mCanvas->save();
131 recordPartialSave(flags);
132 return count;
133}
134
Florin Malita5e271402015-11-04 14:36:02 -0500135// The SkiaCanvas::restore operation layers on the capability to preserve
136// either (or both) the matrix and/or clip state after a SkCanvas::restore
137// operation. It does this by explicitly saving off the clip & matrix state
138// when requested and playing it back after the SkCanvas::restore.
Derek Sollenberger8872b382014-06-23 14:13:53 -0400139void SkiaCanvas::restore() {
Stan Ilievf50806a2016-10-24 10:40:39 -0400140 const auto* rec = this->currentSaveRec();
141 if (!rec) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400142 // Fast path - no record for this frame.
143 mCanvas->restore();
144 return;
145 }
146
Florin Malitaeecff562015-12-21 10:43:01 -0500147 bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix);
148 bool preserveClip = !(rec->saveFlags & SaveFlags::Clip);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400149
150 SkMatrix savedMatrix;
151 if (preserveMatrix) {
152 savedMatrix = mCanvas->getTotalMatrix();
153 }
154
Stan Ilievf50806a2016-10-24 10:40:39 -0400155 const size_t clipIndex = rec->clipIndex;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400156
157 mCanvas->restore();
Stan Ilievf50806a2016-10-24 10:40:39 -0400158 mSaveStack->pop_back();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400159
160 if (preserveMatrix) {
161 mCanvas->setMatrix(savedMatrix);
162 }
163
Stan Ilievf50806a2016-10-24 10:40:39 -0400164 if (preserveClip) {
165 this->applyPersistentClips(clipIndex);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400166 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400167}
168
169void SkiaCanvas::restoreToCount(int restoreCount) {
170 while (mCanvas->getSaveCount() > restoreCount) {
171 this->restore();
172 }
173}
174
Florin Malitaeecff562015-12-21 10:43:01 -0500175static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) {
176 SkCanvas::SaveLayerFlags layerFlags = 0;
177
Yuqian Li83427ff2016-09-14 11:14:06 -0400178 // We intentionally ignore the SaveFlags::HasAlphaLayer and
179 // SkCanvas::kIsOpaque_SaveLayerFlag flags because HWUI ignores it
180 // and our Android client may use it incorrectly.
181 // In Skia, this flag is purely for performance optimization.
Florin Malitaeecff562015-12-21 10:43:01 -0500182
183 if (!(flags & SaveFlags::ClipToLayer)) {
184 layerFlags |= SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
185 }
186
187 return layerFlags;
188}
189
Derek Sollenberger8872b382014-06-23 14:13:53 -0400190int SkiaCanvas::saveLayer(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500191 const SkPaint* paint, SaveFlags::Flags flags) {
192 const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
193 const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags));
194
195 int count = mCanvas->saveLayer(rec);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400196 recordPartialSave(flags);
197 return count;
198}
199
200int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500201 int alpha, SaveFlags::Flags flags) {
Florin Malitaeecff562015-12-21 10:43:01 -0500202 if (static_cast<unsigned>(alpha) < 0xFF) {
Yuqian Lifd92ee42016-04-27 17:03:38 -0400203 SkPaint alphaPaint;
204 alphaPaint.setAlpha(alpha);
205 return this->saveLayer(left, top, right, bottom, &alphaPaint, flags);
Florin Malitaeecff562015-12-21 10:43:01 -0500206 }
Yuqian Lifd92ee42016-04-27 17:03:38 -0400207 return this->saveLayer(left, top, right, bottom, nullptr, flags);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400208}
209
Stan Ilievf50806a2016-10-24 10:40:39 -0400210class SkiaCanvas::Clip {
211public:
212 Clip(const SkRect& rect, SkRegion::Op op, const SkMatrix& m)
213 : mType(Type::Rect), mOp(op), mMatrix(m), mRRect(SkRRect::MakeRect(rect)) {}
214 Clip(const SkRRect& rrect, SkRegion::Op op, const SkMatrix& m)
215 : mType(Type::RRect), mOp(op), mMatrix(m), mRRect(rrect) {}
216 Clip(const SkPath& path, SkRegion::Op op, const SkMatrix& m)
217 : mType(Type::Path), mOp(op), mMatrix(m), mPath(&path) {}
218
219 void apply(SkCanvas* canvas) const {
220 canvas->setMatrix(mMatrix);
221 switch (mType) {
222 case Type::Rect:
223 canvas->clipRect(mRRect.rect(), mOp);
224 break;
225 case Type::RRect:
226 canvas->clipRRect(mRRect, mOp);
227 break;
228 case Type::Path:
229 canvas->clipPath(*mPath.get(), mOp);
230 break;
231 }
232 }
233
234private:
235 enum class Type {
236 Rect,
237 RRect,
238 Path,
239 };
240
241 Type mType;
242 SkRegion::Op mOp;
243 SkMatrix mMatrix;
244
245 // These are logically a union (tracked separately due to non-POD path).
246 SkTLazy<SkPath> mPath;
247 SkRRect mRRect;
248};
249
250const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const {
251 const SaveRec* rec = mSaveStack
252 ? static_cast<const SaveRec*>(mSaveStack->back())
253 : nullptr;
254 int currentSaveCount = mCanvas->getSaveCount();
255 SkASSERT(!rec || currentSaveCount >= rec->saveCount);
256
257 return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr;
258}
259
Derek Sollenberger8872b382014-06-23 14:13:53 -0400260// ----------------------------------------------------------------------------
261// functions to emulate legacy SaveFlags (i.e. independent matrix/clip flags)
262// ----------------------------------------------------------------------------
263
Florin Malitaeecff562015-12-21 10:43:01 -0500264void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400265 // A partial save is a save operation which doesn't capture the full canvas state.
Florin Malitaeecff562015-12-21 10:43:01 -0500266 // (either SaveFlags::Matrix or SaveFlags::Clip is missing).
Derek Sollenberger8872b382014-06-23 14:13:53 -0400267
268 // Mask-out non canvas state bits.
Florin Malitaeecff562015-12-21 10:43:01 -0500269 flags &= SaveFlags::MatrixClip;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400270
Florin Malitaeecff562015-12-21 10:43:01 -0500271 if (flags == SaveFlags::MatrixClip) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400272 // not a partial save.
273 return;
274 }
275
Stan Ilievf50806a2016-10-24 10:40:39 -0400276 if (!mSaveStack) {
Ben Wagnerd1cbc162015-08-19 12:45:09 -0400277 mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400278 }
279
280 SaveRec* rec = static_cast<SaveRec*>(mSaveStack->push_back());
Florin Malita5e271402015-11-04 14:36:02 -0500281 rec->saveCount = mCanvas->getSaveCount();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400282 rec->saveFlags = flags;
Stan Ilievf50806a2016-10-24 10:40:39 -0400283 rec->clipIndex = mClipStack.size();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400284}
285
Stan Ilievf50806a2016-10-24 10:40:39 -0400286template <typename T>
287void SkiaCanvas::recordClip(const T& clip, SkRegion::Op op) {
288 // Only need tracking when in a partial save frame which
289 // doesn't restore the clip.
290 const SaveRec* rec = this->currentSaveRec();
291 if (rec && !(rec->saveFlags & SaveFlags::Clip)) {
292 mClipStack.emplace_back(clip, op, mCanvas->getTotalMatrix());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400293 }
294}
295
Stan Ilievf50806a2016-10-24 10:40:39 -0400296// Applies and optionally removes all clips >= index.
297void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) {
298 SkASSERT(clipStartIndex <= mClipStack.size());
299 const auto begin = mClipStack.cbegin() + clipStartIndex;
300 const auto end = mClipStack.cend();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400301
Stan Ilievf50806a2016-10-24 10:40:39 -0400302 // Clip application mutates the CTM.
303 const SkMatrix saveMatrix = mCanvas->getTotalMatrix();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400304
Stan Ilievf50806a2016-10-24 10:40:39 -0400305 for (auto clip = begin; clip != end; ++clip) {
306 clip->apply(mCanvas.get());
Derek Sollenberger8872b382014-06-23 14:13:53 -0400307 }
308
Stan Ilievf50806a2016-10-24 10:40:39 -0400309 mCanvas->setMatrix(saveMatrix);
310
311 // If the current/post-restore save rec is also persisting clips, we
312 // leave them on the stack to be reapplied part of the next restore().
313 // Otherwise we're done and just pop them.
314 const auto* rec = this->currentSaveRec();
315 if (!rec || (rec->saveFlags & SaveFlags::Clip)) {
316 mClipStack.erase(begin, end);
317 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400318}
319
320// ----------------------------------------------------------------------------
321// Canvas state operations: Matrix
322// ----------------------------------------------------------------------------
323
324void SkiaCanvas::getMatrix(SkMatrix* outMatrix) const {
325 *outMatrix = mCanvas->getTotalMatrix();
326}
327
328void SkiaCanvas::setMatrix(const SkMatrix& matrix) {
329 mCanvas->setMatrix(matrix);
330}
331
332void SkiaCanvas::concat(const SkMatrix& matrix) {
333 mCanvas->concat(matrix);
334}
335
336void SkiaCanvas::rotate(float degrees) {
337 mCanvas->rotate(degrees);
338}
339
340void SkiaCanvas::scale(float sx, float sy) {
341 mCanvas->scale(sx, sy);
342}
343
344void SkiaCanvas::skew(float sx, float sy) {
345 mCanvas->skew(sx, sy);
346}
347
348void SkiaCanvas::translate(float dx, float dy) {
349 mCanvas->translate(dx, dy);
350}
351
352// ----------------------------------------------------------------------------
353// Canvas state operations: Clips
354// ----------------------------------------------------------------------------
355
356// This function is a mirror of SkCanvas::getClipBounds except that it does
357// not outset the edge of the clip to account for anti-aliasing. There is
358// a skia bug to investigate pushing this logic into back into skia.
359// (see https://code.google.com/p/skia/issues/detail?id=1303)
360bool SkiaCanvas::getClipBounds(SkRect* outRect) const {
361 SkIRect ibounds;
362 if (!mCanvas->getClipDeviceBounds(&ibounds)) {
363 return false;
364 }
365
366 SkMatrix inverse;
367 // if we can't invert the CTM, we can't return local clip bounds
368 if (!mCanvas->getTotalMatrix().invert(&inverse)) {
369 if (outRect) {
370 outRect->setEmpty();
371 }
372 return false;
373 }
374
375 if (NULL != outRect) {
376 SkRect r = SkRect::Make(ibounds);
377 inverse.mapRect(outRect, r);
378 }
379 return true;
380}
381
382bool SkiaCanvas::quickRejectRect(float left, float top, float right, float bottom) const {
383 SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
384 return mCanvas->quickReject(bounds);
385}
386
387bool SkiaCanvas::quickRejectPath(const SkPath& path) const {
388 return mCanvas->quickReject(path);
389}
390
391bool SkiaCanvas::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
392 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
Stan Ilievf50806a2016-10-24 10:40:39 -0400393 this->recordClip(rect, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400394 mCanvas->clipRect(rect, op);
Chris Craik5ec6a282015-06-23 15:42:12 -0700395 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400396}
397
398bool SkiaCanvas::clipPath(const SkPath* path, SkRegion::Op op) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400399 SkRRect roundRect;
400 if (path->isRRect(&roundRect)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400401 this->recordClip(roundRect, op);
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400402 mCanvas->clipRRect(roundRect, op);
403 } else {
Stan Ilievf50806a2016-10-24 10:40:39 -0400404 this->recordClip(*path, op);
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400405 mCanvas->clipPath(*path, op);
406 }
Chris Craik5ec6a282015-06-23 15:42:12 -0700407 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400408}
409
410bool SkiaCanvas::clipRegion(const SkRegion* region, SkRegion::Op op) {
411 SkPath rgnPath;
412 if (region->getBoundaryPath(&rgnPath)) {
413 // The region is specified in device space.
414 SkMatrix savedMatrix = mCanvas->getTotalMatrix();
415 mCanvas->resetMatrix();
Stan Ilievf50806a2016-10-24 10:40:39 -0400416 this->recordClip(rgnPath, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400417 mCanvas->clipPath(rgnPath, op);
418 mCanvas->setMatrix(savedMatrix);
419 } else {
Stan Ilievf50806a2016-10-24 10:40:39 -0400420 const auto emptyClip = SkRect::MakeEmpty();
421 this->recordClip(emptyClip, op);
422 mCanvas->clipRect(emptyClip, op);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400423 }
Chris Craik5ec6a282015-06-23 15:42:12 -0700424 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400425}
426
427// ----------------------------------------------------------------------------
428// Canvas state operations: Filters
429// ----------------------------------------------------------------------------
430
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400431SkDrawFilter* SkiaCanvas::getDrawFilter() {
432 return mCanvas->getDrawFilter();
433}
434
Derek Sollenberger8872b382014-06-23 14:13:53 -0400435void SkiaCanvas::setDrawFilter(SkDrawFilter* drawFilter) {
436 mCanvas->setDrawFilter(drawFilter);
437}
438
439// ----------------------------------------------------------------------------
440// Canvas draw operations
441// ----------------------------------------------------------------------------
442
Mike Reed260ab722016-10-07 15:59:20 -0400443void SkiaCanvas::drawColor(int color, SkBlendMode mode) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400444 mCanvas->drawColor(color, mode);
445}
446
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400447void SkiaCanvas::drawPaint(const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400448 mCanvas->drawPaint(paint);
449}
450
451// ----------------------------------------------------------------------------
452// Canvas draw operations: Geometry
453// ----------------------------------------------------------------------------
454
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400455void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400456 SkCanvas::PointMode mode) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400457 if (CC_UNLIKELY(count < 2 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400458 // convert the floats into SkPoints
459 count >>= 1; // now it is the number of points
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400460 std::unique_ptr<SkPoint[]> pts(new SkPoint[count]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400461 for (int i = 0; i < count; i++) {
462 pts[i].set(points[0], points[1]);
463 points += 2;
464 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400465 mCanvas->drawPoints(mode, count, pts.get(), paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400466}
467
468
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400469void SkiaCanvas::drawPoint(float x, float y, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400470 mCanvas->drawPoint(x, y, paint);
471}
472
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400473void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400474 this->drawPoints(points, count, paint, SkCanvas::kPoints_PointMode);
475}
476
477void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400478 const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400479 mCanvas->drawLine(startX, startY, stopX, stopY, paint);
480}
481
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400482void SkiaCanvas::drawLines(const float* points, int count, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400483 if (CC_UNLIKELY(count < 4 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400484 this->drawPoints(points, count, paint, SkCanvas::kLines_PointMode);
485}
486
487void SkiaCanvas::drawRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400488 const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400489 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400490 mCanvas->drawRectCoords(left, top, right, bottom, paint);
491
492}
493
Derek Sollenberger94394b32015-07-10 09:58:41 -0400494void SkiaCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400495 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
496 mCanvas->drawRegion(region, paint);
Derek Sollenberger94394b32015-07-10 09:58:41 -0400497}
498
Derek Sollenberger8872b382014-06-23 14:13:53 -0400499void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400500 float rx, float ry, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400501 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400502 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
503 mCanvas->drawRoundRect(rect, rx, ry, paint);
504}
505
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400506void SkiaCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400507 if (CC_UNLIKELY(radius <= 0 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400508 mCanvas->drawCircle(x, y, radius, paint);
509}
510
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400511void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400512 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400513 SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
514 mCanvas->drawOval(oval, paint);
515}
516
517void SkiaCanvas::drawArc(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400518 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400519 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400520 SkRect arc = SkRect::MakeLTRB(left, top, right, bottom);
521 mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, paint);
522}
523
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400524void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400525 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400526 SkRect rect;
527 SkRRect roundRect;
528 if (path.isOval(&rect)) {
529 mCanvas->drawOval(rect, paint);
530 } else if (path.isRRect(&roundRect)) {
531 mCanvas->drawRRect(roundRect, paint);
532 } else {
533 mCanvas->drawPath(path, paint);
534 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400535}
536
537void SkiaCanvas::drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
538 const float* verts, const float* texs, const int* colors,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400539 const uint16_t* indices, int indexCount, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400540#ifndef SK_SCALAR_IS_FLOAT
541 SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
542#endif
543 const int ptCount = vertexCount >> 1;
544 mCanvas->drawVertices(vertexMode, ptCount, (SkPoint*)verts, (SkPoint*)texs,
545 (SkColor*)colors, NULL, indices, indexCount, paint);
546}
547
548// ----------------------------------------------------------------------------
549// Canvas draw operations: Bitmaps
550// ----------------------------------------------------------------------------
551
sergeyvaed7f582016-10-14 16:30:21 -0700552void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) {
553 SkBitmap skBitmap;
554 bitmap.getSkBitmap(&skBitmap);
555 mCanvas->drawBitmap(skBitmap, left, top, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400556}
557
sergeyvfc9999502016-10-17 13:07:38 -0700558void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, const SkMatrix& matrix, const SkPaint* paint) {
559 SkBitmap bitmap;
560 hwuiBitmap.getSkBitmap(&bitmap);
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400561 SkAutoCanvasRestore acr(mCanvas.get(), true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500562 mCanvas->concat(matrix);
563 mCanvas->drawBitmap(bitmap, 0, 0, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400564}
565
sergeyvfc9999502016-10-17 13:07:38 -0700566void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400567 float srcRight, float srcBottom, float dstLeft, float dstTop,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400568 float dstRight, float dstBottom, const SkPaint* paint) {
sergeyvfc9999502016-10-17 13:07:38 -0700569 SkBitmap bitmap;
570 hwuiBitmap.getSkBitmap(&bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400571 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
572 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400573 mCanvas->drawBitmapRect(bitmap, srcRect, dstRect, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400574}
575
sergeyv5fd2a1c2016-10-20 15:04:28 -0700576void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeight,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400577 const float* vertices, const int* colors, const SkPaint* paint) {
sergeyv5fd2a1c2016-10-20 15:04:28 -0700578 SkBitmap bitmap;
579 hwuiBitmap.getSkBitmap(&bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400580 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
581 const int indexCount = meshWidth * meshHeight * 6;
582
583 /* Our temp storage holds 2 or 3 arrays.
584 texture points [ptCount * sizeof(SkPoint)]
585 optionally vertex points [ptCount * sizeof(SkPoint)] if we need a
586 copy to convert from float to fixed
587 indices [ptCount * sizeof(uint16_t)]
588 */
589 ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
590 storageSize += indexCount * sizeof(uint16_t); // indices[]
591
592
593#ifndef SK_SCALAR_IS_FLOAT
594 SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
595#endif
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400596 std::unique_ptr<char[]> storage(new char[storageSize]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400597 SkPoint* texs = (SkPoint*)storage.get();
598 uint16_t* indices = (uint16_t*)(texs + ptCount);
599
600 // cons up texture coordinates and indices
601 {
602 const SkScalar w = SkIntToScalar(bitmap.width());
603 const SkScalar h = SkIntToScalar(bitmap.height());
604 const SkScalar dx = w / meshWidth;
605 const SkScalar dy = h / meshHeight;
606
607 SkPoint* texsPtr = texs;
608 SkScalar y = 0;
609 for (int i = 0; i <= meshHeight; i++) {
610 if (i == meshHeight) {
611 y = h; // to ensure numerically we hit h exactly
612 }
613 SkScalar x = 0;
614 for (int j = 0; j < meshWidth; j++) {
615 texsPtr->set(x, y);
616 texsPtr += 1;
617 x += dx;
618 }
619 texsPtr->set(w, y);
620 texsPtr += 1;
621 y += dy;
622 }
623 SkASSERT(texsPtr - texs == ptCount);
624 }
625
626 // cons up indices
627 {
628 uint16_t* indexPtr = indices;
629 int index = 0;
630 for (int i = 0; i < meshHeight; i++) {
631 for (int j = 0; j < meshWidth; j++) {
632 // lower-left triangle
633 *indexPtr++ = index;
634 *indexPtr++ = index + meshWidth + 1;
635 *indexPtr++ = index + meshWidth + 2;
636 // upper-right triangle
637 *indexPtr++ = index;
638 *indexPtr++ = index + meshWidth + 2;
639 *indexPtr++ = index + 1;
640 // bump to the next cell
641 index += 1;
642 }
643 // bump to the next row
644 index += 1;
645 }
646 SkASSERT(indexPtr - indices == indexCount);
647 SkASSERT((char*)indexPtr - (char*)storage.get() == storageSize);
648 }
649
650 // double-check that we have legal indices
651#ifdef SK_DEBUG
652 {
653 for (int i = 0; i < indexCount; i++) {
654 SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
655 }
656 }
657#endif
658
659 // cons-up a shader for the bitmap
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400660 SkPaint tmpPaint;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400661 if (paint) {
662 tmpPaint = *paint;
663 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400664
665 sk_sp<SkImage> image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode);
666 tmpPaint.setShader(image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400667
668 mCanvas->drawVertices(SkCanvas::kTriangles_VertexMode, ptCount, (SkPoint*)vertices,
669 texs, (const SkColor*)colors, NULL, indices,
670 indexCount, tmpPaint);
671}
672
Stan Ilievf50806a2016-10-24 10:40:39 -0400673static inline void set_lattice_divs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk,
674 int width, int height) {
675 lattice->fXCount = chunk.numXDivs;
676 lattice->fYCount = chunk.numYDivs;
677 lattice->fXDivs = chunk.getXDivs();
678 lattice->fYDivs = chunk.getYDivs();
679
680 // We'll often see ninepatches where the last div is equal to the width or height.
681 // This doesn't provide any additional information and is not supported by Skia.
682 if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) {
683 lattice->fXCount--;
684 }
685 if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) {
686 lattice->fYCount--;
687 }
688}
689
690static inline int num_distinct_rects(const SkCanvas::Lattice& lattice) {
691 int xRects;
692 if (lattice.fXCount > 0) {
693 xRects = (0 == lattice.fXDivs[0]) ? lattice.fXCount : lattice.fXCount + 1;
694 } else {
695 xRects = 1;
696 }
697
698 int yRects;
699 if (lattice.fYCount > 0) {
700 yRects = (0 == lattice.fYDivs[0]) ? lattice.fYCount : lattice.fYCount + 1;
701 } else {
702 yRects = 1;
703 }
704 return xRects * yRects;
705}
706
707static inline void set_lattice_flags(SkCanvas::Lattice* lattice, SkCanvas::Lattice::Flags* flags,
708 int numFlags, const Res_png_9patch& chunk) {
709 lattice->fFlags = flags;
710 sk_bzero(flags, numFlags * sizeof(SkCanvas::Lattice::Flags));
711
712 bool needPadRow = lattice->fYCount > 0 && 0 == lattice->fYDivs[0];
713 bool needPadCol = lattice->fXCount > 0 && 0 == lattice->fXDivs[0];
714
715 int yCount = lattice->fYCount;
716 if (needPadRow) {
717 // Skip flags for the degenerate first row of rects.
718 flags += lattice->fXCount + 1;
719 yCount--;
720 }
721
722 int i = 0;
723 bool setFlags = false;
724 for (int y = 0; y < yCount + 1; y++) {
725 for (int x = 0; x < lattice->fXCount + 1; x++) {
726 if (0 == x && needPadCol) {
727 // First rect of each column is degenerate, skip the flag.
728 flags++;
729 continue;
730 }
731
732 if (0 == chunk.getColors()[i++]) {
733 *flags = SkCanvas::Lattice::kTransparent_Flags;
734 setFlags = true;
735 }
736
737 flags++;
738 }
739 }
740
741 if (!setFlags) {
742 lattice->fFlags = nullptr;
743 }
744}
745
sergeyv5fd2a1c2016-10-20 15:04:28 -0700746void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk,
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400747 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400748
sergeyv5fd2a1c2016-10-20 15:04:28 -0700749 SkBitmap bitmap;
750 hwuiBitmap.getSkBitmap(&bitmap);
Stan Ilievf50806a2016-10-24 10:40:39 -0400751
752 SkCanvas::Lattice lattice;
753 set_lattice_divs(&lattice, chunk, bitmap.width(), bitmap.height());
754
755 lattice.fFlags = nullptr;
756 int numFlags = 0;
757 if (chunk.numColors > 0 && chunk.numColors == num_distinct_rects(lattice)) {
758 // We can expect the framework to give us a color for every distinct rect.
759 // Skia requires a flag for every rect.
760 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
761 }
762
763 SkAutoSTMalloc<25, SkCanvas::Lattice::Flags> flags(numFlags);
764 if (numFlags > 0) {
765 set_lattice_flags(&lattice, flags.get(), numFlags, chunk);
766 }
767
768 lattice.fBounds = nullptr;
769 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
770 mCanvas->drawBitmapLattice(bitmap, lattice, dst, paint);
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400771}
772
Doris Liu766431a2016-02-04 22:17:11 +0000773void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800774 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000775}
776
Derek Sollenberger8872b382014-06-23 14:13:53 -0400777// ----------------------------------------------------------------------------
778// Canvas draw operations: Text
779// ----------------------------------------------------------------------------
780
sergeyvdccca442016-03-21 15:38:21 -0700781void SkiaCanvas::drawGlyphs(const uint16_t* text, const float* positions, int count,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400782 const SkPaint& paint, float x, float y,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500783 float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
784 float totalAdvance) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400785 if (!text || !positions || count <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
786 // Set align to left for drawing, as we don't want individual
787 // glyphs centered or right-aligned; the offset above takes
788 // care of all alignment.
789 SkPaint paintCopy(paint);
790 paintCopy.setTextAlign(SkPaint::kLeft_Align);
791
792 SkRect bounds = SkRect::MakeLTRB(boundsLeft + x, boundsTop + y,
793 boundsRight + x, boundsBottom + y);
794
795 SkTextBlobBuilder builder;
796 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
797 // TODO: we could reduce the number of memcpy's if the this were exposed further up
798 // in the architecture.
799 memcpy(buffer.glyphs, text, count * sizeof(uint16_t));
800 memcpy(buffer.pos, positions, (count << 1) * sizeof(float));
801
802 sk_sp<SkTextBlob> textBlob(builder.make());
803 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
804 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400805}
806
Yuqian Liafc221492016-07-18 13:07:42 -0400807void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
808 const SkPaint& paint, const SkPath& path, size_t start, size_t end) {
809 const int N = end - start;
810 SkAutoSMalloc<1024> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
811 SkRSXform* xform = (SkRSXform*)storage.get();
812 uint16_t* glyphs = (uint16_t*)(xform + N);
813 SkPathMeasure meas(path, false);
814
815 for (size_t i = start; i < end; i++) {
816 glyphs[i - start] = layout.getGlyphId(i);
817 float x = hOffset + layout.getX(i);
818 float y = vOffset + layout.getY(i);
819
820 SkPoint pos;
821 SkVector tan;
822 if (!meas.getPosTan(x, &pos, &tan)) {
823 pos.set(x, y);
824 tan.set(1, 0);
825 }
826 xform[i - start].fSCos = tan.x();
827 xform[i - start].fSSin = tan.y();
828 xform[i - start].fTx = pos.x() - tan.y() * y;
829 xform[i - start].fTy = pos.y() + tan.x() * y;
830 }
831
832 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400833}
834
Derek Sollenberger6f485562015-07-30 10:00:39 -0400835// ----------------------------------------------------------------------------
836// Canvas draw operations: Animations
837// ----------------------------------------------------------------------------
838
839class AnimatedRoundRect : public SkDrawable {
840 public:
841 AnimatedRoundRect(uirenderer::CanvasPropertyPrimitive* left,
842 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
843 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
844 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* p) :
845 mLeft(left), mTop(top), mRight(right), mBottom(bottom), mRx(rx), mRy(ry), mPaint(p) {}
846
847 protected:
848 virtual SkRect onGetBounds() override {
849 return SkRect::MakeLTRB(mLeft->value, mTop->value, mRight->value, mBottom->value);
850 }
851 virtual void onDraw(SkCanvas* canvas) override {
852 SkRect rect = SkRect::MakeLTRB(mLeft->value, mTop->value, mRight->value, mBottom->value);
853 canvas->drawRoundRect(rect, mRx->value, mRy->value, mPaint->value);
854 }
855
856 private:
857 sp<uirenderer::CanvasPropertyPrimitive> mLeft;
858 sp<uirenderer::CanvasPropertyPrimitive> mTop;
859 sp<uirenderer::CanvasPropertyPrimitive> mRight;
860 sp<uirenderer::CanvasPropertyPrimitive> mBottom;
861 sp<uirenderer::CanvasPropertyPrimitive> mRx;
862 sp<uirenderer::CanvasPropertyPrimitive> mRy;
863 sp<uirenderer::CanvasPropertyPaint> mPaint;
864};
865
866class AnimatedCircle : public SkDrawable {
867 public:
868 AnimatedCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
869 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) :
870 mX(x), mY(y), mRadius(radius), mPaint(paint) {}
871
872 protected:
873 virtual SkRect onGetBounds() override {
874 const float x = mX->value;
875 const float y = mY->value;
876 const float radius = mRadius->value;
877 return SkRect::MakeLTRB(x - radius, y - radius, x + radius, y + radius);
878 }
879 virtual void onDraw(SkCanvas* canvas) override {
880 canvas->drawCircle(mX->value, mY->value, mRadius->value, mPaint->value);
881 }
882
883 private:
884 sp<uirenderer::CanvasPropertyPrimitive> mX;
885 sp<uirenderer::CanvasPropertyPrimitive> mY;
886 sp<uirenderer::CanvasPropertyPrimitive> mRadius;
887 sp<uirenderer::CanvasPropertyPaint> mPaint;
888};
889
890void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
891 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
892 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
893 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400894 sk_sp<AnimatedRoundRect> drawable(
Derek Sollenberger6f485562015-07-30 10:00:39 -0400895 new AnimatedRoundRect(left, top, right, bottom, rx, ry, paint));
896 mCanvas->drawDrawable(drawable.get());
897}
898
899void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
900 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400901 sk_sp<AnimatedCircle> drawable(new AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400902 mCanvas->drawDrawable(drawable.get());
903}
904
905// ----------------------------------------------------------------------------
906// Canvas draw operations: View System
907// ----------------------------------------------------------------------------
908
Stan Ilievf50806a2016-10-24 10:40:39 -0400909void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400910 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
911}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400912
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400913void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
914 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
915}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400916
John Reckcd1c3eb2016-04-14 10:38:54 -0700917void SkiaCanvas::callDrawGLFunction(Functor* functor,
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400918 uirenderer::GlFunctorLifecycleListener* listener) {
919 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
920}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400921
Derek Sollenberger8872b382014-06-23 14:13:53 -0400922} // namespace android