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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1360943003: simplify code in SkRecords.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another SaveLayer Created 5 years, 2 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 | include/private/SkRecords.h » ('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 "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
11 #include "SkCodecTools.h" 11 #include "SkCodecTools.h"
12 #include "SkCommonFlags.h" 12 #include "SkCommonFlags.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 #include "SkDocument.h" 14 #include "SkDocument.h"
15 #include "SkError.h" 15 #include "SkError.h"
16 #include "SkFunction.h" 16 #include "SkFunction.h"
17 #include "SkImageGenerator.h" 17 #include "SkImageGenerator.h"
18 #include "SkMultiPictureDraw.h" 18 #include "SkMultiPictureDraw.h"
19 #include "SkNullCanvas.h" 19 #include "SkNullCanvas.h"
20 #include "SkOSFile.h" 20 #include "SkOSFile.h"
21 #include "SkPictureData.h" 21 #include "SkPictureData.h"
22 #include "SkPictureRecorder.h" 22 #include "SkPictureRecorder.h"
23 #include "SkRandom.h" 23 #include "SkRandom.h"
24 #include "SkRecordDraw.h" 24 #include "SkRecordDraw.h"
25 #include "SkRecorder.h" 25 #include "SkRecorder.h"
26 #include "SkSVGCanvas.h" 26 #include "SkSVGCanvas.h"
27 #include "SkScaledCodec.h"
27 #include "SkScanlineDecoder.h" 28 #include "SkScanlineDecoder.h"
28 #include "SkStream.h" 29 #include "SkStream.h"
30 #include "SkTLogic.h"
29 #include "SkXMLWriter.h" 31 #include "SkXMLWriter.h"
30 #include "SkScaledCodec.h"
31 32
32 DEFINE_bool(multiPage, false, "For document-type backends, render the source" 33 DEFINE_bool(multiPage, false, "For document-type backends, render the source"
33 " into multiple pages"); 34 " into multiple pages");
34 35
35 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { 36 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
36 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); 37 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
37 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); 38 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst);
38 } 39 }
39 40
40 namespace DM { 41 namespace DM {
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1206
1206 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1207 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1207 1208
1208 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as. 1209 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as.
1209 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op. 1210 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op.
1210 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures. 1211 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures.
1211 struct DrawsAsSingletonPictures { 1212 struct DrawsAsSingletonPictures {
1212 SkCanvas* fCanvas; 1213 SkCanvas* fCanvas;
1213 const SkDrawableList& fDrawables; 1214 const SkDrawableList& fDrawables;
1214 1215
1215 SK_CREATE_MEMBER_DETECTOR(paint);
1216
1217 template <typename T> 1216 template <typename T>
1218 void draw(const T& op, SkCanvas* canvas) { 1217 void draw(const T& op, SkCanvas* canvas) {
1219 // We must pass SkMatrix::I() as our initial matrix. 1218 // We must pass SkMatrix::I() as our initial matrix.
1220 // By default SkRecords::Draw() uses the canvas' matrix as its initial m atrix, 1219 // By default SkRecords::Draw() uses the canvas' matrix as its initial m atrix,
1221 // which would have the funky effect of applying transforms over and ove r. 1220 // which would have the funky effect of applying transforms over and ove r.
1222 SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count( ), &SkMatrix::I()); 1221 SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count( ), &SkMatrix::I());
1223 d(op); 1222 d(op);
1224 } 1223 }
1225 1224
1226 // Most things that have paints are Draw-type ops. Create sub-pictures for each. 1225 // Draws get their own picture.
1227 template <typename T> 1226 template <typename T>
1228 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) { 1227 SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) {
1229 SkPictureRecorder rec; 1228 SkPictureRecorder rec;
1230 this->draw(op, rec.beginRecording(SkRect::MakeLargest())); 1229 this->draw(op, rec.beginRecording(SkRect::MakeLargest()));
1231 SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture()); 1230 SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture());
1232 fCanvas->drawPicture(pic); 1231 fCanvas->drawPicture(pic);
1233 } 1232 }
1234 1233
1235 // If you don't have a paint or are a SaveLayer, you're not a Draw-type op. 1234 // We'll just issue non-draws directly.
1236 // We cannot make subpictures out of these because they affect state. Draw them directly.
1237 template <typename T> 1235 template <typename T>
1238 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { this->draw(op, fCanvas); } 1236 skstd::enable_if_t<!(T::kTags & SkRecords::kDraw_Tag), void> operator()(cons t T& op) {
1239 void operator()(const SkRecords::SaveLayer& op) { this->draw(op, fCanvas); } 1237 this->draw(op, fCanvas);
1238 }
1240 }; 1239 };
1241 1240
1242 // Record Src into a picture, then record it into a macro picture with a sub-pic ture for each draw. 1241 // Record Src into a picture, then record it into a macro picture with a sub-pic ture for each draw.
1243 // Then play back that macro picture into our wrapped sink. 1242 // Then play back that macro picture into our wrapped sink.
1244 Error ViaSingletonPictures::draw( 1243 Error ViaSingletonPictures::draw(
1245 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) cons t { 1244 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) cons t {
1246 auto size = src.size(); 1245 auto size = src.size();
1247 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) -> Error { 1246 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) -> Error {
1248 // Use low-level (Skia-private) recording APIs so we can read the SkReco rd. 1247 // Use low-level (Skia-private) recording APIs so we can read the SkReco rd.
1249 SkRecord skr; 1248 SkRecord skr;
(...skipping 19 matching lines...) Expand all
1269 skr.visit<void>(i, drawsAsSingletonPictures); 1268 skr.visit<void>(i, drawsAsSingletonPictures);
1270 } 1269 }
1271 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1270 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1272 1271
1273 canvas->drawPicture(macroPic); 1272 canvas->drawPicture(macroPic);
1274 return ""; 1273 return "";
1275 }); 1274 });
1276 } 1275 }
1277 1276
1278 } // namespace DM 1277 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | include/private/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698