146 {
148
149 ImGui::Begin("SkSL", nullptr, ImGuiWindowFlags_AlwaysVerticalScrollbar);
150
151
152 ImGuiInputTextFlags
flags = ImGuiInputTextFlags_CallbackResize;
153 ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * 30);
154 if (ImGui::InputTextMultiline(
"Code", fSkSL.
data(), fSkSL.
size() + 1, boxSize,
flags,
156 fCodeIsDirty = true;
157 }
158
159 if (ImGui::Checkbox("ShaderToy Uniforms (iResolution/iTime/iMouse)", &fShadertoyUniforms)) {
160 fCodeIsDirty = true;
161 }
162
163 if (fCodeIsDirty || !fEffect) {
164 this->rebuild();
165 }
166
167 if (!fEffect) {
168 ImGui::End();
169 return;
170 }
171
172 bool writeTrace = false;
173 bool writeDump = false;
175 ImGui::InputInt2("Trace Coordinate (X/Y)", fTraceCoord);
176 writeTrace = ImGui::Button("Write Debug Trace (JSON)");
177 writeDump = ImGui::Button("Write Debug Dump (Human-Readable)");
178 }
179
180
181 ImVec2 mousePos = ImGui::GetMousePos();
182 if (ImGui::IsMouseDown(0)) {
183 fMousePos.
x = mousePos.x;
184 fMousePos.
y = mousePos.y;
185 }
186 if (ImGui::IsMouseClicked(0)) {
187 fMousePos.
z = mousePos.x;
188 fMousePos.
w = mousePos.y;
189 }
190 fMousePos.
z =
std::abs(fMousePos.
z) * (ImGui::IsMouseDown(0) ? 1 : -1);
191 fMousePos.
w =
std::abs(fMousePos.
w) * (ImGui::IsMouseClicked(0) ? 1 : -1);
192
194 char*
data = fInputs.
get() + v.offset;
195 if (v.name == "iResolution") {
196 memcpy(
data, &fResolution,
sizeof(fResolution));
197 continue;
198 }
199 if (v.name == "iTime") {
200 memcpy(
data, &fSeconds,
sizeof(fSeconds));
201 continue;
202 }
203 if (v.name == "iMouse") {
204 memcpy(
data, &fMousePos,
sizeof(fMousePos));
205 continue;
206 }
207 switch (v.type) {
213 float*
f =
reinterpret_cast<float*
>(
data);
214 for (
int c = 0; c < v.count; ++c,
f += rows) {
216 ?
SkStringPrintf(
"%.*s[%d]", (
int)v.name.size(), v.name.data(), c)
218 ImGui::PushID(c);
219 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_Float,
f, rows, 1.0f);
220 ImGui::PopID();
221 }
222 break;
223 }
228 int cols = rows;
229 float*
f =
reinterpret_cast<float*
>(
data);
230 for (
int e = 0;
e < v.count; ++
e) {
231 for (
int c = 0; c < cols; ++c,
f += rows) {
233 ?
SkStringPrintf(
"%.*s[%d][%d]", (
int)v.name.size(), v.name.data(),
e, c)
235 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_Float,
f, rows, 1.0f);
236 }
237 }
238 break;
239 }
245 int*
i =
reinterpret_cast<int*
>(
data);
246 for (
int c = 0; c < v.count; ++c,
i += rows) {
248 ?
SkStringPrintf(
"%.*s[%d]", (
int)v.name.size(), v.name.data(), c)
250 ImGui::PushID(c);
251 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_S32,
i, rows, 1.0f);
252 ImGui::PopID();
253 }
254 break;
255 }
256 }
257 }
258
260 auto curShader = std::find_if(
263 [tgt = fChildren[c.index]](
const std::pair<
const char*,
sk_sp<SkShader>>&
p) {
264 return p.second == tgt;
265 });
267
268 if (ImGui::BeginCombo(std::string(c.name).c_str(), curShader->first)) {
269 for (const auto& namedShader : fShaders) {
270 if (ImGui::Selectable(namedShader.first, curShader->second == namedShader.second)) {
271 fChildren[c.index] = namedShader.second;
272 }
273 }
274 ImGui::EndCombo();
275 }
276 }
277
278 static SkColor4f gPaintColor { 1.0f, 1.0f, 1.0f , 1.0f };
279 ImGui::ColorEdit4("Paint Color", gPaintColor.vec());
280
281 ImGui::RadioButton("Fill", &fGeometry, kFill); ImGui::SameLine();
282 ImGui::RadioButton("Circle", &fGeometry, kCircle); ImGui::SameLine();
283 ImGui::RadioButton("RoundRect", &fGeometry, kRoundRect); ImGui::SameLine();
284 ImGui::RadioButton("Capsule", &fGeometry, kCapsule); ImGui::SameLine();
285 ImGui::RadioButton("Text", &fGeometry, kText);
286
287 ImGui::End();
288
290
292
295 if (writeTrace || writeDump) {
296 SkIPoint traceCoord = {fTraceCoord[0], fTraceCoord[1]};
298 traceCoord);
299 shader = std::move(traced.
shader);
301
302
303
304
305
311 }
313 p.setColor4f(gPaintColor);
314 p.setShader(std::move(shader));
315
316 switch (fGeometry) {
317 case kFill:
319 break;
320 case kCircle:
322 break;
323 case kRoundRect:
325 break;
326 case kCapsule:
328 break;
329 case kText: {
334 } break;
335 default: break;
336 }
337
339
340 if (debugTrace && writeTrace) {
343 }
344 if (debugTrace && writeDump) {
346 debugTrace->
dump(&dumpFile);
347 }
348}
constexpr SkColor SK_ColorWHITE
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static int InputTextCallback(ImGuiInputTextCallbackData *data)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
virtual GrRecordingContext * recordingContext() const
void drawPaint(const SkPaint &paint)
SkM44 getLocalToDevice() const
void clear(SkColor color)
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
void setMatrix(const SkM44 &matrix)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
size_t uniformSize() const
SkSpan< const Child > children() const
sk_sp< SkShader > makeShader(sk_sp< const SkData > uniforms, sk_sp< SkShader > children[], size_t childCount, const SkMatrix *localMatrix=nullptr) const
SkSpan< const Uniform > uniforms() const
static TracedShader MakeTraced(sk_sp< SkShader > shader, const SkIPoint &traceCoord)
virtual void writeTrace(SkWStream *w) const =0
virtual void dump(SkWStream *o) const =0
const char * data() const
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library name
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
font
Font Metadata and Metrics.
SIN Vec< N, float > abs(const Vec< N, float > &x)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
sk_sp< SkSL::DebugTrace > debugTrace
std::shared_ptr< const fml::Mapping > data