John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 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 | |
Kevin Lubick | 4e8ce46 | 2022-12-01 20:29:16 +0000 | [diff] [blame] | 22 | enum class SkBlendMode; |
| 23 | |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | namespace test { |
| 27 | |
| 28 | class CallCountingCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> { |
| 29 | private: |
| 30 | int START_MARKER; |
| 31 | public: |
| 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 Jawad | fb1e7f1 | 2020-11-06 22:49:42 -0800 | [diff] [blame] | 85 | drawPathCount++; |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 86 | } |
| 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 Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 112 | int drawImageRectCount = 0; |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 113 | void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, |
| 114 | const SkPaint*, SkCanvas::SrcRectConstraint) override { |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 115 | drawImageRectCount++; |
| 116 | } |
| 117 | |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 118 | int drawImageLatticeCount = 0; |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 119 | void onDrawImageLattice2(const SkImage* image, const SkCanvas::Lattice& lattice, |
| 120 | const SkRect& dst, SkFilterMode, const SkPaint* paint) override { |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 121 | drawImageLatticeCount++; |
| 122 | } |
| 123 | |
| 124 | int drawAtlasCount = 0; |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 125 | 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 Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 128 | 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 Jawad | fb1e7f1 | 2020-11-06 22:49:42 -0800 | [diff] [blame] | 152 | int drawVerticesCount = 0; |
| 153 | void onDrawVerticesObject (const SkVertices *vertices, SkBlendMode mode, |
| 154 | const SkPaint &paint) override { |
| 155 | drawVerticesCount++; |
| 156 | } |
| 157 | |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 158 | private: |
| 159 | int END_MARKER; |
| 160 | }; |
| 161 | |
| 162 | } /* namespace test */ |
| 163 | } /* namespace uirenderer */ |
Mike Reed | 4efe0be | 2021-01-03 20:57:35 -0500 | [diff] [blame] | 164 | } /* namespace android */ |