Bug 1444506 - follow-up - upstream bug fixes. r=me, a=jcristau
authorLee Salzman <lsalzman@mozilla.com>
Mon, 19 Mar 2018 02:28:53 -0400
changeset 462758 2bf3d2cdef340f1352ec2a0e91ded10b4e579236
parent 462757 86e67789dfa793bc51da46ce5eb1dfbe8611cdae
child 462759 23a13199eb6e47552be72347e96d5fab45378209
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, jcristau
bugs1444506
milestone60.0
Bug 1444506 - follow-up - upstream bug fixes. r=me, a=jcristau MozReview-Commit-ID: DcB1BBpKTjj
gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.cpp
gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.h
gfx/skia/skia/src/ports/SkFontHost_mac.cpp
--- a/gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -530,18 +530,22 @@ private:
     bool addBMPathToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo,
                           GrDrawOpAtlas* atlas, ShapeData* shapeData, const GrShape& shape,
                           const SkMatrix& ctm) const {
         const SkRect& bounds = shape.bounds();
         if (bounds.isEmpty()) {
             return false;
         }
         SkMatrix drawMatrix(ctm);
-        drawMatrix.set(SkMatrix::kMTransX, SkScalarFraction(ctm.get(SkMatrix::kMTransX)));
-        drawMatrix.set(SkMatrix::kMTransY, SkScalarFraction(ctm.get(SkMatrix::kMTransY)));
+        SkScalar tx = ctm.getTranslateX();
+        SkScalar ty = ctm.getTranslateY();
+        tx -= SkScalarFloorToScalar(tx);
+        ty -= SkScalarFloorToScalar(ty);
+        drawMatrix.set(SkMatrix::kMTransX, tx);
+        drawMatrix.set(SkMatrix::kMTransY, ty);
         SkRect shapeDevBounds;
         drawMatrix.mapRect(&shapeDevBounds, bounds);
         SkScalar dx = SkScalarFloorToScalar(shapeDevBounds.fLeft);
         SkScalar dy = SkScalarFloorToScalar(shapeDevBounds.fTop);
 
         // get integer boundary
         SkIRect devPathBounds;
         shapeDevBounds.roundOut(&devPathBounds);
@@ -629,18 +633,18 @@ private:
                            size_t vertexStride,
                            const SkMatrix& ctm,
                            const ShapeData* shapeData) const {
         SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
 
         SkRect bounds = shapeData->fBounds;
         SkRect translatedBounds(bounds);
         if (!fUsesDistanceField) {
-            translatedBounds.offset(SkScalarTruncToScalar(ctm.get(SkMatrix::kMTransX)),
-                                  SkScalarTruncToScalar(ctm.get(SkMatrix::kMTransY)));
+            translatedBounds.offset(SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransX)),
+                                    SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransY)));
         }
 
         // vertex positions
         // TODO make the vertex attributes a struct
         if (fUsesDistanceField && !ctm.hasPerspective()) {
             GrQuad quad;
             quad.setFromMappedRect(translatedBounds, ctm);
             intptr_t positionOffset = offset;
@@ -651,21 +655,22 @@ private:
             *position = quad.point(1);
             positionOffset += vertexStride;
             position = (SkPoint*)positionOffset;
             *position = quad.point(2);
             positionOffset += vertexStride;
             position = (SkPoint*)positionOffset;
             *position = quad.point(3);
         } else {
-            SkPointPriv::SetRectTriStrip(positions, translatedBounds.left(),
-                                       translatedBounds.top(),
-                                       translatedBounds.right(),
-                                       translatedBounds.bottom(),
-                                       vertexStride);
+            SkPointPriv::SetRectTriStrip(positions,
+                                         translatedBounds.left(),
+                                         translatedBounds.top(),
+                                         translatedBounds.right(),
+                                         translatedBounds.bottom(),
+                                         vertexStride);
         }
 
         // colors
         for (int i = 0; i < kVerticesPerQuad; i++) {
             GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertexStride);
             *colorPtr = color;
         }
 
