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 SkDeviceProperties& properties) | 24 const SkSurfaceProps& surfaceProps) |
25 : fFallbackTextContext(NULL) | 25 : fFallbackTextContext(NULL) |
26 , fContext(context) | 26 , fContext(context) |
27 , fDeviceProperties(properties) | 27 , fSurfaceProps(surfaceProps) |
28 , fDrawContext(drawContext) { | 28 , fDrawContext(drawContext) { |
29 } | 29 } |
30 | 30 |
31 GrTextContext::~GrTextContext() { | 31 GrTextContext::~GrTextContext() { |
32 SkDELETE(fFallbackTextContext); | 32 SkDELETE(fFallbackTextContext); |
33 } | 33 } |
34 | 34 |
35 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, | 35 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, |
36 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { | 36 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { |
37 fClip = clip; | 37 fClip = clip; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 paint.getColorFilter() || | 101 paint.getColorFilter() || |
102 paint.getPathEffect() || | 102 paint.getPathEffect() || |
103 paint.isFakeBoldText() || | 103 paint.isFakeBoldText() || |
104 paint.getStyle() != SkPaint::kFill_Style) | 104 paint.getStyle() != SkPaint::kFill_Style) |
105 { | 105 { |
106 return true; | 106 return true; |
107 } | 107 } |
108 return false; | 108 return false; |
109 } | 109 } |
110 | 110 |
111 uint32_t GrTextContext::FilterTextFlags(const SkDeviceProperties& devProps, cons
t SkPaint& paint) { | 111 uint32_t GrTextContext::FilterTextFlags(const SkSurfaceProps& surfaceProps, cons
t SkPaint& paint) { |
112 uint32_t flags = paint.getFlags(); | 112 uint32_t flags = paint.getFlags(); |
113 | 113 |
114 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | 114 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
115 return flags; | 115 return flags; |
116 } | 116 } |
117 | 117 |
118 if (kUnknown_SkPixelGeometry == devProps.pixelGeometry() || ShouldDisableLCD
(paint)) { | 118 if (kUnknown_SkPixelGeometry == surfaceProps.pixelGeometry() || ShouldDisabl
eLCD(paint)) { |
119 flags &= ~SkPaint::kLCDRenderText_Flag; | 119 flags &= ~SkPaint::kLCDRenderText_Flag; |
120 flags |= SkPaint::kGenA8FromLCD_Flag; | 120 flags |= SkPaint::kGenA8FromLCD_Flag; |
121 } | 121 } |
122 | 122 |
123 return flags; | 123 return flags; |
124 } | 124 } |
125 | 125 |
126 void GrTextContext::drawTextBlob(GrRenderTarget* rt, | 126 void GrTextContext::drawTextBlob(GrRenderTarget* rt, |
127 const GrClip& clip, const SkPaint& skPaint, | 127 const GrClip& clip, const SkPaint& skPaint, |
128 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | 128 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
129 SkScalar x, SkScalar y, | 129 SkScalar x, SkScalar y, |
130 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { | 130 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { |
131 SkPaint runPaint = skPaint; | 131 SkPaint runPaint = skPaint; |
132 | 132 |
133 SkTextBlob::RunIterator it(blob); | 133 SkTextBlob::RunIterator it(blob); |
134 for (;!it.done(); it.next()) { | 134 for (;!it.done(); it.next()) { |
135 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 135 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
136 const SkPoint& offset = it.offset(); | 136 const SkPoint& offset = it.offset(); |
137 // applyFontToPaint() always overwrites the exact same attributes, | 137 // applyFontToPaint() always overwrites the exact same attributes, |
138 // so it is safe to not re-seed the paint for this reason. | 138 // so it is safe to not re-seed the paint for this reason. |
139 it.applyFontToPaint(&runPaint); | 139 it.applyFontToPaint(&runPaint); |
140 | 140 |
141 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | 141 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
142 // A false return from filter() means we should abort the current dr
aw. | 142 // A false return from filter() means we should abort the current dr
aw. |
143 runPaint = skPaint; | 143 runPaint = skPaint; |
144 continue; | 144 continue; |
145 } | 145 } |
146 | 146 |
147 runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); | 147 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); |
148 | 148 |
149 GrPaint grPaint; | 149 GrPaint grPaint; |
150 if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true
, &grPaint)) { | 150 if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true
, &grPaint)) { |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 switch (it.positioning()) { | 154 switch (it.positioning()) { |
155 case SkTextBlob::kDefault_Positioning: | 155 case SkTextBlob::kDefault_Positioning: |
156 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), | 156 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), |
157 textLen, x + offset.x(), y + offset.y(), clipBounds); | 157 textLen, x + offset.x(), y + offset.y(), clipBounds); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 286 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
287 scaler = (GrFontScaler*)auxData; | 287 scaler = (GrFontScaler*)auxData; |
288 } | 288 } |
289 if (NULL == scaler) { | 289 if (NULL == scaler) { |
290 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 290 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
291 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 291 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
292 } | 292 } |
293 | 293 |
294 return scaler; | 294 return scaler; |
295 } | 295 } |
OLD | NEW |