stub SkReadBuffer when SK_DISABLE_READBUFFER
This seems like a way to disable SkReadBuffer that won't require other preprocessor checks in the various effects. Disable SkReadBuffer in Flutter too, for about 20K. Change-Id: I87039b67d90ad372a21940d7e96fc46bf5114bfd Reviewed-on: https://skia-review.googlesource.com/c/165021 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
dff0d4a2c2
commit
a6c3517e76
@ -11,6 +11,9 @@ flutter_defines = [
|
||||
"SK_DISABLE_AAA",
|
||||
"SK_DISABLE_DAA",
|
||||
|
||||
# Flutter doesn't deserialize anything.
|
||||
"SK_DISABLE_READBUFFER",
|
||||
|
||||
# Fast low-precision software rendering isn't a priority for Flutter.
|
||||
"SK_DISABLE_LEGACY_SHADERCONTEXT",
|
||||
"SK_DISABLE_LOWP_RASTER_PIPELINE",
|
||||
|
@ -209,7 +209,7 @@ sk_sp<SkPicture> SkPicturePriv::MakeFromBuffer(SkReadBuffer& buffer) {
|
||||
// size should be 0, 1, or negative
|
||||
int32_t ssize = buffer.read32();
|
||||
if (ssize < 0) {
|
||||
const SkDeserialProcs& procs = buffer.fProcs;
|
||||
const SkDeserialProcs& procs = buffer.getDeserialProcs();
|
||||
if (!procs.fPictureProc) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "SkStream.h"
|
||||
#include "SkTypeface.h"
|
||||
|
||||
#ifndef SK_DISABLE_READBUFFER
|
||||
|
||||
namespace {
|
||||
// This generator intentionally should always fail on all attempts to get its pixels,
|
||||
// simulating a bad or empty codec stream.
|
||||
@ -451,3 +453,5 @@ int32_t SkReadBuffer::checkInt(int32_t min, int32_t max) {
|
||||
SkFilterQuality SkReadBuffer::checkFilterQuality() {
|
||||
return this->checkRange<SkFilterQuality>(kNone_SkFilterQuality, kLast_SkFilterQuality);
|
||||
}
|
||||
|
||||
#endif // #ifndef SK_DISABLE_READBUFFER
|
||||
|
@ -25,6 +25,8 @@
|
||||
class SkData;
|
||||
class SkImage;
|
||||
|
||||
#ifndef SK_DISABLE_READBUFFER
|
||||
|
||||
class SkReadBuffer {
|
||||
public:
|
||||
SkReadBuffer();
|
||||
@ -157,6 +159,7 @@ public:
|
||||
}
|
||||
|
||||
void setDeserialProcs(const SkDeserialProcs& procs);
|
||||
const SkDeserialProcs& getDeserialProcs() const { return fProcs; }
|
||||
|
||||
/**
|
||||
* If isValid is false, sets the buffer to be "invalid". Returns true if the buffer
|
||||
@ -216,7 +219,6 @@ private:
|
||||
int fFactoryCount;
|
||||
|
||||
SkDeserialProcs fProcs;
|
||||
friend class SkPicturePriv;
|
||||
|
||||
static bool IsPtrAlign4(const void* ptr) {
|
||||
return SkIsAlign4((uintptr_t)ptr);
|
||||
@ -225,4 +227,109 @@ private:
|
||||
bool fError = false;
|
||||
};
|
||||
|
||||
#else // #ifndef SK_DISABLE_READBUFFER
|
||||
|
||||
class SkReadBuffer {
|
||||
public:
|
||||
SkReadBuffer() {}
|
||||
SkReadBuffer(const void*, size_t) {}
|
||||
|
||||
enum Version {
|
||||
kTileModeInBlurImageFilter_Version = 56,
|
||||
kTileInfoInSweepGradient_Version = 57,
|
||||
k2PtConicalNoFlip_Version = 58,
|
||||
kRemovePictureImageFilterLocalSpace = 59,
|
||||
kRemoveHeaderFlags_Version = 60,
|
||||
kTwoColorDrawShadow_Version = 61,
|
||||
kDontNegateImageSize_Version = 62,
|
||||
kStoreImageBounds_Version = 63,
|
||||
kRemoveOccluderFromBlurMaskFilter = 64,
|
||||
kFloat4PaintColor_Version = 65,
|
||||
};
|
||||
|
||||
bool isVersionLT(Version) const { return false; }
|
||||
uint32_t getVersion() const { return 0xffffffff; }
|
||||
void setVersion(int) {}
|
||||
|
||||
size_t size() const { return 0; }
|
||||
size_t offset() const { return 0; }
|
||||
bool eof() { return true; }
|
||||
size_t available() const { return 0; }
|
||||
|
||||
const void* skip(size_t) { return nullptr; }
|
||||
const void* skip(size_t, size_t) { return nullptr; }
|
||||
template <typename T> const T* skipT() { return nullptr; }
|
||||
template <typename T> const T* skipT(size_t) { return nullptr; }
|
||||
|
||||
bool readBool() { return 0; }
|
||||
SkColor readColor() { return 0; }
|
||||
int32_t readInt() { return 0; }
|
||||
SkScalar readScalar() { return 0; }
|
||||
uint32_t readUInt() { return 0; }
|
||||
int32_t read32() { return 0; }
|
||||
|
||||
template <typename T> T read32LE(T max) { return max; }
|
||||
|
||||
uint8_t peekByte() { return 0; }
|
||||
|
||||
void readColor4f(SkColor4f* out) { *out = SkColor4f{0,0,0,0}; }
|
||||
void readPoint (SkPoint* out) { *out = SkPoint{0,0}; }
|
||||
void readPoint3 (SkPoint3* out) { *out = SkPoint3{0,0,0}; }
|
||||
void readMatrix (SkMatrix* out) { *out = SkMatrix::I(); }
|
||||
void readIRect (SkIRect* out) { *out = SkIRect{0,0,0,0}; }
|
||||
void readRect (SkRect* out) { *out = SkRect{0,0,0,0}; }
|
||||
void readRRect (SkRRect* out) { *out = SkRRect(); }
|
||||
void readRegion (SkRegion* out) { *out = SkRegion(); }
|
||||
void readString (SkString* out) { *out = SkString(); }
|
||||
void readPath (SkPath* out) { *out = SkPath(); }
|
||||
bool readPaint (SkPaint* out) { *out = SkPaint(); return false; }
|
||||
|
||||
SkPoint readPoint() { return {0,0}; }
|
||||
|
||||
SkFlattenable* readFlattenable(SkFlattenable::Type) { return nullptr; }
|
||||
|
||||
template <typename T> sk_sp<T> readFlattenable() { return nullptr; }
|
||||
sk_sp<SkColorFilter> readColorFilter() { return nullptr; }
|
||||
sk_sp<SkDrawLooper> readDrawLooper() { return nullptr; }
|
||||
sk_sp<SkImageFilter> readImageFilter() { return nullptr; }
|
||||
sk_sp<SkMaskFilter> readMaskFilter() { return nullptr; }
|
||||
sk_sp<SkPathEffect> readPathEffect() { return nullptr; }
|
||||
sk_sp<SkShader> readShader() { return nullptr; }
|
||||
|
||||
bool readPad32 (void*, size_t) { return false; }
|
||||
bool readByteArray (void*, size_t) { return false; }
|
||||
bool readColorArray (SkColor*, size_t) { return false; }
|
||||
bool readColor4fArray(SkColor4f*, size_t) { return false; }
|
||||
bool readIntArray (int32_t*, size_t) { return false; }
|
||||
bool readPointArray (SkPoint*, size_t) { return false; }
|
||||
bool readScalarArray (SkScalar*, size_t) { return false; }
|
||||
|
||||
sk_sp<SkData> readByteArrayAsData() { return nullptr; }
|
||||
uint32_t getArrayCount() { return 0; }
|
||||
|
||||
sk_sp<SkImage> readImage() { return nullptr; }
|
||||
sk_sp<SkTypeface> readTypeface() { return nullptr; }
|
||||
|
||||
bool validate(bool) { return false; }
|
||||
template <typename T> bool validateCanReadN(size_t) { return false; }
|
||||
bool isValid() const { return false; }
|
||||
bool validateIndex(int, int) { return false; }
|
||||
|
||||
int32_t checkInt(int min, int) { return min; }
|
||||
template <typename T> T checkRange(T min, T) { return min; }
|
||||
|
||||
SkFilterQuality checkFilterQuality() { return SkFilterQuality::kNone_SkFilterQuality; }
|
||||
|
||||
void setTypefaceArray(sk_sp<SkTypeface>[], int) {}
|
||||
void setFactoryPlayback(SkFlattenable::Factory[], int) {}
|
||||
void setDeserialProcs(const SkDeserialProcs&) {}
|
||||
|
||||
const SkDeserialProcs& getDeserialProcs() const {
|
||||
static const SkDeserialProcs procs;
|
||||
return procs;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifndef SK_DISABLE_READBUFFER
|
||||
|
||||
#endif // SkReadBuffer_DEFINED
|
||||
|
@ -373,11 +373,6 @@ void SkDashImpl::flatten(SkWriteBuffer& buffer) const {
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkDashImpl::CreateProc(SkReadBuffer& buffer) {
|
||||
#ifdef SK_DISABLE_READBUFFER
|
||||
// Should not be reachable by PathKit WebAssembly Code.
|
||||
SkASSERT(false);
|
||||
return nullptr;
|
||||
#else
|
||||
const SkScalar phase = buffer.readScalar();
|
||||
uint32_t count = buffer.getArrayCount();
|
||||
|
||||
@ -391,7 +386,6 @@ sk_sp<SkFlattenable> SkDashImpl::CreateProc(SkReadBuffer& buffer) {
|
||||
return SkDashPathEffect::Make(intervals.get(), SkToInt(count), phase);
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -89,18 +89,12 @@ void SkTrimPE::flatten(SkWriteBuffer& buffer) const {
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkTrimPE::CreateProc(SkReadBuffer& buffer) {
|
||||
#ifdef SK_DISABLE_READBUFFER
|
||||
// Should not be reachable by PathKit WebAssembly Code.
|
||||
SkASSERT(false);
|
||||
return nullptr;
|
||||
#else
|
||||
const auto start = buffer.readScalar(),
|
||||
stop = buffer.readScalar();
|
||||
const auto mode = buffer.readUInt();
|
||||
|
||||
return SkTrimPathEffect::Make(start, stop,
|
||||
(mode & 1) ? SkTrimPathEffect::Mode::kInverted : SkTrimPathEffect::Mode::kNormal);
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user