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

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

Issue 1571033002: remove imagefilter::sizeconstraint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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/SkLightingImageFilter.cpp ('k') | src/effects/SkXfermodeImageFilter.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"
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 morphType, bounds, direction); 541 morphType, bounds, direction);
542 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec t, middleDstRect, 542 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec t, middleDstRect,
543 radius, morphType, direction); 543 radius, morphType, direction);
544 } 544 }
545 } 545 }
546 546
547 bool apply_morphology(const SkBitmap& input, 547 bool apply_morphology(const SkBitmap& input,
548 const SkIRect& rect, 548 const SkIRect& rect,
549 GrMorphologyEffect::MorphologyType morphType, 549 GrMorphologyEffect::MorphologyType morphType,
550 SkISize radius, 550 SkISize radius,
551 SkBitmap* dst, 551 SkBitmap* dst) {
552 GrTextureProvider::SizeConstraint constraint) {
553 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); 552 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture()));
554 SkASSERT(srcTexture); 553 SkASSERT(srcTexture);
555 GrContext* context = srcTexture->getContext(); 554 GrContext* context = srcTexture->getContext();
556 555
557 // setup new clip 556 // setup new clip
558 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), 557 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
559 SkIntToScalar(srcTexture->height()))); 558 SkIntToScalar(srcTexture->height())));
560 559
561 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); 560 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
562 GrSurfaceDesc desc; 561 GrSurfaceDesc desc;
563 desc.fFlags = kRenderTarget_GrSurfaceFlag; 562 desc.fFlags = kRenderTarget_GrSurfaceFlag;
564 desc.fWidth = rect.width(); 563 desc.fWidth = rect.width();
565 desc.fHeight = rect.height(); 564 desc.fHeight = rect.height();
566 desc.fConfig = kSkia8888_GrPixelConfig; 565 desc.fConfig = kSkia8888_GrPixelConfig;
567 SkIRect srcRect = rect; 566 SkIRect srcRect = rect;
568 567
569 if (radius.fWidth > 0) { 568 if (radius.fWidth > 0) {
570 GrTextureProvider::SizeConstraint horiConstraint = constraint; 569 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c);
571 if (radius.fHeight > 0) {
572 // Optimization: we will fall through and allocate the "real" textur e after this one
573 // so ours can be approximate (likely faster to allocate)
574 horiConstraint = GrTextureProvider::kApprox_SizeConstraint;
575 }
576
577 GrTexture* scratch = context->textureProvider()->createTexture(desc, hor iConstraint);
578 if (nullptr == scratch) { 570 if (nullptr == scratch) {
579 return false; 571 return false;
580 } 572 }
581 SkAutoTUnref<GrDrawContext> dstDrawContext( 573 SkAutoTUnref<GrDrawContext> dstDrawContext(
582 context->drawContext(scratch->as RenderTarget())); 574 context->drawContext(scratch->as RenderTarget()));
583 if (!dstDrawContext) { 575 if (!dstDrawContext) {
584 return false; 576 return false;
585 } 577 }
586 578
587 apply_morphology_pass(dstDrawContext, clip, srcTexture, 579 apply_morphology_pass(dstDrawContext, clip, srcTexture,
588 srcRect, dstRect, radius.fWidth, morphType, 580 srcRect, dstRect, radius.fWidth, morphType,
589 Gr1DKernelEffect::kX_Direction); 581 Gr1DKernelEffect::kX_Direction);
590 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, 582 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
591 dstRect.width(), radius.fHeight); 583 dstRect.width(), radius.fHeight);
592 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ? 584 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ?
593 SK_ColorWHITE : 585 SK_ColorWHITE :
594 SK_ColorTRANSPARENT; 586 SK_ColorTRANSPARENT;
595 dstDrawContext->clear(&clearRect, clearColor, false); 587 dstDrawContext->clear(&clearRect, clearColor, false);
596 588
597 srcTexture.reset(scratch); 589 srcTexture.reset(scratch);
598 srcRect = dstRect; 590 srcRect = dstRect;
599 } 591 }
600 if (radius.fHeight > 0) { 592 if (radius.fHeight > 0) {
601 GrTexture* scratch = context->textureProvider()->createTexture(desc, con straint); 593 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c);
602 if (nullptr == scratch) { 594 if (nullptr == scratch) {
603 return false; 595 return false;
604 } 596 }
605 SkAutoTUnref<GrDrawContext> dstDrawContext( 597 SkAutoTUnref<GrDrawContext> dstDrawContext(
606 context->drawContext(scratch->as RenderTarget())); 598 context->drawContext(scratch->as RenderTarget()));
607 if (!dstDrawContext) { 599 if (!dstDrawContext) {
608 return false; 600 return false;
609 } 601 }
610 602
611 apply_morphology_pass(dstDrawContext, clip, srcTexture, 603 apply_morphology_pass(dstDrawContext, clip, srcTexture,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 srcBounds.offset(-srcOffset); 641 srcBounds.offset(-srcOffset);
650 if (width == 0 && height == 0) { 642 if (width == 0 && height == 0) {
651 input.extractSubset(result, srcBounds); 643 input.extractSubset(result, srcBounds);
652 offset->fX = bounds.left(); 644 offset->fX = bounds.left();
653 offset->fY = bounds.top(); 645 offset->fY = bounds.top();
654 return true; 646 return true;
655 } 647 }
656 648
657 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType 649 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType
658 : GrMorphologyEffect::kErod e_MorphologyType; 650 : GrMorphologyEffect::kErod e_MorphologyType;
659 if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result, 651 if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result)) {
660 GrTextureProvider::FromImageFilter(ctx.sizeConstraint( )))) {
661 return false; 652 return false;
662 } 653 }
663 offset->fX = bounds.left(); 654 offset->fX = bounds.left();
664 offset->fY = bounds.top(); 655 offset->fY = bounds.top();
665 return true; 656 return true;
666 } 657 }
667 658
668 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t Context& ctx, 659 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t Context& ctx,
669 SkBitmap* result, SkIPoint* offset) con st { 660 SkBitmap* result, SkIPoint* offset) con st {
670 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); 661 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset);
671 } 662 }
672 663
673 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, 664 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
674 SkBitmap* result, SkIPoint* offset) cons t { 665 SkBitmap* result, SkIPoint* offset) cons t {
675 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); 666 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset);
676 } 667 }
677 668
678 #endif 669 #endif
OLDNEW
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | src/effects/SkXfermodeImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698