chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkObjectParser.h" |
humper@google.com | f515ffc | 2013-01-07 15:48:19 +0000 | [diff] [blame] | 9 | #include "SkData.h" |
| 10 | #include "SkFontDescriptor.h" |
robertphillips | 80af645 | 2015-08-24 08:27:38 -0700 | [diff] [blame] | 11 | #include "SkImage.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 12 | #include "SkPath.h" |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 13 | #include "SkRRect.h" |
| 14 | #include "SkShader.h" |
| 15 | #include "SkStream.h" |
| 16 | #include "SkStringUtils.h" |
| 17 | #include "SkTypeface.h" |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 18 | #include "SkUtils.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 19 | #include "SkClipOpPriv.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 20 | |
| 21 | /* TODO(chudy): Replace all std::strings with char */ |
| 22 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 23 | SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 24 | SkString* mBitmap = new SkString("SkBitmap: "); |
| 25 | mBitmap->append("W: "); |
| 26 | mBitmap->appendS32(bitmap.width()); |
| 27 | mBitmap->append(" H: "); |
| 28 | mBitmap->appendS32(bitmap.height()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 29 | |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 30 | const char* ctString = "<unknown>"; |
| 31 | switch (bitmap.colorType()) { |
| 32 | case kUnknown_SkColorType: ctString = "None"; break; |
| 33 | case kAlpha_8_SkColorType: ctString = "A8"; break; |
| 34 | case kRGB_565_SkColorType: ctString = "565"; break; |
| 35 | case kARGB_4444_SkColorType: ctString = "4444"; break; |
| 36 | case kRGBA_8888_SkColorType: ctString = "RGBA"; break; |
| 37 | case kRGB_888x_SkColorType: ctString = "RGB"; break; |
| 38 | case kBGRA_8888_SkColorType: ctString = "BGRA"; break; |
| 39 | case kRGBA_1010102_SkColorType: ctString = "1010102"; break; |
| 40 | case kRGB_101010x_SkColorType: ctString = "101010x"; break; |
| 41 | case kGray_8_SkColorType: ctString = "G8"; break; |
| 42 | case kRGBA_F16_SkColorType: ctString = "RGBAf16"; break; |
| 43 | } |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 44 | mBitmap->append(" ColorType: "); |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 45 | mBitmap->append(ctString); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 46 | |
| 47 | if (bitmap.isOpaque()) { |
| 48 | mBitmap->append(" opaque"); |
| 49 | } else { |
| 50 | mBitmap->append(" not-opaque"); |
| 51 | } |
| 52 | |
| 53 | if (bitmap.isImmutable()) { |
| 54 | mBitmap->append(" immutable"); |
| 55 | } else { |
| 56 | mBitmap->append(" not-immutable"); |
| 57 | } |
| 58 | |
| 59 | if (bitmap.isVolatile()) { |
| 60 | mBitmap->append(" volatile"); |
| 61 | } else { |
| 62 | mBitmap->append(" not-volatile"); |
| 63 | } |
| 64 | |
| 65 | mBitmap->append(" genID: "); |
| 66 | mBitmap->appendS32(bitmap.getGenerationID()); |
| 67 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 68 | return mBitmap; |
| 69 | } |
| 70 | |
robertphillips | 80af645 | 2015-08-24 08:27:38 -0700 | [diff] [blame] | 71 | SkString* SkObjectParser::ImageToString(const SkImage* image) { |
| 72 | SkString* str = new SkString("SkImage: "); |
| 73 | if (!image) { |
| 74 | return str; |
| 75 | } |
| 76 | |
| 77 | str->append("W: "); |
| 78 | str->appendS32(image->width()); |
| 79 | str->append(" H: "); |
| 80 | str->appendS32(image->height()); |
| 81 | |
| 82 | if (image->isOpaque()) { |
| 83 | str->append(" opaque"); |
| 84 | } else { |
| 85 | str->append(" not-opaque"); |
| 86 | } |
| 87 | |
| 88 | str->append(" uniqueID: "); |
| 89 | str->appendS32(image->uniqueID()); |
| 90 | |
| 91 | return str; |
| 92 | } |
| 93 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 94 | SkString* SkObjectParser::BoolToString(bool doAA) { |
| 95 | SkString* mBool = new SkString("Bool doAA: "); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 96 | if (doAA) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 97 | mBool->append("True"); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 98 | } else { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 99 | mBool->append("False"); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 100 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 101 | return mBool; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 102 | } |
| 103 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 104 | SkString* SkObjectParser::CustomTextToString(const char* text) { |
| 105 | SkString* mText = new SkString(text); |
| 106 | return mText; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 107 | } |
| 108 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 109 | SkString* SkObjectParser::IntToString(int x, const char* text) { |
| 110 | SkString* mInt = new SkString(text); |
| 111 | mInt->append(" "); |
| 112 | mInt->appendScalar(SkIntToScalar(x)); |
| 113 | return mInt; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 114 | } |
| 115 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 116 | SkString* SkObjectParser::IRectToString(const SkIRect& rect) { |
| 117 | SkString* mRect = new SkString("SkIRect: "); |
| 118 | mRect->append("L: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 119 | mRect->appendS32(rect.left()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 120 | mRect->append(", T: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 121 | mRect->appendS32(rect.top()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 122 | mRect->append(", R: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 123 | mRect->appendS32(rect.right()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 124 | mRect->append(", B: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 125 | mRect->appendS32(rect.bottom()); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 126 | return mRect; |
| 127 | } |
| 128 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 129 | SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 130 | SkString* str = new SkString("SkMatrix: "); |
| 131 | matrix.toString(str); |
| 132 | return str; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 133 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 134 | |
robertphillips@google.com | 735edb0 | 2013-01-10 18:54:11 +0000 | [diff] [blame] | 135 | SkString* SkObjectParser::PaintToString(const SkPaint& paint) { |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 136 | SkString* str = new SkString; |
| 137 | paint.toString(str); |
| 138 | return str; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | SkString* SkObjectParser::PathToString(const SkPath& path) { |
robertphillips | fe8d5f6 | 2015-10-29 09:45:27 -0700 | [diff] [blame] | 142 | SkString* mPath = new SkString; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 143 | |
robertphillips | fe8d5f6 | 2015-10-29 09:45:27 -0700 | [diff] [blame] | 144 | mPath->appendf("Path (%d) (", path.getGenerationID()); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 145 | |
robertphillips@google.com | 51185fe | 2012-12-05 19:34:33 +0000 | [diff] [blame] | 146 | static const char* gFillStrings[] = { |
| 147 | "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" |
| 148 | }; |
| 149 | |
| 150 | mPath->append(gFillStrings[path.getFillType()]); |
| 151 | mPath->append(", "); |
| 152 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 153 | static const char* gConvexityStrings[] = { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 154 | "Unknown", "Convex", "Concave" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 155 | }; |
| 156 | SkASSERT(SkPath::kConcave_Convexity == 2); |
| 157 | |
| 158 | mPath->append(gConvexityStrings[path.getConvexity()]); |
| 159 | mPath->append(", "); |
| 160 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 161 | if (path.isRect(nullptr)) { |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 162 | mPath->append("isRect, "); |
| 163 | } else { |
| 164 | mPath->append("isNotRect, "); |
| 165 | } |
| 166 | |
robertphillips | 3d2e654 | 2015-11-24 06:34:50 -0800 | [diff] [blame] | 167 | if (path.isOval(nullptr)) { |
| 168 | mPath->append("isOval, "); |
| 169 | } else { |
| 170 | mPath->append("isNotOval, "); |
| 171 | } |
| 172 | |
| 173 | SkRRect rrect; |
| 174 | if (path.isRRect(&rrect)) { |
| 175 | mPath->append("isRRect, "); |
| 176 | } else { |
| 177 | mPath->append("isNotRRect, "); |
| 178 | } |
| 179 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 180 | mPath->appendS32(path.countVerbs()); |
| 181 | mPath->append("V, "); |
| 182 | mPath->appendS32(path.countPoints()); |
| 183 | mPath->append("P): "); |
| 184 | |
| 185 | static const char* gVerbStrings[] = { |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 186 | "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 187 | }; |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 188 | static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 }; |
| 189 | static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 }; |
| 190 | SkASSERT(SkPath::kDone_Verb == 6); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 191 | |
| 192 | SkPath::Iter iter(const_cast<SkPath&>(path), false); |
| 193 | SkPath::Verb verb; |
| 194 | SkPoint points[4]; |
| 195 | |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 196 | for(verb = iter.next(points, false); |
| 197 | verb != SkPath::kDone_Verb; |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 198 | verb = iter.next(points, false)) { |
| 199 | |
| 200 | mPath->append(gVerbStrings[verb]); |
| 201 | mPath->append(" "); |
| 202 | |
| 203 | for (int i = 0; i < gPtsPerVerb[verb]; ++i) { |
| 204 | mPath->append("("); |
| 205 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX); |
| 206 | mPath->append(", "); |
| 207 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY); |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 208 | mPath->append(")"); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 209 | } |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 210 | |
| 211 | if (SkPath::kConic_Verb == verb) { |
| 212 | mPath->append("("); |
| 213 | mPath->appendScalar(iter.conicWeight()); |
| 214 | mPath->append(")"); |
| 215 | } |
| 216 | |
| 217 | mPath->append(" "); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 218 | } |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 219 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 220 | SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bound: "); |
| 221 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 222 | if (boundStr) { |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 223 | mPath->append(*boundStr); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 224 | delete boundStr; |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 225 | } |
| 226 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 227 | return mPath; |
| 228 | } |
| 229 | |
| 230 | SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { |
| 231 | SkString* mPoints = new SkString("SkPoints pts[]: "); |
| 232 | for (unsigned int i = 0; i < count; i++) { |
| 233 | mPoints->append("("); |
| 234 | mPoints->appendScalar(pts[i].fX); |
| 235 | mPoints->append(","); |
| 236 | mPoints->appendScalar(pts[i].fY); |
| 237 | mPoints->append(")"); |
| 238 | } |
| 239 | return mPoints; |
| 240 | } |
| 241 | |
| 242 | SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { |
| 243 | SkString* mMode = new SkString("SkCanvas::PointMode: "); |
| 244 | if (mode == SkCanvas::kPoints_PointMode) { |
| 245 | mMode->append("kPoints_PointMode"); |
| 246 | } else if (mode == SkCanvas::kLines_PointMode) { |
| 247 | mMode->append("kLines_Mode"); |
| 248 | } else if (mode == SkCanvas::kPolygon_PointMode) { |
| 249 | mMode->append("kPolygon_PointMode"); |
| 250 | } |
| 251 | return mMode; |
| 252 | } |
| 253 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 254 | SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) { |
| 255 | |
| 256 | SkString* mRect = new SkString; |
skia.committer@gmail.com | 72b2e6f | 2012-11-08 02:03:56 +0000 | [diff] [blame] | 257 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 258 | if (nullptr == title) { |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 259 | mRect->append("SkRect: "); |
| 260 | } else { |
| 261 | mRect->append(title); |
| 262 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 263 | mRect->append("("); |
| 264 | mRect->appendScalar(rect.left()); |
| 265 | mRect->append(", "); |
| 266 | mRect->appendScalar(rect.top()); |
| 267 | mRect->append(", "); |
| 268 | mRect->appendScalar(rect.right()); |
| 269 | mRect->append(", "); |
| 270 | mRect->appendScalar(rect.bottom()); |
| 271 | mRect->append(")"); |
| 272 | return mRect; |
| 273 | } |
| 274 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 275 | SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) { |
| 276 | |
| 277 | SkString* mRRect = new SkString; |
| 278 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 279 | if (nullptr == title) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 280 | mRRect->append("SkRRect ("); |
| 281 | if (rrect.isEmpty()) { |
| 282 | mRRect->append("empty"); |
| 283 | } else if (rrect.isRect()) { |
| 284 | mRRect->append("rect"); |
| 285 | } else if (rrect.isOval()) { |
| 286 | mRRect->append("oval"); |
| 287 | } else if (rrect.isSimple()) { |
| 288 | mRRect->append("simple"); |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 289 | } else if (rrect.isNinePatch()) { |
| 290 | mRRect->append("nine-patch"); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 291 | } else { |
| 292 | SkASSERT(rrect.isComplex()); |
| 293 | mRRect->append("complex"); |
| 294 | } |
| 295 | mRRect->append("): "); |
| 296 | } else { |
| 297 | mRRect->append(title); |
| 298 | } |
| 299 | mRRect->append("("); |
| 300 | mRRect->appendScalar(rrect.rect().left()); |
| 301 | mRRect->append(", "); |
| 302 | mRRect->appendScalar(rrect.rect().top()); |
| 303 | mRRect->append(", "); |
| 304 | mRRect->appendScalar(rrect.rect().right()); |
| 305 | mRRect->append(", "); |
| 306 | mRRect->appendScalar(rrect.rect().bottom()); |
| 307 | mRRect->append(") radii: ("); |
| 308 | for (int i = 0; i < 4; ++i) { |
| 309 | const SkVector& radii = rrect.radii((SkRRect::Corner) i); |
| 310 | mRRect->appendScalar(radii.fX); |
| 311 | mRRect->append(", "); |
| 312 | mRRect->appendScalar(radii.fY); |
| 313 | if (i < 3) { |
| 314 | mRRect->append(", "); |
| 315 | } |
| 316 | } |
| 317 | mRRect->append(")"); |
| 318 | return mRRect; |
| 319 | } |
| 320 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 321 | SkString* SkObjectParser::ClipOpToString(SkClipOp op) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 322 | SkString* mOp = new SkString("SkRegion::Op: "); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 323 | if (op == kDifference_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 324 | mOp->append("kDifference_Op"); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 325 | } else if (op == kIntersect_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 326 | mOp->append("kIntersect_Op"); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 327 | } else if (op == kUnion_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 328 | mOp->append("kUnion_Op"); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 329 | } else if (op == kXOR_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 330 | mOp->append("kXOR_Op"); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 331 | } else if (op == kReverseDifference_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 332 | mOp->append("kReverseDifference_Op"); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 333 | } else if (op == kReplace_SkClipOp) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 334 | mOp->append("kReplace_Op"); |
| 335 | } else { |
| 336 | mOp->append("Unknown Type"); |
| 337 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 338 | return mOp; |
| 339 | } |
| 340 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 341 | SkString* SkObjectParser::RegionToString(const SkRegion& region) { |
| 342 | SkString* mRegion = new SkString("SkRegion: Data unavailable."); |
| 343 | return mRegion; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 344 | } |
| 345 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 346 | SkString* SkObjectParser::SaveLayerFlagsToString(SkCanvas::SaveLayerFlags saveLayerFlags) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 347 | SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 348 | if (saveLayerFlags & SkCanvas::kPreserveLCDText_SaveLayerFlag) { |
| 349 | mFlags->append("kPreserveLCDText_SaveLayerFlag "); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 350 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 351 | return mFlags; |
| 352 | } |
| 353 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 354 | SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) { |
| 355 | SkString* mScalar = new SkString(text); |
| 356 | mScalar->append(" "); |
| 357 | mScalar->appendScalar(x); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 358 | return mScalar; |
| 359 | } |
| 360 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 361 | SkString* SkObjectParser::TextToString(const void* text, size_t byteLength, |
| 362 | SkPaint::TextEncoding encoding) { |
| 363 | |
| 364 | SkString* decodedText = new SkString(); |
| 365 | switch (encoding) { |
| 366 | case SkPaint::kUTF8_TextEncoding: { |
| 367 | decodedText->append("UTF-8: "); |
| 368 | decodedText->append((const char*)text, byteLength); |
| 369 | break; |
| 370 | } |
| 371 | case SkPaint::kUTF16_TextEncoding: { |
| 372 | decodedText->append("UTF-16: "); |
skia.committer@gmail.com | f61ebc0 | 2013-11-22 07:02:24 +0000 | [diff] [blame] | 373 | size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, |
| 374 | SkToS32(byteLength / 2), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 375 | nullptr); |
scroggo@google.com | b9050d7 | 2013-08-26 21:20:04 +0000 | [diff] [blame] | 376 | SkAutoSTMalloc<0x100, char> utf8(sizeNeeded); |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 377 | SkUTF16_ToUTF8((uint16_t*)text, SkToS32(byteLength / 2), utf8); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 378 | decodedText->append(utf8, sizeNeeded); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 379 | break; |
| 380 | } |
| 381 | case SkPaint::kUTF32_TextEncoding: { |
| 382 | decodedText->append("UTF-32: "); |
| 383 | const SkUnichar* begin = (const SkUnichar*)text; |
| 384 | const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLength); |
| 385 | for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { |
| 386 | decodedText->appendUnichar(*unichar); |
| 387 | } |
| 388 | break; |
| 389 | } |
| 390 | case SkPaint::kGlyphID_TextEncoding: { |
| 391 | decodedText->append("GlyphID: "); |
| 392 | const uint16_t* begin = (const uint16_t*)text; |
| 393 | const uint16_t* end = (const uint16_t*)((const char*)text + byteLength); |
| 394 | for (const uint16_t* glyph = begin; glyph < end; ++glyph) { |
| 395 | decodedText->append("0x"); |
| 396 | decodedText->appendHex(*glyph); |
| 397 | decodedText->append(" "); |
| 398 | } |
| 399 | break; |
| 400 | } |
| 401 | default: |
| 402 | decodedText->append("Unknown text encoding."); |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | return decodedText; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 407 | } |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 408 | |
| 409 | SkString* SkObjectParser::LatticeToString(const SkCanvas::Lattice& lattice) { |
| 410 | SkString* mLattice = new SkString; |
| 411 | mLattice->append("Lattice: "); |
| 412 | mLattice->append("(X: "); |
| 413 | mLattice->appendS32(lattice.fXCount); |
| 414 | mLattice->append(", Y:"); |
| 415 | mLattice->appendS32(lattice.fYCount); |
| 416 | mLattice->append(", Bounds:"); |
| 417 | if (nullptr != lattice.fBounds) { |
| 418 | mLattice->append(*IRectToString(*lattice.fBounds)); |
| 419 | } else { |
| 420 | mLattice->append("null"); |
| 421 | } |
| 422 | mLattice->append(")"); |
| 423 | return mLattice; |
| 424 | } |