Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: src/effects/SkTableColorFilter.cpp

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkRectShaderImageFilter.cpp ('k') | src/effects/SkTableMaskFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkTableColorFilter.cpp
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 2544b0384174466d2a390b95e2d3f88c7d3dde0e..54e1efe5501a21c45693dbf5b6cdad642df4e104 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -61,7 +61,9 @@ public:
};
protected:
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkTable_ColorFilter(SkReadBuffer& buffer);
+#endif
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
private:
@@ -70,6 +72,8 @@ private:
uint8_t fStorage[256 * 4];
unsigned fFlags;
+ friend class SkTableColorFilter;
+
typedef SkColorFilter INHERITED;
};
@@ -168,19 +172,62 @@ static const uint8_t gCountNibBits[] = {
#include "SkPackBits.h"
void SkTable_ColorFilter::flatten(SkWriteBuffer& buffer) const {
- this->INHERITED::flatten(buffer);
-
uint8_t storage[5*256];
int count = gCountNibBits[fFlags & 0xF];
size_t size = SkPackBits::Pack8(fStorage, count * 256, storage);
SkASSERT(size <= sizeof(storage));
-// SkDebugf("raw %d packed %d\n", count * 256, size);
-
- buffer.writeInt(fFlags);
+ buffer.write32(fFlags);
buffer.writeByteArray(storage, size);
}
+SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) {
+ const int flags = buffer.read32();
+ const size_t count = gCountNibBits[flags & 0xF];
+ SkASSERT(count <= 4);
+
+ uint8_t packedStorage[5*256];
+ size_t packedSize = buffer.getArrayCount();
+ if (!buffer.validate(packedSize <= sizeof(packedStorage))) {
+ return NULL;
+ }
+ if (!buffer.readByteArray(packedStorage, packedSize)) {
+ return NULL;
+ }
+
+ uint8_t unpackedStorage[4*256];
+ size_t unpackedSize = SkPackBits::Unpack8(packedStorage, packedSize, unpackedStorage);
+ // now check that we got the size we expected
+ if (!buffer.validate(unpackedSize != count*256)) {
+ return NULL;
+ }
+
+ const uint8_t* a = NULL;
+ const uint8_t* r = NULL;
+ const uint8_t* g = NULL;
+ const uint8_t* b = NULL;
+ const uint8_t* ptr = unpackedStorage;
+
+ if (flags & kA_Flag) {
+ a = ptr;
+ ptr += 256;
+ }
+ if (flags & kR_Flag) {
+ r = ptr;
+ ptr += 256;
+ }
+ if (flags & kG_Flag) {
+ g = ptr;
+ ptr += 256;
+ }
+ if (flags & kB_Flag) {
+ b = ptr;
+ ptr += 256;
+ }
+ return SkTableColorFilter::CreateARGB(a, r, g, b);
+}
+
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkTable_ColorFilter::SkTable_ColorFilter(SkReadBuffer& buffer) : INHERITED(buffer) {
fBitmap = NULL;
@@ -199,6 +246,7 @@ SkTable_ColorFilter::SkTable_ColorFilter(SkReadBuffer& buffer) : INHERITED(buffe
SkDEBUGCODE(size_t count = gCountNibBits[fFlags & 0xF]);
SkASSERT(raw == count * 256);
}
+#endif
bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const {
if (table) {
« no previous file with comments | « src/effects/SkRectShaderImageFilter.cpp ('k') | src/effects/SkTableMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698