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

Side by Side Diff: src/core/SkPath.cpp

Issue 801383002: add dumpHex option to rect and rrect, to match path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 | « include/core/SkRect.h ('k') | src/core/SkRRect.cpp » ('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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBuffer.h" 10 #include "SkBuffer.h"
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 sizeRead = buffer.pos(); 2014 sizeRead = buffer.pos();
2015 } else if (pathRef) { 2015 } else if (pathRef) {
2016 // If the buffer is not valid, pathRef should be NULL 2016 // If the buffer is not valid, pathRef should be NULL
2017 sk_throw(); 2017 sk_throw();
2018 } 2018 }
2019 return sizeRead; 2019 return sizeRead;
2020 } 2020 }
2021 2021
2022 /////////////////////////////////////////////////////////////////////////////// 2022 ///////////////////////////////////////////////////////////////////////////////
2023 2023
2024 #include "SkString.h" 2024 #include "SkStringUtils.h"
2025 #include "SkStream.h" 2025 #include "SkStream.h"
2026 2026
2027 static void append_scalar(SkString* str, SkScalar value, bool dumpAsHex) {
2028 if (dumpAsHex) {
2029 str->appendf("SkBits2Float(0x%08x)", SkFloat2Bits(value));
2030 return;
2031 }
2032 SkString tmp;
2033 tmp.printf("%g", value);
2034 if (tmp.contains('.')) {
2035 tmp.appendUnichar('f');
2036 }
2037 str->append(tmp);
2038 }
2039
2040 static void append_params(SkString* str, const char label[], const SkPoint pts[] , 2027 static void append_params(SkString* str, const char label[], const SkPoint pts[] ,
2041 int count, bool dumpAsHex, SkScalar conicWeight = -1) { 2028 int count, SkScalarAsStringType strType, SkScalar coni cWeight = -1) {
2042 str->append(label); 2029 str->append(label);
2043 str->append("("); 2030 str->append("(");
2044 2031
2045 const SkScalar* values = &pts[0].fX; 2032 const SkScalar* values = &pts[0].fX;
2046 count *= 2; 2033 count *= 2;
2047 2034
2048 for (int i = 0; i < count; ++i) { 2035 for (int i = 0; i < count; ++i) {
2049 append_scalar(str, values[i], dumpAsHex); 2036 SkAppendScalar(str, values[i], strType);
2050 if (i < count - 1) { 2037 if (i < count - 1) {
2051 str->append(", "); 2038 str->append(", ");
2052 } 2039 }
2053 } 2040 }
2054 if (conicWeight >= 0) { 2041 if (conicWeight >= 0) {
2055 str->append(", "); 2042 str->append(", ");
2056 append_scalar(str, conicWeight, dumpAsHex); 2043 SkAppendScalar(str, conicWeight, strType);
2057 } 2044 }
2058 str->append(");"); 2045 str->append(");");
2059 if (dumpAsHex) { 2046 if (kHex_SkScalarAsStringType == strType) {
2060 str->append(" // "); 2047 str->append(" // ");
2061 for (int i = 0; i < count; ++i) { 2048 for (int i = 0; i < count; ++i) {
2062 append_scalar(str, values[i], false); 2049 SkAppendScalarDec(str, values[i]);
2063 if (i < count - 1) { 2050 if (i < count - 1) {
2064 str->append(", "); 2051 str->append(", ");
2065 } 2052 }
2066 } 2053 }
2067 if (conicWeight >= 0) { 2054 if (conicWeight >= 0) {
2068 str->append(", "); 2055 str->append(", ");
2069 append_scalar(str, conicWeight, false); 2056 SkAppendScalarDec(str, conicWeight);
2070 } 2057 }
2071 } 2058 }
2072 str->append("\n"); 2059 str->append("\n");
2073 } 2060 }
2074 2061
2075 void SkPath::dump(SkWStream* wStream, bool forceClose, bool dumpAsHex) const { 2062 void SkPath::dump(SkWStream* wStream, bool forceClose, bool dumpAsHex) const {
2063 SkScalarAsStringType asType = dumpAsHex ? kHex_SkScalarAsStringType : kDec_S kScalarAsStringType;
2076 Iter iter(*this, forceClose); 2064 Iter iter(*this, forceClose);
2077 SkPoint pts[4]; 2065 SkPoint pts[4];
2078 Verb verb; 2066 Verb verb;
2079 2067
2080 if (!wStream) { 2068 if (!wStream) {
2081 SkDebugf("path: forceClose=%s\n", forceClose ? "true" : "false"); 2069 SkDebugf("path: forceClose=%s\n", forceClose ? "true" : "false");
2082 } 2070 }
2083 SkString builder; 2071 SkString builder;
2084 2072
2085 while ((verb = iter.next(pts, false)) != kDone_Verb) { 2073 while ((verb = iter.next(pts, false)) != kDone_Verb) {
2086 switch (verb) { 2074 switch (verb) {
2087 case kMove_Verb: 2075 case kMove_Verb:
2088 append_params(&builder, "path.moveTo", &pts[0], 1, dumpAsHex); 2076 append_params(&builder, "path.moveTo", &pts[0], 1, asType);
2089 break; 2077 break;
2090 case kLine_Verb: 2078 case kLine_Verb:
2091 append_params(&builder, "path.lineTo", &pts[1], 1, dumpAsHex); 2079 append_params(&builder, "path.lineTo", &pts[1], 1, asType);
2092 break; 2080 break;
2093 case kQuad_Verb: 2081 case kQuad_Verb:
2094 append_params(&builder, "path.quadTo", &pts[1], 2, dumpAsHex); 2082 append_params(&builder, "path.quadTo", &pts[1], 2, asType);
2095 break; 2083 break;
2096 case kConic_Verb: 2084 case kConic_Verb:
2097 append_params(&builder, "path.conicTo", &pts[1], 2, dumpAsHex, i ter.conicWeight()); 2085 append_params(&builder, "path.conicTo", &pts[1], 2, asType, iter .conicWeight());
2098 break; 2086 break;
2099 case kCubic_Verb: 2087 case kCubic_Verb:
2100 append_params(&builder, "path.cubicTo", &pts[1], 3, dumpAsHex); 2088 append_params(&builder, "path.cubicTo", &pts[1], 3, asType);
2101 break; 2089 break;
2102 case kClose_Verb: 2090 case kClose_Verb:
2103 builder.append("path.close();\n"); 2091 builder.append("path.close();\n");
2104 break; 2092 break;
2105 default: 2093 default:
2106 SkDebugf(" path: UNKNOWN VERB %d, aborting dump...\n", verb); 2094 SkDebugf(" path: UNKNOWN VERB %d, aborting dump...\n", verb);
2107 verb = kDone_Verb; // stop the loop 2095 verb = kDone_Verb; // stop the loop
2108 break; 2096 break;
2109 } 2097 }
2110 } 2098 }
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 switch (this->getFillType()) { 2866 switch (this->getFillType()) {
2879 case SkPath::kEvenOdd_FillType: 2867 case SkPath::kEvenOdd_FillType:
2880 case SkPath::kInverseEvenOdd_FillType: 2868 case SkPath::kInverseEvenOdd_FillType:
2881 w &= 1; 2869 w &= 1;
2882 break; 2870 break;
2883 default: 2871 default:
2884 break; 2872 break;
2885 } 2873 }
2886 return SkToBool(w); 2874 return SkToBool(w);
2887 } 2875 }
OLDNEW
« no previous file with comments | « include/core/SkRect.h ('k') | src/core/SkRRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698