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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 2342313003: [SVGDom] Improved DM sizing (Closed)
Patch Set: cleanup Created 4 years, 3 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') | 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 "Resources.h" 9 #include "Resources.h"
10 #include "SkAndroidCodec.h" 10 #include "SkAndroidCodec.h"
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 if (!viewport.intersect(info.fCullRect)) { 1025 if (!viewport.intersect(info.fCullRect)) {
1026 return SkISize::Make(0,0); 1026 return SkISize::Make(0,0);
1027 } 1027 }
1028 return viewport.roundOut().size(); 1028 return viewport.roundOut().size();
1029 } 1029 }
1030 1030
1031 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } 1031 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1032 1032
1033 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1033 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1034 #if defined(SK_XML) 1034 #if defined(SK_XML)
1035 // Should we try to use the SVG intrinsic size instead? 1035 // Used when the image doesn't have an intrinsic size.
1036 static const SkSize kSVGSize = SkSize::Make(1000, 1000); 1036 static const SkSize kDefaultSVGSize = SkSize::Make(1000, 1000);
1037 1037
1038 SVGSrc::SVGSrc(Path path) : fPath(path) {} 1038 // Used to force-scale tiny fixed-size images.
1039 static const SkSize kMinimumSVGSize = SkSize::Make(128, 128);
1039 1040
1040 Error SVGSrc::draw(SkCanvas* canvas) const { 1041 SVGSrc::SVGSrc(Path path) : fPath(path), fScale(1) {}
1041 SkFILEStream stream(fPath.c_str()); 1042
1042 if (!stream.isValid()) { 1043 Error SVGSrc::ensureDom() const {
1043 return SkStringPrintf("Unable to open file: %s", fPath.c_str()); 1044 if (!fDom) {
1045 SkFILEStream stream(fPath.c_str());
1046 if (!stream.isValid()) {
1047 return SkStringPrintf("Unable to open file: %s", fPath.c_str());
1048 }
1049 fDom = SkSVGDOM::MakeFromStream(stream);
1050 if (!fDom) {
1051 return SkStringPrintf("Unable to parse file: %s", fPath.c_str());
1052 }
1053
1054 const SkSize& sz = fDom->containerSize();
1055 if (sz.isEmpty()) {
1056 // no intrinsic size
1057 fDom->setContainerSize(kDefaultSVGSize);
1058 } else {
1059 fScale = SkTMax(1.f, SkTMax(kMinimumSVGSize.width() / sz.width(),
1060 kMinimumSVGSize.height() / sz.height())) ;
1061 }
1044 } 1062 }
1045 1063
1046 sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream);
1047 if (!dom) {
1048 return SkStringPrintf("Unable to parse file: %s", fPath.c_str());
1049 }
1050
1051 dom->setContainerSize(kSVGSize);
1052 dom->render(canvas);
1053
1054 return ""; 1064 return "";
1055 } 1065 }
1056 1066
1067 Error SVGSrc::draw(SkCanvas* canvas) const {
1068 Error err = this->ensureDom();
1069 if (err.isEmpty()) {
1070 SkAutoCanvasRestore acr(canvas, true);
1071 canvas->scale(fScale, fScale);
1072 fDom->render(canvas);
1073 }
1074
1075 return err;
1076 }
1077
1057 SkISize SVGSrc::size() const { 1078 SkISize SVGSrc::size() const {
1058 return kSVGSize.toRound(); 1079 Error err = this->ensureDom();
1080 if (!err.isEmpty()) {
1081 return SkISize::Make(0, 0);
1082 }
1083
1084 return SkSize::Make(fDom->containerSize().width() * fScale,
1085 fDom->containerSize().height() * fScale).toRound();
1059 } 1086 }
1060 1087
1061 Name SVGSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } 1088 Name SVGSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1062 1089
1063 bool SVGSrc::veto(SinkFlags flags) const { 1090 bool SVGSrc::veto(SinkFlags flags) const {
1064 // No need to test to non-(raster||gpu) or indirect backends. 1091 // No need to test to non-(raster||gpu) or indirect backends.
1065 bool type_ok = flags.type == SinkFlags::kRaster 1092 bool type_ok = flags.type == SinkFlags::kRaster
1066 || flags.type == SinkFlags::kGPU; 1093 || flags.type == SinkFlags::kGPU;
1067 1094
1068 return !type_ok || flags.approach != SinkFlags::kDirect; 1095 return !type_ok || flags.approach != SinkFlags::kDirect;
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 Error err = src.draw(&rec); 1686 Error err = src.draw(&rec);
1660 if (!err.isEmpty()) { 1687 if (!err.isEmpty()) {
1661 return err; 1688 return err;
1662 } 1689 }
1663 dl->draw(canvas); 1690 dl->draw(canvas);
1664 return check_against_reference(bitmap, src, fSink); 1691 return check_against_reference(bitmap, src, fSink);
1665 }); 1692 });
1666 } 1693 }
1667 1694
1668 } // namespace DM 1695 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698