blob: 81fde3579d287bfcddf6aa50929b22656d7b81f5 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "SkGr.h"
egdaniel378092f2014-12-03 10:40:13 -08009
Brian Osman3b66ab62016-11-28 09:26:31 -050010#include "GrBitmapTextureMaker.h"
bsalomon76228632015-05-29 08:02:10 -070011#include "GrCaps.h"
bsalomonf276ac52015-10-09 13:36:42 -070012#include "GrContext.h"
bsalomon045802d2015-10-20 07:58:01 -070013#include "GrGpuResourcePriv.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050014#include "GrRenderTargetContext.h"
Brian Osman32342f02017-03-04 08:12:46 -050015#include "GrResourceProvider.h"
Hal Canary6f6961e2017-01-31 13:50:44 -050016#include "GrTextureProxy.h"
cblume55f2d2d2016-02-26 13:20:48 -080017#include "GrTypes.h"
egdaniel378092f2014-12-03 10:40:13 -080018#include "GrXferProcessor.h"
reed43fe6182015-09-08 08:37:36 -070019
Hal Canary95e3c052017-01-11 12:44:43 -050020#include "SkAutoMalloc.h"
reed374772b2016-10-05 17:33:02 -070021#include "SkBlendModePriv.h"
Hal Canary95e3c052017-01-11 12:44:43 -050022#include "SkCanvas.h"
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000023#include "SkColorFilter.h"
Matt Sarett485c4992017-02-14 14:18:27 -050024#include "SkConvertPixels.h"
krajcevski9c0e6292014-06-02 07:38:14 -070025#include "SkData.h"
Brian Osman4075ec82017-01-17 16:41:03 +000026#include "SkImageInfoPriv.h"
Robert Phillipsa29a9562016-10-20 09:40:55 -040027#include "SkMaskFilter.h"
commit-bot@chromium.org50a30432013-10-24 17:44:27 +000028#include "SkMessageBus.h"
cblume55f2d2d2016-02-26 13:20:48 -080029#include "SkMipMap.h"
Kevin Lubickc456b732017-01-11 17:21:57 +000030#include "SkPM4fPriv.h"
Hal Canary95e3c052017-01-11 12:44:43 -050031#include "SkPixelRef.h"
sugoi692135f2015-01-19 10:10:27 -080032#include "SkResourceCache.h"
cblume55f2d2d2016-02-26 13:20:48 -080033#include "SkTemplates.h"
joshualitt9bc39542015-08-12 12:57:54 -070034#include "effects/GrBicubicEffect.h"
bsalomonf1b7a1d2015-09-28 06:26:28 -070035#include "effects/GrConstColorProcessor.h"
krajcevskif461a8f2014-06-19 14:14:06 -070036#include "effects/GrDitherEffect.h"
egdaniel378092f2014-12-03 10:40:13 -080037#include "effects/GrPorterDuffXferProcessor.h"
bsalomonf1b7a1d2015-09-28 06:26:28 -070038#include "effects/GrXfermodeFragmentProcessor.h"
krajcevski9c0e6292014-06-02 07:38:14 -070039
brianosmana6359362016-03-21 06:55:37 -070040GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info, const GrCaps& caps) {
bsalomon466c2c42015-10-16 12:01:18 -070041 GrSurfaceDesc desc;
42 desc.fFlags = kNone_GrSurfaceFlags;
43 desc.fWidth = info.width();
44 desc.fHeight = info.height();
brianosmana6359362016-03-21 06:55:37 -070045 desc.fConfig = SkImageInfo2GrPixelConfig(info, caps);
bsalomon466c2c42015-10-16 12:01:18 -070046 desc.fSampleCnt = 0;
47 return desc;
48}
49
bsalomon045802d2015-10-20 07:58:01 -070050void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds) {
51 SkASSERT(key);
52 SkASSERT(imageID);
53 SkASSERT(!imageBounds.isEmpty());
54 static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomain();
55 GrUniqueKey::Builder builder(key, kImageIDDomain, 5);
bsalomon466c2c42015-10-16 12:01:18 -070056 builder[0] = imageID;
bsalomon045802d2015-10-20 07:58:01 -070057 builder[1] = imageBounds.fLeft;
58 builder[2] = imageBounds.fTop;
59 builder[3] = imageBounds.fRight;
60 builder[4] = imageBounds.fBottom;
bsalomon466c2c42015-10-16 12:01:18 -070061}
62
bsalomon045802d2015-10-20 07:58:01 -070063//////////////////////////////////////////////////////////////////////////////
Robert Phillips26c90e02017-03-14 14:39:29 -040064sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrResourceProvider* resourceProvider,
Matt Sarettdedac852017-05-12 10:56:49 -040065 const SkBitmap& bitmap,
66 SkColorSpace* dstColorSpace) {
Robert Phillipsd3749482017-03-14 09:17:43 -040067 if (!bitmap.readyToDraw()) {
Brian Osman4075ec82017-01-17 16:41:03 +000068 return nullptr;
69 }
Robert Phillipsd3749482017-03-14 09:17:43 -040070 SkPixmap pixmap;
71 if (!bitmap.peekPixels(&pixmap)) {
72 return nullptr;
73 }
Matt Sarettdedac852017-05-12 10:56:49 -040074 return GrUploadPixmapToTextureProxy(resourceProvider, pixmap, SkBudgeted::kYes, dstColorSpace);
Robert Phillipsd3749482017-03-14 09:17:43 -040075}
Brian Osman4075ec82017-01-17 16:41:03 +000076
Robert Phillipsd3749482017-03-14 09:17:43 -040077static const SkPixmap* compute_desc(const GrCaps& caps, const SkPixmap& pixmap,
78 GrSurfaceDesc* desc,
79 SkBitmap* tmpBitmap, SkPixmap* tmpPixmap) {
80 const SkPixmap* pmap = &pixmap;
81
82 *desc = GrImageInfoToSurfaceDesc(pixmap.info(), caps);
bsalomon@google.com5782d712011-01-21 21:03:59 +000083
Brian Osmand0be1ef2017-01-11 16:57:15 -050084 // TODO: We're checking for srgbSupport, but we can then end up picking sBGRA as our pixel
85 // config (which may not be supported). We need better fallback management here.
Brian Osman47299142017-03-07 13:22:22 -050086 SkColorSpace* colorSpace = pixmap.colorSpace();
Brian Osmand0be1ef2017-01-11 16:57:15 -050087
Robert Phillipsd3749482017-03-14 09:17:43 -040088 if (caps.srgbSupport() &&
Matt Sarettf3880932017-03-24 10:06:03 -040089 colorSpace && colorSpace->gammaCloseToSRGB() && !GrPixelConfigIsSRGB(desc->fConfig)) {
brianosmanb109b8c2016-06-16 13:03:24 -070090 // We were supplied an sRGB-like color space, but we don't have a suitable pixel config.
brianosmana6359362016-03-21 06:55:37 -070091 // Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't
92 // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both the source and
93 // destination (claim they're linear):
94 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height(),
95 pixmap.colorType(), pixmap.alphaType());
96 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixmap.ctable());
97
brianosmanb109b8c2016-06-16 13:03:24 -070098 SkImageInfo dstInfo = SkImageInfo::Make(pixmap.width(), pixmap.height(),
99 kN32_SkColorType, kPremul_SkAlphaType,
Robert Phillips70b49fd2017-01-13 11:21:36 -0500100 pixmap.info().refColorSpace());
brianosmanb109b8c2016-06-16 13:03:24 -0700101
Robert Phillipsd3749482017-03-14 09:17:43 -0400102 tmpBitmap->allocPixels(dstInfo);
brianosmana6359362016-03-21 06:55:37 -0700103
104 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.height());
Robert Phillipsd3749482017-03-14 09:17:43 -0400105 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap->getPixels(), tmpBitmap->rowBytes())) {
brianosmana6359362016-03-21 06:55:37 -0700106 return nullptr;
107 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400108 if (!tmpBitmap->peekPixels(tmpPixmap)) {
brianosmana6359362016-03-21 06:55:37 -0700109 return nullptr;
110 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400111 pmap = tmpPixmap;
brianosmana6359362016-03-21 06:55:37 -0700112 // must rebuild desc, since we've forced the info to be N32
Robert Phillipsd3749482017-03-14 09:17:43 -0400113 *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps);
brianosmana6359362016-03-21 06:55:37 -0700114 } else if (kIndex_8_SkColorType == pixmap.colorType()) {
Brian Osmand0be1ef2017-01-11 16:57:15 -0500115 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.height());
Robert Phillipsd3749482017-03-14 09:17:43 -0400116 tmpBitmap->allocPixels(info);
117 if (!pixmap.readPixels(info, tmpBitmap->getPixels(), tmpBitmap->rowBytes())) {
Brian Osmand0be1ef2017-01-11 16:57:15 -0500118 return nullptr;
krajcevski9c0e6292014-06-02 07:38:14 -0700119 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400120 if (!tmpBitmap->peekPixels(tmpPixmap)) {
Brian Osmand0be1ef2017-01-11 16:57:15 -0500121 return nullptr;
122 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400123 pmap = tmpPixmap;
Brian Osmand0be1ef2017-01-11 16:57:15 -0500124 // must rebuild desc, since we've forced the info to be N32
Robert Phillipsd3749482017-03-14 09:17:43 -0400125 *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000126 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000127
Robert Phillipsd3749482017-03-14 09:17:43 -0400128 return pmap;
bsalomon37f9a262015-02-02 13:00:10 -0800129}
130
Matt Sarettdedac852017-05-12 10:56:49 -0400131sk_sp<GrTextureProxy> GrUploadPixmapToTextureProxy(GrResourceProvider* resourceProvider,
132 const SkPixmap& pixmap,
133 SkBudgeted budgeted,
134 SkColorSpace* dstColorSpace) {
135 SkDestinationSurfaceColorMode colorMode = dstColorSpace
136 ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
137 : SkDestinationSurfaceColorMode::kLegacy;
138
139 if (!SkImageInfoIsValid(pixmap.info(), colorMode)) {
140 return nullptr;
141 }
142
Robert Phillipsd3749482017-03-14 09:17:43 -0400143 SkBitmap tmpBitmap;
144 SkPixmap tmpPixmap;
145 GrSurfaceDesc desc;
146
Robert Phillips26c90e02017-03-14 14:39:29 -0400147 if (const SkPixmap* pmap = compute_desc(*resourceProvider->caps(), pixmap, &desc,
148 &tmpBitmap, &tmpPixmap)) {
149 return GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
Robert Phillipsd3749482017-03-14 09:17:43 -0400150 budgeted, pmap->addr(), pmap->rowBytes());
151 }
152
153 return nullptr;
154}
bsalomonb4d40ef2015-07-15 10:12:16 -0700155
bsalomon045802d2015-10-20 07:58:01 -0700156////////////////////////////////////////////////////////////////////////////////
157
bsalomonc55271f2015-11-09 11:55:57 -0800158void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) {
bsalomon89fe56b2015-10-29 10:49:28 -0700159 class Invalidator : public SkPixelRef::GenIDChangeListener {
160 public:
161 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
162 private:
163 GrUniqueKeyInvalidatedMessage fMsg;
164
165 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); }
166 };
167
168 pixelRef->addGenIDChangeListener(new Invalidator(key));
169}
170
Robert Phillips78075802017-03-23 11:11:59 -0400171sk_sp<GrTextureProxy> GrGenerateMipMapsAndUploadToTextureProxy(GrContext* ctx,
172 const SkBitmap& bitmap,
173 SkColorSpace* dstColorSpace) {
Brian Osman61624f02016-12-09 14:51:59 -0500174 SkDestinationSurfaceColorMode colorMode = dstColorSpace
175 ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
176 : SkDestinationSurfaceColorMode::kLegacy;
177
Matt Sarettdedac852017-05-12 10:56:49 -0400178 if (!SkImageInfoIsValid(bitmap.info(), colorMode)) {
Brian Osman4075ec82017-01-17 16:41:03 +0000179 return nullptr;
180 }
181
brianosmana6359362016-03-21 06:55:37 -0700182 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
cblume55f2d2d2016-02-26 13:20:48 -0800183
Mike Reed4edb5d22017-04-17 11:02:51 -0400184 SkPixmap pixmap;
185 if (!bitmap.peekPixels(&pixmap)) {
cblume55f2d2d2016-02-26 13:20:48 -0800186 return nullptr;
187 }
cblume55f2d2d2016-02-26 13:20:48 -0800188
Brian Osman7b8400d2016-11-08 17:08:54 -0500189 std::unique_ptr<SkMipMap> mipmaps(SkMipMap::Build(pixmap, colorMode, nullptr));
cblume55f2d2d2016-02-26 13:20:48 -0800190 if (!mipmaps) {
191 return nullptr;
192 }
193
194 const int mipLevelCount = mipmaps->countLevels() + 1;
195 if (mipLevelCount < 1) {
196 return nullptr;
197 }
198
199 const bool isMipMapped = mipLevelCount > 1;
200 desc.fIsMipMapped = isMipMapped;
201
Ben Wagner7ecc5962016-11-02 17:07:33 -0400202 std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
cblume55f2d2d2016-02-26 13:20:48 -0800203
204 texels[0].fPixels = pixmap.addr();
205 texels[0].fRowBytes = pixmap.rowBytes();
206
207 for (int i = 1; i < mipLevelCount; ++i) {
208 SkMipMap::Level generatedMipLevel;
209 mipmaps->getLevel(i - 1, &generatedMipLevel);
210 texels[i].fPixels = generatedMipLevel.fPixmap.addr();
211 texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
212 }
213
Robert Phillipse78b7252017-04-06 07:59:41 -0400214 return ctx->resourceProvider()->createMipMappedTexture(desc,
215 SkBudgeted::kYes,
216 texels.get(),
217 mipLevelCount,
Robert Phillips45fdae12017-04-17 12:57:27 -0400218 colorMode);
Robert Phillips0c984a02017-03-16 07:51:56 -0400219}
220
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400221sk_sp<GrTextureProxy> GrUploadMipMapToTextureProxy(GrContext* ctx, const SkImageInfo& info,
222 const GrMipLevel* texels,
223 int mipLevelCount,
224 SkDestinationSurfaceColorMode colorMode) {
Matt Sarettdedac852017-05-12 10:56:49 -0400225 if (!SkImageInfoIsValid(info, colorMode)) {
Robert Phillips78075802017-03-23 11:11:59 -0400226 return nullptr;
227 }
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400228
Robert Phillips78075802017-03-23 11:11:59 -0400229 const GrCaps* caps = ctx->caps();
Robert Phillipse78b7252017-04-06 07:59:41 -0400230 return ctx->resourceProvider()->createMipMappedTexture(GrImageInfoToSurfaceDesc(info, *caps),
Robert Phillips78075802017-03-23 11:11:59 -0400231 SkBudgeted::kYes, texels,
Robert Phillips45fdae12017-04-17 12:57:27 -0400232 mipLevelCount, colorMode);
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400233}
234
Robert Phillipsbbd7a3b2017-03-21 08:48:40 -0400235sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext* ctx,
236 const SkBitmap& bitmap,
237 const GrSamplerParams& params,
238 SkScalar scaleAdjust[2]) {
239 // Caller doesn't care about the texture's color space (they can always get it from the bitmap)
Robert Phillips3798c862017-03-27 11:08:16 -0400240 return GrBitmapTextureMaker(ctx, bitmap).refTextureProxyForParams(params, nullptr,
241 nullptr, scaleAdjust);
Robert Phillipsbbd7a3b2017-03-21 08:48:40 -0400242}
243
Robert Phillips26c90e02017-03-14 14:39:29 -0400244sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider* resourceProvider,
245 const SkBitmap& bitmap) {
Robert Phillipse14d3052017-02-15 13:18:21 -0500246 GrUniqueKey originalKey;
247
248 if (!bitmap.isVolatile()) {
249 SkIPoint origin = bitmap.pixelRefOrigin();
250 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), bitmap.height());
251 GrMakeKeyFromImageID(&originalKey, bitmap.pixelRef()->getGenerationID(), subset);
252 }
253
Robert Phillipsd3749482017-03-14 09:17:43 -0400254 sk_sp<GrTextureProxy> proxy;
Robert Phillipse14d3052017-02-15 13:18:21 -0500255
256 if (originalKey.isValid()) {
Robert Phillips26c90e02017-03-14 14:39:29 -0400257 proxy = resourceProvider->findProxyByUniqueKey(originalKey);
Robert Phillipse14d3052017-02-15 13:18:21 -0500258 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400259 if (!proxy) {
Matt Sarettdedac852017-05-12 10:56:49 -0400260 // Pass nullptr for |dstColorSpace|. This is lenient - we allow a wider range of
261 // color spaces in legacy mode. Unfortunately, we have to be lenient here, since
262 // we can't necessarily know the |dstColorSpace| at this time.
263 proxy = GrUploadBitmapToTextureProxy(resourceProvider, bitmap, nullptr);
Robert Phillipsd3749482017-03-14 09:17:43 -0400264 if (proxy && originalKey.isValid()) {
Robert Phillips26c90e02017-03-14 14:39:29 -0400265 resourceProvider->assignUniqueKeyToProxy(originalKey, proxy.get());
Robert Phillipsd3749482017-03-14 09:17:43 -0400266 // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
Robert Phillipse14d3052017-02-15 13:18:21 -0500267 GrInstallBitmapUniqueKeyInvalidator(originalKey, bitmap.pixelRef());
268 }
269 }
270
Robert Phillipsd3749482017-03-14 09:17:43 -0400271 return proxy;
Robert Phillipse14d3052017-02-15 13:18:21 -0500272}
273
rileya@google.com24f3ad12012-07-18 21:47:40 +0000274///////////////////////////////////////////////////////////////////////////////
275
Brian Osman72ae4312016-10-20 16:53:45 -0400276GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
277 // We want to premultiply after linearizing, so this is easy:
278 return SkColorToUnpremulGrColor4f(c, dstColorSpace).premul();
279}
280
281GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
282 if (dstColorSpace) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500283 auto srgbColorSpace = SkColorSpace::MakeSRGB();
Brian Osman72ae4312016-10-20 16:53:45 -0400284 auto gamutXform = GrColorSpaceXform::Make(srgbColorSpace.get(), dstColorSpace);
Brian Osman47299142017-03-07 13:22:22 -0500285 return SkColorToUnpremulGrColor4f(c, dstColorSpace, gamutXform.get());
Brian Osman72ae4312016-10-20 16:53:45 -0400286 } else {
Brian Osman47299142017-03-07 13:22:22 -0500287 return SkColorToUnpremulGrColor4f(c, nullptr, nullptr);
Brian Osman72ae4312016-10-20 16:53:45 -0400288 }
289}
290
Brian Osman47299142017-03-07 13:22:22 -0500291GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
292 GrColorSpaceXform* gamutXform) {
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400293 // We want to premultiply after linearizing, so this is easy:
Brian Osman47299142017-03-07 13:22:22 -0500294 return SkColorToUnpremulGrColor4f(c, dstColorSpace, gamutXform).premul();
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400295}
296
Brian Osman47299142017-03-07 13:22:22 -0500297GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
298 GrColorSpaceXform* gamutXform) {
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400299 // You can't be color-space aware in legacy mode
Brian Osman47299142017-03-07 13:22:22 -0500300 SkASSERT(dstColorSpace || !gamutXform);
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400301
302 GrColor4f color;
Brian Osman47299142017-03-07 13:22:22 -0500303 if (dstColorSpace) {
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400304 // SkColor4f::FromColor does sRGB -> Linear
305 color = GrColor4f::FromSkColor4f(SkColor4f::FromColor(c));
306 } else {
307 // GrColor4f::FromGrColor just multiplies by 1/255
308 color = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(c));
309 }
310
311 if (gamutXform) {
312 color = gamutXform->apply(color);
313 }
314
315 return color;
316}
317
318///////////////////////////////////////////////////////////////////////////////
319
Brian Osman0c2997b2017-01-11 16:58:42 -0500320GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) {
brianosmana6359362016-03-21 06:55:37 -0700321 // We intentionally ignore profile type for non-8888 formats. Anything we can't support
322 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture.
Brian Osman0c2997b2017-01-11 16:58:42 -0500323 SkColorSpace* cs = info.colorSpace();
324 switch (info.colorType()) {
brianosmanc571c002016-03-17 13:01:26 -0700325 case kUnknown_SkColorType:
326 return kUnknown_GrPixelConfig;
327 case kAlpha_8_SkColorType:
328 return kAlpha_8_GrPixelConfig;
329 case kRGB_565_SkColorType:
330 return kRGB_565_GrPixelConfig;
331 case kARGB_4444_SkColorType:
332 return kRGBA_4444_GrPixelConfig;
333 case kRGBA_8888_SkColorType:
Matt Sarettf3880932017-03-24 10:06:03 -0400334 return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
brianosmana6359362016-03-21 06:55:37 -0700335 ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
brianosmanc571c002016-03-17 13:01:26 -0700336 case kBGRA_8888_SkColorType:
Matt Sarettf3880932017-03-24 10:06:03 -0400337 return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
brianosmana6359362016-03-21 06:55:37 -0700338 ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
brianosmanc571c002016-03-17 13:01:26 -0700339 case kIndex_8_SkColorType:
Brian Osmand0be1ef2017-01-11 16:57:15 -0500340 return kSkia8888_GrPixelConfig;
brianosmanc571c002016-03-17 13:01:26 -0700341 case kGray_8_SkColorType:
Brian Osman986563b2017-01-10 14:20:02 -0500342 return kGray_8_GrPixelConfig;
brianosmanc571c002016-03-17 13:01:26 -0700343 case kRGBA_F16_SkColorType:
344 return kRGBA_half_GrPixelConfig;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000345 }
346 SkASSERT(0); // shouldn't get here
347 return kUnknown_GrPixelConfig;
348}
349
brianosman396fcdb2016-07-22 06:26:11 -0700350bool GrPixelConfigToColorType(GrPixelConfig config, SkColorType* ctOut) {
reed@google.combf790232013-12-13 19:45:58 +0000351 SkColorType ct;
352 switch (config) {
353 case kAlpha_8_GrPixelConfig:
354 ct = kAlpha_8_SkColorType;
355 break;
Brian Osman986563b2017-01-10 14:20:02 -0500356 case kGray_8_GrPixelConfig:
357 ct = kGray_8_SkColorType;
358 break;
reed@google.combf790232013-12-13 19:45:58 +0000359 case kRGB_565_GrPixelConfig:
360 ct = kRGB_565_SkColorType;
361 break;
362 case kRGBA_4444_GrPixelConfig:
363 ct = kARGB_4444_SkColorType;
364 break;
365 case kRGBA_8888_GrPixelConfig:
366 ct = kRGBA_8888_SkColorType;
367 break;
368 case kBGRA_8888_GrPixelConfig:
369 ct = kBGRA_8888_SkColorType;
370 break;
jvanverthfa1e8a72014-12-22 08:31:49 -0800371 case kSRGBA_8888_GrPixelConfig:
372 ct = kRGBA_8888_SkColorType;
jvanverthfa1e8a72014-12-22 08:31:49 -0800373 break;
brianosmana6359362016-03-21 06:55:37 -0700374 case kSBGRA_8888_GrPixelConfig:
375 ct = kBGRA_8888_SkColorType;
brianosmana6359362016-03-21 06:55:37 -0700376 break;
brianosman9ac5b912016-04-12 13:49:53 -0700377 case kRGBA_half_GrPixelConfig:
378 ct = kRGBA_F16_SkColorType;
379 break;
reed@google.combf790232013-12-13 19:45:58 +0000380 default:
381 return false;
382 }
383 if (ctOut) {
384 *ctOut = ct;
385 }
386 return true;
387}
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000388
brianosman27a3aa52016-09-23 07:11:34 -0700389GrPixelConfig GrRenderableConfigForColorSpace(const SkColorSpace* colorSpace) {
Matt Sarettf3880932017-03-24 10:06:03 -0400390 if (!colorSpace) {
brianosman2695eaa2016-09-21 06:45:09 -0700391 return kRGBA_8888_GrPixelConfig;
392 } else if (colorSpace->gammaIsLinear()) {
393 return kRGBA_half_GrPixelConfig;
394 } else if (colorSpace->gammaCloseToSRGB()) {
395 return kSRGBA_8888_GrPixelConfig;
396 } else {
397 SkDEBUGFAIL("No renderable config exists for color space with strange gamma");
398 return kUnknown_GrPixelConfig;
399 }
400}
401
bsalomonf1b7a1d2015-09-28 06:26:28 -0700402////////////////////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000403
Mike Reed185ba212017-04-28 12:31:05 -0400404static inline bool blend_requires_shader(const SkBlendMode mode) {
405 return SkBlendMode::kDst != mode;
bsalomonaa48d362015-10-01 08:34:17 -0700406}
407
bsalomonf1b7a1d2015-09-28 06:26:28 -0700408static inline bool skpaint_to_grpaint_impl(GrContext* context,
Brian Osman11052242016-10-27 14:47:55 -0400409 GrRenderTargetContext* rtc,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700410 const SkPaint& skPaint,
411 const SkMatrix& viewM,
bungeman06ca8ec2016-06-09 08:01:03 -0700412 sk_sp<GrFragmentProcessor>* shaderProcessor,
Mike Reed7d954ad2016-10-28 15:42:34 -0400413 SkBlendMode* primColorMode,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700414 GrPaint* grPaint) {
Brian Osman11052242016-10-27 14:47:55 -0400415 grPaint->setAllowSRGBInputs(rtc->isGammaCorrect());
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000416
Brian Osmanc68d4aa2016-09-30 11:41:59 -0400417 // Convert SkPaint color to 4f format, including optional linearizing and gamut conversion.
Brian Osman47299142017-03-07 13:22:22 -0500418 GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), rtc->getColorSpace(),
Brian Osman11052242016-10-27 14:47:55 -0400419 rtc->getColorXformFromSRGB());
brianosmana4535a32016-06-24 12:50:19 -0700420
bsalomonf1b7a1d2015-09-28 06:26:28 -0700421 // Setup the initial color considering the shader, the SkPaint color, and the presence or not
422 // of per-vertex colors.
bungeman06ca8ec2016-06-09 08:01:03 -0700423 sk_sp<GrFragmentProcessor> shaderFP;
Mike Reed185ba212017-04-28 12:31:05 -0400424 if (!primColorMode || blend_requires_shader(*primColorMode)) {
bsalomonaa48d362015-10-01 08:34:17 -0700425 if (shaderProcessor) {
426 shaderFP = *shaderProcessor;
427 } else if (const SkShader* shader = skPaint.getShader()) {
brianosman839345d2016-07-22 11:04:53 -0700428 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr,
429 skPaint.getFilterQuality(),
Brian Osman61624f02016-12-09 14:51:59 -0500430 rtc->getColorSpace()));
bsalomonaa48d362015-10-01 08:34:17 -0700431 if (!shaderFP) {
432 return false;
433 }
bsalomonf1b7a1d2015-09-28 06:26:28 -0700434 }
435 }
436
437 // Set this in below cases if the output of the shader/paint-color/paint-alpha/primXfermode is
438 // a known constant value. In that case we can simply apply a color filter during this
439 // conversion without converting the color filter to a GrFragmentProcessor.
440 bool applyColorFilterToPaintColor = false;
441 if (shaderFP) {
442 if (primColorMode) {
443 // There is a blend between the primitive color and the shader color. The shader sees
444 // the opaque paint color. The shader's output is blended using the provided mode by
445 // the primitive color. The blended color is then modulated by the paint's alpha.
446
447 // The geometry processor will insert the primitive color to start the color chain, so
448 // the GrPaint color will be ignored.
449
brianosman4cea3b92016-09-08 09:33:50 -0700450 GrColor4f shaderInput = origColor.opaque();
bsalomonf1b7a1d2015-09-28 06:26:28 -0700451 shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput);
Mike Reed185ba212017-04-28 12:31:05 -0400452 shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std::move(shaderFP),
453 *primColorMode);
454
bsalomonf1b7a1d2015-09-28 06:26:28 -0700455 // The above may return null if compose results in a pass through of the prim color.
456 if (shaderFP) {
457 grPaint->addColorFragmentProcessor(shaderFP);
458 }
459
brianosmana4535a32016-06-24 12:50:19 -0700460 // We can ignore origColor here - alpha is unchanged by gamma
bsalomonf1b7a1d2015-09-28 06:26:28 -0700461 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
462 if (GrColor_WHITE != paintAlpha) {
Brian Osman618d3042016-10-25 10:51:28 -0400463 // No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
464 // color channels. It's value should be treated as the same in ANY color space.
bungeman06ca8ec2016-06-09 08:01:03 -0700465 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
Brian Osman618d3042016-10-25 10:51:28 -0400466 GrColor4f::FromGrColor(paintAlpha),
467 GrConstColorProcessor::kModulateRGBA_InputMode));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700468 }
469 } else {
470 // The shader's FP sees the paint unpremul color
brianosmana4535a32016-06-24 12:50:19 -0700471 grPaint->setColor4f(origColor);
bungeman06ca8ec2016-06-09 08:01:03 -0700472 grPaint->addColorFragmentProcessor(std::move(shaderFP));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700473 }
474 } else {
475 if (primColorMode) {
476 // There is a blend between the primitive color and the paint color. The blend considers
477 // the opaque paint color. The paint's alpha is applied to the post-blended color.
bungeman06ca8ec2016-06-09 08:01:03 -0700478 sk_sp<GrFragmentProcessor> processor(
Brian Osman618d3042016-10-25 10:51:28 -0400479 GrConstColorProcessor::Make(origColor.opaque(),
480 GrConstColorProcessor::kIgnore_InputMode));
Mike Reed185ba212017-04-28 12:31:05 -0400481 processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std::move(processor),
482 *primColorMode);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700483 if (processor) {
bungeman06ca8ec2016-06-09 08:01:03 -0700484 grPaint->addColorFragmentProcessor(std::move(processor));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700485 }
486
brianosmana4535a32016-06-24 12:50:19 -0700487 grPaint->setColor4f(origColor.opaque());
bsalomonf1b7a1d2015-09-28 06:26:28 -0700488
brianosmana4535a32016-06-24 12:50:19 -0700489 // We can ignore origColor here - alpha is unchanged by gamma
bsalomonf1b7a1d2015-09-28 06:26:28 -0700490 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
bsalomonaa48d362015-10-01 08:34:17 -0700491 if (GrColor_WHITE != paintAlpha) {
Brian Osman618d3042016-10-25 10:51:28 -0400492 // No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
493 // color channels. It's value should be treated as the same in ANY color space.
bungeman06ca8ec2016-06-09 08:01:03 -0700494 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
Brian Osman618d3042016-10-25 10:51:28 -0400495 GrColor4f::FromGrColor(paintAlpha),
496 GrConstColorProcessor::kModulateRGBA_InputMode));
bsalomonaa48d362015-10-01 08:34:17 -0700497 }
bsalomonf1b7a1d2015-09-28 06:26:28 -0700498 } else {
499 // No shader, no primitive color.
brianosmana4535a32016-06-24 12:50:19 -0700500 grPaint->setColor4f(origColor.premul());
bsalomonf1b7a1d2015-09-28 06:26:28 -0700501 applyColorFilterToPaintColor = true;
502 }
503 }
504
505 SkColorFilter* colorFilter = skPaint.getColorFilter();
506 if (colorFilter) {
507 if (applyColorFilterToPaintColor) {
Brian Osman8bf4e672016-10-17 16:54:49 -0400508 // If we're in legacy mode, we *must* avoid using the 4f version of the color filter,
509 // because that will combine with the linearized version of the stored color.
Brian Osman11052242016-10-27 14:47:55 -0400510 if (rtc->isGammaCorrect()) {
Brian Osman8bf4e672016-10-17 16:54:49 -0400511 grPaint->setColor4f(GrColor4f::FromSkColor4f(
512 colorFilter->filterColor4f(origColor.toSkColor4f())).premul());
513 } else {
514 grPaint->setColor4f(SkColorToPremulGrColor4f(
Brian Osman47299142017-03-07 13:22:22 -0500515 colorFilter->filterColor(skPaint.getColor()), nullptr, nullptr));
Brian Osman8bf4e672016-10-17 16:54:49 -0400516 }
bsalomonf1b7a1d2015-09-28 06:26:28 -0700517 } else {
Brian Osman618d3042016-10-25 10:51:28 -0400518 sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(context,
Brian Osman11052242016-10-27 14:47:55 -0400519 rtc->getColorSpace()));
bsalomone25eea42015-09-29 06:38:55 -0700520 if (cfFP) {
bungeman06ca8ec2016-06-09 08:01:03 -0700521 grPaint->addColorFragmentProcessor(std::move(cfFP));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700522 } else {
523 return false;
524 }
525 }
526 }
527
Robert Phillipsa29a9562016-10-20 09:40:55 -0400528 SkMaskFilter* maskFilter = skPaint.getMaskFilter();
529 if (maskFilter) {
530 GrFragmentProcessor* mfFP;
531 if (maskFilter->asFragmentProcessor(&mfFP, nullptr, viewM)) {
532 grPaint->addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor>(mfFP));
533 }
534 }
535
robertphillips4f037942016-02-09 05:09:27 -0800536 // When the xfermode is null on the SkPaint (meaning kSrcOver) we need the XPFactory field on
537 // the GrPaint to also be null (also kSrcOver).
538 SkASSERT(!grPaint->getXPFactory());
reed374772b2016-10-05 17:33:02 -0700539 if (!skPaint.isSrcOver()) {
540 grPaint->setXPFactory(SkBlendMode_AsXPFactory(skPaint.getBlendMode()));
robertphillips4f037942016-02-09 05:09:27 -0800541 }
mtklein775b8192014-12-02 09:11:25 -0800542
krajcevskif461a8f2014-06-19 14:14:06 -0700543#ifndef SK_IGNORE_GPU_DITHER
Brian Osman11052242016-10-27 14:47:55 -0400544 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !rtc->isGammaCorrect()) {
bungeman06ca8ec2016-06-09 08:01:03 -0700545 grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
krajcevskif461a8f2014-06-19 14:14:06 -0700546 }
547#endif
bsalomonbed83a62015-04-15 14:18:34 -0700548 return true;
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000549}
550
Brian Osman11052242016-10-27 14:47:55 -0400551bool SkPaintToGrPaint(GrContext* context, GrRenderTargetContext* rtc, const SkPaint& skPaint,
brianosman8fe485b2016-07-25 12:31:51 -0700552 const SkMatrix& viewM, GrPaint* grPaint) {
Mike Reed185ba212017-04-28 12:31:05 -0400553 return skpaint_to_grpaint_impl(context, rtc, skPaint, viewM, nullptr, nullptr, grPaint);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700554}
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000555
bsalomonf1b7a1d2015-09-28 06:26:28 -0700556/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */
557bool SkPaintToGrPaintReplaceShader(GrContext* context,
Brian Osman11052242016-10-27 14:47:55 -0400558 GrRenderTargetContext* rtc,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700559 const SkPaint& skPaint,
bungeman06ca8ec2016-06-09 08:01:03 -0700560 sk_sp<GrFragmentProcessor> shaderFP,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700561 GrPaint* grPaint) {
562 if (!shaderFP) {
bsalomonc21b09e2015-08-28 18:46:56 -0700563 return false;
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000564 }
Mike Reed185ba212017-04-28 12:31:05 -0400565 return skpaint_to_grpaint_impl(context, rtc, skPaint, SkMatrix::I(), &shaderFP, nullptr,
brianosman8fe485b2016-07-25 12:31:51 -0700566 grPaint);
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000567}
reed8b26b992015-05-07 15:36:17 -0700568
bsalomonf1b7a1d2015-09-28 06:26:28 -0700569/** Ignores the SkShader (if any) on skPaint. */
570bool SkPaintToGrPaintNoShader(GrContext* context,
Brian Osman11052242016-10-27 14:47:55 -0400571 GrRenderTargetContext* rtc,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700572 const SkPaint& skPaint,
573 GrPaint* grPaint) {
574 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced.
bungeman06ca8ec2016-06-09 08:01:03 -0700575 static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
576 static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
Brian Osman11052242016-10-27 14:47:55 -0400577 return skpaint_to_grpaint_impl(context, rtc, skPaint, SkMatrix::I(), kIgnoreShader, nullptr,
Mike Reed185ba212017-04-28 12:31:05 -0400578 grPaint);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700579}
580
581/** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must
Mike Reed7d954ad2016-10-28 15:42:34 -0400582be setup as a vertex attribute using the specified SkBlendMode. */
bsalomonf1b7a1d2015-09-28 06:26:28 -0700583bool SkPaintToGrPaintWithXfermode(GrContext* context,
Brian Osman11052242016-10-27 14:47:55 -0400584 GrRenderTargetContext* rtc,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700585 const SkPaint& skPaint,
586 const SkMatrix& viewM,
Mike Reed7d954ad2016-10-28 15:42:34 -0400587 SkBlendMode primColorMode,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700588 GrPaint* grPaint) {
Brian Osman11052242016-10-27 14:47:55 -0400589 return skpaint_to_grpaint_impl(context, rtc, skPaint, viewM, nullptr, &primColorMode,
Mike Reed185ba212017-04-28 12:31:05 -0400590 grPaint);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700591}
592
joshualitt33a5fce2015-11-18 13:28:51 -0800593bool SkPaintToGrPaintWithTexture(GrContext* context,
Brian Osman11052242016-10-27 14:47:55 -0400594 GrRenderTargetContext* rtc,
joshualitt33a5fce2015-11-18 13:28:51 -0800595 const SkPaint& paint,
596 const SkMatrix& viewM,
bungeman06ca8ec2016-06-09 08:01:03 -0700597 sk_sp<GrFragmentProcessor> fp,
joshualitt33a5fce2015-11-18 13:28:51 -0800598 bool textureIsAlphaOnly,
599 GrPaint* grPaint) {
bungeman06ca8ec2016-06-09 08:01:03 -0700600 sk_sp<GrFragmentProcessor> shaderFP;
joshualitt33a5fce2015-11-18 13:28:51 -0800601 if (textureIsAlphaOnly) {
602 if (const SkShader* shader = paint.getShader()) {
brianosman839345d2016-07-22 11:04:53 -0700603 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context,
604 &viewM,
605 nullptr,
606 paint.getFilterQuality(),
Brian Osman61624f02016-12-09 14:51:59 -0500607 rtc->getColorSpace()));
joshualitt33a5fce2015-11-18 13:28:51 -0800608 if (!shaderFP) {
609 return false;
610 }
bungeman06ca8ec2016-06-09 08:01:03 -0700611 sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std::move(fp) };
612 shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2);
joshualitt33a5fce2015-11-18 13:28:51 -0800613 } else {
Brian Salomon22af73f2017-01-26 11:25:12 -0500614 shaderFP = GrFragmentProcessor::MakeInputPremulAndMulByOutput(fp);
joshualitt33a5fce2015-11-18 13:28:51 -0800615 }
616 } else {
bungeman06ca8ec2016-06-09 08:01:03 -0700617 shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
joshualitt33a5fce2015-11-18 13:28:51 -0800618 }
619
Brian Osman11052242016-10-27 14:47:55 -0400620 return SkPaintToGrPaintReplaceShader(context, rtc, paint, std::move(shaderFP), grPaint);
joshualitt33a5fce2015-11-18 13:28:51 -0800621}
622
bsalomonf1b7a1d2015-09-28 06:26:28 -0700623
624////////////////////////////////////////////////////////////////////////////////////////////////
625
Brian Salomon514baff2016-11-17 15:17:07 -0500626GrSamplerParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
joshualitt9bc39542015-08-12 12:57:54 -0700627 const SkMatrix& viewM,
628 const SkMatrix& localM,
629 bool* doBicubic) {
630 *doBicubic = false;
Brian Salomon514baff2016-11-17 15:17:07 -0500631 GrSamplerParams::FilterMode textureFilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700632 switch (paintFilterQuality) {
633 case kNone_SkFilterQuality:
Brian Salomon514baff2016-11-17 15:17:07 -0500634 textureFilterMode = GrSamplerParams::kNone_FilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700635 break;
636 case kLow_SkFilterQuality:
Brian Salomon514baff2016-11-17 15:17:07 -0500637 textureFilterMode = GrSamplerParams::kBilerp_FilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700638 break;
639 case kMedium_SkFilterQuality: {
640 SkMatrix matrix;
641 matrix.setConcat(viewM, localM);
642 if (matrix.getMinScale() < SK_Scalar1) {
Brian Salomon514baff2016-11-17 15:17:07 -0500643 textureFilterMode = GrSamplerParams::kMipMap_FilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700644 } else {
645 // Don't trigger MIP level generation unnecessarily.
Brian Salomon514baff2016-11-17 15:17:07 -0500646 textureFilterMode = GrSamplerParams::kBilerp_FilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700647 }
648 break;
649 }
650 case kHigh_SkFilterQuality: {
651 SkMatrix matrix;
652 matrix.setConcat(viewM, localM);
653 *doBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode);
654 break;
655 }
656 default:
Mike Kleine54c75f2016-10-13 14:18:09 -0400657 // Should be unreachable. If not, fall back to mipmaps.
Brian Salomon514baff2016-11-17 15:17:07 -0500658 textureFilterMode = GrSamplerParams::kMipMap_FilterMode;
joshualitt9bc39542015-08-12 12:57:54 -0700659 break;
660
661 }
662 return textureFilterMode;
663}