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

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

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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
« no previous file with comments | « src/effects/GrCircleBlurFragmentProcessor.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 "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 11 matching lines...) Expand all
22 22
23 SK_TO_STRING_OVERRIDE() 23 SK_TO_STRING_OVERRIDE()
24 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl) 24 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl)
25 25
26 protected: 26 protected:
27 void flatten(SkWriteBuffer&) const override; 27 void flatten(SkWriteBuffer&) const override;
28 28
29 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 29 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
30 SkBitmap* result, SkIPoint* offset) const override; 30 SkBitmap* result, SkIPoint* offset) const override;
31 #if SK_SUPPORT_GPU 31 #if SK_SUPPORT_GPU
32 bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&, 32 bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*,
33 const SkIRect& bounds) const override; 33 const SkMatrix&, const SkIRect& bounds, GrRenderTar get* dst) const override;
34 #endif 34 #endif
35 35
36 private: 36 private:
37 SkRegion fRegion; 37 SkRegion fRegion;
38 SkScalar fInnerThreshold; 38 SkScalar fInnerThreshold;
39 SkScalar fOuterThreshold; 39 SkScalar fOuterThreshold;
40 typedef SkImageFilter INHERITED; 40 typedef SkImageFilter INHERITED;
41 }; 41 };
42 42
43 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, 43 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
(...skipping 17 matching lines...) Expand all
61 #include "glsl/GrGLSLFragmentShaderBuilder.h" 61 #include "glsl/GrGLSLFragmentShaderBuilder.h"
62 #include "glsl/GrGLSLProgramBuilder.h" 62 #include "glsl/GrGLSLProgramBuilder.h"
63 #include "glsl/GrGLSLProgramDataManager.h" 63 #include "glsl/GrGLSLProgramDataManager.h"
64 64
65 class AlphaThresholdEffect : public GrFragmentProcessor { 65 class AlphaThresholdEffect : public GrFragmentProcessor {
66 66
67 public: 67 public:
68 static GrFragmentProcessor* Create(GrTexture* texture, 68 static GrFragmentProcessor* Create(GrTexture* texture,
69 GrTexture* maskTexture, 69 GrTexture* maskTexture,
70 float innerThreshold, 70 float innerThreshold,
71 float outerThreshold) { 71 float outerThreshold, GrRenderTarget* dst ) {
72 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou terThreshold); 72 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold,
73 outerThreshold, dst);
73 } 74 }
74 75
75 virtual ~AlphaThresholdEffect() {}; 76 virtual ~AlphaThresholdEffect() {};
76 77
77 const char* name() const override { return "Alpha Threshold"; } 78 const char* name() const override { return "Alpha Threshold"; }
78 79
79 float innerThreshold() const { return fInnerThreshold; } 80 float innerThreshold() const { return fInnerThreshold; }
80 float outerThreshold() const { return fOuterThreshold; } 81 float outerThreshold() const { return fOuterThreshold; }
81 82
82 private: 83 private:
83 AlphaThresholdEffect(GrTexture* texture, 84 AlphaThresholdEffect(GrTexture* texture,
84 GrTexture* maskTexture, 85 GrTexture* maskTexture,
85 float innerThreshold, 86 float innerThreshold,
86 float outerThreshold) 87 float outerThreshold,
88 GrRenderTarget* dst)
87 : fInnerThreshold(innerThreshold) 89 : fInnerThreshold(innerThreshold)
88 , fOuterThreshold(outerThreshold) 90 , fOuterThreshold(outerThreshold)
89 , fImageCoordTransform(kLocal_GrCoordSet, 91 , fImageCoordTransform(kLocal_GrCoordSet,
90 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture, 92 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture,
91 GrTextureParams::kNone_FilterMode) 93 GrTextureParams::kNone_FilterMode)
92 , fImageTextureAccess(texture) 94 , fImageTextureAccess(texture, GrTextureParams::kNone_FilterMode,SkShade r::kClamp_TileMode, dst)
93 , fMaskCoordTransform(kLocal_GrCoordSet, 95 , fMaskCoordTransform(kLocal_GrCoordSet,
94 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture, 96 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture,
95 GrTextureParams::kNone_FilterMode) 97 GrTextureParams::kNone_FilterMode)
96 , fMaskTextureAccess(maskTexture) { 98 , fMaskTextureAccess(maskTexture, GrTextureParams::kNone_FilterMode,SkSh ader::kClamp_TileMode, dst) {
97 this->initClassID<AlphaThresholdEffect>(); 99 this->initClassID<AlphaThresholdEffect>();
98 this->addCoordTransform(&fImageCoordTransform); 100 this->addCoordTransform(&fImageCoordTransform);
99 this->addTextureAccess(&fImageTextureAccess); 101 this->addTextureAccess(&fImageTextureAccess);
100 this->addCoordTransform(&fMaskCoordTransform); 102 this->addCoordTransform(&fMaskCoordTransform);
101 this->addTextureAccess(&fMaskTextureAccess); 103 this->addTextureAccess(&fMaskTextureAccess);
102 } 104 }
103 105
104 GrGLFragmentProcessor* onCreateGLInstance() const override; 106 GrGLFragmentProcessor* onCreateGLInstance() const override;
105 107
106 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 108 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 193
192 ///////////////////////////////////////////////////////////////////// 194 /////////////////////////////////////////////////////////////////////
193 195
194 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); 196 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect);
195 197
196 const GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) { 198 const GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) {
197 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx]; 199 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx];
198 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx]; 200 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx];
199 float innerThresh = d->fRandom->nextUScalar1(); 201 float innerThresh = d->fRandom->nextUScalar1();
200 float outerThresh = d->fRandom->nextUScalar1(); 202 float outerThresh = d->fRandom->nextUScalar1();
201 return AlphaThresholdEffect::Create(bmpTex, maskTex, innerThresh, outerThres h); 203 return AlphaThresholdEffect::Create(bmpTex, maskTex, innerThresh,
204 outerThresh, NULL);
202 } 205 }
203 206
204 /////////////////////////////////////////////////////////////////////////////// 207 ///////////////////////////////////////////////////////////////////////////////
205 208
206 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 209 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
207 GrProcessorKeyBuilder* b) const { 210 GrProcessorKeyBuilder* b) const {
208 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); 211 GrGLAlphaThresholdEffect::GenKey(*this, caps, b);
209 } 212 }
210 213
211 GrGLFragmentProcessor* AlphaThresholdEffect::onCreateGLInstance() const { 214 GrGLFragmentProcessor* AlphaThresholdEffect::onCreateGLInstance() const {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 : INHERITED(1, &input) 249 : INHERITED(1, &input)
247 , fRegion(region) 250 , fRegion(region)
248 , fInnerThreshold(innerThreshold) 251 , fInnerThreshold(innerThreshold)
249 , fOuterThreshold(outerThreshold) { 252 , fOuterThreshold(outerThreshold) {
250 } 253 }
251 254
252 #if SK_SUPPORT_GPU 255 #if SK_SUPPORT_GPU
253 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, 256 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp,
254 GrTexture* texture, 257 GrTexture* texture,
255 const SkMatrix& inMatrix, 258 const SkMatrix& inMatrix,
256 const SkIRect&) const { 259 const SkIRect&, GrRenderTar get* dst) const {
257 if (fp) { 260 if (fp) {
258 GrContext* context = texture->getContext(); 261 GrContext* context = texture->getContext();
259 GrSurfaceDesc maskDesc; 262 GrSurfaceDesc maskDesc;
260 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { 263 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
261 maskDesc.fConfig = kAlpha_8_GrPixelConfig; 264 maskDesc.fConfig = kAlpha_8_GrPixelConfig;
262 } else { 265 } else {
263 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; 266 maskDesc.fConfig = kRGBA_8888_GrPixelConfig;
264 } 267 }
265 maskDesc.fFlags = kRenderTarget_GrSurfaceFlag; 268 maskDesc.fFlags = kRenderTarget_GrSurfaceFlag;
266 // Add one pixel of border to ensure that clamp mode will be all zeros 269 // Add one pixel of border to ensure that clamp mode will be all zeros
(...skipping 14 matching lines...) Expand all
281 SkRegion::Iterator iter(fRegion); 284 SkRegion::Iterator iter(fRegion);
282 drawContext->clear(nullptr, 0x0, true); 285 drawContext->clear(nullptr, 0x0, true);
283 286
284 while (!iter.done()) { 287 while (!iter.done()) {
285 SkRect rect = SkRect::Make(iter.rect()); 288 SkRect rect = SkRect::Make(iter.rect());
286 drawContext->drawRect(GrClip::WideOpen(), grPaint, inMatrix, rec t); 289 drawContext->drawRect(GrClip::WideOpen(), grPaint, inMatrix, rec t);
287 iter.next(); 290 iter.next();
288 } 291 }
289 } 292 }
290 293
294 // TODO: whoever uses the resulting 'fp' needs to "use" the correct
295 // drawContext
291 *fp = AlphaThresholdEffect::Create(texture, 296 *fp = AlphaThresholdEffect::Create(texture,
292 maskTexture, 297 maskTexture,
293 fInnerThreshold, 298 fInnerThreshold,
294 fOuterThreshold); 299 fOuterThreshold, dst);
295 } 300 }
296 return true; 301 return true;
297 } 302 }
298 #endif 303 #endif
299 304
300 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 305 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
301 this->INHERITED::flatten(buffer); 306 this->INHERITED::flatten(buffer);
302 buffer.writeScalar(fInnerThreshold); 307 buffer.writeScalar(fInnerThreshold);
303 buffer.writeScalar(fOuterThreshold); 308 buffer.writeScalar(fOuterThreshold);
304 buffer.writeRegion(fRegion); 309 buffer.writeRegion(fRegion);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 375 }
371 376
372 #ifndef SK_IGNORE_TO_STRING 377 #ifndef SK_IGNORE_TO_STRING
373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 378 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
374 str->appendf("SkAlphaThresholdImageFilter: ("); 379 str->appendf("SkAlphaThresholdImageFilter: (");
375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 380 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
376 str->append(")"); 381 str->append(")");
377 } 382 }
378 #endif 383 #endif
379 384
OLDNEW
« no previous file with comments | « src/effects/GrCircleBlurFragmentProcessor.cpp ('k') | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698