Flutter Engine
The Flutter Engine
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | List of all members
skiagm::DstReadShuffle Class Reference
Inheritance diagram for skiagm::DstReadShuffle:
skiagm::GM

Public Member Functions

 DstReadShuffle ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Types

enum  ShapeType {
  kCircle_ShapeType , kRoundRect_ShapeType , kRect_ShapeType , kConvexPath_ShapeType ,
  kConcavePath_ShapeType , kText_ShapeType , kNumShapeTypes
}
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void drawShape (SkCanvas *canvas, SkPaint *paint, ShapeType type)
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Static Protected Member Functions

static SkColor GetColor (SkRandom *random)
 
static void DrawHairlines (SkCanvas *canvas)
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Renders overlapping shapes with colorburn against a checkerboard.

Definition at line 36 of file dstreadshuffle.cpp.

Member Enumeration Documentation

◆ ShapeType

Enumerator
kCircle_ShapeType 
kRoundRect_ShapeType 
kRect_ShapeType 
kConvexPath_ShapeType 
kConcavePath_ShapeType 
kText_ShapeType 
kNumShapeTypes 

Definition at line 41 of file dstreadshuffle.cpp.

Constructor & Destructor Documentation

◆ DstReadShuffle()

skiagm::DstReadShuffle::DstReadShuffle ( )
inline

Definition at line 38 of file dstreadshuffle.cpp.

38{ this->setBGColor(kBackground); }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ DrawHairlines()

static void skiagm::DstReadShuffle::DrawHairlines ( SkCanvas canvas)
inlinestaticprotected

Definition at line 115 of file dstreadshuffle.cpp.

115 {
116 if (canvas->imageInfo().alphaType() == kOpaque_SkAlphaType) {
117 canvas->clear(kBackground);
118 } else {
119 canvas->clear(SK_ColorTRANSPARENT);
120 }
121 SkPaint hairPaint;
123 hairPaint.setStrokeWidth(0);
124 hairPaint.setAntiAlias(true);
125 static constexpr int kNumHairlines = 12;
126 SkPoint pts[] = {{3.f, 7.f}, {29.f, 7.f}};
127 SkRandom colorRandom;
128 SkMatrix rot;
129 rot.setRotate(360.f / kNumHairlines, 15.5f, 12.f);
130 rot.postTranslate(3.f, 0);
131 for (int i = 0; i < 12; ++i) {
132 hairPaint.setColor(GetColor(&colorRandom));
133 canvas->drawLine(pts[0], pts[1], hairPaint);
134 rot.mapPoints(pts, 2);
135 }
136 }
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void clear(SkColor color)
Definition: SkCanvas.h:1199
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:281
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition: SkMatrix.cpp:770
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
static SkColor GetColor(SkRandom *random)
SkAlphaType alphaType() const
Definition: SkImageInfo.h:375

◆ drawShape()

void skiagm::DstReadShuffle::drawShape ( SkCanvas canvas,
SkPaint paint,
ShapeType  type 
)
inlineprotected

Definition at line 55 of file dstreadshuffle.cpp.

55 {
56 const SkRect kRect = SkRect::MakeXYWH(0, 0, 75.f, 85.f);
57 switch (type) {
59 canvas->drawCircle(kRect.centerX(), kRect.centerY(), kRect.width() / 2.f, *paint);
60 break;
62 canvas->drawRoundRect(kRect, 15.f, 15.f, *paint);
63 break;
64 case kRect_ShapeType:
65 canvas->drawRect(kRect, *paint);
66 break;
68 if (fConvexPath.isEmpty()) {
69 SkPoint points[4];
70 kRect.toQuad(points);
71 fConvexPath = SkPathBuilder().moveTo(points[0])
72 .quadTo(points[1], points[2])
73 .quadTo(points[3], points[0])
74 .detach();
75 SkASSERT(fConvexPath.isConvex());
76 }
77 canvas->drawPath(fConvexPath, *paint);
78 break;
80 if (fConcavePath.isEmpty()) {
82 SkPoint points[5] = {{50.f, 0.f}};
83 SkMatrix rot;
84 rot.setRotate(360.f / 5, 50.f, 70.f);
85 for (int i = 1; i < 5; ++i) {
86 rot.mapPoints(points + i, points + i - 1, 1);
87 }
88 b.moveTo(points[0]);
89 for (int i = 0; i < 5; ++i) {
90 b.lineTo(points[(2 * i) % 5]);
91 }
92 fConcavePath = b.setFillType(SkPathFillType::kEvenOdd)
93 .detach();
94 SkASSERT(!fConcavePath.isConvex());
95 }
96 canvas->drawPath(fConcavePath, *paint);
97 break;
98 case kText_ShapeType: {
99 const char* text = "N";
101 font.setEmbolden(true);
102 canvas->drawString(text, 0.f, 100.f, font, *paint);
103 break;
104 }
105 default:
106 break;
107 }
108 }
static const int points[]
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
Definition: SkCanvas.cpp:2717
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkFont.h:35
SkPathBuilder & moveTo(SkPoint pt)
SkPathBuilder & quadTo(SkPoint pt1, SkPoint pt2)
bool isEmpty() const
Definition: SkPath.cpp:416
bool isConvex() const
Definition: SkPath.cpp:426
const Paint & paint
Definition: color_source.cc:38
static bool b
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
constexpr std::array< std::array< float, 2 >, 2 > kRect
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ GetColor()

