blob: dc36a2e018157981bf12e576e78ee4b5435d66ce [file] [log] [blame]
John Reck013127b2020-10-29 20:53:51 -04001/*
2 * Copyright (C) 2020 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#pragma once
18
19#include <SkCanvasVirtualEnforcer.h>
20#include <SkNoDrawCanvas.h>
21
Kevin Lubick4e8ce462022-12-01 20:29:16 +000022enum class SkBlendMode;
23
John Reck013127b2020-10-29 20:53:51 -040024namespace android {
25namespace uirenderer {
26namespace test {
27
28class CallCountingCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
29private:
30 int START_MARKER;
31public:
32 CallCountingCanvas() : SkCanvasVirtualEnforcer<SkNoDrawCanvas>(1, 1) {}
33
34 int sumTotalDrawCalls() {
35 // Dirty hack assumes we're nothing but ints between START_MARKET and END_MARKER
36 int* cur = &START_MARKER + 1;
37 int* end = &END_MARKER;
38 int sum = 0;
39 while (cur != end) {
40 sum += *cur;
41 cur++;
42 }
43 return sum;
44 }
45
46 int drawPaintCount = 0;
47 void onDrawPaint(const SkPaint& paint) override {
48 drawPaintCount++;
49 }
50
51 int drawBehindCount = 0;
52 void onDrawBehind(const SkPaint&) override {
53 drawBehindCount++;
54 }
55
56 int drawRectCount = 0;
57 void onDrawRect(const SkRect& rect, const SkPaint& paint) override {
58 drawRectCount++;
59 }
60
61 int drawRRectCount = 0;
62 void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override {
63 drawRRectCount++;
64 }
65
66 int drawDRRectCount = 0;
67 void onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
68 const SkPaint& paint) override {
69 drawDRRectCount++;
70 }
71
72 int drawOvalCount = 0;
73 void onDrawOval(const SkRect& rect, const SkPaint& paint) override {
74 drawOvalCount++;
75 }
76
77 int drawArcCount = 0;
78 void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
79 const SkPaint& paint) override {
80 drawArcCount++;
81 }
82
83 int drawPathCount = 0;
84 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
Nader Jawadfb1e7f12020-11-06 22:49:42 -080085 drawPathCount++;
John Reck013127b2020-10-29 20:53:51 -040086 }
87
88 int drawRegionCount = 0;
89 void onDrawRegion(const SkRegion& region, const SkPaint& paint) override {
90 drawRegionCount++;
91 }
92
93 int drawTextBlobCount = 0;
94 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
95 const SkPaint& paint) override {
96 drawTextBlobCount++;
97 }
98
99 int drawPatchCount = 0;
100 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
101 const SkPoint texCoords[4], SkBlendMode mode,
102 const SkPaint& paint) override {
103 drawPatchCount++;
104 }
105
106 int drawPoints = 0;
107 void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
108 const SkPaint& paint) override {
109 drawPoints++;
110 }
111
112 int drawImageCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500113 void onDrawImage2(const SkImage* image, SkScalar dx, SkScalar dy, const SkSamplingOptions&,
John Reck013127b2020-10-29 20:53:51 -0400114 const SkPaint* paint) override {
115 drawImageCount++;
116 }
117
118 int drawImageRectCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500119 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
120 const SkPaint*, SkCanvas::SrcRectConstraint) override {
John Reck013127b2020-10-29 20:53:51 -0400121 drawImageRectCount++;
122 }
123
John Reck013127b2020-10-29 20:53:51 -0400124 int drawImageLatticeCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500125 void onDrawImageLattice2(const SkImage* image, const SkCanvas::Lattice& lattice,
126 const SkRect& dst, SkFilterMode, const SkPaint* paint) override {
John Reck013127b2020-10-29 20:53:51 -0400127 drawImageLatticeCount++;
128 }
129
130 int drawAtlasCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500131 void onDrawAtlas2(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
132 const SkColor colors[], int count, SkBlendMode mode, const SkSamplingOptions&,
133 const SkRect* cull, const SkPaint* paint) override {
John Reck013127b2020-10-29 20:53:51 -0400134 drawAtlasCount++;
135 }
136
137 int drawAnnotationCount = 0;
138 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override {
139 drawAnnotationCount++;
140 }
141
142 int drawShadowRecCount = 0;
143 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override {
144 drawShadowRecCount++;
145 }
146
147 int drawDrawableCount = 0;
148 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override {
149 drawDrawableCount++;
150 }
151
152 int drawPictureCount = 0;
153 void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
154 const SkPaint* paint) override {
155 drawPictureCount++;
156 }
157
Nader Jawadfb1e7f12020-11-06 22:49:42 -0800158 int drawVerticesCount = 0;
159 void onDrawVerticesObject (const SkVertices *vertices, SkBlendMode mode,
160 const SkPaint &paint) override {
161 drawVerticesCount++;
162 }
163
John Reck013127b2020-10-29 20:53:51 -0400164private:
165 int END_MARKER;
166};
167
168} /* namespace test */
169} /* namespace uirenderer */
Mike Reed4efe0be2021-01-03 20:57:35 -0500170} /* namespace android */