/src/skia/tools/gpu/GrTest.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2013 Google Inc. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #include "include/core/SkString.h" |
9 | | #include "include/gpu/GrBackendSurface.h" |
10 | | #include "include/gpu/GrContextOptions.h" |
11 | | #include "include/gpu/GrRecordingContext.h" |
12 | | #include "include/private/base/SkTo.h" |
13 | | #include "src/base/SkMathPriv.h" |
14 | | #include "src/base/SkRandom.h" |
15 | | #include "src/gpu/ganesh/GrClip.h" |
16 | | #include "src/gpu/ganesh/GrDirectContextPriv.h" |
17 | | #include "src/gpu/ganesh/GrDrawOpAtlas.h" |
18 | | #include "src/gpu/ganesh/GrDrawingManager.h" |
19 | | #include "src/gpu/ganesh/GrGpu.h" |
20 | | #include "src/gpu/ganesh/GrGpuResourceCacheAccess.h" |
21 | | #include "src/gpu/ganesh/GrMemoryPool.h" |
22 | | #include "src/gpu/ganesh/GrRecordingContextPriv.h" |
23 | | #include "src/gpu/ganesh/GrRenderTargetProxy.h" |
24 | | #include "src/gpu/ganesh/GrResourceCache.h" |
25 | | #include "src/gpu/ganesh/GrSemaphore.h" |
26 | | #include "src/gpu/ganesh/GrTexture.h" |
27 | | #include "src/gpu/ganesh/SkGr.h" |
28 | | #include "src/gpu/ganesh/SurfaceDrawContext.h" |
29 | | #include "src/gpu/ganesh/image/SkImage_Ganesh.h" |
30 | | #include "src/text/gpu/StrikeCache.h" |
31 | | #include "src/text/gpu/TextBlobRedrawCoordinator.h" |
32 | | |
33 | | #include <algorithm> |
34 | | |
35 | | ////////////////////////////////////////////////////////////////////////////// |
36 | | |
37 | | #define DRAW_OP_TEST_EXTERN(Op) \ |
38 | | extern GrOp::Owner Op##__Test( \ |
39 | | GrPaint&&, SkRandom*, GrRecordingContext*, skgpu::ganesh::SurfaceDrawContext*, int) |
40 | 0 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
41 | | |
42 | | DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
43 | | DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); |
44 | | DRAW_OP_TEST_EXTERN(AAHairlineOp); |
45 | | DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
46 | | DRAW_OP_TEST_EXTERN(AtlasTextOp); |
47 | | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
48 | | DRAW_OP_TEST_EXTERN(ButtCapDashedCircleOp); |
49 | | DRAW_OP_TEST_EXTERN(CircleOp); |
50 | | #endif |
51 | | DRAW_OP_TEST_EXTERN(DashOpImpl); |
52 | | DRAW_OP_TEST_EXTERN(DefaultPathOp); |
53 | | DRAW_OP_TEST_EXTERN(DrawAtlasOp); |
54 | | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
55 | | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
56 | | DRAW_OP_TEST_EXTERN(EllipseOp); |
57 | | #endif |
58 | | DRAW_OP_TEST_EXTERN(FillRectOp); |
59 | | DRAW_OP_TEST_EXTERN(NonAALatticeOp); |
60 | | DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
61 | | DRAW_OP_TEST_EXTERN(RegionOp); |
62 | | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
63 | | DRAW_OP_TEST_EXTERN(RRectOp); |
64 | | #endif |
65 | | DRAW_OP_TEST_EXTERN(ShadowRRectOp); |
66 | | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
67 | | DRAW_OP_TEST_EXTERN(SmallPathOp); |
68 | | #endif |
69 | | DRAW_OP_TEST_EXTERN(TextureOpImpl); |
70 | | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
71 | | DRAW_OP_TEST_EXTERN(TriangulatingPathOp); |
72 | | #endif |
73 | | |
74 | 0 | void GrDrawRandomOp(SkRandom* random, skgpu::ganesh::SurfaceDrawContext* sdc, GrPaint&& paint) { |
75 | 0 | auto rContext = sdc->recordingContext(); |
76 | 0 | using MakeDrawOpFn = GrOp::Owner(GrPaint&&, |
77 | 0 | SkRandom*, |
78 | 0 | GrRecordingContext*, |
79 | 0 | skgpu::ganesh::SurfaceDrawContext*, |
80 | 0 | int numSamples); |
81 | 0 | static constexpr MakeDrawOpFn* gFactories[] = { |
82 | 0 | DRAW_OP_TEST_ENTRY(AAConvexPathOp), |
83 | 0 | DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp), |
84 | 0 | DRAW_OP_TEST_ENTRY(AAHairlineOp), |
85 | 0 | DRAW_OP_TEST_ENTRY(AAStrokeRectOp), |
86 | 0 | DRAW_OP_TEST_ENTRY(AtlasTextOp), |
87 | 0 | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
88 | 0 | DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp), |
89 | 0 | DRAW_OP_TEST_ENTRY(CircleOp), |
90 | 0 | #endif |
91 | 0 | DRAW_OP_TEST_ENTRY(DashOpImpl), |
92 | 0 | DRAW_OP_TEST_ENTRY(DefaultPathOp), |
93 | 0 | DRAW_OP_TEST_ENTRY(DrawAtlasOp), |
94 | 0 | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
95 | 0 | DRAW_OP_TEST_ENTRY(DIEllipseOp), |
96 | 0 | DRAW_OP_TEST_ENTRY(EllipseOp), |
97 | 0 | #endif |
98 | 0 | DRAW_OP_TEST_ENTRY(FillRectOp), |
99 | 0 | DRAW_OP_TEST_ENTRY(NonAALatticeOp), |
100 | 0 | DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), |
101 | 0 | DRAW_OP_TEST_ENTRY(RegionOp), |
102 | 0 | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
103 | 0 | DRAW_OP_TEST_ENTRY(RRectOp), |
104 | 0 | #endif |
105 | 0 | DRAW_OP_TEST_ENTRY(ShadowRRectOp), |
106 | 0 | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
107 | 0 | DRAW_OP_TEST_ENTRY(SmallPathOp), |
108 | 0 | #endif |
109 | 0 | DRAW_OP_TEST_ENTRY(TextureOpImpl), |
110 | 0 | #if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
111 | 0 | DRAW_OP_TEST_ENTRY(TriangulatingPathOp), |
112 | 0 | #endif |
113 | 0 | }; |
114 | |
|
115 | 0 | static constexpr size_t kTotal = std::size(gFactories); |
116 | 0 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
117 | 0 | auto op = gFactories[index](std::move(paint), |
118 | 0 | random, |
119 | 0 | rContext, |
120 | 0 | sdc, |
121 | 0 | sdc->numSamples()); |
122 | | |
123 | | // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the |
124 | | // render target context. |
125 | 0 | if (op) { |
126 | 0 | sdc->addDrawOp(std::move(op)); |
127 | 0 | } |
128 | 0 | } |