OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | |
10 | |
11 #ifndef SkGr_DEFINED | 8 #ifndef SkGr_DEFINED |
12 #define SkGr_DEFINED | 9 #define SkGr_DEFINED |
13 | 10 |
14 #include <stddef.h> | 11 #include "GrColor.h" |
| 12 #include "GrTextureAccess.h" |
| 13 #include "SkColor.h" |
| 14 #include "SkColorPriv.h" |
| 15 #include "SkFilterQuality.h" |
| 16 #include "SkImageInfo.h" |
15 | 17 |
16 // Gr headers | 18 class GrContext; |
17 #include "GrContext.h" | 19 class GrTexture; |
18 #include "GrTextureAccess.h" | 20 class GrTextureParams; |
19 #include "GrTypes.h" | 21 class SkBitmap; |
20 | |
21 // skia headers | |
22 #include "SkBitmap.h" | |
23 #include "SkPath.h" | |
24 #include "SkPoint.h" | |
25 #include "SkRegion.h" | |
26 #include "SkClipStack.h" | |
27 | 22 |
28 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
29 // Sk to Gr Type conversions | 24 // Sk to Gr Type conversions |
30 | 25 |
31 GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); | 26 static inline GrColor SkColorToPremulGrColor(SkColor c) { |
32 GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); | |
33 GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); | |
34 GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); | |
35 GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); | |
36 GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); | |
37 GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); | |
38 GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); | |
39 GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); | |
40 GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff); | |
41 GR_STATIC_ASSERT(SkXfermode::kCoeffCount == 10); | |
42 | |
43 #define SkXfermodeCoeffToGrBlendCoeff(X) ((GrBlendCoeff)(X)) | |
44 | |
45 /////////////////////////////////////////////////////////////////////////////// | |
46 | |
47 #include "SkColorPriv.h" | |
48 | |
49 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfile
Type); | |
50 | |
51 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) { | |
52 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.pr
ofileType()); | |
53 } | |
54 | |
55 bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfi
leType*); | |
56 | |
57 static inline GrColor SkColor2GrColor(SkColor c) { | |
58 SkPMColor pm = SkPreMultiplyColor(c); | 27 SkPMColor pm = SkPreMultiplyColor(c); |
59 unsigned r = SkGetPackedR32(pm); | 28 unsigned r = SkGetPackedR32(pm); |
60 unsigned g = SkGetPackedG32(pm); | 29 unsigned g = SkGetPackedG32(pm); |
61 unsigned b = SkGetPackedB32(pm); | 30 unsigned b = SkGetPackedB32(pm); |
62 unsigned a = SkGetPackedA32(pm); | 31 unsigned a = SkGetPackedA32(pm); |
63 return GrColorPackRGBA(r, g, b, a); | 32 return GrColorPackRGBA(r, g, b, a); |
64 } | 33 } |
65 | 34 |
66 static inline GrColor SkColor2GrColorJustAlpha(SkColor c) { | 35 static inline GrColor SkColorToUnpremulGrColor(SkColor c) { |
| 36 unsigned r = SkColorGetR(c); |
| 37 unsigned g = SkColorGetG(c); |
| 38 unsigned b = SkColorGetB(c); |
| 39 unsigned a = SkColorGetA(c); |
| 40 return GrColorPackRGBA(r, g, b, a); |
| 41 } |
| 42 |
| 43 static inline GrColor SkColorToOpaqueGrColor(SkColor c) { |
| 44 unsigned r = SkColorGetR(c); |
| 45 unsigned g = SkColorGetG(c); |
| 46 unsigned b = SkColorGetB(c); |
| 47 return GrColorPackRGBA(r, g, b, 0xFF); |
| 48 } |
| 49 |
| 50 /** Replicates the SkColor's alpha to all four channels of the GrColor. */ |
| 51 static inline GrColor SkColorAlphaToGrColor(SkColor c) { |
67 U8CPU a = SkColorGetA(c); | 52 U8CPU a = SkColorGetA(c); |
68 return GrColorPackRGBA(a, a, a, a); | 53 return GrColorPackRGBA(a, a, a, a); |
69 } | 54 } |
70 | 55 |
71 static inline SkPMColor GrColorToSkPMColor(GrColor c) { | 56 static inline SkPMColor GrColorToSkPMColor(GrColor c) { |
72 GrColorIsPMAssert(c); | 57 GrColorIsPMAssert(c); |
73 return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c),
GrColorUnpackB(c)); | 58 return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c),
GrColorUnpackB(c)); |
74 } | 59 } |
75 | 60 |
76 static inline GrColor SkPMColorToGrColor(SkPMColor c) { | 61 static inline GrColor SkPMColorToGrColor(SkPMColor c) { |
77 return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(
c), | 62 return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(
c), |
78 SkGetPackedA32(c)); | 63 SkGetPackedA32(c)); |
79 } | 64 } |
80 | 65 |
81 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&); | |
82 | |
83 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
84 | 67 |
85 /** | 68 GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTexture
Params&); |
86 * If the compressed data in the SkData is supported (as a texture format, this
returns | |
87 * the pixel-config that should be used, and sets outStartOfDataToUpload to the
ptr into | |
88 * the data where the actual raw data starts (skipping any header bytes). | |
89 * | |
90 * If the compressed data is not supported, this returns kUnknown_GrPixelConfig
, and | |
91 * ignores outStartOfDataToUpload. | |
92 */ | |
93 GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, | |
94 int expectedW, int expectedH, | |
95 const void** outStartOfDataToUp
load); | |
96 | 69 |
97 // Helper that calls GrIsImageInCache assuming bitmap is not volatile. | 70 // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWin
dow its subclasses). |
98 bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*
); | 71 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfile
Type); |
99 bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& sub
set, | |
100 GrTexture* nativeTexture, const GrTextureParams*); | |
101 | 72 |
102 GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTexture
Params*); | 73 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) { |
103 GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, SkImageUsageTyp
e); | 74 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.pr
ofileType()); |
104 | 75 } |
105 GrTexture* GrCreateTextureForPixels(GrContext*, const GrUniqueKey& optionalKey,
GrSurfaceDesc, | |
106 SkPixelRef* pixelRefForInvalidationNotificat
ionOrNull, | |
107 const void* pixels, size_t rowBytesOrZero); | |
108 | |
109 //////////////////////////////////////////////////////////////////////////////// | |
110 | |
111 // Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader. | |
112 // Sets the color of GrPaint to the value of the parameter paintColor | |
113 // Callers may subsequently modify the GrPaint. Setting constantColor indicates | |
114 // that the final paint will draw the same color at every pixel. This allows | |
115 // an optimization where the color filter can be applied to the SkPaint's | |
116 // color once while converting to GrPaint and then ignored. TODO: Remove this | |
117 // bool and use the invariant info to automatically apply the color filter. | |
118 bool SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, | |
119 bool constantColor, GrPaint* grPaint); | |
120 | |
121 // This function is similar to skPaint2GrPaintNoShader but also converts | |
122 // skPaint's shader to a GrFragmentProcessor if possible. | |
123 // constantColor has the same meaning as in skPaint2GrPaintNoShader. | |
124 bool SkPaint2GrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix&
viewM, | |
125 bool constantColor, GrPaint* grPaint); | |
126 | |
127 | |
128 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque); | |
129 | |
130 // Using the dreaded SkGrPixelRef ... | |
131 SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, | |
132 SkBitmap* dst); | |
133 | 76 |
134 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain
tFilterQuality, | 77 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain
tFilterQuality, |
135 const SkMatrix& view
M, | 78 const SkMatrix& view
M, |
136 const SkMatrix& loca
lM, | 79 const SkMatrix& loca
lM, |
137 bool* doBicubic); | 80 bool* doBicubic); |
138 | 81 |
139 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
140 // Classes | |
141 | 83 |
142 class SkGlyphCache; | 84 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque); |
143 | 85 |
144 //////////////////////////////////////////////////////////////////////////////// | 86 // Using the dreaded SkGrPixelRef ... |
| 87 SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, |
| 88 SkBitmap* dst); |
145 | 89 |
146 #endif | 90 #endif |
OLD | NEW |