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