blob: 344df0a70da52de7dc72a210e77a9ba0c8c1966d [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
Derek Sollenberger6f485562015-07-30 10:00:39 -040026#include <SkDrawable.h>
John Reck849911a2015-01-20 07:51:14 -080027#include <SkDevice.h>
28#include <SkDeque.h>
29#include <SkDrawFilter.h>
30#include <SkGraphics.h>
Derek Sollenberger6f485562015-07-30 10:00:39 -040031#include <SkImage.h>
Matt Sarett62feb3a2016-09-20 10:34:11 -040032#include <SkImagePriv.h>
Yuqian Liafc221492016-07-18 13:07:42 -040033#include <SkRSXform.h>
John Reck849911a2015-01-20 07:51:14 -080034#include <SkShader.h>
John Reck849911a2015-01-20 07:51:14 -080035#include <SkTemplates.h>
Stan Ilievf50806a2016-10-24 10:40:39 -040036#include <SkTextBlob.h>
Derek Sollenberger8872b382014-06-23 14:13:53 -040037
Ben Wagner60126ef2015-08-07 12:13:48 -040038#include <memory>
39
Derek Sollenberger8872b382014-06-23 14:13:53 -040040namespace android {
41
Stan Ilievf50806a2016-10-24 10:40:39 -040042using uirenderer::PaintUtils;
43
John Reckc1b33d62015-04-22 09:04:45 -070044Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040045 return new SkiaCanvas(bitmap);
46}
47
48Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
49 return new SkiaCanvas(skiaCanvas);
50}
51
Stan Ilievf50806a2016-10-24 10:40:39 -040052SkiaCanvas::SkiaCanvas() {}
53
54SkiaCanvas::SkiaCanvas(SkCanvas* canvas)
Mike Reed6acfe162016-11-18 17:21:09 -050055 : mCanvas(canvas) {}
Stan Ilievf50806a2016-10-24 10:40:39 -040056
John Reckc1b33d62015-04-22 09:04:45 -070057SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
Mike Reed6acfe162016-11-18 17:21:09 -050058 mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap));
59 mCanvas = mCanvasOwned.get();
Derek Sollenberger8872b382014-06-23 14:13:53 -040060}
61
Stan Iliev021693b2016-10-17 16:26:15 -040062SkiaCanvas::~SkiaCanvas() {}
63
Derek Sollenbergerc1908132016-07-15 10:28:16 -040064void SkiaCanvas::reset(SkCanvas* skiaCanvas) {
Mike Reed6acfe162016-11-18 17:21:09 -050065 if (mCanvas != skiaCanvas) {
66 mCanvas = skiaCanvas;
67 mCanvasOwned.reset();
68 }
Derek Sollenbergerc1908132016-07-15 10:28:16 -040069 mSaveStack.reset(nullptr);
70 mHighContrastText = false;
71}
72
Derek Sollenberger8872b382014-06-23 14:13:53 -040073// ----------------------------------------------------------------------------
74// Canvas state operations: Replace Bitmap
75// ----------------------------------------------------------------------------
76
77class ClipCopier : public SkCanvas::ClipVisitor {
78public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -070079 explicit ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {}
Derek Sollenberger8872b382014-06-23 14:13:53 -040080
Mike Reed6e49c9f2016-12-02 15:36:59 -050081 virtual void clipRect(const SkRect& rect, SkClipOp op, bool antialias) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040082 m_dstCanvas->clipRect(rect, op, antialias);
83 }
Mike Reed6e49c9f2016-12-02 15:36:59 -050084 virtual void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040085 m_dstCanvas->clipRRect(rrect, op, antialias);
86 }
Mike Reed6e49c9f2016-12-02 15:36:59 -050087 virtual void clipPath(const SkPath& path, SkClipOp op, bool antialias) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040088 m_dstCanvas->clipPath(path, op, antialias);
89 }
90
91private:
92 SkCanvas* m_dstCanvas;
93};
94
John Reckc1b33d62015-04-22 09:04:45 -070095void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
Stan Ilievf50806a2016-10-24 10:40:39 -040096 SkCanvas* newCanvas = new SkCanvas(bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -040097
John Reckc1b33d62015-04-22 09:04:45 -070098 if (!bitmap.isNull()) {
Derek Sollenberger8872b382014-06-23 14:13:53 -040099 // Copy the canvas matrix & clip state.
100 newCanvas->setMatrix(mCanvas->getTotalMatrix());
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400101
Stan Ilievf50806a2016-10-24 10:40:39 -0400102 ClipCopier copier(newCanvas);
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400103 mCanvas->replayClips(&copier);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400104 }
105
Mike Reed6acfe162016-11-18 17:21:09 -0500106 // deletes the previously owned canvas (if any)
107 mCanvasOwned = std::unique_ptr<SkCanvas>(newCanvas);
108 mCanvas = newCanvas;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400109
110 // clean up the old save stack
Stan Ilievf50806a2016-10-24 10:40:39 -0400111 mSaveStack.reset(nullptr);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400112}
113
114// ----------------------------------------------------------------------------
115// Canvas state operations
116// ----------------------------------------------------------------------------
117
118bool SkiaCanvas::isOpaque() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400119 return mCanvas->imageInfo().isOpaque();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400120}
121
122int SkiaCanvas::width() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400123 return mCanvas->imageInfo().width();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400124}
125
126int SkiaCanvas::height() {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400127 return mCanvas->imageInfo().height();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400128}
129
130// ----------------------------------------------------------------------------
131// Canvas state operations: Save (layer)
132// ----------------------------------------------------------------------------
133
134int SkiaCanvas::getSaveCount() const {
135 return mCanvas->getSaveCount();
136}
137
Florin Malitaeecff562015-12-21 10:43:01 -0500138int SkiaCanvas::save(SaveFlags::Flags flags) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400139 int count = mCanvas->save();
140 recordPartialSave(flags);
141 return count;
142}
143
Florin Malita5e271402015-11-04 14:36:02 -0500144// The SkiaCanvas::restore operation layers on the capability to preserve
145// either (or both) the matrix and/or clip state after a SkCanvas::restore
146// operation. It does this by explicitly saving off the clip & matrix state
147// when requested and playing it back after the SkCanvas::restore.
Derek Sollenberger8872b382014-06-23 14:13:53 -0400148void SkiaCanvas::restore() {
Stan Ilievf50806a2016-10-24 10:40:39 -0400149 const auto* rec = this->currentSaveRec();
150 if (!rec) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400151 // Fast path - no record for this frame.
152 mCanvas->restore();
153 return;
154 }
155
Florin Malitaeecff562015-12-21 10:43:01 -0500156 bool preserveMatrix = !(rec->saveFlags & SaveFlags::Matrix);
157 bool preserveClip = !(rec->saveFlags & SaveFlags::Clip);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400158
159 SkMatrix savedMatrix;
160 if (preserveMatrix) {
161 savedMatrix = mCanvas->getTotalMatrix();
162 }
163
Stan Ilievf50806a2016-10-24 10:40:39 -0400164 const size_t clipIndex = rec->clipIndex;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400165
166 mCanvas->restore();
Stan Ilievf50806a2016-10-24 10:40:39 -0400167 mSaveStack->pop_back();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400168
169 if (preserveMatrix) {
170 mCanvas->setMatrix(savedMatrix);
171 }
172
Stan Ilievf50806a2016-10-24 10:40:39 -0400173 if (preserveClip) {
174 this->applyPersistentClips(clipIndex);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400175 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400176}
177
178void SkiaCanvas::restoreToCount(int restoreCount) {
179 while (mCanvas->getSaveCount() > restoreCount) {
180 this->restore();
181 }
182}
183
Florin Malitaeecff562015-12-21 10:43:01 -0500184static inline SkCanvas::SaveLayerFlags layerFlags(SaveFlags::Flags flags) {
185 SkCanvas::SaveLayerFlags layerFlags = 0;
186
Yuqian Li83427ff2016-09-14 11:14:06 -0400187 // We intentionally ignore the SaveFlags::HasAlphaLayer and
188 // SkCanvas::kIsOpaque_SaveLayerFlag flags because HWUI ignores it
189 // and our Android client may use it incorrectly.
190 // In Skia, this flag is purely for performance optimization.
Florin Malitaeecff562015-12-21 10:43:01 -0500191
192 if (!(flags & SaveFlags::ClipToLayer)) {
193 layerFlags |= SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
194 }
195
196 return layerFlags;
197}
198
Derek Sollenberger8872b382014-06-23 14:13:53 -0400199int SkiaCanvas::saveLayer(float left, float top, float right, float bottom,
Florin Malitaeecff562015-12-21 10:43:01 -0500200 const SkPaint* paint, SaveFlags::Flags flags) {
201 const SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
Stan Iliev68885e32016-12-14 11:18:34 -0500202 //always save matrix and clip to match the behaviour of Skia and HWUI pipelines and to ensure
203 //android state tracking behavior matches that of the Skia API (partial save is not supported)
204 const SkCanvas::SaveLayerRec rec(&bounds, paint, layerFlags(flags | SaveFlags::MatrixClip));
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;
371 if (!mCanvas->getClipDeviceBounds(&ibounds)) {
372 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 Sollenbergerc1908132016-07-15 10:28:16 -0400408 SkRRect roundRect;
409 if (path->isRRect(&roundRect)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400410 this->recordClip(roundRect, op);
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400411 mCanvas->clipRRect(roundRect, op);
412 } else {
Stan Ilievf50806a2016-10-24 10:40:39 -0400413 this->recordClip(*path, op);
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400414 mCanvas->clipPath(*path, op);
415 }
Chris Craik5ec6a282015-06-23 15:42:12 -0700416 return !mCanvas->isClipEmpty();
Derek Sollenberger8872b382014-06-23 14:13:53 -0400417}
418
Derek Sollenberger8872b382014-06-23 14:13:53 -0400419// ----------------------------------------------------------------------------
420// Canvas state operations: Filters
421// ----------------------------------------------------------------------------
422
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400423SkDrawFilter* SkiaCanvas::getDrawFilter() {
424 return mCanvas->getDrawFilter();
425}
426
Derek Sollenberger8872b382014-06-23 14:13:53 -0400427void SkiaCanvas::setDrawFilter(SkDrawFilter* drawFilter) {
428 mCanvas->setDrawFilter(drawFilter);
429}
430
431// ----------------------------------------------------------------------------
432// Canvas draw operations
433// ----------------------------------------------------------------------------
434
Mike Reed260ab722016-10-07 15:59:20 -0400435void SkiaCanvas::drawColor(int color, SkBlendMode mode) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400436 mCanvas->drawColor(color, mode);
437}
438
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400439void SkiaCanvas::drawPaint(const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400440 mCanvas->drawPaint(paint);
441}
442
443// ----------------------------------------------------------------------------
444// Canvas draw operations: Geometry
445// ----------------------------------------------------------------------------
446
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400447void SkiaCanvas::drawPoints(const float* points, int count, const SkPaint& paint,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400448 SkCanvas::PointMode mode) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400449 if (CC_UNLIKELY(count < 2 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400450 // convert the floats into SkPoints
451 count >>= 1; // now it is the number of points
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400452 std::unique_ptr<SkPoint[]> pts(new SkPoint[count]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400453 for (int i = 0; i < count; i++) {
454 pts[i].set(points[0], points[1]);
455 points += 2;
456 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400457 mCanvas->drawPoints(mode, count, pts.get(), paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400458}
459
460
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400461void SkiaCanvas::drawPoint(float x, float y, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400462 mCanvas->drawPoint(x, y, paint);
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 this->drawPoints(points, count, paint, SkCanvas::kPoints_PointMode);
467}
468
469void SkiaCanvas::drawLine(float startX, float startY, float stopX, float stopY,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400470 const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400471 mCanvas->drawLine(startX, startY, stopX, stopY, paint);
472}
473
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400474void SkiaCanvas::drawLines(const float* points, int count, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400475 if (CC_UNLIKELY(count < 4 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400476 this->drawPoints(points, count, paint, SkCanvas::kLines_PointMode);
477}
478
479void SkiaCanvas::drawRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400480 const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400481 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400482 mCanvas->drawRectCoords(left, top, right, bottom, paint);
483
484}
485
Derek Sollenberger94394b32015-07-10 09:58:41 -0400486void SkiaCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400487 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
488 mCanvas->drawRegion(region, paint);
Derek Sollenberger94394b32015-07-10 09:58:41 -0400489}
490
Derek Sollenberger8872b382014-06-23 14:13:53 -0400491void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400492 float rx, float ry, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400493 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400494 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
495 mCanvas->drawRoundRect(rect, rx, ry, paint);
496}
497
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400498void SkiaCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400499 if (CC_UNLIKELY(radius <= 0 || PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400500 mCanvas->drawCircle(x, y, radius, paint);
501}
502
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400503void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400504 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400505 SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
506 mCanvas->drawOval(oval, paint);
507}
508
509void SkiaCanvas::drawArc(float left, float top, float right, float bottom,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400510 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400511 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400512 SkRect arc = SkRect::MakeLTRB(left, top, right, bottom);
513 mCanvas->drawArc(arc, startAngle, sweepAngle, useCenter, paint);
514}
515
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400516void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400517 if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400518 SkRect rect;
519 SkRRect roundRect;
520 if (path.isOval(&rect)) {
521 mCanvas->drawOval(rect, paint);
522 } else if (path.isRRect(&roundRect)) {
523 mCanvas->drawRRect(roundRect, paint);
524 } else {
525 mCanvas->drawPath(path, paint);
526 }
Derek Sollenberger8872b382014-06-23 14:13:53 -0400527}
528
529void SkiaCanvas::drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
530 const float* verts, const float* texs, const int* colors,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400531 const uint16_t* indices, int indexCount, const SkPaint& paint) {
Derek Sollenberger8872b382014-06-23 14:13:53 -0400532#ifndef SK_SCALAR_IS_FLOAT
533 SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
534#endif
535 const int ptCount = vertexCount >> 1;
536 mCanvas->drawVertices(vertexMode, ptCount, (SkPoint*)verts, (SkPoint*)texs,
Mike Reedc2f31df2016-10-28 17:21:45 -0400537 (SkColor*)colors, indices, indexCount, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400538}
539
540// ----------------------------------------------------------------------------
541// Canvas draw operations: Bitmaps
542// ----------------------------------------------------------------------------
543
sergeyvaed7f582016-10-14 16:30:21 -0700544void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) {
545 SkBitmap skBitmap;
546 bitmap.getSkBitmap(&skBitmap);
547 mCanvas->drawBitmap(skBitmap, left, top, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400548}
549
sergeyvfc9999502016-10-17 13:07:38 -0700550void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, const SkMatrix& matrix, const SkPaint* paint) {
551 SkBitmap bitmap;
552 hwuiBitmap.getSkBitmap(&bitmap);
Mike Reed6acfe162016-11-18 17:21:09 -0500553 SkAutoCanvasRestore acr(mCanvas, true);
Mike Reed70ffbf92014-12-08 17:03:30 -0500554 mCanvas->concat(matrix);
555 mCanvas->drawBitmap(bitmap, 0, 0, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400556}
557
sergeyvfc9999502016-10-17 13:07:38 -0700558void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400559 float srcRight, float srcBottom, float dstLeft, float dstTop,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400560 float dstRight, float dstBottom, const SkPaint* paint) {
sergeyvfc9999502016-10-17 13:07:38 -0700561 SkBitmap bitmap;
562 hwuiBitmap.getSkBitmap(&bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400563 SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom);
564 SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400565 mCanvas->drawBitmapRect(bitmap, srcRect, dstRect, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400566}
567
sergeyv5fd2a1c2016-10-20 15:04:28 -0700568void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeight,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400569 const float* vertices, const int* colors, const SkPaint* paint) {
sergeyv5fd2a1c2016-10-20 15:04:28 -0700570 SkBitmap bitmap;
571 hwuiBitmap.getSkBitmap(&bitmap);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400572 const int ptCount = (meshWidth + 1) * (meshHeight + 1);
573 const int indexCount = meshWidth * meshHeight * 6;
574
575 /* Our temp storage holds 2 or 3 arrays.
576 texture points [ptCount * sizeof(SkPoint)]
577 optionally vertex points [ptCount * sizeof(SkPoint)] if we need a
578 copy to convert from float to fixed
579 indices [ptCount * sizeof(uint16_t)]
580 */
581 ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
582 storageSize += indexCount * sizeof(uint16_t); // indices[]
583
584
585#ifndef SK_SCALAR_IS_FLOAT
586 SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
587#endif
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400588 std::unique_ptr<char[]> storage(new char[storageSize]);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400589 SkPoint* texs = (SkPoint*)storage.get();
590 uint16_t* indices = (uint16_t*)(texs + ptCount);
591
592 // cons up texture coordinates and indices
593 {
594 const SkScalar w = SkIntToScalar(bitmap.width());
595 const SkScalar h = SkIntToScalar(bitmap.height());
596 const SkScalar dx = w / meshWidth;
597 const SkScalar dy = h / meshHeight;
598
599 SkPoint* texsPtr = texs;
600 SkScalar y = 0;
601 for (int i = 0; i <= meshHeight; i++) {
602 if (i == meshHeight) {
603 y = h; // to ensure numerically we hit h exactly
604 }
605 SkScalar x = 0;
606 for (int j = 0; j < meshWidth; j++) {
607 texsPtr->set(x, y);
608 texsPtr += 1;
609 x += dx;
610 }
611 texsPtr->set(w, y);
612 texsPtr += 1;
613 y += dy;
614 }
615 SkASSERT(texsPtr - texs == ptCount);
616 }
617
618 // cons up indices
619 {
620 uint16_t* indexPtr = indices;
621 int index = 0;
622 for (int i = 0; i < meshHeight; i++) {
623 for (int j = 0; j < meshWidth; j++) {
624 // lower-left triangle
625 *indexPtr++ = index;
626 *indexPtr++ = index + meshWidth + 1;
627 *indexPtr++ = index + meshWidth + 2;
628 // upper-right triangle
629 *indexPtr++ = index;
630 *indexPtr++ = index + meshWidth + 2;
631 *indexPtr++ = index + 1;
632 // bump to the next cell
633 index += 1;
634 }
635 // bump to the next row
636 index += 1;
637 }
638 SkASSERT(indexPtr - indices == indexCount);
639 SkASSERT((char*)indexPtr - (char*)storage.get() == storageSize);
640 }
641
642 // double-check that we have legal indices
643#ifdef SK_DEBUG
644 {
645 for (int i = 0; i < indexCount; i++) {
646 SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
647 }
648 }
649#endif
650
651 // cons-up a shader for the bitmap
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400652 SkPaint tmpPaint;
Derek Sollenberger8872b382014-06-23 14:13:53 -0400653 if (paint) {
654 tmpPaint = *paint;
655 }
Stan Ilievf50806a2016-10-24 10:40:39 -0400656
657 sk_sp<SkImage> image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode);
658 tmpPaint.setShader(image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
Derek Sollenberger8872b382014-06-23 14:13:53 -0400659
660 mCanvas->drawVertices(SkCanvas::kTriangles_VertexMode, ptCount, (SkPoint*)vertices,
Mike Reedc2f31df2016-10-28 17:21:45 -0400661 texs, (const SkColor*)colors, indices,
Derek Sollenberger8872b382014-06-23 14:13:53 -0400662 indexCount, tmpPaint);
663}
664
sergeyv5fd2a1c2016-10-20 15:04:28 -0700665void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk,
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400666 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400667
sergeyv5fd2a1c2016-10-20 15:04:28 -0700668 SkBitmap bitmap;
669 hwuiBitmap.getSkBitmap(&bitmap);
Stan Ilievf50806a2016-10-24 10:40:39 -0400670
671 SkCanvas::Lattice lattice;
Matt Sarett7de73852016-10-25 18:36:39 -0400672 NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height());
Stan Ilievf50806a2016-10-24 10:40:39 -0400673
674 lattice.fFlags = nullptr;
675 int numFlags = 0;
Stan Iliev021693b2016-10-17 16:26:15 -0400676 if (chunk.numColors > 0 && chunk.numColors == NinePatchUtils::NumDistinctRects(lattice)) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400677 // We can expect the framework to give us a color for every distinct rect.
678 // Skia requires a flag for every rect.
679 numFlags = (lattice.fXCount + 1) * (lattice.fYCount + 1);
680 }
681
682 SkAutoSTMalloc<25, SkCanvas::Lattice::Flags> flags(numFlags);
683 if (numFlags > 0) {
Stan Iliev021693b2016-10-17 16:26:15 -0400684 NinePatchUtils::SetLatticeFlags(&lattice, flags.get(), numFlags, chunk);
Stan Ilievf50806a2016-10-24 10:40:39 -0400685 }
686
687 lattice.fBounds = nullptr;
688 SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
689 mCanvas->drawBitmapLattice(bitmap, lattice, dst, paint);
Derek Sollenbergeredca3202015-07-10 13:56:39 -0400690}
691
Doris Liu766431a2016-02-04 22:17:11 +0000692void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
Doris Liu1d8e1942016-03-02 15:16:28 -0800693 vectorDrawable->drawStaging(this);
Doris Liu766431a2016-02-04 22:17:11 +0000694}
695
Derek Sollenberger8872b382014-06-23 14:13:53 -0400696// ----------------------------------------------------------------------------
697// Canvas draw operations: Text
698// ----------------------------------------------------------------------------
699
sergeyvdccca442016-03-21 15:38:21 -0700700void SkiaCanvas::drawGlyphs(const uint16_t* text, const float* positions, int count,
Derek Sollenbergeracb40992014-07-21 15:22:10 -0400701 const SkPaint& paint, float x, float y,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500702 float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
703 float totalAdvance) {
Stan Ilievf50806a2016-10-24 10:40:39 -0400704 if (!text || !positions || count <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
705 // Set align to left for drawing, as we don't want individual
706 // glyphs centered or right-aligned; the offset above takes
707 // care of all alignment.
708 SkPaint paintCopy(paint);
709 paintCopy.setTextAlign(SkPaint::kLeft_Align);
710
711 SkRect bounds = SkRect::MakeLTRB(boundsLeft + x, boundsTop + y,
712 boundsRight + x, boundsBottom + y);
713
714 SkTextBlobBuilder builder;
715 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(paintCopy, count, &bounds);
716 // TODO: we could reduce the number of memcpy's if the this were exposed further up
717 // in the architecture.
718 memcpy(buffer.glyphs, text, count * sizeof(uint16_t));
719 memcpy(buffer.pos, positions, (count << 1) * sizeof(float));
720
721 sk_sp<SkTextBlob> textBlob(builder.make());
722 mCanvas->drawTextBlob(textBlob, 0, 0, paintCopy);
723 drawTextDecorations(x, y, totalAdvance, paintCopy);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400724}
725
Yuqian Liafc221492016-07-18 13:07:42 -0400726void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
727 const SkPaint& paint, const SkPath& path, size_t start, size_t end) {
728 const int N = end - start;
Derek Sollenbergere547dd02016-11-09 11:55:59 -0500729 SkAutoSTMalloc<1024, uint8_t> storage(N * (sizeof(uint16_t) + sizeof(SkRSXform)));
Yuqian Liafc221492016-07-18 13:07:42 -0400730 SkRSXform* xform = (SkRSXform*)storage.get();
731 uint16_t* glyphs = (uint16_t*)(xform + N);
732 SkPathMeasure meas(path, false);
733
734 for (size_t i = start; i < end; i++) {
735 glyphs[i - start] = layout.getGlyphId(i);
736 float x = hOffset + layout.getX(i);
737 float y = vOffset + layout.getY(i);
738
739 SkPoint pos;
740 SkVector tan;
741 if (!meas.getPosTan(x, &pos, &tan)) {
742 pos.set(x, y);
743 tan.set(1, 0);
744 }
745 xform[i - start].fSCos = tan.x();
746 xform[i - start].fSSin = tan.y();
747 xform[i - start].fTx = pos.x() - tan.y() * y;
748 xform[i - start].fTy = pos.y() + tan.x() * y;
749 }
750
751 this->asSkCanvas()->drawTextRSXform(glyphs, sizeof(uint16_t) * N, xform, nullptr, paint);
Derek Sollenberger8872b382014-06-23 14:13:53 -0400752}
753
Derek Sollenberger6f485562015-07-30 10:00:39 -0400754// ----------------------------------------------------------------------------
755// Canvas draw operations: Animations
756// ----------------------------------------------------------------------------
757
Derek Sollenberger6f485562015-07-30 10:00:39 -0400758void SkiaCanvas::drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
759 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
760 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
761 uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400762 sk_sp<uirenderer::skiapipeline::AnimatedRoundRect> drawable(
763 new uirenderer::skiapipeline::AnimatedRoundRect(left, top, right, bottom, rx, ry, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400764 mCanvas->drawDrawable(drawable.get());
765}
766
767void SkiaCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
768 uirenderer::CanvasPropertyPrimitive* radius, uirenderer::CanvasPropertyPaint* paint) {
Stan Iliev021693b2016-10-17 16:26:15 -0400769 sk_sp<uirenderer::skiapipeline::AnimatedCircle> drawable(new uirenderer::skiapipeline::AnimatedCircle(x, y, radius, paint));
Derek Sollenberger6f485562015-07-30 10:00:39 -0400770 mCanvas->drawDrawable(drawable.get());
771}
772
773// ----------------------------------------------------------------------------
774// Canvas draw operations: View System
775// ----------------------------------------------------------------------------
776
Stan Ilievf50806a2016-10-24 10:40:39 -0400777void SkiaCanvas::drawLayer(uirenderer::DeferredLayerUpdater* layerUpdater) {
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400778 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw Layers");
779}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400780
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400781void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
782 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
783}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400784
John Reckcd1c3eb2016-04-14 10:38:54 -0700785void SkiaCanvas::callDrawGLFunction(Functor* functor,
Derek Sollenbergerc1908132016-07-15 10:28:16 -0400786 uirenderer::GlFunctorLifecycleListener* listener) {
787 LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
788}
Derek Sollenberger6f485562015-07-30 10:00:39 -0400789
Derek Sollenberger8872b382014-06-23 14:13:53 -0400790} // namespace android