2 * Copyright 2010 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrTextContext_DEFINED
9 #define GrTextContext_DEFINED
11 #include "GrContext.h"
15 #include "SkPostConfig.h"
22 * This class wraps the state for a single text render
26 virtual ~GrTextContext() {}
27 virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
31 GrTextContext(GrContext*, const GrPaint&, const SkPaint&);
36 GrDrawTarget* fDrawTarget;
42 * These classes wrap the creation of a single text context for a given GPU device. The
43 * assumption is that we'll only be using one text context at a time for that device.
45 class GrTextContextManager {
47 virtual ~GrTextContextManager() {}
48 virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint,
49 const SkPaint& skPaint) = 0;
52 template <class TextContextClass>
53 class GrTTextContextManager : public GrTextContextManager {
55 class ManagedTextContext : public TextContextClass {
57 ~ManagedTextContext() {}
59 ManagedTextContext(GrContext* context,
60 const GrPaint& grPaint,
61 const SkPaint& skPaint,
62 GrTTextContextManager<TextContextClass>* manager) :
63 TextContextClass(context, grPaint, skPaint) {
67 static void operator delete(void* ptr) {
71 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>(ptr);
72 context->fManager->recycle(context);
75 static void operator delete(void*, void*) {
78 GrTTextContextManager<TextContextClass>* fManager;
82 GrTTextContextManager() {
83 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext));
87 ~GrTTextContextManager() {
92 GrTextContext* create(GrContext* context, const GrPaint& grPaint,
93 const SkPaint& skPaint) {
94 // add check for usePath here?
96 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextContext,
97 (context, grPaint, skPaint, this));
103 void recycle(GrTextContext* textContext) {
104 SkASSERT((void*)textContext == fAllocation);