| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef SkGr_DEFINED |
| 12 | #define SkGr_DEFINED |
| 13 | |
| 14 | #include <stddef.h> |
| 15 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 16 | // Gr headers |
| bsalomon@google.com | 6a2134e | 2011-11-23 21:33:11 +0000 | [diff] [blame] | 17 | #include "GrTypes.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | #include "GrContext.h" |
| 19 | #include "GrFontScaler.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | #include "GrClipIterator.h" |
| reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 21 | #include "GrPath.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
| 23 | // skia headers |
| 24 | #include "SkBitmap.h" |
| 25 | #include "SkPath.h" |
| 26 | #include "SkPoint.h" |
| 27 | #include "SkRegion.h" |
| 28 | #include "SkShader.h" |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 29 | #include "SkClipStack.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | |
| 31 | #if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG)) |
| 32 | // #error "inconsistent GR_DEBUG and SK_DEBUG" |
| 33 | #endif |
| 34 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | // Sk to Gr Type conversions |
| 37 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | GR_STATIC_ASSERT((int)GrSamplerState::kClamp_WrapMode == (int)SkShader::kClamp_TileMode); |
| 39 | GR_STATIC_ASSERT((int)GrSamplerState::kRepeat_WrapMode ==( |
| 40 | int)SkShader::kRepeat_TileMode); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 41 | GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode == |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | (int)SkShader::kMirror_TileMode); |
| 43 | |
| 44 | #define sk_tile_mode_to_grwrap(X) ((GrSamplerState::WrapMode)(X)) |
| 45 | |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 46 | GR_STATIC_ASSERT((int)kZero_BlendCoeff == (int)SkXfermode::kZero_Coeff); |
| 47 | GR_STATIC_ASSERT((int)kOne_BlendCoeff == (int)SkXfermode::kOne_Coeff); |
| 48 | GR_STATIC_ASSERT((int)kSC_BlendCoeff == (int)SkXfermode::kSC_Coeff); |
| 49 | GR_STATIC_ASSERT((int)kISC_BlendCoeff == (int)SkXfermode::kISC_Coeff); |
| 50 | GR_STATIC_ASSERT((int)kDC_BlendCoeff == (int)SkXfermode::kDC_Coeff); |
| 51 | GR_STATIC_ASSERT((int)kIDC_BlendCoeff == (int)SkXfermode::kIDC_Coeff); |
| 52 | GR_STATIC_ASSERT((int)kSA_BlendCoeff == (int)SkXfermode::kSA_Coeff); |
| 53 | GR_STATIC_ASSERT((int)kISA_BlendCoeff == (int)SkXfermode::kISA_Coeff); |
| 54 | GR_STATIC_ASSERT((int)kDA_BlendCoeff == (int)SkXfermode::kDA_Coeff); |
| 55 | GR_STATIC_ASSERT((int)kIDA_BlendCoeff == (int)SkXfermode::kIDA_Coeff); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 57 | #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X)) |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 59 | GR_STATIC_ASSERT((int)SkPath::kMove_Verb == (int)kMove_PathCmd); |
| 60 | GR_STATIC_ASSERT((int)SkPath::kLine_Verb == (int)kLine_PathCmd); |
| 61 | GR_STATIC_ASSERT((int)SkPath::kQuad_Verb == (int)kQuadratic_PathCmd); |
| 62 | GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)kCubic_PathCmd); |
| 63 | GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)kClose_PathCmd); |
| 64 | GR_STATIC_ASSERT((int)SkPath::kDone_Verb == (int)kEnd_PathCmd); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 66 | #define sk_path_verb_to_gr_path_command(X) ((GrPathCmd)(X)) |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 67 | |
| 68 | /////////////////////////////////////////////////////////////////////////////// |
| 69 | |
| 70 | #include "SkColorPriv.h" |
| 71 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | class SkGr { |
| 73 | public: |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Convert the SkBitmap::Config to the corresponding PixelConfig, or |
| 76 | * kUnknown_PixelConfig if the conversion cannot be done. |
| 77 | */ |
| bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 78 | static GrPixelConfig BitmapConfig2PixelConfig(SkBitmap::Config, |
| 79 | bool isOpaque); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | |
| bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 81 | static GrPixelConfig Bitmap2PixelConfig(const SkBitmap& bm) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | return BitmapConfig2PixelConfig(bm.config(), bm.isOpaque()); |
| 83 | } |
| 84 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | static GrColor SkColor2GrColor(SkColor c) { |
| 86 | SkPMColor pm = SkPreMultiplyColor(c); |
| 87 | unsigned r = SkGetPackedR32(pm); |
| 88 | unsigned g = SkGetPackedG32(pm); |
| 89 | unsigned b = SkGetPackedB32(pm); |
| 90 | unsigned a = SkGetPackedA32(pm); |
| 91 | return GrColorPackRGBA(r, g, b, a); |
| 92 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | //////////////////////////////////////////////////////////////////////////////// |
| 96 | // Classes |
| 97 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | class SkGrClipIterator : public GrClipIterator { |
| 99 | public: |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 100 | SkGrClipIterator() { fClipStack = NULL; fCurr = NULL; } |
| 101 | SkGrClipIterator(const SkClipStack& clipStack) { this->reset(clipStack); } |
| 102 | |
| 103 | void reset(const SkClipStack& clipStack); |
| 104 | |
| 105 | // overrides |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 106 | virtual bool isDone() const SK_OVERRIDE { return NULL == fCurr; } |
| 107 | virtual void next() SK_OVERRIDE { fCurr = fIter.next(); } |
| 108 | virtual void rewind() SK_OVERRIDE { this->reset(*fClipStack); } |
| 109 | virtual GrClipType getType() const SK_OVERRIDE; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 110 | |
| robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame^] | 111 | virtual SkRegion::Op getOp() const SK_OVERRIDE; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 112 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 113 | virtual bool getDoAA() const SK_OVERRIDE; |
| 114 | |
| 115 | virtual void getRect(GrRect* rect) const SK_OVERRIDE { |
| scroggo | 7b11807 | 2011-03-23 15:04:26 +0000 | [diff] [blame] | 116 | if (!fCurr->fRect) { |
| 117 | rect->setEmpty(); |
| 118 | } else { |
| reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 119 | *rect = *fCurr->fRect; |
| scroggo | 7b11807 | 2011-03-23 15:04:26 +0000 | [diff] [blame] | 120 | } |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 123 | virtual const GrPath* getPath() SK_OVERRIDE { |
| reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 124 | return fCurr->fPath; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 127 | virtual GrPathFill getPathFill() const SK_OVERRIDE; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 128 | |
| 129 | private: |
| 130 | const SkClipStack* fClipStack; |
| 131 | SkClipStack::B2FIter fIter; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 132 | // SkClipStack's auto advances on each get |
| 133 | // so we store the current pos here. |
| 134 | const SkClipStack::B2FIter::Clip* fCurr; |
| 135 | }; |
| 136 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 137 | class SkGlyphCache; |
| 138 | |
| 139 | class SkGrFontScaler : public GrFontScaler { |
| 140 | public: |
| 141 | explicit SkGrFontScaler(SkGlyphCache* strike); |
| 142 | virtual ~SkGrFontScaler(); |
| 143 | |
| 144 | // overrides |
| 145 | virtual const GrKey* getKey(); |
| reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 146 | virtual GrMaskFormat getMaskFormat(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 147 | virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds); |
| 148 | virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, |
| 149 | int rowBytes, void* image); |
| 150 | virtual bool getGlyphPath(uint16_t glyphID, GrPath*); |
| 151 | |
| 152 | private: |
| 153 | SkGlyphCache* fStrike; |
| 154 | GrKey* fKey; |
| 155 | // DECLARE_INSTANCE_COUNTER(SkGrFontScaler); |
| 156 | }; |
| 157 | |
| 158 | //////////////////////////////////////////////////////////////////////////////// |
| 159 | // Helper functions |
| 160 | |
| bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 161 | static const GrContext::TextureKey gUNCACHED_KEY = ~0; |
| 162 | GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, |
| 163 | GrContext::TextureKey key, |
| bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 164 | const GrSamplerState* sampler, |
| bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 165 | const SkBitmap& bitmap); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 166 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 167 | |
| 168 | #endif |