| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, | 50 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, |
| 51 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 51 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 52 const char text[], size_t byteLength, | 52 const char text[], size_t byteLength, |
| 53 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | 53 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ |
| 54 if (!fContext->getTextTarget()) { | 54 if (!fContext->getTextTarget()) { |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 | 57 |
| 58 GrTextContext* textContext = this; | 58 GrTextContext* textContext = this; |
| 59 do { | 59 do { |
| 60 if (textContext->canDraw(skPaint, viewMatrix)) { | 60 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
| 61 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y, | 61 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y, |
| 62 clipBounds); | 62 clipBounds); |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 textContext = textContext->fFallbackTextContext; | 65 textContext = textContext->fFallbackTextContext; |
| 66 } while (textContext); | 66 } while (textContext); |
| 67 | 67 |
| 68 // fall back to drawing as a path | 68 // fall back to drawing as a path |
| 69 this->drawTextAsPath(skPaint, viewMatrix, text, byteLength, x, y, clipBounds
); | 69 this->drawTextAsPath(skPaint, viewMatrix, text, byteLength, x, y, clipBounds
); |
| 70 } | 70 } |
| 71 | 71 |
| 72 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, |
| 73 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, | 73 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, |
| 74 const char text[], size_t byteLength, | 74 const char text[], size_t byteLength, |
| 75 const SkScalar pos[], int scalarsPerPosition, | 75 const SkScalar pos[], int scalarsPerPosition, |
| 76 const SkPoint& offset, const SkIRect& clipBounds
) { | 76 const SkPoint& offset, const SkIRect& clipBounds
) { |
| 77 if (!fContext->getTextTarget()) { | 77 if (!fContext->getTextTarget()) { |
| 78 return; | 78 return; |
| 79 } | 79 } |
| 80 | 80 |
| 81 GrTextContext* textContext = this; | 81 GrTextContext* textContext = this; |
| 82 do { | 82 do { |
| 83 if (textContext->canDraw(skPaint, viewMatrix)) { | 83 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
| 84 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, | 84 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, |
| 85 scalarsPerPosition, offset, clipBounds); | 85 scalarsPerPosition, offset, clipBounds); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 textContext = textContext->fFallbackTextContext; | 88 textContext = textContext->fFallbackTextContext; |
| 89 } while (textContext); | 89 } while (textContext); |
| 90 | 90 |
| 91 // fall back to drawing as a path | 91 // fall back to drawing as a path |
| 92 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP
erPosition, offset, | 92 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP
erPosition, offset, |
| 93 clipBounds); | 93 clipBounds); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GrTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S
kPaint& skPaint, | 96 void GrTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S
kPaint& skPaint, |
| 97 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | 97 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
| 98 SkScalar x, SkScalar y, | 98 SkScalar x, SkScalar y, |
| 99 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { | 99 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { |
| 100 if (!fContext->getTextTarget()) { | 100 SkPaint runPaint = skPaint; |
| 101 return; | 101 |
| 102 SkTextBlob::RunIterator it(blob); |
| 103 for (;!it.done(); it.next()) { |
| 104 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 105 const SkPoint& offset = it.offset(); |
| 106 // applyFontToPaint() always overwrites the exact same attributes, |
| 107 // so it is safe to not re-seed the paint for this reason. |
| 108 it.applyFontToPaint(&runPaint); |
| 109 |
| 110 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
| 111 // A false return from filter() means we should abort the current dr
aw. |
| 112 runPaint = skPaint; |
| 113 continue; |
| 114 } |
| 115 |
| 116 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); |
| 117 |
| 118 GrPaint grPaint; |
| 119 SkPaint2GrPaintShader(fContext, fRenderTarget, runPaint, viewMatrix, tru
e, &grPaint); |
| 120 |
| 121 switch (it.positioning()) { |
| 122 case SkTextBlob::kDefault_Positioning: |
| 123 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), |
| 124 textLen, x + offset.x(), y + offset.y(), clipBounds); |
| 125 break; |
| 126 case SkTextBlob::kHorizontal_Positioning: |
| 127 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 128 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.
y()), clipBounds); |
| 129 break; |
| 130 case SkTextBlob::kFull_Positioning: |
| 131 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 132 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou
nds); |
| 133 break; |
| 134 default: |
| 135 SkFAIL("unhandled positioning mode"); |
| 136 } |
| 137 |
| 138 if (drawFilter) { |
| 139 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
| 140 runPaint = skPaint; |
| 141 } |
| 102 } | 142 } |
| 103 | |
| 104 GrTextContext* textContext = this; | |
| 105 do { | |
| 106 if (textContext->canDraw(skPaint, viewMatrix)) { | |
| 107 textContext->onDrawTextBlob(rt, clip, skPaint, viewMatrix, blob, x,
y, drawFilter, | |
| 108 clipBounds); | |
| 109 return; | |
| 110 } | |
| 111 textContext = textContext->fFallbackTextContext; | |
| 112 } while (textContext); | |
| 113 } | 143 } |
| 114 | 144 |
| 115 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM
atrix, | 145 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM
atrix, |
| 116 const char text[], size_t byteLength, SkScala
r x, SkScalar y, | 146 const char text[], size_t byteLength, SkScala
r x, SkScalar y, |
| 117 const SkIRect& clipBounds) { | 147 const SkIRect& clipBounds) { |
| 118 SkTextToPathIter iter(text, byteLength, skPaint, true); | 148 SkTextToPathIter iter(text, byteLength, skPaint, true); |
| 119 | 149 |
| 120 SkMatrix matrix; | 150 SkMatrix matrix; |
| 121 matrix.setScale(iter.getPathScale(), iter.getPathScale()); | 151 matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 122 matrix.postTranslate(x, y); | 152 matrix.postTranslate(x, y); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 203 |
| 174 matrix[SkMatrix::kMTransX] = loc.fX; | 204 matrix[SkMatrix::kMTransX] = loc.fX; |
| 175 matrix[SkMatrix::kMTransY] = loc.fY; | 205 matrix[SkMatrix::kMTransY] = loc.fY; |
| 176 fGpuDevice->internalDrawPath(*path, paint, viewMatrix, &matrix,
clipBounds, false); | 206 fGpuDevice->internalDrawPath(*path, paint, viewMatrix, &matrix,
clipBounds, false); |
| 177 } | 207 } |
| 178 } | 208 } |
| 179 pos += scalarsPerPosition; | 209 pos += scalarsPerPosition; |
| 180 } | 210 } |
| 181 } | 211 } |
| 182 | 212 |
| 183 void GrTextContext::onDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, | |
| 184 const SkPaint& skPaint, const SkMatrix& viewM
atrix, | |
| 185 const SkTextBlob* blob, SkScalar x, SkScalar
y, | |
| 186 SkDrawFilter* drawFilter, const SkIRect& clip
Bounds) { | |
| 187 SkPaint runPaint = skPaint; | |
| 188 | |
| 189 SkTextBlob::RunIterator it(blob); | |
| 190 for (;!it.done(); it.next()) { | |
| 191 size_t textLen = it.glyphCount() * sizeof(uint16_t); | |
| 192 const SkPoint& offset = it.offset(); | |
| 193 // applyFontToPaint() always overwrites the exact same attributes, | |
| 194 // so it is safe to not re-seed the paint for this reason. | |
| 195 it.applyFontToPaint(&runPaint); | |
| 196 | |
| 197 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | |
| 198 // A false return from filter() means we should abort the current dr
aw. | |
| 199 runPaint = skPaint; | |
| 200 continue; | |
| 201 } | |
| 202 | |
| 203 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); | |
| 204 | |
| 205 GrPaint grPaint; | |
| 206 SkPaint2GrPaintShader(fContext, fRenderTarget, runPaint, viewMatrix, tru
e, &grPaint); | |
| 207 | |
| 208 switch (it.positioning()) { | |
| 209 case SkTextBlob::kDefault_Positioning: | |
| 210 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), | |
| 211 textLen, x + offset.x(), y + offset.y(), clipBounds); | |
| 212 break; | |
| 213 case SkTextBlob::kHorizontal_Positioning: | |
| 214 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), | |
| 215 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.
y()), clipBounds); | |
| 216 break; | |
| 217 case SkTextBlob::kFull_Positioning: | |
| 218 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), | |
| 219 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou
nds); | |
| 220 break; | |
| 221 default: | |
| 222 SkFAIL("unhandled positioning mode"); | |
| 223 } | |
| 224 | |
| 225 if (drawFilter) { | |
| 226 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | |
| 227 runPaint = skPaint; | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 //*** change to output positions? | 213 //*** change to output positions? |
| 233 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr
oc, | 214 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr
oc, |
| 234 const char text[], size_t byteLength, SkVector*
stopVector) { | 215 const char text[], size_t byteLength, SkVector*
stopVector) { |
| 235 SkFixed x = 0, y = 0; | 216 SkFixed x = 0, y = 0; |
| 236 const char* stop = text + byteLength; | 217 const char* stop = text + byteLength; |
| 237 | 218 |
| 238 SkAutoKern autokern; | 219 SkAutoKern autokern; |
| 239 | 220 |
| 240 int numGlyphs = 0; | 221 int numGlyphs = 0; |
| 241 while (text < stop) { | 222 while (text < stop) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 266 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 247 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 267 scaler = (GrFontScaler*)auxData; | 248 scaler = (GrFontScaler*)auxData; |
| 268 } | 249 } |
| 269 if (NULL == scaler) { | 250 if (NULL == scaler) { |
| 270 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 251 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
| 271 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 252 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 272 } | 253 } |
| 273 | 254 |
| 274 return scaler; | 255 return scaler; |
| 275 } | 256 } |
| OLD | NEW |