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 |
15 class GrContext; | 17 class GrContext; |
16 class GrDrawTarget; | 18 class GrDrawTarget; |
17 class GrFontScaler; | 19 class GrFontScaler; |
18 | 20 |
19 /* | 21 /* |
20 * This class wraps the state for a single text render | 22 * This class wraps the state for a single text render |
21 */ | 23 */ |
22 class GrTextContext { | 24 class GrTextContext { |
23 public: | 25 public: |
| 26 virtual ~GrTextContext() {} |
24 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, | 27 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, |
25 GrFontScaler*) = 0; | 28 GrFontScaler*) = 0; |
26 | 29 |
27 protected: | 30 protected: |
28 GrTextContext(GrContext*, const GrPaint&); | 31 GrTextContext(GrContext*, const GrPaint&, const SkPaint&); |
29 virtual ~GrTextContext() {} | |
30 | 32 |
31 GrPaint fPaint; | 33 GrPaint fPaint; |
| 34 SkPaint fSkPaint; |
32 GrContext* fContext; | 35 GrContext* fContext; |
33 GrDrawTarget* fDrawTarget; | 36 GrDrawTarget* fDrawTarget; |
34 | 37 |
35 SkIRect fClipRect; | 38 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 static void operator delete(void*, void*) { |
| 76 } |
| 77 |
| 78 GrTTextContextManager<TextContextClass>* fManager; |
| 79 }; |
| 80 |
| 81 public: |
| 82 GrTTextContextManager() { |
| 83 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); |
| 84 fUsed = false; |
| 85 } |
| 86 |
| 87 ~GrTTextContextManager() { |
| 88 SkASSERT(!fUsed); |
| 89 sk_free(fAllocation); |
| 90 } |
| 91 |
| 92 GrTextContext* create(GrContext* context, const GrPaint& grPaint, |
| 93 const SkPaint& skPaint) { |
| 94 // add check for usePath here? |
| 95 SkASSERT(!fUsed); |
| 96 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC
ontext, |
| 97 (context, grPaint, skPain
t, this)); |
| 98 fUsed = true; |
| 99 return obj; |
| 100 } |
36 | 101 |
37 private: | 102 private: |
| 103 void recycle(GrTextContext* textContext) { |
| 104 SkASSERT((void*)textContext == fAllocation); |
| 105 SkASSERT(fUsed); |
| 106 fUsed = false; |
| 107 } |
| 108 |
| 109 void* fAllocation; |
| 110 bool fUsed; |
38 }; | 111 }; |
39 | 112 |
40 #endif | 113 #endif |
OLD | NEW |