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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1837263007: DM: allow vias to work with PDF backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 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 "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // passing the Sink draw() arguments, a size, and a function draws into an SkCan vas. 1155 // passing the Sink draw() arguments, a size, and a function draws into an SkCan vas.
1156 // Several examples below. 1156 // Several examples below.
1157 1157
1158 template <typename Fn> 1158 template <typename Fn>
1159 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS tring* log, 1159 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS tring* log,
1160 SkISize size, const Fn& draw) { 1160 SkISize size, const Fn& draw) {
1161 class ProxySrc : public Src { 1161 class ProxySrc : public Src {
1162 public: 1162 public:
1163 ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {} 1163 ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {}
1164 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); } 1164 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
1165 Name name() const override { sk_throw(); return ""; } // Won't be called. 1165 Name name() const override { return "ProxySrc"; }
1166 SkISize size() const override { return fSize; } 1166 SkISize size() const override { return fSize; }
1167 private: 1167 private:
1168 SkISize fSize; 1168 SkISize fSize;
1169 const Fn& fDraw; 1169 const Fn& fDraw;
1170 }; 1170 };
1171 return sink->draw(ProxySrc(size, draw), bitmap, stream, log); 1171 return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
1172 } 1172 }
1173 1173
1174 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1174 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1175 1175
1176 DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output."); 1176 DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output.");
1177 1177
1178 // Is *bitmap identical to what you get drawing src into sink? 1178 // Is *bitmap identical to what you get drawing src into sink?
1179 static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sin k* sink) { 1179 static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sin k* sink) {
1180 // We can only check raster outputs. 1180 // We can only check raster outputs.
1181 // (Non-raster outputs like .pdf, .skp, .svg may differ but still draw ident ically.) 1181 // (Non-raster outputs like .pdf, .skp, .svg may differ but still draw ident ically.)
1182 if (FLAGS_check && bitmap) { 1182 if (FLAGS_check && bitmap) {
1183 SkBitmap reference; 1183 SkBitmap reference;
1184 SkString log; 1184 SkString log;
1185 Error err = sink->draw(src, &reference, nullptr, &log); 1185 SkDynamicMemoryWStream wStream;
1186 Error err = sink->draw(src, &reference, &wStream, &log);
1186 // If we can draw into this Sink via some pipeline, we should be able to draw directly. 1187 // If we can draw into this Sink via some pipeline, we should be able to draw directly.
1187 SkASSERT(err.isEmpty()); 1188 SkASSERT(err.isEmpty());
1188 if (!err.isEmpty()) { 1189 if (!err.isEmpty()) {
1189 return err; 1190 return err;
1190 } 1191 }
1191 // The dimensions are a property of the Src only, and so should be ident ical. 1192 // The dimensions are a property of the Src only, and so should be ident ical.
1192 SkASSERT(reference.getSize() == bitmap->getSize()); 1193 SkASSERT(reference.getSize() == bitmap->getSize());
1193 if (reference.getSize() != bitmap->getSize()) { 1194 if (reference.getSize() != bitmap->getSize()) {
1194 return "Dimensions don't match reference"; 1195 return "Dimensions don't match reference";
1195 } 1196 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 skr.visit(i, drawsAsSingletonPictures); 1507 skr.visit(i, drawsAsSingletonPictures);
1507 } 1508 }
1508 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); 1509 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture());
1509 1510
1510 canvas->drawPicture(macroPic); 1511 canvas->drawPicture(macroPic);
1511 return check_against_reference(bitmap, src, fSink); 1512 return check_against_reference(bitmap, src, fSink);
1512 }); 1513 });
1513 } 1514 }
1514 1515
1515 } // namespace DM 1516 } // namespace DM
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