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

Public Member Functions

 MeshZeroInitGM ()=default
 
- 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
 
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 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 889 of file mesh.cpp.

Member Typedef Documentation

◆ Attribute

Definition at line 894 of file mesh.cpp.

◆ Varying

Definition at line 895 of file mesh.cpp.

Constructor & Destructor Documentation

◆ MeshZeroInitGM()

skiagm::MeshZeroInitGM::MeshZeroInitGM ( )
default

Member Function Documentation

◆ getISize()

SkISize skiagm::MeshZeroInitGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 897 of file mesh.cpp.

897{ return {90, 30}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 948 of file mesh.cpp.

948{ return SkString("mesh_zero_init"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 950 of file mesh.cpp.

950 {
953 if (rc && !dc) {
954 // On GPU this relies on using the DC to update the GPU backed vertex/index buffers.
955 return DrawResult::kSkip;
956 }
957
958 if (dc && dc->abandoned()) {
959 return DrawResult::kSkip;
960 }
961
962 static constexpr SkPoint kTri[]{{10, 10}, {20, 10}, {10, 20}};
963 // The zero will come from the uninit part of the buffer.
964 static constexpr uint16_t kTiIndices[]{1, 2};
965
966 // We test updating CPU and GPU buffers.
967 for (bool gpuBuffer : {false, true}) {
968 auto ctx = gpuBuffer ? dc : nullptr;
969 for (int i = 0; i < 2; ++i) {
970 const auto& spec = fSpec[i];
971
972 size_t posOffset = spec->findAttribute("pos")->offset;
973 auto vb = make_vertex_buffer(ctx, nullptr, spec->stride() * std::size(kTri));
974 SkASSERT(vb);
975 for (size_t j = 0; j < std::size(kTri); ++j) {
976 SkAssertResult(vb->update(ctx,
977 &kTri[j],
978 spec->stride()*j + posOffset,
979 sizeof(kTri[j])));
980 }
981
982 // The first time we make the indices be 0,1,2 using the zero'ed buffer for the
983 // first. However, because uploads must be 4 byte aligned it's actually 0,0,1,2.
984 // The second time we upload 1,2 to beginning of the buffer to form 1,2,0.
985 size_t indexUploadOffset = i == 0 ? 4 : 0;
986 size_t indexMeshOffset = i == 0 ? 2 : 0;
987
988 auto ib = make_index_buffer(ctx, nullptr, sizeof(uint16_t) * 4);
989 SkASSERT(ib);
990 SkAssertResult(ib->update(ctx, kTiIndices, indexUploadOffset, sizeof(kTiIndices)));
991
993 bounds.setBounds(kTri, std::size(kTri));
994 auto result = SkMesh::MakeIndexed(spec,
996 std::move(vb),
997 /*vertexCount=*/std::size(kTri),
998 /*vertexOffset=*/0,
999 std::move(ib),
1000 /*indexCount=*/std::size(kTiIndices) + 1,
1001 indexMeshOffset,
1002 /*uniforms=*/nullptr,
1003 /*children=*/{},
1004 bounds);
1005 if (!result.mesh.isValid()) {
1006 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
1007 return DrawResult::kFail;
1008 }
1009
1010 SkPaint paint;
1011 // The color will be transparent black. Set the blender to kDstOver so when combined
1012 // with the paint's opaque black we get opaque black.
1014 canvas->translate(bounds.width() + 10, 0);
1015 if (ctx) {
1016 // Free up the buffers for recycling in the cache. This helps test that
1017 // a recycled buffer gets zero'ed.
1018 result.mesh = {};
1019 SkASSERT(!ib); // NOLINT - bugprone-use-after-move. We're asserting it's moved.
1020 SkASSERT(!vb); // NOLINT
1021 ctx->flushAndSubmit(GrSyncCpu::kYes);
1022 }
1023 }
1024 }
1025
1026 return DrawResult::kOk;
1027 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kDstOver
r = d + (1-da)*s
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool abandoned() override
static sk_sp< SkBlender > Mode(SkBlendMode mode)
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
void drawMesh(const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
const Attribute * findAttribute(std::string_view name) const
Definition SkMesh.cpp:665
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
Optional< SkRect > bounds
Definition SkRecords.h:189
static sk_sp< SkMesh::VertexBuffer > make_vertex_buffer(GrDirectContext *ctx, const void *data, size_t size)
Definition mesh.cpp:493
static sk_sp< SkMesh::IndexBuffer > make_index_buffer(GrDirectContext *ctx, const void *data, size_t size)
Definition mesh.cpp:502

◆ onOnceBeforeDraw()

void skiagm::MeshZeroInitGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 899 of file mesh.cpp.

899 {
900 static const Attribute kAttributes1[]{
903 };
904 static const Attribute kAttributes2[]{
907 };
908 static const Varying kVaryings[]{{Varying::Type::kHalf4, SkString{"color"}}};
909 static constexpr char kVS[] = R"(
910 Varyings main(const in Attributes attributes) {
911 Varyings varyings;
912 varyings.color = attributes.color;
913 varyings.position = attributes.pos;
914 return varyings;
915 }
916 )";
917 static constexpr char kFS[] = R"(
918 float2 main(const Varyings varyings, out half4 color) {
919 color = varyings.color;
920 return varyings.position;
921 }
922 )";
923 auto result = SkMeshSpecification::Make(kAttributes1,
924 /*vertexStride==*/12,
925 kVaryings,
926 SkString(kVS),
927 SkString(kFS),
930 if (!result.specification) {
931 SkDebugf("%s\n", result.error.c_str());
932 }
933 fSpec[0] = std::move(result.specification);
934
935 result = SkMeshSpecification::Make(kAttributes1,
936 /*vertexStride=*/12,
937 kVaryings,
938 SkString(kVS),
939 SkString(kFS),
942 if (!result.specification) {
943 SkDebugf("%s\n", result.error.c_str());
944 }
945 fSpec[1] = std::move(result.specification);
946 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
static sk_sp< SkColorSpace > MakeSRGB()
static Result Make(SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs)
Definition SkMesh.cpp:389

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