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

Public Member Functions

 MeshUniformsGM ()
 
- 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
 
bool onAnimate (double nanos) 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 513 of file mesh.cpp.

Member Typedef Documentation

◆ Attribute

Definition at line 518 of file mesh.cpp.

◆ Varying

Definition at line 519 of file mesh.cpp.

Constructor & Destructor Documentation

◆ MeshUniformsGM()

skiagm::MeshUniformsGM::MeshUniformsGM ( )
inline

Definition at line 515 of file mesh.cpp.

515{ this->onAnimate(0); }
bool onAnimate(double nanos) override
Definition: mesh.cpp:633

Member Function Documentation

◆ getISize()

SkISize skiagm::MeshUniformsGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 521 of file mesh.cpp.

521{ return {140, 250}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 575 of file mesh.cpp.

575{ return SkString("custommesh_uniforms"); }

◆ onAnimate()

bool skiagm::MeshUniformsGM::onAnimate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 633 of file mesh.cpp.

633 {
634 fDegrees = TimeUtils::NanosToSeconds(nanos) * 360.f/10.f + 45.f;
635 // prime number periods, like locusts.
636 fColor.fR = TimeUtils::SineWave(nanos, 13.f, 0.f, 0.f, 1.f);
637 fColor.fG = TimeUtils::SineWave(nanos, 23.f, 5.f, 0.f, 1.f);
638 fColor.fB = TimeUtils::SineWave(nanos, 11.f, 0.f, 0.f, 1.f);
639 fColor.fA = 1.f;
640 return true;
641 }
static float SineWave(double time, float periodInSecs, float phaseInSecs, float min, float max)
Definition: TimeUtils.h:48
static double NanosToSeconds(double nanos)
Definition: TimeUtils.h:22

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 577 of file mesh.cpp.

577 {
578 SkMatrix matrices[] {
579 SkMatrix::MakeAll(-1, 0, 0, // self inverse so no effect.
580 0, -1, 0,
581 0, 0, 1),
582 SkMatrix::RotateDeg(fDegrees/2.f, {0.5f, 0.5f}),
583 };
584 for (const auto& m : matrices) {
585 auto unis = SkData::MakeUninitialized(fSpec->uniformSize());
586
587 SkPoint trans = -kCoordTrans;
588 static_assert(sizeof(SkPoint) == 2*sizeof(float));
589
590 const SkMeshSpecification::Uniform* u = fSpec->findUniform("t");
591 SkASSERT(u);
592 std::memcpy(SkTAddOffset<void>(unis->writable_data(), u->offset),
593 (void*)&trans,
594 2*sizeof(float));
595
596 u = fSpec->findUniform("m");
597 SkASSERT(u);
598 for (size_t offset = u->offset, col = 0; col < 3; ++col) {
599 for (size_t row = 0; row < 3; ++row, offset += sizeof(float)) {
600 *SkTAddOffset<float>(unis->writable_data(), offset) = m.rc(row, col);
601 }
602 }
603
604 u = fSpec->findUniform("color");
605 SkASSERT(u);
606 std::memcpy(SkTAddOffset<void>(unis->writable_data(), u->offset),
607 fColor.vec(),
608 4*sizeof(float));
609
610 auto result = SkMesh::Make(fSpec,
612 fVB,
613 /*vertexCount=*/4,
614 /*vertexOffset=*/0,
615 /*uniforms=*/std::move(unis),
616 /*children=*/{},
617 kRect);
618
619 if (!result.mesh.isValid()) {
620 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
621 return DrawResult::kFail;
622 }
623
625 paint.setShader(fShader);
627
628 canvas->translate(0, kRect.height() + 10);
629 }
630 return DrawResult::kOk;
631 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kModulate
r = s*d
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkBlender > Mode(SkBlendMode mode)
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawMesh(const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
Definition: SkCanvas.cpp:1739
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
const Uniform * findUniform(std::string_view name) const
Definition: SkMesh.cpp:647
size_t uniformSize() const
Definition: SkMesh.cpp:642
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
GAsyncResult * result
SeparatedVector2 offset

◆ onOnceBeforeDraw()

void skiagm::MeshUniformsGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 523 of file mesh.cpp.

523 {
524 static const Attribute kAttributes[]{
526 {Attribute::Type::kFloat2, 8, SkString{"coords"}},
527 };
528 static const Varying kVaryings[]{
529 {Varying::Type::kFloat2, SkString{"coords"}},
530 };
531 // To exercise shared VS/FS uniforms we have a matrix that is applied twice, once in each
532 // stage.
533 static constexpr char kVS[] = R"(
534 uniform float t[2];
535 uniform half3x3 m;
536 Varyings main(in const Attributes attributes) {
537 Varyings varyings;
538 varyings.coords = (m*float3(attributes.coords + float2(t[0], t[1]), 1)).xy;
539 varyings.position = attributes.pos;
540 return varyings;
541 }
542 )";
543 static constexpr char kFS[] = R"(
544 uniform half3x3 m;
545 layout(color) uniform half4 color;
546 float2 main(const Varyings varyings, out half4 c) {
547 c = color;
548 return (m*float3(varyings.coords, 1)).xy;
549 }
550 )";
551 auto [spec, error] =
553 sizeof(Vertex),
554 kVaryings,
555 SkString(kVS),
556 SkString(kFS),
559 if (!spec) {
560 SkDebugf("%s\n", error.c_str());
561 }
562 fSpec = std::move(spec);
563
565 fShader = SkGradientShader::MakeRadial(kGradCenter,
566 .4f,
567 colors,
568 nullptr,
569 2,
571
572 fVB = SkMeshes::MakeVertexBuffer(kQuad, sizeof(kQuad));
573 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static sk_sp< SkColorSpace > MakeSRGB()
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
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: