reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 8 | #include "src/gpu/SkGr.h" |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColorFilter.h" |
| 12 | #include "include/core/SkData.h" |
| 13 | #include "include/core/SkPixelRef.h" |
Brian Osman | ee426f2 | 2020-01-02 11:55:24 -0500 | [diff] [blame] | 14 | #include "include/effects/SkRuntimeEffect.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 15 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/gpu/GrTypes.h" |
Brian Salomon | 71fe945 | 2020-03-02 16:59:40 -0500 | [diff] [blame] | 17 | #include "include/private/SkIDChangeListener.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/private/SkImageInfoPriv.h" |
Mike Klein | 8aa0edf | 2020-10-16 11:04:18 -0500 | [diff] [blame] | 19 | #include "include/private/SkTPin.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "include/private/SkTemplates.h" |
| 21 | #include "src/core/SkAutoMalloc.h" |
| 22 | #include "src/core/SkBlendModePriv.h" |
Mike Reed | b11e627 | 2020-06-24 16:56:33 -0400 | [diff] [blame] | 23 | #include "src/core/SkColorFilterBase.h" |
Mike Reed | bd84330 | 2019-09-27 21:05:24 -0400 | [diff] [blame] | 24 | #include "src/core/SkColorSpacePriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/core/SkImagePriv.h" |
| 26 | #include "src/core/SkMaskFilterBase.h" |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 27 | #include "src/core/SkMatrixPriv.h" |
Ben Wagner | 21bca28 | 2019-05-15 10:15:52 -0400 | [diff] [blame] | 28 | #include "src/core/SkMessageBus.h" |
Mike Reed | 13711eb | 2020-07-14 17:16:32 -0400 | [diff] [blame] | 29 | #include "src/core/SkMipmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/core/SkPaintPriv.h" |
| 31 | #include "src/core/SkResourceCache.h" |
| 32 | #include "src/core/SkTraceEvent.h" |
| 33 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 34 | #include "src/gpu/GrCaps.h" |
| 35 | #include "src/gpu/GrColorSpaceXform.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 36 | #include "src/gpu/GrGpuResourcePriv.h" |
| 37 | #include "src/gpu/GrPaint.h" |
| 38 | #include "src/gpu/GrProxyProvider.h" |
| 39 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 40 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 41 | #include "src/gpu/GrXferProcessor.h" |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 42 | #include "src/gpu/SkGr.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 43 | #include "src/gpu/effects/GrBicubicEffect.h" |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 44 | #include "src/gpu/effects/GrBlendFragmentProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 45 | #include "src/gpu/effects/GrPorterDuffXferProcessor.h" |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 46 | #include "src/gpu/effects/generated/GrClampFragmentProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 47 | #include "src/gpu/effects/generated/GrConstColorProcessor.h" |
John Stiles | 53ee0fc | 2020-07-09 15:29:33 -0400 | [diff] [blame] | 48 | #include "src/gpu/effects/generated/GrDitherEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 49 | #include "src/image/SkImage_Base.h" |
| 50 | #include "src/shaders/SkShaderBase.h" |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 51 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 52 | void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds) { |
| 53 | SkASSERT(key); |
| 54 | SkASSERT(imageID); |
| 55 | SkASSERT(!imageBounds.isEmpty()); |
| 56 | static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomain(); |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 57 | GrUniqueKey::Builder builder(key, kImageIDDomain, 5, "Image"); |
bsalomon | 466c2c4 | 2015-10-16 12:01:18 -0700 | [diff] [blame] | 58 | builder[0] = imageID; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 59 | builder[1] = imageBounds.fLeft; |
| 60 | builder[2] = imageBounds.fTop; |
| 61 | builder[3] = imageBounds.fRight; |
| 62 | builder[4] = imageBounds.fBottom; |
bsalomon | 466c2c4 | 2015-10-16 12:01:18 -0700 | [diff] [blame] | 63 | } |
| 64 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 65 | //////////////////////////////////////////////////////////////////////////////// |
| 66 | |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 67 | sk_sp<SkIDChangeListener> GrMakeUniqueKeyInvalidationListener(GrUniqueKey* key, |
| 68 | uint32_t contextID) { |
| 69 | class Listener : public SkIDChangeListener { |
| 70 | public: |
| 71 | Listener(const GrUniqueKey& key, uint32_t contextUniqueID) : fMsg(key, contextUniqueID) {} |
| 72 | |
| 73 | void changed() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); } |
| 74 | |
| 75 | private: |
| 76 | GrUniqueKeyInvalidatedMessage fMsg; |
| 77 | }; |
| 78 | |
| 79 | auto listener = sk_make_sp<Listener>(*key, contextID); |
| 80 | |
| 81 | // We stick a SkData on the key that calls invalidateListener in its destructor. |
| 82 | auto invalidateListener = [](const void* ptr, void* /*context*/) { |
| 83 | auto listener = reinterpret_cast<const sk_sp<Listener>*>(ptr); |
| 84 | (*listener)->markShouldDeregister(); |
| 85 | delete listener; |
| 86 | }; |
| 87 | auto data = SkData::MakeWithProc(new sk_sp<Listener>(listener), |
| 88 | sizeof(sk_sp<Listener>), |
| 89 | invalidateListener, |
| 90 | nullptr); |
| 91 | SkASSERT(!key->getCustomData()); |
| 92 | key->setCustomData(std::move(data)); |
| 93 | return std::move(listener); |
| 94 | } |
| 95 | |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 96 | sk_sp<GrSurfaceProxy> GrCopyBaseMipMapToTextureProxy(GrRecordingContext* ctx, |
| 97 | GrSurfaceProxy* baseProxy, |
| 98 | GrSurfaceOrigin origin, |
| 99 | SkBudgeted budgeted) { |
Greg Daniel | 55afd6d | 2017-09-29 09:32:44 -0400 | [diff] [blame] | 100 | SkASSERT(baseProxy); |
| 101 | |
Greg Daniel | 6980c4e | 2019-07-30 16:18:18 -0400 | [diff] [blame] | 102 | if (!ctx->priv().caps()->isFormatCopyable(baseProxy->backendFormat())) { |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 103 | return {}; |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 104 | } |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 105 | auto copy = GrSurfaceProxy::Copy(ctx, baseProxy, origin, GrMipmapped::kYes, |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 106 | SkBackingFit::kExact, budgeted); |
| 107 | if (!copy) { |
| 108 | return {}; |
| 109 | } |
| 110 | SkASSERT(copy->asTextureProxy()); |
| 111 | return copy; |
| 112 | } |
| 113 | |
| 114 | GrSurfaceProxyView GrCopyBaseMipMapToView(GrRecordingContext* context, |
| 115 | GrSurfaceProxyView src, |
| 116 | SkBudgeted budgeted) { |
| 117 | auto origin = src.origin(); |
| 118 | auto swizzle = src.swizzle(); |
| 119 | auto* proxy = src.proxy(); |
| 120 | return {GrCopyBaseMipMapToTextureProxy(context, proxy, origin, budgeted), origin, swizzle}; |
Greg Daniel | 55afd6d | 2017-09-29 09:32:44 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 123 | GrSurfaceProxyView GrRefCachedBitmapView(GrRecordingContext* ctx, const SkBitmap& bitmap, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 124 | GrMipmapped mipMapped) { |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 125 | GrBitmapTextureMaker maker(ctx, bitmap, GrImageTexGenPolicy::kDraw); |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 126 | return maker.view(mipMapped); |
Robert Phillips | bbd7a3b | 2017-03-21 08:48:40 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 129 | GrSurfaceProxyView GrMakeCachedBitmapProxyView(GrRecordingContext* context, |
| 130 | const SkBitmap& bitmap) { |
Greg Daniel | 7e1912a | 2018-02-08 09:15:33 -0500 | [diff] [blame] | 131 | if (!bitmap.peekPixels(nullptr)) { |
Greg Daniel | c52db71 | 2020-01-28 17:03:46 -0500 | [diff] [blame] | 132 | return {}; |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 133 | } |
| 134 | |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 135 | GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kDraw); |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 136 | return maker.view(GrMipmapped::kNo); |
Robert Phillips | 7a92639 | 2018-02-01 15:49:54 -0500 | [diff] [blame] | 137 | } |
| 138 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 139 | /////////////////////////////////////////////////////////////////////////////// |
| 140 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 141 | SkPMColor4f SkColorToPMColor4f(SkColor c, const GrColorInfo& colorInfo) { |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 142 | SkColor4f color = SkColor4f::FromColor(c); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 143 | if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) { |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 144 | color = xform->apply(color); |
| 145 | } |
| 146 | return color.premul(); |
| 147 | } |
| 148 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 149 | SkColor4f SkColor4fPrepForDst(SkColor4f color, const GrColorInfo& colorInfo) { |
| 150 | if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) { |
Brian Osman | 5c8a6b3 | 2018-11-19 11:56:57 -0500 | [diff] [blame] | 151 | color = xform->apply(color); |
| 152 | } |
Brian Osman | 5c8a6b3 | 2018-11-19 11:56:57 -0500 | [diff] [blame] | 153 | return color; |
| 154 | } |
| 155 | |
Brian Osman | c68d4aa | 2016-09-30 11:41:59 -0400 | [diff] [blame] | 156 | /////////////////////////////////////////////////////////////////////////////// |
| 157 | |
Mike Reed | 185ba21 | 2017-04-28 12:31:05 -0400 | [diff] [blame] | 158 | static inline bool blend_requires_shader(const SkBlendMode mode) { |
| 159 | return SkBlendMode::kDst != mode; |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 162 | #ifndef SK_IGNORE_GPU_DITHER |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 163 | static inline float dither_range_for_config(GrColorType dstColorType) { |
| 164 | // We use 1 / (2^bitdepth-1) as the range since each channel can hold 2^bitdepth values |
Brian Salomon | bd3d8d3 | 2019-07-02 09:16:28 -0400 | [diff] [blame] | 165 | switch (dstColorType) { |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 166 | // 4 bit |
| 167 | case GrColorType::kABGR_4444: |
Greg Daniel | 746460e | 2020-06-30 13:13:53 -0400 | [diff] [blame] | 168 | case GrColorType::kARGB_4444: |
| 169 | case GrColorType::kBGRA_4444: |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 170 | return 1 / 15.f; |
| 171 | // 6 bit |
| 172 | case GrColorType::kBGR_565: |
| 173 | return 1 / 63.f; |
| 174 | // 8 bit |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 175 | case GrColorType::kUnknown: |
Brian Salomon | bd3d8d3 | 2019-07-02 09:16:28 -0400 | [diff] [blame] | 176 | case GrColorType::kAlpha_8: |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 177 | case GrColorType::kAlpha_8xxx: |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 178 | case GrColorType::kGray_8: |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 179 | case GrColorType::kGray_8xxx: |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 180 | case GrColorType::kR_8: |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 181 | case GrColorType::kRG_88: |
| 182 | case GrColorType::kRGB_888: |
| 183 | case GrColorType::kRGB_888x: |
| 184 | case GrColorType::kRGBA_8888: |
| 185 | case GrColorType::kRGBA_8888_SRGB: |
| 186 | case GrColorType::kBGRA_8888: |
| 187 | return 1 / 255.f; |
| 188 | // 10 bit |
| 189 | case GrColorType::kRGBA_1010102: |
| 190 | case GrColorType::kBGRA_1010102: |
| 191 | return 1 / 1023.f; |
| 192 | // 16 bit |
| 193 | case GrColorType::kAlpha_16: |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 194 | case GrColorType::kR_16: |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 195 | case GrColorType::kRG_1616: |
| 196 | case GrColorType::kRGBA_16161616: |
| 197 | return 1 / 32767.f; |
| 198 | // Half |
| 199 | case GrColorType::kAlpha_F16: |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 200 | case GrColorType::kGray_F16: |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 201 | case GrColorType::kR_F16: |
| 202 | case GrColorType::kRG_F16: |
| 203 | case GrColorType::kRGBA_F16: |
| 204 | case GrColorType::kRGBA_F16_Clamped: |
| 205 | // Float |
| 206 | case GrColorType::kAlpha_F32xxx: |
| 207 | case GrColorType::kRGBA_F32: |
| 208 | return 0.f; // no dithering |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 209 | } |
Brian Salomon | bd3d8d3 | 2019-07-02 09:16:28 -0400 | [diff] [blame] | 210 | SkUNREACHABLE; |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 211 | } |
| 212 | #endif |
| 213 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 214 | static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 215 | const GrColorInfo& dstColorInfo, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 216 | const SkPaint& skPaint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 217 | const SkMatrixProvider& matrixProvider, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 218 | std::unique_ptr<GrFragmentProcessor>* shaderProcessor, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 219 | SkBlendMode* primColorMode, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 220 | GrPaint* grPaint) { |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 221 | // Convert SkPaint color to 4f format in the destination color space |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 222 | SkColor4f origColor = SkColor4fPrepForDst(skPaint.getColor4f(), dstColorInfo); |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 223 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 224 | GrFPArgs fpArgs(context, matrixProvider, skPaint.getFilterQuality(), &dstColorInfo); |
Mike Reed | bfadcf0 | 2018-01-20 22:24:21 +0000 | [diff] [blame] | 225 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 226 | // Setup the initial color considering the shader, the SkPaint color, and the presence or not |
| 227 | // of per-vertex colors. |
John Stiles | 7f9aa5a | 2020-06-23 11:28:50 -0400 | [diff] [blame] | 228 | std::unique_ptr<GrFragmentProcessor> paintFP; |
Mike Reed | 185ba21 | 2017-04-28 12:31:05 -0400 | [diff] [blame] | 229 | if (!primColorMode || blend_requires_shader(*primColorMode)) { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 230 | fpArgs.fInputColorIsOpaque = origColor.isOpaque(); |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 231 | if (shaderProcessor) { |
John Stiles | 7f9aa5a | 2020-06-23 11:28:50 -0400 | [diff] [blame] | 232 | paintFP = std::move(*shaderProcessor); |
| 233 | } else { |
| 234 | if (const SkShaderBase* shader = as_SB(skPaint.getShader())) { |
| 235 | paintFP = shader->asFragmentProcessor(fpArgs); |
| 236 | if (paintFP == nullptr) { |
| 237 | return false; |
| 238 | } |
Yuqian Li | aad2ec6 | 2018-02-26 10:34:52 -0500 | [diff] [blame] | 239 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | // Set this in below cases if the output of the shader/paint-color/paint-alpha/primXfermode is |
| 244 | // a known constant value. In that case we can simply apply a color filter during this |
| 245 | // conversion without converting the color filter to a GrFragmentProcessor. |
| 246 | bool applyColorFilterToPaintColor = false; |
John Stiles | 7f9aa5a | 2020-06-23 11:28:50 -0400 | [diff] [blame] | 247 | if (paintFP) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 248 | if (primColorMode) { |
| 249 | // There is a blend between the primitive color and the shader color. The shader sees |
| 250 | // the opaque paint color. The shader's output is blended using the provided mode by |
| 251 | // the primitive color. The blended color is then modulated by the paint's alpha. |
| 252 | |
| 253 | // The geometry processor will insert the primitive color to start the color chain, so |
| 254 | // the GrPaint color will be ignored. |
| 255 | |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 256 | SkPMColor4f shaderInput = origColor.makeOpaque().premul(); |
John Stiles | 7f9aa5a | 2020-06-23 11:28:50 -0400 | [diff] [blame] | 257 | paintFP = GrFragmentProcessor::OverrideInput(std::move(paintFP), shaderInput); |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 258 | paintFP = GrBlendFragmentProcessor::Make(std::move(paintFP), /*dst=*/nullptr, |
| 259 | *primColorMode); |
Mike Reed | 185ba21 | 2017-04-28 12:31:05 -0400 | [diff] [blame] | 260 | |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 261 | // We can ignore origColor here - alpha is unchanged by gamma |
Brian Osman | 00b2939 | 2018-11-05 15:42:43 -0500 | [diff] [blame] | 262 | float paintAlpha = skPaint.getColor4f().fA; |
| 263 | if (1.0f != paintAlpha) { |
Brian Osman | 618d304 | 2016-10-25 10:51:28 -0400 | [diff] [blame] | 264 | // No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all |
| 265 | // color channels. It's value should be treated as the same in ANY color space. |
John Stiles | 8589430 | 2020-07-13 11:39:52 -0400 | [diff] [blame] | 266 | paintFP = GrFragmentProcessor::ModulateRGBA( |
John Stiles | 7c19677 | 2020-07-13 10:00:16 -0400 | [diff] [blame] | 267 | std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha}); |
John Stiles | e3a39f7 | 2020-06-15 13:58:48 -0400 | [diff] [blame] | 268 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 269 | } else { |
Brian Osman | e7809c7 | 2020-07-30 16:49:54 -0400 | [diff] [blame] | 270 | grPaint->setColor4f(origColor.premul()); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 271 | } |
| 272 | } else { |
| 273 | if (primColorMode) { |
| 274 | // There is a blend between the primitive color and the paint color. The blend considers |
| 275 | // the opaque paint color. The paint's alpha is applied to the post-blended color. |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 276 | SkPMColor4f opaqueColor = origColor.makeOpaque().premul(); |
John Stiles | 7c19677 | 2020-07-13 10:00:16 -0400 | [diff] [blame] | 277 | paintFP = GrConstColorProcessor::Make(opaqueColor); |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 278 | paintFP = GrBlendFragmentProcessor::Make(std::move(paintFP), /*dst=*/nullptr, |
| 279 | *primColorMode); |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 280 | grPaint->setColor4f(opaqueColor); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 281 | |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 282 | // We can ignore origColor here - alpha is unchanged by gamma |
Brian Osman | 00b2939 | 2018-11-05 15:42:43 -0500 | [diff] [blame] | 283 | float paintAlpha = skPaint.getColor4f().fA; |
| 284 | if (1.0f != paintAlpha) { |
Brian Osman | 618d304 | 2016-10-25 10:51:28 -0400 | [diff] [blame] | 285 | // No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all |
| 286 | // color channels. It's value should be treated as the same in ANY color space. |
John Stiles | 8589430 | 2020-07-13 11:39:52 -0400 | [diff] [blame] | 287 | paintFP = GrFragmentProcessor::ModulateRGBA( |
John Stiles | 7c19677 | 2020-07-13 10:00:16 -0400 | [diff] [blame] | 288 | std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha}); |
John Stiles | e3a39f7 | 2020-06-15 13:58:48 -0400 | [diff] [blame] | 289 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 290 | } else { |
| 291 | // No shader, no primitive color. |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 292 | grPaint->setColor4f(origColor.premul()); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 293 | applyColorFilterToPaintColor = true; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 298 | if (colorFilter) { |
| 299 | if (applyColorFilterToPaintColor) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 300 | SkColorSpace* dstCS = dstColorInfo.colorSpace(); |
Mike Reed | bd84330 | 2019-09-27 21:05:24 -0400 | [diff] [blame] | 301 | grPaint->setColor4f(colorFilter->filterColor4f(origColor, dstCS, dstCS).premul()); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 302 | } else { |
John Stiles | c36b8aa | 2020-06-25 12:47:52 -0400 | [diff] [blame] | 303 | auto [success, fp] = as_CFB(colorFilter)->asFragmentProcessor(std::move(paintFP), |
| 304 | context, dstColorInfo); |
| 305 | if (!success) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 306 | return false; |
| 307 | } |
John Stiles | c36b8aa | 2020-06-25 12:47:52 -0400 | [diff] [blame] | 308 | paintFP = std::move(fp); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 312 | SkMaskFilterBase* maskFilter = as_MFB(skPaint.getMaskFilter()); |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 313 | if (maskFilter) { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 314 | // We may have set this before passing to the SkShader. |
| 315 | fpArgs.fInputColorIsOpaque = false; |
Mike Reed | bfadcf0 | 2018-01-20 22:24:21 +0000 | [diff] [blame] | 316 | if (auto mfFP = maskFilter->asFragmentProcessor(fpArgs)) { |
John Stiles | 41d91b6 | 2020-07-21 14:39:40 -0400 | [diff] [blame] | 317 | grPaint->setCoverageFragmentProcessor(std::move(mfFP)); |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
robertphillips | 4f03794 | 2016-02-09 05:09:27 -0800 | [diff] [blame] | 321 | // When the xfermode is null on the SkPaint (meaning kSrcOver) we need the XPFactory field on |
| 322 | // the GrPaint to also be null (also kSrcOver). |
| 323 | SkASSERT(!grPaint->getXPFactory()); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 324 | if (!skPaint.isSrcOver()) { |
| 325 | grPaint->setXPFactory(SkBlendMode_AsXPFactory(skPaint.getBlendMode())); |
robertphillips | 4f03794 | 2016-02-09 05:09:27 -0800 | [diff] [blame] | 326 | } |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 327 | |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 328 | #ifndef SK_IGNORE_GPU_DITHER |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 329 | GrColorType ct = dstColorInfo.colorType(); |
John Stiles | 53ee0fc | 2020-07-09 15:29:33 -0400 | [diff] [blame] | 330 | if (SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct)) && paintFP != nullptr) { |
Michael Ludwig | 87f5755 | 2020-05-27 14:32:38 -0400 | [diff] [blame] | 331 | float ditherRange = dither_range_for_config(ct); |
John Stiles | 53ee0fc | 2020-07-09 15:29:33 -0400 | [diff] [blame] | 332 | paintFP = GrDitherEffect::Make(std::move(paintFP), ditherRange); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 333 | } |
| 334 | #endif |
John Stiles | 53ee0fc | 2020-07-09 15:29:33 -0400 | [diff] [blame] | 335 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 336 | if (GrColorTypeClampType(dstColorInfo.colorType()) == GrClampType::kManual) { |
John Stiles | d4eb2ec | 2020-07-09 15:38:08 -0400 | [diff] [blame] | 337 | if (paintFP != nullptr) { |
| 338 | paintFP = GrClampFragmentProcessor::Make(std::move(paintFP), /*clampToPremul=*/false); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 339 | } else { |
| 340 | auto color = grPaint->getColor4f(); |
| 341 | grPaint->setColor4f({SkTPin(color.fR, 0.f, 1.f), |
| 342 | SkTPin(color.fG, 0.f, 1.f), |
| 343 | SkTPin(color.fB, 0.f, 1.f), |
| 344 | SkTPin(color.fA, 0.f, 1.f)}); |
| 345 | } |
| 346 | } |
John Stiles | d4eb2ec | 2020-07-09 15:38:08 -0400 | [diff] [blame] | 347 | |
| 348 | if (paintFP) { |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 349 | grPaint->setColorFragmentProcessor(std::move(paintFP)); |
John Stiles | d4eb2ec | 2020-07-09 15:38:08 -0400 | [diff] [blame] | 350 | } |
| 351 | |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 352 | return true; |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 355 | bool SkPaintToGrPaint(GrRecordingContext* context, |
| 356 | const GrColorInfo& dstColorInfo, |
| 357 | const SkPaint& skPaint, |
| 358 | const SkMatrixProvider& matrixProvider, |
| 359 | GrPaint* grPaint) { |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 360 | return skpaint_to_grpaint_impl(context, dstColorInfo, skPaint, matrixProvider, |
| 361 | /*shaderProcessor=*/nullptr, /*primColorMode=*/nullptr, grPaint); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 362 | } |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 363 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 364 | /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */ |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 365 | bool SkPaintToGrPaintReplaceShader(GrRecordingContext* context, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 366 | const GrColorInfo& dstColorInfo, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 367 | const SkPaint& skPaint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 368 | const SkMatrixProvider& matrixProvider, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 369 | std::unique_ptr<GrFragmentProcessor> shaderFP, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 370 | GrPaint* grPaint) { |
| 371 | if (!shaderFP) { |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 372 | return false; |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 373 | } |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 374 | return skpaint_to_grpaint_impl(context, dstColorInfo, skPaint, matrixProvider, &shaderFP, |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 375 | /*primColorMode=*/nullptr, grPaint); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 376 | } |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 377 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 378 | /** Ignores the SkShader (if any) on skPaint. */ |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 379 | bool SkPaintToGrPaintNoShader(GrRecordingContext* context, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 380 | const GrColorInfo& dstColorInfo, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 381 | const SkPaint& skPaint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 382 | const SkMatrixProvider& matrixProvider, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 383 | GrPaint* grPaint) { |
| 384 | // Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced. |
Robert Phillips | d3b37a1 | 2018-03-27 09:53:35 -0400 | [diff] [blame] | 385 | std::unique_ptr<GrFragmentProcessor> nullShaderFP(nullptr); |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 386 | return skpaint_to_grpaint_impl(context, dstColorInfo, skPaint, matrixProvider, &nullShaderFP, |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 387 | /*primColorMode=*/nullptr, grPaint); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 391 | be setup as a vertex attribute using the specified SkBlendMode. */ |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 392 | bool SkPaintToGrPaintWithBlend(GrRecordingContext* context, |
| 393 | const GrColorInfo& dstColorInfo, |
| 394 | const SkPaint& skPaint, |
| 395 | const SkMatrixProvider& matrixProvider, |
| 396 | SkBlendMode primColorMode, |
| 397 | GrPaint* grPaint) { |
| 398 | return skpaint_to_grpaint_impl(context, dstColorInfo, skPaint, matrixProvider, |
| 399 | /*shaderProcessor=*/nullptr, &primColorMode, grPaint); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 400 | } |
| 401 | |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 402 | /** Blends the passed-in shader with a per-primitive color which must be setup as a vertex attribute |
| 403 | using the specified SkBlendMode. */ |
| 404 | bool SkPaintToGrPaintWithBlendReplaceShader(GrRecordingContext* context, |
| 405 | const GrColorInfo& dstColorInfo, |
| 406 | const SkPaint& skPaint, |
| 407 | const SkMatrixProvider& matrixProvider, |
| 408 | std::unique_ptr<GrFragmentProcessor> shaderFP, |
| 409 | SkBlendMode primColorMode, |
| 410 | GrPaint* grPaint) { |
| 411 | if (!shaderFP) { |
| 412 | return false; |
| 413 | } |
| 414 | return skpaint_to_grpaint_impl(context, dstColorInfo, skPaint, matrixProvider, &shaderFP, |
| 415 | &primColorMode, grPaint); |
| 416 | } |
| 417 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 418 | bool SkPaintToGrPaintWithTexture(GrRecordingContext* context, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 419 | const GrColorInfo& dstColorInfo, |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 420 | const SkPaint& paint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 421 | const SkMatrixProvider& matrixProvider, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 422 | std::unique_ptr<GrFragmentProcessor> fp, |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 423 | bool textureIsAlphaOnly, |
| 424 | GrPaint* grPaint) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 425 | std::unique_ptr<GrFragmentProcessor> shaderFP; |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 426 | if (textureIsAlphaOnly) { |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 427 | if (const auto* shader = as_SB(paint.getShader())) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 428 | shaderFP = shader->asFragmentProcessor( |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 429 | GrFPArgs(context, matrixProvider, paint.getFilterQuality(), &dstColorInfo)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 430 | if (!shaderFP) { |
| 431 | return false; |
| 432 | } |
John Stiles | 024d745 | 2020-07-22 19:07:15 -0400 | [diff] [blame] | 433 | shaderFP = GrFragmentProcessor::Compose(std::move(shaderFP), std::move(fp)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 434 | } else { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 435 | shaderFP = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 436 | } |
| 437 | } else { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 438 | if (paint.getColor4f().isOpaque()) { |
| 439 | shaderFP = GrFragmentProcessor::OverrideInput(std::move(fp), SK_PMColor4fWHITE, false); |
| 440 | } else { |
| 441 | shaderFP = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp)); |
| 442 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 445 | return SkPaintToGrPaintReplaceShader(context, dstColorInfo, paint, matrixProvider, |
| 446 | std::move(shaderFP), grPaint); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 447 | } |
| 448 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 449 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 450 | |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 451 | std::tuple<GrSamplerState::Filter, |
| 452 | GrSamplerState::MipmapMode, |
| 453 | bool /*bicubic*/> |
| 454 | GrInterpretFilterQuality(SkISize imageDims, |
| 455 | SkFilterQuality paintFilterQuality, |
| 456 | const SkMatrix& viewM, |
| 457 | const SkMatrix& localM, |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 458 | bool sharpenMipmappedTextures, |
| 459 | bool allowFilterQualityReduction) { |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 460 | using Filter = GrSamplerState::Filter; |
| 461 | using MipmapMode = GrSamplerState::MipmapMode; |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 462 | switch (paintFilterQuality) { |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 463 | case kNone_SkFilterQuality: |
| 464 | return {Filter::kNearest, MipmapMode::kNone, false}; |
| 465 | case kLow_SkFilterQuality: |
| 466 | return {Filter::kLinear, MipmapMode::kNone, false}; |
| 467 | case kMedium_SkFilterQuality: { |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 468 | if (allowFilterQualityReduction) { |
| 469 | SkMatrix matrix; |
| 470 | matrix.setConcat(viewM, localM); |
| 471 | // With sharp mips, we bias lookups by -0.5. That means our final LOD is >= 0 until |
| 472 | // the computed LOD is >= 0.5. At what scale factor does a texture get an LOD of |
| 473 | // 0.5? |
| 474 | // |
| 475 | // Want: 0 = log2(1/s) - 0.5 |
| 476 | // 0.5 = log2(1/s) |
| 477 | // 2^0.5 = 1/s |
| 478 | // 1/2^0.5 = s |
| 479 | // 2^0.5/2 = s |
| 480 | SkScalar mipScale = sharpenMipmappedTextures ? SK_ScalarRoot2Over2 : SK_Scalar1; |
| 481 | if (matrix.getMinScale() >= mipScale) { |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 482 | return {Filter::kLinear, MipmapMode::kNone, false}; |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 483 | } |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 484 | } |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 485 | return {Filter::kLinear, MipmapMode::kLinear, false}; |
| 486 | } |
| 487 | case kHigh_SkFilterQuality: { |
John Stiles | f2f9b0d | 2020-08-25 13:33:45 -0400 | [diff] [blame] | 488 | if (allowFilterQualityReduction) { |
| 489 | SkMatrix matrix; |
| 490 | matrix.setConcat(viewM, localM); |
| 491 | paintFilterQuality = SkMatrixPriv::AdjustHighQualityFilterLevel(matrix); |
| 492 | } |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 493 | switch (paintFilterQuality) { |
| 494 | case kNone_SkFilterQuality: return {Filter::kNearest, MipmapMode::kNone , false}; |
| 495 | case kLow_SkFilterQuality: return {Filter::kLinear , MipmapMode::kNone , false}; |
| 496 | case kMedium_SkFilterQuality: return {Filter::kLinear , MipmapMode::kLinear, false}; |
| 497 | case kHigh_SkFilterQuality: return {Filter::kNearest, MipmapMode::kNone , true }; |
| 498 | } |
| 499 | SkUNREACHABLE; |
| 500 | } |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 501 | } |
Mike Reed | 95b5fb9 | 2020-11-23 19:51:24 +0000 | [diff] [blame^] | 502 | SkUNREACHABLE; |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 503 | } |