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

Unified Diff: tools/SkMultiPictureDocumentReader.cpp

Issue 2023593002: SkMultiPictureDocument & SkMultiPictureDocumentReader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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
Index: tools/SkMultiPictureDocumentReader.cpp
diff --git a/tools/SkMultiPictureDocumentReader.cpp b/tools/SkMultiPictureDocumentReader.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..406f27b9ec2ecfa63cd159bd46ddc4eef8d8b8e6
--- /dev/null
+++ b/tools/SkMultiPictureDocumentReader.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkMultiPictureDocumentPriv.h"
+#include "SkMultiPictureDocumentReader.h"
+#include "SkPicture.h"
+#include "SkStream.h"
+
+bool SkMultiPictureDocumentReader::init(SkStreamSeekable* stream) {
+ stream->seek(0);
+ const size_t size = sizeof(SkMultiPictureDocumentProtocol::kMagic) - 1;
+ char buffer[size];
+ if (size != stream->read(buffer, size) ||
+ 0 != memcmp(SkMultiPictureDocumentProtocol::kMagic, buffer, size)) {
+ stream = nullptr;
+ return false;
+ }
+ bool good = true;
+ uint32_t versionNumber = stream->readU32();
+ if (versionNumber != 1) {
+ return false;
+ }
+ uint32_t pageCount = stream->readU32();
+ fSizes.reset(pageCount);
+ fOffsets.reset(pageCount);
+ for (uint32_t i = 0; i < pageCount; ++i) {
+ SkMultiPictureDocumentProtocol::Entry entry;
+ good &= sizeof(entry) == stream->read(&entry, sizeof(entry));
+ fSizes[i] = SkSize::Make(entry.sizeX, entry.sizeY);
+ good &= SkTFitsIn<size_t>(entry.offset);
+ fOffsets[i] = static_cast<size_t>(entry.offset);
+ }
+ return good;
+}
+
+sk_sp<SkPicture> SkMultiPictureDocumentReader::readPage(SkStreamSeekable* stream,
+ int pageNumber) const {
+ SkASSERT(pageNumber >= 0);
+ SkASSERT(pageNumber < fOffsets.count());
+ SkAssertResult(stream->seek(fOffsets[pageNumber]));
+ return SkPicture::MakeFromStream(stream);
+}
« src/core/SkMultiPictureDocument.cpp ('K') | « tools/SkMultiPictureDocumentReader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698