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

Side by Side 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: Revise GrTextContext destruction. 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 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 class GrContext; 15 class GrContext;
16 class GrDrawTarget; 16 class GrDrawTarget;
17 class GrFontScaler; 17 class GrFontScaler;
18 class GrTextContext;
19
20 /*
21 * These classes wrap the creation of a single text context for a given GPU devi ce. The
22 * assumption is that we'll only be using one text context at a time for that de vice.
23 */
24 class GrTextContextFactory {
25 public:
26 virtual ~GrTextContextFactory() {}
27 virtual GrTextContext* Create(GrContext* context, const GrPaint& grPaint,
28 const SkPaint& skPaint) = 0;
29 virtual void Recycle(GrTextContext* textContext) = 0;
30 };
31
32 template <class TextContextClass>
33 class GrTTextContextFactory : public GrTextContextFactory {
34 public:
35 GrTTextContextFactory() {
36 fAllocation = sk_malloc_throw(sizeof(TextContextClass));
37 fUsed = false;
38 }
39
40 ~GrTTextContextFactory() {
41 SkASSERT(!fUsed);
42 sk_free(fAllocation);
43 }
44
45 GrTextContext* Create(GrContext* context, const GrPaint& grPaint,
bsalomon 2014/01/22 19:13:36 nit: since Create and Destroy are not static they
jvanverth1 2014/01/22 20:28:40 Done.
46 const SkPaint& skPaint) {
47 // add check for usePath here?
48 SkASSERT(!fUsed);
49 TextContextClass* obj = new(fAllocation) TextContextClass(context, grPai nt, skPaint);
50 obj->fFactory = this;
51 fUsed = true;
52 return obj;
53 }
54
55 void Recycle(GrTextContext* textContext) {
56 SkASSERT((void*)textContext == fAllocation);
57 SkASSERT(fUsed);
58 fUsed = false;
59 }
60
61 private:
62 void* fAllocation;
63 bool fUsed;
64 };
18 65
19 /* 66 /*
20 * This class wraps the state for a single text render 67 * This class wraps the state for a single text render
21 */ 68 */
22 class GrTextContext { 69 class GrTextContext {
23 public: 70 public:
71 virtual ~GrTextContext() {}
72
24 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, 73 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
25 GrFontScaler*) = 0; 74 GrFontScaler*) = 0;
26 75
76 static void operator delete(void* ptr) throw() {
bsalomon 2014/01/22 19:13:36 Do we need the throw here? We build without except
jvanverth1 2014/01/22 20:28:40 Done.
77 if (ptr == NULL) {
78 return;
79 }
80 GrTextContext* context = reinterpret_cast<GrTextContext*>(ptr);
81 context->fFactory->Recycle(context);
82 }
83
27 protected: 84 protected:
28 GrTextContext(GrContext*, const GrPaint&); 85 GrTextContext(GrContext*, const GrPaint&, const SkPaint&);
29 virtual ~GrTextContext() {} 86
30
31 GrPaint fPaint; 87 GrPaint fPaint;
88 SkPaint fSkPaint;
32 GrContext* fContext; 89 GrContext* fContext;
33 GrDrawTarget* fDrawTarget; 90 GrDrawTarget* fDrawTarget;
34 91
35 SkIRect fClipRect; 92 SkIRect fClipRect;
36 93
37 private: 94 GrTextContextFactory* fFactory;
38 }; 95 };
39 96
40 #endif 97 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698