Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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:3824
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
virtual GrRecordingContext * recordingContext() const
void clear(SkColor color)
Definition SkCanvas.h:1199
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
void drawPath(const SkPath &path, const SkPaint &paint)
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
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
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:789
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
virtual void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions *) const
Definition gm.h:179
void onDraw(SkCanvas *canvas) override
void modifyGrContextOptions(GrContextOptions *ctxOptions) override
SkString getName() const override
ManyPathAtlasesGM(int maxAtlasSize)
SkISize getISize() override
#define DEF_GM(CODE)
Definition gm.h:40
constexpr SkColor4f kYellow
Definition SkColor.h:443
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20