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 class GrContext; | 15 class GrContext; |
16 class GrDrawTarget; | 16 class GrDrawTarget; |
17 class GrFontScaler; | 17 class GrFontScaler; |
18 | 18 |
19 /* | 19 /* |
20 * This class wraps the state for a single text render | 20 * This class wraps the state for a single text render |
21 */ | 21 */ |
22 class GrTextContext { | 22 class GrTextContext { |
23 public: | 23 public: |
24 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, | 24 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, |
25 GrFontScaler*) = 0; | 25 GrFontScaler*) = 0; |
26 | 26 |
27 protected: | 27 protected: |
28 GrTextContext(GrContext*, const GrPaint&); | 28 GrTextContext(GrContext*, const GrPaint&, const SkPaint&); |
29 virtual ~GrTextContext() {} | 29 virtual ~GrTextContext() {} |
30 | 30 |
31 GrPaint fPaint; | 31 GrPaint fPaint; |
32 SkPaint fSkPaint; | |
32 GrContext* fContext; | 33 GrContext* fContext; |
33 GrDrawTarget* fDrawTarget; | 34 GrDrawTarget* fDrawTarget; |
34 | 35 |
35 SkIRect fClipRect; | 36 SkIRect fClipRect; |
36 | 37 |
37 private: | 38 private: |
tfarina
2014/01/21 23:49:45
while here, remove this empty section?
| |
38 }; | 39 }; |
39 | 40 |
41 class GrTextContextFactory { | |
42 public: | |
43 virtual ~GrTextContextFactory() {} | |
44 virtual GrTextContext* Create(GrContext* context, const GrPaint& grPaint, | |
45 const SkPaint& skPaint) = 0; | |
46 virtual void Destroy(GrTextContext* textContext) = 0; | |
47 }; | |
48 | |
49 /* | |
50 * This class wraps the creation of a single text context | |
bsalomon
2014/01/21 20:46:17
Maybe a little more clear in the comment that it i
jvanverth1
2014/01/21 21:10:56
Done.
| |
51 */ | |
52 template <class TextContextClass> | |
53 class GrTTextContextFactory : public GrTextContextFactory { | |
54 public: | |
55 GrTTextContextFactory() { | |
56 fAllocation = malloc(sizeof(TextContextClass)); | |
bsalomon
2014/01/21 20:46:17
SkMalloc/SkFree
jvanverth1
2014/01/21 21:10:56
Done.
| |
57 fUsed = false; | |
58 } | |
59 | |
60 ~GrTTextContextFactory() { | |
61 SkASSERT(!fUsed); | |
62 free(fAllocation); | |
63 } | |
64 | |
65 GrTextContext* Create(GrContext* context, const GrPaint& grPaint, | |
66 const SkPaint& skPaint) { | |
67 // add check for usePath here? | |
68 SkASSERT(!fUsed); | |
69 TextContextClass* obj = new(fAllocation) TextContextClass(context, grPai nt, skPaint); | |
70 fUsed = true; | |
71 return obj; | |
72 } | |
73 | |
74 void Destroy(GrTextContext* textContext) { | |
75 SkASSERT((void*)textContext == fAllocation); | |
76 SkASSERT(fUsed); | |
77 ((TextContextClass*)textContext)->~TextContextClass(); | |
78 fUsed = false; | |
79 } | |
80 | |
81 private: | |
82 void* fAllocation; | |
83 bool fUsed; | |
84 }; | |
85 | |
40 #endif | 86 #endif |
OLD | NEW |