Debian Codegraph @

gm/manypathatlases.cpp

raw
1 /*
2 * Copyright 2019 Google LLC.
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 "gm/gm.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkClipOp.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkPathBuilder.h"
14 #include "tools/ToolUtils.h"
15
16 #if defined(SK_GANESH)
17 #include "include/gpu/ganesh/GrContextOptions.h"
18 #include "include/gpu/ganesh/GrRecordingContext.h"
19 #include "src/gpu/ganesh/GrDirectContextPriv.h"
20 #include "src/gpu/ganesh/GrDrawingManager.h"
21 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
22 #endif
23
24 #if defined(SK_GRAPHITE)
25 #include "include/gpu/graphite/ContextOptions.h"
26 #include "src/gpu/graphite/ContextOptionsPriv.h"
27 #endif
28
29 namespace skiagm {
30
31 /**
32 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCPR is gone
33 * now, but we decided to keep the test.
34 */
35 class ManyPathAtlasesGM : public GM {
36 public:
37 ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {}
38 private:
39 SkString getName() const override {
40 return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize);
41 }
42 SkISize getISize() override { return SkISize::Make(128, 128); }
43
44 #if defined(SK_GANESH)
45 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
46 // This will test the case where the atlas runs out of room if fMaxAtlasSize is small.
47 ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize;
48 }
49 #endif
50
51 #if defined(SK_GRAPHITE)
52 void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions* options) const override {
53 options->fMaxPathAtlasTextureSize = fMaxAtlasSize;
54 }
55 #endif
56
57 void onDraw(SkCanvas* canvas) override {
58 canvas->clear(SkColors::kYellow);
59
60 #if defined(SK_GANESH)
61 // Flush the context to make the DAG empty. This will test the case where we try to add an
62 // atlas task to an empty DAG.
63 auto dContext = GrAsDirectContext(canvas->recordingContext());
64 if (dContext) {
65 dContext->flush();
66 }
67 #endif
68
69 SkPath clip = SkPathBuilder().moveTo(-50, 20)
70 .cubicTo(-50, -20, 50, -20, 50, 40)
71 .cubicTo(20, 0, -20, 0, -50, 20)
72 .transform(SkMatrix::Translate(64, 70))
73 .detach();
74 for (int i = 0; i < 4; ++i) {
75 SkPath rotatedClip = clip.makeTransform(SkMatrix::RotateDeg(30 * i + 128, {64, 70}));
76 rotatedClip.setIsVolatile(true);
77 canvas->clipPath(rotatedClip, SkClipOp::kDifference, true);
78 }
79 SkPath path = SkPathBuilder().moveTo(20, 0)
80 .lineTo(108, 0).cubicTo(108, 20, 108, 20, 128, 20)
81 .lineTo(128, 108).cubicTo(108, 108, 108, 108, 108, 128)
82 .lineTo(20, 128).cubicTo(20, 108, 20, 108, 0, 108)
83 .lineTo(0, 20).cubicTo(20, 20, 20, 20, 20, 0)
84 .detach();
85 path.setIsVolatile(true);
86 SkPaint teal;
87 teal.setColor4f({.03f, .91f, .87f, 1});
88 teal.setAntiAlias(true);
89 canvas->drawPath(path, teal);
90 }
91
92 const int fMaxAtlasSize;
93 };
94
95 DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room.
96 DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room.
97
98 } // namespace skiagm