From 1e447dfb7702460fc3dea5634c1e69d274b1b739 Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Tue, 12 Jun 2018 16:49:49 -0400 Subject: [PATCH] minor fixes to SkRRect Move methods that are not publicly callable to SkRRectPriv.h. Name params, add a trailing comma to the enum list. R=reed@google.com,bsalomon@google.com Bug: skia:6898 Change-Id: If93f712656dde563567a647624e58ce9a9d74494 Reviewed-on: https://skia-review.googlesource.com/134423 Reviewed-by: Brian Salomon Commit-Queue: Cary Clark --- include/core/SkRRect.h | 10 +++------- src/core/SkPath_serial.cpp | 6 +++--- src/core/SkRRect.cpp | 12 ++++++------ src/core/SkRRectPriv.h | 7 +++++++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h index 0acc7169ba..dae5a0cdde 100644 --- a/include/core/SkRRect.h +++ b/include/core/SkRRect.h @@ -13,8 +13,6 @@ class SkPath; class SkMatrix; -class SkRBuffer; -class SkWBuffer; // Path forward: // core work @@ -51,8 +49,8 @@ public: /** Default initialized to a rrect at the origin with zero width and height. */ SkRRect() = default; - SkRRect(const SkRRect&) = default; - SkRRect& operator=(const SkRRect&) = default; + SkRRect(const SkRRect& rrect) = default; + SkRRect& operator=(const SkRRect& rrect) = default; /** * Enum to capture the various possible subtypes of RR. Accessed @@ -201,7 +199,7 @@ public: kUpperLeft_Corner, kUpperRight_Corner, kLowerRight_Corner, - kLowerLeft_Corner + kLowerLeft_Corner, }; const SkRect& rect() const { return fRect; } @@ -278,7 +276,6 @@ public: * a multiple of 4. Return kSizeInMemory. */ size_t writeToMemory(void* buffer) const; - void writeToBuffer(SkWBuffer*) const; /** * Reads the rrect from the specified buffer @@ -292,7 +289,6 @@ public: * 0 if there was not enough memory available */ size_t readFromMemory(const void* buffer, size_t length); - bool readFromBuffer(SkRBuffer*); /** * Transform by the specified matrix, and put the result in dst. diff --git a/src/core/SkPath_serial.cpp b/src/core/SkPath_serial.cpp index e538a462db..3adcec2d63 100644 --- a/src/core/SkPath_serial.cpp +++ b/src/core/SkPath_serial.cpp @@ -11,7 +11,7 @@ #include "SkMath.h" #include "SkPathPriv.h" #include "SkPathRef.h" -#include "SkRRect.h" +#include "SkRRectPriv.h" #include "SkSafeMath.h" enum SerializationOffsets { @@ -77,7 +77,7 @@ size_t SkPath::writeToMemoryAsRRect(void* storage) const { SkWBuffer buffer(storage); buffer.write32(packed); - rrect.writeToBuffer(&buffer); + SkRRectPriv::WriteToBuffer(rrect, &buffer); buffer.write32(SkToS32(start)); buffer.padToAlign4(); SkASSERT(sizeNeeded == buffer.pos()); @@ -177,7 +177,7 @@ size_t SkPath::readAsRRect(const void* storage, size_t length) { default: return 0; } - if (!rrect.readFromBuffer(&buffer)) { + if (!SkRRectPriv::ReadFromBuffer(&buffer, &rrect)) { return 0; } if (!buffer.readS32(&start) || start != SkTPin(start, 0, 7)) { diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp index 50a87fab3c..46e83aec0f 100644 --- a/src/core/SkRRect.cpp +++ b/src/core/SkRRect.cpp @@ -501,9 +501,9 @@ size_t SkRRect::writeToMemory(void* buffer) const { return kSizeInMemory; } -void SkRRect::writeToBuffer(SkWBuffer* buffer) const { +void SkRRectPriv::WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer) { // Serialize only the rect and corners, but not the derived type tag. - buffer->write(this, kSizeInMemory); + buffer->write(&rr, SkRRect::kSizeInMemory); } size_t SkRRect::readFromMemory(const void* buffer, size_t length) { @@ -517,13 +517,13 @@ size_t SkRRect::readFromMemory(const void* buffer, size_t length) { return kSizeInMemory; } -bool SkRRect::readFromBuffer(SkRBuffer* buffer) { - if (buffer->available() < kSizeInMemory) { +bool SkRRectPriv::ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr) { + if (buffer->available() < SkRRect::kSizeInMemory) { return false; } SkRRect storage; - return buffer->read(&storage, kSizeInMemory) && - (this->readFromMemory(&storage, kSizeInMemory) == kSizeInMemory); + return buffer->read(&storage, SkRRect::kSizeInMemory) && + (rr->readFromMemory(&storage, SkRRect::kSizeInMemory) == SkRRect::kSizeInMemory); } #include "SkString.h" diff --git a/src/core/SkRRectPriv.h b/src/core/SkRRectPriv.h index ea277f7f33..226af247cd 100644 --- a/src/core/SkRRectPriv.h +++ b/src/core/SkRRectPriv.h @@ -10,6 +10,9 @@ #include "SkRRect.h" +class SkRBuffer; +class SkWBuffer; + class SkRRectPriv { public: static bool IsCircle(const SkRRect& rr) { @@ -30,6 +33,10 @@ public: } static bool AllCornersCircular(const SkRRect& rr, SkScalar tolerance = SK_ScalarNearlyZero); + + static bool ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr); + + static void WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer); }; #endif