Skip to content

Commit

Permalink
Revert "Fix dithering on drawImage[Rect] calls"
Browse files Browse the repository at this point in the history
This reverts commit 1024148.

Reason for revert: Speculative revert for b/220676062

Original change's description:
> Fix dithering on drawImage[Rect] calls
>
> Bug: skia:12516
> Change-Id: Ibb68558e0f474143df3c6a5fb0fb3d4881529226
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/508677
> Reviewed-by: Brian Osman <[email protected]>
> Commit-Queue: Michael Ludwig <[email protected]>

Bug: skia:12516
Change-Id: If496c6be355bbb026ffe478512f8a6334116bb66
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/511806
Commit-Queue: Brian Osman <[email protected]>
Bot-Commit: Rubber Stamper <[email protected]>
  • Loading branch information
brianosman authored and SkCQ committed Feb 22, 2022
1 parent fd1f1b3 commit 1e420a3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 48 deletions.
37 changes: 0 additions & 37 deletions gm/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "include/core/SkSurface.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrDirectContext.h"
#include "include/private/SkMalloc.h"
#include "src/core/SkAutoPixmapStorage.h"
Expand Down Expand Up @@ -460,39 +459,3 @@ DEF_SIMPLE_GM_CAN_FAIL(image_subset, canvas, errorMsg, 440, 220) {
canvas->drawImage(sub, 220+110, 10);
return skiagm::DrawResult::kOk;
}

///////////////////////////////////////////////////////////////////////////////////////////////////

DEF_SIMPLE_GM(image_dither, canvas, 800, 800) {
// Make a low-res image of a gradient that shows banding if there's no dithering. When up-scaled
// bilerp filtering will emphasize the banding unless the image is drawn with dithering.
auto gradImage = []() -> sk_sp<SkImage> {
SkImageInfo gradImageInfo = SkImageInfo::Make({8, 16}, {SkColorType::kRGBA_8888_SkColorType,
SkAlphaType::kPremul_SkAlphaType,
nullptr});
auto surface = SkSurface::MakeRaster(gradImageInfo);

SkPoint pts[2] = {{0.f, 0.f},
{(float) 2 * gradImageInfo.width(), (float) gradImageInfo.height()}};
const SkColor colors[] = { 0xFF555555, 0xFF444444 };
SkPaint p;
p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
surface->getCanvas()->drawPaint(p);
return surface->makeImageSnapshot();
}();

SkRect imageBounds = SkRect::MakeIWH(gradImage->width(), gradImage->height());

canvas->scale(50, 50);

// 1st image definitely goes through general shader paths so should have dithering
SkPaint p;
p.setShader(gradImage->makeShader(SkSamplingOptions{SkFilterMode::kLinear}));
p.setDither(true);
canvas->drawRect(imageBounds, p);

// 2nd image goes through draw-image fast paths, but dithering should be detected
p.setShader(nullptr);
canvas->translate(imageBounds.width(), 0.f);
canvas->drawImage(gradImage, 0.f, 0.f, SkSamplingOptions{SkFilterMode::kLinear}, &p);
}
4 changes: 1 addition & 3 deletions src/core/SkMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,9 +1639,7 @@ bool SkTreatAsSprite(const SkMatrix& mat, const SkISize& size, const SkSamplingO
if (!SkSamplingPriv::NoChangeWithIdentityMatrix(sampling)) {
return false;
}
if (paint.isDither()) {
return false;
}

// Our path aa is 2-bits, and our rect aa is 8, so we could use 8,
// but in practice 4 seems enough (still looks smooth) and allows
// more slightly fractional cases to fall into the fast (sprite) case.
Expand Down
5 changes: 2 additions & 3 deletions src/core/SkPaintPriv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool SkPaintPriv::Overwrites(const SkPaint* paint, ShaderOverrideOpacity overrid
return SkXfermode::IsOpaque(bm.value(), opacityType);
}

bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT, bool shaderOverride) {
bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
// The paint dither flag can veto.
if (!p.isDither()) {
return false;
Expand All @@ -63,8 +63,7 @@ bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT, bool shaderO

// Otherwise, dither is only needed for non-const paints.
return p.getImageFilter() || p.getMaskFilter() ||
(p.getShader() && !as_SB(p.getShader())->isConstant()) ||
shaderOverride;
(p.getShader() && !as_SB(p.getShader())->isConstant());
}

// return true if the paint is just a single color (i.e. not a shader). If its
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkPaintPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SkPaintPriv {
*/
static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity);

static bool ShouldDither(const SkPaint&, SkColorType, bool shaderOverride=false);
static bool ShouldDither(const SkPaint&, SkColorType);

/*
* The luminance color is used to determine which Gamma Canonical color to map to. This is
Expand Down
3 changes: 1 addition & 2 deletions src/gpu/SkGr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ static inline bool skpaint_to_grpaint_impl(

#ifndef SK_IGNORE_GPU_DITHER
GrColorType ct = dstColorInfo.colorType();
const bool shaderOverride = SkToBool(paintFP);
if (SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct), shaderOverride)) {
if (SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct)) && paintFP != nullptr) {
float ditherRange = dither_range_for_config(ct);
paintFP = make_dither_effect(
context, std::move(paintFP), ditherRange, context->priv().caps());
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/v1/Device_drawTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ ImageDrawMode optimize_sample_area(const SkISize& image, const SkRect* origSrcRe
*/
bool can_use_draw_texture(const SkPaint& paint, bool useCubicResampler, SkMipmapMode mm) {
return (!paint.getColorFilter() && !paint.getShader() && !paint.getMaskFilter() &&
!paint.getImageFilter() && !paint.getBlender() && !paint.isDither() &&
!useCubicResampler && mm == SkMipmapMode::kNone);
!paint.getImageFilter() && !paint.getBlender() && !useCubicResampler &&
mm == SkMipmapMode::kNone);
}

SkPMColor4f texture_color(SkColor4f paintColor, float entryAlpha, GrColorType srcColorType,
Expand Down

0 comments on commit 1e420a3

Please sign in to comment.