Flutter Engine
The Flutter Engine
Classes | Namespaces | Typedefs | Functions | Variables
drawquadset.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkCanvasPriv.h"
#include "src/gpu/ganesh/GrCanvas.h"
#include "src/gpu/ganesh/GrPaint.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/SurfaceDrawContext.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  skiagm::DrawQuadSetGM
 

Namespaces

namespace  skiagm
 

Typedefs

typedef void(* TileRenderer) (SkCanvas *)
 

Functions

static void draw_text (SkCanvas *canvas, const char *text)
 
static void draw_gradient_tiles (SkCanvas *canvas, bool alignGradients)
 
static void draw_color_tiles (SkCanvas *canvas, bool multicolor)
 
static void draw_tile_boundaries (SkCanvas *canvas, const SkMatrix &local)
 

Variables

static constexpr SkScalar kTileWidth = 40
 
static constexpr SkScalar kTileHeight = 30
 
static constexpr int kRowCount = 4
 
static constexpr int kColCount = 3
 
static TileRenderer kTileSets []
 
static const char * kTileSetNames [] = { "Local", "Aligned", "Green", "Multicolor" }
 

Typedef Documentation

◆ TileRenderer

typedef void(* TileRenderer) (SkCanvas *)

Definition at line 169 of file drawquadset.cpp.

Function Documentation

◆ draw_color_tiles()

static void draw_color_tiles ( SkCanvas canvas,
bool  multicolor 
)
static

Definition at line 111 of file drawquadset.cpp.

111 {
112 for (int i = 0; i < kRowCount; ++i) {
113 for (int j = 0; j < kColCount; ++j) {
115
117 if (multicolor) {
118 color = {(i + 1.f) / kRowCount, (j + 1.f) / kColCount, .4f, 1.f};
119 } else {
120 color = {.2f, .8f, .3f, 1.f};
121 }
122
123 unsigned aa = SkCanvas::kNone_QuadAAFlags;
124 if (i == 0) {
126 }
127 if (i == kRowCount - 1) {
129 }
130 if (j == 0) {
132 }
133 if (j == kColCount - 1) {
135 }
136
138 tile, nullptr, static_cast<SkCanvas::QuadAAFlags>(aa), color.toSkColor(),
140 }
141 }
142}
@ kSrcOver
r = s + (1-sa)*d
void experimental_DrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
Definition: SkCanvas.cpp:1845
@ kTop_QuadAAFlag
Definition: SkCanvas.h:1660
@ kRight_QuadAAFlag
Definition: SkCanvas.h:1661
@ kLeft_QuadAAFlag
Definition: SkCanvas.h:1659
@ kBottom_QuadAAFlag
Definition: SkCanvas.h:1662
@ kNone_QuadAAFlags
Definition: SkCanvas.h:1664
DlColor color
static constexpr SkScalar kTileHeight
Definition: drawquadset.cpp:38
static constexpr SkScalar kTileWidth
Definition: drawquadset.cpp:37
static constexpr int kRowCount
Definition: drawquadset.cpp:40
static constexpr int kColCount
Definition: drawquadset.cpp:41
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ draw_gradient_tiles()

static void draw_gradient_tiles ( SkCanvas canvas,
bool  alignGradients 
)
static

Definition at line 48 of file drawquadset.cpp.

