Flutter Engine
The Flutter Engine
manypathatlases.cpp
Go to the documentation of this file.
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"
16#include "tools/ToolUtils.h"
17
18#if defined(SK_GRAPHITE)
21#endif
22
23namespace skiagm {
24
25/**
26 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCPR is gone
27 * now, but we decided to keep the test.
28 */
29class ManyPathAtlasesGM : public GM {
30public:
31 ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {}
32private:
33 SkString getName() const override {
34 return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize);
35 }
36 SkISize getISize() override { return SkISize::Make(128, 128); }
37
38 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
39 // This will test the case where the atlas runs out of room if fMaxAtlasSize is small.
40 ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize;
41 }
42
43#if defined(SK_GRAPHITE)
45 SkASSERT(options->fOptionsPriv);
46 options->fOptionsPriv->fMaxTextureAtlasSize = fMaxAtlasSize;
47 }
48#endif
49
50 void onDraw(SkCanvas* canvas) override {
51 canvas->clear(SkColors::kYellow);
52
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.
55 auto dContext = GrAsDirectContext(canvas->recordingContext());
56 if (dContext) {
57 dContext->flush();
58 }
59
60 SkPath clip = SkPath().moveTo(-50, 20)
61 .cubicTo(-50, -20, 50, -20, 50, 40)
62 .cubicTo(20, 0, -20, 0, -50, 20);
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);
80 }
81
82 const int fMaxAtlasSize;
83};
84
85DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room.
86DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room.
87
88} // namespace skiagm
const char * options
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void clear(SkColor color)
Definition: SkCanvas.h:1199
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setColor4f(const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
Definition: SkPaint.h:253
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & setIsVolatile(bool isVolatile)
Definition: SkPath.h:370
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition: SkPath.cpp:799
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711
Definition: gm.h:110
virtual void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions *) const
Definition: gm.h:179
ManyPathAtlasesGM(int maxAtlasSize)
constexpr SkColor4f kYellow
Definition: SkColor.h:443
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20