aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-06-07 14:42:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-07 19:42:41 +0000
commit4d3f517282b90250026ca61ed8846092b9fbf604 (patch)
tree1867b0b09a8a7064cc9b783fb651e31345c90fa7 /src/gpu/glsl
parentcd2c3f9055452d413d6be7ea6dc63fd1922fe994 (diff)
Remove GrGLSLFragProcs typedef. Use unique_ptr to for GrGLSLFragmentProcessor ownership.
Change-Id: Ifefbde2ec0002e7e41bed2e4bc2cd7bdd04504d0 Reviewed-on: https://skia-review.googlesource.com/132931 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.h4
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp29
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h10
3 files changed, 22 insertions, 21 deletions
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 0fed0ea6ef..1b12fb60d5 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -169,9 +169,9 @@ public:
class Iter : public SkNoncopyable {
public:
explicit Iter(GrGLSLFragmentProcessor* fp) { fFPStack.push_back(fp); }
- explicit Iter(GrGLSLFragmentProcessor* fps[], int cnt) {
+ explicit Iter(std::unique_ptr<GrGLSLFragmentProcessor> fps[], int cnt) {
for (int i = cnt - 1; i >= 0; --i) {
- fFPStack.push_back(fps[i]);
+ fFPStack.push_back(fps[i].get());
}
}
GrGLSLFragmentProcessor* next();
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 91ac5c3e71..cae1c2ad65 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -128,28 +128,37 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
int transformedCoordVarsIdx = 0;
SkString** inOut = &color;
+ SkSTArray<8, std::unique_ptr<GrGLSLFragmentProcessor>> glslFragmentProcessors;
for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
if (i == this->pipeline().numColorFragmentProcessors()) {
inOut = &coverage;
}
SkString output;
const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
- output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output);
+ output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output,
+ &glslFragmentProcessors);
GrFragmentProcessor::Iter iter(&fp);
while (const GrFragmentProcessor* fp = iter.next()) {
transformedCoordVarsIdx += fp->numCoordTransforms();
}
**inOut = output;
}
+ fFragmentProcessorCnt = glslFragmentProcessors.count();
+ fFragmentProcessors.reset(new std::unique_ptr<GrGLSLFragmentProcessor>[fFragmentProcessorCnt]);
+ for (int i = 0; i < fFragmentProcessorCnt; ++i) {
+ fFragmentProcessors[i] = std::move(glslFragmentProcessors[i]);
+ }
}
// TODO Processors cannot output zeros because an empty string is all 1s
// the fix is to allow effects to take the SkString directly
-SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
- int index,
- int transformedCoordVarsIdx,
- const SkString& input,
- SkString output) {
+SkString GrGLSLProgramBuilder::emitAndInstallFragProc(
+ const GrFragmentProcessor& fp,
+ int index,
+ int transformedCoordVarsIdx,
+ const SkString& input,
+ SkString output,
+ SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>* glslFragmentProcessors) {
SkASSERT(input.size());
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
@@ -188,7 +197,7 @@ SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor&
// We have to check that effects and the code they emit are consistent, ie if an effect
// asks for dst color, then the emit code needs to follow suit
SkDEBUGCODE(verify(fp);)
- fFragmentProcessors.push_back(fragProc);
+ glslFragmentProcessors->emplace_back(fragProc);
fFS.codeAppend("}");
return output;
@@ -403,12 +412,6 @@ void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
name, false, 0, nullptr);
}
-void GrGLSLProgramBuilder::cleanupFragmentProcessors() {
- for (int i = 0; i < fFragmentProcessors.count(); ++i) {
- delete fFragmentProcessors[i];
- }
-}
-
void GrGLSLProgramBuilder::finalizeShaders() {
this->varyingHandler()->finalize();
fVS.finalize(kVertex_GrShaderFlag);
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index d4d2099a41..04d169d4d9 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -24,8 +24,6 @@ class GrGLSLVaryingHandler;
class SkString;
class GrShaderCaps;
-typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs;
-
class GrGLSLProgramBuilder {
public:
using UniformHandle = GrGLSLUniformHandler::UniformHandle;
@@ -100,7 +98,8 @@ public:
std::unique_ptr<GrGLSLPrimitiveProcessor> fGeometryProcessor;
std::unique_ptr<GrGLSLXferProcessor> fXferProcessor;
- GrGLSLFragProcs fFragmentProcessors;
+ std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fFragmentProcessors;
+ int fFragmentProcessorCnt;
protected:
explicit GrGLSLProgramBuilder(const GrPipeline&,
@@ -111,8 +110,6 @@ protected:
bool emitAndInstallProcs();
- void cleanupFragmentProcessors();
-
void finalizeShaders();
bool fragColorIsInOut() const { return fFS.primaryColorOutputIsInOut(); }
@@ -151,7 +148,8 @@ private:
int index,
int transformedCoordVarsIdx,
const SkString& input,
- SkString output);
+ SkString output,
+ SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>*);
void emitAndInstallXferProc(const SkString& colorIn, const SkString& coverageIn);
void emitSamplers(const GrResourceIOProcessor& processor,
SkTArray<SamplerHandle>* outTexSamplerHandles,