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

Public Member Functions

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

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

Protected Member Functions

SkISize getISize () override
 
void onOnceBeforeDraw () override
 
SkString getName () const override
 
DrawResult onDraw (SkCanvas *canvas, SkString *error) 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
 

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 345 of file mesh.cpp.

Member Typedef Documentation

◆ Attribute

Definition at line 350 of file mesh.cpp.

◆ Varying

Definition at line 351 of file mesh.cpp.

Constructor & Destructor Documentation

◆ MeshColorSpaceGM()

skiagm::MeshColorSpaceGM::MeshColorSpaceGM ( )
inline

Definition at line 347 of file mesh.cpp.

347{}

Member Function Documentation

◆ getISize()

SkISize skiagm::MeshColorSpaceGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 353 of file mesh.cpp.

353{ return {468, 258}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 416 of file mesh.cpp.

416{ return SkString("custommesh_cs"); }

◆ onDraw()

DrawResult skiagm::MeshColorSpaceGM::onDraw ( SkCanvas canvas,
SkString error 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 418 of file mesh.cpp.

418 {
419 // Force an intermediate surface if the canvas is in "legacy" mode
420 SkCanvas* c = canvas;
422 if (!c->imageInfo().colorSpace()) {
424 surface = canvas->makeSurface(info);
425 if (!surface) {
426 // This GM won't work on configs that use a recording canvas.
427 return DrawResult::kSkip;
428 }
429 c = surface->getCanvas();
431 }
432 for (bool useShader : {false, true})
433 for (bool unpremul : {false, true}) {
434 c->save();
435 for (bool spin : {false, true}) {
436 auto result = SkMesh::Make(fSpecs[SpecIndex(unpremul, spin)],
438 fVB,
439 /*vertexCount=*/4,
440 /*vertexOffset=*/0,
441 /*uniforms=*/nullptr,
442 /*children=*/{},
443 kRect);
444 if (!result.mesh.isValid()) {
445 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
446 return DrawResult::kFail;
447 }
448
450 paint.setShader(useShader ? fShader : nullptr);
452 canvas->drawMesh(result.mesh, SkBlender::Mode(mode), paint);
453
454 c->translate(0, kRect.height() + 10);
455 }
456 c->restore();
457 c->translate(kRect.width() + 10, 0);
458 c->save();
459 }
460 if (surface) {
461 surface->draw(canvas, 0, 0);
462 }
463 return DrawResult::kOk;
464 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkBlendMode
Definition: SkBlendMode.h:38
@ kModulate
r = s*d
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkBlender > Mode(SkBlendMode mode)
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
void drawMesh(const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
Definition: SkCanvas.cpp:1739
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
static sk_sp< SkColorSpace > MakeSRGB()
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
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
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 mode
Definition: switches.h:228
SkColorSpace * colorSpace() const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
static sk_sp< SkColorFilter > spin(sk_sp< SkColorFilter > cf)

◆ onOnceBeforeDraw()

void skiagm::MeshColorSpaceGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 355 of file mesh.cpp.

355 {
356 static const Attribute kAttributes[]{
358 {Attribute::Type::kFloat4, 8, SkString{"color"}},
359 };
360 static const Varying kVaryings[]{
362 };
363 static constexpr char kPremulVS[] = R"(
364 Varyings main(const in Attributes attributes) {
365 Varyings varyings;
366 varyings.color = half4(attributes.color.a*attributes.color.rgb,
367 attributes.color.a);
368 varyings.position = attributes.pos;
369 return varyings;
370 }
371 )";
372 static constexpr char kUnpremulVS[] = R"(
373 Varyings main(const in Attributes attributes) {
374 Varyings varyings;
375 varyings.color = attributes.color;
376 varyings.position = attributes.pos;
377 return varyings;
378 }
379 )";
380 static constexpr char kFS[] = R"(
381 float2 main(in const Varyings varyings, out half4 color) {
382 color = varyings.color;
383 return varyings.position;
384 }
385 )";
386 for (bool unpremul : {false, true}) {
387 auto at = unpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType;
388 auto vs = unpremul ? kUnpremulVS : kPremulVS;
389 for (bool spin : {false, true}) {
390 auto cs = SkColorSpace::MakeSRGB();
391 if (spin) {
392 cs = cs->makeColorSpin();
393 }
394
395 auto [spec, error] = SkMeshSpecification::Make(
397 sizeof(Vertex),
398 kVaryings,
399 SkString(vs),
400 SkString(kFS),
401 std::move(cs),
402 at);
403 if (!spec) {
404 SkDebugf("%s\n", error.c_str());
405 }
406 fSpecs[SpecIndex(unpremul, spin)] = std::move(spec);
407 }
408 }
409 SkPoint pts[] = {{kRect.fLeft, 0}, {kRect.centerX(), 0}};
411 fShader = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kMirror);
412
413 fVB = SkMeshes::MakeVertexBuffer(kQuad, sizeof(kQuad));
414 }
kUnpremul_SkAlphaType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
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)
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
SK_API sk_sp< SkMesh::VertexBuffer > MakeVertexBuffer(const void *, size_t size)
Definition: SkMesh.cpp:905
PODArray< SkColor > colors
Definition: SkRecords.h:276
static const std::map< std::string, VerticesBuilder::AttributeType > kAttributes

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