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

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: cleanup 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
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;
80
81 virtual uint32_t classID() const {
82 static uint32_t id = GenClassID();
83 return id;
84 }
81 85
82 private: 86 private:
83 AlphaThresholdEffect(GrTexture* texture, 87 AlphaThresholdEffect(GrTexture* texture,
84 GrTexture* maskTexture, 88 GrTexture* maskTexture,
85 float innerThreshold, 89 float innerThreshold,
86 float outerThreshold) 90 float outerThreshold)
87 : fInnerThreshold(innerThreshold) 91 : fInnerThreshold(innerThreshold)
88 , fOuterThreshold(outerThreshold) 92 , fOuterThreshold(outerThreshold)
89 , fImageCoordTransform(kLocal_GrCoordSet, 93 , fImageCoordTransform(kLocal_GrCoordSet,
90 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture) 94 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture)
(...skipping 18 matching lines...) Expand all
109 GrCoordTransform fImageCoordTransform; 113 GrCoordTransform fImageCoordTransform;
110 GrTextureAccess fImageTextureAccess; 114 GrTextureAccess fImageTextureAccess;
111 GrCoordTransform fMaskCoordTransform; 115 GrCoordTransform fMaskCoordTransform;
112 GrTextureAccess fMaskTextureAccess; 116 GrTextureAccess fMaskTextureAccess;
113 117
114 typedef GrFragmentProcessor INHERITED; 118 typedef GrFragmentProcessor INHERITED;
115 }; 119 };
116 120
117 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor { 121 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor {
118 public: 122 public:
119 GrGLAlphaThresholdEffect(const GrBackendProcessorFactory&, const GrProcessor &); 123 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {}
120 124
121 virtual void emitCode(GrGLFPBuilder*, 125 virtual void emitCode(GrGLFPBuilder*,
122 const GrFragmentProcessor&, 126 const GrFragmentProcessor&,
123 const char* outputColor, 127 const char* outputColor,
124 const char* inputColor, 128 const char* inputColor,
125 const TransformedCoordsArray&, 129 const TransformedCoordsArray&,
126 const TextureSamplerArray&) SK_OVERRIDE; 130 const TextureSamplerArray&) SK_OVERRIDE;
127 131
128 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE; 132 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
129 133
130 private: 134 private:
131 135
132 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; 136 GrGLProgramDataManager::UniformHandle fInnerThresholdVar;
133 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; 137 GrGLProgramDataManager::UniformHandle fOuterThresholdVar;
134 138
135 typedef GrGLFragmentProcessor INHERITED; 139 typedef GrGLFragmentProcessor INHERITED;
136 }; 140 };
137 141
138 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendProcessorFacto ry& factory,
139 const GrProcessor&)
140 : INHERITED(factory) {
141 }
142
143 void GrGLAlphaThresholdEffect::emitCode(GrGLFPBuilder* builder, 142 void GrGLAlphaThresholdEffect::emitCode(GrGLFPBuilder* builder,
144 const GrFragmentProcessor&, 143 const GrFragmentProcessor&,
145 const char* outputColor, 144 const char* outputColor,
146 const char* inputColor, 145 const char* inputColor,
147 const TransformedCoordsArray& coords, 146 const TransformedCoordsArray& coords,
148 const TextureSamplerArray& samplers) { 147 const TextureSamplerArray& samplers) {
149 fInnerThresholdVar = builder->addUniform( 148 fInnerThresholdVar = builder->addUniform(
150 GrGLProgramBuilder::kFragment_Visibility, 149 GrGLProgramBuilder::kFragment_Visibility,
151 kFloat_GrSLType, "inner_threshold"); 150 kFloat_GrSLType, "inner_threshold");
152 fOuterThresholdVar = builder->addUniform( 151 fOuterThresholdVar = builder->addUniform(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 GrTexture** textures) { 205 GrTexture** textures) {
207 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx]; 206 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx];
208 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx]; 207 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx];
209 float inner_thresh = random->nextUScalar1(); 208 float inner_thresh = random->nextUScalar1();
210 float outer_thresh = random->nextUScalar1(); 209 float outer_thresh = random->nextUScalar1();
211 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh); 210 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh);
212 } 211 }
213 212
214 /////////////////////////////////////////////////////////////////////////////// 213 ///////////////////////////////////////////////////////////////////////////////
215 214
216 const GrBackendFragmentProcessorFactory& AlphaThresholdEffect::getFactory() cons t { 215 void AlphaThresholdEffect::getGLProcessorKey(const GrGLCaps& caps,
217 return GrTBackendFragmentProcessorFactory<AlphaThresholdEffect>::getInstance (); 216 GrProcessorKeyBuilder* b) const {
217 GrGLAlphaThresholdEffect::GenKey(*this, caps, b);
218 }
219
220 GrGLFragmentProcessor* AlphaThresholdEffect::createGLInstance() const {
221 return SkNEW_ARGS(GrGLAlphaThresholdEffect, (*this));
218 } 222 }
219 223
220 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 224 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
221 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); 225 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>();
222 return (this->fInnerThreshold == s.fInnerThreshold && 226 return (this->fInnerThreshold == s.fInnerThreshold &&
223 this->fOuterThreshold == s.fOuterThreshold); 227 this->fOuterThreshold == s.fOuterThreshold);
224 } 228 }
225 229
226 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst { 230 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst {
227 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { 231 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 (U8CPU)(SkColorGetG(source) * scale), 370 (U8CPU)(SkColorGetG(source) * scale),
367 (U8CPU)(SkColorGetB(source) * scale)); 371 (U8CPU)(SkColorGetB(source) * scale));
368 } 372 }
369 } 373 }
370 dptr[y * dst->width() + x] = output_color; 374 dptr[y * dst->width() + x] = output_color;
371 } 375 }
372 } 376 }
373 377
374 return true; 378 return true;
375 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698