Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: src/ports/SkScalerContext_win_dw.cpp

Issue 2055023003: Type-erase SkAutoMutexAcquire and SkAutoExclusive. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(SK_BUILD_FOR_WIN32) 9 #if defined(SK_BUILD_FOR_WIN32)
10 10
(...skipping 24 matching lines...) Expand all
35 #if SK_HAS_DWRITE_1_H 35 #if SK_HAS_DWRITE_1_H
36 # include <dwrite_1.h> 36 # include <dwrite_1.h>
37 #endif 37 #endif
38 38
39 /* Note: 39 /* Note:
40 * In versions 8 and 8.1 of Windows, some calls in DWrite are not thread safe. 40 * In versions 8 and 8.1 of Windows, some calls in DWrite are not thread safe.
41 * The DWriteFactoryMutex protects the calls that are problematic. 41 * The DWriteFactoryMutex protects the calls that are problematic.
42 */ 42 */
43 static SkSharedMutex DWriteFactoryMutex; 43 static SkSharedMutex DWriteFactoryMutex;
44 44
45 typedef SkAutoTExclusive<SkSharedMutex> Exclusive;
46 typedef SkAutoSharedMutexShared Shared; 45 typedef SkAutoSharedMutexShared Shared;
47 46
48 static bool isLCD(const SkScalerContext::Rec& rec) { 47 static bool isLCD(const SkScalerContext::Rec& rec) {
49 return SkMask::kLCD16_Format == rec.fMaskFormat; 48 return SkMask::kLCD16_Format == rec.fMaskFormat;
50 } 49 }
51 50
52 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) { 51 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) {
53 Exclusive l(DWriteFactoryMutex); 52 SkAutoExclusive l(DWriteFactoryMutex);
54 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get ()); 53 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get ());
55 if (!maxp.fExists) { 54 if (!maxp.fExists) {
56 return false; 55 return false;
57 } 56 }
58 if (maxp.fSize < sizeof(SkOTTableMaximumProfile::Version::TT)) { 57 if (maxp.fSize < sizeof(SkOTTableMaximumProfile::Version::TT)) {
59 return false; 58 return false;
60 } 59 }
61 if (maxp->version.version != SkOTTableMaximumProfile::Version::TT::VERSION) { 60 if (maxp->version.version != SkOTTableMaximumProfile::Version::TT::VERSION) {
62 return false; 61 return false;
63 } 62 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 { 112 {
114 range->min = minPPEM + 1; 113 range->min = minPPEM + 1;
115 range->max = maxPPEM; 114 range->max = maxPPEM;
116 return; 115 return;
117 } 116 }
118 minPPEM = maxPPEM; 117 minPPEM = maxPPEM;
119 } 118 }
120 } 119 }
121 120
122 static bool has_bitmap_strike(DWriteFontTypeface* typeface, PPEMRange range) { 121 static bool has_bitmap_strike(DWriteFontTypeface* typeface, PPEMRange range) {
123 Exclusive l(DWriteFactoryMutex); 122 SkAutoExclusive l(DWriteFactoryMutex);
124 { 123 {
125 AutoTDWriteTable<SkOTTableEmbeddedBitmapLocation> eblc(typeface->fDWrite FontFace.get()); 124 AutoTDWriteTable<SkOTTableEmbeddedBitmapLocation> eblc(typeface->fDWrite FontFace.get());
126 if (!eblc.fExists) { 125 if (!eblc.fExists) {
127 return false; 126 return false;
128 } 127 }
129 if (eblc.fSize < sizeof(SkOTTableEmbeddedBitmapLocation)) { 128 if (eblc.fSize < sizeof(SkOTTableEmbeddedBitmapLocation)) {
130 return false; 129 return false;
131 } 130 }
132 if (eblc->version != SkOTTableEmbeddedBitmapLocation::version_initial) { 131 if (eblc->version != SkOTTableEmbeddedBitmapLocation::version_initial) {
133 return false; 132 return false;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 355
357 glyph->fAdvanceX = 0; 356 glyph->fAdvanceX = 0;
358 glyph->fAdvanceY = 0; 357 glyph->fAdvanceY = 0;
359 358
360 uint16_t glyphId = glyph->getGlyphID(); 359 uint16_t glyphId = glyph->getGlyphID();
361 DWRITE_GLYPH_METRICS gm; 360 DWRITE_GLYPH_METRICS gm;
362 361
363 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode || 362 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode ||
364 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode) 363 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode)
365 { 364 {
366 Exclusive l(DWriteFactoryMutex); 365 SkAutoExclusive l(DWriteFactoryMutex);
367 HRVM(fTypeface->fDWriteFontFace->GetGdiCompatibleGlyphMetrics( 366 HRVM(fTypeface->fDWriteFontFace->GetGdiCompatibleGlyphMetrics(
368 fTextSizeMeasure, 367 fTextSizeMeasure,
369 1.0f, // pixelsPerDip 368 1.0f, // pixelsPerDip
370 &fGsA, 369 &fGsA,
371 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode, 370 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode,
372 &glyphId, 1, 371 &glyphId, 1,
373 &gm), 372 &gm),
374 "Could not get gdi compatible glyph metrics."); 373 "Could not get gdi compatible glyph metrics.");
375 } else { 374 } else {
376 Exclusive l(DWriteFactoryMutex); 375 SkAutoExclusive l(DWriteFactoryMutex);
377 HRVM(fTypeface->fDWriteFontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm) , 376 HRVM(fTypeface->fDWriteFontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm) ,
378 "Could not get design metrics."); 377 "Could not get design metrics.");
379 } 378 }
380 379
381 DWRITE_FONT_METRICS dwfm; 380 DWRITE_FONT_METRICS dwfm;
382 { 381 {
383 Shared l(DWriteFactoryMutex); 382 Shared l(DWriteFactoryMutex);
384 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); 383 fTypeface->fDWriteFontFace->GetMetrics(&dwfm);
385 } 384 }
386 SkScalar advanceX = SkScalarMulDiv(fTextSizeMeasure, 385 SkScalar advanceX = SkScalarMulDiv(fTextSizeMeasure,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 run.glyphAdvances = &advance; 424 run.glyphAdvances = &advance;
426 run.fontFace = fTypeface->fDWriteFontFace.get(); 425 run.fontFace = fTypeface->fDWriteFontFace.get();
427 run.fontEmSize = SkScalarToFloat(fTextSizeRender); 426 run.fontEmSize = SkScalarToFloat(fTextSizeRender);
428 run.bidiLevel = 0; 427 run.bidiLevel = 0;
429 run.glyphIndices = &glyphId; 428 run.glyphIndices = &glyphId;
430 run.isSideways = FALSE; 429 run.isSideways = FALSE;
431 run.glyphOffsets = &offset; 430 run.glyphOffsets = &offset;
432 431
433 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; 432 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
434 { 433 {
435 Exclusive l(DWriteFactoryMutex); 434 SkAutoExclusive l(DWriteFactoryMutex);
436 HRM(fTypeface->fFactory->CreateGlyphRunAnalysis( 435 HRM(fTypeface->fFactory->CreateGlyphRunAnalysis(
437 &run, 436 &run,
438 1.0f, // pixelsPerDip, 437 1.0f, // pixelsPerDip,
439 &fXform, 438 &fXform,
440 renderingMode, 439 renderingMode,
441 fMeasuringMode, 440 fMeasuringMode,
442 0.0f, // baselineOriginX, 441 0.0f, // baselineOriginX,
443 0.0f, // baselineOriginY, 442 0.0f, // baselineOriginY,
444 &glyphRunAnalysis), 443 &glyphRunAnalysis),
445 "Could not create glyph run analysis."); 444 "Could not create glyph run analysis.");
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 run.fontFace = fTypeface->fDWriteFontFace.get(); 729 run.fontFace = fTypeface->fDWriteFontFace.get();
731 run.fontEmSize = SkScalarToFloat(fTextSizeRender); 730 run.fontEmSize = SkScalarToFloat(fTextSizeRender);
732 run.bidiLevel = 0; 731 run.bidiLevel = 0;
733 run.glyphIndices = &index; 732 run.glyphIndices = &index;
734 run.isSideways = FALSE; 733 run.isSideways = FALSE;
735 run.glyphOffsets = &offset; 734 run.glyphOffsets = &offset;
736 { 735 {
737 736
738 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; 737 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
739 { 738 {
740 Exclusive l(DWriteFactoryMutex); 739 SkAutoExclusive l(DWriteFactoryMutex);
741 HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run, 740 HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run,
742 1.0f, // pixelsPerDip, 741 1.0f, // pixelsPerDip,
743 &fXform, 742 &fXform,
744 renderingMode, 743 renderingMode,
745 fMeasuringMode, 744 fMeasuringMode,
746 0.0f, // baselineOriginX, 745 0.0f, // baselineOriginX,
747 0.0f, // baselineOriginY, 746 0.0f, // baselineOriginY,
748 &glyphRunAnalysis), 747 &glyphRunAnalysis),
749 "Could not create glyph run analysis."); 748 "Could not create glyph run analysis.");
750 } 749 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 SkASSERT(false); 813 SkASSERT(false);
815 color = fRec.getLuminanceColor(); 814 color = fRec.getLuminanceColor();
816 } 815 }
817 paint.setColor(color); 816 paint.setColor(color);
818 817
819 SkPath path; 818 SkPath path;
820 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath; 819 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath;
821 HRVM(SkDWriteGeometrySink::Create(&path, &geometryToPath), 820 HRVM(SkDWriteGeometrySink::Create(&path, &geometryToPath),
822 "Could not create geometry to path converter."); 821 "Could not create geometry to path converter.");
823 { 822 {
824 Exclusive l(DWriteFactoryMutex); 823 SkAutoExclusive l(DWriteFactoryMutex);
825 HRVM(colorGlyph->glyphRun.fontFace->GetGlyphRunOutline( 824 HRVM(colorGlyph->glyphRun.fontFace->GetGlyphRunOutline(
826 colorGlyph->glyphRun.fontEmSize, 825 colorGlyph->glyphRun.fontEmSize,
827 colorGlyph->glyphRun.glyphIndices, 826 colorGlyph->glyphRun.glyphIndices,
828 colorGlyph->glyphRun.glyphAdvances, 827 colorGlyph->glyphRun.glyphAdvances,
829 colorGlyph->glyphRun.glyphOffsets, 828 colorGlyph->glyphRun.glyphOffsets,
830 colorGlyph->glyphRun.glyphCount, 829 colorGlyph->glyphRun.glyphCount,
831 colorGlyph->glyphRun.isSideways, 830 colorGlyph->glyphRun.isSideways,
832 colorGlyph->glyphRun.bidiLevel % 2, //rtl 831 colorGlyph->glyphRun.bidiLevel % 2, //rtl
833 geometryToPath.get()), 832 geometryToPath.get()),
834 "Could not create glyph outline."); 833 "Could not create glyph outline.");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 void SkScalerContext_DW::generatePath(const SkGlyph& glyph, SkPath* path) { 891 void SkScalerContext_DW::generatePath(const SkGlyph& glyph, SkPath* path) {
893 SkASSERT(path); 892 SkASSERT(path);
894 893
895 path->reset(); 894 path->reset();
896 895
897 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath; 896 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath;
898 HRVM(SkDWriteGeometrySink::Create(path, &geometryToPath), 897 HRVM(SkDWriteGeometrySink::Create(path, &geometryToPath),
899 "Could not create geometry to path converter."); 898 "Could not create geometry to path converter.");
900 uint16_t glyphId = glyph.getGlyphID(); 899 uint16_t glyphId = glyph.getGlyphID();
901 { 900 {
902 Exclusive l(DWriteFactoryMutex); 901 SkAutoExclusive l(DWriteFactoryMutex);
903 //TODO: convert to<->from DIUs? This would make a difference if hinting. 902 //TODO: convert to<->from DIUs? This would make a difference if hinting.
904 //It may not be needed, it appears that DirectWrite only hints at em siz e. 903 //It may not be needed, it appears that DirectWrite only hints at em siz e.
905 HRVM(fTypeface->fDWriteFontFace->GetGlyphRunOutline(SkScalarToFloat(fTex tSizeRender), 904 HRVM(fTypeface->fDWriteFontFace->GetGlyphRunOutline(SkScalarToFloat(fTex tSizeRender),
906 &glyphId, 905 &glyphId,
907 nullptr, //advances 906 nullptr, //advances
908 nullptr, //offsets 907 nullptr, //offsets
909 1, //num glyphs 908 1, //num glyphs
910 FALSE, //sideways 909 FALSE, //sideways
911 FALSE, //rtl 910 FALSE, //rtl
912 geometryToPath.get()), 911 geometryToPath.get()),
913 "Could not create glyph outline."); 912 "Could not create glyph outline.");
914 } 913 }
915 914
916 path->transform(fSkXform); 915 path->transform(fSkXform);
917 } 916 }
918 917
919 #endif//defined(SK_BUILD_FOR_WIN32) 918 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698