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

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

Issue 1913743002: Add another dollop of sk_sp to SkSpecialImage and SkSpecialSurface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rm std::move Created 4 years, 7 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 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec t, middleDstRect, 467 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec t, middleDstRect,
468 radius, morphType, direction); 468 radius, morphType, direction);
469 } 469 }
470 } 470 }
471 471
472 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, 472 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
473 SkSpecialImage* input, 473 SkSpecialImage* input,
474 const SkIRect& rect, 474 const SkIRect& rect,
475 GrMorphologyEffect::MorphologyType morphType, 475 GrMorphologyEffect::MorphologyType morphType,
476 SkISize radius) { 476 SkISize radius) {
477 SkAutoTUnref<GrTexture> srcTexture(input->asTextureRef(context)); 477 sk_sp<GrTexture> srcTexture(input->asTextureRef(context));
478 SkASSERT(srcTexture); 478 SkASSERT(srcTexture);
479 479
480 // setup new clip 480 // setup new clip
481 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), 481 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
482 SkIntToScalar(srcTexture->height()))); 482 SkIntToScalar(srcTexture->height())));
483 483
484 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); 484 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
485 GrSurfaceDesc desc; 485 GrSurfaceDesc desc;
486 desc.fFlags = kRenderTarget_GrSurfaceFlag; 486 desc.fFlags = kRenderTarget_GrSurfaceFlag;
487 desc.fWidth = rect.width(); 487 desc.fWidth = rect.width();
488 desc.fHeight = rect.height(); 488 desc.fHeight = rect.height();
489 desc.fConfig = kSkia8888_GrPixelConfig; 489 desc.fConfig = kSkia8888_GrPixelConfig;
490 SkIRect srcRect = rect; 490 SkIRect srcRect = rect;
491 491
492 SkASSERT(radius.width() > 0 || radius.height() > 0); 492 SkASSERT(radius.width() > 0 || radius.height() > 0);
493 493
494 if (radius.fWidth > 0) { 494 if (radius.fWidth > 0) {
495 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c); 495 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c);
496 if (!scratch) { 496 if (!scratch) {
497 return nullptr; 497 return nullptr;
498 } 498 }
499 SkAutoTUnref<GrDrawContext> dstDrawContext( 499 SkAutoTUnref<GrDrawContext> dstDrawContext(
500 context->drawContext(scratch->as RenderTarget())); 500 context->drawContext(scratch->as RenderTarget()));
501 if (!dstDrawContext) { 501 if (!dstDrawContext) {
502 return nullptr; 502 return nullptr;
503 } 503 }
504 504
505 apply_morphology_pass(dstDrawContext, clip, srcTexture, 505 apply_morphology_pass(dstDrawContext, clip, srcTexture.get(),
506 srcRect, dstRect, radius.fWidth, morphType, 506 srcRect, dstRect, radius.fWidth, morphType,
507 Gr1DKernelEffect::kX_Direction); 507 Gr1DKernelEffect::kX_Direction);
508 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, 508 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
509 dstRect.width(), radius.fHeight); 509 dstRect.width(), radius.fHeight);
510 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ? 510 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ?
511 SK_ColorWHITE : 511 SK_ColorWHITE :
512 SK_ColorTRANSPARENT; 512 SK_ColorTRANSPARENT;
513 dstDrawContext->clear(&clearRect, clearColor, false); 513 dstDrawContext->clear(&clearRect, clearColor, false);
514 514
515 srcTexture.reset(scratch); 515 srcTexture.reset(scratch);
516 srcRect = dstRect; 516 srcRect = dstRect;
517 } 517 }
518 if (radius.fHeight > 0) { 518 if (radius.fHeight > 0) {
519 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c); 519 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c);
520 if (!scratch) { 520 if (!scratch) {
521 return nullptr; 521 return nullptr;
522 } 522 }
523 SkAutoTUnref<GrDrawContext> dstDrawContext( 523 SkAutoTUnref<GrDrawContext> dstDrawContext(
524 context->drawContext(scratch->as RenderTarget())); 524 context->drawContext(scratch->as RenderTarget()));
525 if (!dstDrawContext) { 525 if (!dstDrawContext) {
526 return nullptr; 526 return nullptr;
527 } 527 }
528 528
529 apply_morphology_pass(dstDrawContext, clip, srcTexture, 529 apply_morphology_pass(dstDrawContext, clip, srcTexture.get(),
530 srcRect, dstRect, radius.fHeight, morphType, 530 srcRect, dstRect, radius.fHeight, morphType,
531 Gr1DKernelEffect::kY_Direction); 531 Gr1DKernelEffect::kY_Direction);
532 532
533 srcTexture.reset(scratch); 533 srcTexture.reset(scratch);
534 } 534 }
535 535
536 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height ()), 536 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height ()),
537 kNeedNewImageUniqueID_SpecialImage, 537 kNeedNewImageUniqueID_SpecialImage,
538 srcTexture, &input->props()); 538 std::move(srcTexture), &input->props());
539 } 539 }
540 #endif 540 #endif
541 541
542 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce, 542 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce,
543 const Context& ctx, 543 const Context& ctx,
544 SkIPoint* offset) c onst { 544 SkIPoint* offset) c onst {
545 SkIPoint inputOffset = SkIPoint::Make(0, 0); 545 SkIPoint inputOffset = SkIPoint::Make(0, 0);
546 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ; 546 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
547 if (!input) { 547 if (!input) {
548 return nullptr; 548 return nullptr;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), 639 inputBM.getAddr32(srcBounds.left(), srcBounds.top()),
640 inputBM.rowBytesAsPixels(), 640 inputBM.rowBytesAsPixels(),
641 &dst, height, srcBounds); 641 &dst, height, srcBounds);
642 } 642 }
643 offset->fX = bounds.left(); 643 offset->fX = bounds.left();
644 offset->fY = bounds.top(); 644 offset->fY = bounds.top();
645 645
646 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()), 646 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()),
647 dst, &source->props()); 647 dst, &source->props());
648 } 648 }
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