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