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

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

Issue 1834953002: Update Morphology image filter to store its type (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Change enum name Created 4 years, 9 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
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 10 matching lines...) Expand all
21 #include "GrInvariantOutput.h" 21 #include "GrInvariantOutput.h"
22 #include "GrTexture.h" 22 #include "GrTexture.h"
23 #include "SkGr.h" 23 #include "SkGr.h"
24 #include "effects/Gr1DKernelEffect.h" 24 #include "effects/Gr1DKernelEffect.h"
25 #include "glsl/GrGLSLFragmentProcessor.h" 25 #include "glsl/GrGLSLFragmentProcessor.h"
26 #include "glsl/GrGLSLFragmentShaderBuilder.h" 26 #include "glsl/GrGLSLFragmentShaderBuilder.h"
27 #include "glsl/GrGLSLProgramDataManager.h" 27 #include "glsl/GrGLSLProgramDataManager.h"
28 #include "glsl/GrGLSLUniformHandler.h" 28 #include "glsl/GrGLSLUniformHandler.h"
29 #endif 29 #endif
30 30
31 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, 31 SkMorphologyImageFilter::SkMorphologyImageFilter(Op op,
32 int radiusX,
32 int radiusY, 33 int radiusY,
33 SkImageFilter* input, 34 SkImageFilter* input,
34 const CropRect* cropRect) 35 const CropRect* cropRect)
35 : INHERITED(1, &input, cropRect) 36 : INHERITED(1, &input, cropRect)
37 , fOp(op)
36 , fRadius(SkISize::Make(radiusX, radiusY)) { 38 , fRadius(SkISize::Make(radiusX, radiusY)) {
37 } 39 }
38 40
39 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { 41 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const {
40 this->INHERITED::flatten(buffer); 42 this->INHERITED::flatten(buffer);
41 buffer.writeInt(fRadius.fWidth); 43 buffer.writeInt(fRadius.fWidth);
42 buffer.writeInt(fRadius.fHeight); 44 buffer.writeInt(fRadius.fHeight);
43 } 45 }
44 46
45 static void call_proc_X(SkMorphologyImageFilter::Proc procX, 47 static void call_proc_X(SkMorphologyImageFilter::Proc procX,
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 srcTexture.reset(scratch); 510 srcTexture.reset(scratch);
509 } 511 }
510 512
511 return SkSpecialImage::MakeFromGpu(input->internal_getProxy(), 513 return SkSpecialImage::MakeFromGpu(input->internal_getProxy(),
512 SkIRect::MakeWH(rect.width(), rect.height ()), 514 SkIRect::MakeWH(rect.width(), rect.height ()),
513 kNeedNewImageUniqueID_SpecialImage, 515 kNeedNewImageUniqueID_SpecialImage,
514 srcTexture); 516 srcTexture);
515 } 517 }
516 #endif 518 #endif
517 519
518 sk_sp<SkSpecialImage> SkMorphologyImageFilter::filterImageGeneric(bool dilate, 520 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce,
519 SkSpecialImage * source, 521 const Context& ctx,
520 const Context& ctx, 522 SkIPoint* offset) c onst {
521 SkIPoint* offs et) const {
522 SkIPoint inputOffset = SkIPoint::Make(0, 0); 523 SkIPoint inputOffset = SkIPoint::Make(0, 0);
523 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ; 524 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
524 if (!input) { 525 if (!input) {
525 return nullptr; 526 return nullptr;
526 } 527 }
527 528
528 SkIRect bounds; 529 SkIRect bounds;
529 input = this->applyCropRect(this->mapContext(ctx), input.get(), &inputOffset , &bounds); 530 input = this->applyCropRect(this->mapContext(ctx), input.get(), &inputOffset , &bounds);
530 if (!input) { 531 if (!input) {
531 return nullptr; 532 return nullptr;
(...skipping 13 matching lines...) Expand all
545 srcBounds.offset(-inputOffset); 546 srcBounds.offset(-inputOffset);
546 547
547 if (0 == width && 0 == height) { 548 if (0 == width && 0 == height) {
548 offset->fX = bounds.left(); 549 offset->fX = bounds.left();
549 offset->fY = bounds.top(); 550 offset->fY = bounds.top();
550 return input->makeSubset(srcBounds); 551 return input->makeSubset(srcBounds);
551 } 552 }
552 553
553 #if SK_SUPPORT_GPU 554 #if SK_SUPPORT_GPU
554 if (input->peekTexture()) { 555 if (input->peekTexture()) {
555 auto type = dilate ? GrMorphologyEffect::kDilate_MorphologyType 556 auto type = (kDilate_Op == fOp) ? GrMorphologyEffect::kDilate_Morphology Type
556 : GrMorphologyEffect::kErode_MorphologyType; 557 : GrMorphologyEffect::kErode_MorphologyT ype;
557 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe, 558 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe,
558 SkISize::Make(width, heigh t))); 559 SkISize::Make(width, heigh t)));
559 if (result) { 560 if (result) {
560 offset->fX = bounds.left(); 561 offset->fX = bounds.left();
561 offset->fY = bounds.top(); 562 offset->fY = bounds.top();
562 } 563 }
563 return result; 564 return result;
564 } 565 }
565 #endif 566 #endif
566 567
(...skipping 12 matching lines...) Expand all
579 580
580 SkBitmap dst; 581 SkBitmap dst;
581 if (!dst.tryAllocPixels(info)) { 582 if (!dst.tryAllocPixels(info)) {
582 return nullptr; 583 return nullptr;
583 } 584 }
584 585
585 SkAutoLockPixels dstLock(dst); 586 SkAutoLockPixels dstLock(dst);
586 587
587 SkMorphologyImageFilter::Proc procX, procY; 588 SkMorphologyImageFilter::Proc procX, procY;
588 589
589 if (dilate) { 590 if (kDilate_Op == fOp) {
590 procX = SkOpts::dilate_x; 591 procX = SkOpts::dilate_x;
591 procY = SkOpts::dilate_y; 592 procY = SkOpts::dilate_y;
592 } else { 593 } else {
593 procX = SkOpts::erode_x; 594 procX = SkOpts::erode_x;
594 procY = SkOpts::erode_y; 595 procY = SkOpts::erode_y;
595 } 596 }
596 597
597 if (width > 0 && height > 0) { 598 if (width > 0 && height > 0) {
598 SkBitmap tmp; 599 SkBitmap tmp;
599 if (!tmp.tryAllocPixels(info)) { 600 if (!tmp.tryAllocPixels(info)) {
(...skipping 15 matching lines...) Expand all
615 inputPixmap.rowBytesAsPixels(), 616 inputPixmap.rowBytesAsPixels(),
616 &dst, height, srcBounds); 617 &dst, height, srcBounds);
617 } 618 }
618 offset->fX = bounds.left(); 619 offset->fX = bounds.left();
619 offset->fY = bounds.top(); 620 offset->fY = bounds.top();
620 621
621 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), 622 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(),
622 SkIRect::MakeWH(bounds.width(), bounds .height()), 623 SkIRect::MakeWH(bounds.width(), bounds .height()),
623 dst); 624 dst);
624 } 625 }
625
626 sk_sp<SkSpecialImage> SkDilateImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx,
627 SkIPoint* offset) const {
628 return this->filterImageGeneric(true, source, ctx, offset);
629 }
630
631 sk_sp<SkSpecialImage> SkErodeImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx,
632 SkIPoint* offset) const {
633 return this->filterImageGeneric(false, source, ctx, offset);
634 }
635
OLDNEW
« include/effects/SkMorphologyImageFilter.h ('K') | « include/effects/SkMorphologyImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698