Bug 1454692 - Backport some upstream Skia fixes to ESR52. r=rhunt, a=abillings
authorLee Salzman <lsalzman@mozilla.com>
Sun, 29 Apr 2018 20:10:51 -0400
changeset 357086 f729bf78fb3a178c216ac4517d1fad81d53ff3ef
parent 357085 3f2ec03c04055850e5b11f8836632c9d7a973115
child 357087 40f12255a8cde3a43ceb36078b132544a255d35c
push id7663
push userryanvm@gmail.com
push dateMon, 30 Apr 2018 18:44:18 +0000
treeherdermozilla-esr52@f729bf78fb3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt, abillings
bugs1454692
milestone52.8.0
Bug 1454692 - Backport some upstream Skia fixes to ESR52. r=rhunt, a=abillings
gfx/skia/skia/src/core/SkMask.cpp
gfx/skia/skia/src/gpu/GrBufferAllocPool.cpp
gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.cpp
--- a/gfx/skia/skia/src/core/SkMask.cpp
+++ b/gfx/skia/skia/src/core/SkMask.cpp
@@ -38,17 +38,22 @@ size_t SkMask::computeTotalImageSize() c
 
 /** We explicitly use this allocator for SkBimap pixels, so that we can
     freely assign memory allocated by one class to the other.
 */
 uint8_t* SkMask::AllocImage(size_t size) {
 #ifdef TRACK_SKMASK_LIFETIME
     SkDebugf("SkMask::AllocImage %d\n", gCounter++);
 #endif
-    return (uint8_t*)sk_malloc_throw(SkAlign4(size));
+    size_t aligned_size = std::numeric_limits<size_t>::max();
+    size_t adjustment = 3;
+    if (size + adjustment > size) {
+        aligned_size = (size + adjustment) & ~adjustment;
+    }
+    return static_cast<uint8_t*>(sk_malloc_throw(aligned_size));
 }
 
 /** We explicitly use this allocator for SkBimap pixels, so that we can
     freely assign memory allocated by one class to the other.
 */
 void SkMask::FreeImage(void* image) {
 #ifdef TRACK_SKMASK_LIFETIME
     if (image) {
--- a/gfx/skia/skia/src/gpu/GrBufferAllocPool.cpp
+++ b/gfx/skia/skia/src/gpu/GrBufferAllocPool.cpp
@@ -9,16 +9,17 @@
 #include "GrBufferAllocPool.h"
 #include "GrBuffer.h"
 #include "GrCaps.h"
 #include "GrContext.h"
 #include "GrGpu.h"
 #include "GrResourceProvider.h"
 #include "GrTypes.h"
 
+#include "SkSafeMath.h"
 #include "SkTraceEvent.h"
 
 #ifdef SK_DEBUG
     #define VALIDATE validate
 #else
     static void VALIDATE(bool = false) {}
 #endif
 
@@ -330,17 +331,17 @@ void* GrVertexBufferAllocPool::makeSpace
                                          const GrBuffer** buffer,
                                          int* startVertex) {
 
     SkASSERT(vertexCount >= 0);
     SkASSERT(buffer);
     SkASSERT(startVertex);
 
     size_t offset = 0; // assign to suppress warning
-    void* ptr = INHERITED::makeSpace(vertexSize * vertexCount,
+    void* ptr = INHERITED::makeSpace(SkSafeMath::Mul(vertexSize, vertexCount),
                                      vertexSize,
                                      buffer,
                                      &offset);
 
     SkASSERT(0 == offset % vertexSize);
     *startVertex = static_cast<int>(offset / vertexSize);
     return ptr;
 }
@@ -355,17 +356,17 @@ void* GrIndexBufferAllocPool::makeSpace(
                                         const GrBuffer** buffer,
                                         int* startIndex) {
 
     SkASSERT(indexCount >= 0);
     SkASSERT(buffer);
     SkASSERT(startIndex);
 
     size_t offset = 0; // assign to suppress warning
-    void* ptr = INHERITED::makeSpace(indexCount * sizeof(uint16_t),
+    void* ptr = INHERITED::makeSpace(SkSafeMath::Mul(indexCount, sizeof(uint16_t)),
                                      sizeof(uint16_t),
                                      buffer,
                                      &offset);
 
     SkASSERT(0 == offset % sizeof(uint16_t));
     *startIndex = static_cast<int>(offset / sizeof(uint16_t));
     return ptr;
 }
--- a/gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.cpp
+++ b/gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.cpp
@@ -823,16 +823,23 @@ void AAHairlineBatch::onPrepareDraws(Tar
     for (int i = 0; i < instanceCount; i++) {
         const Geometry& args = fGeoData[i];
         quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds,
                                             &lines, &quads, &conics, &qSubdivs, &cWeights);
     }
 
     int lineCount = lines.count() / 2;
     int conicCount = conics.count() / 3;
+    int quadAndConicCount = conicCount + quadCount;
+
+    static constexpr int kMaxLines = SK_MaxS32 / kLineSegNumVertices;
+    static constexpr int kMaxQuadsAndConics = SK_MaxS32 / kQuadNumVertices;
+    if (lineCount > kMaxLines || quadAndConicCount > kMaxQuadsAndConics) {
+        return;
+    }
 
     // do lines first
     if (lineCount) {
         sk_sp<GrGeometryProcessor> lineGP;
         {
             using namespace GrDefaultGeoProcFactory;
 
             Color color(this->color());
@@ -894,17 +901,17 @@ void AAHairlineBatch::onPrepareDraws(Tar
 
         const GrBuffer* vertexBuffer;
         int firstVertex;
 
         SkAutoTUnref<const GrBuffer> quadsIndexBuffer(
             ref_quads_index_buffer(target->resourceProvider()));
 
         size_t vertexStride = sizeof(BezierVertex);
-        int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * conicCount;
+        int vertexCount = kQuadNumVertices * quadAndConicCount;
         void *vertices = target->makeVertexSpace(vertexStride, vertexCount,
                                                  &vertexBuffer, &firstVertex);
 
         if (!vertices || !quadsIndexBuffer) {
             SkDebugf("Could not allocate vertices\n");
             return;
         }