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 #include "GrTextContext.h" | 8 #include "GrTextContext.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrDrawTarget.h" | |
11 #include "GrFontScaler.h" | |
12 | 10 |
13 #include "SkAutoKern.h" | 11 #include "SkAutoKern.h" |
14 #include "SkGlyphCache.h" | 12 #include "SkGlyphCache.h" |
| 13 #include "GrFontScaler.h" |
15 | 14 |
16 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope
rties) : | 15 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope
rties) : |
17 fFallbackTextContext(NULL), | 16 fFallbackTextContext(NULL), |
18 fContext(context), fDeviceProperties(properties), fD
rawTarget(NULL) { | 17 fContext(context), fDeviceProperties(properties), fD
rawTarget(NULL) { |
19 } | 18 } |
20 | 19 |
21 GrTextContext::~GrTextContext() { | 20 GrTextContext::~GrTextContext() { |
22 SkDELETE(fFallbackTextContext); | 21 SkDELETE(fFallbackTextContext); |
23 } | 22 } |
24 | 23 |
25 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, | 24 void GrTextContext::init(GrRenderTarget* rt, const GrPaint& grPaint, const SkPai
nt& skPaint) { |
26 const SkPaint& skPaint) { | 25 fClip = fContext->getClip(); |
27 fClip = clip; | |
28 | 26 |
29 fRenderTarget.reset(SkRef(rt)); | 27 fRenderTarget.reset(SkRef(rt)); |
30 | 28 |
31 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); | 29 fClip->getConservativeBounds(fRenderTarget->width(), fRenderTarget->height()
, &fClipRect); |
32 | 30 |
33 fDrawTarget = fContext->getTextTarget(); | 31 fDrawTarget = fContext->getTextTarget(); |
34 | 32 |
35 fPaint = grPaint; | 33 fPaint = grPaint; |
36 fSkPaint = skPaint; | 34 fSkPaint = skPaint; |
37 } | 35 } |
38 | 36 |
39 bool GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, | 37 bool GrTextContext::drawText(GrRenderTarget* rt, const GrPaint& paint, const SkP
aint& skPaint, |
40 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 38 const SkMatrix& viewMatrix, |
41 const char text[], size_t byteLength, | 39 const char text[], size_t byteLength, |
42 SkScalar x, SkScalar y) { | 40 SkScalar x, SkScalar y) { |
43 | 41 |
44 GrTextContext* textContext = this; | 42 GrTextContext* textContext = this; |
45 do { | 43 do { |
46 if (textContext->canDraw(skPaint, viewMatrix)) { | 44 if (textContext->canDraw(skPaint, viewMatrix)) { |
47 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y); | 45 textContext->onDrawText(rt, paint, skPaint, viewMatrix, text, byteLe
ngth, x, y); |
48 return true; | 46 return true; |
49 } | 47 } |
50 textContext = textContext->fFallbackTextContext; | 48 textContext = textContext->fFallbackTextContext; |
51 } while (textContext); | 49 } while (textContext); |
52 | 50 |
53 return false; | 51 return false; |
54 } | 52 } |
55 | 53 |
56 bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, | 54 bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrPaint& paint, const
SkPaint& skPaint, |
57 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, | 55 const SkMatrix& viewMatrix, |
58 const char text[], size_t byteLength, | 56 const char text[], size_t byteLength, |
59 const SkScalar pos[], int scalarsPerPosition, | 57 const SkScalar pos[], int scalarsPerPosition, |
60 const SkPoint& offset) { | 58 const SkPoint& offset) { |
61 | 59 |
62 GrTextContext* textContext = this; | 60 GrTextContext* textContext = this; |
63 do { | 61 do { |
64 if (textContext->canDraw(skPaint, viewMatrix)) { | 62 if (textContext->canDraw(skPaint, viewMatrix)) { |
65 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, | 63 textContext->onDrawPosText(rt, paint, skPaint, viewMatrix, text, byt
eLength, pos, |
66 scalarsPerPosition, offset); | 64 scalarsPerPosition, offset); |
67 return true; | 65 return true; |
68 } | 66 } |
69 textContext = textContext->fFallbackTextContext; | 67 textContext = textContext->fFallbackTextContext; |
70 } while (textContext); | 68 } while (textContext); |
71 | 69 |
72 return false; | 70 return false; |
73 } | 71 } |
74 | 72 |
75 | 73 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 108 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
111 scaler = (GrFontScaler*)auxData; | 109 scaler = (GrFontScaler*)auxData; |
112 } | 110 } |
113 if (NULL == scaler) { | 111 if (NULL == scaler) { |
114 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 112 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
115 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 113 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
116 } | 114 } |
117 | 115 |
118 return scaler; | 116 return scaler; |
119 } | 117 } |
OLD | NEW |