aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-04-06 22:34:59 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-07 13:36:54 +0000
commitca878ccfb5d514b4e7baea9e6d410b0085211b40 (patch)
treec9888c407981a992a885f4a20e3509036c702e27 /src
parent3a1ad6fde24e1064dae77f602152399df08f18d8 (diff)
simplify SkRRect serialization
I think this happens to fix the particular issue in the attached bug. memcpy() is kind of the swiss army knife as far as strict aliasing is concerned... you're always allowed to use it. The generated code for writeToMemory() is unchanged, and readFromMemory() gets a bit better looking. BUG=skia:5105 Change-Id: Ib5bf96600f1138650c004ced2d696e9a4ba83ca7 Reviewed-on: https://skia-review.googlesource.com/11682 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkRRect.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index 2ed8bbfc5e..824ee62e60 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -456,10 +456,8 @@ void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const {
///////////////////////////////////////////////////////////////////////////////
size_t SkRRect::writeToMemory(void* buffer) const {
- SkASSERT(kSizeInMemory == sizeof(SkRect) + sizeof(fRadii));
-
- memcpy(buffer, &fRect, sizeof(SkRect));
- memcpy((char*)buffer + sizeof(SkRect), fRadii, sizeof(fRadii));
+ // Serialize only the rect and corners, but not the derived type tag.
+ memcpy(buffer, this, kSizeInMemory);
return kSizeInMemory;
}
@@ -468,14 +466,10 @@ size_t SkRRect::readFromMemory(const void* buffer, size_t length) {
return 0;
}
- SkScalar storage[12];
- SkASSERT(sizeof(storage) == kSizeInMemory);
-
- // we make a local copy, to ensure alignment before we cast
- memcpy(storage, buffer, kSizeInMemory);
+ // Deserialize rect and corners, then rederive the type tag.
+ memcpy(this, buffer, kSizeInMemory);
+ this->computeType();
- this->setRectRadii(*(const SkRect*)&storage[0],
- (const SkVector*)&storage[4]);
return kSizeInMemory;
}