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

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

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

Powered by Google App Engine
This is Rietveld 408576698