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 GrTextContext_DEFINED |
| 12 | #define GrTextContext_DEFINED |
| 13 | |
| 14 | #include "GrGlyph.h" |
bsalomon@google.com | cc4dac3 | 2011-05-10 13:52:42 +0000 | [diff] [blame] | 15 | #include "GrMatrix.h" |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 16 | #include "GrRefCnt.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
| 18 | class GrContext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | class GrFontScaler; |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 20 | class GrPaint; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 22 | class SkGpuDevice; |
| 23 | class SkPaint; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | bf5cad4 | 2012-05-10 12:40:40 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Derived classes can use stages GrPaint::kTotalStages through |
| 27 | * GrDrawState::kNumStages-1. The stages before GrPaint::kTotalStages |
| 28 | * are reserved for setting up the draw (i.e., textures and filter masks). |
| 29 | */ |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 30 | class GrTextContext: public GrRefCnt { |
| 31 | protected: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | GrContext* fContext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 34 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame^] | 35 | SK_DECLARE_INST_COUNT(GrTextContext) |
| 36 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 37 | /** |
| 38 | * To use a text context it must be wrapped in an AutoFinish. AutoFinish's |
| 39 | * destructor ensures all drawing is flushed to the GrContext. |
| 40 | */ |
| 41 | class AutoFinish { |
| 42 | public: |
| 43 | AutoFinish(GrTextContext* textContext, GrContext* context, |
| 44 | const GrPaint&, const GrMatrix* extMatrix); |
| 45 | ~AutoFinish(); |
| 46 | GrTextContext* getTextContext() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 48 | private: |
| 49 | GrTextContext* fTextContext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 52 | virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, |
| 53 | GrFontScaler*) = 0; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 55 | virtual ~GrTextContext() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 57 | protected: |
| 58 | GrTextContext() { |
| 59 | fContext = NULL; |
| 60 | } |
| 61 | |
| 62 | bool isValid() const { |
| 63 | return (NULL != fContext); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Initialize the object. |
| 68 | * |
| 69 | * Before call to this method, the instance is considered to be in |
| 70 | * invalid state. I.e. call to any method other than isValid will result in |
| 71 | * undefined behaviour. |
| 72 | * |
| 73 | * @see finish |
| 74 | */ |
| 75 | virtual void init(GrContext* context, const GrPaint&, |
| 76 | const GrMatrix* extMatrix) { |
| 77 | fContext = context; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Reset the object to invalid state. |
| 82 | * |
| 83 | * After call to this method, the instance is considered to be in |
| 84 | * invalid state. |
| 85 | * |
| 86 | * It might be brought back to a valid state by calling init. |
| 87 | * |
| 88 | * @see init |
| 89 | */ |
| 90 | virtual void finish() { |
| 91 | fContext = NULL; |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | typedef GrRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 98 | inline GrTextContext::AutoFinish::AutoFinish(GrTextContext* textContext, |
| 99 | GrContext* context, |
| 100 | const GrPaint& grPaint, |
| 101 | const GrMatrix* extMatrix) { |
| 102 | GrAssert(NULL != textContext); |
| 103 | fTextContext = textContext; |
| 104 | fTextContext->ref(); |
| 105 | fTextContext->init(context, grPaint, extMatrix); |
| 106 | } |
| 107 | |
| 108 | inline GrTextContext::AutoFinish::~AutoFinish() { |
| 109 | fTextContext->finish(); |
| 110 | fTextContext->unref(); |
| 111 | } |
| 112 | |
| 113 | inline GrTextContext* GrTextContext::AutoFinish::getTextContext() const { |
| 114 | return fTextContext; |
| 115 | } |
| 116 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | #endif |