Respect color space in GrTextureDomainEffect
Forgot that this was plumbed in, but not being used. From local testing, fixes color correctness in a variety of real world content. BUG=skia: Change-Id: Iad4cdf38da03719d1af144a9094c16d545139114 Reviewed-on: https://skia-review.googlesource.com/6296 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
3711e1185d
commit
c468963b96
@ -10,6 +10,7 @@
|
|||||||
#include "GrShaderCaps.h"
|
#include "GrShaderCaps.h"
|
||||||
#include "GrSimpleTextureEffect.h"
|
#include "GrSimpleTextureEffect.h"
|
||||||
#include "SkFloatingPoint.h"
|
#include "SkFloatingPoint.h"
|
||||||
|
#include "glsl/GrGLSLColorSpaceXformHelper.h"
|
||||||
#include "glsl/GrGLSLFragmentProcessor.h"
|
#include "glsl/GrGLSLFragmentProcessor.h"
|
||||||
#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
||||||
#include "glsl/GrGLSLProgramDataManager.h"
|
#include "glsl/GrGLSLProgramDataManager.h"
|
||||||
@ -50,7 +51,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
const char* outColor,
|
const char* outColor,
|
||||||
const SkString& inCoords,
|
const SkString& inCoords,
|
||||||
GrGLSLFragmentProcessor::SamplerHandle sampler,
|
GrGLSLFragmentProcessor::SamplerHandle sampler,
|
||||||
const char* inModulateColor) {
|
const char* inModulateColor,
|
||||||
|
GrGLSLColorSpaceXformHelper* colorXformHelper) {
|
||||||
SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
|
SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
|
||||||
SkDEBUGCODE(fMode = textureDomain.mode();)
|
SkDEBUGCODE(fMode = textureDomain.mode();)
|
||||||
|
|
||||||
@ -69,8 +71,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
switch (textureDomain.mode()) {
|
switch (textureDomain.mode()) {
|
||||||
case kIgnore_Mode: {
|
case kIgnore_Mode: {
|
||||||
builder->codeAppendf("%s = ", outColor);
|
builder->codeAppendf("%s = ", outColor);
|
||||||
builder->appendTextureLookupAndModulate(inModulateColor, sampler,
|
builder->appendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str(),
|
||||||
inCoords.c_str());
|
kVec2f_GrSLType, colorXformHelper);
|
||||||
builder->codeAppend(";");
|
builder->codeAppend(";");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -80,8 +82,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str());
|
inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str());
|
||||||
|
|
||||||
builder->codeAppendf("%s = ", outColor);
|
builder->codeAppendf("%s = ", outColor);
|
||||||
builder->appendTextureLookupAndModulate(inModulateColor, sampler,
|
builder->appendTextureLookupAndModulate(inModulateColor, sampler, clampedCoords.c_str(),
|
||||||
clampedCoords.c_str());
|
kVec2f_GrSLType, colorXformHelper);
|
||||||
builder->codeAppend(";");
|
builder->codeAppend(";");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -99,8 +101,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
// result=white;" code fails to compile.
|
// result=white;" code fails to compile.
|
||||||
builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);");
|
builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);");
|
||||||
builder->codeAppend("vec4 inside = ");
|
builder->codeAppend("vec4 inside = ");
|
||||||
builder->appendTextureLookupAndModulate(inModulateColor, sampler,
|
builder->appendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str(),
|
||||||
inCoords.c_str());
|
kVec2f_GrSLType, colorXformHelper);
|
||||||
builder->codeAppend(";");
|
builder->codeAppend(";");
|
||||||
|
|
||||||
builder->codeAppendf("highp float x = (%s).x;", inCoords.c_str());
|
builder->codeAppendf("highp float x = (%s).x;", inCoords.c_str());
|
||||||
@ -120,8 +122,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
domain);
|
domain);
|
||||||
builder->codeAppendf("%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ",
|
builder->codeAppendf("%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ",
|
||||||
outColor);
|
outColor);
|
||||||
builder->appendTextureLookupAndModulate(inModulateColor, sampler,
|
builder->appendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str(),
|
||||||
inCoords.c_str());
|
kVec2f_GrSLType, colorXformHelper);
|
||||||
builder->codeAppend(";");
|
builder->codeAppend(";");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -133,8 +135,8 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
|
|||||||
fDomainName.c_str(), fDomainName.c_str());
|
fDomainName.c_str(), fDomainName.c_str());
|
||||||
|
|
||||||
builder->codeAppendf("%s = ", outColor);
|
builder->codeAppendf("%s = ", outColor);
|
||||||
builder->appendTextureLookupAndModulate(inModulateColor, sampler,
|
builder->appendTextureLookupAndModulate(inModulateColor, sampler, clampedCoords.c_str(),
|
||||||
clampedCoords.c_str());
|
kVec2f_GrSLType, colorXformHelper);
|
||||||
builder->codeAppend(";");
|
builder->codeAppend(";");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -213,6 +215,10 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const {
|
|||||||
|
|
||||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||||
SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
|
SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
|
||||||
|
|
||||||
|
GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler,
|
||||||
|
tde.colorSpaceXform(),
|
||||||
|
&fColorSpaceXformUni);
|
||||||
fGLDomain.sampleTexture(fragBuilder,
|
fGLDomain.sampleTexture(fragBuilder,
|
||||||
args.fUniformHandler,
|
args.fUniformHandler,
|
||||||
args.fShaderCaps,
|
args.fShaderCaps,
|
||||||
@ -220,7 +226,8 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const {
|
|||||||
args.fOutputColor,
|
args.fOutputColor,
|
||||||
coords2D,
|
coords2D,
|
||||||
args.fTexSamplers[0],
|
args.fTexSamplers[0],
|
||||||
args.fInputColor);
|
args.fInputColor,
|
||||||
|
&colorSpaceHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -228,11 +235,14 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const {
|
|||||||
const GrTextureDomainEffect& tde = fp.cast<GrTextureDomainEffect>();
|
const GrTextureDomainEffect& tde = fp.cast<GrTextureDomainEffect>();
|
||||||
const GrTextureDomain& domain = tde.fTextureDomain;
|
const GrTextureDomain& domain = tde.fTextureDomain;
|
||||||
fGLDomain.setData(pdman, domain, tde.textureSampler(0).texture()->origin());
|
fGLDomain.setData(pdman, domain, tde.textureSampler(0).texture()->origin());
|
||||||
|
if (SkToBool(tde.colorSpaceXform())) {
|
||||||
|
pdman.setSkMatrix44(fColorSpaceXformUni, tde.colorSpaceXform()->srcToDst());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrTextureDomain::GLDomain fGLDomain;
|
GrTextureDomain::GLDomain fGLDomain;
|
||||||
|
UniformHandle fColorSpaceXformUni;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new GLSLProcessor;
|
return new GLSLProcessor;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "glsl/GrGLSLProgramDataManager.h"
|
#include "glsl/GrGLSLProgramDataManager.h"
|
||||||
|
|
||||||
class GrGLProgramBuilder;
|
class GrGLProgramBuilder;
|
||||||
|
class GrGLSLColorSpaceXformHelper;
|
||||||
class GrGLSLShaderBuilder;
|
class GrGLSLShaderBuilder;
|
||||||
class GrInvariantOutput;
|
class GrInvariantOutput;
|
||||||
class GrGLSLUniformHandler;
|
class GrGLSLUniformHandler;
|
||||||
@ -120,7 +121,8 @@ public:
|
|||||||
const char* outColor,
|
const char* outColor,
|
||||||
const SkString& inCoords,
|
const SkString& inCoords,
|
||||||
GrGLSLFragmentProcessor::SamplerHandle sampler,
|
GrGLSLFragmentProcessor::SamplerHandle sampler,
|
||||||
const char* inModulateColor = nullptr);
|
const char* inModulateColor = nullptr,
|
||||||
|
GrGLSLColorSpaceXformHelper* colorXformHelper = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this from GrGLSLFragmentProcessor::setData() to upload uniforms necessary for the
|
* Call this from GrGLSLFragmentProcessor::setData() to upload uniforms necessary for the
|
||||||
|
Loading…
Reference in New Issue
Block a user