Revert "converted GrSimpleTextureEffect to sksl"
This reverts commit 46b654df9e
.
Reason for revert: making Vulkan mad
Original change's description:
> converted GrSimpleTextureEffect to sksl
>
> Bug: skia:
> Change-Id: If556c6baad75f22135f429759feabaaec095b900
> Reviewed-on: https://skia-review.googlesource.com/21720
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,ethannicholas@google.com
Change-Id: I06fac3d106435e1d58e19cc54a919c5d84784d92
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/22266
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
46b654df9e
commit
baf981f716
@ -27,5 +27,4 @@ skia_gpu_processor_sources = [
|
|||||||
"$_src/effects/GrAlphaThresholdFragmentProcessor.fp",
|
"$_src/effects/GrAlphaThresholdFragmentProcessor.fp",
|
||||||
"$_src/effects/GrCircleBlurFragmentProcessor.fp",
|
"$_src/effects/GrCircleBlurFragmentProcessor.fp",
|
||||||
"$_src/gpu/effects/GrDitherEffect.fp",
|
"$_src/gpu/effects/GrDitherEffect.fp",
|
||||||
"$_src/gpu/effects/GrSimpleTextureEffect.fp",
|
|
||||||
]
|
]
|
||||||
|
@ -28,12 +28,20 @@ in uniform float outerThreshold;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@coordTransform(image) {
|
@fields {
|
||||||
SkMatrix::I()
|
GrCoordTransform fImageCoordTransform;
|
||||||
|
GrCoordTransform fMaskCoordTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@coordTransform(mask) {
|
@initializers {
|
||||||
SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y()))
|
fImageCoordTransform(SkMatrix::I(), image.get()),
|
||||||
|
fMaskCoordTransform(SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())),
|
||||||
|
mask.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
@constructorCode {
|
||||||
|
this->addCoordTransform(&fImageCoordTransform);
|
||||||
|
this->addCoordTransform(&fMaskCoordTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@header {
|
@header {
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "GrColorSpaceXform.h"
|
#include "GrColorSpaceXform.h"
|
||||||
#include "GrFragmentProcessor.h"
|
#include "GrFragmentProcessor.h"
|
||||||
#include "GrCoordTransform.h"
|
#include "GrCoordTransform.h"
|
||||||
#include "GrColorSpaceXform.h"
|
|
||||||
#include "effects/GrProxyMove.h"
|
#include "effects/GrProxyMove.h"
|
||||||
class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
|
class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
|
||||||
public:
|
public:
|
||||||
@ -45,34 +44,35 @@ private:
|
|||||||
const SkIRect& bounds
|
const SkIRect& bounds
|
||||||
)
|
)
|
||||||
: INHERITED(kNone_OptimizationFlags)
|
: INHERITED(kNone_OptimizationFlags)
|
||||||
|
,
|
||||||
|
fImageCoordTransform(SkMatrix::I(), image.get()),
|
||||||
|
fMaskCoordTransform(SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())),
|
||||||
|
mask.get())
|
||||||
|
|
||||||
, fImage(std::move(image))
|
, fImage(std::move(image))
|
||||||
, fColorXform(colorXform)
|
, fColorXform(colorXform)
|
||||||
, fMask(std::move(mask))
|
, fMask(std::move(mask))
|
||||||
, fInnerThreshold(innerThreshold)
|
, fInnerThreshold(innerThreshold)
|
||||||
, fOuterThreshold(outerThreshold)
|
, fOuterThreshold(outerThreshold) {
|
||||||
, fImageCoordTransform(
|
|
||||||
SkMatrix::I()
|
this->addCoordTransform(&fImageCoordTransform);
|
||||||
, fImage.proxy())
|
this->addCoordTransform(&fMaskCoordTransform);
|
||||||
, fMaskCoordTransform(
|
|
||||||
SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y()))
|
|
||||||
, fMask.proxy()) {
|
|
||||||
this->addTextureSampler(&fImage);
|
this->addTextureSampler(&fImage);
|
||||||
this->addTextureSampler(&fMask);
|
this->addTextureSampler(&fMask);
|
||||||
this->addCoordTransform(&fImageCoordTransform);
|
|
||||||
this->addCoordTransform(&fMaskCoordTransform);
|
|
||||||
this->initClassID<GrAlphaThresholdFragmentProcessor>();
|
this->initClassID<GrAlphaThresholdFragmentProcessor>();
|
||||||
}
|
}
|
||||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||||
void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const override;
|
void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const override;
|
||||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||||
|
|
||||||
|
GrCoordTransform fImageCoordTransform;
|
||||||
|
GrCoordTransform fMaskCoordTransform;
|
||||||
TextureSampler fImage;
|
TextureSampler fImage;
|
||||||
sk_sp<GrColorSpaceXform> fColorXform;
|
sk_sp<GrColorSpaceXform> fColorXform;
|
||||||
TextureSampler fMask;
|
TextureSampler fMask;
|
||||||
float fInnerThreshold;
|
float fInnerThreshold;
|
||||||
float fOuterThreshold;
|
float fOuterThreshold;
|
||||||
GrCoordTransform fImageCoordTransform;
|
|
||||||
GrCoordTransform fMaskCoordTransform;
|
|
||||||
typedef GrFragmentProcessor INHERITED;
|
typedef GrFragmentProcessor INHERITED;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#if SK_SUPPORT_GPU
|
#if SK_SUPPORT_GPU
|
||||||
#include "GrFragmentProcessor.h"
|
#include "GrFragmentProcessor.h"
|
||||||
#include "GrCoordTransform.h"
|
#include "GrCoordTransform.h"
|
||||||
#include "GrColorSpaceXform.h"
|
|
||||||
#include "effects/GrProxyMove.h"
|
#include "effects/GrProxyMove.h"
|
||||||
class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
|
class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
|
||||||
public:
|
public:
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#if SK_SUPPORT_GPU
|
#if SK_SUPPORT_GPU
|
||||||
#include "GrFragmentProcessor.h"
|
#include "GrFragmentProcessor.h"
|
||||||
#include "GrCoordTransform.h"
|
#include "GrCoordTransform.h"
|
||||||
#include "GrColorSpaceXform.h"
|
|
||||||
#include "effects/GrProxyMove.h"
|
#include "effects/GrProxyMove.h"
|
||||||
class GrDitherEffect : public GrFragmentProcessor {
|
class GrDitherEffect : public GrFragmentProcessor {
|
||||||
public:
|
public:
|
||||||
|
@ -1,81 +1,111 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Google Inc.
|
* Copyright 2012 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* This file was autogenerated from GrSimpleTextureEffect.fp; do not modify.
|
|
||||||
*/
|
|
||||||
#include "GrSimpleTextureEffect.h"
|
#include "GrSimpleTextureEffect.h"
|
||||||
#if SK_SUPPORT_GPU
|
#include "GrProxyMove.h"
|
||||||
#include "glsl/GrGLSLColorSpaceXformHelper.h"
|
#include "glsl/GrGLSLColorSpaceXformHelper.h"
|
||||||
#include "glsl/GrGLSLFragmentProcessor.h"
|
#include "glsl/GrGLSLFragmentProcessor.h"
|
||||||
#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
||||||
#include "glsl/GrGLSLProgramBuilder.h"
|
|
||||||
#include "SkSLCPP.h"
|
GrSimpleTextureEffect::GrSimpleTextureEffect(sk_sp<GrTextureProxy> proxy,
|
||||||
#include "SkSLUtil.h"
|
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||||
class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
|
const SkMatrix& matrix,
|
||||||
|
GrSamplerParams::FilterMode filterMode)
|
||||||
|
: INHERITED{ModulationFlags(proxy->config()),
|
||||||
|
GR_PROXY_MOVE(proxy),
|
||||||
|
std::move(colorSpaceXform),
|
||||||
|
matrix,
|
||||||
|
filterMode} {
|
||||||
|
this->initClassID<GrSimpleTextureEffect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
GrSimpleTextureEffect::GrSimpleTextureEffect(sk_sp<GrTextureProxy> proxy,
|
||||||
|
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||||
|
const SkMatrix& matrix,
|
||||||
|
const GrSamplerParams& params)
|
||||||
|
: INHERITED{ModulationFlags(proxy->config()),
|
||||||
|
GR_PROXY_MOVE(proxy),
|
||||||
|
std::move(colorSpaceXform),
|
||||||
|
matrix,
|
||||||
|
params} {
|
||||||
|
this->initClassID<GrSimpleTextureEffect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor {
|
||||||
public:
|
public:
|
||||||
GrGLSLSimpleTextureEffect() {}
|
|
||||||
void emitCode(EmitArgs& args) override {
|
void emitCode(EmitArgs& args) override {
|
||||||
|
const GrSimpleTextureEffect& textureEffect = args.fFp.cast<GrSimpleTextureEffect>();
|
||||||
|
fColorSpaceHelper.emitCode(args.fUniformHandler, textureEffect.colorSpaceXform());
|
||||||
|
|
||||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||||
const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
|
fragBuilder->codeAppendf("%s = ", args.fOutputColor);
|
||||||
(void) _outer;
|
fragBuilder->appendTextureLookupAndModulate(args.fInputColor,
|
||||||
fColorSpaceHelper.emitCode(args.fUniformHandler, _outer.colorXform().get());
|
args.fTexSamplers[0],
|
||||||
SkSL::String sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
|
args.fTransformedCoords[0].c_str(),
|
||||||
fragBuilder->codeAppendf("vec4 _tmp0;\n%s = %s * (_tmp0 = texture(%s, %s).%s , %s != mat4(1.0) ? vec4(clamp((%s * vec4(_tmp0.xyz, 1.0)).xyz, 0.0, _tmp0.w), _tmp0.w) : _tmp0);\n", args.fOutputColor, args.fInputColor ? args.fInputColor : "vec4(1)", fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), sk_TransformedCoords2D_0.c_str(), fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), fColorSpaceHelper.isValid() ? args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform()) : "mat4(1.0)", fColorSpaceHelper.isValid() ? args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform()) : "mat4(1.0)");
|
args.fTransformedCoords[0].getType(),
|
||||||
|
&fColorSpaceHelper);
|
||||||
|
fragBuilder->codeAppend(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void GenKey(const GrProcessor& effect, const GrShaderCaps&,
|
||||||
|
GrProcessorKeyBuilder* b) {
|
||||||
|
const GrSimpleTextureEffect& textureEffect = effect.cast<GrSimpleTextureEffect>();
|
||||||
|
b->add32(GrColorSpaceXform::XformKey(textureEffect.colorSpaceXform()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||||
|
const GrFragmentProcessor& processor) override {
|
||||||
|
const GrSimpleTextureEffect& textureEffect = processor.cast<GrSimpleTextureEffect>();
|
||||||
|
if (SkToBool(textureEffect.colorSpaceXform())) {
|
||||||
|
fColorSpaceHelper.setData(pdman, textureEffect.colorSpaceXform());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
typedef GrGLSLFragmentProcessor INHERITED;
|
||||||
const GrSimpleTextureEffect& _outer = _proc.cast<GrSimpleTextureEffect>();
|
|
||||||
{
|
|
||||||
if (fColorSpaceHelper.isValid()) {
|
|
||||||
fColorSpaceHelper.setData(pdman, _outer.colorXform().get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UniformHandle fImageVar;
|
|
||||||
GrGLSLColorSpaceXformHelper fColorSpaceHelper;
|
GrGLSLColorSpaceXformHelper fColorSpaceHelper;
|
||||||
};
|
};
|
||||||
GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
|
|
||||||
return new GrGLSLSimpleTextureEffect();
|
|
||||||
}
|
|
||||||
void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
|
||||||
b->add32(GrColorSpaceXform::XformKey(fColorXform.get()));
|
|
||||||
}
|
|
||||||
bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
|
||||||
const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
|
|
||||||
(void) that;
|
|
||||||
if (fImage != that.fImage) return false;
|
|
||||||
if (fColorXform != that.fColorXform) return false;
|
|
||||||
if (fMatrix != that.fMatrix) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
|
|
||||||
#if GR_TEST_UTILS
|
|
||||||
sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* testData) {
|
|
||||||
|
|
||||||
int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
: GrProcessorUnitTest::kAlphaTextureIdx;
|
|
||||||
|
void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||||
|
GrProcessorKeyBuilder* b) const {
|
||||||
|
GrGLSimpleTextureEffect::GenKey(*this, caps, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
|
||||||
|
return new GrGLSimpleTextureEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
|
||||||
|
|
||||||
|
#if GR_TEST_UTILS
|
||||||
|
sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) {
|
||||||
|
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
|
||||||
|
: GrProcessorUnitTest::kAlphaTextureIdx;
|
||||||
static const SkShader::TileMode kTileModes[] = {
|
static const SkShader::TileMode kTileModes[] = {
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode,
|
||||||
SkShader::kRepeat_TileMode,
|
SkShader::kRepeat_TileMode,
|
||||||
SkShader::kMirror_TileMode,
|
SkShader::kMirror_TileMode,
|
||||||
};
|
};
|
||||||
SkShader::TileMode tileModes[] = {
|
SkShader::TileMode tileModes[] = {
|
||||||
kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
||||||
kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
||||||
};
|
};
|
||||||
GrSamplerParams params(tileModes, testData->fRandom->nextBool()
|
GrSamplerParams params(tileModes, d->fRandom->nextBool() ? GrSamplerParams::kBilerp_FilterMode
|
||||||
? GrSamplerParams::kBilerp_FilterMode
|
: GrSamplerParams::kNone_FilterMode);
|
||||||
: GrSamplerParams::kNone_FilterMode);
|
|
||||||
|
|
||||||
const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
|
const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom);
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom);
|
sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(d->fRandom);
|
||||||
return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform),
|
return GrSimpleTextureEffect::Make(d->textureProxy(texIdx),
|
||||||
matrix);
|
std::move(colorSpaceXform), matrix);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Google Inc.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
in uniform sampler2D image;
|
|
||||||
in uniform colorSpaceXform colorXform;
|
|
||||||
in mat4 matrix;
|
|
||||||
|
|
||||||
@constructorParams {
|
|
||||||
GrSamplerParams samplerParams
|
|
||||||
}
|
|
||||||
|
|
||||||
@coordTransform(image) {
|
|
||||||
matrix
|
|
||||||
}
|
|
||||||
|
|
||||||
@samplerParams(image) {
|
|
||||||
samplerParams
|
|
||||||
}
|
|
||||||
|
|
||||||
@make {
|
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
|
||||||
const SkMatrix& matrix) {
|
|
||||||
return sk_sp<GrFragmentProcessor>(
|
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix,
|
|
||||||
GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clamp mode */
|
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
|
||||||
const SkMatrix& matrix,
|
|
||||||
GrSamplerParams::FilterMode filterMode) {
|
|
||||||
return sk_sp<GrFragmentProcessor>(
|
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix,
|
|
||||||
GrSamplerParams(SkShader::kClamp_TileMode, filterMode)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
|
||||||
const SkMatrix& matrix,
|
|
||||||
const GrSamplerParams& p) {
|
|
||||||
return sk_sp<GrFragmentProcessor>(
|
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@optimizationFlags {
|
|
||||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
|
||||||
(GrPixelConfigIsOpaque(image->config()) ? kPreservesOpaqueInput_OptimizationFlag :
|
|
||||||
kNone_OptimizationFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
sk_OutColor = sk_InColor * texture(image, sk_TransformedCoords2D[0], colorXform);
|
|
||||||
}
|
|
||||||
|
|
||||||
@test(testData) {
|
|
||||||
int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
|
|
||||||
: GrProcessorUnitTest::kAlphaTextureIdx;
|
|
||||||
static const SkShader::TileMode kTileModes[] = {
|
|
||||||
SkShader::kClamp_TileMode,
|
|
||||||
SkShader::kRepeat_TileMode,
|
|
||||||
SkShader::kMirror_TileMode,
|
|
||||||
};
|
|
||||||
SkShader::TileMode tileModes[] = {
|
|
||||||
kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
|
||||||
kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
|
|
||||||
};
|
|
||||||
GrSamplerParams params(tileModes, testData->fRandom->nextBool()
|
|
||||||
? GrSamplerParams::kBilerp_FilterMode
|
|
||||||
: GrSamplerParams::kNone_FilterMode);
|
|
||||||
|
|
||||||
const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
|
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom);
|
|
||||||
return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform),
|
|
||||||
matrix);
|
|
||||||
}
|
|
@ -1,82 +1,77 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Google Inc.
|
* Copyright 2013 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* This file was autogenerated from GrSimpleTextureEffect.fp; do not modify.
|
|
||||||
*/
|
|
||||||
#ifndef GrSimpleTextureEffect_DEFINED
|
#ifndef GrSimpleTextureEffect_DEFINED
|
||||||
#define GrSimpleTextureEffect_DEFINED
|
#define GrSimpleTextureEffect_DEFINED
|
||||||
#include "SkTypes.h"
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
#include "GrFragmentProcessor.h"
|
|
||||||
#include "GrCoordTransform.h"
|
|
||||||
#include "GrColorSpaceXform.h"
|
|
||||||
#include "effects/GrProxyMove.h"
|
|
||||||
class GrSimpleTextureEffect : public GrFragmentProcessor {
|
|
||||||
public:
|
|
||||||
sk_sp<GrColorSpaceXform> colorXform() const { return fColorXform; }
|
|
||||||
SkMatrix44 matrix() const { return fMatrix; }
|
|
||||||
|
|
||||||
|
#include "GrSingleTextureEffect.h"
|
||||||
|
#include "GrTextureProxy.h"
|
||||||
|
|
||||||
|
class GrInvariantOutput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output color of this effect is a modulation of the input color and a sample from a texture.
|
||||||
|
* It allows explicit specification of the filtering and wrap modes (GrSamplerParams) and accepts
|
||||||
|
* a matrix that is used to compute texture coordinates from local coordinates.
|
||||||
|
*/
|
||||||
|
class GrSimpleTextureEffect : public GrSingleTextureEffect {
|
||||||
|
public:
|
||||||
|
/* unfiltered, clamp mode */
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||||
const SkMatrix& matrix) {
|
const SkMatrix& matrix) {
|
||||||
return sk_sp<GrFragmentProcessor>(
|
return sk_sp<GrFragmentProcessor>(
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix,
|
new GrSimpleTextureEffect(std::move(proxy),
|
||||||
GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode)));
|
std::move(colorSpaceXform), matrix,
|
||||||
|
GrSamplerParams::kNone_FilterMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clamp mode */
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||||
const SkMatrix& matrix,
|
const SkMatrix& matrix,
|
||||||
GrSamplerParams::FilterMode filterMode) {
|
GrSamplerParams::FilterMode filterMode) {
|
||||||
return sk_sp<GrFragmentProcessor>(
|
return sk_sp<GrFragmentProcessor>(
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix,
|
new GrSimpleTextureEffect(std::move(proxy),
|
||||||
GrSamplerParams(SkShader::kClamp_TileMode, filterMode)));
|
std::move(colorSpaceXform),
|
||||||
}
|
matrix, filterMode));
|
||||||
|
}
|
||||||
|
|
||||||
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
|
||||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||||
const SkMatrix& matrix,
|
const SkMatrix& matrix,
|
||||||
const GrSamplerParams& p) {
|
const GrSamplerParams& p) {
|
||||||
return sk_sp<GrFragmentProcessor>(
|
return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(std::move(proxy),
|
||||||
new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, p));
|
std::move(colorSpaceXform),
|
||||||
|
matrix, p));
|
||||||
}
|
}
|
||||||
const char* name() const override { return "SimpleTextureEffect"; }
|
|
||||||
|
~GrSimpleTextureEffect() override {}
|
||||||
|
|
||||||
|
const char* name() const override { return "SimpleTexture"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrSimpleTextureEffect(sk_sp<GrTextureProxy> image, sk_sp<GrColorSpaceXform> colorXform, SkMatrix44 matrix,
|
GrSimpleTextureEffect(sk_sp<GrTextureProxy>,
|
||||||
GrSamplerParams samplerParams
|
sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
|
||||||
)
|
GrSamplerParams::FilterMode);
|
||||||
: INHERITED((OptimizationFlags)
|
|
||||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
GrSimpleTextureEffect(sk_sp<GrTextureProxy>,
|
||||||
(GrPixelConfigIsOpaque(image->config()) ? kPreservesOpaqueInput_OptimizationFlag :
|
sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
|
||||||
kNone_OptimizationFlags)
|
const GrSamplerParams&);
|
||||||
)
|
|
||||||
, fImage(std::move(image),
|
|
||||||
samplerParams
|
|
||||||
)
|
|
||||||
, fColorXform(colorXform)
|
|
||||||
, fMatrix(matrix)
|
|
||||||
, fImageCoordTransform(
|
|
||||||
matrix
|
|
||||||
, fImage.proxy()) {
|
|
||||||
this->addTextureSampler(&fImage);
|
|
||||||
this->addCoordTransform(&fImageCoordTransform);
|
|
||||||
this->initClassID<GrSimpleTextureEffect>();
|
|
||||||
}
|
|
||||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||||
void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const override;
|
|
||||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||||
|
|
||||||
|
bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
|
||||||
|
|
||||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||||
TextureSampler fImage;
|
|
||||||
sk_sp<GrColorSpaceXform> fColorXform;
|
typedef GrSingleTextureEffect INHERITED;
|
||||||
SkMatrix44 fMatrix;
|
|
||||||
GrCoordTransform fImageCoordTransform;
|
|
||||||
typedef GrFragmentProcessor INHERITED;
|
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,11 +89,6 @@ Within an '.fp' fragment processor file:
|
|||||||
the name of the GrGLSLProgramDataManager)
|
the name of the GrGLSLProgramDataManager)
|
||||||
@test(<testData>) (the body of the TestCreate function, where <testData> is
|
@test(<testData>) (the body of the TestCreate function, where <testData> is
|
||||||
the name of the GrProcessorTestData* parameter)
|
the name of the GrProcessorTestData* parameter)
|
||||||
@coordTransform(<sampler>)
|
|
||||||
(the matrix to attach to the named sampler2D's
|
|
||||||
GrCoordTransform)
|
|
||||||
@samplerParams(<sampler>)
|
|
||||||
(the sampler params to attach to the named sampler2D)
|
|
||||||
* global 'in' variables represent data passed to the fragment processor at
|
* global 'in' variables represent data passed to the fragment processor at
|
||||||
construction time. These variables become constructor parameters and are
|
construction time. These variables become constructor parameters and are
|
||||||
stored in fragment processor fields. vec2s map to SkPoints, and vec4s map to
|
stored in fragment processor fields. vec2s map to SkPoints, and vec4s map to
|
||||||
|
@ -163,7 +163,7 @@ void CPPCodeGenerator::writeVarInitializer(const Variable& var, const Expression
|
|||||||
|
|
||||||
String CPPCodeGenerator::getSamplerHandle(const Variable& var) {
|
String CPPCodeGenerator::getSamplerHandle(const Variable& var) {
|
||||||
int samplerCount = 0;
|
int samplerCount = 0;
|
||||||
for (const auto param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto param : fSectionAndParameterHelper.fParameters) {
|
||||||
if (&var == param) {
|
if (&var == param) {
|
||||||
return "args.fTexSamplers[" + to_string(samplerCount) + "]";
|
return "args.fTexSamplers[" + to_string(samplerCount) + "]";
|
||||||
}
|
}
|
||||||
@ -267,9 +267,9 @@ void CPPCodeGenerator::writeSetting(const Setting& s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CPPCodeGenerator::writeSection(const char* name, const char* prefix) {
|
void CPPCodeGenerator::writeSection(const char* name, const char* prefix) {
|
||||||
const Section* s = fSectionAndParameterHelper.getSection(name);
|
const auto found = fSectionAndParameterHelper.fSections.find(String(name));
|
||||||
if (s) {
|
if (found != fSectionAndParameterHelper.fSections.end()) {
|
||||||
this->writef("%s%s", prefix, s->fText.c_str());
|
this->writef("%s%s", prefix, found->second->fText.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,8 +398,10 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
|
|||||||
|
|
||||||
void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||||
const char* fullName = fFullName.c_str();
|
const char* fullName = fFullName.c_str();
|
||||||
const Section* section = fSectionAndParameterHelper.getSection(SET_DATA_SECTION);
|
auto section = fSectionAndParameterHelper.fSections.find(String(SET_DATA_SECTION));
|
||||||
const char* pdman = section ? section->fArgument.c_str() : "pdman";
|
const char* pdman = section != fSectionAndParameterHelper.fSections.end() ?
|
||||||
|
section->second->fArgument.c_str() :
|
||||||
|
"pdman";
|
||||||
this->writef(" void onSetData(const GrGLSLProgramDataManager& %s, "
|
this->writef(" void onSetData(const GrGLSLProgramDataManager& %s, "
|
||||||
"const GrFragmentProcessor& _proc) override {\n",
|
"const GrFragmentProcessor& _proc) override {\n",
|
||||||
pdman);
|
pdman);
|
||||||
@ -437,7 +439,7 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
|||||||
if (wroteProcessor) {
|
if (wroteProcessor) {
|
||||||
this->writef(" }\n");
|
this->writef(" }\n");
|
||||||
}
|
}
|
||||||
if (section) {
|
if (section != fSectionAndParameterHelper.fSections.end()) {
|
||||||
for (const auto& p : fProgram.fElements) {
|
for (const auto& p : fProgram.fElements) {
|
||||||
if (ProgramElement::kVar_Kind == p->fKind) {
|
if (ProgramElement::kVar_Kind == p->fKind) {
|
||||||
const VarDeclarations* decls = (const VarDeclarations*) p.get();
|
const VarDeclarations* decls = (const VarDeclarations*) p.get();
|
||||||
@ -468,25 +470,27 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CPPCodeGenerator::writeTest() {
|
void CPPCodeGenerator::writeTest() {
|
||||||
const Section* test = fSectionAndParameterHelper.getSection(TEST_CODE_SECTION);
|
const auto found = fSectionAndParameterHelper.fSections.find(TEST_CODE_SECTION);
|
||||||
if (test) {
|
if (found == fSectionAndParameterHelper.fSections.end()) {
|
||||||
this->writef("GR_DEFINE_FRAGMENT_PROCESSOR_TEST(%s);\n"
|
return;
|
||||||
"#if GR_TEST_UTILS\n"
|
|
||||||
"sk_sp<GrFragmentProcessor> %s::TestCreate(GrProcessorTestData* %s) {\n",
|
|
||||||
fFullName.c_str(),
|
|
||||||
fFullName.c_str(),
|
|
||||||
test->fArgument.c_str());
|
|
||||||
this->writeSection(TEST_CODE_SECTION);
|
|
||||||
this->write("}\n"
|
|
||||||
"#endif\n");
|
|
||||||
}
|
}
|
||||||
|
const Section* test = found->second;
|
||||||
|
this->writef("GR_DEFINE_FRAGMENT_PROCESSOR_TEST(%s);\n"
|
||||||
|
"#if GR_TEST_UTILS\n"
|
||||||
|
"sk_sp<GrFragmentProcessor> %s::TestCreate(GrProcessorTestData* %s) {\n",
|
||||||
|
fFullName.c_str(),
|
||||||
|
fFullName.c_str(),
|
||||||
|
test->fArgument.c_str());
|
||||||
|
this->writeSection(TEST_CODE_SECTION);
|
||||||
|
this->write("}\n"
|
||||||
|
"#endif\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPCodeGenerator::writeGetKey() {
|
void CPPCodeGenerator::writeGetKey() {
|
||||||
this->writef("void %s::onGetGLSLProcessorKey(const GrShaderCaps& caps, "
|
this->writef("void %s::onGetGLSLProcessorKey(const GrShaderCaps& caps, "
|
||||||
"GrProcessorKeyBuilder* b) const {\n",
|
"GrProcessorKeyBuilder* b) const {\n",
|
||||||
fFullName.c_str());
|
fFullName.c_str());
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
const char* name = param->fName.c_str();
|
const char* name = param->fName.c_str();
|
||||||
if (param->fType == *fContext.fColorSpaceXform_Type) {
|
if (param->fType == *fContext.fColorSpaceXform_Type) {
|
||||||
this->writef(" b->add32(GrColorSpaceXform::XformKey(%s.get()));\n",
|
this->writef(" b->add32(GrColorSpaceXform::XformKey(%s.get()));\n",
|
||||||
@ -576,7 +580,7 @@ bool CPPCodeGenerator::generateCode() {
|
|||||||
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
|
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
const char* name = param->fName.c_str();
|
const char* name = param->fName.c_str();
|
||||||
if (needs_uniform_var(*param)) {
|
if (needs_uniform_var(*param)) {
|
||||||
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
|
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
|
||||||
@ -595,7 +599,7 @@ bool CPPCodeGenerator::generateCode() {
|
|||||||
" const %s& that = other.cast<%s>();\n"
|
" const %s& that = other.cast<%s>();\n"
|
||||||
" (void) that;\n",
|
" (void) that;\n",
|
||||||
fullName, fullName, fullName);
|
fullName, fullName, fullName);
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
const char* name = param->fName.c_str();
|
const char* name = param->fName.c_str();
|
||||||
this->writef(" if (%s != that.%s) return false;\n",
|
this->writef(" if (%s != that.%s) return false;\n",
|
||||||
HCodeGenerator::FieldName(name).c_str(),
|
HCodeGenerator::FieldName(name).c_str(),
|
||||||
|
@ -69,9 +69,9 @@ void HCodeGenerator::writef(const char* s, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool HCodeGenerator::writeSection(const char* name, const char* prefix) {
|
bool HCodeGenerator::writeSection(const char* name, const char* prefix) {
|
||||||
const Section* s = fSectionAndParameterHelper.getSection(name);
|
const auto found = fSectionAndParameterHelper.fSections.find(String(name));
|
||||||
if (s) {
|
if (found != fSectionAndParameterHelper.fSections.end()) {
|
||||||
this->writef("%s%s", prefix, s->fText.c_str());
|
this->writef("%s%s", prefix, found->second->fText.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -81,9 +81,10 @@ void HCodeGenerator::writeExtraConstructorParams(const char* separator) {
|
|||||||
// super-simple parse, just assume the last token before a comma is the name of a parameter
|
// super-simple parse, just assume the last token before a comma is the name of a parameter
|
||||||
// (which is true as long as there are no multi-parameter template types involved). Will replace
|
// (which is true as long as there are no multi-parameter template types involved). Will replace
|
||||||
// this with something more robust if the need arises.
|
// this with something more robust if the need arises.
|
||||||
const Section* section = fSectionAndParameterHelper.getSection(CONSTRUCTOR_PARAMS_SECTION);
|
const auto found = fSectionAndParameterHelper.fSections.find(
|
||||||
if (section) {
|
String(CONSTRUCTOR_PARAMS_SECTION));
|
||||||
const char* s = section->fText.c_str();
|
if (found != fSectionAndParameterHelper.fSections.end()) {
|
||||||
|
const char* s = found->second->fText.c_str();
|
||||||
#define BUFFER_SIZE 64
|
#define BUFFER_SIZE 64
|
||||||
char lastIdentifier[BUFFER_SIZE];
|
char lastIdentifier[BUFFER_SIZE];
|
||||||
int lastIdentifierLength = 0;
|
int lastIdentifierLength = 0;
|
||||||
@ -125,7 +126,7 @@ void HCodeGenerator::writeMake() {
|
|||||||
if (!this->writeSection(MAKE_SECTION)) {
|
if (!this->writeSection(MAKE_SECTION)) {
|
||||||
this->writef(" static sk_sp<GrFragmentProcessor> Make(");
|
this->writef(" static sk_sp<GrFragmentProcessor> Make(");
|
||||||
separator = "";
|
separator = "";
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
|
this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
|
||||||
param->fName.c_str());
|
param->fName.c_str());
|
||||||
separator = ", ";
|
separator = ", ";
|
||||||
@ -135,7 +136,7 @@ void HCodeGenerator::writeMake() {
|
|||||||
" return sk_sp<GrFragmentProcessor>(new %s(",
|
" return sk_sp<GrFragmentProcessor>(new %s(",
|
||||||
fFullName.c_str());
|
fFullName.c_str());
|
||||||
separator = "";
|
separator = "";
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
this->writef("%s%s", separator, param->fName.c_str());
|
this->writef("%s%s", separator, param->fName.c_str());
|
||||||
separator = ", ";
|
separator = ", ";
|
||||||
}
|
}
|
||||||
@ -145,25 +146,13 @@ void HCodeGenerator::writeMake() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HCodeGenerator::failOnSection(const char* section, const char* msg) {
|
|
||||||
std::vector<const Section*> s = fSectionAndParameterHelper.getSections(section);
|
|
||||||
if (s.size()) {
|
|
||||||
fErrors.error(s[0]->fPosition, String("@") + section + " " + msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HCodeGenerator::writeConstructor() {
|
void HCodeGenerator::writeConstructor() {
|
||||||
if (this->writeSection(CONSTRUCTOR_SECTION)) {
|
if (this->writeSection(CONSTRUCTOR_SECTION)) {
|
||||||
const char* msg = "may not be present when constructor is overridden";
|
return;
|
||||||
this->failOnSection(CONSTRUCTOR_CODE_SECTION, msg);
|
|
||||||
this->failOnSection(CONSTRUCTOR_PARAMS_SECTION, msg);
|
|
||||||
this->failOnSection(COORD_TRANSFORM_SECTION, msg);
|
|
||||||
this->failOnSection(INITIALIZERS_SECTION, msg);
|
|
||||||
this->failOnSection(OPTIMIZATION_FLAGS_SECTION, msg);
|
|
||||||
}
|
}
|
||||||
this->writef(" %s(", fFullName.c_str());
|
this->writef(" %s(", fFullName.c_str());
|
||||||
const char* separator = "";
|
const char* separator = "";
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
|
this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
|
||||||
param->fName.c_str());
|
param->fName.c_str());
|
||||||
separator = ", ";
|
separator = ", ";
|
||||||
@ -176,38 +165,23 @@ void HCodeGenerator::writeConstructor() {
|
|||||||
}
|
}
|
||||||
this->writef(")");
|
this->writef(")");
|
||||||
this->writeSection(INITIALIZERS_SECTION, "\n , ");
|
this->writeSection(INITIALIZERS_SECTION, "\n , ");
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
const char* name = param->fName.c_str();
|
const char* name = param->fName.c_str();
|
||||||
if (param->fType.kind() == Type::kSampler_Kind) {
|
if (param->fType.kind() == Type::kSampler_Kind) {
|
||||||
this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name);
|
this->writef("\n , %s(std::move(%s))", FieldName(name).c_str(),
|
||||||
for (const Section* s : fSectionAndParameterHelper.getSections(
|
name);
|
||||||
SAMPLER_PARAMS_SECTION)) {
|
|
||||||
if (s->fArgument == name) {
|
|
||||||
this->writef(", %s", s->fText.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->writef(")");
|
|
||||||
} else {
|
} else {
|
||||||
this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
|
this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
|
|
||||||
String field = FieldName(s->fArgument.c_str());
|
|
||||||
this->writef("\n , %sCoordTransform(%s, %s.proxy())", field.c_str(), s->fText.c_str(),
|
|
||||||
field.c_str());
|
|
||||||
}
|
|
||||||
this->writef(" {\n");
|
this->writef(" {\n");
|
||||||
this->writeSection(CONSTRUCTOR_CODE_SECTION);
|
this->writeSection(CONSTRUCTOR_CODE_SECTION);
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
if (param->fType.kind() == Type::kSampler_Kind) {
|
if (param->fType.kind() == Type::kSampler_Kind) {
|
||||||
this->writef(" this->addTextureSampler(&%s);\n",
|
this->writef(" this->addTextureSampler(&%s);\n",
|
||||||
FieldName(param->fName.c_str()).c_str());
|
FieldName(param->fName.c_str()).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
|
|
||||||
String field = FieldName(s->fArgument.c_str());
|
|
||||||
this->writef(" this->addCoordTransform(&%sCoordTransform);\n", field.c_str());
|
|
||||||
}
|
|
||||||
this->writef(" this->initClassID<%s>();\n"
|
this->writef(" this->initClassID<%s>();\n"
|
||||||
" }\n",
|
" }\n",
|
||||||
fFullName.c_str());
|
fFullName.c_str());
|
||||||
@ -215,14 +189,10 @@ void HCodeGenerator::writeConstructor() {
|
|||||||
|
|
||||||
void HCodeGenerator::writeFields() {
|
void HCodeGenerator::writeFields() {
|
||||||
this->writeSection(FIELDS_SECTION);
|
this->writeSection(FIELDS_SECTION);
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
const char* name = param->fName.c_str();
|
const char* name = param->fName.c_str();
|
||||||
this->writef(" %s %s;\n", FieldType(param->fType).c_str(), FieldName(name).c_str());
|
this->writef(" %s %s;\n", FieldType(param->fType).c_str(), FieldName(name).c_str());
|
||||||
}
|
}
|
||||||
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
|
|
||||||
this->writef(" GrCoordTransform %sCoordTransform;\n",
|
|
||||||
FieldName(s->fArgument.c_str()).c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HCodeGenerator::generateCode() {
|
bool HCodeGenerator::generateCode() {
|
||||||
@ -236,13 +206,12 @@ bool HCodeGenerator::generateCode() {
|
|||||||
this->writeSection(HEADER_SECTION);
|
this->writeSection(HEADER_SECTION);
|
||||||
this->writef("#include \"GrFragmentProcessor.h\"\n"
|
this->writef("#include \"GrFragmentProcessor.h\"\n"
|
||||||
"#include \"GrCoordTransform.h\"\n"
|
"#include \"GrCoordTransform.h\"\n"
|
||||||
"#include \"GrColorSpaceXform.h\"\n"
|
|
||||||
"#include \"effects/GrProxyMove.h\"\n");
|
"#include \"effects/GrProxyMove.h\"\n");
|
||||||
this->writef("class %s : public GrFragmentProcessor {\n"
|
this->writef("class %s : public GrFragmentProcessor {\n"
|
||||||
"public:\n",
|
"public:\n",
|
||||||
fFullName.c_str());
|
fFullName.c_str());
|
||||||
this->writeSection(CLASS_SECTION);
|
this->writeSection(CLASS_SECTION);
|
||||||
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
|
for (const auto& param : fSectionAndParameterHelper.fParameters) {
|
||||||
if (param->fType.kind() == Type::kSampler_Kind) {
|
if (param->fType.kind() == Type::kSampler_Kind) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,6 @@ private:
|
|||||||
|
|
||||||
void writeFields();
|
void writeFields();
|
||||||
|
|
||||||
void failOnSection(const char* section, const char* msg);
|
|
||||||
|
|
||||||
String fName;
|
String fName;
|
||||||
String fFullName;
|
String fFullName;
|
||||||
SectionAndParameterHelper fSectionAndParameterHelper;
|
SectionAndParameterHelper fSectionAndParameterHelper;
|
||||||
|
@ -18,20 +18,18 @@
|
|||||||
namespace SkSL {
|
namespace SkSL {
|
||||||
|
|
||||||
#define CLASS_SECTION "class"
|
#define CLASS_SECTION "class"
|
||||||
#define CONSTRUCTOR_SECTION "constructor"
|
|
||||||
#define CONSTRUCTOR_CODE_SECTION "constructorCode"
|
|
||||||
#define CONSTRUCTOR_PARAMS_SECTION "constructorParams"
|
|
||||||
#define COORD_TRANSFORM_SECTION "coordTransform"
|
|
||||||
#define CPP_SECTION "cpp"
|
#define CPP_SECTION "cpp"
|
||||||
#define CPP_END_SECTION "cppEnd"
|
#define CPP_END_SECTION "cppEnd"
|
||||||
#define HEADER_SECTION "header"
|
#define HEADER_SECTION "header"
|
||||||
#define HEADER_END_SECTION "headerEnd"
|
#define HEADER_END_SECTION "headerEnd"
|
||||||
|
#define CONSTRUCTOR_PARAMS_SECTION "constructorParams"
|
||||||
|
#define CONSTRUCTOR_SECTION "constructor"
|
||||||
|
#define CONSTRUCTOR_CODE_SECTION "constructorCode"
|
||||||
|
#define INITIALIZERS_SECTION "initializers"
|
||||||
#define EMIT_CODE_SECTION "emitCode"
|
#define EMIT_CODE_SECTION "emitCode"
|
||||||
#define FIELDS_SECTION "fields"
|
#define FIELDS_SECTION "fields"
|
||||||
#define INITIALIZERS_SECTION "initializers"
|
|
||||||
#define MAKE_SECTION "make"
|
#define MAKE_SECTION "make"
|
||||||
#define OPTIMIZATION_FLAGS_SECTION "optimizationFlags"
|
#define OPTIMIZATION_FLAGS_SECTION "optimizationFlags"
|
||||||
#define SAMPLER_PARAMS_SECTION "samplerParams"
|
|
||||||
#define SET_DATA_SECTION "setData"
|
#define SET_DATA_SECTION "setData"
|
||||||
#define TEST_CODE_SECTION "test"
|
#define TEST_CODE_SECTION "test"
|
||||||
|
|
||||||
@ -67,12 +65,11 @@ public:
|
|||||||
errors.error(s->fPosition,
|
errors.error(s->fPosition,
|
||||||
("unsupported section '@" + s->fName + "'").c_str());
|
("unsupported section '@" + s->fName + "'").c_str());
|
||||||
}
|
}
|
||||||
if (!SectionPermitsDuplicates(s->fName.c_str()) &&
|
if (fSections.find(s->fName) != fSections.end()) {
|
||||||
fSections.find(s->fName) != fSections.end()) {
|
|
||||||
errors.error(s->fPosition,
|
errors.error(s->fPosition,
|
||||||
("duplicate section '@" + s->fName + "'").c_str());
|
("duplicate section '@" + s->fName + "'").c_str());
|
||||||
}
|
}
|
||||||
fSections[s->fName].push_back(s);
|
fSections[s->fName] = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -81,28 +78,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Section* getSection(const char* name) {
|
|
||||||
ASSERT(!SectionPermitsDuplicates(name));
|
|
||||||
auto found = fSections.find(name);
|
|
||||||
if (found == fSections.end()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
ASSERT(found->second.size() == 1);
|
|
||||||
return found->second[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const Section*> getSections(const char* name) {
|
|
||||||
auto found = fSections.find(name);
|
|
||||||
if (found == fSections.end()) {
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
return found->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Variable*>& getParameters() {
|
|
||||||
return fParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsParameter(const Variable& var) {
|
static bool IsParameter(const Variable& var) {
|
||||||
return (var.fModifiers.fFlags & Modifiers::kIn_Flag) &&
|
return (var.fModifiers.fFlags & Modifiers::kIn_Flag) &&
|
||||||
-1 == var.fModifiers.fLayout.fBuiltin;
|
-1 == var.fModifiers.fLayout.fBuiltin;
|
||||||
@ -110,39 +85,29 @@ public:
|
|||||||
|
|
||||||
static bool IsSupportedSection(const char* name) {
|
static bool IsSupportedSection(const char* name) {
|
||||||
return !strcmp(name, CLASS_SECTION) ||
|
return !strcmp(name, CLASS_SECTION) ||
|
||||||
|
!strcmp(name, CPP_SECTION) ||
|
||||||
|
!strcmp(name, CPP_END_SECTION) ||
|
||||||
|
!strcmp(name, HEADER_SECTION) ||
|
||||||
|
!strcmp(name, HEADER_END_SECTION) ||
|
||||||
!strcmp(name, CONSTRUCTOR_SECTION) ||
|
!strcmp(name, CONSTRUCTOR_SECTION) ||
|
||||||
!strcmp(name, CONSTRUCTOR_CODE_SECTION) ||
|
!strcmp(name, CONSTRUCTOR_CODE_SECTION) ||
|
||||||
!strcmp(name, CONSTRUCTOR_PARAMS_SECTION) ||
|
!strcmp(name, CONSTRUCTOR_PARAMS_SECTION) ||
|
||||||
!strcmp(name, COORD_TRANSFORM_SECTION) ||
|
|
||||||
!strcmp(name, CPP_SECTION) ||
|
|
||||||
!strcmp(name, CPP_END_SECTION) ||
|
|
||||||
!strcmp(name, EMIT_CODE_SECTION) ||
|
!strcmp(name, EMIT_CODE_SECTION) ||
|
||||||
!strcmp(name, FIELDS_SECTION) ||
|
!strcmp(name, FIELDS_SECTION) ||
|
||||||
!strcmp(name, HEADER_SECTION) ||
|
|
||||||
!strcmp(name, HEADER_END_SECTION) ||
|
|
||||||
!strcmp(name, INITIALIZERS_SECTION) ||
|
!strcmp(name, INITIALIZERS_SECTION) ||
|
||||||
!strcmp(name, MAKE_SECTION) ||
|
!strcmp(name, MAKE_SECTION) ||
|
||||||
!strcmp(name, OPTIMIZATION_FLAGS_SECTION) ||
|
!strcmp(name, OPTIMIZATION_FLAGS_SECTION) ||
|
||||||
!strcmp(name, SAMPLER_PARAMS_SECTION) ||
|
|
||||||
!strcmp(name, SET_DATA_SECTION) ||
|
!strcmp(name, SET_DATA_SECTION) ||
|
||||||
!strcmp(name, TEST_CODE_SECTION);
|
!strcmp(name, TEST_CODE_SECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SectionAcceptsArgument(const char* name) {
|
static bool SectionAcceptsArgument(const char* name) {
|
||||||
return !strcmp(name, COORD_TRANSFORM_SECTION) ||
|
return !strcmp(name, SET_DATA_SECTION) ||
|
||||||
!strcmp(name, SAMPLER_PARAMS_SECTION) ||
|
|
||||||
!strcmp(name, SET_DATA_SECTION) ||
|
|
||||||
!strcmp(name, TEST_CODE_SECTION);
|
!strcmp(name, TEST_CODE_SECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SectionPermitsDuplicates(const char* name) {
|
|
||||||
return !strcmp(name, COORD_TRANSFORM_SECTION) ||
|
|
||||||
!strcmp(name, SAMPLER_PARAMS_SECTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<const Variable*> fParameters;
|
std::vector<const Variable*> fParameters;
|
||||||
std::unordered_map<String, std::vector<const Section*>> fSections;
|
std::unordered_map<String, const Section*> fSections;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace SkSL
|
} // namespace SkSL
|
||||||
|
@ -82,7 +82,6 @@ DEF_TEST(SkSLFPHelloWorld, r) {
|
|||||||
"#if SK_SUPPORT_GPU\n"
|
"#if SK_SUPPORT_GPU\n"
|
||||||
"#include \"GrFragmentProcessor.h\"\n"
|
"#include \"GrFragmentProcessor.h\"\n"
|
||||||
"#include \"GrCoordTransform.h\"\n"
|
"#include \"GrCoordTransform.h\"\n"
|
||||||
"#include \"GrColorSpaceXform.h\"\n"
|
|
||||||
"#include \"effects/GrProxyMove.h\"\n"
|
"#include \"effects/GrProxyMove.h\"\n"
|
||||||
"class GrTest : public GrFragmentProcessor {\n"
|
"class GrTest : public GrFragmentProcessor {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user