blob: cf37f472188cf999ff1d165e1570aa973652090b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef SkGr_DEFINED
12#define SkGr_DEFINED
13
14#include <stddef.h>
15
bsalomon@google.comd302f142011-03-03 13:54:13 +000016// Gr headers
bsalomon@google.com6a2134e2011-11-23 21:33:11 +000017#include "GrTypes.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018#include "GrContext.h"
19#include "GrFontScaler.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
21// skia headers
22#include "SkBitmap.h"
23#include "SkPath.h"
24#include "SkPoint.h"
25#include "SkRegion.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000026#include "SkClipStack.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000027
28#if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
29// #error "inconsistent GR_DEBUG and SK_DEBUG"
30#endif
31
reed@google.comac10a2d2010-12-22 21:39:39 +000032////////////////////////////////////////////////////////////////////////////////
33// Sk to Gr Type conversions
34
bsalomon@google.com47059542012-06-06 20:51:20 +000035GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
36GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff);
37GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff);
38GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff);
39GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff);
40GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff);
41GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff);
42GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff);
43GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff);
44GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff);
reed@google.comac10a2d2010-12-22 21:39:39 +000045
bsalomon@google.comffca4002011-02-22 20:34:01 +000046#define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000047
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000048GR_STATIC_ASSERT((int)SkPath::kMove_Verb == (int)kMove_PathCmd);
49GR_STATIC_ASSERT((int)SkPath::kLine_Verb == (int)kLine_PathCmd);
50GR_STATIC_ASSERT((int)SkPath::kQuad_Verb == (int)kQuadratic_PathCmd);
51GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)kCubic_PathCmd);
52GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)kClose_PathCmd);
53GR_STATIC_ASSERT((int)SkPath::kDone_Verb == (int)kEnd_PathCmd);
reed@google.comac10a2d2010-12-22 21:39:39 +000054
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000055#define sk_path_verb_to_gr_path_command(X) ((GrPathCmd)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000056
57///////////////////////////////////////////////////////////////////////////////
58
59#include "SkColorPriv.h"
60
rileya@google.com24f3ad12012-07-18 21:47:40 +000061/**
62 * Convert the SkBitmap::Config to the corresponding PixelConfig, or
63 * kUnknown_PixelConfig if the conversion cannot be done.
64 */
65GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
reed@google.comac10a2d2010-12-22 21:39:39 +000066
rileya@google.com24f3ad12012-07-18 21:47:40 +000067static inline GrColor SkColor2GrColor(SkColor c) {
68 SkPMColor pm = SkPreMultiplyColor(c);
69 unsigned r = SkGetPackedR32(pm);
70 unsigned g = SkGetPackedG32(pm);
71 unsigned b = SkGetPackedB32(pm);
72 unsigned a = SkGetPackedA32(pm);
73 return GrColorPackRGBA(r, g, b, a);
74}
75
76////////////////////////////////////////////////////////////////////////////////
77
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000078bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
79
bsalomon@google.com95ed55a2013-01-24 14:46:47 +000080GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
rileya@google.com24f3ad12012-07-18 21:47:40 +000081
bsalomon@google.com95ed55a2013-01-24 14:46:47 +000082void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
reed@google.comac10a2d2010-12-22 21:39:39 +000083
84////////////////////////////////////////////////////////////////////////////////
85// Classes
86
reed@google.comac10a2d2010-12-22 21:39:39 +000087class SkGlyphCache;
88
89class SkGrFontScaler : public GrFontScaler {
90public:
91 explicit SkGrFontScaler(SkGlyphCache* strike);
92 virtual ~SkGrFontScaler();
93
94 // overrides
95 virtual const GrKey* getKey();
reed@google.com98539c62011-03-15 15:40:16 +000096 virtual GrMaskFormat getMaskFormat();
reed@google.comac10a2d2010-12-22 21:39:39 +000097 virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds);
98 virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
99 int rowBytes, void* image);
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000100 virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
reed@google.comac10a2d2010-12-22 21:39:39 +0000101
102private:
103 SkGlyphCache* fStrike;
104 GrKey* fKey;
105// DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
106};
107
108////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000109
110#endif