epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef SkGr_DEFINED |
| 12 | #define SkGr_DEFINED |
| 13 | |
| 14 | #include <stddef.h> |
| 15 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 16 | // Gr headers |
bsalomon@google.com | 6a2134e | 2011-11-23 21:33:11 +0000 | [diff] [blame] | 17 | #include "GrTypes.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | #include "GrContext.h" |
| 19 | #include "GrFontScaler.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
| 21 | // skia headers |
| 22 | #include "SkBitmap.h" |
| 23 | #include "SkPath.h" |
| 24 | #include "SkPoint.h" |
| 25 | #include "SkRegion.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 26 | #include "SkClipStack.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | //////////////////////////////////////////////////////////////////////////////// |
| 29 | // Sk to Gr Type conversions |
| 30 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 31 | GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); |
| 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); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 42 | #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X)) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | #include "SkColorPriv.h" |
| 47 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 48 | /** |
| 49 | * Convert the SkBitmap::Config to the corresponding PixelConfig, or |
| 50 | * kUnknown_PixelConfig if the conversion cannot be done. |
| 51 | */ |
| 52 | GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 53 | GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType); |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 54 | |
| 55 | static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) { |
| 56 | return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType()); |
| 57 | } |
| 58 | |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 59 | bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 61 | static inline GrColor SkColor2GrColor(SkColor c) { |
| 62 | SkPMColor pm = SkPreMultiplyColor(c); |
| 63 | unsigned r = SkGetPackedR32(pm); |
| 64 | unsigned g = SkGetPackedG32(pm); |
| 65 | unsigned b = SkGetPackedB32(pm); |
| 66 | unsigned a = SkGetPackedA32(pm); |
| 67 | return GrColorPackRGBA(r, g, b, a); |
| 68 | } |
| 69 | |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame^] | 70 | static inline GrColor SkColor2GrColorJustAlpha(SkColor c) { |
| 71 | U8CPU a = SkColorGetA(c); |
| 72 | return GrColorPackRGBA(a, a, a, a); |
| 73 | } |
| 74 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 75 | //////////////////////////////////////////////////////////////////////////////// |
| 76 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 77 | bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*); |
| 78 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 79 | GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 81 | void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | |
| 83 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 84 | |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 85 | // Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader. |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame^] | 86 | // Sets the color of GrPaint to the value of the parameter grColor |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 87 | // Callers may subsequently modify the GrPaint. Setting constantColor indicates |
| 88 | // that the final paint will draw the same color at every pixel. This allows |
| 89 | // an optimization where the the color filter can be applied to the SkPaint's |
| 90 | // color once while converting to GrPaint and then ignored. |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame^] | 91 | void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor grColor, |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 92 | bool constantColor, GrPaint* grPaint); |
| 93 | |
| 94 | // This function is similar to skPaint2GrPaintNoShader but also converts |
| 95 | // skPaint's shader to a GrTexture/GrEffectStage if possible. |
| 96 | // constantColor has the same meaning as in skPaint2GrPaintNoShader. |
commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 97 | void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 98 | bool constantColor, GrPaint* grPaint); |
| 99 | |
| 100 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 101 | // Classes |
| 102 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | class SkGlyphCache; |
| 104 | |
| 105 | class SkGrFontScaler : public GrFontScaler { |
| 106 | public: |
| 107 | explicit SkGrFontScaler(SkGlyphCache* strike); |
| 108 | virtual ~SkGrFontScaler(); |
| 109 | |
| 110 | // overrides |
| 111 | virtual const GrKey* getKey(); |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 112 | virtual GrMaskFormat getMaskFormat(); |
commit-bot@chromium.org | 762cd80 | 2014-04-14 22:05:07 +0000 | [diff] [blame] | 113 | virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, |
commit-bot@chromium.org | 762cd80 | 2014-04-14 22:05:07 +0000 | [diff] [blame] | 115 | int rowBytes, void* image) SK_OVERRIDE; |
| 116 | virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE; |
| 117 | virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, |
| 118 | void* image) SK_OVERRIDE; |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 119 | virtual bool getGlyphPath(uint16_t glyphID, SkPath*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 120 | |
| 121 | private: |
| 122 | SkGlyphCache* fStrike; |
| 123 | GrKey* fKey; |
| 124 | // DECLARE_INSTANCE_COUNTER(SkGrFontScaler); |
| 125 | }; |
| 126 | |
| 127 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 128 | |
| 129 | #endif |