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

Side by Side Diff: src/utils/SkMultiPictureDocumentReader.cpp

Issue 2023593002: SkMultiPictureDocument & SkMultiPictureDocumentReader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-06-02 (Thursday) 09:23:50 EDT Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « src/utils/SkMultiPictureDocumentReader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkMultiPictureDocumentPriv.h"
9 #include "SkMultiPictureDocumentReader.h"
10 #include "SkPicture.h"
11 #include "SkStream.h"
12
13 bool SkMultiPictureDocumentReader::init(SkStreamSeekable* stream) {
14 if (!stream) {
15 return false;
16 }
17 stream->seek(0);
18 const size_t size = sizeof(SkMultiPictureDocumentProtocol::kMagic) - 1;
19 char buffer[size];
20 if (size != stream->read(buffer, size) ||
21 0 != memcmp(SkMultiPictureDocumentProtocol::kMagic, buffer, size)) {
22 stream = nullptr;
23 return false;
24 }
25 bool good = true;
26 uint32_t versionNumber = stream->readU32();
27 if (versionNumber != 1) {
28 return false;
29 }
30 uint32_t pageCount = stream->readU32();
31 fSizes.reset(pageCount);
32 fOffsets.reset(pageCount);
33 for (uint32_t i = 0; i < pageCount; ++i) {
34 SkMultiPictureDocumentProtocol::Entry entry;
35 good &= sizeof(entry) == stream->read(&entry, sizeof(entry));
36 fSizes[i] = SkSize::Make(entry.sizeX, entry.sizeY);
37 good &= SkTFitsIn<size_t>(entry.offset);
38 fOffsets[i] = static_cast<size_t>(entry.offset);
39 }
40 return good;
41 }
42
43 sk_sp<SkPicture> SkMultiPictureDocumentReader::readPage(SkStreamSeekable* stream ,
44 int pageNumber) const {
45 SkASSERT(pageNumber >= 0);
46 SkASSERT(pageNumber < fOffsets.count());
47 SkAssertResult(stream->seek(fOffsets[pageNumber]));
48 return SkPicture::MakeFromStream(stream);
49 }
OLDNEW
« no previous file with comments | « src/utils/SkMultiPictureDocumentReader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698