48 {
49 // Always draw the same gradient
50 static constexpr SkPoint pts[] = { {0.f, 0.f}, {0.25f * kTileWidth, 0.25f * kTileHeight} };
51 static constexpr SkColor colors[] = { SK_ColorBLUE, SK_ColorWHITE };
52
54
55 auto rContext = canvas->recordingContext();
56
57 auto gradient = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kMirror);
59 paint.setShader(gradient);
60
61 for (int i = 0; i < kRowCount; ++i) {
62 for (int j = 0; j < kColCount; ++j) {
64 if (alignGradients) {
65 tile.offset(j * kTileWidth, i * kTileHeight);
66 } else {
67 canvas->save();
68 canvas->translate(j * kTileWidth, i * kTileHeight);
69 }
70
71 unsigned aa = SkCanvas::kNone_QuadAAFlags;
72 if (i == 0) {
74 }
75 if (i == kRowCount - 1) {
77 }
78 if (j == 0) {
80 }
81 if (j == kColCount - 1) {
83 }
84
85 if (sdc) {
86 // Use non-public API to leverage general GrPaint capabilities
87 const SkMatrix& view = canvas->getTotalMatrix();
88 SkSurfaceProps props;
89 GrPaint grPaint;
90 SkPaintToGrPaint(rContext, sdc->colorInfo(), paint, view, props, &grPaint);
91 sdc->fillRectWithEdgeAA(nullptr, std::move(grPaint),
92 static_cast<GrQuadAAFlags>(aa), view, tile);
93 } else {
94 // Fallback to solid color on raster backend since the public API only has color
95 SkColor color = alignGradients ? SK_ColorBLUE
96 : (i * kColCount + j) % 2 == 0 ? SK_ColorBLUE
99 tile, nullptr, static_cast<SkCanvas::QuadAAFlags>(aa), color,
101 }
102
103 if (!alignGradients) {
104 // Pop off the matrix translation when drawing unaligned
105 canvas->restore();
106 }
107 }
108 }
109}
GrQuadAAFlags
Definition: GrTypesPriv.h:247
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
bool SkPaintToGrPaint(GrRecordingContext *context, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition: SkGr.cpp:553
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ draw_text()

static void draw_text ( SkCanvas canvas,
const char *  text 
)
static

Definition at line 43 of file drawquadset.cpp.

43 {
45 canvas->drawString(text, 0, 0, font, SkPaint());
46}
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.

◆ draw_tile_boundaries()

static void draw_tile_boundaries ( SkCanvas canvas,
const SkMatrix local 
)
static

Definition at line 144 of file drawquadset.cpp.

144 {
145 // Draw grid of red lines at interior tile boundaries.
146 static constexpr SkScalar kLineOutset = 10.f;
148 paint.setAntiAlias(true);
149 paint.setColor(SK_ColorRED);
151 paint.setStrokeWidth(0.f);
152 for (int x = 1; x < kColCount; ++x) {
153 SkPoint pts[] = {{x * kTileWidth, 0}, {x * kTileWidth, kRowCount * kTileHeight}};
154 local.mapPoints(pts, 2);
155 SkVector v = pts[1] - pts[0];
156 v.setLength(v.length() + kLineOutset);
157 canvas->drawLine(pts[1] - v, pts[0] + v, paint);
158 }
159 for (int y = 1; y < kRowCount; ++y) {
160 SkPoint pts[] = {{0, y * kTileHeight}, {kTileWidth * kColCount, y * kTileHeight}};
161 local.mapPoints(pts, 2);
162 SkVector v = pts[1] - pts[0];
163 v.setLength(v.length() + kLineOutset);
164 canvas->drawLine(pts[1] - v, pts[0] + v, paint);
165 }
166}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
float SkScalar
Definition: extension.cpp:12
double y
double x
bool setLength(float length)
Definition: SkPoint.cpp:30
float length() const
Definition: SkPoint_impl.h:282

Variable Documentation

◆ kColCount

constexpr int kColCount = 3
staticconstexpr

Definition at line 41 of file drawquadset.cpp.

◆ kRowCount

constexpr int kRowCount = 4
staticconstexpr

Definition at line 40 of file drawquadset.cpp.

◆ kTileHeight

constexpr SkScalar kTileHeight = 30
staticconstexpr

Definition at line 38 of file drawquadset.cpp.

◆ kTileSetNames

const char* kTileSetNames[] = { "Local", "Aligned", "Green", "Multicolor" }
static

Definition at line 176 of file drawquadset.cpp.

◆ kTileSets

TileRenderer kTileSets[]
static
Initial value:
= {
[](SkCanvas* canvas) { draw_gradient_tiles(canvas, false); },
[](SkCanvas* canvas) { draw_gradient_tiles(canvas, true); },
[](SkCanvas* canvas) { draw_color_tiles(canvas, false); },
[](SkCanvas* canvas) { draw_color_tiles(canvas, true); },
}
static void draw_gradient_tiles(SkCanvas *canvas, bool alignGradients)
Definition: drawquadset.cpp:48
static void draw_color_tiles(SkCanvas *canvas, bool multicolor)

Definition at line 170 of file drawquadset.cpp.

◆ kTileWidth

constexpr SkScalar kTileWidth = 40
staticconstexpr

Definition at line 37 of file drawquadset.cpp.