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