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

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

Issue 571973003: add dumpHex() option to SkPath (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove dummy function Created 6 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 | « src/core/SkClipStack.cpp ('k') | tests/PathTest.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 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 sk_throw(); 2012 sk_throw();
2013 } 2013 }
2014 return sizeRead; 2014 return sizeRead;
2015 } 2015 }
2016 2016
2017 /////////////////////////////////////////////////////////////////////////////// 2017 ///////////////////////////////////////////////////////////////////////////////
2018 2018
2019 #include "SkString.h" 2019 #include "SkString.h"
2020 #include "SkStream.h" 2020 #include "SkStream.h"
2021 2021
2022 static void append_scalar(SkString* str, SkScalar value) { 2022 static void append_scalar(SkString* str, SkScalar value, bool dumpAsHex) {
2023 if (dumpAsHex) {
2024 str->appendf("SkBits2Float(0x%08x)", SkFloat2Bits(value));
2025 return;
2026 }
2023 SkString tmp; 2027 SkString tmp;
2024 tmp.printf("%g", value); 2028 tmp.printf("%g", value);
2025 if (tmp.contains('.')) { 2029 if (tmp.contains('.')) {
2026 tmp.appendUnichar('f'); 2030 tmp.appendUnichar('f');
2027 } 2031 }
2028 str->append(tmp); 2032 str->append(tmp);
2029 } 2033 }
2030 2034
2031 static void append_params(SkString* str, const char label[], const SkPoint pts[] , 2035 static void append_params(SkString* str, const char label[], const SkPoint pts[] ,
2032 int count, SkScalar conicWeight = -1) { 2036 int count, bool dumpAsHex, SkScalar conicWeight = -1) {
2033 str->append(label); 2037 str->append(label);
2034 str->append("("); 2038 str->append("(");
2035 2039
2036 const SkScalar* values = &pts[0].fX; 2040 const SkScalar* values = &pts[0].fX;
2037 count *= 2; 2041 count *= 2;
2038 2042
2039 for (int i = 0; i < count; ++i) { 2043 for (int i = 0; i < count; ++i) {
2040 append_scalar(str, values[i]); 2044 append_scalar(str, values[i], dumpAsHex);
2041 if (i < count - 1) { 2045 if (i < count - 1) {
2042 str->append(", "); 2046 str->append(", ");
2043 } 2047 }
2044 } 2048 }
2045 if (conicWeight >= 0) { 2049 if (conicWeight >= 0) {
2046 str->append(", "); 2050 str->append(", ");
2047 append_scalar(str, conicWeight); 2051 append_scalar(str, conicWeight, dumpAsHex);
2048 } 2052 }
2049 str->append(");\n"); 2053 str->append(");\n");
2050 } 2054 }
2051 2055
2052 void SkPath::dump(SkWStream* wStream, bool forceClose) const { 2056 void SkPath::dump(SkWStream* wStream, bool forceClose, bool dumpAsHex) const {
2053 Iter iter(*this, forceClose); 2057 Iter iter(*this, forceClose);
2054 SkPoint pts[4]; 2058 SkPoint pts[4];
2055 Verb verb; 2059 Verb verb;
2056 2060
2057 if (!wStream) { 2061 if (!wStream) {
2058 SkDebugf("path: forceClose=%s\n", forceClose ? "true" : "false"); 2062 SkDebugf("path: forceClose=%s\n", forceClose ? "true" : "false");
2059 } 2063 }
2060 SkString builder; 2064 SkString builder;
2061 2065
2062 while ((verb = iter.next(pts, false)) != kDone_Verb) { 2066 while ((verb = iter.next(pts, false)) != kDone_Verb) {
2063 switch (verb) { 2067 switch (verb) {
2064 case kMove_Verb: 2068 case kMove_Verb:
2065 append_params(&builder, "path.moveTo", &pts[0], 1); 2069 append_params(&builder, "path.moveTo", &pts[0], 1, dumpAsHex);
2066 break; 2070 break;
2067 case kLine_Verb: 2071 case kLine_Verb:
2068 append_params(&builder, "path.lineTo", &pts[1], 1); 2072 append_params(&builder, "path.lineTo", &pts[1], 1, dumpAsHex);
2069 break; 2073 break;
2070 case kQuad_Verb: 2074 case kQuad_Verb:
2071 append_params(&builder, "path.quadTo", &pts[1], 2); 2075 append_params(&builder, "path.quadTo", &pts[1], 2, dumpAsHex);
2072 break; 2076 break;
2073 case kConic_Verb: 2077 case kConic_Verb:
2074 append_params(&builder, "path.conicTo", &pts[1], 2, iter.conicWe ight()); 2078 append_params(&builder, "path.conicTo", &pts[1], 2, dumpAsHex, i ter.conicWeight());
2075 break; 2079 break;
2076 case kCubic_Verb: 2080 case kCubic_Verb:
2077 append_params(&builder, "path.cubicTo", &pts[1], 3); 2081 append_params(&builder, "path.cubicTo", &pts[1], 3, dumpAsHex);
2078 break; 2082 break;
2079 case kClose_Verb: 2083 case kClose_Verb:
2080 builder.append("path.close();\n"); 2084 builder.append("path.close();\n");
2081 break; 2085 break;
2082 default: 2086 default:
2083 SkDebugf(" path: UNKNOWN VERB %d, aborting dump...\n", verb); 2087 SkDebugf(" path: UNKNOWN VERB %d, aborting dump...\n", verb);
2084 verb = kDone_Verb; // stop the loop 2088 verb = kDone_Verb; // stop the loop
2085 break; 2089 break;
2086 } 2090 }
2087 } 2091 }
2088 if (wStream) { 2092 if (wStream) {
2089 wStream->writeText(builder.c_str()); 2093 wStream->writeText(builder.c_str());
2090 } else { 2094 } else {
2091 SkDebugf("%s", builder.c_str()); 2095 SkDebugf("%s", builder.c_str());
2092 } 2096 }
2093 } 2097 }
2094 2098
2095 void SkPath::dump() const { 2099 void SkPath::dump() const {
2096 this->dump(NULL, false); 2100 this->dump(NULL, false, false);
2101 }
2102
2103 void SkPath::dumpHex() const {
2104 this->dump(NULL, false, true);
2097 } 2105 }
2098 2106
2099 #ifdef SK_DEBUG 2107 #ifdef SK_DEBUG
2100 void SkPath::validate() const { 2108 void SkPath::validate() const {
2101 SkASSERT(this != NULL); 2109 SkASSERT(this != NULL);
2102 SkASSERT((fFillType & ~3) == 0); 2110 SkASSERT((fFillType & ~3) == 0);
2103 2111
2104 #ifdef SK_DEBUG_PATH 2112 #ifdef SK_DEBUG_PATH
2105 if (!fBoundsIsDirty) { 2113 if (!fBoundsIsDirty) {
2106 SkRect bounds; 2114 SkRect bounds;
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 switch (this->getFillType()) { 2802 switch (this->getFillType()) {
2795 case SkPath::kEvenOdd_FillType: 2803 case SkPath::kEvenOdd_FillType:
2796 case SkPath::kInverseEvenOdd_FillType: 2804 case SkPath::kInverseEvenOdd_FillType:
2797 w &= 1; 2805 w &= 1;
2798 break; 2806 break;
2799 default: 2807 default:
2800 break; 2808 break;
2801 } 2809 }
2802 return SkToBool(w); 2810 return SkToBool(w);
2803 } 2811 }
OLDNEW
« no previous file with comments | « src/core/SkClipStack.cpp ('k') | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698