blob: 975a1bad44662ee884726530830f25ec974bbcc9 [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#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 "SkShader.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000028#include "SkClipStack.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000029
30#if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
31// #error "inconsistent GR_DEBUG and SK_DEBUG"
32#endif
33
reed@google.comac10a2d2010-12-22 21:39:39 +000034////////////////////////////////////////////////////////////////////////////////
35// Sk to Gr Type conversions
36
reed@google.comac10a2d2010-12-22 21:39:39 +000037GR_STATIC_ASSERT((int)GrSamplerState::kClamp_WrapMode == (int)SkShader::kClamp_TileMode);
38GR_STATIC_ASSERT((int)GrSamplerState::kRepeat_WrapMode ==(
39 int)SkShader::kRepeat_TileMode);
bsalomon@google.com5782d712011-01-21 21:03:59 +000040GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode ==
reed@google.comac10a2d2010-12-22 21:39:39 +000041 (int)SkShader::kMirror_TileMode);
42
43#define sk_tile_mode_to_grwrap(X) ((GrSamplerState::WrapMode)(X))
44
bsalomon@google.com47059542012-06-06 20:51:20 +000045GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
46GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff);
47GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff);
48GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff);
49GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff);
50GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff);
51GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff);
52GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff);
53GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff);
54GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff);
reed@google.comac10a2d2010-12-22 21:39:39 +000055
bsalomon@google.comffca4002011-02-22 20:34:01 +000056#define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000057
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000058GR_STATIC_ASSERT((int)SkPath::kMove_Verb == (int)kMove_PathCmd);
59GR_STATIC_ASSERT((int)SkPath::kLine_Verb == (int)kLine_PathCmd);
60GR_STATIC_ASSERT((int)SkPath::kQuad_Verb == (int)kQuadratic_PathCmd);
61GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)kCubic_PathCmd);
62GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)kClose_PathCmd);
63GR_STATIC_ASSERT((int)SkPath::kDone_Verb == (int)kEnd_PathCmd);
reed@google.comac10a2d2010-12-22 21:39:39 +000064
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000065#define sk_path_verb_to_gr_path_command(X) ((GrPathCmd)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000066
67///////////////////////////////////////////////////////////////////////////////
68
69#include "SkColorPriv.h"
70
rileya@google.com24f3ad12012-07-18 21:47:40 +000071/**
72 * Convert the SkBitmap::Config to the corresponding PixelConfig, or
73 * kUnknown_PixelConfig if the conversion cannot be done.
74 */
75GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
reed@google.comac10a2d2010-12-22 21:39:39 +000076
rileya@google.com24f3ad12012-07-18 21:47:40 +000077static inline GrColor SkColor2GrColor(SkColor c) {
78 SkPMColor pm = SkPreMultiplyColor(c);
79 unsigned r = SkGetPackedR32(pm);
80 unsigned g = SkGetPackedG32(pm);
81 unsigned b = SkGetPackedB32(pm);
82 unsigned a = SkGetPackedA32(pm);
83 return GrColorPackRGBA(r, g, b, a);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87
88GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx,
89 const SkBitmap& bitmap,
90 const GrSamplerState* sampler);
91
92void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache);
reed@google.comac10a2d2010-12-22 21:39:39 +000093
94////////////////////////////////////////////////////////////////////////////////
95// Classes
96
reed@google.comac10a2d2010-12-22 21:39:39 +000097class SkGrClipIterator : public GrClipIterator {
98public:
bsalomon@google.comd302f142011-03-03 13:54:13 +000099 SkGrClipIterator() { fClipStack = NULL; fCurr = NULL; }
100 SkGrClipIterator(const SkClipStack& clipStack) { this->reset(clipStack); }
101
102 void reset(const SkClipStack& clipStack);
103
104 // overrides
robertphillips@google.comfa1d2912012-04-16 14:49:14 +0000105 virtual bool isDone() const SK_OVERRIDE { return NULL == fCurr; }
106 virtual void next() SK_OVERRIDE { fCurr = fIter.next(); }
107 virtual void rewind() SK_OVERRIDE { this->reset(*fClipStack); }
108 virtual GrClipType getType() const SK_OVERRIDE;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000109
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000110 virtual SkRegion::Op getOp() const SK_OVERRIDE;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000111
robertphillips@google.comfa1d2912012-04-16 14:49:14 +0000112 virtual bool getDoAA() const SK_OVERRIDE;
113
114 virtual void getRect(GrRect* rect) const SK_OVERRIDE {
scroggo7b118072011-03-23 15:04:26 +0000115 if (!fCurr->fRect) {
116 rect->setEmpty();
117 } else {
reed@google.com20efde72011-05-09 17:00:02 +0000118 *rect = *fCurr->fRect;
scroggo7b118072011-03-23 15:04:26 +0000119 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000120 }
121
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000122 virtual const SkPath* getPath() SK_OVERRIDE {
reed@google.com07f3ee12011-05-16 17:21:57 +0000123 return fCurr->fPath;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000124 }
125
robertphillips@google.comfa1d2912012-04-16 14:49:14 +0000126 virtual GrPathFill getPathFill() const SK_OVERRIDE;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000127
128private:
129 const SkClipStack* fClipStack;
130 SkClipStack::B2FIter fIter;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000131 // SkClipStack's auto advances on each get
132 // so we store the current pos here.
133 const SkClipStack::B2FIter::Clip* fCurr;
134};
135
reed@google.comac10a2d2010-12-22 21:39:39 +0000136class SkGlyphCache;
137
138class SkGrFontScaler : public GrFontScaler {
139public:
140 explicit SkGrFontScaler(SkGlyphCache* strike);
141 virtual ~SkGrFontScaler();
142
143 // overrides
144 virtual const GrKey* getKey();
reed@google.com98539c62011-03-15 15:40:16 +0000145 virtual GrMaskFormat getMaskFormat();
reed@google.comac10a2d2010-12-22 21:39:39 +0000146 virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds);
147 virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
148 int rowBytes, void* image);
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000149 virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
reed@google.comac10a2d2010-12-22 21:39:39 +0000150
151private:
152 SkGlyphCache* fStrike;
153 GrKey* fKey;
154// DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
155};
156
157////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000158
159#endif