blob: fe617d2add8c8df4935d0d45f4f097fcc94fc435 [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"
13#include "src/gpu/GrDirectContextPriv.h"
14#include "src/gpu/GrDrawingManager.h"
15#include "src/gpu/GrRecordingContextPriv.h"
16#include "src/gpu/GrSurfaceDrawContext.h"
17#include "tools/ToolUtils.h"
18
19namespace skiagm {
20
21/**
22 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCRP is gone
23 * now, but we decided to keep the test.
24 */
25class ManyPathAtlasesGM : public GpuGM {
Chris Dalton061aa812021-06-25 13:16:24 -060026public:
27 ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {}
Chris Dalton83420eb2021-06-23 18:47:09 -060028private:
Chris Dalton061aa812021-06-25 13:16:24 -060029 SkString onShortName() override { return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize); }
Chris Dalton83420eb2021-06-23 18:47:09 -060030 SkISize onISize() override { return SkISize::Make(128, 128); }
31
32 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
Chris Dalton061aa812021-06-25 13:16:24 -060033 // This will test the case where the atlas runs out of room if fMaxAtlasSize is small.
34 ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize;
Chris Dalton83420eb2021-06-23 18:47:09 -060035 }
36
Chris Dalton061aa812021-06-25 13:16:24 -060037 DrawResult onDraw(GrRecordingContext* rContext, GrSurfaceDrawContext*, SkCanvas* canvas,
Chris Dalton83420eb2021-06-23 18:47:09 -060038 SkString* errorMsg) override {
39 canvas->clear({1,1,0,1});
Chris Dalton061aa812021-06-25 13:16:24 -060040
41 // Flush the context to make the DAG empty. This will test the case where we try to add an
42 // atlas task to an empty DAG.
43 if (auto dContext = rContext->asDirectContext()) {
44 dContext->flush();
45 }
46
Chris Dalton83420eb2021-06-23 18:47:09 -060047 SkPath clip = SkPath().moveTo(-50, 20)
48 .cubicTo(-50, -20, 50, -20, 50, 40)
49 .cubicTo(20, 0, -20, 0, -50, 20);
50 clip.transform(SkMatrix::Translate(64, 70));
51 for (int i = 0; i < 4; ++i) {
52 SkPath rotatedClip = clip;
53 rotatedClip.transform(SkMatrix::RotateDeg(30 * i + 128, {64, 70}));
54 rotatedClip.setIsVolatile(true);
55 canvas->clipPath(rotatedClip, SkClipOp::kDifference, true);
56 }
57 SkPath path = SkPath().moveTo(20, 0)
58 .lineTo(108, 0).cubicTo(108, 20, 108, 20, 128, 20)
59 .lineTo(128, 108).cubicTo(108, 108, 108, 108, 108, 128)
60 .lineTo(20, 128).cubicTo(20, 108, 20, 108, 0, 108)
61 .lineTo(0, 20).cubicTo(20, 20, 20, 20, 20, 0);
62 path.setIsVolatile(true);
63 SkPaint teal;
64 teal.setColor4f({.03f, .91f, .87f, 1});
65 teal.setAntiAlias(true);
66 canvas->drawPath(path, teal);
67 return DrawResult::kOk;
68 }
Chris Dalton061aa812021-06-25 13:16:24 -060069
70 const int fMaxAtlasSize;
Chris Dalton83420eb2021-06-23 18:47:09 -060071};
72
Chris Dalton061aa812021-06-25 13:16:24 -060073DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room.
74DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room.
Chris Dalton83420eb2021-06-23 18:47:09 -060075
76} // namespace skiagm