SK_DEFINE_INST_COUNT(GrGLProgram)
-#define GL_CALL(X) GR_GL_CALL(fContext.interface(), X)
-#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContext.interface(), R, X)
+#define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
+#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false,
"Print the source code for all shaders generated.");
inline const char* dual_source_output_name() { return "dualSourceOut"; }
}
-GrGLProgram* GrGLProgram::Create(const GrGLContext& gl,
+GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu,
const GrGLProgramDesc& desc,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[]) {
- GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, colorStages, coverageStages));
+ GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gpu, desc, colorStages, coverageStages));
if (!program->succeeded()) {
delete program;
program = NULL;
return program;
}
-GrGLProgram::GrGLProgram(const GrGLContext& gl,
+GrGLProgram::GrGLProgram(GrGpuGL* gpu,
const GrGLProgramDesc& desc,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[])
-: fContext(gl)
-, fUniformManager(gl) {
+: fGpu(gpu)
+, fUniformManager(gpu) {
fDesc = desc;
fVShaderID = 0;
fGShaderID = 0;
#if GR_GL_EXPERIMENTAL_GS
// TODO: The builder should add all this glue code.
if (fDesc.getHeader().fExperimentalGS) {
- SkASSERT(fContext.info().glslGeneration() >= k150_GrGLSLGeneration);
+ SkASSERT(fGpu->glslGeneration() >= k150_GrGLSLGeneration);
vertexBuilder->fGSHeader.append("layout(triangles) in;\n"
"layout(triangle_strip, max_vertices = 6) out;\n");
vertexBuilder->gsCodeAppend("\tfor (int i = 0; i < 3; ++i) {\n"
}
// Compiles a GL shader, returns shader ID or 0 if failed params have same meaning as glShaderSource
-GrGLuint compile_shader(const GrGLContext& gl,
+GrGLuint compile_shader(const GrGLInterface* gli,
GrGLenum type,
int stringCnt,
const char** strings,
"stringCount", SkStringPrintf("%i", stringCnt).c_str());
GrGLuint shader;
- GR_GL_CALL_RET(gl.interface(), shader, CreateShader(type));
+ GR_GL_CALL_RET(gli, shader, CreateShader(type));
if (0 == shader) {
return 0;
}
- const GrGLInterface* gli = gl.interface();
GrGLint compiled = GR_GL_INIT_ZERO;
GR_GL_CALL(gli, ShaderSource(shader, stringCnt, strings, stringLengths));
GR_GL_CALL(gli, CompileShader(shader));
}
// helper version of above for when shader is already flattened into a single SkString
-GrGLuint compile_shader(const GrGLContext& gl, GrGLenum type, const SkString& shader) {
+GrGLuint compile_shader(const GrGLInterface* gli, GrGLenum type, const SkString& shader) {
const GrGLchar* str = shader.c_str();
int length = shader.size();
- return compile_shader(gl, type, 1, &str, &length);
+ return compile_shader(gli, type, 1, &str, &length);
}
void expand_known_value4f(SkString* string, GrSLConstantVec vec) {
GrPrintf(shader.c_str());
GrPrintf("\n");
}
- if (!(fVShaderID = compile_shader(fContext, GR_GL_VERTEX_SHADER, shader))) {
+ if (!(fVShaderID = compile_shader(fGpu->glInterface(), GR_GL_VERTEX_SHADER, shader))) {
return false;
}
GrPrintf(shader.c_str());
GrPrintf("\n");
}
- if (!(fGShaderID = compile_shader(fContext, GR_GL_GEOMETRY_SHADER, shader))) {
+ if (!(fGShaderID = compile_shader(fGpu->glInterface(), GR_GL_GEOMETRY_SHADER, shader))) {
return false;
}
}
GrPrintf(shader.c_str());
GrPrintf("\n");
}
- if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader))) {
+ if (!(fFShaderID = compile_shader(fGpu->glInterface(), GR_GL_FRAGMENT_SHADER, shader))) {
return false;
}
bool needsVertexShader = true;
- GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc, needsVertexShader);
+ GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, needsVertexShader);
if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuilder()) {
const char* viewMName;
bool dualSourceOutputWritten = false;
GrGLShaderVar colorOutput;
- bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneration(),
+ bool isColorDeclared = GrGLSLSetupFSColorOuput(fGpu->glslGeneration(),
declared_color_output_name(),
&colorOutput);
if (isColorDeclared) {
///////////////////////////////////////////////////////////////////////////////
-void GrGLProgram::setEffectData(GrGpuGL* gpu,
- const GrEffectStage& stage,
+void GrGLProgram::setEffectData(const GrEffectStage& stage,
const EffectAndSamplers& effect) {
// Let the GrGLEffect set its data.
const GrTextureAccess& access = (*stage.getEffect())->textureAccess(s);
GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture());
int unit = effect.fTextureUnits[s];
- gpu->bindTexture(unit, access.getParams(), texture);
+ fGpu->bindTexture(unit, access.getParams(), texture);
}
}
}
-void GrGLProgram::setData(GrGpuGL* gpu,
- GrDrawState::BlendOptFlags blendOpts,
+void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[],
const GrDeviceCoordTexture* dstCopy,
SharedGLState* sharedState) {
- const GrDrawState& drawState = gpu->getDrawState();
+ const GrDrawState& drawState = fGpu->getDrawState();
GrColor color;
GrColor coverage;
1.f / dstCopy->texture()->height());
GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
static GrTextureParams kParams; // the default is clamp, nearest filtering.
- gpu->bindTexture(fDstCopyTexUnit, kParams, texture);
+ fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
} else {
SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid());
SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid());
// We may have omitted the GrGLEffect because of the color filter logic in genProgram.
// This can be removed when the color filter is an effect.
if (NULL != fColorEffects[e].fGLEffect) {
- this->setEffectData(gpu, *colorStages[e], fColorEffects[e]);
+ this->setEffectData(*colorStages[e], fColorEffects[e]);
}
}
for (int e = 0; e < fCoverageEffects.count(); ++e) {
if (NULL != fCoverageEffects[e].fGLEffect) {
- this->setEffectData(gpu, *coverageStages[e], fCoverageEffects[e]);
+ this->setEffectData(*coverageStages[e], fCoverageEffects[e]);
}
}
}
public:
SK_DECLARE_INST_COUNT(GrGLProgram)
- static GrGLProgram* Create(const GrGLContext& gl,
+ static GrGLProgram* Create(GrGpuGL* gpu,
const GrGLProgramDesc& desc,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[]);
* GrGpuGL object to bind the textures required by the GrGLEffects. The color and coverage
* stages come from GrGLProgramDesc::Build().
*/
- void setData(GrGpuGL*,
- GrDrawState::BlendOptFlags,
+ void setData(GrDrawState::BlendOptFlags,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[],
const GrDeviceCoordTexture* dstCopy, // can be NULL
TextureUnitSArray fTextureUnits; // texture unit used for each entry of fSamplerUnis
};
- GrGLProgram(const GrGLContext& gl,
+ GrGLProgram(GrGpuGL* gpu,
const GrGLProgramDesc& desc,
const GrEffectStage* colorStages[],
const GrEffectStage* coverageStages[]);
const char* adjustInColor(const SkString& inColor) const;
// Helper for setData().
- void setEffectData(GrGpuGL* gpu, const GrEffectStage& stage, const EffectAndSamplers& effect);
+ void setEffectData(const GrEffectStage& stage, const EffectAndSamplers& effect);
// Helper for setData(). Makes GL calls to specify the initial color when there is not
// per-vertex colors.
SkTArray<EffectAndSamplers> fCoverageEffects;
GrGLProgramDesc fDesc;
- const GrGLContext& fContext;
+ GrGpuGL* fGpu;
GrGLUniformManager fUniformManager;
UniformHandles fUniformHandles;
#include "gl/GrGLShaderBuilder.h"
#include "gl/GrGLProgram.h"
#include "gl/GrGLUniformHandle.h"
+#include "gl/GrGpuGL.h"
#include "SkMatrix.h"
#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \
// once stages insert their own samplers.
// SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1i(uni.fFSLocation, texUnit));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1i(uni.fVSLocation, texUnit));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit));
}
}
SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1f(uni.fFSLocation, v0));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1f(uni.fVSLocation, v0));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0));
}
}
// arrays in VS and FS driver bug workaround, this can be enabled.
//SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation + offset, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform1fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation + offset, arrayCount, v));
}
}
SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform2f(uni.fFSLocation, v0, v1));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform2f(uni.fVSLocation, v0, v1));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1));
}
}
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform2fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation + offset, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform2fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation + offset, arrayCount, v));
}
}
SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
}
}
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform3fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation + offset, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform3fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation + offset, arrayCount, v));
}
}
SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3));
}
}
SkASSERT(arrayCount > 0);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform4fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation + offset, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), Uniform4fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation + offset, arrayCount, v));
}
}
// TODO: Re-enable this assert once texture matrices aren't forced on all effects
// SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix));
+ GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix));
+ GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix));
}
}
SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix));
+ GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix));
+ GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix));
}
}
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(),
+ GR_GL_CALL(fGpu->glInterface(),
UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(),
+ GR_GL_CALL(fGpu->glInterface(),
UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices));
}
}
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(),
+ GR_GL_CALL(fGpu->glInterface(),
UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fContext.interface(),
+ GR_GL_CALL(fGpu->glInterface(),
UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices));
}
}
SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount);
GrGLint location;
// TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
- GR_GL_CALL_RET(fContext.interface(), location,
+ GR_GL_CALL_RET(fGpu->glInterface(), location,
GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
fUniforms[i].fVSLocation = location;
#include "SkTArray.h"
-class GrGLContext;
+class GrGpuGL;
class SkMatrix;
/** Manages a program's uniforms.
friend class GrGLUniformManager; // For accessing toUniformIndex().
};
- GrGLUniformManager(const GrGLContext& context) : fContext(context) {}
+ GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {}
UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray);
};
SkTArray<Uniform, true> fUniforms;
- const GrGLContext& fContext;
+ GrGpuGL* fGpu;
};
#endif
ctx.info().caps()->print();
}
- fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext()));
+ fProgramCache = SkNEW_ARGS(ProgramCache, (this));
SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttribCnt);
virtual ~GrGpuGL();
const GrGLInterface* glInterface() const { return fGLContext.interface(); }
+ const GrGLContextInfo& ctxInfo() const { return fGLContext.info(); }
GrGLBinding glBinding() const { return fGLContext.info().binding(); }
GrGLVersion glVersion() const { return fGLContext.info().version(); }
GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); }
class ProgramCache : public ::GrNoncopyable {
public:
- ProgramCache(const GrGLContext& gl);
+ ProgramCache(GrGpuGL* gpu);
~ProgramCache();
void abandon();
int fCount;
unsigned int fCurrLRUStamp;
- const GrGLContext& fGL;
+ GrGpuGL* fGpu;
#ifdef PROGRAM_CACHE_STATS
int fTotalRequests;
int fCacheMisses;
}
};
-GrGpuGL::ProgramCache::ProgramCache(const GrGLContext& gl)
+GrGpuGL::ProgramCache::ProgramCache(GrGpuGL* gpu)
: fCount(0)
, fCurrLRUStamp(0)
- , fGL(gl)
+ , fGpu(gpu)
#ifdef PROGRAM_CACHE_STATS
, fTotalRequests(0)
, fCacheMisses(0)
#ifdef PROGRAM_CACHE_STATS
++fCacheMisses;
#endif
- GrGLProgram* program = GrGLProgram::Create(fGL, desc, colorStages, coverageStages);
+ GrGLProgram* program = GrGLProgram::Create(fGpu, desc, colorStages, coverageStages);
if (NULL == program) {
return NULL;
}
fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff);
this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff);
- fCurrentProgram->setData(this,
- blendOpts,
+ fCurrentProgram->setData(blendOpts,
colorStages.begin(),
coverageStages.begin(),
dstCopy,
numCoverageStages,
currAttribIndex);
- SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(),
+ SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this,
pdesc,
stages,
stages + numColorStages));