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

Side by Side Diff: src/effects/SkMorphologyImageFilter.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/effects/SkMagnifierImageFilter.cpp ('k') | src/effects/SkPerlinNoiseShader.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 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkMorphologyImageFilter.h" 8 #include "SkMorphologyImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkRect.h" 13 #include "SkRect.h"
14 #include "SkMorphology_opts.h" 14 #include "SkMorphology_opts.h"
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #include "GrInvariantOutput.h" 17 #include "GrInvariantOutput.h"
18 #include "GrTexture.h" 18 #include "GrTexture.h"
19 #include "GrTBackendProcessorFactory.h" 19 #include "effects/Gr1DKernelEffect.h"
20 #include "gl/GrGLProcessor.h" 20 #include "gl/GrGLProcessor.h"
21 #include "gl/builders/GrGLProgramBuilder.h" 21 #include "gl/builders/GrGLProgramBuilder.h"
22 #include "effects/Gr1DKernelEffect.h"
23 #endif 22 #endif
24 23
25 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, 24 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX,
26 int radiusY, 25 int radiusY,
27 SkImageFilter* input, 26 SkImageFilter* input,
28 const CropRect* cropRect, 27 const CropRect* cropRect,
29 uint32_t uniqueID) 28 uint32_t uniqueID)
30 : INHERITED(1, &input, cropRect, uniqueID), fRadius(SkISize::Make(radiusX, r adiusY)) { 29 : INHERITED(1, &input, cropRect, uniqueID), fRadius(SkISize::Make(radiusX, r adiusY)) {
31 } 30 }
32 31
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 SkFlattenable* SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) { 260 SkFlattenable* SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) {
262 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 261 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
263 const int width = buffer.readInt(); 262 const int width = buffer.readInt();
264 const int height = buffer.readInt(); 263 const int height = buffer.readInt();
265 return Create(width, height, common.getInput(0), &common.cropRect(), common. uniqueID()); 264 return Create(width, height, common.getInput(0), &common.cropRect(), common. uniqueID());
266 } 265 }
267 266
268 #if SK_SUPPORT_GPU 267 #if SK_SUPPORT_GPU
269 268
270 /////////////////////////////////////////////////////////////////////////////// 269 ///////////////////////////////////////////////////////////////////////////////
271
272 class GrGLMorphologyEffect;
273
274 /** 270 /**
275 * Morphology effects. Depending upon the type of morphology, either the 271 * Morphology effects. Depending upon the type of morphology, either the
276 * component-wise min (Erode_Type) or max (Dilate_Type) of all pixels in the 272 * component-wise min (Erode_Type) or max (Dilate_Type) of all pixels in the
277 * kernel is selected as the new color. The new color is modulated by the input 273 * kernel is selected as the new color. The new color is modulated by the input
278 * color. 274 * color.
279 */ 275 */
280 class GrMorphologyEffect : public Gr1DKernelEffect { 276 class GrMorphologyEffect : public Gr1DKernelEffect {
281 277
282 public: 278 public:
283 279
284 enum MorphologyType { 280 enum MorphologyType {
285 kErode_MorphologyType, 281 kErode_MorphologyType,
286 kDilate_MorphologyType, 282 kDilate_MorphologyType,
287 }; 283 };
288 284
289 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius , 285 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius ,
290 MorphologyType type) { 286 MorphologyType type) {
291 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); 287 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type));
292 } 288 }
293 289
294 virtual ~GrMorphologyEffect(); 290 virtual ~GrMorphologyEffect();
295 291
296 MorphologyType type() const { return fType; } 292 MorphologyType type() const { return fType; }
297 293
298 static const char* Name() { return "Morphology"; } 294 virtual const char* name() const SK_OVERRIDE { return "Morphology"; }
299 295
300 typedef GrGLMorphologyEffect GLProcessor; 296 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons t SK_OVERRIDE;
301 297
302 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR IDE; 298 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE;
303 299
304 protected: 300 protected:
305 301
306 MorphologyType fType; 302 MorphologyType fType;
307 303
308 private: 304 private:
309 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; 305 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
310 306
311 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE; 307 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE;
312 308
313 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); 309 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType);
314 310
315 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 311 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
316 312
317 typedef Gr1DKernelEffect INHERITED; 313 typedef Gr1DKernelEffect INHERITED;
318 }; 314 };
319 315
320 /////////////////////////////////////////////////////////////////////////////// 316 ///////////////////////////////////////////////////////////////////////////////
321 317
322 class GrGLMorphologyEffect : public GrGLFragmentProcessor { 318 class GrGLMorphologyEffect : public GrGLFragmentProcessor {
323 public: 319 public:
324 GrGLMorphologyEffect (const GrBackendProcessorFactory&, const GrProcessor&); 320 GrGLMorphologyEffect(const GrProcessor&);
325 321
326 virtual void emitCode(GrGLFPBuilder*, 322 virtual void emitCode(GrGLFPBuilder*,
327 const GrFragmentProcessor&, 323 const GrFragmentProcessor&,
328 const char* outputColor, 324 const char* outputColor,
329 const char* inputColor, 325 const char* inputColor,
330 const TransformedCoordsArray&, 326 const TransformedCoordsArray&,
331 const TextureSamplerArray&) SK_OVERRIDE; 327 const TextureSamplerArray&) SK_OVERRIDE;
332 328
333 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder* b); 329 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder* b);
334 330
335 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE; 331 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
336 332
337 private: 333 private:
338 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } 334 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); }
339 335
340 int fRadius; 336 int fRadius;
341 GrMorphologyEffect::MorphologyType fType; 337 GrMorphologyEffect::MorphologyType fType;
342 GrGLProgramDataManager::UniformHandle fImageIncrementUni; 338 GrGLProgramDataManager::UniformHandle fImageIncrementUni;
343 339
344 typedef GrGLFragmentProcessor INHERITED; 340 typedef GrGLFragmentProcessor INHERITED;
345 }; 341 };
346 342
347 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendProcessorFactory& fact ory, 343 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) {
348 const GrProcessor& proc)
349 : INHERITED(factory) {
350 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); 344 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>();
351 fRadius = m.radius(); 345 fRadius = m.radius();
352 fType = m.type(); 346 fType = m.type();
353 } 347 }
354 348
355 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, 349 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder,
356 const GrFragmentProcessor&, 350 const GrFragmentProcessor&,
357 const char* outputColor, 351 const char* outputColor,
358 const char* inputColor, 352 const char* inputColor,
359 const TransformedCoordsArray& coords, 353 const TransformedCoordsArray& coords,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 415 }
422 416
423 /////////////////////////////////////////////////////////////////////////////// 417 ///////////////////////////////////////////////////////////////////////////////
424 418
425 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, 419 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture,
426 Direction direction, 420 Direction direction,
427 int radius, 421 int radius,
428 MorphologyType type) 422 MorphologyType type)
429 : Gr1DKernelEffect(texture, direction, radius) 423 : Gr1DKernelEffect(texture, direction, radius)
430 , fType(type) { 424 , fType(type) {
425 this->initClassID<GrMorphologyEffect>();
431 } 426 }
432 427
433 GrMorphologyEffect::~GrMorphologyEffect() { 428 GrMorphologyEffect::~GrMorphologyEffect() {
434 } 429 }
435 430
436 const GrBackendFragmentProcessorFactory& GrMorphologyEffect::getFactory() const { 431 void GrMorphologyEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyB uilder* b) const {
437 return GrTBackendFragmentProcessorFactory<GrMorphologyEffect>::getInstance() ; 432 GrGLMorphologyEffect::GenKey(*this, caps, b);
438 } 433 }
439 434
435 GrGLFragmentProcessor* GrMorphologyEffect::createGLInstance() const {
436 return SkNEW_ARGS(GrGLMorphologyEffect, (*this));
437 }
440 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 438 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
441 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); 439 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>();
442 return (this->radius() == s.radius() && 440 return (this->radius() == s.radius() &&
443 this->direction() == s.direction() && 441 this->direction() == s.direction() &&
444 this->type() == s.type()); 442 this->type() == s.type());
445 } 443 }
446 444
447 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t { 445 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t {
448 // This is valid because the color components of the result of the kernel al l come 446 // This is valid because the color components of the result of the kernel al l come
449 // exactly from existing values in the source texture. 447 // exactly from existing values in the source texture.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 SkBitmap* result, SkIPoint* offset) con st { 588 SkBitmap* result, SkIPoint* offset) con st {
591 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); 589 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset);
592 } 590 }
593 591
594 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, 592 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
595 SkBitmap* result, SkIPoint* offset) cons t { 593 SkBitmap* result, SkIPoint* offset) cons t {
596 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); 594 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset);
597 } 595 }
598 596
599 #endif 597 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMagnifierImageFilter.cpp ('k') | src/effects/SkPerlinNoiseShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698