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

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: Some clean-up work. 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
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 "GrContext.h"
12 #include "GrGlyph.h" 12 #include "GrGlyph.h"
13 #include "GrPaint.h" 13 #include "GrPaint.h"
14 14
15 #include "SkPostConfig.h" 15 #include "SkPostConfig.h"
16 16
17 class GrContext; 17 class SkGpuDevice;
18 class GrDrawTarget; 18 class GrDrawTarget;
19 class GrFontScaler; 19 class GrFontScaler;
20 20
21 /* 21 /*
22 * This class wraps the state for a single text render 22 * This class wraps the state for a single text render
23 */ 23 */
24 class GrTextContext { 24 class GrTextContext {
25 public: 25 public:
26 virtual ~GrTextContext() {} 26 virtual ~GrTextContext() {}
27 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, 27 virtual void drawText(const char text[], size_t byteLength, SkScalar x, SkSc alar y) = 0;
28 GrFontScaler*) = 0; 28 virtual void drawPosText(const char text[], size_t byteLength,
29 const SkScalar pos[], SkScalar constY,
30 int scalarsPerPosition) = 0;
29 31
30 protected: 32 protected:
31 GrTextContext(GrContext*, const GrPaint&, const SkPaint&); 33 GrTextContext(SkGpuDevice*, const GrPaint&, const SkPaint&);
32 34
35 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
36 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
37 const char text[], size_t byteLength, SkVector* stop Vector);
38
33 GrPaint fPaint; 39 GrPaint fPaint;
34 SkPaint fSkPaint; 40 SkPaint fSkPaint;
35 GrContext* fContext; 41 SkGpuDevice* fDevice;
36 GrDrawTarget* fDrawTarget; 42 GrDrawTarget* fDrawTarget;
37 43
38 SkIRect fClipRect; 44 SkIRect fClipRect;
39 }; 45 };
40 46
41 /* 47 /*
42 * These classes wrap the creation of a single text context for a given GPU devi ce. The 48 * 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. 49 * assumption is that we'll only be using one text context at a time for that de vice.
44 */ 50 */
45 class GrTextContextManager { 51 class GrTextContextManager {
46 public: 52 public:
47 virtual ~GrTextContextManager() {} 53 virtual ~GrTextContextManager() {}
48 virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint, 54 virtual GrTextContext* create(SkGpuDevice* device, const GrPaint& grPaint,
49 const SkPaint& skPaint) = 0; 55 const SkPaint& skPaint) = 0;
50 }; 56 };
51 57
52 template <class TextContextClass> 58 template <class TextContextClass>
53 class GrTTextContextManager : public GrTextContextManager { 59 class GrTTextContextManager : public GrTextContextManager {
54 private: 60 private:
55 class ManagedTextContext : public TextContextClass { 61 class ManagedTextContext : public TextContextClass {
56 public: 62 public:
57 ~ManagedTextContext() {} 63 ~ManagedTextContext() {}
58 64
59 ManagedTextContext(GrContext* context, 65 ManagedTextContext(SkGpuDevice* device,
bsalomon 2014/01/27 21:51:25 Is this just to get at the device properties? I'd
jvanverth1 2014/01/28 18:05:33 Done.
60 const GrPaint& grPaint, 66 const GrPaint& grPaint,
61 const SkPaint& skPaint, 67 const SkPaint& skPaint,
62 GrTTextContextManager<TextContextClass>* manager) : 68 GrTTextContextManager<TextContextClass>* manager) :
63 TextContextClass(context, grPaint, skPaint) { 69 TextContextClass(device, grPaint, skPaint) {
64 fManager = manager; 70 fManager = manager;
65 } 71 }
66 72
67 static void operator delete(void* ptr) { 73 static void operator delete(void* ptr) {
68 if (ptr == NULL) { 74 if (ptr == NULL) {
69 return; 75 return;
70 } 76 }
71 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>( ptr); 77 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>( ptr);
72 context->fManager->recycle(context); 78 context->fManager->recycle(context);
73 } 79 }
74 80
75 static void operator delete(void*, void*) { 81 static void operator delete(void*, void*) {
76 } 82 }
77 83
78 GrTTextContextManager<TextContextClass>* fManager; 84 GrTTextContextManager<TextContextClass>* fManager;
79 }; 85 };
80 86
81 public: 87 public:
82 GrTTextContextManager() { 88 GrTTextContextManager() {
83 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); 89 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext));
84 fUsed = false; 90 fUsed = false;
85 } 91 }
86 92
87 ~GrTTextContextManager() { 93 ~GrTTextContextManager() {
88 SkASSERT(!fUsed); 94 SkASSERT(!fUsed);
89 sk_free(fAllocation); 95 sk_free(fAllocation);
90 } 96 }
91 97
92 GrTextContext* create(GrContext* context, const GrPaint& grPaint, 98 GrTextContext* create(SkGpuDevice* device, const GrPaint& grPaint,
93 const SkPaint& skPaint) { 99 const SkPaint& skPaint) {
94 // add check for usePath here? 100 // add check for usePath here?
95 SkASSERT(!fUsed); 101 SkASSERT(!fUsed);
96 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC ontext, 102 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC ontext,
97 (context, grPaint, skPain t, this)); 103 (device, grPaint, skPaint , this));
98 fUsed = true; 104 fUsed = true;
99 return obj; 105 return obj;
100 } 106 }
101 107
102 private: 108 private:
103 void recycle(GrTextContext* textContext) { 109 void recycle(GrTextContext* textContext) {
104 SkASSERT((void*)textContext == fAllocation); 110 SkASSERT((void*)textContext == fAllocation);
105 SkASSERT(fUsed); 111 SkASSERT(fUsed);
106 fUsed = false; 112 fUsed = false;
107 } 113 }
108 114
109 void* fAllocation; 115 void* fAllocation;
110 bool fUsed; 116 bool fUsed;
111 }; 117 };
112 118
113 #endif 119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698