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

Side by Side Diff: dm/DMSrcSink.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 | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkAndroidCodec.h" 10 #include "SkAndroidCodec.h"
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 if (!viewport.intersect(info.fCullRect)) { 1000 if (!viewport.intersect(info.fCullRect)) {
1001 return SkISize::Make(0,0); 1001 return SkISize::Make(0,0);
1002 } 1002 }
1003 return viewport.roundOut().size(); 1003 return viewport.roundOut().size();
1004 } 1004 }
1005 1005
1006 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } 1006 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1007 1007
1008 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1008 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1009 1009
1010 MSKPSrc::MSKPSrc(Path path) : fPath(path) {
1011 std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
1012 (void)fReader.init(stream.get());
1013 }
1014
1015 int MSKPSrc::pageCount() const { return fReader.pageCount(); }
1016
1017 SkISize MSKPSrc::size() const { return this->size(0); }
1018 SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); }
1019
1020 Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
1021 Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
1022 std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
1023 if (!stream) {
1024 return SkStringPrintf("Unable to open file: %s", fPath.c_str());
1025 }
1026 if (fReader.pageCount() == 0) {
1027 return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", f Path.c_str());
1028 }
1029 if (i >= fReader.pageCount()) {
1030 return SkStringPrintf("MultiPictureDocument page number out of range: %d ", i);
1031 }
1032 sk_sp<SkPicture> page = fReader.readPage(stream.get(), i);
1033 if (!page) {
1034 return SkStringPrintf("SkMultiPictureDocumentReader failed on page %d: % s",
1035 i, fPath.c_str());
1036 }
1037 canvas->drawPicture(page);
1038 return "";
1039 }
1040
1041 Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1042
1043 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1044
1010 Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const { 1045 Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
1011 SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas()); 1046 SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas());
1012 return src.draw(canvas); 1047 return src.draw(canvas);
1013 } 1048 }
1014 1049
1015 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1050 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1016 1051
1017 DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?"); 1052 DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
1018 1053
1019 GPUSink::GPUSink(GrContextFactory::ContextType ct, 1054 GPUSink::GPUSink(GrContextFactory::ContextType ct,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 return ""; 1127 return "";
1093 } 1128 }
1094 1129
1095 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1130 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1096 1131
1097 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { 1132 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
1098 if (src.size().isEmpty()) { 1133 if (src.size().isEmpty()) {
1099 return "Source has empty dimensions"; 1134 return "Source has empty dimensions";
1100 } 1135 }
1101 SkASSERT(doc); 1136 SkASSERT(doc);
1102 int width = src.size().width(), 1137 int pageCount = src.pageCount();
1103 height = src.size().height(); 1138 for (int i = 0; i < pageCount; ++i) {
1104 1139 int width = src.size(i).width(), height = src.size(i).height();
1105 if (FLAGS_multiPage) {
1106 // Print the given DM:Src to a document, breaking on 8.5x11 pages.
1107 const int kLetterWidth = 612, // 8.5 * 72
1108 kLetterHeight = 792; // 11 * 72
1109 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
1110 SkIntToScalar(kLetterHeight));
1111
1112 int xPages = ((width - 1) / kLetterWidth) + 1;
1113 int yPages = ((height - 1) / kLetterHeight) + 1;
1114
1115 for (int y = 0; y < yPages; ++y) {
1116 for (int x = 0; x < xPages; ++x) {
1117 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
1118 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
1119 SkCanvas* canvas =
1120 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
1121 if (!canvas) {
1122 return "SkDocument::beginPage(w,h) returned nullptr";
1123 }
1124 canvas->clipRect(letter);
1125 canvas->translate(-letter.width() * x, -letter.height() * y);
1126 Error err = src.draw(canvas);
1127 if (!err.isEmpty()) {
1128 return err;
1129 }
1130 doc->endPage();
1131 }
1132 }
1133 } else {
1134 SkCanvas* canvas = 1140 SkCanvas* canvas =
1135 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height)); 1141 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
1136 if (!canvas) { 1142 if (!canvas) {
1137 return "SkDocument::beginPage(w,h) returned nullptr"; 1143 return "SkDocument::beginPage(w,h) returned nullptr";
1138 } 1144 }
1139 Error err = src.draw(canvas); 1145 Error err = src.draw(i, canvas);
1140 if (!err.isEmpty()) { 1146 if (!err.isEmpty()) {
1141 return err; 1147 return err;
1142 } 1148 }
1143 doc->endPage(); 1149 doc->endPage();
1144 } 1150 }
1145 if (!doc->close()) { 1151 if (!doc->close()) {
1146 return "SkDocument::close() returned false"; 1152 return "SkDocument::close() returned false";
1147 } 1153 }
1148 dst->flush(); 1154 dst->flush();
1149 return ""; 1155 return "";
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 skr.visit(i, drawsAsSingletonPictures); 1539 skr.visit(i, drawsAsSingletonPictures);
1534 } 1540 }
1535 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); 1541 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture());
1536 1542
1537 canvas->drawPicture(macroPic); 1543 canvas->drawPicture(macroPic);
1538 return check_against_reference(bitmap, src, fSink); 1544 return check_against_reference(bitmap, src, fSink);
1539 }); 1545 });
1540 } 1546 }
1541 1547
1542 } // namespace DM 1548 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698