1 2 /* 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. 7 */ 8 9 10 11 #ifndef SkGr_DEFINED 12 #define SkGr_DEFINED 13 14 #include <stddef.h> 15 16 // Gr headers 17 #include "GrTypes.h" 18 #include "GrContext.h" 19 #include "GrFontScaler.h" 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 28 #if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG)) 29 // #error "inconsistent GR_DEBUG and SK_DEBUG" 30 #endif 31 32 //////////////////////////////////////////////////////////////////////////////// 33 // Sk to Gr Type conversions 34 35 GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); 36 GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); 37 GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); 38 GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); 39 GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); 40 GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); 41 GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); 42 GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); 43 GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); 44 GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff); 45 46 #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X)) 47 48 /////////////////////////////////////////////////////////////////////////////// 49 50 #include "SkColorPriv.h" 51 52 /** 53 * Convert the SkBitmap::Config to the corresponding PixelConfig, or 54 * kUnknown_PixelConfig if the conversion cannot be done. 55 */ 56 GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config); 57 58 static inline GrColor SkColor2GrColor(SkColor c) { 59 SkPMColor pm = SkPreMultiplyColor(c); 60 unsigned r = SkGetPackedR32(pm); 61 unsigned g = SkGetPackedG32(pm); 62 unsigned b = SkGetPackedB32(pm); 63 unsigned a = SkGetPackedA32(pm); 64 return GrColorPackRGBA(r, g, b, a); 65 } 66 67 //////////////////////////////////////////////////////////////////////////////// 68 69 bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*); 70 71 GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); 72 73 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*); 74 75 //////////////////////////////////////////////////////////////////////////////// 76 // Classes 77 78 class SkGlyphCache; 79 80 class SkGrFontScaler : public GrFontScaler { 81 public: 82 explicit SkGrFontScaler(SkGlyphCache* strike); 83 virtual ~SkGrFontScaler(); 84 85 // overrides 86 virtual const GrKey* getKey(); 87 virtual GrMaskFormat getMaskFormat(); 88 virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); 89 virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, 90 int rowBytes, void* image); 91 virtual bool getGlyphPath(uint16_t glyphID, SkPath*); 92 93 private: 94 SkGlyphCache* fStrike; 95 GrKey* fKey; 96 // DECLARE_INSTANCE_COUNTER(SkGrFontScaler); 97 }; 98 99 //////////////////////////////////////////////////////////////////////////////// 100 101 #endif 102