--- a/gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.h
+++ b/gfx/skia/skia/src/gpu/ops/GrSmallPathRenderer.h
@@ -91,18 +91,20 @@ private:
                 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
                 SkScalar sx = ctm.get(SkMatrix::kMScaleX);
                 SkScalar sy = ctm.get(SkMatrix::kMScaleY);
                 SkScalar kx = ctm.get(SkMatrix::kMSkewX);
                 SkScalar ky = ctm.get(SkMatrix::kMSkewY);
                 SkScalar tx = ctm.get(SkMatrix::kMTransX);
                 SkScalar ty = ctm.get(SkMatrix::kMTransY);
                 // Allow 8 bits each in x and y of subpixel positioning.
-                SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
-                SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
+                tx -= SkScalarFloorToScalar(tx);
+                ty -= SkScalarFloorToScalar(ty);
+                SkFixed fracX = SkScalarToFixed(tx) & 0x0000FF00;
+                SkFixed fracY = SkScalarToFixed(ty) & 0x0000FF00;
                 int shapeKeySize = shape.unstyledKeySize();
                 fKey.reset(5 + shapeKeySize);
                 fKey[0] = SkFloat2Bits(sx);
                 fKey[1] = SkFloat2Bits(sy);
                 fKey[2] = SkFloat2Bits(kx);
                 fKey[3] = SkFloat2Bits(ky);
                 fKey[4] = fracX | (fracY >> 8);
                 shape.writeUnstyledKey(&fKey[5]);
--- a/gfx/skia/skia/src/ports/SkFontHost_mac.cpp
+++ b/gfx/skia/skia/src/ports/SkFontHost_mac.cpp
@@ -1660,25 +1660,40 @@ SkStreamAsset* SkTypeface_Mac::onOpenStr
     }
 
     // get table tags
     int numTables = this->countTables();
     SkTDArray<SkFontTableTag> tableTags;
     tableTags.setCount(numTables);
     this->getTableTags(tableTags.begin());
 
-    // calc total size for font, save sizes
+    // see if there are any required 'typ1' tables (see Adobe Technical Note #5180)
+    bool couldBeTyp1 = false;
+    constexpr SkFontTableTag TYPE1Tag = SkSetFourByteTag('T', 'Y', 'P', '1');
+    constexpr SkFontTableTag CIDTag = SkSetFourByteTag('C', 'I', 'D', ' ');
+    // get the table sizes and accumulate the total size of the font
     SkTDArray<size_t> tableSizes;
     size_t totalSize = sizeof(SkSFNTHeader) + sizeof(SkSFNTHeader::TableDirectoryEntry) * numTables;
     for (int tableIndex = 0; tableIndex < numTables; ++tableIndex) {
+        if (TYPE1Tag == tableTags[tableIndex] || CIDTag == tableTags[tableIndex]) {
+            couldBeTyp1 = true;
+        }
+
         size_t tableSize = this->getTableSize(tableTags[tableIndex]);
         totalSize += (tableSize + 3) & ~3;
         *tableSizes.append() = tableSize;
     }
 
+    // sometimes CoreGraphics incorrectly thinks a font is kCTFontFormatPostScript
+    // it is exceedingly unlikely that this is the case, so double check
+    // see https://crbug.com/809763
+    if (fontType == SkSFNTHeader::fontType_PostScript::TAG && !couldBeTyp1) {
+        fontType = SkSFNTHeader::fontType_OpenTypeCFF::TAG;
+    }
+
     // reserve memory for stream, and zero it (tables must be zero padded)
     SkMemoryStream* stream = new SkMemoryStream(totalSize);
     char* dataStart = (char*)stream->getMemoryBase();
     sk_bzero(dataStart, totalSize);
     char* dataPtr = dataStart;
 
     // compute font header entries
     uint16_t entrySelector = 0;