OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrStencilAndCoverTextContext.h" | 8 #include "GrStencilAndCoverTextContext.h" |
9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const GrPaint& paint, | 48 const GrPaint& paint, |
49 const SkPaint& skPaint, | 49 const SkPaint& skPaint, |
50 const SkMatrix& viewMatrix) { | 50 const SkMatrix& viewMatrix) { |
51 if (skPaint.getRasterizer()) { | 51 if (skPaint.getRasterizer()) { |
52 return false; | 52 return false; |
53 } | 53 } |
54 if (skPaint.getMaskFilter()) { | 54 if (skPaint.getMaskFilter()) { |
55 return false; | 55 return false; |
56 } | 56 } |
57 if (SkPathEffect* pe = skPaint.getPathEffect()) { | 57 if (SkPathEffect* pe = skPaint.getPathEffect()) { |
58 if (pe->asADash(NULL) != SkPathEffect::kDash_DashType) { | 58 if (pe->asADash(nullptr) != SkPathEffect::kDash_DashType) { |
59 return false; | 59 return false; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 // No hairlines unless we can map the 1 px width to the object space. | 63 // No hairlines unless we can map the 1 px width to the object space. |
64 if (skPaint.getStyle() == SkPaint::kStroke_Style | 64 if (skPaint.getStyle() == SkPaint::kStroke_Style |
65 && skPaint.getStrokeWidth() == 0 | 65 && skPaint.getStrokeWidth() == 0 |
66 && viewMatrix.hasPerspective()) { | 66 && viewMatrix.hasPerspective()) { |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 // No color bitmap fonts. | 70 // No color bitmap fonts. |
71 SkScalerContext::Rec rec; | 71 SkScalerContext::Rec rec; |
72 SkScalerContext::MakeRec(skPaint, &fSurfaceProps, NULL, &rec); | 72 SkScalerContext::MakeRec(skPaint, &fSurfaceProps, nullptr, &rec); |
73 return rec.getFormat() != SkMask::kARGB32_Format; | 73 return rec.getFormat() != SkMask::kARGB32_Format; |
74 } | 74 } |
75 | 75 |
76 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, | 76 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, |
77 const GrClip& clip, | 77 const GrClip& clip, |
78 const GrPaint& paint, | 78 const GrPaint& paint, |
79 const SkPaint& skPaint, | 79 const SkPaint& skPaint, |
80 const SkMatrix& viewMatrix, | 80 const SkMatrix& viewMatrix, |
81 const char text[], | 81 const char text[], |
82 size_t byteLength, | 82 size_t byteLength, |
83 SkScalar x, SkScalar y, | 83 SkScalar x, SkScalar y, |
84 const SkIRect& regionClipBounds) { | 84 const SkIRect& regionClipBounds) { |
85 SkASSERT(byteLength == 0 || text != NULL); | 85 SkASSERT(byteLength == 0 || text != nullptr); |
86 | 86 |
87 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | 87 if (text == nullptr || byteLength == 0 /*|| fRC->isEmpty()*/) { |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 // This is the slow path, mainly used by Skia unit tests. The other | 91 // This is the slow path, mainly used by Skia unit tests. The other |
92 // backends (8888, gpu, ...) use device-space dependent glyph caches. In | 92 // backends (8888, gpu, ...) use device-space dependent glyph caches. In |
93 // order to match the glyph positions that the other code paths produce, we | 93 // order to match the glyph positions that the other code paths produce, we |
94 // must also use device-space dependent glyph cache. This has the | 94 // must also use device-space dependent glyph cache. This has the |
95 // side-effect that the glyph shape outline will be in device-space, | 95 // side-effect that the glyph shape outline will be in device-space, |
96 // too. This in turn has the side-effect that NVPR can not stroke the paths, | 96 // too. This in turn has the side-effect that NVPR can not stroke the paths, |
97 // as the stroke in NVPR is defined in object-space. | 97 // as the stroke in NVPR is defined in object-space. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const GrClip& clip, | 170 const GrClip& clip, |
171 const GrPaint& paint, | 171 const GrPaint& paint, |
172 const SkPaint& skPaint, | 172 const SkPaint& skPaint, |
173 const SkMatrix& viewMatrix, | 173 const SkMatrix& viewMatrix, |
174 const char text[], | 174 const char text[], |
175 size_t byteLength, | 175 size_t byteLength, |
176 const SkScalar pos[], | 176 const SkScalar pos[], |
177 int scalarsPerPosition, | 177 int scalarsPerPosition, |
178 const SkPoint& offset, | 178 const SkPoint& offset, |
179 const SkIRect& regionClipBounds
) { | 179 const SkIRect& regionClipBounds
) { |
180 SkASSERT(byteLength == 0 || text != NULL); | 180 SkASSERT(byteLength == 0 || text != nullptr); |
181 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 181 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
182 | 182 |
183 // nothing to draw | 183 // nothing to draw |
184 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 184 if (text == nullptr || byteLength == 0/* || fRC->isEmpty()*/) { |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 // This is the fast path. Here we do not bake in the device-transform to | 188 // This is the fast path. Here we do not bake in the device-transform to |
189 // the glyph outline or the advances. This is because we do not need to | 189 // the glyph outline or the advances. This is because we do not need to |
190 // position the glyphs at all, since the caller has done the positioning. | 190 // position the glyphs at all, since the caller has done the positioning. |
191 // The positioning is based on SkPaint::measureText of individual | 191 // The positioning is based on SkPaint::measureText of individual |
192 // glyphs. That already uses glyph cache without device transforms. Device | 192 // glyphs. That already uses glyph cache without device transforms. Device |
193 // transform is not part of SkPaint::measureText API, and thus we use the | 193 // transform is not part of SkPaint::measureText API, and thus we use the |
194 // same glyphs as what were measured. | 194 // same glyphs as what were measured. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 reinterpret_cast<uint32_t&>(builder[0]) = desc ? desc->getChecksum() : 0; | 230 reinterpret_cast<uint32_t&>(builder[0]) = desc ? desc->getChecksum() : 0; |
231 reinterpret_cast<uint32_t&>(builder[1]) = typeface ? typeface->uniqueID() :
0; | 231 reinterpret_cast<uint32_t&>(builder[1]) = typeface ? typeface->uniqueID() :
0; |
232 if (strokeDataCount > 0) { | 232 if (strokeDataCount > 0) { |
233 stroke.asUniqueKeyFragment(&builder[2]); | 233 stroke.asUniqueKeyFragment(&builder[2]); |
234 } | 234 } |
235 builder.finish(); | 235 builder.finish(); |
236 | 236 |
237 SkAutoTUnref<GrPathRange> glyphs( | 237 SkAutoTUnref<GrPathRange> glyphs( |
238 static_cast<GrPathRange*>( | 238 static_cast<GrPathRange*>( |
239 ctx->resourceProvider()->findAndRefResourceByUniqueKey(glyphKey))); | 239 ctx->resourceProvider()->findAndRefResourceByUniqueKey(glyphKey))); |
240 if (NULL == glyphs) { | 240 if (nullptr == glyphs) { |
241 glyphs.reset(ctx->resourceProvider()->createGlyphs(typeface, desc, strok
e)); | 241 glyphs.reset(ctx->resourceProvider()->createGlyphs(typeface, desc, strok
e)); |
242 ctx->resourceProvider()->assignUniqueKeyToResource(glyphKey, glyphs); | 242 ctx->resourceProvider()->assignUniqueKeyToResource(glyphKey, glyphs); |
243 } else { | 243 } else { |
244 SkASSERT(NULL == desc || glyphs->isEqualTo(*desc)); | 244 SkASSERT(nullptr == desc || glyphs->isEqualTo(*desc)); |
245 } | 245 } |
246 | 246 |
247 return glyphs.detach(); | 247 return glyphs.detach(); |
248 } | 248 } |
249 | 249 |
250 void GrStencilAndCoverTextContext::init(GrRenderTarget* rt, | 250 void GrStencilAndCoverTextContext::init(GrRenderTarget* rt, |
251 const GrClip& clip, | 251 const GrClip& clip, |
252 const GrPaint& paint, | 252 const GrPaint& paint, |
253 const SkPaint& skPaint, | 253 const SkPaint& skPaint, |
254 size_t textByteLength, | 254 size_t textByteLength, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 fTextRatio = fTextInverseRatio = 1.0f; | 364 fTextRatio = fTextInverseRatio = 1.0f; |
365 canUseRawPaths = false; | 365 canUseRawPaths = false; |
366 } | 366 } |
367 | 367 |
368 SkMatrix textMatrix; | 368 SkMatrix textMatrix; |
369 // Glyphs loaded by GPU path rendering have an inverted y-direction. | 369 // Glyphs loaded by GPU path rendering have an inverted y-direction. |
370 textMatrix.setScale(fTextRatio, -fTextRatio); | 370 textMatrix.setScale(fTextRatio, -fTextRatio); |
371 fViewMatrix.preConcat(textMatrix); | 371 fViewMatrix.preConcat(textMatrix); |
372 fLocalMatrix = textMatrix; | 372 fLocalMatrix = textMatrix; |
373 | 373 |
374 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, NULL, true /*ignoreGa
mma*/); | 374 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, nullptr, true /*ignor
eGamma*/); |
375 fGlyphs = canUseRawPaths ? | 375 fGlyphs = canUseRawPaths ? |
376 get_gr_glyphs(fContext, fSkPaint.getTypeface(), NULL, fStr
oke) : | 376 get_gr_glyphs(fContext, fSkPaint.getTypeface(), nullptr, f
Stroke) : |
377 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), | 377 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), |
378 &fGlyphCache->getDescriptor(), fStroke); | 378 &fGlyphCache->getDescriptor(), fStroke); |
379 } | 379 } |
380 | 380 |
381 } | 381 } |
382 | 382 |
383 bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) { | 383 bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) { |
384 // The current view matrix is flipped because GPU path rendering glyphs have
an | 384 // The current view matrix is flipped because GPU path rendering glyphs have
an |
385 // inverted y-direction. Unflip the view matrix for the fallback context. If
using | 385 // inverted y-direction. Unflip the view matrix for the fallback context. If
using |
386 // device-space glyphs, we'll also need to restore the original view matrix
since | 386 // device-space glyphs, we'll also need to restore the original view matrix
since |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 2, SkPoint::Make(0, 0), fRegionClipBou
nds); | 479 2, SkPoint::Make(0, 0), fRegionClipBou
nds); |
480 | 480 |
481 fFallbackGlyphsIdx = kGlyphBufferSize; | 481 fFallbackGlyphsIdx = kGlyphBufferSize; |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 void GrStencilAndCoverTextContext::finish() { | 485 void GrStencilAndCoverTextContext::finish() { |
486 this->flush(); | 486 this->flush(); |
487 | 487 |
488 fGlyphs->unref(); | 488 fGlyphs->unref(); |
489 fGlyphs = NULL; | 489 fGlyphs = nullptr; |
490 | 490 |
491 SkGlyphCache::AttachCache(fGlyphCache); | 491 SkGlyphCache::AttachCache(fGlyphCache); |
492 fGlyphCache = NULL; | 492 fGlyphCache = nullptr; |
493 | 493 |
494 fViewMatrix = fContextInitialMatrix; | 494 fViewMatrix = fContextInitialMatrix; |
495 } | 495 } |
496 | 496 |
OLD | NEW |