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; |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 19 | class GrContext; |
| 20 | class GrTexture; |
| 21 | class GrTextureParams; |
| 22 | class SkBitmap; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 23 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | //////////////////////////////////////////////////////////////////////////////// |
| 25 | // Sk to Gr Type conversions |
| 26 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 27 | static inline GrColor SkColorToPremulGrColor(SkColor c) { |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 28 | SkPMColor pm = SkPreMultiplyColor(c); |
| 29 | unsigned r = SkGetPackedR32(pm); |
| 30 | unsigned g = SkGetPackedG32(pm); |
| 31 | unsigned b = SkGetPackedB32(pm); |
| 32 | unsigned a = SkGetPackedA32(pm); |
| 33 | return GrColorPackRGBA(r, g, b, a); |
| 34 | } |
| 35 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 36 | static inline GrColor SkColorToUnpremulGrColor(SkColor c) { |
| 37 | unsigned r = SkColorGetR(c); |
| 38 | unsigned g = SkColorGetG(c); |
| 39 | unsigned b = SkColorGetB(c); |
| 40 | unsigned a = SkColorGetA(c); |
| 41 | return GrColorPackRGBA(r, g, b, a); |
| 42 | } |
| 43 | |
| 44 | static inline GrColor SkColorToOpaqueGrColor(SkColor c) { |
| 45 | unsigned r = SkColorGetR(c); |
| 46 | unsigned g = SkColorGetG(c); |
| 47 | unsigned b = SkColorGetB(c); |
| 48 | return GrColorPackRGBA(r, g, b, 0xFF); |
| 49 | } |
| 50 | |
| 51 | /** Replicates the SkColor's alpha to all four channels of the GrColor. */ |
| 52 | static inline GrColor SkColorAlphaToGrColor(SkColor c) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 53 | U8CPU a = SkColorGetA(c); |
| 54 | return GrColorPackRGBA(a, a, a, a); |
| 55 | } |
| 56 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 57 | static inline SkPMColor GrColorToSkPMColor(GrColor c) { |
| 58 | GrColorIsPMAssert(c); |
| 59 | return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c), GrColorUnpackB(c)); |
| 60 | } |
| 61 | |
| 62 | static inline GrColor SkPMColorToGrColor(SkPMColor c) { |
| 63 | return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c), |
| 64 | SkGetPackedA32(c)); |
| 65 | } |
| 66 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 67 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 68 | /** Returns a texture representing the bitmap that is compatible with the GrTextureParams. The |
| 69 | texture is inserted into the cache (unless the bitmap is marked volatile) and can be |
| 70 | retrieved again via this function. */ |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 71 | GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&, |
| 72 | SkSourceGammaTreatment); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 73 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 74 | // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). |
brianosman | ab82418 | 2016-06-16 11:41:44 -0700 | [diff] [blame] | 75 | GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType, const GrCaps&); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 76 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 77 | static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) { |
brianosman | ab82418 | 2016-06-16 11:41:44 -0700 | [diff] [blame] | 78 | return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType(), caps); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, |
| 82 | const SkMatrix& viewM, |
| 83 | const SkMatrix& localM, |
| 84 | bool* doBicubic); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 85 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 87 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 88 | SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque); |
| 89 | |
| 90 | // Using the dreaded SkGrPixelRef ... |
bsalomon | cb1ccfd | 2015-09-09 14:51:52 -0700 | [diff] [blame] | 91 | SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, |
| 92 | SkBitmap* dst); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 93 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | #endif |