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/gpu/ganesh/GrClip.h"
15 #include "src/gpu/ganesh/GrDirectContextPriv.h"
16 #include "src/gpu/ganesh/GrDrawOpAtlas.h"
17 #include "src/gpu/ganesh/GrDrawingManager.h"
18 #include "src/gpu/ganesh/GrGpu.h"
19 #include "src/gpu/ganesh/GrGpuResourceCacheAccess.h"
20 #include "src/gpu/ganesh/GrMemoryPool.h"
21 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
22 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
23 #include "src/gpu/ganesh/GrResourceCache.h"
24 #include "src/gpu/ganesh/GrSemaphore.h"
25 #include "src/gpu/ganesh/GrTexture.h"
26 #include "src/gpu/ganesh/SkGr.h"
27 #include "src/gpu/ganesh/SurfaceDrawContext.h"
28 #include "src/image/SkImage_Gpu.h"
29 #include "src/text/gpu/StrikeCache.h"
30 #include "src/text/gpu/TextBlobRedrawCoordinator.h"
31
32 #include <algorithm>
33
34 //////////////////////////////////////////////////////////////////////////////
35
36 #define DRAW_OP_TEST_EXTERN(Op) \
37 extern GrOp::Owner Op##__Test(GrPaint&&, \
38 SkRandom*, \
39 GrRecordingContext*, \
40 skgpu::v1::SurfaceDrawContext*, \
41 int)
42 #define DRAW_OP_TEST_ENTRY(Op) Op##__Test
43
44 DRAW_OP_TEST_EXTERN(AAConvexPathOp);
45 DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
46 DRAW_OP_TEST_EXTERN(AAHairlineOp);
47 DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
48 DRAW_OP_TEST_EXTERN(AtlasTextOp);
49 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
50 DRAW_OP_TEST_EXTERN(ButtCapDashedCircleOp);
51 DRAW_OP_TEST_EXTERN(CircleOp);
52 #endif
53 DRAW_OP_TEST_EXTERN(DashOpImpl);
54 DRAW_OP_TEST_EXTERN(DefaultPathOp);
55 DRAW_OP_TEST_EXTERN(DrawAtlasOp);
56 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
57 DRAW_OP_TEST_EXTERN(DIEllipseOp);
58 DRAW_OP_TEST_EXTERN(EllipseOp);
59 #endif
60 DRAW_OP_TEST_EXTERN(FillRectOp);
61 DRAW_OP_TEST_EXTERN(NonAALatticeOp);
62 DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
63 DRAW_OP_TEST_EXTERN(RegionOp);
64 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
65 DRAW_OP_TEST_EXTERN(RRectOp);
66 #endif
67 DRAW_OP_TEST_EXTERN(ShadowRRectOp);
68 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
69 DRAW_OP_TEST_EXTERN(SmallPathOp);
70 #endif
71 DRAW_OP_TEST_EXTERN(TextureOpImpl);
72 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
73 DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
74 #endif
75
GrDrawRandomOp(SkRandom * random,skgpu::v1::SurfaceDrawContext * sdc,GrPaint && paint)76 void GrDrawRandomOp(SkRandom* random, skgpu::v1::SurfaceDrawContext* sdc, GrPaint&& paint) {
77 auto rContext = sdc->recordingContext();
78 using MakeDrawOpFn = GrOp::Owner (GrPaint&&,
79 SkRandom*,
80 GrRecordingContext*,
81 skgpu::v1::SurfaceDrawContext*,
82 int numSamples);
83 static constexpr MakeDrawOpFn* gFactories[] = {
84 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
85 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
86 DRAW_OP_TEST_ENTRY(AAHairlineOp),
87 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
88 DRAW_OP_TEST_ENTRY(AtlasTextOp),
89 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
90 DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp),
91 DRAW_OP_TEST_ENTRY(CircleOp),
92 #endif
93 DRAW_OP_TEST_ENTRY(DashOpImpl),
94 DRAW_OP_TEST_ENTRY(DefaultPathOp),
95 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
96 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
97 DRAW_OP_TEST_ENTRY(DIEllipseOp),
98 DRAW_OP_TEST_ENTRY(EllipseOp),
99 #endif
100 DRAW_OP_TEST_ENTRY(FillRectOp),
101 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
102 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
103 DRAW_OP_TEST_ENTRY(RegionOp),
104 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
105 DRAW_OP_TEST_ENTRY(RRectOp),
106 #endif
107 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
108 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
109 DRAW_OP_TEST_ENTRY(SmallPathOp),
110 #endif
111 DRAW_OP_TEST_ENTRY(TextureOpImpl),
112 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
113 DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
114 #endif
115 };
116
117 static constexpr size_t kTotal = std::size(gFactories);
118 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
119 auto op = gFactories[index](std::move(paint),
120 random,
121 rContext,
122 sdc,
123 sdc->numSamples());
124
125 // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the
126 // render target context.
127 if (op) {
128 sdc->addDrawOp(std::move(op));
129 }
130 }
131