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

Public Member Functions

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

Member Typedef Documentation

◆ Attribute

Definition at line 1042 of file mesh.cpp.

◆ Varying

Definition at line 1043 of file mesh.cpp.

Constructor & Destructor Documentation

◆ PictureMesh()

skiagm::PictureMesh::PictureMesh ( )
default

Member Function Documentation

◆ getISize()

SkISize skiagm::PictureMesh::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 1045 of file mesh.cpp.

1045{ return {390, 90}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 1110 of file mesh.cpp.

1110{ return SkString("picture_mesh"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 1112 of file mesh.cpp.

1112 {
1113 SkPaint paint;
1114 paint.setShader(fShader);
1115
1116 auto dc = GrAsDirectContext(canvas->recordingContext());
1117 for (bool picture : {false, true}) {
1118 canvas->save();
1119 for (bool gpu : {false, true}) {
1120 auto vb = gpu ? SkMeshes::CopyVertexBuffer(dc, fVB) : fVB;
1121 auto ib = gpu ? SkMeshes::CopyIndexBuffer (dc, fIB) : fIB;
1122
1123 float offset[2] = {8, 8};
1124 for (size_t i = 0; i < 4; ++i) {
1125 auto uniforms = SkData::MakeWithCopy(&offset, sizeof(offset));
1127 switch (i) {
1128 case 0:
1129 r = SkMesh::Make(fSpec,
1131 fVB,
1132 6,
1133 1 * sizeof(Vertex),
1134 std::move(uniforms),
1135 /*children=*/{},
1136 kRect);
1137 break;
1138 case 1:
1139 r = SkMesh::Make(fSpec,
1141 fVB,
1142 4,
1143 1 * sizeof(Vertex),
1144 std::move(uniforms),
1145 /*children=*/{},
1146 kRect);
1147 break;
1148 case 2:
1149 r = SkMesh::MakeIndexed(fSpec,
1151 fVB,
1152 std::size(kQuad),
1153 0,
1154 fIB,
1155 6,
1156 2 * (sizeof(uint16_t)),
1157 std::move(uniforms),
1158 /*children=*/{},
1159 kRect);
1160 break;
1161 case 3:
1162 r = SkMesh::MakeIndexed(fSpec,
1164 fVB,
1165 std::size(kQuad),
1166 0,
1167 fIB,
1168 6,
1169 2 * sizeof(uint16_t),
1170 std::move(uniforms),
1171 /*children=*/{},
1172 kRect);
1173 break;
1174 }
1175
1176 if (!r.mesh.isValid()) {
1177 *error = r.error;
1178 return DrawResult::kFail;
1179 }
1180
1181 auto draw = [&](SkCanvas* c) {
1183 };
1184 if (picture) {
1185 SkPictureRecorder recorder;
1186 draw(recorder.beginRecording(SkRect::Make(this->getISize()),
1187 /*bbhFactory=*/nullptr));
1188 canvas->drawPicture(recorder.finishRecordingAsPicture());
1189 } else {
1190 draw(canvas);
1191 }
1192 offset[i%2] *= -1;
1193 canvas->translate(kRect.width() + 10, 0);
1194 }
1195 }
1196 canvas->restore();
1197 canvas->translate(0, kRect.height() + 10);
1198 }
1199 return DrawResult::kOk;
1200 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
static sk_sp< SkBlender > Mode(SkBlendMode mode)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
int save()
Definition SkCanvas.cpp:451
void drawPicture(const SkPicture *picture)
Definition SkCanvas.h:1961
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
bool isValid() const
Definition SkMesh.cpp:753
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
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
DrawResult draw(SkCanvas *canvas)
Definition gm.h:140
const Paint & paint
const uint8_t uint32_t uint32_t GError ** error
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
Point offset
SkString error
Definition SkMesh.h:395
SkMesh mesh
Definition SkMesh.h:395
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ onOnceBeforeDraw()

void skiagm::PictureMesh::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 1047 of file mesh.cpp.

1047 {
1048 static const Attribute kAttributes[]{
1050 };
1051 static const Varying kVaryings[]{
1052 {Varying::Type::kFloat2, SkString{"coords"}},
1053 };
1054 static constexpr char kVS[] = R"(
1055 Varyings main(in const Attributes attributes) {
1056 Varyings varyings;
1057 varyings.position = attributes.pos;
1058 return varyings;
1059 }
1060 )";
1061 static const SkString kFS = SkStringPrintf(R"(
1062 uniform float2 offset;
1063 float2 main(const Varyings varyings, out float4 color) {
1064 float2 tl = float2(%f, %f);
1065 float2 wh = float2(%f, %f);
1066 float2 c = tl + wh/2;
1067 float r = length(wh)/4;
1068 color.rba = float3(1);
1069 color.g = min(1, length(varyings.position - c + offset) / r);
1070 return varyings.position;
1071 }
1072 )", kRect.x(), kRect.y(), kRect.width(), kRect.height());
1073 auto [spec, error] =
1074 SkMeshSpecification::Make(kAttributes,
1075 sizeof(Vertex),
1076 kVaryings,
1077 SkString(kVS),
1078 kFS,
1079 SkColorSpace::MakeSRGB()->makeColorSpin(),
1081 if (!spec) {
1082 SkDebugf("%s\n", error.c_str());
1083 }
1084 fSpec = std::move(spec);
1085
1086 fVB = SkMeshes::MakeVertexBuffer(kQuad, sizeof(kQuad));
1087 fIB = SkMeshes::MakeIndexBuffer(kIndices, sizeof(kIndices));
1088
1089 SkRandom random;
1090 SkColor4f colors[6];
1091 for (size_t i = 0; i < std::size(colors) - 1; ++i) {
1092 colors[i] = {random.nextF(), random.nextF(), random.nextF(), 1.f};
1093 }
1094 colors[std::size(colors) - 1] = colors[0];
1095 SkPaint paint;
1096 SkGradientShader::Interpolation interpolation;
1098 fShader = SkGradientShader::MakeSweep(kRect.centerX(), kRect.centerY(),
1099 colors,
1101 nullptr,
1102 std::size(colors),
1104 0,
1105 360.f,
1106 interpolation,
1107 /*localMatrix=*/nullptr);
1108 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
static Result Make(SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs)
Definition SkMesh.cpp:389
float nextF()
Definition SkRandom.h:55
SK_API sk_sp< SkMesh::IndexBuffer > MakeIndexBuffer(const void *data, size_t size)
Definition SkMesh.cpp:889
SK_API sk_sp< SkMesh::VertexBuffer > MakeVertexBuffer(const void *, size_t size)
Definition SkMesh.cpp:905
PODArray< SkColor > colors
Definition SkRecords.h:276

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