From aa72eab5d82d4c2aa9f6f41755a001282443b042 Mon Sep 17 00:00:00 2001 From: "tomhudson@google.com" Date: Thu, 19 Jul 2012 18:01:07 +0000 Subject: Create GL implementation for GrSingleTextureEffect, use it instead of GrPaint::setTexture() or GrDrawState::setTexture() in GrContext.cpp http://codereview.appspot.com/6399053/ git-svn-id: http://skia.googlecode.com/svn/trunk@4677 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrContext.cpp | 16 ++++++++------ src/gpu/effects/GrSingleTextureEffect.cpp | 35 +++++++++++++++++++++++++++++++ src/gpu/effects/GrSingleTextureEffect.h | 11 ++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 67fa5ab0c5..ee5d3976c7 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -11,6 +11,7 @@ #include "effects/GrMorphologyEffect.h" #include "effects/GrConvolutionEffect.h" +#include "effects/GrSingleTextureEffect.h" #include "GrBufferAllocPool.h" #include "GrClipIterator.h" @@ -385,7 +386,8 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture( GrDrawTarget::kReset_ASRInit); GrDrawState* drawState = fGpu->drawState(); drawState->setRenderTarget(texture->asRenderTarget()); - drawState->setTexture(0, clampEntry.texture()); + drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, + (clampEntry.texture())))->unref(); GrSamplerState::Filter filter; // if filtering is not desired then we want to ensure all @@ -1425,7 +1427,7 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target, matrix.postIDiv(src->width(), src->height()); drawState->sampler(0)->reset(matrix); drawState->sampler(0)->setRAndBSwap(swapRAndB); - drawState->setTexture(0, src); + drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (src)))->unref(); GrRect rect; rect.setXYWH(0, 0, SK_Scalar1 * width, SK_Scalar1 * height); fGpu->drawSimpleRect(rect, NULL, 0x1); @@ -1464,8 +1466,8 @@ void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst) { drawState->setRenderTarget(dst); GrMatrix sampleM; sampleM.setIDiv(src->width(), src->height()); - drawState->setTexture(0, src); drawState->sampler(0)->reset(sampleM); + drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (src)))->unref(); SkRect rect = SkRect::MakeXYWH(0, 0, SK_Scalar1 * src->width(), SK_Scalar1 * src->height()); @@ -1559,12 +1561,12 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target, matrix.setTranslate(GrIntToScalar(left), GrIntToScalar(top)); drawState->setViewMatrix(matrix); drawState->setRenderTarget(target); - drawState->setTexture(0, texture); matrix.setIDiv(texture->width(), texture->height()); drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode, GrSamplerState::kNearest_Filter, matrix); + drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref(); drawState->sampler(0)->setRAndBSwap(swapRAndB); static const GrVertexLayout layout = 0; @@ -1853,7 +1855,8 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture, SkRect dstRect(srcRect); scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, i < scaleFactorY ? 0.5f : 1.0f); - paint.setTexture(0, srcTexture); + paint.textureSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, + (srcTexture)))->unref(); this->drawRectToRect(paint, dstRect, srcRect); srcRect = dstRect; srcTexture = dstTexture; @@ -1909,7 +1912,8 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture, paint.textureSampler(0)->matrix()->setIDiv(srcTexture->width(), srcTexture->height()); this->setRenderTarget(dstTexture->asRenderTarget()); - paint.setTexture(0, srcTexture); + paint.textureSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, + (srcTexture)))->unref(); SkRect dstRect(srcRect); scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); this->drawRectToRect(paint, dstRect, srcRect); diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index a373ebe4e1..d8b90a15fc 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -6,8 +6,39 @@ */ #include "effects/GrSingleTextureEffect.h" +#include "gl/GrGLProgramStage.h" +#include "gl/GrGLSL.h" +#include "gl/GrGLTexture.h" +#include "GrProgramStageFactory.h" #include "GrTexture.h" +// For brevity, and these definitions are likely to move to a different class soon. +typedef GrGLShaderBuilder::UniformHandle UniformHandle; +static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle; + +class GrGLSingleTextureEffect : public GrGLProgramStage { +public: + GrGLSingleTextureEffect(const GrProgramStageFactory& factory, + const GrCustomStage& stage) : INHERITED (factory) { } + + virtual void emitVS(GrGLShaderBuilder* builder, + const char* vertexCoords) SK_OVERRIDE { } + virtual void emitFS(GrGLShaderBuilder* builder, + const char* outputColor, + const char* inputColor, + const char* samplerName) SK_OVERRIDE { + builder->emitDefaultFetch(outputColor, samplerName); + } + + static inline StageKey GenKey(const GrCustomStage&) { return 0; } + +private: + + typedef GrGLProgramStage INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture) : fTexture (texture) { SkSafeRef(fTexture); @@ -26,4 +57,8 @@ GrTexture* GrSingleTextureEffect::texture(unsigned int index) const { return fTexture; } +const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const { + return GrTProgramStageFactory::getInstance(); +} + diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h index 9a6bd1cae3..c49dac8859 100644 --- a/src/gpu/effects/GrSingleTextureEffect.h +++ b/src/gpu/effects/GrSingleTextureEffect.h @@ -10,6 +10,11 @@ #include "GrCustomStage.h" +class GrGLSingleTextureEffect; + +/** + * An effect that merely blits a single texture; commonly used as a base class. + */ class GrSingleTextureEffect : public GrCustomStage { public: @@ -19,6 +24,12 @@ public: virtual unsigned int numTextures() const SK_OVERRIDE; virtual GrTexture* texture(unsigned int index) const SK_OVERRIDE; + static const char* Name() { return "Single Texture"; } + + typedef GrGLSingleTextureEffect GLProgramStage; + + virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; + private: GrTexture* fTexture; -- cgit v1.2.3