diff --git a/src/sksl/SkSLDehydrator.cpp b/src/sksl/SkSLDehydrator.cpp index 001c5805fd..d8708eeb46 100644 --- a/src/sksl/SkSLDehydrator.cpp +++ b/src/sksl/SkSLDehydrator.cpp @@ -592,11 +592,11 @@ void Dehydrator::write(const std::vector>& eleme } void Dehydrator::finish(OutputStream& out) { + out.write16(Rehydrator::kVersion); String stringBuffer = fStringBuffer.str(); String commandBuffer = fBody.str(); - out.write16(fStringBuffer.str().size()); - fStringBufferStart = 2; + fStringBufferStart = 4; out.writeString(stringBuffer); fCommandStart = fStringBufferStart + stringBuffer.size(); out.writeString(commandBuffer); diff --git a/src/sksl/SkSLDehydrator.h b/src/sksl/SkSLDehydrator.h index bec942323f..c9ef1f8e36 100644 --- a/src/sksl/SkSLDehydrator.h +++ b/src/sksl/SkSLDehydrator.h @@ -32,6 +32,7 @@ class SymbolTable; // The file has the structure: // +// uint16 version // uint16 total string length // string data // symboltable diff --git a/src/sksl/SkSLRehydrator.cpp b/src/sksl/SkSLRehydrator.cpp index 5d911f5694..dba04e571c 100644 --- a/src/sksl/SkSLRehydrator.cpp +++ b/src/sksl/SkSLRehydrator.cpp @@ -79,12 +79,16 @@ Rehydrator::Rehydrator(const Context* context, std::shared_ptr sym const uint8_t* src, size_t length) : fContext(*context) , fSymbolTable(std::move(symbolTable)) - , fStart(src) - SkDEBUGCODE(, fEnd(fStart + length)) { + SkDEBUGCODE(, fEnd(src + length)) { SkASSERT(fSymbolTable); SkASSERT(fSymbolTable->isBuiltin()); - // skip past string data - fIP = fStart; + fIP = src; + uint16_t version = this->readU16(); + (void)version; + SkASSERTF(version == kVersion, "Dehydrated file is an unsupported version (current version is " + "%d, found version %d)", kVersion, version); + fStringStart = fIP; + // skip over string data fIP += this->readU16(); } diff --git a/src/sksl/SkSLRehydrator.h b/src/sksl/SkSLRehydrator.h index 22c1bf3280..80bb5bb016 100644 --- a/src/sksl/SkSLRehydrator.h +++ b/src/sksl/SkSLRehydrator.h @@ -32,6 +32,8 @@ class Type; */ class Rehydrator { public: + static constexpr uint16_t kVersion = 1; + enum Command { // uint16 id, Type componentType, uint8 count kArrayType_Command, @@ -180,8 +182,8 @@ private: skstd::string_view readString() { uint16_t offset = this->readU16(); - uint8_t length = *(uint8_t*) (fStart + offset); - const char* chars = (const char*) fStart + offset + 1; + uint8_t length = *(uint8_t*) (fStringStart + offset); + const char* chars = (const char*) fStringStart + offset + 1; return skstd::string_view(chars, length); } @@ -223,7 +225,7 @@ private: std::shared_ptr fSymbolTable; std::vector fSymbols; - const uint8_t* fStart; + const uint8_t* fStringStart; const uint8_t* fIP; SkDEBUGCODE(const uint8_t* fEnd;) diff --git a/src/sksl/generated/sksl_frag.dehydrated.sksl b/src/sksl/generated/sksl_frag.dehydrated.sksl index e59be1343d..429e2e0ef9 100644 --- a/src/sksl/generated/sksl_frag.dehydrated.sksl +++ b/src/sksl/generated/sksl_frag.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_frag[] = {96,0, +static uint8_t SKSL_INCLUDE_sksl_frag[] = {1,0,96,0, 12,115,107,95,70,114,97,103,67,111,111,114,100, 6,102,108,111,97,116,52, 12,115,107,95,67,108,111,99,107,119,105,115,101, diff --git a/src/sksl/generated/sksl_gpu.dehydrated.sksl b/src/sksl/generated/sksl_gpu.dehydrated.sksl index a135eb2b15..9a868271e8 100644 --- a/src/sksl/generated/sksl_gpu.dehydrated.sksl +++ b/src/sksl/generated/sksl_gpu.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_gpu[] = {189,8, +static uint8_t SKSL_INCLUDE_sksl_gpu[] = {1,0,189,8, 7,100,101,103,114,101,101,115, 8,36,103,101,110,84,121,112,101, 7,114,97,100,105,97,110,115, diff --git a/src/sksl/generated/sksl_public.dehydrated.sksl b/src/sksl/generated/sksl_public.dehydrated.sksl index 188966c7cb..5a343874c8 100644 --- a/src/sksl/generated/sksl_public.dehydrated.sksl +++ b/src/sksl/generated/sksl_public.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_public[] = {227,3, +static uint8_t SKSL_INCLUDE_sksl_public[] = {1,0,227,3, 7,100,101,103,114,101,101,115, 8,36,103,101,110,84,121,112,101, 7,114,97,100,105,97,110,115, diff --git a/src/sksl/generated/sksl_rt_shader.dehydrated.sksl b/src/sksl/generated/sksl_rt_shader.dehydrated.sksl index f765b76114..69fcc0bb62 100644 --- a/src/sksl/generated/sksl_rt_shader.dehydrated.sksl +++ b/src/sksl/generated/sksl_rt_shader.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_rt_shader[] = {20,0, +static uint8_t SKSL_INCLUDE_sksl_rt_shader[] = {1,0,20,0, 12,115,107,95,70,114,97,103,67,111,111,114,100, 6,102,108,111,97,116,52, 47,1,0, diff --git a/src/sksl/generated/sksl_vert.dehydrated.sksl b/src/sksl/generated/sksl_vert.dehydrated.sksl index f6b73288e4..95c253434a 100644 --- a/src/sksl/generated/sksl_vert.dehydrated.sksl +++ b/src/sksl/generated/sksl_vert.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_vert[] = {82,0, +static uint8_t SKSL_INCLUDE_sksl_vert[] = {1,0,82,0, 12,115,107,95,80,101,114,86,101,114,116,101,120, 11,115,107,95,80,111,115,105,116,105,111,110, 6,102,108,111,97,116,52,