make rrect's more self-consistent, check drawable index
Bug: skia:7403 Change-Id: Ifb8f9ffce2acb1c6f1ebc6c733ad3b6c0865409a Reviewed-on: https://skia-review.googlesource.com/91503 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
2cc7d13978
commit
e58260031e
@ -116,9 +116,8 @@ public:
|
||||
}
|
||||
|
||||
SkDrawable* getDrawable(SkReadBuffer* reader) const {
|
||||
int index = reader->readInt();
|
||||
SkASSERT(index > 0 && index <= fDrawableCount);
|
||||
return fDrawableRefs[index - 1];
|
||||
int index = reader->readInt() - 1;
|
||||
return reader->validateIndex(index, fDrawableCount) ? fDrawableRefs[index] : nullptr;
|
||||
}
|
||||
|
||||
const SkPaint* getPaint(SkReadBuffer* reader) const {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "SkRRect.h"
|
||||
#include "SkScopeExit.h"
|
||||
#include "SkBuffer.h"
|
||||
#include "SkMalloc.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkScaleToSides.h"
|
||||
|
||||
@ -387,6 +388,10 @@ bool SkRRect::transform(const SkMatrix& matrix, SkRRect* dst) const {
|
||||
// remains unchanged.
|
||||
dst->fType = fType;
|
||||
|
||||
if (kRect_Type == fType) {
|
||||
SkASSERT(dst->isValid());
|
||||
return true;
|
||||
}
|
||||
if (kOval_Type == fType) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
dst->fRadii[i].fX = SkScalarHalf(newRect.width());
|
||||
@ -495,16 +500,10 @@ size_t SkRRect::readFromMemory(const void* buffer, size_t length) {
|
||||
if (length < kSizeInMemory) {
|
||||
return 0;
|
||||
}
|
||||
// Note that the buffer may be smaller than SkRRect. It is important not to access
|
||||
// bufferAsRRect->fType.
|
||||
const SkRRect* bufferAsRRect = reinterpret_cast<const SkRRect*>(buffer);
|
||||
if (!AreRectAndRadiiValid(bufferAsRRect->fRect, bufferAsRRect->fRadii)) {
|
||||
return 0;
|
||||
}
|
||||
// Deserialize rect and corners, then rederive the type tag.
|
||||
memcpy(this, buffer, kSizeInMemory);
|
||||
this->computeType();
|
||||
|
||||
SkRRect raw;
|
||||
memcpy(&raw, buffer, kSizeInMemory);
|
||||
this->setRectRadii(raw.fRect, raw.fRadii);
|
||||
return kSizeInMemory;
|
||||
}
|
||||
|
||||
@ -512,14 +511,9 @@ bool SkRRect::readFromBuffer(SkRBuffer* buffer) {
|
||||
if (buffer->available() < kSizeInMemory) {
|
||||
return false;
|
||||
}
|
||||
SkRRect readData;
|
||||
buffer->read(&readData, kSizeInMemory);
|
||||
if (!AreRectAndRadiiValid(readData.fRect, readData.fRadii)) {
|
||||
return false;
|
||||
}
|
||||
memcpy(this, &readData, kSizeInMemory);
|
||||
this->computeType();
|
||||
return true;
|
||||
SkRRect storage;
|
||||
return buffer->read(&storage, kSizeInMemory) &&
|
||||
(this->readFromMemory(&storage, kSizeInMemory) == kSizeInMemory);
|
||||
}
|
||||
|
||||
#include "SkString.h"
|
||||
|
@ -739,21 +739,17 @@ static void test_issue_2696(skiatest::Reporter* reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
void test_read_rrect(skiatest::Reporter* reporter, const SkRRect& rrect, bool shouldSucceed) {
|
||||
void test_read_rrect(skiatest::Reporter* reporter, const SkRRect& rrect, bool shouldEqualSrc) {
|
||||
// It would be cleaner to call rrect.writeToMemory into a buffer. However, writeToMemory asserts
|
||||
// that the rrect is valid and our caller may have fiddled with the internals of rrect to make
|
||||
// it invalid.
|
||||
const void* buffer = reinterpret_cast<const void*>(&rrect);
|
||||
SkRRect deserialized;
|
||||
size_t size = deserialized.readFromMemory(buffer, sizeof(SkRRect));
|
||||
if (shouldSucceed) {
|
||||
REPORTER_ASSERT(reporter, size == SkRRect::kSizeInMemory);
|
||||
if (size) {
|
||||
REPORTER_ASSERT(reporter, rrect == deserialized);
|
||||
REPORTER_ASSERT(reporter, rrect.getType() == deserialized.getType());
|
||||
}
|
||||
} else {
|
||||
REPORTER_ASSERT(reporter, !size);
|
||||
REPORTER_ASSERT(reporter, size == SkRRect::kSizeInMemory);
|
||||
REPORTER_ASSERT(reporter, deserialized.isValid());
|
||||
if (shouldEqualSrc) {
|
||||
REPORTER_ASSERT(reporter, rrect == deserialized);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user