diff options
author | halcanary <halcanary@google.com> | 2016-06-14 11:06:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-14 11:06:37 -0700 |
commit | 59d6402ba7dae4ed1e26c155b7c446d6f7ec3527 (patch) | |
tree | 2f481bbd49c4bd380f67db7837298251c94b2e7f | |
parent | 4999616c3af3ddd38b4d12213eeeaeabee4907c5 (diff) |
SkMultiPictureDocument: don't rely on SkPicture::cullRect
SkPicture::cullRect() is not guaranteed to be the same as the
bounds passed to SkPictureRecorder::beginRecording().
Review-Url: https://codereview.chromium.org/2067473003
-rw-r--r-- | src/utils/SkMultiPictureDocument.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/utils/SkMultiPictureDocument.cpp b/src/utils/SkMultiPictureDocument.cpp index 1cbf0aebc1..e4105fa31d 100644 --- a/src/utils/SkMultiPictureDocument.cpp +++ b/src/utils/SkMultiPictureDocument.cpp @@ -5,6 +5,8 @@ * found in the LICENSE file. */ +#include <vector> + #include "SkMultiPictureDocument.h" #include "SkMultiPictureDocumentPriv.h" #include "SkPicture.h" @@ -56,18 +58,35 @@ struct NullWStream : public SkWStream { size_t fN; }; +struct Page { + Page(SkSize s, sk_sp<SkPicture> c) : fSize(s), fContent(std::move(c)) {} + Page(Page&& that) : fSize(that.fSize), fContent(std::move(that.fContent)) {} + Page(const Page&) = default; + Page& operator=(const Page&) = default; + Page& operator=(Page&& that) { + fSize = that.fSize; + fContent = std::move(that.fContent); + return *this; + } + SkSize fSize; + sk_sp<SkPicture> fContent; +}; + struct MultiPictureDocument final : public SkDocument { SkPictureRecorder fPictureRecorder; - SkTArray<sk_sp<SkPicture>> fPages; + SkSize fCurrentPageSize; + std::vector<Page> fPages; MultiPictureDocument(SkWStream* s, void (*d)(SkWStream*, bool)) : SkDocument(s, d) {} ~MultiPictureDocument() { this->close(); } SkCanvas* onBeginPage(SkScalar w, SkScalar h, const SkRect& c) override { + fCurrentPageSize.set(w, h); return trim(fPictureRecorder.beginRecording(w, h), w, h, c); } void onEndPage() override { - fPages.emplace_back(fPictureRecorder.finishRecordingAsPicture()); + fPages.emplace_back(fCurrentPageSize, + fPictureRecorder.finishRecordingAsPicture()); } bool onClose(SkWStream* wStream) override { SkASSERT(wStream); @@ -75,29 +94,26 @@ struct MultiPictureDocument final : public SkDocument { bool good = true; good &= wStream->writeText(SkMultiPictureDocumentProtocol::kMagic); good &= wStream->write32(SkToU32(1)); // version - good &= wStream->write32(SkToU32(fPages.count())); + good &= wStream->write32(SkToU32(fPages.size())); uint64_t offset = wStream->bytesWritten(); - offset += fPages.count() * sizeof(SkMultiPictureDocumentProtocol::Entry); + offset += fPages.size() * sizeof(SkMultiPictureDocumentProtocol::Entry); for (const auto& page : fPages) { - SkRect cullRect = page->cullRect(); - // We recorded a picture at the origin. - SkASSERT(cullRect.x() == 0 && cullRect.y() == 0); SkMultiPictureDocumentProtocol::Entry entry{ - offset, (float)cullRect.right(), (float)cullRect.bottom()}; + offset, page.fSize.width(), page.fSize.height()}; good &= wStream->write(&entry, sizeof(entry)); NullWStream buffer; - page->serialize(&buffer); + page.fContent->serialize(&buffer); offset += buffer.bytesWritten(); } for (const auto& page : fPages) { - page->serialize(wStream); + page.fContent->serialize(wStream); } SkASSERT(wStream->bytesWritten() == offset); good &= wStream->writeText("\nEndOfMultiPicture\n"); - fPages.reset(); + fPages.clear(); return good; } - void onAbort() override { fPages.reset(); } + void onAbort() override { fPages.clear(); } }; } |