Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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;
107 bounds.offset(SkIntToScalar(x), SkIntToScalar(y));
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
#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)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
static const SkMatrix & I()
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
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
static GrOp::Owner MakeNonAARect(GrRecordingContext *, GrPaint &&, const SkMatrix &view, const SkRect &, const GrUserStencilSettings *=nullptr)
SkString getName() const override
DrawResult onDraw(GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
BigRRectAAEffectGM(const SkRRect &rrect, const char *name)
const Paint & paint
const char * name
Definition fuchsia.cc:50
#define DEF_GM(CODE)
Definition gm.h:40
double y
double x
GrFPResult Make(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, const SkRRect &, const GrShaderCaps &)
SkColor color_to_565(SkColor color)
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition GrCanvas.cpp:20
constexpr int kSize
DrawResult
Definition gm.h:104
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