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

Unified Diff: dm/DMSrcSink.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: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index f8c9bc0b586c858df22e23e1e497e6de763b0b43..bc3b60022542382656c1c7456e11a311c9c3ceef 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1004,6 +1004,32 @@ Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+MSKPSrc::MSKPSrc(Path path) : fPath(path) {
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
+ fReader.init(stream.get());
+}
+
+int MSKPSrc::pageCount() const { return fReader.pageCount(); }
+
+SkISize MSKPSrc::size() const { return this->size(0); }
+SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); }
+
+Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
+Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
tomhudson 2016/06/01 16:54:59 We have to recreate this stream with every draw ca
hal.canary 2016/06/02 13:24:04 This is how the SKPSrc works too. These objects a
+ sk_sp<SkPicture> page = fReader.readPage(stream.get(), i);
+ if (!page) {
+ return SkStringPrintf("SkMultiPictureDocumentReader failed: %s",
tomhudson 2016/06/01 16:54:59 Do we also want the page # in this error message?
hal.canary 2016/06/02 13:24:04 good idea. I've improved all error messages and c
+ fPath.c_str());
+ }
+ canvas->drawPicture(page);
+ return "";
+}
+
+Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas());
return src.draw(canvas);
@@ -1096,44 +1122,15 @@ static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
return "Source has empty dimensions";
}
SkASSERT(doc);
- int width = src.size().width(),
- height = src.size().height();
-
- if (FLAGS_multiPage) {
- // Print the given DM:Src to a document, breaking on 8.5x11 pages.
- const int kLetterWidth = 612, // 8.5 * 72
- kLetterHeight = 792; // 11 * 72
- const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
- SkIntToScalar(kLetterHeight));
-
- int xPages = ((width - 1) / kLetterWidth) + 1;
- int yPages = ((height - 1) / kLetterHeight) + 1;
-
- for (int y = 0; y < yPages; ++y) {
- for (int x = 0; x < xPages; ++x) {
- int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
- int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
- SkCanvas* canvas =
- doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
- if (!canvas) {
- return "SkDocument::beginPage(w,h) returned nullptr";
- }
- canvas->clipRect(letter);
- canvas->translate(-letter.width() * x, -letter.height() * y);
- Error err = src.draw(canvas);
- if (!err.isEmpty()) {
- return err;
- }
- doc->endPage();
- }
- }
- } else {
+ int pageCount = src.pageCount();
+ for (int i = 0; i < pageCount; ++i) {
+ int width = src.size(i).width(), height = src.size(i).height();
SkCanvas* canvas =
doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
if (!canvas) {
return "SkDocument::beginPage(w,h) returned nullptr";
}
- Error err = src.draw(canvas);
+ Error err = src.draw(i, canvas);
if (!err.isEmpty()) {
return err;
}

Powered by Google App Engine
This is Rietveld 408576698