| 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" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 textContext = textContext->fFallbackTextContext; | 96 textContext = textContext->fFallbackTextContext; |
| 97 } while (textContext); | 97 } while (textContext); |
| 98 | 98 |
| 99 // fall back to drawing as a path | 99 // fall back to drawing as a path |
| 100 this->drawPosTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, text, by
teLength, pos, | 100 this->drawPosTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, text, by
teLength, pos, |
| 101 scalarsPerPosition, offset, clipBounds); | 101 scalarsPerPosition, offset, clipBounds); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void GrTextContext::drawTextBlob(SkGpuDevice* gpuDevice, GrRenderTarget* rt, | 104 bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) { |
| 105 if (paint.getShader() || |
| 106 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || |
| 107 paint.getMaskFilter() || |
| 108 paint.getRasterizer() || |
| 109 paint.getColorFilter() || |
| 110 paint.getPathEffect() || |
| 111 paint.isFakeBoldText() || |
| 112 paint.getStyle() != SkPaint::kFill_Style) |
| 113 { |
| 114 return true; |
| 115 } |
| 116 return false; |
| 117 } |
| 118 |
| 119 uint32_t GrTextContext::FilterTextFlags(const SkDeviceProperties& devProps, cons
t SkPaint& paint) { |
| 120 uint32_t flags = paint.getFlags(); |
| 121 |
| 122 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
| 123 return flags; |
| 124 } |
| 125 |
| 126 if (kUnknown_SkPixelGeometry == devProps.pixelGeometry() || ShouldDisableLCD
(paint)) { |
| 127 flags &= ~SkPaint::kLCDRenderText_Flag; |
| 128 flags |= SkPaint::kGenA8FromLCD_Flag; |
| 129 } |
| 130 |
| 131 return flags; |
| 132 } |
| 133 |
| 134 void GrTextContext::drawTextBlob(GrRenderTarget* rt, |
| 105 const GrClip& clip, const SkPaint& skPaint, | 135 const GrClip& clip, const SkPaint& skPaint, |
| 106 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | 136 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
| 107 SkScalar x, SkScalar y, | 137 SkScalar x, SkScalar y, |
| 108 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { | 138 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { |
| 109 SkPaint runPaint = skPaint; | 139 SkPaint runPaint = skPaint; |
| 110 | 140 |
| 111 SkTextBlob::RunIterator it(blob); | 141 SkTextBlob::RunIterator it(blob); |
| 112 for (;!it.done(); it.next()) { | 142 for (;!it.done(); it.next()) { |
| 113 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 143 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 114 const SkPoint& offset = it.offset(); | 144 const SkPoint& offset = it.offset(); |
| 115 // applyFontToPaint() always overwrites the exact same attributes, | 145 // applyFontToPaint() always overwrites the exact same attributes, |
| 116 // so it is safe to not re-seed the paint for this reason. | 146 // so it is safe to not re-seed the paint for this reason. |
| 117 it.applyFontToPaint(&runPaint); | 147 it.applyFontToPaint(&runPaint); |
| 118 | 148 |
| 119 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | 149 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
| 120 // A false return from filter() means we should abort the current dr
aw. | 150 // A false return from filter() means we should abort the current dr
aw. |
| 121 runPaint = skPaint; | 151 runPaint = skPaint; |
| 122 continue; | 152 continue; |
| 123 } | 153 } |
| 124 | 154 |
| 125 runPaint.setFlags(gpuDevice->filterTextFlags(runPaint)); | 155 runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); |
| 126 | 156 |
| 127 GrPaint grPaint; | 157 GrPaint grPaint; |
| 128 if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true
, &grPaint)) { | 158 if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true
, &grPaint)) { |
| 129 return; | 159 return; |
| 130 } | 160 } |
| 131 | 161 |
| 132 switch (it.positioning()) { | 162 switch (it.positioning()) { |
| 133 case SkTextBlob::kDefault_Positioning: | 163 case SkTextBlob::kDefault_Positioning: |
| 134 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), | 164 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), |
| 135 textLen, x + offset.x(), y + offset.y(), clipBounds); | 165 textLen, x + offset.x(), y + offset.y(), clipBounds); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 294 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 265 scaler = (GrFontScaler*)auxData; | 295 scaler = (GrFontScaler*)auxData; |
| 266 } | 296 } |
| 267 if (NULL == scaler) { | 297 if (NULL == scaler) { |
| 268 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 298 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
| 269 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 299 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 270 } | 300 } |
| 271 | 301 |
| 272 return scaler; | 302 return scaler; |
| 273 } | 303 } |
| OLD | NEW |