Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1ce8964

Browse files
Nathaniel NifongSkia Commit-Bot
authored andcommitted
Move SKP version extraction into JS
two reasons: 1. It prevents any crash during reading from prevening a version number being returned from wasm. 2. It lets me use a common solution for reading a version number from SKP files and MSKP files. bug:skia:10832 Change-Id: Icad27690aac9d614d72140ea4b88b350faf21a4f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334897 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Nathaniel Nifong <nifong@google.com>
1 parent ee33a3a commit 1ce8964

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

experimental/wasm-skp-debugger/debugger_bindings.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SimpleImageInfo toSimpleImageInfo(const SkImageInfo& ii) {
6565
return (SimpleImageInfo){ii.width(), ii.height(), ii.colorType(), ii.alphaType()};
6666
}
6767

68+
uint32_t MinVersion() { return SkPicturePriv::kMin_Version; }
69+
6870
class SkpDebugPlayer {
6971
public:
7072
SkpDebugPlayer() :
@@ -84,34 +86,24 @@ class SkpDebugPlayer {
8486
*/
8587
std::string loadSkp(uintptr_t cptr, int length) {
8688
const uint8_t* data = reinterpret_cast<const uint8_t*>(cptr);
87-
char magic[8];
8889
// Both traditional and multi-frame skp files have a magic word
8990
SkMemoryStream stream(data, length);
9091
SkDebugf("make stream at %p, with %d bytes\n",data, length);
91-
// Why -1? I think it's got to do with using a constexpr, just a guess.
92-
const size_t magicsize = sizeof(kMultiMagic) - 1;
93-
const bool isMulti = memcmp(data, kMultiMagic, magicsize) == 0;
92+
const bool isMulti = memcmp(data, kMultiMagic, sizeof(kMultiMagic) - 1) == 0;
93+
94+
9495
if (isMulti) {
9596
SkDebugf("Try reading as a multi-frame skp\n");
9697
const auto& error = loadMultiFrame(&stream);
9798
if (!error.empty()) { return error; }
9899
} else {
99100
SkDebugf("Try reading as single-frame skp\n");
100-
// The unint32 after the magic string is the SKP version
101-
memcpy(&fFileVersion, data + 8, 4);
102101
// TODO(nifong): Rely on SkPicture's return errors once it provides some.
103-
if (fFileVersion < SkPicturePriv::kMin_Version ||
104-
fFileVersion > SkPicturePriv::kCurrent_Version) {
105-
return std::string(SkStringPrintf("Skp version (%d) cannot be read by this build. Version range supported = (%d, %d)",
106-
fFileVersion, SkPicturePriv::kMin_Version, SkPicturePriv::kCurrent_Version).c_str());
107-
}
108102
frames.push_back(loadSingleFrame(&stream));
109103
}
110104
return "";
111105
}
112106

113-
uint32_t fileVersion() { return fFileVersion; }
114-
115107
/* drawTo asks the debug canvas to draw from the beginning of the picture
116108
* to the given command and flush the canvas.
117109
*/
@@ -467,8 +459,6 @@ class SkpDebugPlayer {
467459
int fp = 0;
468460
// The width and height of the animation. (in practice the bounds of the last loaded frame)
469461
SkIRect fBounds;
470-
// SKP version of loaded file.
471-
uint32_t fFileVersion;
472462
// image resources from a loaded file
473463
std::vector<sk_sp<SkImage>> fImages;
474464

@@ -556,14 +546,15 @@ sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageIn
556546
using namespace emscripten;
557547
EMSCRIPTEN_BINDINGS(my_module) {
558548

549+
function("MinVersion", &MinVersion);
550+
559551
// The main class that the JavaScript in index.html uses
560552
class_<SkpDebugPlayer>("SkpDebugPlayer")
561553
.constructor<>()
562554
.function("changeFrame", &SkpDebugPlayer::changeFrame)
563555
.function("deleteCommand", &SkpDebugPlayer::deleteCommand)
564556
.function("draw", &SkpDebugPlayer::draw, allow_raw_pointers())
565557
.function("drawTo", &SkpDebugPlayer::drawTo, allow_raw_pointers())
566-
.function("fileVersion", &SkpDebugPlayer::fileVersion)
567558
.function("findCommandByPixel", &SkpDebugPlayer::findCommandByPixel, allow_raw_pointers())
568559
.function("getBounds", &SkpDebugPlayer::getBounds)
569560
.function("getFrameCount", &SkpDebugPlayer::getFrameCount)

0 commit comments

Comments
 (0)