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, GrDrawContext* drawContext, | 23 GrTextContext::GrTextContext(GrContext* context, GrDrawContext* drawContext, |
24 const SkSurfaceProps& surfaceProps) | 24 const SkSurfaceProps& surfaceProps) |
25 : fFallbackTextContext(NULL) | 25 : fFallbackTextContext(nullptr) |
26 , fContext(context) | 26 , fContext(context) |
27 , fSurfaceProps(surfaceProps) | 27 , fSurfaceProps(surfaceProps) |
28 , fDrawContext(drawContext) { | 28 , fDrawContext(drawContext) { |
29 } | 29 } |
30 | 30 |
31 GrTextContext::~GrTextContext() { delete fFallbackTextContext; } | 31 GrTextContext::~GrTextContext() { delete fFallbackTextContext; } |
32 | 32 |
33 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, | 33 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, |
34 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 34 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
35 const char text[], size_t byteLength, | 35 const char text[], size_t byteLength, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 const SkPoint& offset, const SkIRect& clip
Bounds) { | 193 const SkPoint& offset, const SkIRect& clip
Bounds) { |
194 // setup our std paint, in hopes of getting hits in the cache | 194 // setup our std paint, in hopes of getting hits in the cache |
195 SkPaint paint(origPaint); | 195 SkPaint paint(origPaint); |
196 SkScalar matrixScale = paint.setupForAsPaths(); | 196 SkScalar matrixScale = paint.setupForAsPaths(); |
197 | 197 |
198 SkMatrix matrix; | 198 SkMatrix matrix; |
199 matrix.setScale(matrixScale, matrixScale); | 199 matrix.setScale(matrixScale, matrixScale); |
200 | 200 |
201 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. | 201 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. |
202 paint.setStyle(SkPaint::kFill_Style); | 202 paint.setStyle(SkPaint::kFill_Style); |
203 paint.setPathEffect(NULL); | 203 paint.setPathEffect(nullptr); |
204 | 204 |
205 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); | 205 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
206 SkAutoGlyphCache autoCache(paint, &fSurfaceProps, NULL); | 206 SkAutoGlyphCache autoCache(paint, &fSurfaceProps, nullptr); |
207 SkGlyphCache* cache = autoCache.getCache(); | 207 SkGlyphCache* cache = autoCache.getCache(); |
208 | 208 |
209 const char* stop = text + byteLength; | 209 const char* stop = text + byteLength; |
210 SkTextAlignProc alignProc(paint.getTextAlign()); | 210 SkTextAlignProc alignProc(paint.getTextAlign()); |
211 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); | 211 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
212 | 212 |
213 // Now restore the original settings, so we "draw" with whatever style/strok
ing. | 213 // Now restore the original settings, so we "draw" with whatever style/strok
ing. |
214 paint.setStyle(origPaint.getStyle()); | 214 paint.setStyle(origPaint.getStyle()); |
215 paint.setPathEffect(origPaint.getPathEffect()); | 215 paint.setPathEffect(origPaint.getPathEffect()); |
216 | 216 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return numGlyphs; | 259 return numGlyphs; |
260 } | 260 } |
261 | 261 |
262 static void GlyphCacheAuxProc(void* data) { | 262 static void GlyphCacheAuxProc(void* data) { |
263 GrFontScaler* scaler = (GrFontScaler*)data; | 263 GrFontScaler* scaler = (GrFontScaler*)data; |
264 SkSafeUnref(scaler); | 264 SkSafeUnref(scaler); |
265 } | 265 } |
266 | 266 |
267 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { | 267 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { |
268 void* auxData; | 268 void* auxData; |
269 GrFontScaler* scaler = NULL; | 269 GrFontScaler* scaler = nullptr; |
270 | 270 |
271 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 271 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
272 scaler = (GrFontScaler*)auxData; | 272 scaler = (GrFontScaler*)auxData; |
273 } | 273 } |
274 if (NULL == scaler) { | 274 if (nullptr == scaler) { |
275 scaler = new GrFontScaler(cache); | 275 scaler = new GrFontScaler(cache); |
276 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 276 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
277 } | 277 } |
278 | 278 |
279 return scaler; | 279 return scaler; |
280 } | 280 } |
OLD | NEW |