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

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

Issue 145073005: Move GrTextContext to private interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove use of GrTextContext.h from GrSkGpuDevice.h 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
(Empty)
1 /*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrTextContext_DEFINED
9 #define GrTextContext_DEFINED
10
11 #include "GrPoint.h"
12 #include "GrGlyph.h"
13 #include "GrPaint.h"
14 #include "SkDeviceProperties.h"
15
16 #include "SkPostConfig.h"
17
18 class GrContext;
19 class GrDrawTarget;
20 class GrFontScaler;
21
22 /*
23 * This class wraps the state for a single text render
24 */
25 class GrTextContext {
26 public:
27 virtual ~GrTextContext() {}
28 virtual void drawText(const char text[], size_t byteLength, SkScalar x, SkSc alar y) = 0;
29 virtual void drawPosText(const char text[], size_t byteLength,
30 const SkScalar pos[], SkScalar constY,
31 int scalarsPerPosition) = 0;
32
33 protected:
34 GrTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProp erties&);
35
36 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
37 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
38 const char text[], size_t byteLength, SkVector* stop Vector);
39
40 GrContext* fContext;
41 GrPaint fPaint;
42 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 };
128
129 #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