| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 1 | /* | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 2 | * Copyright 2017 Google Inc. | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 3 | * | 
|  | 4 | * Use of this source code is governed by a BSD-style license that can be | 
|  | 5 | * found in the LICENSE file. | 
|  | 6 | */ | 
|  | 7 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 8 | #ifndef SkGr_DEFINED | 
|  | 9 | #define SkGr_DEFINED | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 10 |  | 
| Ethan Nicholas | 052fd51 | 2017-01-27 15:34:34 +0000 | [diff] [blame] | 11 | #include "GrBlend.h" | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 12 | #include "GrColor.h" | 
| Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 13 | #include "GrSamplerParams.h" | 
| Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 14 | #include "GrTypes.h" | 
| Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 15 | #include "SkCanvas.h" | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 16 | #include "SkColor.h" | 
|  | 17 | #include "SkColorPriv.h" | 
|  | 18 | #include "SkFilterQuality.h" | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 19 | #include "SkImageInfo.h" | 
| bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 20 | #include "SkMatrix.h" | 
| Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 21 | #include "SkPM4f.h" | 
| Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 22 | #include "SkVertices.h" | 
| Mike Reed | d470673 | 2016-11-15 16:44:34 -0500 | [diff] [blame] | 23 | #include "SkXfermodePriv.h" | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | class GrCaps; | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 26 | class GrColorSpaceXform; | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 27 | class GrContext; | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 28 | class GrRenderTargetContext; | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 29 | class GrFragmentProcessor; | 
|  | 30 | class GrPaint; | 
| Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 31 | class GrResourceProvider; | 
| Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 32 | class GrTextureProxy; | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 33 | class GrUniqueKey; | 
| Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 34 | class SkBitmap; | 
| bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 35 | class SkData; | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 36 | class SkPaint; | 
| bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 37 | class SkPixelRef; | 
| Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 38 | class SkPixmap; | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 39 | struct SkIRect; | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 40 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 41 | //////////////////////////////////////////////////////////////////////////////// | 
|  | 42 | // Color type conversions | 
| reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 43 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 44 | static inline GrColor SkColorToPremulGrColor(SkColor c) { | 
|  | 45 | SkPMColor pm = SkPreMultiplyColor(c); | 
|  | 46 | unsigned r = SkGetPackedR32(pm); | 
|  | 47 | unsigned g = SkGetPackedG32(pm); | 
|  | 48 | unsigned b = SkGetPackedB32(pm); | 
|  | 49 | unsigned a = SkGetPackedA32(pm); | 
|  | 50 | return GrColorPackRGBA(r, g, b, a); | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | static inline GrColor SkColorToUnpremulGrColor(SkColor c) { | 
|  | 54 | unsigned r = SkColorGetR(c); | 
|  | 55 | unsigned g = SkColorGetG(c); | 
|  | 56 | unsigned b = SkColorGetB(c); | 
|  | 57 | unsigned a = SkColorGetA(c); | 
|  | 58 | return GrColorPackRGBA(r, g, b, a); | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | /** Transform an SkColor (sRGB bytes) to GrColor4f for the specified color space. */ | 
|  | 62 | GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace); | 
|  | 63 | GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace); | 
|  | 64 |  | 
|  | 65 | /** | 
|  | 66 | * As above, but with a caller-supplied color space xform object. Faster for the cases where we | 
|  | 67 | * have that cached. | 
|  | 68 | */ | 
|  | 69 | GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace, | 
|  | 70 | GrColorSpaceXform* gamutXform); | 
|  | 71 | GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace, | 
|  | 72 | GrColorSpaceXform* gamutXform); | 
|  | 73 |  | 
|  | 74 | /** Replicates the SkColor's alpha to all four channels of the GrColor. */ | 
|  | 75 | static inline GrColor SkColorAlphaToGrColor(SkColor c) { | 
|  | 76 | U8CPU a = SkColorGetA(c); | 
|  | 77 | return GrColorPackRGBA(a, a, a, a); | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | ////////////////////////////////////////////////////////////////////////////// | 
|  | 81 |  | 
|  | 82 | static inline SkPM4f GrColor4fToSkPM4f(const GrColor4f& c) { | 
|  | 83 | SkPM4f pm4f; | 
|  | 84 | pm4f.fVec[SkPM4f::R] = c.fRGBA[0]; | 
|  | 85 | pm4f.fVec[SkPM4f::G] = c.fRGBA[1]; | 
|  | 86 | pm4f.fVec[SkPM4f::B] = c.fRGBA[2]; | 
|  | 87 | pm4f.fVec[SkPM4f::A] = c.fRGBA[3]; | 
|  | 88 | return pm4f; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | static inline GrColor4f SkPM4fToGrColor4f(const SkPM4f& c) { | 
|  | 92 | return GrColor4f{c.r(), c.g(), c.b(), c.a()}; | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | //////////////////////////////////////////////////////////////////////////////// | 
|  | 96 | // Paint conversion | 
| bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 97 |  | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 98 | /** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order | 
| bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 99 | to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */ | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 100 | bool SkPaintToGrPaint(GrContext*, | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 101 | GrRenderTargetContext*, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 102 | const SkPaint& skPaint, | 
|  | 103 | const SkMatrix& viewM, | 
|  | 104 | GrPaint* grPaint); | 
|  | 105 |  | 
| bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 106 | /** Same as above but ignores the SkShader (if any) on skPaint. */ | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 107 | bool SkPaintToGrPaintNoShader(GrContext* context, | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 108 | GrRenderTargetContext* rtc, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 109 | const SkPaint& skPaint, | 
|  | 110 | GrPaint* grPaint); | 
|  | 111 |  | 
|  | 112 | /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. The processor | 
| bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 113 | should expect an unpremul input color and produce a premultiplied output color. There is | 
|  | 114 | no primitive color. */ | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 115 | bool SkPaintToGrPaintReplaceShader(GrContext*, | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 116 | GrRenderTargetContext*, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 117 | const SkPaint& skPaint, | 
| bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 118 | sk_sp<GrFragmentProcessor> shaderFP, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 119 | GrPaint* grPaint); | 
|  | 120 |  | 
|  | 121 | /** Blends the SkPaint's shader (or color if no shader) with the color which specified via a | 
| Mike Reed | 185ba21 | 2017-04-28 12:31:05 -0400 | [diff] [blame] | 122 | GrOp's GrPrimitiveProcesssor. */ | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 123 | bool SkPaintToGrPaintWithXfermode(GrContext* context, | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 124 | GrRenderTargetContext* rtc, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 125 | const SkPaint& skPaint, | 
|  | 126 | const SkMatrix& viewM, | 
| Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 127 | SkBlendMode primColorMode, | 
| bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 128 | GrPaint* grPaint); | 
|  | 129 |  | 
| bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 130 | /** This is used when there is a primitive color, but the shader should be ignored. Currently, | 
|  | 131 | the expectation is that the primitive color will be premultiplied, though it really should be | 
|  | 132 | unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be | 
|  | 133 | applied to the primitive color after interpolation. */ | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 134 | inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrRenderTargetContext* rtc, | 
| brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 135 | const SkPaint& skPaint, GrPaint* grPaint) { | 
| Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 136 | return SkPaintToGrPaintWithXfermode(context, rtc, skPaint, SkMatrix::I(), SkBlendMode::kDst, | 
| Mike Reed | 185ba21 | 2017-04-28 12:31:05 -0400 | [diff] [blame] | 137 | grPaint); | 
| bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 140 | /** This is used when there may or may not be a shader, and the caller wants to plugin a texture | 
|  | 141 | lookup.  If there is a shader, then its output will only be used if the texture is alpha8. */ | 
|  | 142 | bool SkPaintToGrPaintWithTexture(GrContext* context, | 
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 143 | GrRenderTargetContext* rtc, | 
| joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 144 | const SkPaint& paint, | 
|  | 145 | const SkMatrix& viewM, | 
| bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 146 | sk_sp<GrFragmentProcessor> fp, | 
| joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 147 | bool textureIsAlphaOnly, | 
|  | 148 | GrPaint* grPaint); | 
|  | 149 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 150 | //////////////////////////////////////////////////////////////////////////////// | 
|  | 151 | // Misc Sk to Gr type conversions | 
|  | 152 |  | 
|  | 153 | GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&); | 
|  | 154 | GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps); | 
|  | 155 |  | 
|  | 156 | bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*); | 
|  | 157 |  | 
|  | 158 | GrSamplerParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, | 
|  | 159 | const SkMatrix& viewM, | 
|  | 160 | const SkMatrix& localM, | 
|  | 161 | bool* doBicubic); | 
|  | 162 |  | 
| bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 163 | ////////////////////////////////////////////////////////////////////////////// | 
|  | 164 |  | 
| Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 165 | static inline GrPrimitiveType SkVertexModeToGrPrimitiveType(SkVertices::VertexMode mode) { | 
| Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 166 | switch (mode) { | 
| Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 167 | case SkVertices::kTriangles_VertexMode: | 
| Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 168 | return kTriangles_GrPrimitiveType; | 
| Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 169 | case SkVertices::kTriangleStrip_VertexMode: | 
| Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 170 | return kTriangleStrip_GrPrimitiveType; | 
| Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 171 | case SkVertices::kTriangleFan_VertexMode: | 
| Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 172 | return kTriangleFan_GrPrimitiveType; | 
|  | 173 | } | 
|  | 174 | SkFAIL("Invalid mode"); | 
|  | 175 | return kPoints_GrPrimitiveType; | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | ////////////////////////////////////////////////////////////////////////////// | 
|  | 179 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 180 | GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); | 
|  | 181 | GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); | 
|  | 182 | GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); | 
|  | 183 | GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); | 
|  | 184 | GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); | 
|  | 185 | GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); | 
|  | 186 | GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); | 
|  | 187 | GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); | 
|  | 188 | GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); | 
|  | 189 | GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff); | 
|  | 190 | GR_STATIC_ASSERT(SkXfermode::kCoeffCount == 10); | 
| Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 191 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 192 | #define SkXfermodeCoeffToGrBlendCoeff(X) ((GrBlendCoeff)(X)) | 
| Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 193 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 194 | //////////////////////////////////////////////////////////////////////////////// | 
|  | 195 | // Texture management | 
| Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 196 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 197 | /** Returns a texture representing the bitmap that is compatible with the GrSamplerParams. The | 
|  | 198 | *  texture is inserted into the cache (unless the bitmap is marked volatile) and can be | 
|  | 199 | *  retrieved again via this function. | 
|  | 200 | *  The 'scaleAdjust' in/out parameter will be updated to hold any rescaling that needs to be | 
|  | 201 | *  performed on the absolute texture coordinates (e.g., if the texture is resized out to | 
|  | 202 | *  the next power of two). It can be null if the caller is sure the bitmap won't be resized. | 
| bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 203 | */ | 
| Robert Phillips | bbd7a3b | 2017-03-21 08:48:40 -0400 | [diff] [blame] | 204 | sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext*, | 
|  | 205 | const SkBitmap&, | 
|  | 206 | const GrSamplerParams&, | 
|  | 207 | SkScalar scaleAdjust[2]); | 
|  | 208 |  | 
| bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 209 | /** | 
|  | 210 | * Creates a new texture for the bitmap. Does not concern itself with cache keys or texture params. | 
|  | 211 | * The bitmap must have CPU-accessible pixels. Attempts to take advantage of faster paths for | 
|  | 212 | * compressed textures and yuv planes. | 
|  | 213 | */ | 
| Matt Sarett | dedac85 | 2017-05-12 10:56:49 -0400 | [diff] [blame^] | 214 | sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrResourceProvider*, const SkBitmap&, | 
|  | 215 | SkColorSpace* dstColorSpace); | 
| Robert Phillips | d374948 | 2017-03-14 09:17:43 -0400 | [diff] [blame] | 216 |  | 
| Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 217 | sk_sp<GrTextureProxy> GrGenerateMipMapsAndUploadToTextureProxy(GrContext*, const SkBitmap&, | 
|  | 218 | SkColorSpace* dstColorSpace); | 
|  | 219 |  | 
| bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 220 | /** | 
|  | 221 | * Creates a new texture for the pixmap. | 
|  | 222 | */ | 
| Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 223 | sk_sp<GrTextureProxy> GrUploadPixmapToTextureProxy(GrResourceProvider*, | 
| Matt Sarett | dedac85 | 2017-05-12 10:56:49 -0400 | [diff] [blame^] | 224 | const SkPixmap&, SkBudgeted, SkColorSpace*); | 
| bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 225 |  | 
| cblume | 186d2d4 | 2016-06-03 11:17:42 -0700 | [diff] [blame] | 226 | /** | 
|  | 227 | * Creates a new texture populated with the mipmap levels. | 
|  | 228 | */ | 
| Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 229 | sk_sp<GrTextureProxy> GrUploadMipMapToTextureProxy(GrContext*, const SkImageInfo&, | 
|  | 230 | const GrMipLevel* texels, | 
|  | 231 | int mipLevelCount, | 
|  | 232 | SkDestinationSurfaceColorMode colorMode); | 
|  | 233 |  | 
| Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 234 | // This is intended to replace: | 
|  | 235 | //    SkAutoLockPixels alp(bitmap, true); | 
|  | 236 | //    if (!bitmap.readyToDraw()) { | 
|  | 237 | //        return nullptr; | 
|  | 238 | //    } | 
|  | 239 | //    sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap, | 
|  | 240 | //                                                         GrSamplerParams::ClampNoFilter(), | 
|  | 241 | //                                                         nullptr); | 
|  | 242 | //    if (!texture) { | 
|  | 243 | //        return nullptr; | 
|  | 244 | //    } | 
| Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 245 | sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider*, const SkBitmap& bitmap); | 
| Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 246 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 247 |  | 
|  | 248 | /** | 
|  | 249 | *  Our key includes the offset, width, and height so that bitmaps created by extractSubset() | 
|  | 250 | *  are unique. | 
|  | 251 | * | 
|  | 252 | *  The imageID is in the shared namespace (see SkNextID::ImageID()) | 
|  | 253 | *      - SkBitmap/SkPixelRef | 
|  | 254 | *      - SkImage | 
|  | 255 | *      - SkImageGenerator | 
|  | 256 | * | 
|  | 257 | *  Note: width/height must fit in 16bits for this impl. | 
|  | 258 | */ | 
|  | 259 | void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds); | 
|  | 260 |  | 
|  | 261 | /** Call this after installing a GrUniqueKey on texture. It will cause the texture's key to be | 
|  | 262 | removed should the bitmap's contents change or be destroyed. */ | 
|  | 263 | void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef); | 
|  | 264 |  | 
| bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 265 | ////////////////////////////////////////////////////////////////////////////// | 
|  | 266 |  | 
| Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 267 | /** When image filter code needs to construct a render target context to do intermediate rendering, | 
|  | 268 | we need a renderable pixel config. The source (SkSpecialImage) may not be in a renderable | 
|  | 269 | format, but we want to preserve the color space of that source. This picks an appropriate format | 
|  | 270 | to use. */ | 
|  | 271 | GrPixelConfig GrRenderableConfigForColorSpace(const SkColorSpace*); | 
| bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 272 |  | 
| reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 273 | #endif |