gfx/skia/trunk/src/gpu/effects/GrCustomCoordsTextureEffect.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "GrCustomCoordsTextureEffect.h"
michael@0 9 #include "gl/GrGLEffect.h"
michael@0 10 #include "gl/GrGLSL.h"
michael@0 11 #include "gl/GrGLTexture.h"
michael@0 12 #include "gl/GrGLVertexEffect.h"
michael@0 13 #include "GrTBackendEffectFactory.h"
michael@0 14 #include "GrTexture.h"
michael@0 15
michael@0 16 class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect {
michael@0 17 public:
michael@0 18 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect)
michael@0 19 : INHERITED (factory) {}
michael@0 20
michael@0 21 virtual void emitCode(GrGLFullShaderBuilder* builder,
michael@0 22 const GrDrawEffect& drawEffect,
michael@0 23 EffectKey key,
michael@0 24 const char* outputColor,
michael@0 25 const char* inputColor,
michael@0 26 const TransformedCoordsArray&,
michael@0 27 const TextureSamplerArray& samplers) SK_OVERRIDE {
michael@0 28 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVertexAttribs());
michael@0 29
michael@0 30 SkString fsCoordName;
michael@0 31 const char* vsVaryingName;
michael@0 32 const char* fsVaryingNamePtr;
michael@0 33 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsVaryingNamePtr);
michael@0 34 fsCoordName = fsVaryingNamePtr;
michael@0 35
michael@0 36 const char* attrName =
michael@0 37 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0])->c_str();
michael@0 38 builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName);
michael@0 39
michael@0 40 builder->fsCodeAppendf("\t%s = ", outputColor);
michael@0 41 builder->fsAppendTextureLookupAndModulate(inputColor,
michael@0 42 samplers[0],
michael@0 43 fsCoordName.c_str(),
michael@0 44 kVec2f_GrSLType);
michael@0 45 builder->fsCodeAppend(";\n");
michael@0 46 }
michael@0 47
michael@0 48 virtual void setData(const GrGLUniformManager& uman,
michael@0 49 const GrDrawEffect& drawEffect) SK_OVERRIDE {}
michael@0 50
michael@0 51 private:
michael@0 52 typedef GrGLVertexEffect INHERITED;
michael@0 53 };
michael@0 54
michael@0 55 ///////////////////////////////////////////////////////////////////////////////
michael@0 56
michael@0 57 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture,
michael@0 58 const GrTextureParams& params)
michael@0 59 : fTextureAccess(texture, params) {
michael@0 60 this->addTextureAccess(&fTextureAccess);
michael@0 61 this->addVertexAttrib(kVec2f_GrSLType);
michael@0 62 }
michael@0 63
michael@0 64 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const {
michael@0 65 const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEffect>(other);
michael@0 66 return fTextureAccess == cte.fTextureAccess;
michael@0 67 }
michael@0 68
michael@0 69 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color,
michael@0 70 uint32_t* validFlags) const {
michael@0 71 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
michael@0 72 GrPixelConfigIsOpaque(this->texture(0)->config())) {
michael@0 73 *validFlags = kA_GrColorComponentFlag;
michael@0 74 } else {
michael@0 75 *validFlags = 0;
michael@0 76 }
michael@0 77 }
michael@0 78
michael@0 79 const GrBackendEffectFactory& GrCustomCoordsTextureEffect::getFactory() const {
michael@0 80 return GrTBackendEffectFactory<GrCustomCoordsTextureEffect>::getInstance();
michael@0 81 }
michael@0 82
michael@0 83 ///////////////////////////////////////////////////////////////////////////////
michael@0 84
michael@0 85 GR_DEFINE_EFFECT_TEST(GrCustomCoordsTextureEffect);
michael@0 86
michael@0 87 GrEffectRef* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random,
michael@0 88 GrContext*,
michael@0 89 const GrDrawTargetCaps&,
michael@0 90 GrTexture* textures[]) {
michael@0 91 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
michael@0 92 GrEffectUnitTest::kAlphaTextureIdx;
michael@0 93 static const SkShader::TileMode kTileModes[] = {
michael@0 94 SkShader::kClamp_TileMode,
michael@0 95 SkShader::kRepeat_TileMode,
michael@0 96 SkShader::kMirror_TileMode,
michael@0 97 };
michael@0 98 SkShader::TileMode tileModes[] = {
michael@0 99 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
michael@0 100 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
michael@0 101 };
michael@0 102 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
michael@0 103 GrTextureParams::kNone_FilterMode);
michael@0 104
michael@0 105 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params);
michael@0 106 }

mercurial