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