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

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

Issue 2359443003: Fix some GPU image filter code to preserve precision and color space (Closed)
Patch Set: Created 4 years, 3 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
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"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkOpts.h" 12 #include "SkOpts.h"
13 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
14 #include "SkRect.h" 14 #include "SkRect.h"
15 #include "SkSpecialImage.h" 15 #include "SkSpecialImage.h"
16 #include "SkWriteBuffer.h" 16 #include "SkWriteBuffer.h"
17 17
18 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
19 #include "GrContext.h" 19 #include "GrContext.h"
20 #include "GrDrawContext.h" 20 #include "GrDrawContext.h"
21 #include "GrFixedClip.h" 21 #include "GrFixedClip.h"
22 #include "GrInvariantOutput.h" 22 #include "GrInvariantOutput.h"
23 #include "GrTexture.h" 23 #include "GrTexture.h"
24 #include "SkGr.h" 24 #include "SkGr.h"
25 #include "SkGrPriv.h"
25 #include "effects/Gr1DKernelEffect.h" 26 #include "effects/Gr1DKernelEffect.h"
26 #include "glsl/GrGLSLFragmentProcessor.h" 27 #include "glsl/GrGLSLFragmentProcessor.h"
27 #include "glsl/GrGLSLFragmentShaderBuilder.h" 28 #include "glsl/GrGLSLFragmentShaderBuilder.h"
28 #include "glsl/GrGLSLProgramDataManager.h" 29 #include "glsl/GrGLSLProgramDataManager.h"
29 #include "glsl/GrGLSLUniformHandler.h" 30 #include "glsl/GrGLSLUniformHandler.h"
30 #endif 31 #endif
31 32
32 sk_sp<SkImageFilter> SkDilateImageFilter::Make(int radiusX, int radiusY, 33 sk_sp<SkImageFilter> SkDilateImageFilter::Make(int radiusX, int radiusY,
33 sk_sp<SkImageFilter> input, 34 sk_sp<SkImageFilter> input,
34 const CropRect* cropRect) { 35 const CropRect* cropRect) {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 470 }
470 471
471 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, 472 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
472 SkSpecialImage* input, 473 SkSpecialImage* input,
473 const SkIRect& rect, 474 const SkIRect& rect,
474 GrMorphologyEffect::MorphologyType morphType, 475 GrMorphologyEffect::MorphologyType morphType,
475 SkISize radius) { 476 SkISize radius) {
476 sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); 477 sk_sp<GrTexture> srcTexture(input->asTextureRef(context));
477 SkASSERT(srcTexture); 478 SkASSERT(srcTexture);
478 sk_sp<SkColorSpace> colorSpace = sk_ref_sp(input->getColorSpace()); 479 sk_sp<SkColorSpace> colorSpace = sk_ref_sp(input->getColorSpace());
480 GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get());
479 481
480 // setup new clip 482 // setup new clip
481 const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->heig ht())); 483 const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->heig ht()));
482 484
483 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); 485 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
484 SkIRect srcRect = rect; 486 SkIRect srcRect = rect;
485 487
486 SkASSERT(radius.width() > 0 || radius.height() > 0); 488 SkASSERT(radius.width() > 0 || radius.height() > 0);
487 489
488 if (radius.fWidth > 0) { 490 if (radius.fWidth > 0) {
489 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFi t::kApprox, 491 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFi t::kApprox,
490 rect.width( ), rect.height(), 492 rect.width( ), rect.height(),
491 kSkia8888_G rPixelConfig, 493 config, col orSpace));
492 colorSpace) );
493 if (!dstDrawContext) { 494 if (!dstDrawContext) {
494 return nullptr; 495 return nullptr;
495 } 496 }
496 497
497 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), 498 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
498 srcRect, dstRect, radius.fWidth, morphType, 499 srcRect, dstRect, radius.fWidth, morphType,
499 Gr1DKernelEffect::kX_Direction); 500 Gr1DKernelEffect::kX_Direction);
500 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, 501 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
501 dstRect.width(), radius.fHeight); 502 dstRect.width(), radius.fHeight);
502 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype 503 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype
503 ? SK_ColorWHITE 504 ? SK_ColorWHITE
504 : SK_ColorTRANSPARENT; 505 : SK_ColorTRANSPARENT;
505 dstDrawContext->clear(&clearRect, clearColor, false); 506 dstDrawContext->clear(&clearRect, clearColor, false);
506 507
507 srcTexture = dstDrawContext->asTexture(); 508 srcTexture = dstDrawContext->asTexture();
508 srcRect = dstRect; 509 srcRect = dstRect;
509 } 510 }
510 if (radius.fHeight > 0) { 511 if (radius.fHeight > 0) {
511 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFi t::kApprox, 512 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFi t::kApprox,
512 rect.width( ), rect.height(), 513 rect.width( ), rect.height(),
513 kSkia8888_G rPixelConfig, 514 config, col orSpace));
514 colorSpace) );
515 if (!dstDrawContext) { 515 if (!dstDrawContext) {
516 return nullptr; 516 return nullptr;
517 } 517 }
518 518
519 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), 519 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
520 srcRect, dstRect, radius.fHeight, morphType, 520 srcRect, dstRect, radius.fHeight, morphType,
521 Gr1DKernelEffect::kY_Direction); 521 Gr1DKernelEffect::kY_Direction);
522 522
523 srcTexture = dstDrawContext->asTexture(); 523 srcTexture = dstDrawContext->asTexture();
524 } 524 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), 630 inputBM.getAddr32(srcBounds.left(), srcBounds.top()),
631 inputBM.rowBytesAsPixels(), 631 inputBM.rowBytesAsPixels(),
632 &dst, height, srcBounds); 632 &dst, height, srcBounds);
633 } 633 }
634 offset->fX = bounds.left(); 634 offset->fX = bounds.left();
635 offset->fY = bounds.top(); 635 offset->fY = bounds.top();
636 636
637 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()), 637 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds .height()),
638 dst, &source->props()); 638 dst, &source->props());
639 } 639 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698