Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 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/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 | |
| 19 | namespace 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 | */ |
| 25 | class ManyPathAtlasesGM : public GpuGM { |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 26 | public: |
| 27 | ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {} |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 28 | private: |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 29 | SkString onShortName() override { return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize); } |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 30 | SkISize onISize() override { return SkISize::Make(128, 128); } |
| 31 | |
| 32 | void modifyGrContextOptions(GrContextOptions* ctxOptions) override { |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 33 | // This will test the case where the atlas runs out of room if fMaxAtlasSize is small. |
| 34 | ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize; |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 35 | } |
| 36 | |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 37 | DrawResult onDraw(GrRecordingContext* rContext, GrSurfaceDrawContext*, SkCanvas* canvas, |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 38 | SkString* errorMsg) override { |
| 39 | canvas->clear({1,1,0,1}); |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 40 | |
| 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 Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 47 | 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 Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 69 | |
| 70 | const int fMaxAtlasSize; |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 71 | }; |
| 72 | |
Chris Dalton | 061aa81 | 2021-06-25 13:16:24 -0600 | [diff] [blame^] | 73 | DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room. |
| 74 | DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room. |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 75 | |
| 76 | } // namespace skiagm |