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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef SkGr_DEFINED |
| 9 | #define SkGr_DEFINED |
| 10 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 12 | #include "GrTextureAccess.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 13 | #include "SkColor.h" |
| 14 | #include "SkColorPriv.h" |
| 15 | #include "SkFilterQuality.h" |
| 16 | #include "SkImageInfo.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 18 | class GrCaps; |
Brian Osman | c68d4aa | 2016-09-30 11:41:59 -0400 | [diff] [blame] | 19 | class GrColorSpaceXform; |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 20 | class GrContext; |
| 21 | class GrTexture; |
| 22 | class GrTextureParams; |
| 23 | class SkBitmap; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | //////////////////////////////////////////////////////////////////////////////// |
| 26 | // Sk to Gr Type conversions |
| 27 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 28 | static inline GrColor SkColorToPremulGrColor(SkColor c) { |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 29 | SkPMColor pm = SkPreMultiplyColor(c); |
| 30 | unsigned r = SkGetPackedR32(pm); |
| 31 | unsigned g = SkGetPackedG32(pm); |
| 32 | unsigned b = SkGetPackedB32(pm); |
| 33 | unsigned a = SkGetPackedA32(pm); |
| 34 | return GrColorPackRGBA(r, g, b, a); |
| 35 | } |
| 36 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 37 | static inline GrColor SkColorToUnpremulGrColor(SkColor c) { |
| 38 | unsigned r = SkColorGetR(c); |
| 39 | unsigned g = SkColorGetG(c); |
| 40 | unsigned b = SkColorGetB(c); |
| 41 | unsigned a = SkColorGetA(c); |
| 42 | return GrColorPackRGBA(r, g, b, a); |
| 43 | } |
| 44 | |
Brian Osman | 72ae431 | 2016-10-20 16:53:45 -0400 | [diff] [blame] | 45 | /** Transform an SkColor (sRGB bytes) to GrColor4f for the specified color space. */ |
| 46 | GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace); |
| 47 | GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace); |
| 48 | |
| 49 | /** |
| 50 | * As above, but with explicit control over the linearization and gamut xform steps. |
| 51 | * Typically used when you have easy access to a pre-computed xform. |
| 52 | */ |
Brian Osman | c68d4aa | 2016-09-30 11:41:59 -0400 | [diff] [blame] | 53 | GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform); |
| 54 | GrColor4f SkColorToUnpremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform); |
| 55 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 56 | static inline GrColor SkColorToOpaqueGrColor(SkColor c) { |
| 57 | unsigned r = SkColorGetR(c); |
| 58 | unsigned g = SkColorGetG(c); |
| 59 | unsigned b = SkColorGetB(c); |
| 60 | return GrColorPackRGBA(r, g, b, 0xFF); |
| 61 | } |
| 62 | |
| 63 | /** Replicates the SkColor's alpha to all four channels of the GrColor. */ |
| 64 | static inline GrColor SkColorAlphaToGrColor(SkColor c) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 65 | U8CPU a = SkColorGetA(c); |
| 66 | return GrColorPackRGBA(a, a, a, a); |
| 67 | } |
| 68 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 69 | static inline SkPMColor GrColorToSkPMColor(GrColor c) { |
| 70 | GrColorIsPMAssert(c); |
| 71 | return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c), GrColorUnpackB(c)); |
| 72 | } |
| 73 | |
| 74 | static inline GrColor SkPMColorToGrColor(SkPMColor c) { |
| 75 | return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c), |
| 76 | SkGetPackedA32(c)); |
| 77 | } |
| 78 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 79 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 80 | /** Returns a texture representing the bitmap that is compatible with the GrTextureParams. The |
| 81 | texture is inserted into the cache (unless the bitmap is marked volatile) and can be |
| 82 | retrieved again via this function. */ |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 83 | GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&, |
| 84 | SkSourceGammaTreatment); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 85 | |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 86 | sk_sp<GrTexture> GrMakeCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&, |
| 87 | SkSourceGammaTreatment); |
| 88 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 89 | // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 90 | GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, const SkColorSpace*, |
| 91 | const GrCaps&); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 92 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 93 | static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 94 | return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.colorSpace(), caps); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, |
| 98 | const SkMatrix& viewM, |
| 99 | const SkMatrix& localM, |
| 100 | bool* doBicubic); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 101 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | #endif |