1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/effects/GrSimpleTextureEffect.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "GrSimpleTextureEffect.h" 1.12 +#include "gl/GrGLEffect.h" 1.13 +#include "gl/GrGLSL.h" 1.14 +#include "gl/GrGLTexture.h" 1.15 +#include "GrTBackendEffectFactory.h" 1.16 +#include "GrTexture.h" 1.17 + 1.18 +class GrGLSimpleTextureEffect : public GrGLEffect { 1.19 +public: 1.20 + GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 1.21 + : INHERITED (factory) { 1.22 + } 1.23 + 1.24 + virtual void emitCode(GrGLShaderBuilder* builder, 1.25 + const GrDrawEffect& drawEffect, 1.26 + EffectKey key, 1.27 + const char* outputColor, 1.28 + const char* inputColor, 1.29 + const TransformedCoordsArray& coords, 1.30 + const TextureSamplerArray& samplers) SK_OVERRIDE { 1.31 + builder->fsCodeAppendf("\t%s = ", outputColor); 1.32 + builder->fsAppendTextureLookupAndModulate(inputColor, 1.33 + samplers[0], 1.34 + coords[0].c_str(), 1.35 + coords[0].type()); 1.36 + builder->fsCodeAppend(";\n"); 1.37 + } 1.38 + 1.39 +private: 1.40 + typedef GrGLEffect INHERITED; 1.41 +}; 1.42 + 1.43 +/////////////////////////////////////////////////////////////////////////////// 1.44 + 1.45 +void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 1.46 + this->updateConstantColorComponentsForModulation(color, validFlags); 1.47 +} 1.48 + 1.49 +const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { 1.50 + return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance(); 1.51 +} 1.52 + 1.53 +/////////////////////////////////////////////////////////////////////////////// 1.54 + 1.55 +GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); 1.56 + 1.57 +GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random, 1.58 + GrContext*, 1.59 + const GrDrawTargetCaps&, 1.60 + GrTexture* textures[]) { 1.61 + int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 1.62 + GrEffectUnitTest::kAlphaTextureIdx; 1.63 + static const SkShader::TileMode kTileModes[] = { 1.64 + SkShader::kClamp_TileMode, 1.65 + SkShader::kRepeat_TileMode, 1.66 + SkShader::kMirror_TileMode, 1.67 + }; 1.68 + SkShader::TileMode tileModes[] = { 1.69 + kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 1.70 + kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 1.71 + }; 1.72 + GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : 1.73 + GrTextureParams::kNone_FilterMode); 1.74 + 1.75 + static const GrCoordSet kCoordSets[] = { 1.76 + kLocal_GrCoordSet, 1.77 + kPosition_GrCoordSet 1.78 + }; 1.79 + GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoordSets))]; 1.80 + 1.81 + const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 1.82 + return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); 1.83 +}