| OLD | NEW |
| 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(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProp
erties*); |
| 32 | 34 |
| 33 GrPaint fPaint; | 35 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); |
| 34 SkPaint fSkPaint; | 36 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, |
| 35 GrContext* fContext; | 37 const char text[], size_t byteLength, SkVector* stop
Vector); |
| 36 GrDrawTarget* fDrawTarget; | 38 |
| 39 GrContext* fContext; |
| 40 const SkDeviceProperties* fDeviceProperties; |
| 41 GrPaint fPaint; |
| 42 SkPaint fSkPaint; |
| 43 GrDrawTarget* fDrawTarget; |
| 37 | 44 |
| 38 SkIRect fClipRect; | 45 SkIRect fClipRect; |
| 39 }; | 46 }; |
| 40 | 47 |
| 41 /* | 48 /* |
| 42 * These classes wrap the creation of a single text context for a given GPU devi
ce. The | 49 * 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. | 50 * assumption is that we'll only be using one text context at a time for that de
vice. |
| 44 */ | 51 */ |
| 45 class GrTextContextManager { | 52 class GrTextContextManager { |
| 46 public: | 53 public: |
| 47 virtual ~GrTextContextManager() {} | 54 virtual ~GrTextContextManager() {} |
| 48 virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint, | 55 virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint, |
| 49 const SkPaint& skPaint) = 0; | 56 const SkPaint& skPaint, const SkDeviceProperti
es* props) = 0; |
| 50 }; | 57 }; |
| 51 | 58 |
| 52 template <class TextContextClass> | 59 template <class TextContextClass> |
| 53 class GrTTextContextManager : public GrTextContextManager { | 60 class GrTTextContextManager : public GrTextContextManager { |
| 54 private: | 61 private: |
| 55 class ManagedTextContext : public TextContextClass { | 62 class ManagedTextContext : public TextContextClass { |
| 56 public: | 63 public: |
| 57 ~ManagedTextContext() {} | 64 virtual ~ManagedTextContext() {} |
| 58 | 65 |
| 59 ManagedTextContext(GrContext* context, | 66 ManagedTextContext(GrContext* grContext, |
| 60 const GrPaint& grPaint, | 67 const GrPaint& grPaint, |
| 61 const SkPaint& skPaint, | 68 const SkPaint& skPaint, |
| 69 const SkDeviceProperties* properties, |
| 62 GrTTextContextManager<TextContextClass>* manager) : | 70 GrTTextContextManager<TextContextClass>* manager) : |
| 63 TextContextClass(context, grPaint, skPaint) { | 71 TextContextClass(grContext, grPaint, skPaint, properti
es) { |
| 64 fManager = manager; | 72 fManager = manager; |
| 65 } | 73 } |
| 66 | 74 |
| 67 static void operator delete(void* ptr) { | 75 static void operator delete(void* ptr) { |
| 68 if (ptr == NULL) { | 76 if (ptr == NULL) { |
| 69 return; | 77 return; |
| 70 } | 78 } |
| 71 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>(
ptr); | 79 ManagedTextContext* context = reinterpret_cast<ManagedTextContext*>(
ptr); |
| 72 context->fManager->recycle(context); | 80 context->fManager->recycle(context); |
| 73 } | 81 } |
| 74 | 82 |
| 75 static void operator delete(void*, void*) { | 83 static void operator delete(void*, void*) { |
| 76 } | 84 } |
| 77 | 85 |
| 78 GrTTextContextManager<TextContextClass>* fManager; | 86 GrTTextContextManager<TextContextClass>* fManager; |
| 79 }; | 87 }; |
| 80 | 88 |
| 81 public: | 89 public: |
| 82 GrTTextContextManager() { | 90 GrTTextContextManager() { |
| 83 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); | 91 fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); |
| 84 fUsed = false; | 92 fUsed = false; |
| 85 } | 93 } |
| 86 | 94 |
| 87 ~GrTTextContextManager() { | 95 virtual ~GrTTextContextManager() { |
| 88 SkASSERT(!fUsed); | 96 SkASSERT(!fUsed); |
| 89 sk_free(fAllocation); | 97 sk_free(fAllocation); |
| 90 } | 98 } |
| 91 | 99 |
| 92 GrTextContext* create(GrContext* context, const GrPaint& grPaint, | 100 virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint, |
| 93 const SkPaint& skPaint) { | 101 const SkPaint& skPaint, const SkDeviceProperti
es* properties) |
| 102 SK_OVERRIDE { |
| 94 // add check for usePath here? | 103 // add check for usePath here? |
| 95 SkASSERT(!fUsed); | 104 SkASSERT(!fUsed); |
| 96 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC
ontext, | 105 ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextC
ontext, |
| 97 (context, grPaint, skPain
t, this)); | 106 (grContext, grPaint, skPa
int, properties, |
| 107 this)); |
| 98 fUsed = true; | 108 fUsed = true; |
| 99 return obj; | 109 return obj; |
| 100 } | 110 } |
| 101 | 111 |
| 102 private: | 112 private: |
| 103 void recycle(GrTextContext* textContext) { | 113 void recycle(GrTextContext* textContext) { |
| 104 SkASSERT((void*)textContext == fAllocation); | 114 SkASSERT((void*)textContext == fAllocation); |
| 105 SkASSERT(fUsed); | 115 SkASSERT(fUsed); |
| 106 fUsed = false; | 116 fUsed = false; |
| 107 } | 117 } |
| 108 | 118 |
| 109 void* fAllocation; | 119 void* fAllocation; |
| 110 bool fUsed; | 120 bool fUsed; |
| 111 }; | 121 }; |
| 112 | 122 |
| 113 #endif | 123 #endif |
| OLD | NEW |