| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 #undef GetGlyphIndices | 9 #undef GetGlyphIndices |
| 10 | 10 |
| 11 #include "SkDWrite.h" | 11 #include "SkDWrite.h" |
| 12 #include "SkDWriteGeometrySink.h" | 12 #include "SkDWriteGeometrySink.h" |
| 13 #include "SkEndian.h" | 13 #include "SkEndian.h" |
| 14 #include "SkGlyph.h" | 14 #include "SkGlyph.h" |
| 15 #include "SkHRESULT.h" | 15 #include "SkHRESULT.h" |
| 16 #include "SkMaskGamma.h" | 16 #include "SkMaskGamma.h" |
| 17 #include "SkMatrix22.h" | 17 #include "SkMatrix22.h" |
| 18 #include "SkMutex.h" | 18 #include "SkMutex.h" |
| 19 #include "SkOTTable_EBLC.h" | 19 #include "SkOTTable_EBLC.h" |
| 20 #include "SkOTTable_EBSC.h" | 20 #include "SkOTTable_EBSC.h" |
| 21 #include "SkOTTable_gasp.h" | 21 #include "SkOTTable_gasp.h" |
| 22 #include "SkOTTable_maxp.h" | 22 #include "SkOTTable_maxp.h" |
| 23 #include "SkPath.h" | 23 #include "SkPath.h" |
| 24 #include "SkScalerContext.h" | 24 #include "SkScalerContext.h" |
| 25 #include "SkScalerContext_win_dw.h" | 25 #include "SkScalerContext_win_dw.h" |
| 26 #include "SkSharedMutex.h" |
| 26 #include "SkTScopedComPtr.h" | 27 #include "SkTScopedComPtr.h" |
| 27 #include "SkTypeface_win_dw.h" | 28 #include "SkTypeface_win_dw.h" |
| 28 | 29 |
| 29 #include <dwrite.h> | 30 #include <dwrite.h> |
| 30 #if SK_HAS_DWRITE_1_H | 31 #if SK_HAS_DWRITE_1_H |
| 31 # include <dwrite_1.h> | 32 # include <dwrite_1.h> |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 /* Note: | 35 /* Note: |
| 35 * In versions 8 and 8.1 of Windows, some calls in DWrite are not thread safe. | 36 * In versions 8 and 8.1 of Windows, some calls in DWrite are not thread safe. |
| 36 * The DWriteFactoryMutex protects the calls that are problematic. | 37 * The DWriteFactoryMutex protects the calls that are problematic. |
| 37 */ | 38 */ |
| 38 SK_DECLARE_STATIC_MUTEX(DWriteFactoryMutex); | 39 static SkSharedMutex DWriteFactoryMutex; |
| 39 | 40 |
| 40 typedef SkAutoMutexExclusive Exclusive; | 41 typedef SkAutoTExclusive<SkSharedMutex> Exclusive; |
| 42 typedef SkAutoSharedMutexShared Shared; |
| 41 | 43 |
| 42 static bool isLCD(const SkScalerContext::Rec& rec) { | 44 static bool isLCD(const SkScalerContext::Rec& rec) { |
| 43 return SkMask::kLCD16_Format == rec.fMaskFormat; | 45 return SkMask::kLCD16_Format == rec.fMaskFormat; |
| 44 } | 46 } |
| 45 | 47 |
| 46 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) { | 48 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) { |
| 47 Exclusive l(DWriteFactoryMutex); | 49 Exclusive l(DWriteFactoryMutex); |
| 48 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get
()); | 50 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get
()); |
| 49 if (!maxp.fExists) { | 51 if (!maxp.fExists) { |
| 50 return false; | 52 return false; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 &gm), | 360 &gm), |
| 359 "Could not get gdi compatible glyph metrics."); | 361 "Could not get gdi compatible glyph metrics."); |
| 360 } else { | 362 } else { |
| 361 Exclusive l(DWriteFactoryMutex); | 363 Exclusive l(DWriteFactoryMutex); |
| 362 HRVM(fTypeface->fDWriteFontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm)
, | 364 HRVM(fTypeface->fDWriteFontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm)
, |
| 363 "Could not get design metrics."); | 365 "Could not get design metrics."); |
| 364 } | 366 } |
| 365 | 367 |
| 366 DWRITE_FONT_METRICS dwfm; | 368 DWRITE_FONT_METRICS dwfm; |
| 367 { | 369 { |
| 368 Exclusive l(DWriteFactoryMutex); | 370 Shared l(DWriteFactoryMutex); |
| 369 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); | 371 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); |
| 370 } | 372 } |
| 371 SkScalar advanceX = SkScalarMulDiv(fTextSizeMeasure, | 373 SkScalar advanceX = SkScalarMulDiv(fTextSizeMeasure, |
| 372 SkIntToScalar(gm.advanceWidth), | 374 SkIntToScalar(gm.advanceWidth), |
| 373 SkIntToScalar(dwfm.designUnitsPerEm)); | 375 SkIntToScalar(dwfm.designUnitsPerEm)); |
| 374 | 376 |
| 375 SkVector vecs[1] = { { advanceX, 0 } }; | 377 SkVector vecs[1] = { { advanceX, 0 } }; |
| 376 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode || | 378 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode || |
| 377 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode) | 379 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode) |
| 378 { | 380 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 407 | 409 |
| 408 DWRITE_GLYPH_RUN run; | 410 DWRITE_GLYPH_RUN run; |
| 409 run.glyphCount = 1; | 411 run.glyphCount = 1; |
| 410 run.glyphAdvances = &advance; | 412 run.glyphAdvances = &advance; |
| 411 run.fontFace = fTypeface->fDWriteFontFace.get(); | 413 run.fontFace = fTypeface->fDWriteFontFace.get(); |
| 412 run.fontEmSize = SkScalarToFloat(fTextSizeRender); | 414 run.fontEmSize = SkScalarToFloat(fTextSizeRender); |
| 413 run.bidiLevel = 0; | 415 run.bidiLevel = 0; |
| 414 run.glyphIndices = &glyphId; | 416 run.glyphIndices = &glyphId; |
| 415 run.isSideways = FALSE; | 417 run.isSideways = FALSE; |
| 416 run.glyphOffsets = &offset; | 418 run.glyphOffsets = &offset; |
| 419 |
| 420 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; |
| 417 { | 421 { |
| 418 Exclusive l(DWriteFactoryMutex); | 422 Exclusive l(DWriteFactoryMutex); |
| 419 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; | |
| 420 HRM(fTypeface->fFactory->CreateGlyphRunAnalysis( | 423 HRM(fTypeface->fFactory->CreateGlyphRunAnalysis( |
| 421 &run, | 424 &run, |
| 422 1.0f, // pixelsPerDip, | 425 1.0f, // pixelsPerDip, |
| 423 &fXform, | 426 &fXform, |
| 424 renderingMode, | 427 renderingMode, |
| 425 fMeasuringMode, | 428 fMeasuringMode, |
| 426 0.0f, // baselineOriginX, | 429 0.0f, // baselineOriginX, |
| 427 0.0f, // baselineOriginY, | 430 0.0f, // baselineOriginY, |
| 428 &glyphRunAnalysis), | 431 &glyphRunAnalysis), |
| 429 "Could not create glyph run analysis."); | 432 "Could not create glyph run analysis."); |
| 430 | 433 } |
| 434 { |
| 435 Shared l2(DWriteFactoryMutex); |
| 431 HRM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox), | 436 HRM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox), |
| 432 "Could not get texture bounds."); | 437 "Could not get texture bounds."); |
| 433 } | 438 } |
| 434 return S_OK; | 439 return S_OK; |
| 435 } | 440 } |
| 436 | 441 |
| 437 /** GetAlphaTextureBounds succeeds but sometimes returns empty bounds like | 442 /** GetAlphaTextureBounds succeeds but sometimes returns empty bounds like |
| 438 * { 0x80000000, 0x80000000, 0x80000000, 0x80000000 } | 443 * { 0x80000000, 0x80000000, 0x80000000, 0x80000000 } |
| 439 * for small, but not quite zero, sized glyphs. | 444 * for small, but not quite zero, sized glyphs. |
| 440 * Only set as non-empty if the returned bounds are non-empty. | 445 * Only set as non-empty if the returned bounds are non-empty. |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 DWRITE_GLYPH_RUN run; | 667 DWRITE_GLYPH_RUN run; |
| 663 run.glyphCount = 1; | 668 run.glyphCount = 1; |
| 664 run.glyphAdvances = &advance; | 669 run.glyphAdvances = &advance; |
| 665 run.fontFace = fTypeface->fDWriteFontFace.get(); | 670 run.fontFace = fTypeface->fDWriteFontFace.get(); |
| 666 run.fontEmSize = SkScalarToFloat(fTextSizeRender); | 671 run.fontEmSize = SkScalarToFloat(fTextSizeRender); |
| 667 run.bidiLevel = 0; | 672 run.bidiLevel = 0; |
| 668 run.glyphIndices = &index; | 673 run.glyphIndices = &index; |
| 669 run.isSideways = FALSE; | 674 run.isSideways = FALSE; |
| 670 run.glyphOffsets = &offset; | 675 run.glyphOffsets = &offset; |
| 671 { | 676 { |
| 672 Exclusive l(DWriteFactoryMutex); | 677 |
| 673 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; | 678 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; |
| 674 HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run, | 679 { |
| 675 1.0f, // pixelsPerDip, | 680 Exclusive l(DWriteFactoryMutex); |
| 676 &fXform, | 681 HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run, |
| 677 renderingMode, | 682 1.0f, // pixelsPerDip, |
| 678 fMeasuringMode, | 683 &fXform, |
| 679 0.0f, // baselineOriginX, | 684 renderingMode, |
| 680 0.0f, // baselineOriginY, | 685 fMeasuringMode, |
| 681 &glyphRunAnalysis), | 686 0.0f, // baselineOriginX, |
| 682 "Could not create glyph run analysis."); | 687 0.0f, // baselineOriginY, |
| 683 | 688 &glyphRunAnalysis), |
| 689 "Could not create glyph run analysis."); |
| 690 } |
| 684 //NOTE: this assumes that the glyph has already been measured | 691 //NOTE: this assumes that the glyph has already been measured |
| 685 //with an exact same glyph run analysis. | 692 //with an exact same glyph run analysis. |
| 686 RECT bbox; | 693 RECT bbox; |
| 687 bbox.left = glyph.fLeft; | 694 bbox.left = glyph.fLeft; |
| 688 bbox.top = glyph.fTop; | 695 bbox.top = glyph.fTop; |
| 689 bbox.right = glyph.fLeft + glyph.fWidth; | 696 bbox.right = glyph.fLeft + glyph.fWidth; |
| 690 bbox.bottom = glyph.fTop + glyph.fHeight; | 697 bbox.bottom = glyph.fTop + glyph.fHeight; |
| 691 HRNM(glyphRunAnalysis->CreateAlphaTexture(textureType, | 698 { |
| 692 &bbox, | 699 Shared l(DWriteFactoryMutex); |
| 693 fBits.begin(), | 700 HRNM(glyphRunAnalysis->CreateAlphaTexture(textureType, |
| 694 sizeNeeded), | 701 &bbox, |
| 695 "Could not draw mask."); | 702 fBits.begin(), |
| 703 sizeNeeded), |
| 704 "Could not draw mask."); |
| 705 } |
| 696 } | 706 } |
| 697 return fBits.begin(); | 707 return fBits.begin(); |
| 698 } | 708 } |
| 699 | 709 |
| 700 void SkScalerContext_DW::generateImage(const SkGlyph& glyph) { | 710 void SkScalerContext_DW::generateImage(const SkGlyph& glyph) { |
| 701 //Create the mask. | 711 //Create the mask. |
| 702 DWRITE_RENDERING_MODE renderingMode = fRenderingMode; | 712 DWRITE_RENDERING_MODE renderingMode = fRenderingMode; |
| 703 DWRITE_TEXTURE_TYPE textureType = fTextureType; | 713 DWRITE_TEXTURE_TYPE textureType = fTextureType; |
| 704 if (glyph.fForceBW) { | 714 if (glyph.fForceBW) { |
| 705 renderingMode = DWRITE_RENDERING_MODE_ALIASED; | 715 renderingMode = DWRITE_RENDERING_MODE_ALIASED; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 nullptr, //offsets | 769 nullptr, //offsets |
| 760 1, //num glyphs | 770 1, //num glyphs |
| 761 FALSE, //sideways | 771 FALSE, //sideways |
| 762 FALSE, //rtl | 772 FALSE, //rtl |
| 763 geometryToPath.get()), | 773 geometryToPath.get()), |
| 764 "Could not create glyph outline."); | 774 "Could not create glyph outline."); |
| 765 } | 775 } |
| 766 | 776 |
| 767 path->transform(fSkXform); | 777 path->transform(fSkXform); |
| 768 } | 778 } |
| OLD | NEW |