Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(807)

Unified Diff: include/gpu/GrTextContext.h

Issue 144283002: Add factory class for generating various flavors of GrTextContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698