aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2017-10-20 12:14:33 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-20 16:49:57 +0000
commit6d6d603c812a6c9bb3e70157be909d355233ba6d (patch)
tree71f1700b4f93dc48d15736bc0f4eb19c458b5a19 /src
parent5a83f590911f30b125bc6edce01a26ac971d6e1d (diff)
make matrix serialization private
Moves readFromMemory, writeToMemory to private section. No sign that these are called from google3, android, chromium, but function names are common enough that it's hard to know for sure. These are used inside templates internally and for testing, so it is not quite as simple as adding alternate entry points in SkMatrixPriv. R=reed@google.com Bug: skia:6898 Change-Id: I1fac142f4bf0f38608ea93438c46f39147606c4d Reviewed-on: https://skia-review.googlesource.com/62361 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Cary Clark <caryclark@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkMatrixPriv.h14
-rw-r--r--src/core/SkPictureRecord.cpp14
-rw-r--r--src/core/SkValidatingReadBuffer.cpp3
-rw-r--r--src/core/SkWriter32.cpp7
4 files changed, 31 insertions, 7 deletions
diff --git a/src/core/SkMatrixPriv.h b/src/core/SkMatrixPriv.h
index b0df2ecf9a..ed1a5f117e 100644
--- a/src/core/SkMatrixPriv.h
+++ b/src/core/SkMatrixPriv.h
@@ -13,9 +13,23 @@
class SkMatrixPriv {
public:
+ enum {
+ // writeTo/readFromMemory will never return a value larger than this
+ kMaxFlattenSize = 9 * sizeof(SkScalar) + sizeof(uint32_t),
+ };
+
+ static size_t WriteToMemory(const SkMatrix& matrix, void* buffer) {
+ return matrix.writeToMemory(buffer);
+ }
+
+ static size_t ReadFromMemory(SkMatrix* matrix, const void* buffer, size_t length) {
+ return matrix->readFromMemory(buffer, length);
+ }
+
typedef SkMatrix::MapXYProc MapXYProc;
typedef SkMatrix::MapPtsProc MapPtsProc;
+
static MapPtsProc GetMapPtsProc(const SkMatrix& matrix) {
return SkMatrix::GetMapPtsProc(matrix.getType());
}
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 2ebe7bbe50..3700e3b330 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -8,6 +8,7 @@
#include "SkPictureRecord.h"
#include "SkDrawShadowInfo.h"
#include "SkImage_Base.h"
+#include "SkMatrixPriv.h"
#include "SkPatchUtils.h"
#include "SkPixelRef.h"
#include "SkRRect.h"
@@ -111,7 +112,7 @@ void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) {
}
if (rec.fClipMatrix) {
flatFlags |= SAVELAYERREC_HAS_CLIPMATRIX;
- size += rec.fClipMatrix->writeToMemory(nullptr);
+ size += SkMatrixPriv::WriteToMemory(*rec.fClipMatrix, nullptr);
}
const size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERREC, &size);
@@ -225,7 +226,7 @@ void SkPictureRecord::didConcat(const SkMatrix& matrix) {
void SkPictureRecord::recordConcat(const SkMatrix& matrix) {
this->validate(fWriter.bytesWritten(), 0);
// op + matrix
- size_t size = kUInt32Size + matrix.writeToMemory(nullptr);
+ size_t size = kUInt32Size + SkMatrixPriv::WriteToMemory(matrix, nullptr);
size_t initialOffset = this->addDraw(CONCAT, &size);
this->addMatrix(matrix);
this->validate(initialOffset, size);
@@ -234,7 +235,7 @@ void SkPictureRecord::recordConcat(const SkMatrix& matrix) {
void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) {
this->validate(fWriter.bytesWritten(), 0);
// op + matrix
- size_t size = kUInt32Size + matrix.writeToMemory(nullptr);
+ size_t size = kUInt32Size + SkMatrixPriv::WriteToMemory(matrix, nullptr);
size_t initialOffset = this->addDraw(SET_MATRIX, &size);
this->addMatrix(matrix);
this->validate(initialOffset, size);
@@ -623,7 +624,8 @@ void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons
const SkMatrix* matrix, const SkPaint& paint) {
// op + paint index + length + 'length' worth of data + path index + matrix
const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
- size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.writeToMemory(nullptr);
+ size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size +
+ SkMatrixPriv::WriteToMemory(m, nullptr);
size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
this->addPaint(paint);
this->addText(text, byteLength);
@@ -682,7 +684,7 @@ void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma
this->addPicture(picture);
} else {
const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
- size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint
+ size += SkMatrixPriv::WriteToMemory(m, nullptr) + kUInt32Size; // matrix + paint
initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size);
this->addPaintPtr(paint);
this->addMatrix(m);
@@ -700,7 +702,7 @@ void SkPictureRecord::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matri
initialOffset = this->addDraw(DRAW_DRAWABLE, &size);
this->addDrawable(drawable);
} else {
- size += matrix->writeToMemory(nullptr); // matrix
+ size += SkMatrixPriv::WriteToMemory(*matrix, nullptr); // matrix
initialOffset = this->addDraw(DRAW_DRAWABLE_MATRIX, &size);
this->addMatrix(*matrix);
this->addDrawable(drawable);
diff --git a/src/core/SkValidatingReadBuffer.cpp b/src/core/SkValidatingReadBuffer.cpp
index 2da08c6f09..e13cde5da6 100644
--- a/src/core/SkValidatingReadBuffer.cpp
+++ b/src/core/SkValidatingReadBuffer.cpp
@@ -6,6 +6,7 @@
*/
#include "SkBitmap.h"
+#include "SkMatrixPriv.h"
#include "SkValidatingReadBuffer.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -135,7 +136,7 @@ void SkValidatingReadBuffer::readPoint3(SkPoint3* point) {
void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) {
size_t size = 0;
if (!fError) {
- size = matrix->readFromMemory(fReader.peek(), fReader.available());
+ size = SkMatrixPriv::ReadFromMemory(matrix, fReader.peek(), fReader.available());
this->validate((SkAlign4(size) == size) && (0 != size));
}
if (!fError) {
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index d328644f6b..3261aad36f 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -5,10 +5,17 @@
* found in the LICENSE file.
*/
+#include "SkMatrixPriv.h"
#include "SkReader32.h"
#include "SkString.h"
#include "SkWriter32.h"
+void SkWriter32::writeMatrix(const SkMatrix& matrix) {
+ size_t size = SkMatrixPriv::WriteToMemory(matrix, nullptr);
+ SkASSERT(SkAlign4(size) == size);
+ SkMatrixPriv::WriteToMemory(matrix, this->reserve(size));
+}
+
/*
* Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4
*/