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

Side by Side Diff: src/effects/SkAlphaThresholdFilter.cpp

Issue 778453002: Remove backend factories (Closed) Base URL: https://skia.googlesource.com/skia.git@unichoice
Patch Set: more clang warnings 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
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAlphaThresholdFilter.h" 8 #include "SkAlphaThresholdFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 29 matching lines...) Expand all
40 SkScalar outerThreshold, 40 SkScalar outerThreshold,
41 SkImageFilter* input) { 41 SkImageFilter* input) {
42 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, innerThreshold, outer Threshold, input)); 42 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, innerThreshold, outer Threshold, input));
43 } 43 }
44 44
45 #if SK_SUPPORT_GPU 45 #if SK_SUPPORT_GPU
46 #include "GrContext.h" 46 #include "GrContext.h"
47 #include "GrCoordTransform.h" 47 #include "GrCoordTransform.h"
48 #include "GrFragmentProcessor.h" 48 #include "GrFragmentProcessor.h"
49 #include "GrInvariantOutput.h" 49 #include "GrInvariantOutput.h"
50 #include "gl/GrGLProcessor.h"
51 #include "gl/builders/GrGLProgramBuilder.h"
52 #include "GrTBackendProcessorFactory.h"
53 #include "GrTextureAccess.h" 50 #include "GrTextureAccess.h"
54 51
55 #include "SkGr.h" 52 #include "SkGr.h"
56 53
57 class GrGLAlphaThresholdEffect; 54 #include "gl/GrGLProcessor.h"
55 #include "gl/builders/GrGLProgramBuilder.h"
58 56
59 class AlphaThresholdEffect : public GrFragmentProcessor { 57 class AlphaThresholdEffect : public GrFragmentProcessor {
60 58
61 public: 59 public:
62 static GrFragmentProcessor* Create(GrTexture* texture, 60 static GrFragmentProcessor* Create(GrTexture* texture,
63 GrTexture* maskTexture, 61 GrTexture* maskTexture,
64 float innerThreshold, 62 float innerThreshold,
65 float outerThreshold) { 63 float outerThreshold) {
66 return SkNEW_ARGS(AlphaThresholdEffect, (texture, 64 return SkNEW_ARGS(AlphaThresholdEffect, (texture,
67 maskTexture, 65 maskTexture,
68 innerThreshold, 66 innerThreshold,
69 outerThreshold)); 67 outerThreshold));
70 } 68 }
71 69
72 virtual ~AlphaThresholdEffect() {}; 70 virtual ~AlphaThresholdEffect() {};
73 71
74 static const char* Name() { return "Alpha Threshold"; } 72 virtual const char* name() const SK_OVERRIDE { return "Alpha Threshold"; }
75 73
76 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR IDE;
77 float innerThreshold() const { return fInnerThreshold; } 74 float innerThreshold() const { return fInnerThreshold; }
78 float outerThreshold() const { return fOuterThreshold; } 75 float outerThreshold() const { return fOuterThreshold; }
79 76
80 typedef GrGLAlphaThresholdEffect GLProcessor; 77 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons t SK_OVERRIDE;
78
79 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE;
81 80
82 private: 81 private:
83 AlphaThresholdEffect(GrTexture* texture, 82 AlphaThresholdEffect(GrTexture* texture,
84 GrTexture* maskTexture, 83 GrTexture* maskTexture,
85 float innerThreshold, 84 float innerThreshold,
86 float outerThreshold) 85 float outerThreshold)
87 : fInnerThreshold(innerThreshold) 86 : fInnerThreshold(innerThreshold)
88 , fOuterThreshold(outerThreshold) 87 , fOuterThreshold(outerThreshold)
89 , fImageCoordTransform(kLocal_GrCoordSet, 88 , fImageCoordTransform(kLocal_GrCoordSet,
90 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture) 89 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture)
91 , fImageTextureAccess(texture) 90 , fImageTextureAccess(texture)
92 , fMaskCoordTransform(kLocal_GrCoordSet, 91 , fMaskCoordTransform(kLocal_GrCoordSet,
93 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture) 92 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture)
94 , fMaskTextureAccess(maskTexture) { 93 , fMaskTextureAccess(maskTexture) {
94 this->initClassID<AlphaThresholdEffect>();
95 this->addCoordTransform(&fImageCoordTransform); 95 this->addCoordTransform(&fImageCoordTransform);
96 this->addTextureAccess(&fImageTextureAccess); 96 this->addTextureAccess(&fImageTextureAccess);
97 this->addCoordTransform(&fMaskCoordTransform); 97 this->addCoordTransform(&fMaskCoordTransform);
98 this->addTextureAccess(&fMaskTextureAccess); 98 this->addTextureAccess(&fMaskTextureAccess);
99 } 99 }
100 100
101 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; 101 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
102 102
103 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE; 103 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE;
104 104
105 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 105 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
106 106
107 float fInnerThreshold; 107 float fInnerThreshold;
108 float fOuterThreshold; 108 float fOuterThreshold;
109 GrCoordTransform fImageCoordTransform; 109 GrCoordTransform fImageCoordTransform;
110 GrTextureAccess fImageTextureAccess; 110 GrTextureAccess fImageTextureAccess;
111 GrCoordTransform fMaskCoordTransform; 111 GrCoordTransform fMaskCoordTransform;
112 GrTextureAccess fMaskTextureAccess; 112 GrTextureAccess fMaskTextureAccess;
113 113
114 typedef GrFragmentProcessor INHERITED; 114 typedef GrFragmentProcessor INHERITED;
115 }; 115 };
116 116
117 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor { 117 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor {
118 public: 118 public:
119 GrGLAlphaThresholdEffect(const GrBackendProcessorFactory&, const GrProcessor &); 119 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {}
120 120
121 virtual void emitCode(GrGLFPBuilder*, 121 virtual void emitCode(GrGLFPBuilder*,
122 const GrFragmentProcessor&, 122 const GrFragmentProcessor&,
123 const char* outputColor, 123 const char* outputColor,
124 const char* inputColor, 124 const char* inputColor,
125 const TransformedCoordsArray&, 125 const TransformedCoordsArray&,
126 const TextureSamplerArray&) SK_OVERRIDE; 126 const TextureSamplerArray&) SK_OVERRIDE;
127 127
128 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE; 128 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
129 129
130 private: 130 private:
131 131
132 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; 132 GrGLProgramDataManager::UniformHandle fInnerThresholdVar;
133 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; 133 GrGLProgramDataManager::UniformHandle fOuterThresholdVar;
134 134
135 typedef GrGLFragmentProcessor INHERITED; 135 typedef GrGLFragmentProcessor INHERITED;
136 }; 136 };
137 137
138 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendProcessorFacto ry& factory,
139 const GrProcessor&)
140 : INHERITED(factory) {
141 }
142
143 void GrGLAlphaThresholdEffect::emitCode(GrGLFPBuilder* builder, 138 void GrGLAlphaThresholdEffect::emitCode(GrGLFPBuilder* builder,
144 const GrFragmentProcessor&, 139 const GrFragmentProcessor&,
145 const char* outputColor, 140 const char* outputColor,
146 const char* inputColor, 141 const char* inputColor,
147 const TransformedCoordsArray& coords, 142 const TransformedCoordsArray& coords,
148 const TextureSamplerArray& samplers) { 143 const TextureSamplerArray& samplers) {
149 fInnerThresholdVar = builder->addUniform( 144 fInnerThresholdVar = builder->addUniform(
150 GrGLProgramBuilder::kFragment_Visibility, 145 GrGLProgramBuilder::kFragment_Visibility,
151 kFloat_GrSLType, "inner_threshold"); 146 kFloat_GrSLType, "inner_threshold");
152 fOuterThresholdVar = builder->addUniform( 147 fOuterThresholdVar = builder->addUniform(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 GrTexture** textures) { 201 GrTexture** textures) {
207 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx]; 202 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx];
208 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx]; 203 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx];
209 float inner_thresh = random->nextUScalar1(); 204 float inner_thresh = random->nextUScalar1();
210 float outer_thresh = random->nextUScalar1(); 205 float outer_thresh = random->nextUScalar1();
211 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh); 206 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh);
212 } 207 }
213 208
214 /////////////////////////////////////////////////////////////////////////////// 209 ///////////////////////////////////////////////////////////////////////////////
215 210
216 const GrBackendFragmentProcessorFactory& AlphaThresholdEffect::getFactory() cons t { 211 void AlphaThresholdEffect::getGLProcessorKey(const GrGLCaps& caps,
217 return GrTBackendFragmentProcessorFactory<AlphaThresholdEffect>::getInstance (); 212 GrProcessorKeyBuilder* b) const {
213 GrGLAlphaThresholdEffect::GenKey(*this, caps, b);
214 }
215
216 GrGLFragmentProcessor* AlphaThresholdEffect::createGLInstance() const {
217 return SkNEW_ARGS(GrGLAlphaThresholdEffect, (*this));
218 } 218 }
219 219
220 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 220 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
221 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); 221 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>();
222 return (this->fInnerThreshold == s.fInnerThreshold && 222 return (this->fInnerThreshold == s.fInnerThreshold &&
223 this->fOuterThreshold == s.fOuterThreshold); 223 this->fOuterThreshold == s.fOuterThreshold);
224 } 224 }
225 225
226 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst { 226 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst {
227 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { 227 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 (U8CPU)(SkColorGetG(source) * scale), 366 (U8CPU)(SkColorGetG(source) * scale),
367 (U8CPU)(SkColorGetB(source) * scale)); 367 (U8CPU)(SkColorGetB(source) * scale));
368 } 368 }
369 } 369 }
370 dptr[y * dst->width() + x] = output_color; 370 dptr[y * dst->width() + x] = output_color;
371 } 371 }
372 } 372 }
373 373
374 return true; 374 return true;
375 } 375 }
OLDNEW
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698