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 "GrBlurUtils.h" | 9 #include "GrBlurUtils.h" |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
12 #include "GrFontScaler.h" | 12 #include "GrFontScaler.h" |
13 | 13 |
14 #include "SkAutoKern.h" | 14 #include "SkAutoKern.h" |
15 #include "SkDrawFilter.h" | 15 #include "SkDrawFilter.h" |
16 #include "SkDrawProcs.h" | 16 #include "SkDrawProcs.h" |
17 #include "SkGlyphCache.h" | 17 #include "SkGlyphCache.h" |
18 #include "SkGpuDevice.h" | 18 #include "SkGpuDevice.h" |
19 #include "SkTextBlob.h" | 19 #include "SkTextBlob.h" |
20 #include "SkTextMapStateProc.h" | 20 #include "SkTextMapStateProc.h" |
21 #include "SkTextToPathIter.h" | 21 #include "SkTextToPathIter.h" |
22 | 22 |
23 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope
rties) | 23 GrTextContext::GrTextContext(GrContext* context, GrDrawContext* drawContext, |
| 24 const SkDeviceProperties& properties, bool useDFT) |
24 : fFallbackTextContext(NULL) | 25 : fFallbackTextContext(NULL) |
25 , fContext(context) | 26 , fContext(context) |
26 , fDeviceProperties(properties) { | 27 , fDeviceProperties(properties) |
| 28 , fUseDFT(useDFT) |
| 29 , fDrawContext(drawContext) { |
27 } | 30 } |
28 | 31 |
29 GrTextContext::~GrTextContext() { | 32 GrTextContext::~GrTextContext() { |
30 SkDELETE(fFallbackTextContext); | 33 SkDELETE(fFallbackTextContext); |
31 } | 34 } |
32 | 35 |
33 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, | 36 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, |
34 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { | 37 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { |
35 fClip = clip; | 38 fClip = clip; |
36 | 39 |
37 fRenderTarget.reset(SkRef(rt)); | 40 fRenderTarget.reset(SkRef(rt)); |
38 | 41 |
39 fRegionClipBounds = regionClipBounds; | 42 fRegionClipBounds = regionClipBounds; |
40 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); | 43 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); |
41 | 44 |
42 fPaint = grPaint; | 45 fPaint = grPaint; |
43 fSkPaint = skPaint; | 46 fSkPaint = skPaint; |
44 } | 47 } |
45 | 48 |
46 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, | 49 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, |
47 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 50 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
48 const char text[], size_t byteLength, | 51 const char text[], size_t byteLength, |
49 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | 52 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ |
50 if (fContext->abandoned()) { | 53 if (fContext->abandoned() || !fDrawContext) { |
51 return; | |
52 } | |
53 | |
54 GrDrawContext* drawContext = fContext->drawContext(); | |
55 if (!drawContext) { | |
56 return; | 54 return; |
57 } | 55 } |
58 | 56 |
59 GrTextContext* textContext = this; | 57 GrTextContext* textContext = this; |
60 do { | 58 do { |
61 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { | 59 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
62 textContext->onDrawText(drawContext, rt, clip, paint, skPaint, viewM
atrix, | 60 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, |
63 text, byteLength, x, y, clipBounds); | 61 text, byteLength, x, y, clipBounds); |
64 return; | 62 return; |
65 } | 63 } |
66 textContext = textContext->fFallbackTextContext; | 64 textContext = textContext->fFallbackTextContext; |
67 } while (textContext); | 65 } while (textContext); |
68 | 66 |
69 // fall back to drawing as a path | 67 // fall back to drawing as a path |
70 this->drawTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, | 68 this->drawTextAsPath(rt, clip, skPaint, viewMatrix, |
71 text, byteLength, x, y, clipBounds); | 69 text, byteLength, x, y, clipBounds); |
72 } | 70 } |
73 | 71 |
74 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, | 72 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, |
75 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, | 73 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, |
76 const char text[], size_t byteLength, | 74 const char text[], size_t byteLength, |
77 const SkScalar pos[], int scalarsPerPosition, | 75 const SkScalar pos[], int scalarsPerPosition, |
78 const SkPoint& offset, const SkIRect& clipBounds
) { | 76 const SkPoint& offset, const SkIRect& clipBounds
) { |
79 if (fContext->abandoned()) { | 77 if (fContext->abandoned() || !fDrawContext) { |
80 return; | |
81 } | |
82 | |
83 GrDrawContext* drawContext = fContext->drawContext(); | |
84 if (!drawContext) { | |
85 return; | 78 return; |
86 } | 79 } |
87 | 80 |
88 GrTextContext* textContext = this; | 81 GrTextContext* textContext = this; |
89 do { | 82 do { |
90 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { | 83 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
91 textContext->onDrawPosText(drawContext, rt, clip, paint, skPaint, vi
ewMatrix, | 84 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, |
92 text, byteLength, pos, | 85 text, byteLength, pos, |
93 scalarsPerPosition, offset, clipBounds); | 86 scalarsPerPosition, offset, clipBounds); |
94 return; | 87 return; |
95 } | 88 } |
96 textContext = textContext->fFallbackTextContext; | 89 textContext = textContext->fFallbackTextContext; |
97 } while (textContext); | 90 } while (textContext); |
98 | 91 |
99 // fall back to drawing as a path | 92 // fall back to drawing as a path |
100 this->drawPosTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, text, by
teLength, pos, | 93 this->drawPosTextAsPath(rt, clip, skPaint, viewMatrix, text, byteLength, pos
, |
101 scalarsPerPosition, offset, clipBounds); | 94 scalarsPerPosition, offset, clipBounds); |
102 } | 95 } |
103 | 96 |
104 bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) { | 97 bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) { |
105 if (paint.getShader() || | 98 if (paint.getShader() || |
106 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || | 99 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || |
107 paint.getMaskFilter() || | 100 paint.getMaskFilter() || |
108 paint.getRasterizer() || | 101 paint.getRasterizer() || |
109 paint.getColorFilter() || | 102 paint.getColorFilter() || |
110 paint.getPathEffect() || | 103 paint.getPathEffect() || |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 SkFAIL("unhandled positioning mode"); | 169 SkFAIL("unhandled positioning mode"); |
177 } | 170 } |
178 | 171 |
179 if (drawFilter) { | 172 if (drawFilter) { |
180 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | 173 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
181 runPaint = skPaint; | 174 runPaint = skPaint; |
182 } | 175 } |
183 } | 176 } |
184 } | 177 } |
185 | 178 |
186 void GrTextContext::drawTextAsPath(GrDrawContext* drawContext, GrRenderTarget* r
t, | 179 void GrTextContext::drawTextAsPath(GrRenderTarget* rt, |
187 const GrClip& clip, | 180 const GrClip& clip, |
188 const SkPaint& skPaint, const SkMatrix& viewM
atrix, | 181 const SkPaint& skPaint, const SkMatrix& viewM
atrix, |
189 const char text[], size_t byteLength, SkScala
r x, SkScalar y, | 182 const char text[], size_t byteLength, SkScala
r x, SkScalar y, |
190 const SkIRect& clipBounds) { | 183 const SkIRect& clipBounds) { |
191 SkTextToPathIter iter(text, byteLength, skPaint, true); | 184 SkTextToPathIter iter(text, byteLength, skPaint, true); |
192 | 185 |
193 SkMatrix matrix; | 186 SkMatrix matrix; |
194 matrix.setScale(iter.getPathScale(), iter.getPathScale()); | 187 matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
195 matrix.postTranslate(x, y); | 188 matrix.postTranslate(x, y); |
196 | 189 |
197 const SkPath* iterPath; | 190 const SkPath* iterPath; |
198 SkScalar xpos, prevXPos = 0; | 191 SkScalar xpos, prevXPos = 0; |
199 | 192 |
200 while (iter.next(&iterPath, &xpos)) { | 193 while (iter.next(&iterPath, &xpos)) { |
201 matrix.postTranslate(xpos - prevXPos, 0); | 194 matrix.postTranslate(xpos - prevXPos, 0); |
202 if (iterPath) { | 195 if (iterPath) { |
203 const SkPaint& pnt = iter.getPaint(); | 196 const SkPaint& pnt = iter.getPaint(); |
204 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip,
*iterPath, | 197 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip
, *iterPath, |
205 pnt, viewMatrix, &matrix, clipBo
unds, false); | 198 pnt, viewMatrix, &matrix, clipBo
unds, false); |
206 } | 199 } |
207 prevXPos = xpos; | 200 prevXPos = xpos; |
208 } | 201 } |
209 } | 202 } |
210 | 203 |
211 void GrTextContext::drawPosTextAsPath(GrDrawContext* drawContext, GrRenderTarget
* rt, | 204 void GrTextContext::drawPosTextAsPath(GrRenderTarget* rt, |
212 const GrClip& clip, | 205 const GrClip& clip, |
213 const SkPaint& origPaint, const SkMatrix&
viewMatrix, | 206 const SkPaint& origPaint, const SkMatrix&
viewMatrix, |
214 const char text[], size_t byteLength, | 207 const char text[], size_t byteLength, |
215 const SkScalar pos[], int scalarsPerPositi
on, | 208 const SkScalar pos[], int scalarsPerPositi
on, |
216 const SkPoint& offset, const SkIRect& clip
Bounds) { | 209 const SkPoint& offset, const SkIRect& clip
Bounds) { |
217 // setup our std paint, in hopes of getting hits in the cache | 210 // setup our std paint, in hopes of getting hits in the cache |
218 SkPaint paint(origPaint); | 211 SkPaint paint(origPaint); |
219 SkScalar matrixScale = paint.setupForAsPaths(); | 212 SkScalar matrixScale = paint.setupForAsPaths(); |
220 | 213 |
221 SkMatrix matrix; | 214 SkMatrix matrix; |
(...skipping 20 matching lines...) Expand all Loading... |
242 if (glyph.fWidth) { | 235 if (glyph.fWidth) { |
243 const SkPath* path = cache->findPath(glyph); | 236 const SkPath* path = cache->findPath(glyph); |
244 if (path) { | 237 if (path) { |
245 SkPoint tmsLoc; | 238 SkPoint tmsLoc; |
246 tmsProc(pos, &tmsLoc); | 239 tmsProc(pos, &tmsLoc); |
247 SkPoint loc; | 240 SkPoint loc; |
248 alignProc(tmsLoc, glyph, &loc); | 241 alignProc(tmsLoc, glyph, &loc); |
249 | 242 |
250 matrix[SkMatrix::kMTransX] = loc.fX; | 243 matrix[SkMatrix::kMTransX] = loc.fX; |
251 matrix[SkMatrix::kMTransY] = loc.fY; | 244 matrix[SkMatrix::kMTransY] = loc.fY; |
252 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, c
lip, *path, paint, | 245 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt,
clip, *path, paint, |
253 viewMatrix, &matrix, clipBou
nds, false); | 246 viewMatrix, &matrix, clipBou
nds, false); |
254 } | 247 } |
255 } | 248 } |
256 pos += scalarsPerPosition; | 249 pos += scalarsPerPosition; |
257 } | 250 } |
258 } | 251 } |
259 | 252 |
260 //*** change to output positions? | 253 //*** change to output positions? |
261 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr
oc, | 254 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr
oc, |
262 const char text[], size_t byteLength, SkVector*
stopVector) { | 255 const char text[], size_t byteLength, SkVector*
stopVector) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 287 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
295 scaler = (GrFontScaler*)auxData; | 288 scaler = (GrFontScaler*)auxData; |
296 } | 289 } |
297 if (NULL == scaler) { | 290 if (NULL == scaler) { |
298 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 291 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
299 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 292 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
300 } | 293 } |
301 | 294 |
302 return scaler; | 295 return scaler; |
303 } | 296 } |
OLD | NEW |