Chromium Code Reviews| Index: include/gpu/GrTextContext.h |
| diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h |
| index b367cf228d57fd5c0103cbb77332bc7b7a0dd4ae..54c2d1f18affbb177199246545c826c51feba43d 100644 |
| --- a/include/gpu/GrTextContext.h |
| +++ b/include/gpu/GrTextContext.h |
| @@ -15,26 +15,83 @@ |
| class GrContext; |
| class GrDrawTarget; |
| class GrFontScaler; |
| +class GrTextContext; |
| + |
| +/* |
| + * These classes wrap the creation of a single text context for a given GPU device. The |
| + * assumption is that we'll only be using one text context at a time for that device. |
| + */ |
| +class GrTextContextFactory { |
| +public: |
| + virtual ~GrTextContextFactory() {} |
| + virtual GrTextContext* Create(GrContext* context, const GrPaint& grPaint, |
| + const SkPaint& skPaint) = 0; |
| + virtual void Recycle(GrTextContext* textContext) = 0; |
| +}; |
| + |
| +template <class TextContextClass> |
| +class GrTTextContextFactory : public GrTextContextFactory { |
| +public: |
| + GrTTextContextFactory() { |
| + fAllocation = sk_malloc_throw(sizeof(TextContextClass)); |
| + fUsed = false; |
| + } |
| + |
| + ~GrTTextContextFactory() { |
| + SkASSERT(!fUsed); |
| + sk_free(fAllocation); |
| + } |
| + |
| + 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.
|
| + const SkPaint& skPaint) { |
| + // add check for usePath here? |
| + SkASSERT(!fUsed); |
| + TextContextClass* obj = new(fAllocation) TextContextClass(context, grPaint, skPaint); |
| + obj->fFactory = this; |
| + fUsed = true; |
| + return obj; |
| + } |
| + |
| + void Recycle(GrTextContext* textContext) { |
| + SkASSERT((void*)textContext == fAllocation); |
| + SkASSERT(fUsed); |
| + fUsed = false; |
| + } |
| + |
| +private: |
| + void* fAllocation; |
| + bool fUsed; |
| +}; |
| /* |
| * This class wraps the state for a single text render |
| */ |
| class GrTextContext { |
| public: |
| + virtual ~GrTextContext() {} |
| + |
| virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, |
| GrFontScaler*) = 0; |
| - |
| + |
| + 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.
|
| + if (ptr == NULL) { |
| + return; |
| + } |
| + GrTextContext* context = reinterpret_cast<GrTextContext*>(ptr); |
| + context->fFactory->Recycle(context); |
| + } |
| + |
| protected: |
| - GrTextContext(GrContext*, const GrPaint&); |
| - virtual ~GrTextContext() {} |
| - |
| + GrTextContext(GrContext*, const GrPaint&, const SkPaint&); |
| + |
| GrPaint fPaint; |
| + SkPaint fSkPaint; |
| GrContext* fContext; |
| GrDrawTarget* fDrawTarget; |
| - |
| + |
| SkIRect fClipRect; |
| - |
| -private: |
| + |
| + GrTextContextFactory* fFactory; |
| }; |
| #endif |