Chromium Code Reviews| 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 "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 const GrClip& clip, | 48 const GrClip& clip, |
| 49 const GrPaint& paint, | 49 const GrPaint& paint, |
| 50 const SkPaint& skPaint, | 50 const SkPaint& skPaint, |
| 51 const SkMatrix& viewMatrix) { | 51 const SkMatrix& viewMatrix) { |
| 52 if (skPaint.getRasterizer()) { | 52 if (skPaint.getRasterizer()) { |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 if (skPaint.getMaskFilter()) { | 55 if (skPaint.getMaskFilter()) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 if (skPaint.getPathEffect()) { | 58 if (SkPathEffect* pe = skPaint.getPathEffect()) { |
| 59 return false; | 59 if (pe->asADash(NULL) != SkPathEffect::kDash_DashType) { |
| 60 return false; | |
| 61 } | |
| 60 } | 62 } |
| 61 | 63 |
| 62 // No hairlines unless we can map the 1 px width to the object space. | 64 // No hairlines unless we can map the 1 px width to the object space. |
| 63 if (skPaint.getStyle() == SkPaint::kStroke_Style | 65 if (skPaint.getStyle() == SkPaint::kStroke_Style |
| 64 && skPaint.getStrokeWidth() == 0 | 66 && skPaint.getStrokeWidth() == 0 |
| 65 && viewMatrix.hasPerspective()) { | 67 && viewMatrix.hasPerspective()) { |
| 66 return false; | 68 return false; |
| 67 } | 69 } |
| 68 | 70 |
| 69 // No color bitmap fonts. | 71 // No color bitmap fonts. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 } | 215 } |
| 214 pos += scalarsPerPosition; | 216 pos += scalarsPerPosition; |
| 215 } | 217 } |
| 216 | 218 |
| 217 this->finish(); | 219 this->finish(); |
| 218 } | 220 } |
| 219 | 221 |
| 220 static GrPathRange* get_gr_glyphs(GrContext* ctx, | 222 static GrPathRange* get_gr_glyphs(GrContext* ctx, |
| 221 const SkTypeface* typeface, | 223 const SkTypeface* typeface, |
| 222 const SkDescriptor* desc, | 224 const SkDescriptor* desc, |
| 223 const SkStrokeRec& stroke) { | 225 const GrStrokeInfo& stroke) { |
| 224 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 226 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 225 GrUniqueKey key; | 227 GrUniqueKey key; |
| 226 GrUniqueKey::Builder builder(&key, kDomain, 4); | 228 GrUniqueKey::Builder builder(&key, kDomain, 4); |
| 227 struct GlyphKey { | 229 struct GlyphKey { |
| 228 uint32_t fChecksum; | 230 uint32_t fChecksum; |
| 229 uint32_t fTypeface; | 231 uint32_t fTypeface; |
| 230 uint64_t fStroke; | 232 uint64_t fStroke; |
| 231 }; | 233 }; |
| 232 GlyphKey* glyphKey = reinterpret_cast<GlyphKey*>(&builder[0]); | 234 GlyphKey* glyphKey = reinterpret_cast<GlyphKey*>(&builder[0]); |
| 233 glyphKey->fChecksum = desc ? desc->getChecksum() : 0; | 235 glyphKey->fChecksum = desc ? desc->getChecksum() : 0; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 kMaxAccuracy_RenderMode == renderMode && | 268 kMaxAccuracy_RenderMode == renderMode && |
| 267 SkToBool(fContextInitialMatrix.getType() & | 269 SkToBool(fContextInitialMatrix.getType() & |
| 268 (SkMatrix::kScale_Mask | SkMatrix::kAffin e_Mask)); | 270 (SkMatrix::kScale_Mask | SkMatrix::kAffin e_Mask)); |
| 269 | 271 |
| 270 if (fUsingDeviceSpaceGlyphs) { | 272 if (fUsingDeviceSpaceGlyphs) { |
| 271 // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms. | 273 // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms. |
| 272 SkASSERT(!fContextInitialMatrix.hasPerspective()); | 274 SkASSERT(!fContextInitialMatrix.hasPerspective()); |
| 273 | 275 |
| 274 // The whole shape (including stroke) will be baked into the glyph outli nes. Make | 276 // The whole shape (including stroke) will be baked into the glyph outli nes. Make |
| 275 // NVPR just fill the baked shapes. | 277 // NVPR just fill the baked shapes. |
| 276 fStroke = SkStrokeRec(SkStrokeRec::kFill_InitStyle); | 278 fStroke = GrStrokeInfo(SkStrokeRec::kFill_InitStyle); |
| 277 | 279 |
| 278 fTextRatio = fTextInverseRatio = 1.0f; | 280 fTextRatio = fTextInverseRatio = 1.0f; |
| 279 | 281 |
| 280 // Glyphs loaded by GPU path rendering have an inverted y-direction. | 282 // Glyphs loaded by GPU path rendering have an inverted y-direction. |
| 281 SkMatrix m; | 283 SkMatrix m; |
| 282 m.setScale(1, -1); | 284 m.setScale(1, -1); |
| 283 fViewMatrix = m; | 285 fViewMatrix = m; |
| 284 | 286 |
| 285 // Post-flip the initial matrix so we're left with just the flip after | 287 // Post-flip the initial matrix so we're left with just the flip after |
| 286 // the paint preConcats the inverse. | 288 // the paint preConcats the inverse. |
| 287 m = fContextInitialMatrix; | 289 m = fContextInitialMatrix; |
| 288 m.postScale(1, -1); | 290 m.postScale(1, -1); |
| 289 if (!m.invert(&fLocalMatrix)) { | 291 if (!m.invert(&fLocalMatrix)) { |
| 290 SkDebugf("Not invertible!\n"); | 292 SkDebugf("Not invertible!\n"); |
| 291 return; | 293 return; |
| 292 } | 294 } |
| 293 | 295 |
| 294 fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, &fContextInitialM atrix, | 296 fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, &fContextInitialM atrix, |
| 295 true /*ignoreGamma*/); | 297 true /*ignoreGamma*/); |
| 296 fGlyphs = get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->getTy peface(), | 298 fGlyphs = get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->getTy peface(), |
| 297 &fGlyphCache->getDescriptor(), fStroke); | 299 &fGlyphCache->getDescriptor(), fStroke); |
| 298 } else { | 300 } else { |
| 299 // Don't bake strokes into the glyph outlines. We will stroke the glyphs | 301 // Don't bake strokes into the glyph outlines. We will stroke the glyphs |
| 300 // using the GPU instead. This is the fast path. | 302 // using the GPU instead. This is the fast path. |
| 301 fStroke = SkStrokeRec(fSkPaint); | 303 fStroke = GrStrokeInfo(fSkPaint); |
| 304 SkStrokeRec* strokeRec = fStroke.getStrokeRecPtr(); | |
| 302 fSkPaint.setStyle(SkPaint::kFill_Style); | 305 fSkPaint.setStyle(SkPaint::kFill_Style); |
| 303 | 306 |
| 304 if (fStroke.isHairlineStyle()) { | 307 if (strokeRec->isHairlineStyle()) { |
| 305 // Approximate hairline stroke. | 308 // Approximate hairline stroke. |
| 306 SkScalar strokeWidth = SK_Scalar1 / | 309 SkScalar strokeWidth = SK_Scalar1 / |
| 307 (SkVector::Make(fContextInitialMatrix.getScaleX(), | 310 (SkVector::Make(fContextInitialMatrix.getScaleX(), |
| 308 fContextInitialMatrix.getSkewY()).length()); | 311 fContextInitialMatrix.getSkewY()).length()); |
| 309 fStroke.setStrokeStyle(strokeWidth, false /*strokeAndFill*/); | 312 strokeRec->setStrokeStyle(strokeWidth, false /*strokeAndFill*/); |
| 310 | 313 |
| 311 } else if (fSkPaint.isFakeBoldText() && | 314 } else if (fSkPaint.isFakeBoldText() && |
| 312 #ifdef SK_USE_FREETYPE_EMBOLDEN | 315 #ifdef SK_USE_FREETYPE_EMBOLDEN |
| 313 kMaxPerformance_RenderMode == renderMode && | 316 kMaxPerformance_RenderMode == renderMode && |
| 314 #endif | 317 #endif |
| 315 SkStrokeRec::kStroke_Style != fStroke.getStyle()) { | 318 SkStrokeRec::kStroke_Style != strokeRec->getStyle()) { |
| 316 | 319 |
| 317 // Instead of baking fake bold into the glyph outlines, do it with t he GPU stroke. | 320 // Instead of baking fake bold into the glyph outlines, do it with t he GPU stroke. |
| 318 SkScalar fakeBoldScale = SkScalarInterpFunc(fSkPaint.getTextSize(), | 321 SkScalar fakeBoldScale = SkScalarInterpFunc(fSkPaint.getTextSize(), |
| 319 kStdFakeBoldInterpKeys, | 322 kStdFakeBoldInterpKeys, |
| 320 kStdFakeBoldInterpValues , | 323 kStdFakeBoldInterpValues , |
| 321 kStdFakeBoldInterpLength ); | 324 kStdFakeBoldInterpLength ); |
| 322 SkScalar extra = SkScalarMul(fSkPaint.getTextSize(), fakeBoldScale); | 325 SkScalar extra = SkScalarMul(fSkPaint.getTextSize(), fakeBoldScale); |
| 323 fStroke.setStrokeStyle(fStroke.needToApply() ? fStroke.getWidth() + extra : extra, | 326 strokeRec->setStrokeStyle(strokeRec->needToApply() ? strokeRec->getW idth() + extra : extra, |
| 324 true /*strokeAndFill*/); | 327 true /*strokeAndFill*/); |
| 325 | 328 |
| 326 fSkPaint.setFakeBoldText(false); | 329 fSkPaint.setFakeBoldText(false); |
| 327 } | 330 } |
| 328 | 331 |
| 329 bool canUseRawPaths; | 332 bool canUseRawPaths; |
| 330 | 333 if (!fStroke.isDashed() && (otherBackendsWillDrawAsPaths || kMaxPerforma nce_RenderMode == renderMode)) { |
|
egdaniel
2015/05/05 19:48:44
100 chars
Kimmo Kinnunen
2015/05/06 08:30:25
Done.
| |
| 331 if (otherBackendsWillDrawAsPaths || kMaxPerformance_RenderMode == render Mode) { | |
| 332 // We can draw the glyphs from canonically sized paths. | 334 // We can draw the glyphs from canonically sized paths. |
| 333 fTextRatio = fSkPaint.getTextSize() / SkPaint::kCanonicalTextSizeFor Paths; | 335 fTextRatio = fSkPaint.getTextSize() / SkPaint::kCanonicalTextSizeFor Paths; |
| 334 fTextInverseRatio = SkPaint::kCanonicalTextSizeForPaths / fSkPaint.g etTextSize(); | 336 fTextInverseRatio = SkPaint::kCanonicalTextSizeForPaths / fSkPaint.g etTextSize(); |
| 335 | 337 |
| 336 // Compensate for the glyphs being scaled by fTextRatio. | 338 // Compensate for the glyphs being scaled by fTextRatio. |
| 337 if (!fStroke.isFillStyle()) { | 339 if (!strokeRec->isFillStyle()) { |
| 338 fStroke.setStrokeStyle(fStroke.getWidth() / fTextRatio, | 340 strokeRec->setStrokeStyle(strokeRec->getWidth() / fTextRatio, |
| 339 SkStrokeRec::kStrokeAndFill_Style == fStr oke.getStyle()); | 341 SkStrokeRec::kStrokeAndFill_Style == stro keRec->getStyle()); |
| 340 } | 342 } |
| 341 | 343 |
| 342 fSkPaint.setLinearText(true); | 344 fSkPaint.setLinearText(true); |
| 343 fSkPaint.setLCDRenderText(false); | 345 fSkPaint.setLCDRenderText(false); |
| 344 fSkPaint.setAutohinted(false); | 346 fSkPaint.setAutohinted(false); |
| 345 fSkPaint.setHinting(SkPaint::kNo_Hinting); | 347 fSkPaint.setHinting(SkPaint::kNo_Hinting); |
| 346 fSkPaint.setSubpixelText(true); | 348 fSkPaint.setSubpixelText(true); |
| 347 fSkPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPat hs)); | 349 fSkPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPat hs)); |
| 348 | 350 |
| 349 canUseRawPaths = SK_Scalar1 == fSkPaint.getTextScaleX() && | 351 canUseRawPaths = SK_Scalar1 == fSkPaint.getTextScaleX() && |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 fQueuedGlyphCount = 0; | 443 fQueuedGlyphCount = 0; |
| 442 } | 444 } |
| 443 | 445 |
| 444 if (fFallbackGlyphsIdx < kGlyphBufferSize) { | 446 if (fFallbackGlyphsIdx < kGlyphBufferSize) { |
| 445 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; | 447 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; |
| 446 | 448 |
| 447 GrPaint paintFallback(fPaint); | 449 GrPaint paintFallback(fPaint); |
| 448 | 450 |
| 449 SkPaint skPaintFallback(fSkPaint); | 451 SkPaint skPaintFallback(fSkPaint); |
| 450 if (!fUsingDeviceSpaceGlyphs) { | 452 if (!fUsingDeviceSpaceGlyphs) { |
| 451 fStroke.applyToPaint(&skPaintFallback); | 453 fStroke.getStrokeRecPtr()->applyToPaint(&skPaintFallback); |
| 452 } | 454 } |
| 453 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for. | 455 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for. |
| 454 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 456 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 455 | 457 |
| 456 SkMatrix inverse; | 458 SkMatrix inverse; |
| 457 if (this->mapToFallbackContext(&inverse)) { | 459 if (this->mapToFallbackContext(&inverse)) { |
| 458 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount); | 460 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount); |
| 459 } | 461 } |
| 460 | 462 |
| 461 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, | 463 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 476 | 478 |
| 477 SkGlyphCache::AttachCache(fGlyphCache); | 479 SkGlyphCache::AttachCache(fGlyphCache); |
| 478 fGlyphCache = NULL; | 480 fGlyphCache = NULL; |
| 479 | 481 |
| 480 fPipelineBuilder.stencil()->setDisabled(); | 482 fPipelineBuilder.stencil()->setDisabled(); |
| 481 fStateRestore.set(NULL); | 483 fStateRestore.set(NULL); |
| 482 fViewMatrix = fContextInitialMatrix; | 484 fViewMatrix = fContextInitialMatrix; |
| 483 GrTextContext::finish(); | 485 GrTextContext::finish(); |
| 484 } | 486 } |
| 485 | 487 |
| OLD | NEW |