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

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: add virtual op() method Created 4 years, 8 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 | « include/effects/SkMorphologyImageFilter.h ('k') | no next file » | 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 srcTexture.reset(scratch); 508 srcTexture.reset(scratch);
509 } 509 }
510 510
511 return SkSpecialImage::MakeFromGpu(input->internal_getProxy(), 511 return SkSpecialImage::MakeFromGpu(input->internal_getProxy(),
512 SkIRect::MakeWH(rect.width(), rect.height ()), 512 SkIRect::MakeWH(rect.width(), rect.height ()),
513 kNeedNewImageUniqueID_SpecialImage, 513 kNeedNewImageUniqueID_SpecialImage,
514 srcTexture); 514 srcTexture);
515 } 515 }
516 #endif 516 #endif
517 517
518 sk_sp<SkSpecialImage> SkMorphologyImageFilter::filterImageGeneric(bool dilate, 518 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce,
519 SkSpecialImage * source, 519 const Context& ctx,
520 const Context& ctx, 520 SkIPoint* offset) c onst {
521 SkIPoint* offs et) const {
522 SkIPoint inputOffset = SkIPoint::Make(0, 0); 521 SkIPoint inputOffset = SkIPoint::Make(0, 0);
523 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ; 522 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
524 if (!input) { 523 if (!input) {
525 return nullptr; 524 return nullptr;
526 } 525 }
527 526
528 SkIRect bounds; 527 SkIRect bounds;
529 input = this->applyCropRect(this->mapContext(ctx), input.get(), &inputOffset , &bounds); 528 input = this->applyCropRect(this->mapContext(ctx), input.get(), &inputOffset , &bounds);
530 if (!input) { 529 if (!input) {
531 return nullptr; 530 return nullptr;
(...skipping 13 matching lines...) Expand all
545 srcBounds.offset(-inputOffset); 544 srcBounds.offset(-inputOffset);
546 545
547 if (0 == width && 0 == height) { 546 if (0 == width && 0 == height) {
548 offset->fX = bounds.left(); 547 offset->fX = bounds.left();
549 offset->fY = bounds.top(); 548 offset->fY = bounds.top();
550 return input->makeSubset(srcBounds); 549 return input->makeSubset(srcBounds);
551 } 550 }
552 551
553 #if SK_SUPPORT_GPU 552 #if SK_SUPPORT_GPU
554 if (input->peekTexture() && input->peekTexture()->getContext()) { 553 if (input->peekTexture() && input->peekTexture()->getContext()) {
555 auto type = dilate ? GrMorphologyEffect::kDilate_MorphologyType 554 auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::kDilate_Mor phologyType
556 : GrMorphologyEffect::kErode_MorphologyType; 555 : GrMorphologyEffect::kErode_Morp hologyType;
557 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe, 556 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe,
558 SkISize::Make(width, heigh t))); 557 SkISize::Make(width, heigh t)));
559 if (result) { 558 if (result) {
560 offset->fX = bounds.left(); 559 offset->fX = bounds.left();
561 offset->fY = bounds.top(); 560 offset->fY = bounds.top();
562 } 561 }
563 return result; 562 return result;
564 } 563 }
565 #endif 564 #endif
566 565
(...skipping 12 matching lines...) Expand all
579 578
580 SkBitmap dst; 579 SkBitmap dst;
581 if (!dst.tryAllocPixels(info)) { 580 if (!dst.tryAllocPixels(info)) {
582 return nullptr; 581 return nullptr;
583 } 582 }
584 583
585 SkAutoLockPixels dstLock(dst); 584 SkAutoLockPixels dstLock(dst);
586 585
587 SkMorphologyImageFilter::Proc procX, procY; 586 SkMorphologyImageFilter::Proc procX, procY;
588 587
589 if (dilate) { 588 if (kDilate_Op == this->op()) {
590 procX = SkOpts::dilate_x; 589 procX = SkOpts::dilate_x;
591 procY = SkOpts::dilate_y; 590 procY = SkOpts::dilate_y;
592 } else { 591 } else {
593 procX = SkOpts::erode_x; 592 procX = SkOpts::erode_x;
594 procY = SkOpts::erode_y; 593 procY = SkOpts::erode_y;
595 } 594 }
596 595
597 if (width > 0 && height > 0) { 596 if (width > 0 && height > 0) {
598 SkBitmap tmp; 597 SkBitmap tmp;
599 if (!tmp.tryAllocPixels(info)) { 598 if (!tmp.tryAllocPixels(info)) {
(...skipping 15 matching lines...) Expand all
615 inputPixmap.rowBytesAsPixels(), 614 inputPixmap.rowBytesAsPixels(),
616 &dst, height, srcBounds); 615 &dst, height, srcBounds);
617 } 616 }
618 offset->fX = bounds.left(); 617 offset->fX = bounds.left();
619 offset->fY = bounds.top(); 618 offset->fY = bounds.top();
620 619
621 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), 620 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(),
622 SkIRect::MakeWH(bounds.width(), bounds .height()), 621 SkIRect::MakeWH(bounds.width(), bounds .height()),
623 dst); 622 dst);
624 } 623 }
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 }
OLDNEW
« no previous file with comments | « include/effects/SkMorphologyImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698