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

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

Issue 2067473003: SkMultiPictureDocument: don't rely on SkPicture::cullRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | 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
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <vector>
9
8 #include "SkMultiPictureDocument.h" 10 #include "SkMultiPictureDocument.h"
9 #include "SkMultiPictureDocumentPriv.h" 11 #include "SkMultiPictureDocumentPriv.h"
10 #include "SkPicture.h" 12 #include "SkPicture.h"
11 #include "SkPictureRecorder.h" 13 #include "SkPictureRecorder.h"
12 #include "SkStream.h" 14 #include "SkStream.h"
13 15
14 /* 16 /*
15 File format: 17 File format:
16 BEGINNING_OF_FILE: 18 BEGINNING_OF_FILE:
17 kMagic 19 kMagic
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 struct NullWStream : public SkWStream { 51 struct NullWStream : public SkWStream {
50 NullWStream() : fN(0) {} 52 NullWStream() : fN(0) {}
51 bool write(const void*, size_t n) override { 53 bool write(const void*, size_t n) override {
52 fN += n; 54 fN += n;
53 return true; 55 return true;
54 } 56 }
55 size_t bytesWritten() const override { return fN; } 57 size_t bytesWritten() const override { return fN; }
56 size_t fN; 58 size_t fN;
57 }; 59 };
58 60
61 struct Page {
62 Page(SkSize s, sk_sp<SkPicture> c) : fSize(s), fContent(std::move(c)) {}
63 Page(Page&& that) : fSize(that.fSize), fContent(std::move(that.fContent)) {}
64 Page(const Page&) = default;
65 Page& operator=(const Page&) = default;
66 Page& operator=(Page&& that) {
67 fSize = that.fSize;
68 fContent = std::move(that.fContent);
69 return *this;
70 }
71 SkSize fSize;
72 sk_sp<SkPicture> fContent;
73 };
74
59 struct MultiPictureDocument final : public SkDocument { 75 struct MultiPictureDocument final : public SkDocument {
60 SkPictureRecorder fPictureRecorder; 76 SkPictureRecorder fPictureRecorder;
61 SkTArray<sk_sp<SkPicture>> fPages; 77 SkSize fPageSize;
tomhudson 2016/06/14 17:23:29 bikeshed: fCurrentPageSize?
hal.canary 2016/06/14 17:53:28 Done.
78 std::vector<Page> fPages;
62 MultiPictureDocument(SkWStream* s, void (*d)(SkWStream*, bool)) 79 MultiPictureDocument(SkWStream* s, void (*d)(SkWStream*, bool))
63 : SkDocument(s, d) {} 80 : SkDocument(s, d) {}
64 ~MultiPictureDocument() { this->close(); } 81 ~MultiPictureDocument() { this->close(); }
65 82
66 SkCanvas* onBeginPage(SkScalar w, SkScalar h, const SkRect& c) override { 83 SkCanvas* onBeginPage(SkScalar w, SkScalar h, const SkRect& c) override {
84 fPageSize.set(w, h);
67 return trim(fPictureRecorder.beginRecording(w, h), w, h, c); 85 return trim(fPictureRecorder.beginRecording(w, h), w, h, c);
68 } 86 }
69 void onEndPage() override { 87 void onEndPage() override {
70 fPages.emplace_back(fPictureRecorder.finishRecordingAsPicture()); 88 fPages.emplace_back(fPageSize, fPictureRecorder.finishRecordingAsPicture ());
71 } 89 }
72 bool onClose(SkWStream* wStream) override { 90 bool onClose(SkWStream* wStream) override {
73 SkASSERT(wStream); 91 SkASSERT(wStream);
74 SkASSERT(wStream->bytesWritten() == 0); 92 SkASSERT(wStream->bytesWritten() == 0);
75 bool good = true; 93 bool good = true;
76 good &= wStream->writeText(SkMultiPictureDocumentProtocol::kMagic); 94 good &= wStream->writeText(SkMultiPictureDocumentProtocol::kMagic);
77 good &= wStream->write32(SkToU32(1)); // version 95 good &= wStream->write32(SkToU32(1)); // version
78 good &= wStream->write32(SkToU32(fPages.count())); 96 good &= wStream->write32(SkToU32(fPages.size()));
79 uint64_t offset = wStream->bytesWritten(); 97 uint64_t offset = wStream->bytesWritten();
80 offset += fPages.count() * sizeof(SkMultiPictureDocumentProtocol::Entry) ; 98 offset += fPages.size() * sizeof(SkMultiPictureDocumentProtocol::Entry);
81 for (const auto& page : fPages) { 99 for (const auto& page : fPages) {
82 SkRect cullRect = page->cullRect();
83 // We recorded a picture at the origin.
84 SkASSERT(cullRect.x() == 0 && cullRect.y() == 0);
85 SkMultiPictureDocumentProtocol::Entry entry{ 100 SkMultiPictureDocumentProtocol::Entry entry{
86 offset, (float)cullRect.right(), (float)cullRect.bottom()}; 101 offset, page.fSize.width(), page.fSize.height()};
87 good &= wStream->write(&entry, sizeof(entry)); 102 good &= wStream->write(&entry, sizeof(entry));
88 NullWStream buffer; 103 NullWStream buffer;
89 page->serialize(&buffer); 104 page.fContent->serialize(&buffer);
90 offset += buffer.bytesWritten(); 105 offset += buffer.bytesWritten();
91 } 106 }
92 for (const auto& page : fPages) { 107 for (const auto& page : fPages) {
93 page->serialize(wStream); 108 page.fContent->serialize(wStream);
94 } 109 }
95 SkASSERT(wStream->bytesWritten() == offset); 110 SkASSERT(wStream->bytesWritten() == offset);
96 good &= wStream->writeText("\nEndOfMultiPicture\n"); 111 good &= wStream->writeText("\nEndOfMultiPicture\n");
97 fPages.reset(); 112 fPages.clear();
98 return good; 113 return good;
99 } 114 }
100 void onAbort() override { fPages.reset(); } 115 void onAbort() override { fPages.clear(); }
101 }; 116 };
102 } 117 }
103 118
104 sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* wStream) { 119 sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* wStream) {
105 return sk_make_sp<MultiPictureDocument>(wStream, nullptr); 120 return sk_make_sp<MultiPictureDocument>(wStream, nullptr);
106 } 121 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698