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

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

Issue 1914883002: Refactor drawContext/RenderTarget creation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix variable name 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 sk_sp<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 const 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 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
485 GrSurfaceDesc desc;
486 desc.fFlags = kRenderTarget_GrSurfaceFlag;
487 desc.fWidth = rect.width();
488 desc.fHeight = rect.height();
489 desc.fConfig = kSkia8888_GrPixelConfig;
490 SkIRect srcRect = rect; 485 SkIRect srcRect = rect;
491 486
492 SkASSERT(radius.width() > 0 || radius.height() > 0); 487 SkASSERT(radius.width() > 0 || radius.height() > 0);
493 488
494 if (radius.fWidth > 0) { 489 if (radius.fWidth > 0) {
495 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c); 490 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::k Loose_BackingFit,
496 if (!scratch) { 491 rect.width() , rect.height(),
497 return nullptr; 492 kSkia8888_Gr PixelConfig));
498 }
499 sk_sp<GrDrawContext> dstDrawContext(
500 context->drawContext(sk_ref_sp(scratch->as RenderTarget())));
501 if (!dstDrawContext) { 493 if (!dstDrawContext) {
502 return nullptr; 494 return nullptr;
503 } 495 }
504 496
505 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), 497 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
506 srcRect, dstRect, radius.fWidth, morphType, 498 srcRect, dstRect, radius.fWidth, morphType,
507 Gr1DKernelEffect::kX_Direction); 499 Gr1DKernelEffect::kX_Direction);
508 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, 500 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
509 dstRect.width(), radius.fHeight); 501 dstRect.width(), radius.fHeight);
510 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ? 502 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype
511 SK_ColorWHITE : 503 ? SK_ColorWHITE
512 SK_ColorTRANSPARENT; 504 : SK_ColorTRANSPARENT;
513 dstDrawContext->clear(&clearRect, clearColor, false); 505 dstDrawContext->clear(&clearRect, clearColor, false);
514 506
515 srcTexture.reset(scratch); 507 srcTexture = dstDrawContext->asTexture();
516 srcRect = dstRect; 508 srcRect = dstRect;
517 } 509 }
518 if (radius.fHeight > 0) { 510 if (radius.fHeight > 0) {
519 GrTexture* scratch = context->textureProvider()->createApproxTexture(des c); 511 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::k Loose_BackingFit,
520 if (!scratch) { 512 rect.width() , rect.height(),
521 return nullptr; 513 kSkia8888_Gr PixelConfig));
522 }
523 sk_sp<GrDrawContext> dstDrawContext(
524 context->drawContext(sk_ref_sp(scratch->as RenderTarget())));
525 if (!dstDrawContext) { 514 if (!dstDrawContext) {
526 return nullptr; 515 return nullptr;
527 } 516 }
528 517
529 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), 518 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
530 srcRect, dstRect, radius.fHeight, morphType, 519 srcRect, dstRect, radius.fHeight, morphType,
531 Gr1DKernelEffect::kY_Direction); 520 Gr1DKernelEffect::kY_Direction);
532 521
533 srcTexture.reset(scratch); 522 srcTexture = dstDrawContext->asTexture();
534 } 523 }
535 524
536 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height ()), 525 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height ()),
537 kNeedNewImageUniqueID_SpecialImage, 526 kNeedNewImageUniqueID_SpecialImage,
538 std::move(srcTexture), &input->props()); 527 std::move(srcTexture), &input->props());
539 } 528 }
540 #endif 529 #endif
541 530
542 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce, 531 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou rce,
543 const Context& ctx, 532 const Context& ctx,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), 628 inputBM.getAddr32(srcBounds.left(), srcBounds.top()),
640 inputBM.rowBytesAsPixels(), 629 inputBM.rowBytesAsPixels(),
641 &dst, height, srcBounds); 630 &dst, height, srcBounds);
642 } 631 }
643 offset->fX = bounds.left(); 632 offset->fX = bounds.left();
644 offset->fY = bounds.top(); 633 offset->fY = bounds.top();
645 634
646 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()), 635 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()),
647 dst, &source->props()); 636 dst, &source->props());
648 } 637 }
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