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

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

Issue 786293002: Rename CustomCoordTextureEffect to GrBitmapTextGeoProc. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Review updates Created 6 years 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
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 "GrInvariantOutput.h"
10 #include "GrTexture.h"
11 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLSL.h"
13 #include "gl/GrGLTexture.h"
14 #include "gl/GrGLGeometryProcessor.h"
15 #include "gl/builders/GrGLProgramBuilder.h"
16
17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor {
18 public:
19 GrGLCustomCoordsTextureEffect(const GrGeometryProcessor&,
20 const GrBatchTracker&) {}
21
22 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
23 const GrCustomCoordsTextureEffect& cte =
24 args.fGP.cast<GrCustomCoordsTextureEffect>();
25
26 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
27
28 GrGLVertToFrag v(kVec2f_GrSLType);
29 args.fPB->addVarying("TextureCoords", &v);
30 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa me);
31
32 if (cte.inColor()) {
33 args.fPB->addPassThroughAttribute(cte.inColor(), args.fOutputColor);
34 }
35
36 // setup output coords
37 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), cte.inPo sition()->fName);
38 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), cte.inPosit ion()->fName);
39
40 // setup position varying
41 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition() ,
42 vsBuilder->uViewM(), cte.inPosition()->fName);
43
44 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
45 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage);
46 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT ype);
47 fsBuilder->codeAppend(";");
48 }
49
50 virtual void setData(const GrGLProgramDataManager&,
51 const GrGeometryProcessor&,
52 const GrBatchTracker&) SK_OVERRIDE {}
53
54 static inline void GenKey(const GrGeometryProcessor& proc,
55 const GrBatchTracker&,
56 const GrGLCaps&,
57 GrProcessorKeyBuilder* b) {
58 const GrCustomCoordsTextureEffect& gp = proc.cast<GrCustomCoordsTextureE ffect>();
59
60 b->add32(SkToBool(gp.inColor()));
61 }
62
63
64 private:
65 typedef GrGLGeometryProcessor INHERITED;
66 };
67
68 ///////////////////////////////////////////////////////////////////////////////
69
70 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture,
71 const GrTextureParams& params,
72 bool hasColor)
73 : fTextureAccess(texture, params), fInColor(NULL) {
74 this->initClassID<GrCustomCoordsTextureEffect>();
75 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert exAttribType));
76 if (hasColor) {
77 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte xAttribType));
78 this->setHasVertexColor();
79 }
80 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords",
81 kVec2f_GrVertexAttribT ype));
82 this->addTextureAccess(&fTextureAccess);
83 }
84
85 bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co nst {
86 const GrCustomCoordsTextureEffect& gp = other.cast<GrCustomCoordsTextureEffe ct>();
87 return SkToBool(this->inColor()) == SkToBool(gp.inColor());
88 }
89
90 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in out) const {
91 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
92 inout->mulByUnknownAlpha();
93 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
94 inout->mulByUnknownOpaqueColor();
95 } else {
96 inout->mulByUnknownColor();
97 }
98 }
99
100 void GrCustomCoordsTextureEffect::getGLProcessorKey(const GrBatchTracker& bt,
101 const GrGLCaps& caps,
102 GrProcessorKeyBuilder* b) co nst {
103 GrGLCustomCoordsTextureEffect::GenKey(*this, bt, caps, b);
104 }
105
106 GrGLGeometryProcessor*
107 GrCustomCoordsTextureEffect::createGLInstance(const GrBatchTracker& bt) const {
108 return SkNEW_ARGS(GrGLCustomCoordsTextureEffect, (*this, bt));
109 }
110 ///////////////////////////////////////////////////////////////////////////////
111
112 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect);
113
114 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random,
115 GrContext*,
116 const GrDrawTargetC aps&,
117 GrTexture* textures []) {
118 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
119 GrProcessorUnitTest::kAlphaTextureIdx;
120 static const SkShader::TileMode kTileModes[] = {
121 SkShader::kClamp_TileMode,
122 SkShader::kRepeat_TileMode,
123 SkShader::kMirror_TileMode,
124 };
125 SkShader::TileMode tileModes[] = {
126 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
127 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
128 };
129 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode :
130 GrTextureParams::kNon e_FilterMode);
131
132 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random- >nextBool());
133 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCustomCoordsTextureEffect.h ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698