1 /*
2 * Copyright (C) 2018 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
17 #include "RecordingCanvas.h"
18 #include <hwui/Paint.h>
19
20 #include <GrRecordingContext.h>
21
22 #include <experimental/type_traits>
23
24 #include "SkAndroidFrameworkUtils.h"
25 #include "SkCanvas.h"
26 #include "SkCanvasPriv.h"
27 #include "SkColor.h"
28 #include "SkData.h"
29 #include "SkDrawShadowInfo.h"
30 #include "SkImage.h"
31 #include "SkImageFilter.h"
32 #include "SkLatticeIter.h"
33 #include "SkMath.h"
34 #include "SkPicture.h"
35 #include "SkRSXform.h"
36 #include "SkRegion.h"
37 #include "SkTextBlob.h"
38 #include "SkVertices.h"
39 #include "VectorDrawable.h"
40 #include "pipeline/skia/AnimatedDrawables.h"
41 #include "pipeline/skia/FunctorDrawable.h"
42 #ifdef __ANDROID__
43 #include "renderthread/CanvasContext.h"
44 #endif
45
46 namespace android {
47 namespace uirenderer {
48
49 #ifndef SKLITEDL_PAGE
50 #define SKLITEDL_PAGE 4096
51 #endif
52
53 // A stand-in for an optional SkRect which was not set, e.g. bounds for a saveLayer().
54 static const SkRect kUnset = {SK_ScalarInfinity, 0, 0, 0};
maybe_unset(const SkRect & r)55 static const SkRect* maybe_unset(const SkRect& r) {
56 return r.left() == SK_ScalarInfinity ? nullptr : &r;
57 }
58
59 // copy_v(dst, src,n, src,n, ...) copies an arbitrary number of typed srcs into dst.
copy_v(void * dst)60 static void copy_v(void* dst) {}
61
62 template <typename S, typename... Rest>
copy_v(void * dst,const S * src,int n,Rest &&...rest)63 static void copy_v(void* dst, const S* src, int n, Rest&&... rest) {
64 SkASSERTF(((uintptr_t)dst & (alignof(S) - 1)) == 0,
65 "Expected %p to be aligned for at least %zu bytes.", dst, alignof(S));
66 sk_careful_memcpy(dst, src, n * sizeof(S));
67 copy_v(SkTAddOffset<void>(dst, n * sizeof(S)), std::forward<Rest>(rest)...);
68 }
69
70 // Helper for getting back at arrays which have been copy_v'd together after an Op.
71 template <typename D, typename T>
pod(const T * op,size_t offset=0)72 static const D* pod(const T* op, size_t offset = 0) {
73 return SkTAddOffset<const D>(op + 1, offset);
74 }
75
76 namespace {
77
78 #define X(T) T,
79 enum class Type : uint8_t {
80 #include "DisplayListOps.in"
81 };
82 #undef X
83
84 struct Op {
85 uint32_t type : 8;
86 uint32_t skip : 24;
87 };
88 static_assert(sizeof(Op) == 4, "");
89
90 struct Flush final : Op {
91 static const auto kType = Type::Flush;
drawandroid::uirenderer::__anon6687b4140111::Flush92 void draw(SkCanvas* c, const SkMatrix&) const { c->flush(); }
93 };
94
95 struct Save final : Op {
96 static const auto kType = Type::Save;
drawandroid::uirenderer::__anon6687b4140111::Save97 void draw(SkCanvas* c, const SkMatrix&) const { c->save(); }
98 };
99 struct Restore final : Op {
100 static const auto kType = Type::Restore;
drawandroid::uirenderer::__anon6687b4140111::Restore101 void draw(SkCanvas* c, const SkMatrix&) const { c->restore(); }
102 };
103 struct SaveLayer final : Op {
104 static const auto kType = Type::SaveLayer;
SaveLayerandroid::uirenderer::__anon6687b4140111::SaveLayer105 SaveLayer(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
106 SkCanvas::SaveLayerFlags flags) {
107 if (bounds) {
108 this->bounds = *bounds;
109 }
110 if (paint) {
111 this->paint = *paint;
112 }
113 this->backdrop = sk_ref_sp(backdrop);
114 this->flags = flags;
115 }
116 SkRect bounds = kUnset;
117 SkPaint paint;
118 sk_sp<const SkImageFilter> backdrop;
119 SkCanvas::SaveLayerFlags flags;
drawandroid::uirenderer::__anon6687b4140111::SaveLayer120 void draw(SkCanvas* c, const SkMatrix&) const {
121 c->saveLayer({maybe_unset(bounds), &paint, backdrop.get(), flags});
122 }
123 };
124 struct SaveBehind final : Op {
125 static const auto kType = Type::SaveBehind;
SaveBehindandroid::uirenderer::__anon6687b4140111::SaveBehind126 SaveBehind(const SkRect* subset) {
127 if (subset) { this->subset = *subset; }
128 }
129 SkRect subset = kUnset;
drawandroid::uirenderer::__anon6687b4140111::SaveBehind130 void draw(SkCanvas* c, const SkMatrix&) const {
131 SkAndroidFrameworkUtils::SaveBehind(c, &subset);
132 }
133 };
134
135 struct Concat final : Op {
136 static const auto kType = Type::Concat;
Concatandroid::uirenderer::__anon6687b4140111::Concat137 Concat(const SkM44& matrix) : matrix(matrix) {}
138 SkM44 matrix;
drawandroid::uirenderer::__anon6687b4140111::Concat139 void draw(SkCanvas* c, const SkMatrix&) const { c->concat(matrix); }
140 };
141 struct SetMatrix final : Op {
142 static const auto kType = Type::SetMatrix;
SetMatrixandroid::uirenderer::__anon6687b4140111::SetMatrix143 SetMatrix(const SkM44& matrix) : matrix(matrix) {}
144 SkM44 matrix;
drawandroid::uirenderer::__anon6687b4140111::SetMatrix145 void draw(SkCanvas* c, const SkMatrix& original) const {
146 c->setMatrix(SkM44(original) * matrix);
147 }
148 };
149 struct Scale final : Op {
150 static const auto kType = Type::Scale;
Scaleandroid::uirenderer::__anon6687b4140111::Scale151 Scale(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {}
152 SkScalar sx, sy;
drawandroid::uirenderer::__anon6687b4140111::Scale153 void draw(SkCanvas* c, const SkMatrix&) const { c->scale(sx, sy); }
154 };
155 struct Translate final : Op {
156 static const auto kType = Type::Translate;
Translateandroid::uirenderer::__anon6687b4140111::Translate157 Translate(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {}
158 SkScalar dx, dy;
drawandroid::uirenderer::__anon6687b4140111::Translate159 void draw(SkCanvas* c, const SkMatrix&) const { c->translate(dx, dy); }
160 };
161
162 struct ClipPath final : Op {
163 static const auto kType = Type::ClipPath;
ClipPathandroid::uirenderer::__anon6687b4140111::ClipPath164 ClipPath(const SkPath& path, SkClipOp op, bool aa) : path(path), op(op), aa(aa) {}
165 SkPath path;
166 SkClipOp op;
167 bool aa;
drawandroid::uirenderer::__anon6687b4140111::ClipPath168 void draw(SkCanvas* c, const SkMatrix&) const { c->clipPath(path, op, aa); }
169 };
170 struct ClipRect final : Op {
171 static const auto kType = Type::ClipRect;
ClipRectandroid::uirenderer::__anon6687b4140111::ClipRect172 ClipRect(const SkRect& rect, SkClipOp op, bool aa) : rect(rect), op(op), aa(aa) {}
173 SkRect rect;
174 SkClipOp op;
175 bool aa;
drawandroid::uirenderer::__anon6687b4140111::ClipRect176 void draw(SkCanvas* c, const SkMatrix&) const { c->clipRect(rect, op, aa); }
177 };
178 struct ClipRRect final : Op {
179 static const auto kType = Type::ClipRRect;
ClipRRectandroid::uirenderer::__anon6687b4140111::ClipRRect180 ClipRRect(const SkRRect& rrect, SkClipOp op, bool aa) : rrect(rrect), op(op), aa(aa) {}
181 SkRRect rrect;
182 SkClipOp op;
183 bool aa;
drawandroid::uirenderer::__anon6687b4140111::ClipRRect184 void draw(SkCanvas* c, const SkMatrix&) const { c->clipRRect(rrect, op, aa); }
185 };
186 struct ClipRegion final : Op {
187 static const auto kType = Type::ClipRegion;
ClipRegionandroid::uirenderer::__anon6687b4140111::ClipRegion188 ClipRegion(const SkRegion& region, SkClipOp op) : region(region), op(op) {}
189 SkRegion region;
190 SkClipOp op;
drawandroid::uirenderer::__anon6687b4140111::ClipRegion191 void draw(SkCanvas* c, const SkMatrix&) const { c->clipRegion(region, op); }
192 };
193 struct ResetClip final : Op {
194 static const auto kType = Type::ResetClip;
ResetClipandroid::uirenderer::__anon6687b4140111::ResetClip195 ResetClip() {}
drawandroid::uirenderer::__anon6687b4140111::ResetClip196 void draw(SkCanvas* c, const SkMatrix&) const { SkAndroidFrameworkUtils::ResetClip(c); }
197 };
198
199 struct DrawPaint final : Op {
200 static const auto kType = Type::DrawPaint;
DrawPaintandroid::uirenderer::__anon6687b4140111::DrawPaint201 DrawPaint(const SkPaint& paint) : paint(paint) {}
202 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawPaint203 void draw(SkCanvas* c, const SkMatrix&) const { c->drawPaint(paint); }
204 };
205 struct DrawBehind final : Op {
206 static const auto kType = Type::DrawBehind;
DrawBehindandroid::uirenderer::__anon6687b4140111::DrawBehind207 DrawBehind(const SkPaint& paint) : paint(paint) {}
208 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawBehind209 void draw(SkCanvas* c, const SkMatrix&) const { SkCanvasPriv::DrawBehind(c, paint); }
210 };
211 struct DrawPath final : Op {
212 static const auto kType = Type::DrawPath;
DrawPathandroid::uirenderer::__anon6687b4140111::DrawPath213 DrawPath(const SkPath& path, const SkPaint& paint) : path(path), paint(paint) {}
214 SkPath path;
215 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawPath216 void draw(SkCanvas* c, const SkMatrix&) const { c->drawPath(path, paint); }
217 };
218 struct DrawRect final : Op {
219 static const auto kType = Type::DrawRect;
DrawRectandroid::uirenderer::__anon6687b4140111::DrawRect220 DrawRect(const SkRect& rect, const SkPaint& paint) : rect(rect), paint(paint) {}
221 SkRect rect;
222 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawRect223 void draw(SkCanvas* c, const SkMatrix&) const { c->drawRect(rect, paint); }
224 };
225 struct DrawRegion final : Op {
226 static const auto kType = Type::DrawRegion;
DrawRegionandroid::uirenderer::__anon6687b4140111::DrawRegion227 DrawRegion(const SkRegion& region, const SkPaint& paint) : region(region), paint(paint) {}
228 SkRegion region;
229 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawRegion230 void draw(SkCanvas* c, const SkMatrix&) const { c->drawRegion(region, paint); }
231 };
232 struct DrawOval final : Op {
233 static const auto kType = Type::DrawOval;
DrawOvalandroid::uirenderer::__anon6687b4140111::DrawOval234 DrawOval(const SkRect& oval, const SkPaint& paint) : oval(oval), paint(paint) {}
235 SkRect oval;
236 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawOval237 void draw(SkCanvas* c, const SkMatrix&) const { c->drawOval(oval, paint); }
238 };
239 struct DrawArc final : Op {
240 static const auto kType = Type::DrawArc;
DrawArcandroid::uirenderer::__anon6687b4140111::DrawArc241 DrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
242 const SkPaint& paint)
243 : oval(oval)
244 , startAngle(startAngle)
245 , sweepAngle(sweepAngle)
246 , useCenter(useCenter)
247 , paint(paint) {}
248 SkRect oval;
249 SkScalar startAngle;
250 SkScalar sweepAngle;
251 bool useCenter;
252 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawArc253 void draw(SkCanvas* c, const SkMatrix&) const {
254 c->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
255 }
256 };
257 struct DrawRRect final : Op {
258 static const auto kType = Type::DrawRRect;
DrawRRectandroid::uirenderer::__anon6687b4140111::DrawRRect259 DrawRRect(const SkRRect& rrect, const SkPaint& paint) : rrect(rrect), paint(paint) {}
260 SkRRect rrect;
261 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawRRect262 void draw(SkCanvas* c, const SkMatrix&) const { c->drawRRect(rrect, paint); }
263 };
264 struct DrawDRRect final : Op {
265 static const auto kType = Type::DrawDRRect;
DrawDRRectandroid::uirenderer::__anon6687b4140111::DrawDRRect266 DrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint)
267 : outer(outer), inner(inner), paint(paint) {}
268 SkRRect outer, inner;
269 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawDRRect270 void draw(SkCanvas* c, const SkMatrix&) const { c->drawDRRect(outer, inner, paint); }
271 };
272
273 struct DrawAnnotation final : Op {
274 static const auto kType = Type::DrawAnnotation;
DrawAnnotationandroid::uirenderer::__anon6687b4140111::DrawAnnotation275 DrawAnnotation(const SkRect& rect, SkData* value) : rect(rect), value(sk_ref_sp(value)) {}
276 SkRect rect;
277 sk_sp<SkData> value;
drawandroid::uirenderer::__anon6687b4140111::DrawAnnotation278 void draw(SkCanvas* c, const SkMatrix&) const {
279 c->drawAnnotation(rect, pod<char>(this), value.get());
280 }
281 };
282 struct DrawDrawable final : Op {
283 static const auto kType = Type::DrawDrawable;
DrawDrawableandroid::uirenderer::__anon6687b4140111::DrawDrawable284 DrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) : drawable(sk_ref_sp(drawable)) {
285 if (matrix) {
286 this->matrix = *matrix;
287 }
288 }
289 sk_sp<SkDrawable> drawable;
290 SkMatrix matrix = SkMatrix::I();
291 // It is important that we call drawable->draw(c) here instead of c->drawDrawable(drawable).
292 // Drawables are mutable and in cases, like RenderNodeDrawable, are not expected to produce the
293 // same content if retained outside the duration of the frame. Therefore we resolve
294 // them now and do not allow the canvas to take a reference to the drawable and potentially
295 // keep it alive for longer than the frames duration (e.g. SKP serialization).
drawandroid::uirenderer::__anon6687b4140111::DrawDrawable296 void draw(SkCanvas* c, const SkMatrix&) const { drawable->draw(c, &matrix); }
297 };
298 struct DrawPicture final : Op {
299 static const auto kType = Type::DrawPicture;
DrawPictureandroid::uirenderer::__anon6687b4140111::DrawPicture300 DrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint)
301 : picture(sk_ref_sp(picture)) {
302 if (matrix) {
303 this->matrix = *matrix;
304 }
305 if (paint) {
306 this->paint = *paint;
307 has_paint = true;
308 }
309 }
310 sk_sp<const SkPicture> picture;
311 SkMatrix matrix = SkMatrix::I();
312 SkPaint paint;
313 bool has_paint = false; // TODO: why is a default paint not the same?
drawandroid::uirenderer::__anon6687b4140111::DrawPicture314 void draw(SkCanvas* c, const SkMatrix&) const {
315 c->drawPicture(picture.get(), &matrix, has_paint ? &paint : nullptr);
316 }
317 };
318
319 struct DrawImage final : Op {
320 static const auto kType = Type::DrawImage;
DrawImageandroid::uirenderer::__anon6687b4140111::DrawImage321 DrawImage(sk_sp<const SkImage>&& image, SkScalar x, SkScalar y,
322 const SkSamplingOptions& sampling, const SkPaint* paint, BitmapPalette palette)
323 : image(std::move(image)), x(x), y(y), sampling(sampling), palette(palette) {
324 if (paint) {
325 this->paint = *paint;
326 }
327 }
328 sk_sp<const SkImage> image;
329 SkScalar x, y;
330 SkSamplingOptions sampling;
331 SkPaint paint;
332 BitmapPalette palette;
drawandroid::uirenderer::__anon6687b4140111::DrawImage333 void draw(SkCanvas* c, const SkMatrix&) const {
334 c->drawImage(image.get(), x, y, sampling, &paint);
335 }
336 };
337 struct DrawImageRect final : Op {
338 static const auto kType = Type::DrawImageRect;
DrawImageRectandroid::uirenderer::__anon6687b4140111::DrawImageRect339 DrawImageRect(sk_sp<const SkImage>&& image, const SkRect* src, const SkRect& dst,
340 const SkSamplingOptions& sampling, const SkPaint* paint,
341 SkCanvas::SrcRectConstraint constraint, BitmapPalette palette)
342 : image(std::move(image)), dst(dst), sampling(sampling), constraint(constraint)
343 , palette(palette) {
344 this->src = src ? *src : SkRect::MakeIWH(this->image->width(), this->image->height());
345 if (paint) {
346 this->paint = *paint;
347 }
348 }
349 sk_sp<const SkImage> image;
350 SkRect src, dst;
351 SkSamplingOptions sampling;
352 SkPaint paint;
353 SkCanvas::SrcRectConstraint constraint;
354 BitmapPalette palette;
drawandroid::uirenderer::__anon6687b4140111::DrawImageRect355 void draw(SkCanvas* c, const SkMatrix&) const {
356 c->drawImageRect(image.get(), src, dst, sampling, &paint, constraint);
357 }
358 };
359 struct DrawImageLattice final : Op {
360 static const auto kType = Type::DrawImageLattice;
DrawImageLatticeandroid::uirenderer::__anon6687b4140111::DrawImageLattice361 DrawImageLattice(sk_sp<const SkImage>&& image, int xs, int ys, int fs, const SkIRect& src,
362 const SkRect& dst, SkFilterMode filter, const SkPaint* paint,
363 BitmapPalette palette)
364 : image(std::move(image))
365 , xs(xs)
366 , ys(ys)
367 , fs(fs)
368 , src(src)
369 , dst(dst)
370 , filter(filter)
371 , palette(palette) {
372 if (paint) {
373 this->paint = *paint;
374 }
375 }
376 sk_sp<const SkImage> image;
377 int xs, ys, fs;
378 SkIRect src;
379 SkRect dst;
380 SkFilterMode filter;
381 SkPaint paint;
382 BitmapPalette palette;
drawandroid::uirenderer::__anon6687b4140111::DrawImageLattice383 void draw(SkCanvas* c, const SkMatrix&) const {
384 auto xdivs = pod<int>(this, 0), ydivs = pod<int>(this, xs * sizeof(int));
385 auto colors = (0 == fs) ? nullptr : pod<SkColor>(this, (xs + ys) * sizeof(int));
386 auto flags =
387 (0 == fs) ? nullptr : pod<SkCanvas::Lattice::RectType>(
388 this, (xs + ys) * sizeof(int) + fs * sizeof(SkColor));
389 c->drawImageLattice(image.get(), {xdivs, ydivs, flags, xs, ys, &src, colors}, dst,
390 filter, &paint);
391 }
392 };
393
394 struct DrawTextBlob final : Op {
395 static const auto kType = Type::DrawTextBlob;
DrawTextBlobandroid::uirenderer::__anon6687b4140111::DrawTextBlob396 DrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint)
397 : blob(sk_ref_sp(blob)), x(x), y(y), paint(paint), drawTextBlobMode(gDrawTextBlobMode) {}
398 sk_sp<const SkTextBlob> blob;
399 SkScalar x, y;
400 SkPaint paint;
401 DrawTextBlobMode drawTextBlobMode;
drawandroid::uirenderer::__anon6687b4140111::DrawTextBlob402 void draw(SkCanvas* c, const SkMatrix&) const { c->drawTextBlob(blob.get(), x, y, paint); }
403 };
404
405 struct DrawPatch final : Op {
406 static const auto kType = Type::DrawPatch;
DrawPatchandroid::uirenderer::__anon6687b4140111::DrawPatch407 DrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texs[4],
408 SkBlendMode bmode, const SkPaint& paint)
409 : xfermode(bmode), paint(paint) {
410 copy_v(this->cubics, cubics, 12);
411 if (colors) {
412 copy_v(this->colors, colors, 4);
413 has_colors = true;
414 }
415 if (texs) {
416 copy_v(this->texs, texs, 4);
417 has_texs = true;
418 }
419 }
420 SkPoint cubics[12];
421 SkColor colors[4];
422 SkPoint texs[4];
423 SkBlendMode xfermode;
424 SkPaint paint;
425 bool has_colors = false;
426 bool has_texs = false;
drawandroid::uirenderer::__anon6687b4140111::DrawPatch427 void draw(SkCanvas* c, const SkMatrix&) const {
428 c->drawPatch(cubics, has_colors ? colors : nullptr, has_texs ? texs : nullptr, xfermode,
429 paint);
430 }
431 };
432 struct DrawPoints final : Op {
433 static const auto kType = Type::DrawPoints;
DrawPointsandroid::uirenderer::__anon6687b4140111::DrawPoints434 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPaint& paint)
435 : mode(mode), count(count), paint(paint) {}
436 SkCanvas::PointMode mode;
437 size_t count;
438 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawPoints439 void draw(SkCanvas* c, const SkMatrix&) const {
440 if (paint.isAntiAlias()) {
441 c->drawPoints(mode, count, pod<SkPoint>(this), paint);
442 } else {
443 c->save();
444 #ifdef __ANDROID__
445 auto pixelSnap = renderthread::CanvasContext::getActiveContext()->getPixelSnapMatrix();
446 auto transform = c->getLocalToDevice();
447 transform.postConcat(pixelSnap);
448 c->setMatrix(transform);
449 #endif
450 c->drawPoints(mode, count, pod<SkPoint>(this), paint);
451 c->restore();
452 }
453 }
454 };
455 struct DrawVertices final : Op {
456 static const auto kType = Type::DrawVertices;
DrawVerticesandroid::uirenderer::__anon6687b4140111::DrawVertices457 DrawVertices(const SkVertices* v, SkBlendMode m, const SkPaint& p)
458 : vertices(sk_ref_sp(const_cast<SkVertices*>(v))), mode(m), paint(p) {}
459 sk_sp<SkVertices> vertices;
460 SkBlendMode mode;
461 SkPaint paint;
drawandroid::uirenderer::__anon6687b4140111::DrawVertices462 void draw(SkCanvas* c, const SkMatrix&) const {
463 c->drawVertices(vertices, mode, paint);
464 }
465 };
466 struct DrawAtlas final : Op {
467 static const auto kType = Type::DrawAtlas;
DrawAtlasandroid::uirenderer::__anon6687b4140111::DrawAtlas468 DrawAtlas(const SkImage* atlas, int count, SkBlendMode mode, const SkSamplingOptions& sampling,
469 const SkRect* cull, const SkPaint* paint, bool has_colors)
470 : atlas(sk_ref_sp(atlas)), count(count), mode(mode), sampling(sampling)
471 , has_colors(has_colors) {
472 if (cull) {
473 this->cull = *cull;
474 }
475 if (paint) {
476 this->paint = *paint;
477 }
478 }
479 sk_sp<const SkImage> atlas;
480 int count;
481 SkBlendMode mode;
482 SkSamplingOptions sampling;
483 SkRect cull = kUnset;
484 SkPaint paint;
485 bool has_colors;
drawandroid::uirenderer::__anon6687b4140111::DrawAtlas486 void draw(SkCanvas* c, const SkMatrix&) const {
487 auto xforms = pod<SkRSXform>(this, 0);
488 auto texs = pod<SkRect>(this, count * sizeof(SkRSXform));
489 auto colors = has_colors ? pod<SkColor>(this, count * (sizeof(SkRSXform) + sizeof(SkRect)))
490 : nullptr;
491 c->drawAtlas(atlas.get(), xforms, texs, colors, count, mode, sampling, maybe_unset(cull),
492 &paint);
493 }
494 };
495 struct DrawShadowRec final : Op {
496 static const auto kType = Type::DrawShadowRec;
DrawShadowRecandroid::uirenderer::__anon6687b4140111::DrawShadowRec497 DrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) : fPath(path), fRec(rec) {}
498 SkPath fPath;
499 SkDrawShadowRec fRec;
drawandroid::uirenderer::__anon6687b4140111::DrawShadowRec500 void draw(SkCanvas* c, const SkMatrix&) const { c->private_draw_shadow_rec(fPath, fRec); }
501 };
502
503 struct DrawVectorDrawable final : Op {
504 static const auto kType = Type::DrawVectorDrawable;
DrawVectorDrawableandroid::uirenderer::__anon6687b4140111::DrawVectorDrawable505 DrawVectorDrawable(VectorDrawableRoot* tree)
506 : mRoot(tree)
507 , mBounds(tree->stagingProperties().getBounds())
508 , palette(tree->computePalette()) {
509 // Recording, so use staging properties
510 tree->getPaintFor(&paint, tree->stagingProperties());
511 }
512
drawandroid::uirenderer::__anon6687b4140111::DrawVectorDrawable513 void draw(SkCanvas* canvas, const SkMatrix&) const {
514 mRoot->draw(canvas, mBounds, paint);
515 }
516
517 sp<VectorDrawableRoot> mRoot;
518 SkRect mBounds;
519 Paint paint;
520 BitmapPalette palette;
521 };
522
523 struct DrawRippleDrawable final : Op {
524 static const auto kType = Type::DrawRippleDrawable;
DrawRippleDrawableandroid::uirenderer::__anon6687b4140111::DrawRippleDrawable525 DrawRippleDrawable(const skiapipeline::RippleDrawableParams& params) : mParams(params) {}
526
drawandroid::uirenderer::__anon6687b4140111::DrawRippleDrawable527 void draw(SkCanvas* canvas, const SkMatrix&) const {
528 skiapipeline::AnimatedRippleDrawable::draw(canvas, mParams);
529 }
530
531 skiapipeline::RippleDrawableParams mParams;
532 };
533
534 struct DrawWebView final : Op {
535 static const auto kType = Type::DrawWebView;
DrawWebViewandroid::uirenderer::__anon6687b4140111::DrawWebView536 DrawWebView(skiapipeline::FunctorDrawable* drawable) : drawable(sk_ref_sp(drawable)) {}
537 sk_sp<skiapipeline::FunctorDrawable> drawable;
538 // We can't invoke SkDrawable::draw directly, because VkFunctorDrawable expects
539 // SkDrawable::onSnapGpuDrawHandler callback instead of SkDrawable::onDraw.
540 // SkCanvas::drawDrawable/SkGpuDevice::drawDrawable has the logic to invoke
541 // onSnapGpuDrawHandler.
542 private:
543 // Unfortunately WebView does not have complex clip information serialized, and we only perform
544 // best-effort stencil fill for GLES. So for Vulkan we create an intermediate layer if the
545 // canvas clip is complex.
needsCompositedLayerandroid::uirenderer::__anon6687b4140111::DrawWebView546 static bool needsCompositedLayer(SkCanvas* c) {
547 if (Properties::getRenderPipelineType() != RenderPipelineType::SkiaVulkan) {
548 return false;
549 }
550 SkRegion clipRegion;
551 // WebView's rasterizer has access to simple clips, so for Vulkan we only need to check if
552 // the clip is more complex than a rectangle.
553 c->temporary_internal_getRgnClip(&clipRegion);
554 return clipRegion.isComplex();
555 }
556
557 mutable SkImageInfo mLayerImageInfo;
558 mutable sk_sp<SkSurface> mLayerSurface = nullptr;
559
560 public:
drawandroid::uirenderer::__anon6687b4140111::DrawWebView561 void draw(SkCanvas* c, const SkMatrix&) const {
562 if (needsCompositedLayer(c)) {
563 // What we do now is create an offscreen surface, sized by the clip bounds.
564 // We won't apply a clip while drawing - clipping will be performed when compositing the
565 // surface back onto the original canvas. Note also that we're not using saveLayer
566 // because the webview functor still doesn't respect the canvas clip stack.
567 const SkIRect deviceBounds = c->getDeviceClipBounds();
568 if (mLayerSurface == nullptr || c->imageInfo() != mLayerImageInfo) {
569 GrRecordingContext* directContext = c->recordingContext();
570 mLayerImageInfo =
571 c->imageInfo().makeWH(deviceBounds.width(), deviceBounds.height());
572 mLayerSurface = SkSurface::MakeRenderTarget(directContext, SkBudgeted::kYes,
573 mLayerImageInfo, 0,
574 kTopLeft_GrSurfaceOrigin, nullptr);
575 }
576
577 SkCanvas* layerCanvas = mLayerSurface->getCanvas();
578
579 SkAutoCanvasRestore(layerCanvas, true);
580 layerCanvas->clear(SK_ColorTRANSPARENT);
581
582 // Preserve the transform from the original canvas, but now the clip rectangle is
583 // anchored at the origin so we need to transform the clipped content to the origin.
584 SkM44 mat4(c->getLocalToDevice());
585 mat4.postTranslate(-deviceBounds.fLeft, -deviceBounds.fTop);
586 layerCanvas->concat(mat4);
587 layerCanvas->drawDrawable(drawable.get());
588
589 SkAutoCanvasRestore acr(c, true);
590
591 // Temporarily use an identity transform, because this is just blitting to the parent
592 // canvas with an offset.
593 SkMatrix invertedMatrix;
594 if (!c->getTotalMatrix().invert(&invertedMatrix)) {
595 ALOGW("Unable to extract invert canvas matrix; aborting VkFunctor draw");
596 return;
597 }
598 c->concat(invertedMatrix);
599 mLayerSurface->draw(c, deviceBounds.fLeft, deviceBounds.fTop);
600 } else {
601 c->drawDrawable(drawable.get());
602 }
603 }
604 };
605 }
606
607 template <typename T, typename... Args>
push(size_t pod,Args &&...args)608 void* DisplayListData::push(size_t pod, Args&&... args) {
609 size_t skip = SkAlignPtr(sizeof(T) + pod);
610 SkASSERT(skip < (1 << 24));
611 if (fUsed + skip > fReserved) {
612 static_assert(SkIsPow2(SKLITEDL_PAGE), "This math needs updating for non-pow2.");
613 // Next greater multiple of SKLITEDL_PAGE.
614 fReserved = (fUsed + skip + SKLITEDL_PAGE) & ~(SKLITEDL_PAGE - 1);
615 fBytes.realloc(fReserved);
616 LOG_ALWAYS_FATAL_IF(fBytes.get() == nullptr, "realloc(%zd) failed", fReserved);
617 }
618 SkASSERT(fUsed + skip <= fReserved);
619 auto op = (T*)(fBytes.get() + fUsed);
620 fUsed += skip;
621 new (op) T{std::forward<Args>(args)...};
622 op->type = (uint32_t)T::kType;
623 op->skip = skip;
624 return op + 1;
625 }
626
627 template <typename Fn, typename... Args>
map(const Fn fns[],Args...args) const628 inline void DisplayListData::map(const Fn fns[], Args... args) const {
629 auto end = fBytes.get() + fUsed;
630 for (const uint8_t* ptr = fBytes.get(); ptr < end;) {
631 auto op = (const Op*)ptr;
632 auto type = op->type;
633 auto skip = op->skip;
634 if (auto fn = fns[type]) { // We replace no-op functions with nullptrs
635 fn(op, args...); // to avoid the overhead of a pointless call.
636 }
637 ptr += skip;
638 }
639 }
640
flush()641 void DisplayListData::flush() {
642 this->push<Flush>(0);
643 }
644
save()645 void DisplayListData::save() {
646 this->push<Save>(0);
647 }
restore()648 void DisplayListData::restore() {
649 this->push<Restore>(0);
650 }
saveLayer(const SkRect * bounds,const SkPaint * paint,const SkImageFilter * backdrop,SkCanvas::SaveLayerFlags flags)651 void DisplayListData::saveLayer(const SkRect* bounds, const SkPaint* paint,
652 const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags) {
653 this->push<SaveLayer>(0, bounds, paint, backdrop, flags);
654 }
655
saveBehind(const SkRect * subset)656 void DisplayListData::saveBehind(const SkRect* subset) {
657 this->push<SaveBehind>(0, subset);
658 }
659
concat(const SkM44 & m)660 void DisplayListData::concat(const SkM44& m) {
661 this->push<Concat>(0, m);
662 }
setMatrix(const SkM44 & matrix)663 void DisplayListData::setMatrix(const SkM44& matrix) {
664 this->push<SetMatrix>(0, matrix);
665 }
scale(SkScalar sx,SkScalar sy)666 void DisplayListData::scale(SkScalar sx, SkScalar sy) {
667 this->push<Scale>(0, sx, sy);
668 }
translate(SkScalar dx,SkScalar dy)669 void DisplayListData::translate(SkScalar dx, SkScalar dy) {
670 this->push<Translate>(0, dx, dy);
671 }
672
clipPath(const SkPath & path,SkClipOp op,bool aa)673 void DisplayListData::clipPath(const SkPath& path, SkClipOp op, bool aa) {
674 this->push<ClipPath>(0, path, op, aa);
675 }
clipRect(const SkRect & rect,SkClipOp op,bool aa)676 void DisplayListData::clipRect(const SkRect& rect, SkClipOp op, bool aa) {
677 this->push<ClipRect>(0, rect, op, aa);
678 }
clipRRect(const SkRRect & rrect,SkClipOp op,bool aa)679 void DisplayListData::clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) {
680 this->push<ClipRRect>(0, rrect, op, aa);
681 }
clipRegion(const SkRegion & region,SkClipOp op)682 void DisplayListData::clipRegion(const SkRegion& region, SkClipOp op) {
683 this->push<ClipRegion>(0, region, op);
684 }
resetClip()685 void DisplayListData::resetClip() {
686 this->push<ResetClip>(0);
687 }
688
drawPaint(const SkPaint & paint)689 void DisplayListData::drawPaint(const SkPaint& paint) {
690 this->push<DrawPaint>(0, paint);
691 }
drawBehind(const SkPaint & paint)692 void DisplayListData::drawBehind(const SkPaint& paint) {
693 this->push<DrawBehind>(0, paint);
694 }
drawPath(const SkPath & path,const SkPaint & paint)695 void DisplayListData::drawPath(const SkPath& path, const SkPaint& paint) {
696 this->push<DrawPath>(0, path, paint);
697 }
drawRect(const SkRect & rect,const SkPaint & paint)698 void DisplayListData::drawRect(const SkRect& rect, const SkPaint& paint) {
699 this->push<DrawRect>(0, rect, paint);
700 }
drawRegion(const SkRegion & region,const SkPaint & paint)701 void DisplayListData::drawRegion(const SkRegion& region, const SkPaint& paint) {
702 this->push<DrawRegion>(0, region, paint);
703 }
drawOval(const SkRect & oval,const SkPaint & paint)704 void DisplayListData::drawOval(const SkRect& oval, const SkPaint& paint) {
705 this->push<DrawOval>(0, oval, paint);
706 }
drawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)707 void DisplayListData::drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
708 bool useCenter, const SkPaint& paint) {
709 this->push<DrawArc>(0, oval, startAngle, sweepAngle, useCenter, paint);
710 }
drawRRect(const SkRRect & rrect,const SkPaint & paint)711 void DisplayListData::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
712 this->push<DrawRRect>(0, rrect, paint);
713 }
drawDRRect(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)714 void DisplayListData::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
715 this->push<DrawDRRect>(0, outer, inner, paint);
716 }
717
drawAnnotation(const SkRect & rect,const char * key,SkData * value)718 void DisplayListData::drawAnnotation(const SkRect& rect, const char* key, SkData* value) {
719 size_t bytes = strlen(key) + 1;
720 void* pod = this->push<DrawAnnotation>(bytes, rect, value);
721 copy_v(pod, key, bytes);
722 }
drawDrawable(SkDrawable * drawable,const SkMatrix * matrix)723 void DisplayListData::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
724 this->push<DrawDrawable>(0, drawable, matrix);
725 }
drawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)726 void DisplayListData::drawPicture(const SkPicture* picture, const SkMatrix* matrix,
727 const SkPaint* paint) {
728 this->push<DrawPicture>(0, picture, matrix, paint);
729 }
drawImage(sk_sp<const SkImage> image,SkScalar x,SkScalar y,const SkSamplingOptions & sampling,const SkPaint * paint,BitmapPalette palette)730 void DisplayListData::drawImage(sk_sp<const SkImage> image, SkScalar x, SkScalar y,
731 const SkSamplingOptions& sampling, const SkPaint* paint,
732 BitmapPalette palette) {
733 this->push<DrawImage>(0, std::move(image), x, y, sampling, paint, palette);
734 }
drawImageRect(sk_sp<const SkImage> image,const SkRect * src,const SkRect & dst,const SkSamplingOptions & sampling,const SkPaint * paint,SkCanvas::SrcRectConstraint constraint,BitmapPalette palette)735 void DisplayListData::drawImageRect(sk_sp<const SkImage> image, const SkRect* src,
736 const SkRect& dst, const SkSamplingOptions& sampling,
737 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint,
738 BitmapPalette palette) {
739 this->push<DrawImageRect>(0, std::move(image), src, dst, sampling, paint, constraint, palette);
740 }
drawImageLattice(sk_sp<const SkImage> image,const SkCanvas::Lattice & lattice,const SkRect & dst,SkFilterMode filter,const SkPaint * paint,BitmapPalette palette)741 void DisplayListData::drawImageLattice(sk_sp<const SkImage> image, const SkCanvas::Lattice& lattice,
742 const SkRect& dst, SkFilterMode filter, const SkPaint* paint,
743 BitmapPalette palette) {
744 int xs = lattice.fXCount, ys = lattice.fYCount;
745 int fs = lattice.fRectTypes ? (xs + 1) * (ys + 1) : 0;
746 size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::RectType) +
747 fs * sizeof(SkColor);
748 SkASSERT(lattice.fBounds);
749 void* pod = this->push<DrawImageLattice>(bytes, std::move(image), xs, ys, fs, *lattice.fBounds,
750 dst, filter, paint, palette);
751 copy_v(pod, lattice.fXDivs, xs, lattice.fYDivs, ys, lattice.fColors, fs, lattice.fRectTypes,
752 fs);
753 }
754
drawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)755 void DisplayListData::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
756 const SkPaint& paint) {
757 this->push<DrawTextBlob>(0, blob, x, y, paint);
758 mHasText = true;
759 }
760
drawRippleDrawable(const skiapipeline::RippleDrawableParams & params)761 void DisplayListData::drawRippleDrawable(const skiapipeline::RippleDrawableParams& params) {
762 this->push<DrawRippleDrawable>(0, params);
763 }
764
drawPatch(const SkPoint points[12],const SkColor colors[4],const SkPoint texs[4],SkBlendMode bmode,const SkPaint & paint)765 void DisplayListData::drawPatch(const SkPoint points[12], const SkColor colors[4],
766 const SkPoint texs[4], SkBlendMode bmode, const SkPaint& paint) {
767 this->push<DrawPatch>(0, points, colors, texs, bmode, paint);
768 }
drawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint points[],const SkPaint & paint)769 void DisplayListData::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint points[],
770 const SkPaint& paint) {
771 void* pod = this->push<DrawPoints>(count * sizeof(SkPoint), mode, count, paint);
772 copy_v(pod, points, count);
773 }
drawVertices(const SkVertices * vert,SkBlendMode mode,const SkPaint & paint)774 void DisplayListData::drawVertices(const SkVertices* vert, SkBlendMode mode, const SkPaint& paint) {
775 this->push<DrawVertices>(0, vert, mode, paint);
776 }
drawAtlas(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode xfermode,const SkSamplingOptions & sampling,const SkRect * cull,const SkPaint * paint)777 void DisplayListData::drawAtlas(const SkImage* atlas, const SkRSXform xforms[], const SkRect texs[],
778 const SkColor colors[], int count, SkBlendMode xfermode,
779 const SkSamplingOptions& sampling, const SkRect* cull,
780 const SkPaint* paint) {
781 size_t bytes = count * (sizeof(SkRSXform) + sizeof(SkRect));
782 if (colors) {
783 bytes += count * sizeof(SkColor);
784 }
785 void* pod = this->push<DrawAtlas>(bytes, atlas, count, xfermode, sampling, cull, paint,
786 colors != nullptr);
787 copy_v(pod, xforms, count, texs, count, colors, colors ? count : 0);
788 }
drawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)789 void DisplayListData::drawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
790 this->push<DrawShadowRec>(0, path, rec);
791 }
drawVectorDrawable(VectorDrawableRoot * tree)792 void DisplayListData::drawVectorDrawable(VectorDrawableRoot* tree) {
793 this->push<DrawVectorDrawable>(0, tree);
794 }
drawWebView(skiapipeline::FunctorDrawable * drawable)795 void DisplayListData::drawWebView(skiapipeline::FunctorDrawable* drawable) {
796 this->push<DrawWebView>(0, drawable);
797 }
798
799 typedef void (*draw_fn)(const void*, SkCanvas*, const SkMatrix&);
800 typedef void (*void_fn)(const void*);
801 typedef void (*color_transform_fn)(const void*, ColorTransform);
802
803 // All ops implement draw().
804 #define X(T) \
805 [](const void* op, SkCanvas* c, const SkMatrix& original) { \
806 ((const T*)op)->draw(c, original); \
807 },
808 static const draw_fn draw_fns[] = {
809 #include "DisplayListOps.in"
810 };
811 #undef X
812
813 // Most state ops (matrix, clip, save, restore) have a trivial destructor.
814 #define X(T) \
815 !std::is_trivially_destructible<T>::value ? [](const void* op) { ((const T*)op)->~T(); } \
816 : (void_fn) nullptr,
817
818 static const void_fn dtor_fns[] = {
819 #include "DisplayListOps.in"
820 };
821 #undef X
822
draw(SkCanvas * canvas) const823 void DisplayListData::draw(SkCanvas* canvas) const {
824 SkAutoCanvasRestore acr(canvas, false);
825 this->map(draw_fns, canvas, canvas->getTotalMatrix());
826 }
827
~DisplayListData()828 DisplayListData::~DisplayListData() {
829 this->reset();
830 }
831
reset()832 void DisplayListData::reset() {
833 this->map(dtor_fns);
834
835 // Leave fBytes and fReserved alone.
836 fUsed = 0;
837 }
838
839 template <class T>
840 using has_paint_helper = decltype(std::declval<T>().paint);
841
842 template <class T>
843 constexpr bool has_paint = std::experimental::is_detected_v<has_paint_helper, T>;
844
845 template <class T>
846 using has_palette_helper = decltype(std::declval<T>().palette);
847
848 template <class T>
849 constexpr bool has_palette = std::experimental::is_detected_v<has_palette_helper, T>;
850
851 template <class T>
colorTransformForOp()852 constexpr color_transform_fn colorTransformForOp() {
853 if
854 constexpr(has_paint<T> && has_palette<T>) {
855 // It's a bitmap
856 return [](const void* opRaw, ColorTransform transform) {
857 // TODO: We should be const. Or not. Or just use a different map
858 // Unclear, but this is the quick fix
859 const T* op = reinterpret_cast<const T*>(opRaw);
860 const SkPaint* paint = &op->paint;
861 transformPaint(transform, const_cast<SkPaint*>(paint), op->palette);
862 };
863 }
864 else if
865 constexpr(has_paint<T>) {
866 return [](const void* opRaw, ColorTransform transform) {
867 // TODO: We should be const. Or not. Or just use a different map
868 // Unclear, but this is the quick fix
869 const T* op = reinterpret_cast<const T*>(opRaw);
870 const SkPaint* paint = &op->paint;
871 transformPaint(transform, const_cast<SkPaint*>(paint));
872 };
873 }
874 else {
875 return nullptr;
876 }
877 }
878
879 template<>
colorTransformForOp()880 constexpr color_transform_fn colorTransformForOp<DrawTextBlob>() {
881 return [](const void *opRaw, ColorTransform transform) {
882 const DrawTextBlob *op = reinterpret_cast<const DrawTextBlob*>(opRaw);
883 switch (op->drawTextBlobMode) {
884 case DrawTextBlobMode::HctOutline:
885 const_cast<SkPaint&>(op->paint).setColor(SK_ColorBLACK);
886 break;
887 case DrawTextBlobMode::HctInner:
888 const_cast<SkPaint&>(op->paint).setColor(SK_ColorWHITE);
889 break;
890 default:
891 transformPaint(transform, const_cast<SkPaint*>(&(op->paint)));
892 break;
893 }
894 };
895 }
896
897 template <>
colorTransformForOp()898 constexpr color_transform_fn colorTransformForOp<DrawRippleDrawable>() {
899 return [](const void* opRaw, ColorTransform transform) {
900 const DrawRippleDrawable* op = reinterpret_cast<const DrawRippleDrawable*>(opRaw);
901 // Ripple drawable needs to contrast against the background, so we need the inverse color.
902 SkColor color = transformColorInverse(transform, op->mParams.color);
903 const_cast<DrawRippleDrawable*>(op)->mParams.color = color;
904 };
905 }
906
907 #define X(T) colorTransformForOp<T>(),
908 static const color_transform_fn color_transform_fns[] = {
909 #include "DisplayListOps.in"
910 };
911 #undef X
912
applyColorTransform(ColorTransform transform)913 void DisplayListData::applyColorTransform(ColorTransform transform) {
914 this->map(color_transform_fns, transform);
915 }
916
RecordingCanvas()917 RecordingCanvas::RecordingCanvas() : INHERITED(1, 1), fDL(nullptr) {}
918
reset(DisplayListData * dl,const SkIRect & bounds)919 void RecordingCanvas::reset(DisplayListData* dl, const SkIRect& bounds) {
920 this->resetCanvas(bounds.right(), bounds.bottom());
921 fDL = dl;
922 mClipMayBeComplex = false;
923 mSaveCount = mComplexSaveCount = 0;
924 }
925
onNewSurface(const SkImageInfo &,const SkSurfaceProps &)926 sk_sp<SkSurface> RecordingCanvas::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
927 return nullptr;
928 }
929
onFlush()930 void RecordingCanvas::onFlush() {
931 fDL->flush();
932 }
933
willSave()934 void RecordingCanvas::willSave() {
935 mSaveCount++;
936 fDL->save();
937 }
getSaveLayerStrategy(const SaveLayerRec & rec)938 SkCanvas::SaveLayerStrategy RecordingCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
939 fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags);
940 return SkCanvas::kNoLayer_SaveLayerStrategy;
941 }
willRestore()942 void RecordingCanvas::willRestore() {
943 mSaveCount--;
944 if (mSaveCount < mComplexSaveCount) {
945 mClipMayBeComplex = false;
946 mComplexSaveCount = 0;
947 }
948 fDL->restore();
949 }
950
onDoSaveBehind(const SkRect * subset)951 bool RecordingCanvas::onDoSaveBehind(const SkRect* subset) {
952 fDL->saveBehind(subset);
953 return false;
954 }
955
didConcat44(const SkM44 & m)956 void RecordingCanvas::didConcat44(const SkM44& m) {
957 fDL->concat(m);
958 }
didSetM44(const SkM44 & matrix)959 void RecordingCanvas::didSetM44(const SkM44& matrix) {
960 fDL->setMatrix(matrix);
961 }
didScale(SkScalar sx,SkScalar sy)962 void RecordingCanvas::didScale(SkScalar sx, SkScalar sy) {
963 fDL->scale(sx, sy);
964 }
didTranslate(SkScalar dx,SkScalar dy)965 void RecordingCanvas::didTranslate(SkScalar dx, SkScalar dy) {
966 fDL->translate(dx, dy);
967 }
968
onClipRect(const SkRect & rect,SkClipOp op,ClipEdgeStyle style)969 void RecordingCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle style) {
970 fDL->clipRect(rect, op, style == kSoft_ClipEdgeStyle);
971 if (!getTotalMatrix().isScaleTranslate()) {
972 setClipMayBeComplex();
973 }
974 this->INHERITED::onClipRect(rect, op, style);
975 }
onClipRRect(const SkRRect & rrect,SkClipOp op,ClipEdgeStyle style)976 void RecordingCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle style) {
977 if (rrect.getType() > SkRRect::kRect_Type || !getTotalMatrix().isScaleTranslate()) {
978 setClipMayBeComplex();
979 }
980 fDL->clipRRect(rrect, op, style == kSoft_ClipEdgeStyle);
981 this->INHERITED::onClipRRect(rrect, op, style);
982 }
onClipPath(const SkPath & path,SkClipOp op,ClipEdgeStyle style)983 void RecordingCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle style) {
984 setClipMayBeComplex();
985 fDL->clipPath(path, op, style == kSoft_ClipEdgeStyle);
986 this->INHERITED::onClipPath(path, op, style);
987 }
onClipRegion(const SkRegion & region,SkClipOp op)988 void RecordingCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
989 if (region.isComplex() || !getTotalMatrix().isScaleTranslate()) {
990 setClipMayBeComplex();
991 }
992 fDL->clipRegion(region, op);
993 this->INHERITED::onClipRegion(region, op);
994 }
onResetClip()995 void RecordingCanvas::onResetClip() {
996 // This is part of "replace op" emulation, but rely on the following intersection
997 // clip to potentially mark the clip as complex. If we are already complex, we do
998 // not reset the complexity so that we don't break the contract that no higher
999 // save point has a complex clip when "not complex".
1000 fDL->resetClip();
1001 this->INHERITED::onResetClip();
1002 }
1003
onDrawPaint(const SkPaint & paint)1004 void RecordingCanvas::onDrawPaint(const SkPaint& paint) {
1005 fDL->drawPaint(paint);
1006 }
onDrawBehind(const SkPaint & paint)1007 void RecordingCanvas::onDrawBehind(const SkPaint& paint) {
1008 fDL->drawBehind(paint);
1009 }
onDrawPath(const SkPath & path,const SkPaint & paint)1010 void RecordingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
1011 fDL->drawPath(path, paint);
1012 }
onDrawRect(const SkRect & rect,const SkPaint & paint)1013 void RecordingCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
1014 fDL->drawRect(rect, paint);
1015 }
onDrawRegion(const SkRegion & region,const SkPaint & paint)1016 void RecordingCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
1017 fDL->drawRegion(region, paint);
1018 }
onDrawOval(const SkRect & oval,const SkPaint & paint)1019 void RecordingCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
1020 fDL->drawOval(oval, paint);
1021 }
onDrawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)1022 void RecordingCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
1023 bool useCenter, const SkPaint& paint) {
1024 fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
1025 }
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)1026 void RecordingCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
1027 fDL->drawRRect(rrect, paint);
1028 }
onDrawDRRect(const SkRRect & out,const SkRRect & in,const SkPaint & paint)1029 void RecordingCanvas::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
1030 fDL->drawDRRect(out, in, paint);
1031 }
1032
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)1033 void RecordingCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
1034 fDL->drawDrawable(drawable, matrix);
1035 }
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)1036 void RecordingCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
1037 const SkPaint* paint) {
1038 fDL->drawPicture(picture, matrix, paint);
1039 }
onDrawAnnotation(const SkRect & rect,const char key[],SkData * val)1040 void RecordingCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
1041 fDL->drawAnnotation(rect, key, val);
1042 }
1043
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)1044 void RecordingCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
1045 const SkPaint& paint) {
1046 fDL->drawTextBlob(blob, x, y, paint);
1047 }
1048
drawRippleDrawable(const skiapipeline::RippleDrawableParams & params)1049 void RecordingCanvas::drawRippleDrawable(const skiapipeline::RippleDrawableParams& params) {
1050 fDL->drawRippleDrawable(params);
1051 }
1052
drawImage(const sk_sp<SkImage> & image,SkScalar x,SkScalar y,const SkSamplingOptions & sampling,const SkPaint * paint,BitmapPalette palette)1053 void RecordingCanvas::drawImage(const sk_sp<SkImage>& image, SkScalar x, SkScalar y,
1054 const SkSamplingOptions& sampling, const SkPaint* paint,
1055 BitmapPalette palette) {
1056 fDL->drawImage(image, x, y, sampling, paint, palette);
1057 }
1058
drawImageRect(const sk_sp<SkImage> & image,const SkRect & src,const SkRect & dst,const SkSamplingOptions & sampling,const SkPaint * paint,SrcRectConstraint constraint,BitmapPalette palette)1059 void RecordingCanvas::drawImageRect(const sk_sp<SkImage>& image, const SkRect& src,
1060 const SkRect& dst, const SkSamplingOptions& sampling,
1061 const SkPaint* paint, SrcRectConstraint constraint,
1062 BitmapPalette palette) {
1063 fDL->drawImageRect(image, &src, dst, sampling, paint, constraint, palette);
1064 }
1065
drawImageLattice(const sk_sp<SkImage> & image,const Lattice & lattice,const SkRect & dst,SkFilterMode filter,const SkPaint * paint,BitmapPalette palette)1066 void RecordingCanvas::drawImageLattice(const sk_sp<SkImage>& image, const Lattice& lattice,
1067 const SkRect& dst, SkFilterMode filter, const SkPaint* paint,
1068 BitmapPalette palette) {
1069 if (!image || dst.isEmpty()) {
1070 return;
1071 }
1072
1073 SkIRect bounds;
1074 Lattice latticePlusBounds = lattice;
1075 if (!latticePlusBounds.fBounds) {
1076 bounds = SkIRect::MakeWH(image->width(), image->height());
1077 latticePlusBounds.fBounds = &bounds;
1078 }
1079
1080 if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) {
1081 fDL->drawImageLattice(image, latticePlusBounds, dst, filter, paint, palette);
1082 } else {
1083 SkSamplingOptions sampling(filter, SkMipmapMode::kNone);
1084 fDL->drawImageRect(image, nullptr, dst, sampling, paint, kFast_SrcRectConstraint, palette);
1085 }
1086 }
1087
onDrawImage2(const SkImage * img,SkScalar x,SkScalar y,const SkSamplingOptions & sampling,const SkPaint * paint)1088 void RecordingCanvas::onDrawImage2(const SkImage* img, SkScalar x, SkScalar y,
1089 const SkSamplingOptions& sampling, const SkPaint* paint) {
1090 fDL->drawImage(sk_ref_sp(img), x, y, sampling, paint, BitmapPalette::Unknown);
1091 }
1092
onDrawImageRect2(const SkImage * img,const SkRect & src,const SkRect & dst,const SkSamplingOptions & sampling,const SkPaint * paint,SrcRectConstraint constraint)1093 void RecordingCanvas::onDrawImageRect2(const SkImage* img, const SkRect& src, const SkRect& dst,
1094 const SkSamplingOptions& sampling, const SkPaint* paint,
1095 SrcRectConstraint constraint) {
1096 fDL->drawImageRect(sk_ref_sp(img), &src, dst, sampling, paint, constraint,
1097 BitmapPalette::Unknown);
1098 }
1099
onDrawImageLattice2(const SkImage * img,const SkCanvas::Lattice & lattice,const SkRect & dst,SkFilterMode filter,const SkPaint * paint)1100 void RecordingCanvas::onDrawImageLattice2(const SkImage* img, const SkCanvas::Lattice& lattice,
1101 const SkRect& dst, SkFilterMode filter,
1102 const SkPaint* paint) {
1103 fDL->drawImageLattice(sk_ref_sp(img), lattice, dst, filter, paint, BitmapPalette::Unknown);
1104 }
1105
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)1106 void RecordingCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
1107 const SkPoint texCoords[4], SkBlendMode bmode,
1108 const SkPaint& paint) {
1109 fDL->drawPatch(cubics, colors, texCoords, bmode, paint);
1110 }
onDrawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)1111 void RecordingCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
1112 const SkPaint& paint) {
1113 fDL->drawPoints(mode, count, pts, paint);
1114 }
onDrawVerticesObject(const SkVertices * vertices,SkBlendMode mode,const SkPaint & paint)1115 void RecordingCanvas::onDrawVerticesObject(const SkVertices* vertices,
1116 SkBlendMode mode, const SkPaint& paint) {
1117 fDL->drawVertices(vertices, mode, paint);
1118 }
onDrawAtlas2(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode bmode,const SkSamplingOptions & sampling,const SkRect * cull,const SkPaint * paint)1119 void RecordingCanvas::onDrawAtlas2(const SkImage* atlas, const SkRSXform xforms[],
1120 const SkRect texs[], const SkColor colors[], int count,
1121 SkBlendMode bmode, const SkSamplingOptions& sampling,
1122 const SkRect* cull, const SkPaint* paint) {
1123 fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, sampling, cull, paint);
1124 }
onDrawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)1125 void RecordingCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
1126 fDL->drawShadowRec(path, rec);
1127 }
1128
drawVectorDrawable(VectorDrawableRoot * tree)1129 void RecordingCanvas::drawVectorDrawable(VectorDrawableRoot* tree) {
1130 fDL->drawVectorDrawable(tree);
1131 }
1132
drawWebView(skiapipeline::FunctorDrawable * drawable)1133 void RecordingCanvas::drawWebView(skiapipeline::FunctorDrawable* drawable) {
1134 fDL->drawWebView(drawable);
1135 }
1136
1137 } // namespace uirenderer
1138 } // namespace android
1139