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