Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 107c666

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Make it safe to include SkRuntimeEffect.h from client code
Bundling the pipeline stage arguments also simplifies the code in several spots. Change-Id: I85e81b436a39378f753cc9404b6eeb27fe055525 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261778 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
1 parent 60b69ec commit 107c666

File tree

8 files changed

+31
-27
lines changed

8 files changed

+31
-27
lines changed

fuzz/oss_fuzz/FuzzSKSL2Pipeline.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
1414
SkSL::Compiler compiler;
15-
SkSL::String output;
1615
SkSL::Program::Settings settings;
1716
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
1817
settings.fCaps = caps.get();
@@ -21,9 +20,8 @@ bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
2120
SkSL::String((const char*) bytes->data(),
2221
bytes->size()),
2322
settings);
24-
std::vector<SkSL::Compiler::FormatArg> formatArgs;
25-
std::vector<SkSL::Compiler::GLSLFunction> functions;
26-
if (!program || !compiler.toPipelineStage(*program, &output, &formatArgs, &functions)) {
23+
SkSL::PipelineStageArgs args;
24+
if (!program || !compiler.toPipelineStage(*program, &args)) {
2725
return false;
2826
}
2927
return true;

modules/canvaskit/canvaskit_bindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "src/core/SkFontMgrPriv.h"
5454
#include "src/core/SkResourceCache.h"
5555
#include "src/core/SkRuntimeEffect.h"
56+
#include "src/sksl/SkSLCompiler.h"
5657

5758
#include <iostream>
5859
#include <string>

src/core/SkRuntimeEffect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ size_t SkRuntimeEffect::inputSize() const {
182182

183183
#if SK_SUPPORT_GPU
184184
bool SkRuntimeEffect::toPipelineStage(const void* inputs, const GrShaderCaps* shaderCaps,
185-
SkSL::String* outCode,
186-
std::vector<SkSL::Compiler::FormatArg>* outFormatArgs,
187-
std::vector<SkSL::Compiler::GLSLFunction>* outFunctions) {
185+
SkSL::PipelineStageArgs* outArgs) {
188186
// This function is used by the GPU backend, and can't reuse our previously built fBaseProgram.
189187
// If the supplied shaderCaps have any non-default values, we have baked in the wrong settings.
190188
SkSL::Program::Settings settings;
@@ -233,7 +231,7 @@ bool SkRuntimeEffect::toPipelineStage(const void* inputs, const GrShaderCaps* sh
233231
return false;
234232
}
235233

236-
if (!fCompiler->toPipelineStage(*specialized, outCode, outFormatArgs, outFunctions)) {
234+
if (!fCompiler->toPipelineStage(*specialized, outArgs)) {
237235
SkDebugf("%s\n", fCompiler->errorText().c_str());
238236
SkASSERT(false);
239237
return false;

src/core/SkRuntimeEffect.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
#define SkRuntimeEffect_DEFINED
1010

1111
#include "include/core/SkString.h"
12-
#include "src/sksl/SkSLCompiler.h"
1312

1413
#include <vector>
1514

15+
#if SK_SUPPORT_GPU
16+
#include "include/private/GrTypesPriv.h"
17+
#endif
18+
1619
class GrShaderCaps;
1720
class SkMatrix;
1821
class SkShader;
1922

2023
namespace SkSL {
2124
class ByteCode;
25+
class Compiler;
26+
struct PipelineStageArgs;
2227
struct Program;
2328
}
2429

@@ -79,9 +84,7 @@ class SkRuntimeEffect : public SkRefCnt {
7984
// This re-compiles the program from scratch, using the supplied shader caps.
8085
// This is necessary to get the correct values of settings.
8186
bool toPipelineStage(const void* inputs, const GrShaderCaps* shaderCaps,
82-
SkSL::String* outCode,
83-
std::vector<SkSL::Compiler::FormatArg>* outFormatArgs,
84-
std::vector<SkSL::Compiler::GLSLFunction>* outFunctions);
87+
SkSL::PipelineStageArgs* outArgs);
8588
#endif
8689

8790
// [ByteCode, ErrorText]

src/gpu/effects/GrSkSLFP.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) {
217217

218218
GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {
219219
// Note: This is actually SkSL (again) but with inline format specifiers.
220-
SkSL::String code;
221-
std::vector<SkSL::Compiler::FormatArg> formatArgs;
222-
std::vector<SkSL::Compiler::GLSLFunction> functions;
223-
SkAssertResult(fEffect->toPipelineStage(fInputs.get(), fShaderCaps.get(),
224-
&code, &formatArgs, &functions));
225-
return new GrGLSLSkSLFP(code, formatArgs, functions);
220+
SkSL::PipelineStageArgs args;
221+
SkAssertResult(fEffect->toPipelineStage(fInputs.get(), fShaderCaps.get(), &args));
222+
return new GrGLSLSkSLFP(std::move(args.fCode), std::move(args.fFormatArgs),
223+
std::move(args.fFunctions));
226224
}
227225

228226
void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {

src/sksl/SkSLCompiler.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,18 +1597,16 @@ bool Compiler::toH(Program& program, String name, OutputStream& out) {
15971597
#endif
15981598

15991599
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
1600-
bool Compiler::toPipelineStage(const Program& program, String* out,
1601-
std::vector<FormatArg>* outFormatArgs,
1602-
std::vector<GLSLFunction>* outFunctions) {
1600+
bool Compiler::toPipelineStage(const Program& program, PipelineStageArgs* outArgs) {
16031601
SkASSERT(program.fIsOptimized);
16041602
fSource = program.fSource.get();
16051603
StringStream buffer;
1606-
PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, outFormatArgs,
1607-
outFunctions);
1604+
PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, &outArgs->fFormatArgs,
1605+
&outArgs->fFunctions);
16081606
bool result = cg.generateCode();
16091607
fSource = nullptr;
16101608
if (result) {
1611-
*out = buffer.str();
1609+
outArgs->fCode = buffer.str();
16121610
}
16131611
return result;
16141612
}

src/sksl/SkSLCompiler.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace SkSL {
5050
class ByteCode;
5151
class ExternalValue;
5252
class IRGenerator;
53+
struct PipelineStageArgs;
5354

5455
/**
5556
* Main compiler entry point. This is a traditional compiler design which first parses the .sksl
@@ -147,9 +148,7 @@ class SK_API Compiler : public ErrorReporter {
147148
std::unique_ptr<ByteCode> toByteCode(Program& program);
148149

149150
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
150-
bool toPipelineStage(const Program& program, String* out,
151-
std::vector<FormatArg>* outFormatArgs,
152-
std::vector<GLSLFunction>* outFunctions);
151+
bool toPipelineStage(const Program& program, PipelineStageArgs* outArgs);
153152
#endif
154153

155154
/**
@@ -241,6 +240,14 @@ class SK_API Compiler : public ErrorReporter {
241240
String fErrorText;
242241
};
243242

243+
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
244+
struct PipelineStageArgs {
245+
String fCode;
246+
std::vector<Compiler::FormatArg> fFormatArgs;
247+
std::vector<Compiler::GLSLFunction> fFunctions;
248+
};
249+
#endif
250+
244251
} // namespace
245252

246253
#endif

tools/viewer/SkSLSlide.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "tools/Resources.h"
1313
#include "tools/viewer/ImGuiLayer.h"
1414

15+
#include <algorithm>
1516
#include "imgui.h"
1617

1718
using namespace sk_app;

0 commit comments

Comments
 (0)