xref: /aosp_15_r20/external/skia/tools/gpu/GrTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/ganesh/GrBackendSurface.h"
10 #include "include/gpu/ganesh/GrContextOptions.h"
11 #include "include/gpu/ganesh/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 #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 
GrDrawRandomOp(SkRandom * random,skgpu::ganesh::SurfaceDrawContext * sdc,GrPaint && paint)74 void GrDrawRandomOp(SkRandom* random, skgpu::ganesh::SurfaceDrawContext* sdc, GrPaint&& paint) {
75     auto rContext = sdc->recordingContext();
76     using MakeDrawOpFn = GrOp::Owner(GrPaint&&,
77                                      SkRandom*,
78                                      GrRecordingContext*,
79                                      skgpu::ganesh::SurfaceDrawContext*,
80                                      int numSamples);
81     static constexpr MakeDrawOpFn* gFactories[] = {
82             DRAW_OP_TEST_ENTRY(AAConvexPathOp),
83             DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
84             DRAW_OP_TEST_ENTRY(AAHairlineOp),
85             DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
86             DRAW_OP_TEST_ENTRY(AtlasTextOp),
87 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
88             DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp),
89             DRAW_OP_TEST_ENTRY(CircleOp),
90 #endif
91             DRAW_OP_TEST_ENTRY(DashOpImpl),
92             DRAW_OP_TEST_ENTRY(DefaultPathOp),
93             DRAW_OP_TEST_ENTRY(DrawAtlasOp),
94 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
95             DRAW_OP_TEST_ENTRY(DIEllipseOp),
96             DRAW_OP_TEST_ENTRY(EllipseOp),
97 #endif
98             DRAW_OP_TEST_ENTRY(FillRectOp),
99             DRAW_OP_TEST_ENTRY(NonAALatticeOp),
100             DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
101             DRAW_OP_TEST_ENTRY(RegionOp),
102 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
103             DRAW_OP_TEST_ENTRY(RRectOp),
104 #endif
105             DRAW_OP_TEST_ENTRY(ShadowRRectOp),
106 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
107             DRAW_OP_TEST_ENTRY(SmallPathOp),
108 #endif
109             DRAW_OP_TEST_ENTRY(TextureOpImpl),
110 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
111             DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
112 #endif
113     };
114 
115     static constexpr size_t kTotal = std::size(gFactories);
116     uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
117     auto op = gFactories[index](std::move(paint),
118                                 random,
119                                 rContext,
120                                 sdc,
121                                 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     if (op) {
126         sdc->addDrawOp(std::move(op));
127     }
128 }
129