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

Side by Side Diff: src/gpu/GrTextContext.h

Issue 150743002: Replace factory generation of TextContexts with persistent objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: And an if statement Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrPoint.h" 11 #include "GrPoint.h"
12 #include "GrGlyph.h" 12 #include "GrGlyph.h"
13 #include "GrPaint.h" 13 #include "GrPaint.h"
14 #include "SkDeviceProperties.h" 14 #include "SkDeviceProperties.h"
15 15
16 #include "SkPostConfig.h" 16 #include "SkPostConfig.h"
17 17
18 class GrContext; 18 class GrContext;
19 class GrDrawTarget; 19 class GrDrawTarget;
20 class GrFontScaler; 20 class GrFontScaler;
21 21
22 /* 22 /*
23 * This class wraps the state for a single text render 23 * This class wraps the state for a single text render
24 */ 24 */
25 class GrTextContext { 25 class GrTextContext {
26 public: 26 public:
27 virtual ~GrTextContext() {} 27 virtual ~GrTextContext() {}
28 virtual void drawText(const char text[], size_t byteLength, SkScalar x, SkSc alar y) = 0; 28 virtual void drawText(const GrPaint&, const SkPaint&, const char text[], siz e_t byteLength,
29 virtual void drawPosText(const char text[], size_t byteLength, 29 SkScalar x, SkScalar y) = 0;
30 virtual void drawPosText(const GrPaint&, const SkPaint&,
31 const char text[], size_t byteLength,
30 const SkScalar pos[], SkScalar constY, 32 const SkScalar pos[], SkScalar constY,
31 int scalarsPerPosition) = 0; 33 int scalarsPerPosition) = 0;
34
35 virtual bool canDraw(const SkPaint& paint) = 0;
32 36
33 protected: 37 protected:
34 GrTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProp erties&); 38 GrTextContext(GrContext*, const SkDeviceProperties&);
35 39
36 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); 40 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
37 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, 41 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
38 const char text[], size_t byteLength, SkVector* stop Vector); 42 const char text[], size_t byteLength, SkVector* stop Vector);
39 43
44 void init(const GrPaint&, const SkPaint&);
45 void finish() { fDrawTarget = NULL; }
46
40 GrContext* fContext; 47 GrContext* fContext;
48 SkDeviceProperties fDeviceProperties;
49
50 GrDrawTarget* fDrawTarget;
51 SkIRect fClipRect;
41 GrPaint fPaint; 52 GrPaint fPaint;
42 SkPaint fSkPaint; 53 SkPaint fSkPaint;
43 SkDeviceProperties fDeviceProperties;
44 GrDrawTarget* fDrawTarget;
45
46 SkIRect fClipRect;
47 };
48
49 /*
50 * These classes wrap the creation of a single text context for a given GPU devi ce. The
51 * assumption is that we'll only be using one text context at a time for that de vice.
52 */
53 class GrTextContextManager {
54 public:
55 virtual ~GrTextContextManager() {}
56 virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint,
57 const SkPaint& skPaint, const SkDeviceProperti es& props) = 0;
58 virtual bool canDraw(const SkPaint& paint, const SkMatrix& ctm) = 0;
59 };
60
61 template <class TextContextClass>
62 class GrTTextContextManager : public GrTextContextManager {
63 private:
64 class ManagedTextContext : public TextContextClass {
65 public:
66 virtual ~ManagedTextContext() {}
67
68 ManagedTextContext(GrContext* grContext,
69 const GrPaint& grPaint,
70 const SkPaint& skPaint,
71 const SkDeviceProperties& properties,
72 GrTTextContextManager<TextContextClass>* manager) :
73 TextContextClass(grContext, grPaint, skPaint, properti es) {
74 fManager = manager;
75 }
76
77 static void operator delete(void* ptr) {
78 if (ptr == NULL) {
79 return;
80 }
81 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>( ptr);
82 context->fManager->recycle(context);
83 }
84
85 static void operator delete(void*, void*) {
86 }
87
88 GrTTextContextManager<TextContextClass>* fManager;
89 };
90
91 public:
92 GrTTextContextManager() {
93 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext));
94 fUsed = false;
95 }
96
97 virtual ~GrTTextContextManager() {
98 SkASSERT(!fUsed);
99 sk_free(fAllocation);
100 }
101
102 virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint,
103 const SkPaint& skPaint, const SkDeviceProperti es& properties)
104 SK_OVERRIDE {
105 // add check for usePath here?
106 SkASSERT(!fUsed);
107 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC ontext,
108 (grContext, grPaint, skPa int, properties,
109 this));
110 fUsed = true;
111 return obj;
112 }
113
114 virtual bool canDraw(const SkPaint& paint, const SkMatrix& ctm) SK_OVERRIDE {
115 return TextContextClass::CanDraw(paint, ctm);
116 }
117
118 private:
119 void recycle(GrTextContext* textContext) {
120 SkASSERT((void*)textContext == fAllocation);
121 SkASSERT(fUsed);
122 fUsed = false;
123 }
124
125 void* fAllocation;
126 bool fUsed;
127 }; 54 };
128 55
129 #endif 56 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698