Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: src/gpu/effects/GrCustomCoordsTextureEffect.cpp

Issue 24018007: Add a GrCustomCoordsTextureEffect class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrCustomCoordsTextureEffect.h ('k') | src/gpu/effects/GrSimpleTextureEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrCustomCoordsTextureEffect.h"
9 #include "gl/GrGLEffect.h"
10 #include "gl/GrGLEffectMatrix.h"
11 #include "gl/GrGLSL.h"
12 #include "gl/GrGLTexture.h"
13 #include "GrTBackendEffectFactory.h"
14 #include "GrTexture.h"
15
16 class GrGLCustomCoordsTextureEffect : public GrGLEffect {
17 public:
18 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G rDrawEffect& drawEffect)
19 : INHERITED (factory) {}
20
21 virtual void emitCode(GrGLShaderBuilder* builder,
22 const GrDrawEffect& drawEffect,
23 EffectKey key,
24 const char* outputColor,
25 const char* inputColor,
26 const TextureSamplerArray& samplers) SK_OVERRIDE {
27 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuil der();
28 SkASSERT(NULL != vertexBuilder);
29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe rtexAttribs());
30
31 SkString fsCoordName;
32 const char* vsVaryingName;
33 const char* fsVaryingNamePtr;
34 vertexBuilder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingNa me, &fsVaryingNamePtr);
35 fsCoordName = fsVaryingNamePtr;
36
37 const char* attrName =
38 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi ces()[0])->c_str();
39 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName);
40
41 builder->fsCodeAppendf("\t%s = ", outputColor);
42 builder->fsAppendTextureLookupAndModulate(inputColor,
43 samplers[0],
44 fsCoordName.c_str(),
45 kVec2f_GrSLType);
46 builder->fsCodeAppend(";\n");
47 }
48
49 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
50 return 1 << GrGLEffectMatrix::kKeyBits;
51 }
52
53 virtual void setData(const GrGLUniformManager& uman,
54 const GrDrawEffect& drawEffect) SK_OVERRIDE {}
55
56 private:
57 typedef GrGLEffect INHERITED;
58 };
59
60 ///////////////////////////////////////////////////////////////////////////////
61
62 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture,
63 const GrTextureParams& params)
64 : fTextureAccess(texture, params) {
65 this->addTextureAccess(&fTextureAccess);
66 this->addVertexAttrib(kVec2f_GrSLType);
67 }
68
69 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const {
70 const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEff ect>(other);
71 return fTextureAccess == cte.fTextureAccess;
72 }
73
74 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color,
75 uint32_t* validFlag s) const {
76 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color ) &&
77 GrPixelConfigIsOpaque(this->texture(0)->config())) {
78 *validFlags = kA_GrColorComponentFlag;
79 } else {
80 *validFlags = 0;
81 }
82 }
83
84 const GrBackendEffectFactory& GrCustomCoordsTextureEffect::getFactory() const {
85 return GrTBackendEffectFactory<GrCustomCoordsTextureEffect>::getInstance();
86 }
87
88 ///////////////////////////////////////////////////////////////////////////////
89
90 GR_DEFINE_EFFECT_TEST(GrCustomCoordsTextureEffect);
91
92 GrEffectRef* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random,
93 GrContext*,
94 const GrDrawTargetCaps&,
95 GrTexture* textures[]) {
96 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
97 GrEffectUnitTest::kAlphaTextureIdx;
98 static const SkShader::TileMode kTileModes[] = {
99 SkShader::kClamp_TileMode,
100 SkShader::kRepeat_TileMode,
101 SkShader::kMirror_TileMode,
102 };
103 SkShader::TileMode tileModes[] = {
104 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
106 };
107 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode :
108 GrTextureParams::kNon e_FilterMode);
109
110 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params);
111 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCustomCoordsTextureEffect.h ('k') | src/gpu/effects/GrSimpleTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698