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

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

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

Powered by Google App Engine
This is Rietveld 408576698