Flutter Engine
The Flutter Engine
bigrrectaaeffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
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"
15#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
31#include "tools/ToolUtils.h"
32
33#include <memory>
34#include <utility>
35
36namespace skiagm {
37
38///////////////////////////////////////////////////////////////////////////////
39
40class BigRRectAAEffectGM : public GpuGM {
41public:
42 BigRRectAAEffectGM(const SkRRect& rrect, const char* name)
43 : fRRect(rrect)
44 , fName(name) {
45 this->setBGColor(ToolUtils::color_to_565(SK_ColorBLUE));
46 // Each test case draws the rrect with gaps around it.
47 fTestWidth = SkScalarCeilToInt(rrect.width()) + 2 * kGap;
48 fTestHeight = SkScalarCeilToInt(rrect.height()) + 2 * kGap;
49
50 // Add a pad between test cases.
51 fTestOffsetX = fTestWidth + kPad;
52 fTestOffsetY = fTestHeight + kPad;
53
54 // We draw two tests in x (fill and inv-fill) and pad around
55 // all four sides of the image.
56 fWidth = 2 * fTestOffsetX + kPad;
57 fHeight = fTestOffsetY + kPad;
58 }
59
60protected:
61 SkString getName() const override {
63 name.printf("big_rrect_%s_aa_effect", fName);
64 return name;
65 }
66
67 SkISize getISize() override { return SkISize::Make(fWidth, fHeight); }
68
69 DrawResult onDraw(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg) override {
71 if (!sdc) {
72 *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
73 return DrawResult::kSkip;
74 }
75
76 int y = kPad;
77 int x = kPad;
78 constexpr GrClipEdgeType kEdgeTypes[] = {
81 };
82 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight);
83 for (size_t et = 0; et < std::size(kEdgeTypes); ++et) {
84 GrClipEdgeType edgeType = kEdgeTypes[et];
85 canvas->save();
87
88 // Draw a background for the test case
90 paint.setColor(SK_ColorWHITE);
91 canvas->drawRect(testBounds, paint);
92
93 SkRRect rrect = fRRect;
94 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap));
95 const auto& caps = *rContext->priv().caps()->shaderCaps();
96 auto [success, fp] = GrRRectEffect::Make(/*inputFP=*/nullptr, edgeType, rrect,
97 caps);
98 SkASSERT(success);
99 if (success) {
100 SkASSERT(fp);
101 GrPaint grPaint;
102 grPaint.setColor4f({ 0, 0, 0, 1.f });
104 grPaint.setCoverageFragmentProcessor(std::move(fp));
105
106 SkRect bounds = testBounds;
108
110 rContext, std::move(grPaint), SkMatrix::I(), bounds));
111 }
112 canvas->restore();
113 x = x + fTestOffsetX;
114 }
115
116 return DrawResult::kOk;
117 }
118
119private:
120 // pad between test cases
121 inline static constexpr int kPad = 7;
122 // gap between rect for each case that is rendered and exterior of rrect
123 inline static constexpr int kGap = 3;
124
125 SkRRect fRRect;
126 int fWidth;
127 int fHeight;
128 int fTestWidth;
129 int fTestHeight;
130 int fTestOffsetX;
131 int fTestOffsetY;
132 const char* fName;
133 using INHERITED = GM;
134};
135
136///////////////////////////////////////////////////////////////////////////////
137// This value is motivated by bug chromium:477684. It has to be large to cause overflow in
138// the shader
139constexpr int kSize = 700;
140
143DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize - 1, kSize - 10)), "ellipse"); )
144// The next two have small linear segments between the corners
145DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 10.f), "circular_corner"); )
146DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 15.f), "elliptical_corner"); )
147
148} // namespace skiagm
GrClipEdgeType
Definition: GrTypesPriv.h:361
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
#define SkIntToScalar(x)
Definition: SkScalar.h:57
constexpr int kPad
const GrCaps * caps() const
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
void setXPFactory(const GrXPFactory *xpFactory)
Definition: GrPaint.h:53
void setColor4f(const SkPMColor4f &color)
Definition: GrPaint.h:50
void setCoverageFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition: GrPaint.h:75
static const GrXPFactory * Get(SkBlendMode blendMode)
GrRecordingContextPriv priv()
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
static SkRRect MakeOval(const SkRect &oval)
Definition: SkRRect.h:162
static SkRRect MakeRect(const SkRect &r)
Definition: SkRRect.h:149
SkScalar width() const
Definition: SkRRect.h:95
void offset(SkScalar dx, SkScalar dy)
Definition: SkRRect.h:387
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
SkScalar height() const
Definition: SkRRect.h:102
static GrOp::Owner MakeNonAARect(GrRecordingContext *, GrPaint &&, const SkMatrix &view, const SkRect &, const GrUserStencilSettings *=nullptr)
Definition: FillRectOp.cpp:480
SkString getName() const override
DrawResult onDraw(GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
BigRRectAAEffectGM(const SkRRect &rrect, const char *name)
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
double y
double x
GrFPResult Make(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, const SkRRect &, const GrShaderCaps &)
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
const uint32_t fp
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
constexpr int kSize
DrawResult
Definition: gm.h:104
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623