move GrGLPathProcessor back into GrPathProcessor

BUG=skia:

Review URL: https://codereview.chromium.org/1333423003
This commit is contained in:
joshualitt 2015-09-11 11:52:17 -07:00 committed by Commit bot
parent c4a83e2652
commit 102081aba2
6 changed files with 100 additions and 155 deletions

View File

@ -315,8 +315,6 @@
'<(skia_src_path)/gpu/gl/GrGLNoOpInterface.h',
'<(skia_src_path)/gpu/gl/GrGLPath.cpp',
'<(skia_src_path)/gpu/gl/GrGLPath.h',
'<(skia_src_path)/gpu/gl/GrGLPathProcessor.cpp',
'<(skia_src_path)/gpu/gl/GrGLPathProcessor.h',
'<(skia_src_path)/gpu/gl/GrGLPathRange.cpp',
'<(skia_src_path)/gpu/gl/GrGLPathRange.h',
'<(skia_src_path)/gpu/gl/GrGLPathRendering.cpp',

View File

@ -7,11 +7,110 @@
#include "GrPathProcessor.h"
#include "gl/GrGLPathProcessor.h"
#include "gl/GrGLGpu.h"
#include "glsl/GrGLSLCaps.h"
class GrGLPathProcessor : public GrGLPrimitiveProcessor {
public:
GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {}
static void GenKey(const GrPathProcessor& pathProc,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
b->add32(SkToInt(pathProc.opts().readsColor()) |
SkToInt(pathProc.opts().readsCoverage()) << 16);
}
void emitCode(EmitArgs& args) override {
GrGLGPBuilder* pb = args.fPB;
GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>();
// emit transforms
this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut);
// Setup uniform color
if (pathProc.opts().readsColor()) {
const char* stagedLocalVarName;
fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"Color",
&stagedLocalVarName);
fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName);
}
// setup constant solid coverage
if (pathProc.opts().readsCoverage()) {
fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
}
}
void emitTransforms(GrGLGPBuilder* pb, const TransformsIn& tin, TransformsOut* tout) {
tout->push_back_n(tin.count());
fInstalledTransforms.push_back_n(tin.count());
for (int i = 0; i < tin.count(); i++) {
const ProcCoords& coordTransforms = tin[i];
fInstalledTransforms[i].push_back_n(coordTransforms.count());
for (int t = 0; t < coordTransforms.count(); t++) {
GrSLType varyingType =
coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_GrSLType :
kVec2f_GrSLType;
SkString strVaryingName("MatrixCoord");
strVaryingName.appendf("_%i_%i", i, t);
GrGLVertToFrag v(varyingType);
fInstalledTransforms[i][t].fHandle =
pb->addSeparableVarying(strVaryingName.c_str(), &v).toIndex();
fInstalledTransforms[i][t].fType = varyingType;
SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords,
(SkString(v.fsIn()), varyingType));
}
}
}
void setData(const GrGLProgramDataManager& pd, const GrPrimitiveProcessor& primProc) override {
const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
if (pathProc.opts().readsColor() && pathProc.color() != fColor) {
GrGLfloat c[4];
GrColorToRGBAFloat(pathProc.color(), c);
pd.set4fv(fColorUniform, 1, c);
fColor = pathProc.color();
}
}
void setTransformData(const GrPrimitiveProcessor& primProc,
const GrGLProgramDataManager& pdman,
int index,
const SkTArray<const GrCoordTransform*, true>& coordTransforms) override {
const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
SkSTArray<2, Transform, true>& transforms = fInstalledTransforms[index];
int numTransforms = transforms.count();
for (int t = 0; t < numTransforms; ++t) {
SkASSERT(transforms[t].fHandle.isValid());
const SkMatrix& transform = GetTransformMatrix(pathProc.localMatrix(),
*coordTransforms[t]);
if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
continue;
}
transforms[t].fCurrentValue = transform;
SkASSERT(transforms[t].fType == kVec2f_GrSLType ||
transforms[t].fType == kVec3f_GrSLType);
unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
pdman.setPathFragmentInputTransform(transforms[t].fHandle, components, transform);
}
}
private:
UniformHandle fColorUniform;
GrColor fColor;
typedef GrGLPrimitiveProcessor INHERITED;
};
GrPathProcessor::GrPathProcessor(GrColor color,
const GrPipelineOptimizations& opts,
const SkMatrix& viewMatrix,

View File

@ -1,107 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrGLPathProcessor.h"
#include "GrPathProcessor.h"
#include "GrGLGpu.h"
#include "GrGLPathRendering.h"
GrGLPathProcessor::GrGLPathProcessor()
: fColor(GrColor_ILLEGAL) {}
void GrGLPathProcessor::emitCode(EmitArgs& args) {
GrGLGPBuilder* pb = args.fPB;
GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>();
// emit transforms
this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut);
// Setup uniform color
if (pathProc.opts().readsColor()) {
const char* stagedLocalVarName;
fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"Color",
&stagedLocalVarName);
fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName);
}
// setup constant solid coverage
if (pathProc.opts().readsCoverage()) {
fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
}
}
void GrGLPathProcessor::GenKey(const GrPathProcessor& pathProc,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
b->add32(SkToInt(pathProc.opts().readsColor()) |
SkToInt(pathProc.opts().readsCoverage()) << 16);
}
void GrGLPathProcessor::setData(const GrGLProgramDataManager& pdman,
const GrPrimitiveProcessor& primProc) {
const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
if (pathProc.opts().readsColor() && pathProc.color() != fColor) {
GrGLfloat c[4];
GrColorToRGBAFloat(pathProc.color(), c);
pdman.set4fv(fColorUniform, 1, c);
fColor = pathProc.color();
}
}
void GrGLPathProcessor::emitTransforms(GrGLGPBuilder* pb, const TransformsIn& tin,
TransformsOut* tout) {
tout->push_back_n(tin.count());
fInstalledTransforms.push_back_n(tin.count());
for (int i = 0; i < tin.count(); i++) {
const ProcCoords& coordTransforms = tin[i];
fInstalledTransforms[i].push_back_n(coordTransforms.count());
for (int t = 0; t < coordTransforms.count(); t++) {
GrSLType varyingType =
coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_GrSLType :
kVec2f_GrSLType;
SkString strVaryingName("MatrixCoord");
strVaryingName.appendf("_%i_%i", i, t);
GrGLVertToFrag v(varyingType);
fInstalledTransforms[i][t].fHandle =
pb->addSeparableVarying(strVaryingName.c_str(), &v).toIndex();
fInstalledTransforms[i][t].fType = varyingType;
SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords,
(SkString(v.fsIn()), varyingType));
}
}
}
void GrGLPathProcessor::setTransformData(
const GrPrimitiveProcessor& primProc,
const GrGLProgramDataManager& pdman,
int index,
const SkTArray<const GrCoordTransform*, true>& coordTransforms) {
const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
SkSTArray<2, Transform, true>& transforms = fInstalledTransforms[index];
int numTransforms = transforms.count();
for (int t = 0; t < numTransforms; ++t) {
SkASSERT(transforms[t].fHandle.isValid());
const SkMatrix& transform = GetTransformMatrix(pathProc.localMatrix(),
*coordTransforms[t]);
if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
continue;
}
transforms[t].fCurrentValue = transform;
SkASSERT(transforms[t].fType == kVec2f_GrSLType ||
transforms[t].fType == kVec3f_GrSLType);
unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
pdman.setPathFragmentInputTransform(transforms[t].fHandle, components, transform);
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrGLPathProcessor_DEFINED
#define GrGLPathProcessor_DEFINED
#include "GrGLPrimitiveProcessor.h"
class GrPathProcessor;
class GrGLPathRendering;
class GrGLGpu;
class GrGLPathProcessor : public GrGLPrimitiveProcessor {
public:
GrGLPathProcessor();
static void GenKey(const GrPathProcessor&,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b);
void emitCode(EmitArgs&) override;
void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsOut*);
void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) override;
void setTransformData(const GrPrimitiveProcessor&,
const GrGLProgramDataManager&,
int index,
const SkTArray<const GrCoordTransform*, true>& transforms) override;
private:
UniformHandle fColorUniform;
GrColor fColor;
typedef GrGLPrimitiveProcessor INHERITED;
};
#endif

View File

@ -12,7 +12,6 @@
#include "GrCoordTransform.h"
#include "GrGLGeometryProcessor.h"
#include "GrGLGpu.h"
#include "GrGLPathProcessor.h"
#include "GrGLPathRendering.h"
#include "GrGLShaderVar.h"
#include "GrGLXferProcessor.h"

View File

@ -15,7 +15,6 @@
#include "SkTraceEvent.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLPathProcessor.h"
#include "gl/GrGLProgram.h"
#include "gl/GrGLSLPrettyPrint.h"
#include "gl/GrGLXferProcessor.h"