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

Public Member Functions

 MeshUpdateGM ()=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 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 678 of file mesh.cpp.

Member Typedef Documentation

◆ Attribute

Definition at line 683 of file mesh.cpp.

◆ Varying

Definition at line 684 of file mesh.cpp.

Constructor & Destructor Documentation

◆ MeshUpdateGM()

skiagm::MeshUpdateGM::MeshUpdateGM ( )
default

Member Function Documentation

◆ getISize()

SkISize skiagm::MeshUpdateGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 686 of file mesh.cpp.

686{ return {270, 490}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 727 of file mesh.cpp.

727{ return SkString("mesh_updates"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 729 of file mesh.cpp.

729 {
730 canvas->clear(SK_ColorBLACK);
731
734 if (rc && !dc) {
735 // On GPU this relies on using the DC to update the GPU backed vertex/index buffers.
736 return DrawResult::kSkip;
737 }
738
739 if (dc && dc->abandoned()) {
740 return DrawResult::kSkip;
741 }
742
744 paint.setShader(fShader);
745
746 SkRect r = SkRect::MakeXYWH(10.f, 10.f, 50.f, 50.f);
747
748 // We test updating CPU and GPU buffers.
749 for (bool gpuBuffer : {false, true}) {
750 auto ctx = gpuBuffer ? dc : nullptr;
751
752 // How many rects worth of storage is in the vertex buffer?
753 static constexpr int kVBRects = 2;
754
755 // How many times do we update the vertex buffer? Wraps to start of buffer if
756 // > kVBRects.
757 static constexpr int kUpdatesRects = 3;
758
759 auto vb = make_vertex_buffer(ctx, /*data=*/nullptr, kVBRects * 6 * sizeof(Vertex));
760 SkASSERT(vb);
761
763 for (int i = 0; i < kUpdatesRects; ++i) {
764 auto p = r.makeOffset(100.f*i, 0.f);
765 if (i) {
766 bounds.join(p);
767 } else {
768 bounds = p;
769 }
770
771 SkPoint t[4];
772 SkRect::MakeWH(2.f, 2.f).toQuad(t);
773 SkMatrix::RotateDeg(90.f*i, {1.f, 1.f}).mapPoints(t, std::size(t));
774
775 Vertex vertices[6];
776 vertices[0] = {{p.left(), p.top()}, t[0]};
777 vertices[1] = {{p.left(), p.bottom()}, t[3]};
778 vertices[2] = {{p.right(), p.top()}, t[1]};
779 vertices[3] = vertices[2];
780 vertices[4] = vertices[1];
781 vertices[5] = {{p.right(), p.bottom()}, t[2]};
782
783 size_t offset = 6*(i % kVBRects)*sizeof(Vertex);
784 SkAssertResult(vb->update(ctx, vertices, offset, 6*sizeof(Vertex)));
785 // Make there aren't accidentally deferred reads of the client data.
786 std::memset(vertices, 0, sizeof(vertices));
787
788 int rectCount = std::min(i + 1, kVBRects);
789 auto result = SkMesh::Make(fSpec,
791 vb,
792 /*vertexCount=*/6 * rectCount,
793 /*vertexOffset=*/0,
794 /*uniforms=*/nullptr,
795 /*children=*/{},
796 bounds);
797
798 if (!result.mesh.isValid()) {
799 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
800 return DrawResult::kFail;
801 }
802
804
805 canvas->translate(0, r.height() + 10);
806 }
807
808 // Now test updating an IB.
809
810 // How many rects worth of storage is in the index buffer?
811 static constexpr int kIBRects = 2;
812
813 // How many times do we update the index buffer? Wraps to start of buffer if > kIBRects.
814 static constexpr int kNumIBUpdates = 3;
815
816 // Make the vertex buffer large enough to hold all the rects and populate.
817 vb = make_vertex_buffer(ctx, /*data=*/nullptr, kNumIBUpdates * 4 * sizeof(Vertex));
818 SkASSERT(vb);
819 for (int i = 0; i < kNumIBUpdates; ++i) {
820 SkPoint p[4];
821 auto rect = r.makeOffset(100*i, 0);
822 rect.toQuad(p);
823 if (i) {
824 bounds.join(rect);
825 } else {
826 bounds = rect;
827 }
828
829 SkPoint t[4];
830 SkRect::MakeWH(2.f, 2.f).toQuad(t);
831 SkMatrix::RotateDeg(90.f*i, {1.f, 1.f}).mapPoints(t, std::size(t));
832 Vertex vertices[4]{{p[0], t[0]}, {p[1], t[1]}, {p[2], t[2]}, {p[3], t[3]}};
834 vb->update(ctx, vertices, i*4*sizeof(Vertex), 4*sizeof(Vertex)));
835 }
836
837 auto ib = make_index_buffer(
838 ctx, /*data=*/nullptr, kIBRects * 6 * sizeof(uint16_t));
839 SkASSERT(ib);
840 for (int i = 0; i < kNumIBUpdates; ++i) {
841 uint16_t indices[6] = {SkToU16(0 + 4*i),
842 SkToU16(3 + 4*i),
843 SkToU16(1 + 4*i),
844 SkToU16(1 + 4*i),
845 SkToU16(3 + 4*i),
846 SkToU16(2 + 4*i)};
847 size_t offset = 6*(i % kIBRects)*sizeof(uint16_t);
848 SkAssertResult(ib->update(ctx, indices, offset, 6*sizeof(uint16_t)));
849 std::memset(indices, 0, 6*sizeof(uint16_t));
850
851 auto result = SkMesh::MakeIndexed(fSpec,
853 vb,
854 /*vertexCount=*/4 * kNumIBUpdates,
855 /*vertexOffset=*/0,
856 ib,
857 /*indexCount=*/6,
858 /*indexOffset=*/offset,
859 /*uniforms=*/nullptr,
860 /*children=*/{},
861 bounds);
862
863 if (!result.mesh.isValid()) {
864 SkDebugf("Mesh creation failed: %s\n", result.error.c_str());
865 return DrawResult::kFail;
866 }
867
869 }
870 canvas->translate(0, r.height() + 10);
871 }
872
873 return DrawResult::kOk;
874 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
constexpr uint16_t SkToU16(S x)
Definition: SkTo.h:24
bool abandoned() override
static sk_sp< SkBlender > Mode(SkBlendMode mode)
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawMesh(const SkMesh &mesh, sk_sp< SkBlender > blender, const SkPaint &paint)
Definition: SkCanvas.cpp:1739
void clear(SkColor color)
Definition: SkCanvas.h:1199
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104
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
Definition: color_source.cc:38
GAsyncResult * result
static float min(float r, float g, float b)
Definition: hsl.cpp:48
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
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
SeparatedVector2 offset
void toQuad(SkPoint quad[4]) const
Definition: SkRect.cpp:50
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
constexpr float height() const
Definition: SkRect.h:769
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ onOnceBeforeDraw()

void skiagm::MeshUpdateGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 688 of file mesh.cpp.

688 {
689 static const Attribute kAttributes[]{
691 {Attribute::Type::kFloat2, 8, SkString{"coords"}},
692 };
693 static const Varying kVaryings[]{
694 {Varying::Type::kFloat2, SkString{"coords"}},
695 };
696 static constexpr char kVS[] = R"(
697 Varyings main(const in Attributes attributes) {
698 Varyings varyings;
699 varyings.coords = attributes.coords;
700 varyings.position = attributes.pos;
701 return varyings;
702 }
703 )";
704 static constexpr char kFS[] = R"(
705 float2 main(const Varyings varyings) { return varyings.coords; }
706 )";
708 sizeof(Vertex),
709 kVaryings,
710 SkString(kVS),
711 SkString(kFS),
714 if (!spec) {
715 SkDebugf("%s\n", error.c_str());
716 }
717 fSpec = std::move(spec);
718
721 colors,
722 /*rowBytes=*/8);
725 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
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< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
PODArray< SkColor > colors
Definition: SkRecords.h:276
static const std::map< std::string, VerticesBuilder::AttributeType > kAttributes
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

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