| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrTextContext_DEFINED | 8 #ifndef GrTextContext_DEFINED |
| 9 #define GrTextContext_DEFINED | 9 #define GrTextContext_DEFINED |
| 10 | 10 |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrGlyph.h" | 12 #include "GrGlyph.h" |
| 13 #include "GrPaint.h" | 13 #include "GrPaint.h" |
| 14 | 14 |
| 15 #include "SkPostConfig.h" | |
| 16 | |
| 17 class GrContext; | 15 class GrContext; |
| 18 class GrDrawTarget; | 16 class GrDrawTarget; |
| 19 class GrFontScaler; | 17 class GrFontScaler; |
| 20 | 18 |
| 21 /* | 19 /* |
| 22 * This class wraps the state for a single text render | 20 * This class wraps the state for a single text render |
| 23 */ | 21 */ |
| 24 class GrTextContext { | 22 class GrTextContext { |
| 25 public: | 23 public: |
| 26 virtual ~GrTextContext() {} | |
| 27 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, | 24 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, |
| 28 GrFontScaler*) = 0; | 25 GrFontScaler*) = 0; |
| 29 | 26 |
| 30 protected: | 27 protected: |
| 31 GrTextContext(GrContext*, const GrPaint&, const SkPaint&); | 28 GrTextContext(GrContext*, const GrPaint&); |
| 29 virtual ~GrTextContext() {} |
| 32 | 30 |
| 33 GrPaint fPaint; | 31 GrPaint fPaint; |
| 34 SkPaint fSkPaint; | |
| 35 GrContext* fContext; | 32 GrContext* fContext; |
| 36 GrDrawTarget* fDrawTarget; | 33 GrDrawTarget* fDrawTarget; |
| 37 | 34 |
| 38 SkIRect fClipRect; | 35 SkIRect fClipRect; |
| 39 }; | |
| 40 | |
| 41 /* | |
| 42 * These classes wrap the creation of a single text context for a given GPU devi
ce. The | |
| 43 * assumption is that we'll only be using one text context at a time for that de
vice. | |
| 44 */ | |
| 45 class GrTextContextManager { | |
| 46 public: | |
| 47 virtual ~GrTextContextManager() {} | |
| 48 virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint, | |
| 49 const SkPaint& skPaint) = 0; | |
| 50 }; | |
| 51 | |
| 52 template <class TextContextClass> | |
| 53 class GrTTextContextManager : public GrTextContextManager { | |
| 54 private: | |
| 55 class ManagedTextContext : public TextContextClass { | |
| 56 public: | |
| 57 ~ManagedTextContext() {} | |
| 58 | |
| 59 ManagedTextContext(GrContext* context, | |
| 60 const GrPaint& grPaint, | |
| 61 const SkPaint& skPaint, | |
| 62 GrTTextContextManager<TextContextClass>* manager) : | |
| 63 TextContextClass(context, grPaint, skPaint) { | |
| 64 fManager = manager; | |
| 65 } | |
| 66 | |
| 67 static void operator delete(void* ptr) { | |
| 68 if (ptr == NULL) { | |
| 69 return; | |
| 70 } | |
| 71 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>(
ptr); | |
| 72 context->fManager->recycle(context); | |
| 73 } | |
| 74 | |
| 75 GrTTextContextManager<TextContextClass>* fManager; | |
| 76 }; | |
| 77 | |
| 78 public: | |
| 79 GrTTextContextManager() { | |
| 80 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); | |
| 81 fUsed = false; | |
| 82 } | |
| 83 | |
| 84 ~GrTTextContextManager() { | |
| 85 SkASSERT(!fUsed); | |
| 86 sk_free(fAllocation); | |
| 87 } | |
| 88 | |
| 89 GrTextContext* create(GrContext* context, const GrPaint& grPaint, | |
| 90 const SkPaint& skPaint) { | |
| 91 // add check for usePath here? | |
| 92 SkASSERT(!fUsed); | |
| 93 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC
ontext, | |
| 94 (context, grPaint, skPain
t, this)); | |
| 95 fUsed = true; | |
| 96 return obj; | |
| 97 } | |
| 98 | 36 |
| 99 private: | 37 private: |
| 100 void recycle(GrTextContext* textContext) { | |
| 101 SkASSERT((void*)textContext == fAllocation); | |
| 102 SkASSERT(fUsed); | |
| 103 fUsed = false; | |
| 104 } | |
| 105 | |
| 106 void* fAllocation; | |
| 107 bool fUsed; | |
| 108 }; | 38 }; |
| 109 | 39 |
| 110 #endif | 40 #endif |
| OLD | NEW |