blob: df5f04f9904e0b2cd08af5f7fc88480795f13bee [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
John Reck013127b2020-10-29 20:53:51 -0400112 int drawImageRectCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500113 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
114 const SkPaint*, SkCanvas::SrcRectConstraint) override {
John Reck013127b2020-10-29 20:53:51 -0400115 drawImageRectCount++;
116 }
117
John Reck013127b2020-10-29 20:53:51 -0400118 int drawImageLatticeCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500119 void onDrawImageLattice2(const SkImage* image, const SkCanvas::Lattice& lattice,
120 const SkRect& dst, SkFilterMode, const SkPaint* paint) override {
John Reck013127b2020-10-29 20:53:51 -0400121 drawImageLatticeCount++;
122 }
123
124 int drawAtlasCount = 0;
Mike Reed2d1279f2020-12-30 09:57:25 -0500125 void onDrawAtlas2(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
126 const SkColor colors[], int count, SkBlendMode mode, const SkSamplingOptions&,
127 const SkRect* cull, const SkPaint* paint) override {
John Reck013127b2020-10-29 20:53:51 -0400128 drawAtlasCount++;
129 }
130
131 int drawAnnotationCount = 0;
132 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override {
133 drawAnnotationCount++;
134 }
135
136 int drawShadowRecCount = 0;
137 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override {
138 drawShadowRecCount++;
139 }
140
141 int drawDrawableCount = 0;
142 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override {
143 drawDrawableCount++;
144 }
145
146 int drawPictureCount = 0;
147 void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
148 const SkPaint* paint) override {
149 drawPictureCount++;
150 }
151
Nader Jawadfb1e7f12020-11-06 22:49:42 -0800152 int drawVerticesCount = 0;
153 void onDrawVerticesObject (const SkVertices *vertices, SkBlendMode mode,
154 const SkPaint &paint) override {
155 drawVerticesCount++;
156 }
157
John Reck013127b2020-10-29 20:53:51 -0400158private:
159 int END_MARKER;
160};
161
162} /* namespace test */
163} /* namespace uirenderer */
Mike Reed4efe0be2021-01-03 20:57:35 -0500164} /* namespace android */