SkGr.h revision b8670998a59d305cd22a3c0cbdc6e075b0a37a6e
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#include "GrClipIterator.h"
21
22// skia headers
23#include "SkBitmap.h"
24#include "SkPath.h"
25#include "SkPoint.h"
26#include "SkRegion.h"
27#include "SkClipStack.h"
28
29#if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
30//    #error "inconsistent GR_DEBUG and SK_DEBUG"
31#endif
32
33////////////////////////////////////////////////////////////////////////////////
34// Sk to Gr Type conversions
35
36GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
37GR_STATIC_ASSERT((int)kOne_GrBlendCoeff  == (int)SkXfermode::kOne_Coeff);
38GR_STATIC_ASSERT((int)kSC_GrBlendCoeff   == (int)SkXfermode::kSC_Coeff);
39GR_STATIC_ASSERT((int)kISC_GrBlendCoeff  == (int)SkXfermode::kISC_Coeff);
40GR_STATIC_ASSERT((int)kDC_GrBlendCoeff   == (int)SkXfermode::kDC_Coeff);
41GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff  == (int)SkXfermode::kIDC_Coeff);
42GR_STATIC_ASSERT((int)kSA_GrBlendCoeff   == (int)SkXfermode::kSA_Coeff);
43GR_STATIC_ASSERT((int)kISA_GrBlendCoeff  == (int)SkXfermode::kISA_Coeff);
44GR_STATIC_ASSERT((int)kDA_GrBlendCoeff   == (int)SkXfermode::kDA_Coeff);
45GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff  == (int)SkXfermode::kIDA_Coeff);
46
47#define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
48
49GR_STATIC_ASSERT((int)SkPath::kMove_Verb  == (int)kMove_PathCmd);
50GR_STATIC_ASSERT((int)SkPath::kLine_Verb  == (int)kLine_PathCmd);
51GR_STATIC_ASSERT((int)SkPath::kQuad_Verb  == (int)kQuadratic_PathCmd);
52GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)kCubic_PathCmd);
53GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)kClose_PathCmd);
54GR_STATIC_ASSERT((int)SkPath::kDone_Verb  == (int)kEnd_PathCmd);
55
56#define sk_path_verb_to_gr_path_command(X) ((GrPathCmd)(X))
57
58///////////////////////////////////////////////////////////////////////////////
59
60#include "SkColorPriv.h"
61
62/**
63 *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
64 *  kUnknown_PixelConfig if the conversion cannot be done.
65 */
66GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
67
68static inline GrColor SkColor2GrColor(SkColor c) {
69    SkPMColor pm = SkPreMultiplyColor(c);
70    unsigned r = SkGetPackedR32(pm);
71    unsigned g = SkGetPackedG32(pm);
72    unsigned b = SkGetPackedB32(pm);
73    unsigned a = SkGetPackedA32(pm);
74    return GrColorPackRGBA(r, g, b, a);
75}
76
77////////////////////////////////////////////////////////////////////////////////
78
79GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext*,
80                                                       const SkBitmap&,
81                                                       const GrTextureParams*);
82
83void GrUnlockCachedBitmapTexture(GrContext*, GrContext::TextureCacheEntry);
84
85////////////////////////////////////////////////////////////////////////////////
86// Classes
87
88class SkGrClipIterator : public GrClipIterator {
89public:
90    SkGrClipIterator() { fClipStack = NULL;  fCurr = NULL; }
91    SkGrClipIterator(const SkClipStack& clipStack) { this->reset(clipStack); }
92
93    void reset(const SkClipStack& clipStack);
94
95    // overrides
96    virtual bool isDone() const SK_OVERRIDE { return NULL == fCurr; }
97    virtual void next() SK_OVERRIDE { fCurr = fIter.next(); }
98    virtual void rewind() SK_OVERRIDE { this->reset(*fClipStack); }
99    virtual GrClipType getType() const SK_OVERRIDE;
100
101    virtual SkRegion::Op getOp() const SK_OVERRIDE;
102
103    virtual bool getDoAA() const SK_OVERRIDE;
104
105    virtual void getRect(GrRect* rect) const SK_OVERRIDE {
106        if (!fCurr->fRect) {
107            rect->setEmpty();
108        } else {
109            *rect = *fCurr->fRect;
110        }
111    }
112
113    virtual const SkPath* getPath() SK_OVERRIDE {
114        return fCurr->fPath;
115    }
116
117    virtual GrPathFill getPathFill() const SK_OVERRIDE;
118
119private:
120    const SkClipStack*                  fClipStack;
121    SkClipStack::B2TIter                fIter;
122    // SkClipStack's auto advances on each get
123    // so we store the current pos here.
124    const SkClipStack::B2TIter::Clip*   fCurr;
125};
126
127class SkGlyphCache;
128
129class SkGrFontScaler : public GrFontScaler {
130public:
131    explicit SkGrFontScaler(SkGlyphCache* strike);
132    virtual ~SkGrFontScaler();
133
134    // overrides
135    virtual const GrKey* getKey();
136    virtual GrMaskFormat getMaskFormat();
137    virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds);
138    virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
139                                     int rowBytes, void* image);
140    virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
141
142private:
143    SkGlyphCache* fStrike;
144    GrKey*  fKey;
145//    DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
146};
147
148////////////////////////////////////////////////////////////////////////////////
149
150#endif
151