Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | List of all members
skiagm::MeshGM Class Reference
Inheritance diagram for skiagm::MeshGM:
skiagm::GM

Public Member Functions

 MeshGM ()
 
- 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 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

using Attribute = SkMeshSpecification::Attribute
 
using Varying = SkMeshSpecification::Varying
 

Protected Member Functions

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

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

Definition at line 33 of file mesh.cpp.

Member Typedef Documentation

◆ Attribute

Definition at line 38 of file mesh.cpp.

◆ Varying

Definition at line 39 of file mesh.cpp.

Constructor & Destructor Documentation

◆ MeshGM()

skiagm::MeshGM::MeshGM ( )
inline

Definition at line 35 of file mesh.cpp.

35{}

Member Function Documentation

◆ getISize()

SkISize skiagm::MeshGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 41 of file mesh.cpp.

41{ return {435, 1180}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 147 of file mesh.cpp.

147{ return SkString("custommesh"); }

◆ onDraw()

DrawResult skiagm::MeshGM::onDraw ( SkCanvas canvas,
SkString  
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 149 of file mesh.cpp.

149 {
150 SkRuntimeEffect::ChildPtr nullChild[1] = {};
151 int i = 0;
152 for (const sk_sp<SkBlender>& blender : {SkBlender::Mode(SkBlendMode::kDst),
155 canvas->save();
156 for (uint8_t alpha : {0xFF , 0x40})
157 for (bool colors : {false, true})
158 for (bool shader : {false, true}) {
160 // Rather than pile onto the combinatorics we draw every other test case indexed.
161 if ((i & 1) == 0) {
162 if (colors) {
163 result = SkMesh::Make(fSpecWithColor,
165 fColorVB,
166 /*vertexCount=*/4,
167 /*vertexOffset=*/0,
168 /*uniforms=*/nullptr,
169 /*children=*/nullChild,
170 kRect);
171 } else {
172 result = SkMesh::Make(fSpecWithNoColor,
174 fNoColorVB,
175 /*vertexCount=*/4,
176 kNoColorOffset,
177 /*uniforms=*/nullptr,
178 /*children=*/{},
179 kRect);
180 }
181 } else {
182 // Alternate between CPU and GPU-backend index buffers.
183 auto ib = (i % 4 == 0) ? fIB[0] : fIB[1];
184 if (colors) {
185 result = SkMesh::MakeIndexed(fSpecWithColor,
187 fColorIndexedVB,
188 /*vertexCount=*/6,
189 kColorIndexedOffset,
190 std::move(ib),
191 /*indexCount=*/6,
192 kIndexOffset,
193 /*uniforms=*/nullptr,
194 /*children=*/nullChild,
195 kRect);
196 } else {
197 result = SkMesh::MakeIndexed(fSpecWithNoColor,
199 fNoColorIndexedVB,
200 /*vertexCount=*/6,
201 /*vertexOffset=*/0,
202 std::move(ib),
203 /*indexCount=*/6,
204 kIndexOffset,
205 /*uniforms=*/nullptr,
206 /*children=*/{},
207 kRect);
208 }
209 }
210 if (!result.mesh.isValid()) {
211 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
212 return DrawResult::kFail;
213 }
214
216 paint.setColor(SK_ColorGREEN);
217 paint.setShader(shader ? fShader : nullptr);
218 paint.setAlpha(alpha);
219
220 canvas->drawMesh(result.mesh, blender, paint);
221
222 canvas->translate(0, 150);
223 ++i;
224 }
225 canvas->restore();
226 canvas->translate(150, 0);
227 }
228 return DrawResult::kOk;
229 }
@ kSaturation
saturation of source with hue and luminosity of destination
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkBlender > Mode(SkBlendMode mode)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void drawMesh(const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
int save()
Definition SkCanvas.cpp:451
static Result Make(sk_sp< SkMeshSpecification >, Mode, sk_sp< VertexBuffer >, size_t vertexCount, size_t vertexOffset, sk_sp< const SkData > uniforms, SkSpan< ChildPtr > children, const SkRect &bounds)
Definition SkMesh.cpp:694
static Result MakeIndexed(sk_sp< SkMeshSpecification >, Mode, sk_sp< VertexBuffer >, size_t vertexCount, size_t vertexOffset, sk_sp< IndexBuffer >, size_t indexCount, size_t indexOffset, sk_sp< const SkData > uniforms, SkSpan< ChildPtr > children, const SkRect &bounds)
Definition SkMesh.cpp:718
const Paint & paint
GAsyncResult * result

◆ onGpuSetup()

DrawResult skiagm::MeshGM::onGpuSetup ( SkCanvas canvas,
SkString string,
GraphiteTestContext  
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 123 of file mesh.cpp.

123 {
124 auto dc = GrAsDirectContext(canvas->recordingContext());
125 this->ensureBuffers();
126 if (!dc || dc->abandoned()) {
127 return DrawResult::kOk;
128 }
129
130 fColorVB = SkMeshes::CopyVertexBuffer(dc, fColorVB);
131 fColorIndexedVB = SkMeshes::CopyVertexBuffer(dc, fColorIndexedVB);
132 fIB[1] = SkMeshes::CopyIndexBuffer (dc, fIB[0]);
133 if (!fColorVB || !fColorIndexedVB || !fIB[1]) {
134 return DrawResult::kFail;
135 }
136 return DrawResult::kOk;
137 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
virtual GrRecordingContext * recordingContext() const
SK_API sk_sp< SkMesh::IndexBuffer > CopyIndexBuffer(const sk_sp< SkMesh::IndexBuffer > &)
Definition SkMesh.cpp:893
SK_API sk_sp< SkMesh::VertexBuffer > CopyVertexBuffer(const sk_sp< SkMesh::VertexBuffer > &)
Definition SkMesh.cpp:909

◆ onGpuTeardown()

void skiagm::MeshGM::onGpuTeardown ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 139 of file mesh.cpp.

139 {
140 // Destroy the GPU buffers and recreate on CPU
141 fColorVB = nullptr;
142 fColorIndexedVB = nullptr;
143 fIB[1] = nullptr;
144 this->ensureBuffers();
145 }

◆ onOnceBeforeDraw()

void skiagm::MeshGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 43 of file mesh.cpp.

43 {
44 {
45 static const Attribute kAttributes[]{
48 };
49 static const Varying kVaryings[]{
52 };
53 static constexpr char kVS[] = R"(
54 half4 unswizzle_color(half4 color) { return color.garb; }
55
56 Varyings main(const in Attributes attributes) {
57 Varyings varyings;
58 varyings.color = unswizzle_color(attributes.brag);
59 varyings.uv = attributes.xuyv.yw;
60 varyings.position = attributes.xuyv.xz;
61 return varyings;
62 }
63 )";
64 static constexpr char kFS[] = R"(
65 uniform colorFilter filter;
66
67 float2 main(const in Varyings varyings, out float4 color) {
68 color = filter.eval(varyings.color);
69 return varyings.uv;
70 }
71 )";
72 auto [spec, error] = SkMeshSpecification::Make(kAttributes,
73 sizeof(ColorVertex),
74 kVaryings,
75 SkString(kVS),
76 SkString(kFS));
77 if (!spec) {
78 SkDebugf("%s\n", error.c_str());
79 }
80 fSpecWithColor = std::move(spec);
81 }
82 {
83 static const Attribute kAttributes[]{
85 };
86 static const Varying kVaryings[]{
88 };
89 static constexpr char kVS[] = R"(
90 Varyings main(const in Attributes a) {
91 Varyings v;
92 v.vux2 = 2*a.xuyv.wy;
93 v.position = a.xuyv.xz;
94 return v;
95 }
96 )";
97 static constexpr char kFS[] = R"(
98 float2 helper(in float2 vux2) { return vux2.yx/2; }
99 float2 main(const in Varyings varyings) {
100 return helper(varyings.vux2);
101 }
102 )";
103 auto [spec, error] = SkMeshSpecification::Make(kAttributes,
104 sizeof(NoColorVertex),
105 kVaryings,
106 SkString(kVS),
107 SkString(kFS));
108 if (!spec) {
109 SkDebugf("%s\n", error.c_str());
110 }
111 fSpecWithNoColor = std::move(spec);
112 }
113
114 static constexpr SkColor kColors[] = {SK_ColorTRANSPARENT, SK_ColorWHITE};
115 fShader = SkGradientShader::MakeRadial({10, 10},
116 3,
117 kColors,
118 nullptr,
119 2,
121 }
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static Result Make(SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs)
Definition SkMesh.cpp:389
const uint8_t uint32_t uint32_t GError ** error
const DlColor kColors[]

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