static SkColor skiagm::DstReadShuffle::GetColor ( SkRandom random)
inlinestaticprotected

Definition at line 110 of file dstreadshuffle.cpp.

110 {
111 SkColor color = ToolUtils::color_to_565(random->nextU() | 0xFF000000);
112 return SkColorSetA(color, 0x80);
113 }
uint32_t SkColor
Definition: SkColor.h:37
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition: SkColor.h:82
uint32_t nextU()
Definition: SkRandom.h:42
DlColor color
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139

◆ getISize()

SkISize skiagm::DstReadShuffle::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 53 of file dstreadshuffle.cpp.

53{ return SkISize::Make(530, 680); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::DstReadShuffle::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 51 of file dstreadshuffle.cpp.

51{ return SkString("dstreadshuffle"); }

◆ onDraw()

void skiagm::DstReadShuffle::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 138 of file dstreadshuffle.cpp.

138 {
139 SkScalar y = 5;
140 for (int i = 0; i < kNumShapeTypes; i++) {
141 SkRandom colorRandom;
142 ShapeType shapeType = static_cast<ShapeType>(i);
143 SkScalar x = 5;
144 for (int r = 0; r <= 15; r++) {
145 SkPaint p;
146 p.setAntiAlias(true);
147 p.setColor(GetColor(&colorRandom));
148 // In order to get some op combining on the GPU backend we do 2 src over
149 // for each xfer mode which requires a dst read
150 p.setBlendMode(r % 3 == 0 ? SkBlendMode::kColorBurn : SkBlendMode::kSrcOver);
151 canvas->save();
152 canvas->translate(x, y);
153 this->drawShape(canvas, &p, shapeType);
154 canvas->restore();
155 x += 15;
156 }
157 y += 110;
158 }
159 // Draw hairlines to a surface and then draw that to the main canvas with a zoom so that
160 // it is easier to see how they blend.
162 // Recording canvases don't have a color type.
165 } else {
166 info = SkImageInfo::Make(35, 35,
167 canvas->imageInfo().colorType(),
168 canvas->imageInfo().alphaType(),
169 canvas->imageInfo().refColorSpace());
170 }
171 auto surf = canvas->makeSurface(info);
172 if (!surf) {
173 // Fall back to raster. Raster supports only one of the 8 bit per-channel RGBA or BGRA
174 // formats. This fall back happens when running with --preAbandonGpuContext.
175 if ((info.colorType() == kRGBA_8888_SkColorType ||
176 info.colorType() == kBGRA_8888_SkColorType) &&
177 info.colorType() != kN32_SkColorType) {
178 info = SkImageInfo::Make(35, 35,
179 kN32_SkColorType,
180 canvas->imageInfo().alphaType(),
181 canvas->imageInfo().refColorSpace());
182 }
183 surf = SkSurfaces::Raster(info);
184 SkASSERT(surf);
185 }
186 canvas->scale(5.f, 5.f);
187 canvas->translate(67.f, 10.f);
188 DrawHairlines(surf->getCanvas());
189 canvas->drawImage(surf->makeImageSnapshot(), 0.f, 0.f);
190 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kColorBurn
darken destination to reflect source
@ kSrcOver
r = s + (1-sa)*d
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void drawShape(SkCanvas *canvas, SkPaint *paint, ShapeType type)
static void DrawHairlines(SkCanvas *canvas)
float SkScalar
Definition: extension.cpp:12
double y
double x
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)
sk_sp< SkColorSpace > refColorSpace() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkColorType colorType() const
Definition: SkImageInfo.h:373

The documentation for this class was generated from the following file: