blob: 8964419bd7cdcac99a8157877e9cb291ad8f6416 [file] [log] [blame]
Chris Dalton83420eb2021-06-23 18:47:09 -06001/*
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/SkPath.h"
11#include "include/gpu/GrContextOptions.h"
12#include "include/gpu/GrRecordingContext.h"
Greg Daniel719239c2022-04-07 11:20:24 -040013#include "src/gpu/ganesh/GrDirectContextPriv.h"
14#include "src/gpu/ganesh/GrDrawingManager.h"
15#include "src/gpu/ganesh/GrRecordingContextPriv.h"
Chris Dalton83420eb2021-06-23 18:47:09 -060016#include "tools/ToolUtils.h"
17
Robert Phillips9360fae2023-06-20 13:34:37 -040018#if defined(SK_GRAPHITE)
19#include "include/gpu/graphite/ContextOptions.h"
Jim Van Verth18bdcfb2023-09-15 13:57:36 -040020#include "include/private/gpu/graphite/ContextOptionsPriv.h"
Robert Phillips9360fae2023-06-20 13:34:37 -040021#endif
22
Chris Dalton83420eb2021-06-23 18:47:09 -060023namespace skiagm {
24
25/**
Robert Phillipsb1cd9772023-01-06 11:16:13 -050026 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCPR is gone
Chris Dalton83420eb2021-06-23 18:47:09 -060027 * now, but we decided to keep the test.
28 */
Robert Phillipsb1cd9772023-01-06 11:16:13 -050029class ManyPathAtlasesGM : public GM {
Chris Dalton061aa812021-06-25 13:16:24 -060030public:
31 ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {}
Chris Dalton83420eb2021-06-23 18:47:09 -060032private:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000033 SkString getName() const override {
34 return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize);
35 }
Leandro Lovisolo8f023882023-08-15 21:13:52 +000036 SkISize getISize() override { return SkISize::Make(128, 128); }
Chris Dalton83420eb2021-06-23 18:47:09 -060037
38 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
Chris Dalton061aa812021-06-25 13:16:24 -060039 // This will test the case where the atlas runs out of room if fMaxAtlasSize is small.
40 ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize;
Chris Dalton83420eb2021-06-23 18:47:09 -060041 }
42
Robert Phillips9360fae2023-06-20 13:34:37 -040043#if defined(SK_GRAPHITE)
Jim Van Verth18bdcfb2023-09-15 13:57:36 -040044 void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions* options) const override {
45 SkASSERT(options->fOptionsPriv);
46 options->fOptionsPriv->fMaxTextureAtlasSize = fMaxAtlasSize;
Robert Phillips9360fae2023-06-20 13:34:37 -040047 }
48#endif
49
Robert Phillipsb1cd9772023-01-06 11:16:13 -050050 void onDraw(SkCanvas* canvas) override {
51 canvas->clear(SkColors::kYellow);
Chris Dalton061aa812021-06-25 13:16:24 -060052
53 // Flush the context to make the DAG empty. This will test the case where we try to add an
54 // atlas task to an empty DAG.
Robert Phillipsb1cd9772023-01-06 11:16:13 -050055 auto dContext = GrAsDirectContext(canvas->recordingContext());
56 if (dContext) {
Chris Dalton061aa812021-06-25 13:16:24 -060057 dContext->flush();
58 }
59
Chris Dalton83420eb2021-06-23 18:47:09 -060060 SkPath clip = SkPath().moveTo(-50, 20)
61 .cubicTo(-50, -20, 50, -20, 50, 40)
62 .cubicTo(20, 0, -20, 0, -50, 20);
63 clip.transform(SkMatrix::Translate(64, 70));
64 for (int i = 0; i < 4; ++i) {
65 SkPath rotatedClip = clip;
66 rotatedClip.transform(SkMatrix::RotateDeg(30 * i + 128, {64, 70}));
67 rotatedClip.setIsVolatile(true);
68 canvas->clipPath(rotatedClip, SkClipOp::kDifference, true);
69 }
70 SkPath path = SkPath().moveTo(20, 0)
71 .lineTo(108, 0).cubicTo(108, 20, 108, 20, 128, 20)
72 .lineTo(128, 108).cubicTo(108, 108, 108, 108, 108, 128)
73 .lineTo(20, 128).cubicTo(20, 108, 20, 108, 0, 108)
74 .lineTo(0, 20).cubicTo(20, 20, 20, 20, 20, 0);
75 path.setIsVolatile(true);
76 SkPaint teal;
77 teal.setColor4f({.03f, .91f, .87f, 1});
78 teal.setAntiAlias(true);
79 canvas->drawPath(path, teal);
Chris Dalton83420eb2021-06-23 18:47:09 -060080 }
Chris Dalton061aa812021-06-25 13:16:24 -060081
82 const int fMaxAtlasSize;
Chris Dalton83420eb2021-06-23 18:47:09 -060083};
84
Chris Dalton061aa812021-06-25 13:16:24 -060085DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room.
86DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room.
Chris Dalton83420eb2021-06-23 18:47:09 -060087
88} // namespace skiagm