Use the Read/WriteBuffer bulk API for points

In the TransformedMaskVertexFiller, use the bulk API for reading
and writing SkPoints. This should now be the same as the
DirectMaskSubRun code. Next CL will be to extract the common code.

Change-Id: If7592e4dc876a96c69086a0b04fbc88acadc76a6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/565013
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/text/gpu/SubRunContainer.cpp b/src/text/gpu/SubRunContainer.cpp
index 903e7ab..7bc553d 100644
--- a/src/text/gpu/SubRunContainer.cpp
+++ b/src/text/gpu/SubRunContainer.cpp
@@ -231,18 +231,29 @@
     if (!buffer.validate(0 < strikeToSourceScale)) { return std::nullopt; }
     SkRect sourceBounds = buffer.readRect();
 
-    int glyphCount = buffer.readInt();
-    if (!buffer.validate(check_glyph_count(buffer, glyphCount))) { return std::nullopt; }
-    SkPoint* leftTopStorage =
-            alloc->makePODArray<SkPoint>(glyphCount);
-    for (int i = 0; i < glyphCount; ++i) {
-        leftTopStorage[i] = buffer.readPoint();
-    }
-    SkSpan<SkPoint> topLeft(leftTopStorage, glyphCount);
+    uint32_t glyphCount = buffer.getArrayCount();
 
+    // Zero indicates a problem with serialization.
+    if (!buffer.validate(glyphCount != 0)) { return std::nullopt; }
+
+    // Check that the count will not overflow the arena.
+    if (!buffer.validate(glyphCount <= INT_MAX &&
+                         BagOfBytes::WillCountFit<SkPoint>(glyphCount))) { return std::nullopt; }
+
+    SkPoint* leftTopStorage = alloc->makePODArray<SkPoint>(glyphCount);
+    if (!buffer.readPointArray(leftTopStorage, glyphCount)) { return std::nullopt; }
+    SkSpan<SkPoint> topLeft(leftTopStorage, glyphCount);
+    SkASSERT(buffer.isValid());
     return {TransformedMaskVertexFiller{maskType, strikeToSourceScale, sourceBounds, topLeft}};
 }
 
+void TransformedMaskVertexFiller::flatten(SkWriteBuffer& buffer) const {
+    buffer.writeInt(static_cast<int>(fMaskType));
+    buffer.writeScalar(fStrikeToSourceScale);
+    buffer.writeRect(fSourceBounds);
+    buffer.writePointArray(fLeftTop.data(), SkCount(fLeftTop));
+}
+
 SkRect TransformedMaskVertexFiller::deviceRect(
         const SkMatrix& drawMatrix, SkPoint drawOrigin) const {
     SkRect outBounds = fSourceBounds;
@@ -254,16 +265,6 @@
     return fLeftTop.size_bytes();
 }
 
-void TransformedMaskVertexFiller::flatten(SkWriteBuffer& buffer) const {
-    buffer.writeInt(static_cast<int>(fMaskType));
-    buffer.writeScalar(fStrikeToSourceScale);
-    buffer.writeRect(fSourceBounds);
-    buffer.writeInt(SkCount(fLeftTop));
-    for (SkPoint leftTop : fLeftTop) {
-        buffer.writePoint(leftTop);
-    }
-}
-
 #if SK_SUPPORT_GPU
 void TransformedMaskVertexFiller::fillVertexData(int offset, int count,
                                                  SkSpan<const Glyph*> glyphs,