aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders/SkLightingShader.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-06-30 08:40:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-30 15:29:50 +0000
commit1c9686bfa5e2de3e06f1d1b9691105afb6659e85 (patch)
treeb292d1f6b0b7d023d9a5122d22b0f4fc92dfc7d3 /src/shaders/SkLightingShader.cpp
parent95581bbba1d696f14de45e00dd0c09119377027f (diff)
Speculative "fix" for crash in analyzeProcessors
From the bug it looks like a null fragment processors may be getting into the processor set. This CL tries to plug any gaps in our fragmentProcessor handling. The only real substantive part to this CL is the addition of some "if (!fp) { return nullptr; }" blocks. Everything else is just to add chokepoints for processor allocation. Bug: 734076 Change-Id: I4952b1a05bc6690d5aa09de977fa6dc54c80338a Reviewed-on: https://skia-review.googlesource.com/21267 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/shaders/SkLightingShader.cpp')
-rw-r--r--src/shaders/SkLightingShader.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/shaders/SkLightingShader.cpp b/src/shaders/SkLightingShader.cpp
index cdfa528e1e..b19f9df97f 100644
--- a/src/shaders/SkLightingShader.cpp
+++ b/src/shaders/SkLightingShader.cpp
@@ -114,21 +114,9 @@ private:
// premul'd.
class LightingFP : public GrFragmentProcessor {
public:
- LightingFP(sk_sp<GrFragmentProcessor> normalFP, sk_sp<SkLights> lights)
- : INHERITED(kPreservesOpaqueInput_OptimizationFlag) {
- // fuse all ambient lights into a single one
- fAmbientColor = lights->ambientLightColor();
- for (int i = 0; i < lights->numLights(); ++i) {
- if (SkLights::Light::kDirectional_LightType == lights->light(i).type()) {
- fDirectionalLights.push_back(lights->light(i));
- // TODO get the handle to the shadow map if there is one
- } else {
- SkDEBUGFAIL("Unimplemented Light Type passed to LightingFP");
- }
- }
-
- this->registerChildProcessor(std::move(normalFP));
- this->initClassID<LightingFP>();
+ static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> normalFP,
+ sk_sp<SkLights> lights) {
+ return sk_sp<GrFragmentProcessor>(new LightingFP(std::move(normalFP), std::move(lights)));
}
class GLSLLightingFP : public GrGLSLFragmentProcessor {
@@ -247,6 +235,23 @@ public:
const SkColor3f& ambientColor() const { return fAmbientColor; }
private:
+ LightingFP(sk_sp<GrFragmentProcessor> normalFP, sk_sp<SkLights> lights)
+ : INHERITED(kPreservesOpaqueInput_OptimizationFlag) {
+ // fuse all ambient lights into a single one
+ fAmbientColor = lights->ambientLightColor();
+ for (int i = 0; i < lights->numLights(); ++i) {
+ if (SkLights::Light::kDirectional_LightType == lights->light(i).type()) {
+ fDirectionalLights.push_back(lights->light(i));
+ // TODO get the handle to the shadow map if there is one
+ } else {
+ SkDEBUGFAIL("Unimplemented Light Type passed to LightingFP");
+ }
+ }
+
+ this->registerChildProcessor(std::move(normalFP));
+ this->initClassID<LightingFP>();
+ }
+
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLLightingFP; }
bool onIsEqual(const GrFragmentProcessor& proc) const override {
@@ -272,9 +277,9 @@ sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor(const AsFPA
if (fDiffuseShader) {
sk_sp<GrFragmentProcessor> fpPipeline[] = {
as_SB(fDiffuseShader)->asFragmentProcessor(args),
- sk_make_sp<LightingFP>(std::move(normalFP), fLights)
+ LightingFP::Make(std::move(normalFP), fLights)
};
- if(!fpPipeline[0]) {
+ if (!fpPipeline[0] || !fpPipeline[1]) {
return nullptr;
}
@@ -284,8 +289,7 @@ sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor(const AsFPA
} else {
// FP is wrapped because paint comes in unpremul'd to fragment shader, but LightingFP
// expects premul'd color.
- return GrFragmentProcessor::PremulInput(sk_make_sp<LightingFP>(std::move(normalFP),
- fLights));
+ return GrFragmentProcessor::PremulInput(LightingFP::Make(std::move(normalFP), fLights));
}
}