Index: include/gpu/GrTextContext.h |
diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h |
index b367cf228d57fd5c0103cbb77332bc7b7a0dd4ae..f312a979a356b093e84887078a897aced466c12f 100644 |
--- a/include/gpu/GrTextContext.h |
+++ b/include/gpu/GrTextContext.h |
@@ -25,10 +25,11 @@ public: |
GrFontScaler*) = 0; |
protected: |
- GrTextContext(GrContext*, const GrPaint&); |
+ GrTextContext(GrContext*, const GrPaint&, const SkPaint&); |
virtual ~GrTextContext() {} |
GrPaint fPaint; |
+ SkPaint fSkPaint; |
GrContext* fContext; |
GrDrawTarget* fDrawTarget; |
@@ -37,4 +38,49 @@ protected: |
private: |
tfarina
2014/01/21 23:49:45
while here, remove this empty section?
|
}; |
+class GrTextContextFactory { |
+public: |
+ virtual ~GrTextContextFactory() {} |
+ virtual GrTextContext* Create(GrContext* context, const GrPaint& grPaint, |
+ const SkPaint& skPaint) = 0; |
+ virtual void Destroy(GrTextContext* textContext) = 0; |
+}; |
+ |
+/* |
+ * 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.
|
+ */ |
+template <class TextContextClass> |
+class GrTTextContextFactory : public GrTextContextFactory { |
+public: |
+ GrTTextContextFactory() { |
+ fAllocation = malloc(sizeof(TextContextClass)); |
bsalomon
2014/01/21 20:46:17
SkMalloc/SkFree
jvanverth1
2014/01/21 21:10:56
Done.
|
+ fUsed = false; |
+ } |
+ |
+ ~GrTTextContextFactory() { |
+ SkASSERT(!fUsed); |
+ free(fAllocation); |
+ } |
+ |
+ GrTextContext* Create(GrContext* context, const GrPaint& grPaint, |
+ const SkPaint& skPaint) { |
+ // add check for usePath here? |
+ SkASSERT(!fUsed); |
+ TextContextClass* obj = new(fAllocation) TextContextClass(context, grPaint, skPaint); |
+ fUsed = true; |
+ return obj; |
+ } |
+ |
+ void Destroy(GrTextContext* textContext) { |
+ SkASSERT((void*)textContext == fAllocation); |
+ SkASSERT(fUsed); |
+ ((TextContextClass*)textContext)->~TextContextClass(); |
+ fUsed = false; |
+ } |
+ |
+private: |
+ void* fAllocation; |
+ bool fUsed; |
+}; |
+ |
#endif |