Debian Codegraph @

libs/hwui/tests/common/CallCountingCanvas.h

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