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" | 10 #include "GrDrawTarget.h" |
11 #include "GrFontScaler.h" | 11 #include "GrFontScaler.h" |
12 | 12 |
13 #include "SkAutoKern.h" | 13 #include "SkAutoKern.h" |
| 14 #include "SkDrawFilter.h" |
14 #include "SkDrawProcs.h" | 15 #include "SkDrawProcs.h" |
15 #include "SkGlyphCache.h" | 16 #include "SkGlyphCache.h" |
16 #include "SkGpuDevice.h" | 17 #include "SkGpuDevice.h" |
| 18 #include "SkTextBlob.h" |
17 #include "SkTextMapStateProc.h" | 19 #include "SkTextMapStateProc.h" |
18 #include "SkTextToPathIter.h" | 20 #include "SkTextToPathIter.h" |
19 | 21 |
20 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice, | 22 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice, |
21 const SkDeviceProperties& properties) | 23 const SkDeviceProperties& properties) |
22 : fFallbackTextContext(NULL) | 24 : fFallbackTextContext(NULL) |
23 , fContext(context) | 25 , fContext(context) |
24 , fGpuDevice(gpuDevice) | 26 , fGpuDevice(gpuDevice) |
25 , fDeviceProperties(properties) | 27 , fDeviceProperties(properties) |
26 , fDrawTarget(NULL) { | 28 , fDrawTarget(NULL) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return; | 84 return; |
83 } | 85 } |
84 textContext = textContext->fFallbackTextContext; | 86 textContext = textContext->fFallbackTextContext; |
85 } while (textContext); | 87 } while (textContext); |
86 | 88 |
87 // fall back to drawing as a path | 89 // fall back to drawing as a path |
88 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP
erPosition, offset, | 90 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP
erPosition, offset, |
89 clipBounds); | 91 clipBounds); |
90 } | 92 } |
91 | 93 |
| 94 void GrTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S
kPaint& skPaint, |
| 95 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
| 96 SkScalar x, SkScalar y, |
| 97 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { |
| 98 SkPaint runPaint = skPaint; |
| 99 |
| 100 SkTextBlob::RunIterator it(blob); |
| 101 for (;!it.done(); it.next()) { |
| 102 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 103 const SkPoint& offset = it.offset(); |
| 104 // applyFontToPaint() always overwrites the exact same attributes, |
| 105 // so it is safe to not re-seed the paint for this reason. |
| 106 it.applyFontToPaint(&runPaint); |
| 107 |
| 108 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
| 109 // A false return from filter() means we should abort the current dr
aw. |
| 110 runPaint = skPaint; |
| 111 continue; |
| 112 } |
| 113 |
| 114 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); |
| 115 |
| 116 GrPaint grPaint; |
| 117 SkPaint2GrPaintShader(fContext, fRenderTarget, runPaint, viewMatrix, tru
e, &grPaint); |
| 118 |
| 119 switch (it.positioning()) { |
| 120 case SkTextBlob::kDefault_Positioning: |
| 121 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), |
| 122 textLen, x + offset.x(), y + offset.y(), clipBounds); |
| 123 break; |
| 124 case SkTextBlob::kHorizontal_Positioning: |
| 125 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 126 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.
y()), clipBounds); |
| 127 break; |
| 128 case SkTextBlob::kFull_Positioning: |
| 129 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 130 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou
nds); |
| 131 break; |
| 132 default: |
| 133 SkFAIL("unhandled positioning mode"); |
| 134 } |
| 135 |
| 136 if (drawFilter) { |
| 137 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
| 138 runPaint = skPaint; |
| 139 } |
| 140 } |
| 141 } |
| 142 |
92 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM
atrix, | 143 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM
atrix, |
93 const char text[], size_t byteLength, SkScala
r x, SkScalar y, | 144 const char text[], size_t byteLength, SkScala
r x, SkScalar y, |
94 const SkIRect& clipBounds) { | 145 const SkIRect& clipBounds) { |
95 SkTextToPathIter iter(text, byteLength, skPaint, true); | 146 SkTextToPathIter iter(text, byteLength, skPaint, true); |
96 | 147 |
97 SkMatrix matrix; | 148 SkMatrix matrix; |
98 matrix.setScale(iter.getPathScale(), iter.getPathScale()); | 149 matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
99 matrix.postTranslate(x, y); | 150 matrix.postTranslate(x, y); |
100 | 151 |
101 const SkPath* iterPath; | 152 const SkPath* iterPath; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 245 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
195 scaler = (GrFontScaler*)auxData; | 246 scaler = (GrFontScaler*)auxData; |
196 } | 247 } |
197 if (NULL == scaler) { | 248 if (NULL == scaler) { |
198 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 249 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
199 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 250 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
200 } | 251 } |
201 | 252 |
202 return scaler; | 253 return scaler; |
203 } | 254 } |
OLD | NEW |