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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/SkMatrixConvolutionImageFilter.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 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 */ 136 */
137 class GrMorphologyEffect : public Gr1DKernelEffect { 137 class GrMorphologyEffect : public Gr1DKernelEffect {
138 138
139 public: 139 public:
140 140
141 enum MorphologyType { 141 enum MorphologyType {
142 kErode_MorphologyType, 142 kErode_MorphologyType,
143 kDilate_MorphologyType, 143 kDilate_MorphologyType,
144 }; 144 };
145 145
146 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius , 146 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, Direction dir, int ra dius,
147 MorphologyType type) { 147 MorphologyType type) {
148 return new GrMorphologyEffect(tex, dir, radius, type); 148 return sk_sp<GrFragmentProcessor>(new GrMorphologyEffect(tex, dir, radiu s, type));
149 } 149 }
150 150
151 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius , 151 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, Direction dir, int ra dius,
152 MorphologyType type, float bounds[2]) { 152 MorphologyType type, float bounds[2]) {
153 return new GrMorphologyEffect(tex, dir, radius, type, bounds); 153 return sk_sp<GrFragmentProcessor>(new GrMorphologyEffect(tex, dir, radiu s, type, bounds));
154 } 154 }
155 155
156 virtual ~GrMorphologyEffect(); 156 virtual ~GrMorphologyEffect();
157 157
158 MorphologyType type() const { return fType; } 158 MorphologyType type() const { return fType; }
159 bool useRange() const { return fUseRange; } 159 bool useRange() const { return fUseRange; }
160 const float* range() const { return fRange; } 160 const float* range() const { return fRange; }
161 161
162 const char* name() const override { return "Morphology"; } 162 const char* name() const override { return "Morphology"; }
163 163
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t { 363 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t {
364 // This is valid because the color components of the result of the kernel al l come 364 // This is valid because the color components of the result of the kernel al l come
365 // exactly from existing values in the source texture. 365 // exactly from existing values in the source texture.
366 this->updateInvariantOutputForModulation(inout); 366 this->updateInvariantOutputForModulation(inout);
367 } 367 }
368 368
369 /////////////////////////////////////////////////////////////////////////////// 369 ///////////////////////////////////////////////////////////////////////////////
370 370
371 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMorphologyEffect); 371 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMorphologyEffect);
372 372
373 const GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d ) { 373 sk_sp<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d ) {
374 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : 374 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
375 GrProcessorUnitTest::kAlphaTextureIdx; 375 GrProcessorUnitTest::kAlphaTextureIdx;
376 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; 376 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction;
377 static const int kMaxRadius = 10; 377 static const int kMaxRadius = 10;
378 int radius = d->fRandom->nextRangeU(1, kMaxRadius); 378 int radius = d->fRandom->nextRangeU(1, kMaxRadius);
379 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo rphologyType : 379 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo rphologyType :
380 GrMorphologyEffect::kDilate_Morph ologyType; 380 GrMorphologyEffect::kDilate_Morph ologyType;
381 381
382 return GrMorphologyEffect::Create(d->fTextures[texIdx], dir, radius, type); 382 return GrMorphologyEffect::Make(d->fTextures[texIdx], dir, radius, type);
383 } 383 }
384 384
385 385
386 static void apply_morphology_rect(GrDrawContext* drawContext, 386 static void apply_morphology_rect(GrDrawContext* drawContext,
387 const GrClip& clip, 387 const GrClip& clip,
388 GrTexture* texture, 388 GrTexture* texture,
389 const SkIRect& srcRect, 389 const SkIRect& srcRect,
390 const SkIRect& dstRect, 390 const SkIRect& dstRect,
391 int radius, 391 int radius,
392 GrMorphologyEffect::MorphologyType morphType, 392 GrMorphologyEffect::MorphologyType morphType,
393 float bounds[2], 393 float bounds[2],
394 Gr1DKernelEffect::Direction direction) { 394 Gr1DKernelEffect::Direction direction) {
395 GrPaint paint; 395 GrPaint paint;
396 // SRGBTODO: AllowSRGBInputs? 396 // SRGBTODO: AllowSRGBInputs?
397 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(texture, 397 paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture,
398 direction, 398 direction,
399 radius, 399 radius,
400 morphType, 400 morphType,
401 bounds))->unref() ; 401 bounds));
402 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 402 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
403 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect ), 403 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect ),
404 SkRect::Make(srcRect)); 404 SkRect::Make(srcRect));
405 } 405 }
406 406
407 static void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, 407 static void apply_morphology_rect_no_bounds(GrDrawContext* drawContext,
408 const GrClip& clip, 408 const GrClip& clip,
409 GrTexture* texture, 409 GrTexture* texture,
410 const SkIRect& srcRect, 410 const SkIRect& srcRect,
411 const SkIRect& dstRect, 411 const SkIRect& dstRect,
412 int radius, 412 int radius,
413 GrMorphologyEffect::MorphologyType m orphType, 413 GrMorphologyEffect::MorphologyType m orphType,
414 Gr1DKernelEffect::Direction directio n) { 414 Gr1DKernelEffect::Direction directio n) {
415 GrPaint paint; 415 GrPaint paint;
416 // SRGBTODO: AllowSRGBInputs? 416 // SRGBTODO: AllowSRGBInputs?
417 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(texture, 417 paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, direction, radius,
418 direction, 418 morphType));
419 radius,
420 morphType))->unre f();
421 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 419 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
422 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect ), 420 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect ),
423 SkRect::Make(srcRect)); 421 SkRect::Make(srcRect));
424 } 422 }
425 423
426 static void apply_morphology_pass(GrDrawContext* drawContext, 424 static void apply_morphology_pass(GrDrawContext* drawContext,
427 const GrClip& clip, 425 const GrClip& clip,
428 GrTexture* texture, 426 GrTexture* texture,
429 const SkIRect& srcRect, 427 const SkIRect& srcRect,
430 const SkIRect& dstRect, 428 const SkIRect& dstRect,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), 625 inputBM.getAddr32(srcBounds.left(), srcBounds.top()),
628 inputBM.rowBytesAsPixels(), 626 inputBM.rowBytesAsPixels(),
629 &dst, height, srcBounds); 627 &dst, height, srcBounds);
630 } 628 }
631 offset->fX = bounds.left(); 629 offset->fX = bounds.left();
632 offset->fY = bounds.top(); 630 offset->fY = bounds.top();
633 631
634 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()), 632 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()),
635 dst, &source->props()); 633 dst, &source->props());
636 } 634 }
OLDNEW
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkPerlinNoiseShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698