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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 1220873009: add option to use global mutex-lock in mac-scalercontext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 990658d1fcb66a4034b3bc96e7139bba63bae674..bfacb0786092c078ebe53e7f3ee48f9aa9b23a3d 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -48,6 +48,17 @@
#include <dlfcn.h>
+// Experimental code to use a global lock whenever we access CG, to see if this reduces
+// crashes in Chrome
+#define USE_GLOBAL_MUTEX_FOR_CG_ACCESS
+
+#ifdef USE_GLOBAL_MUTEX_FOR_CG_ACCESS
+ static SkMutex gCGMutex;
+ #define AUTO_CG_LOCK() SkAutoMutexAcquire amc(gCGMutex)
+#else
+ #define AUTO_CG_LOCK()
+#endif
+
// Set to make glyph bounding boxes visible.
#define SK_SHOW_TEXT_BLIT_COVERAGE 0
@@ -713,6 +724,8 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
, fVertical(SkToBool(fRec.fFlags & kVertical_Flag))
{
+ AUTO_CG_LOCK();
+
CTFontRef ctFont = typeface->fFontRef.get();
CFIndex numGlyphs = CTFontGetGlyphCount(ctFont);
SkASSERT(numGlyphs >= 1 && numGlyphs <= 0xFFFF);
@@ -985,6 +998,8 @@ unsigned SkScalerContext_Mac::generateGlyphCount(void) {
}
uint16_t SkScalerContext_Mac::generateCharToGlyph(SkUnichar uni) {
+ AUTO_CG_LOCK();
+
CGGlyph cgGlyph[2];
UniChar theChar[2]; // UniChar is a UTF-16 16-bit code unit.
@@ -1004,6 +1019,8 @@ void SkScalerContext_Mac::generateAdvance(SkGlyph* glyph) {
}
void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph) {
+ AUTO_CG_LOCK();
+
const CGGlyph cgGlyph = (CGGlyph) glyph->getGlyphID();
glyph->zeroMetrics();
@@ -1320,6 +1337,8 @@ void SkScalerContext_Mac::generateImage(const SkGlyph& glyph) {
#define kScaleForSubPixelPositionHinting (4.0f)
void SkScalerContext_Mac::generatePath(const SkGlyph& glyph, SkPath* path) {
+ AUTO_CG_LOCK();
+
CTFontRef font = fCTFont;
SkScalar scaleX = SK_Scalar1;
SkScalar scaleY = SK_Scalar1;
@@ -1383,6 +1402,8 @@ void SkScalerContext_Mac::generateFontMetrics(SkPaint::FontMetrics* metrics) {
return;
}
+ AUTO_CG_LOCK();
+
CGRect theBounds = CTFontGetBoundingBox(fCTFont);
metrics->fTop = CGToScalar(-CGRectGetMaxY_inline(theBounds));
@@ -1544,6 +1565,8 @@ SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
+ AUTO_CG_LOCK();
+
CTFontRef originalCTFont = fFontRef.get();
AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698