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

Side by Side Diff: src/utils/debugger/SkObjectParser.cpp

Issue 1678893003: moved debugger support files from src/utils/debugger to tools/debugger (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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/utils/debugger/SkObjectParser.h ('k') | src/utils/debugger/SkOverdrawMode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "SkObjectParser.h"
10 #include "SkData.h"
11 #include "SkFontDescriptor.h"
12 #include "SkImage.h"
13 #include "SkPath.h"
14 #include "SkRRect.h"
15 #include "SkShader.h"
16 #include "SkStream.h"
17 #include "SkStringUtils.h"
18 #include "SkTypeface.h"
19 #include "SkUtils.h"
20
21 /* TODO(chudy): Replace all std::strings with char */
22
23 SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) {
24 SkString* mBitmap = new SkString("SkBitmap: ");
25 mBitmap->append("W: ");
26 mBitmap->appendS32(bitmap.width());
27 mBitmap->append(" H: ");
28 mBitmap->appendS32(bitmap.height());
29
30 const char* gColorTypeStrings[] = {
31 "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8", "G8"
32 };
33 SkASSERT(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings));
34
35 mBitmap->append(" ColorType: ");
36 mBitmap->append(gColorTypeStrings[bitmap.colorType()]);
37
38 if (bitmap.isOpaque()) {
39 mBitmap->append(" opaque");
40 } else {
41 mBitmap->append(" not-opaque");
42 }
43
44 if (bitmap.isImmutable()) {
45 mBitmap->append(" immutable");
46 } else {
47 mBitmap->append(" not-immutable");
48 }
49
50 if (bitmap.isVolatile()) {
51 mBitmap->append(" volatile");
52 } else {
53 mBitmap->append(" not-volatile");
54 }
55
56 mBitmap->append(" genID: ");
57 mBitmap->appendS32(bitmap.getGenerationID());
58
59 return mBitmap;
60 }
61
62 SkString* SkObjectParser::ImageToString(const SkImage* image) {
63 SkString* str = new SkString("SkImage: ");
64 if (!image) {
65 return str;
66 }
67
68 str->append("W: ");
69 str->appendS32(image->width());
70 str->append(" H: ");
71 str->appendS32(image->height());
72
73 if (image->isOpaque()) {
74 str->append(" opaque");
75 } else {
76 str->append(" not-opaque");
77 }
78
79 str->append(" uniqueID: ");
80 str->appendS32(image->uniqueID());
81
82 return str;
83 }
84
85 SkString* SkObjectParser::BoolToString(bool doAA) {
86 SkString* mBool = new SkString("Bool doAA: ");
87 if (doAA) {
88 mBool->append("True");
89 } else {
90 mBool->append("False");
91 }
92 return mBool;
93 }
94
95 SkString* SkObjectParser::CustomTextToString(const char* text) {
96 SkString* mText = new SkString(text);
97 return mText;
98 }
99
100 SkString* SkObjectParser::IntToString(int x, const char* text) {
101 SkString* mInt = new SkString(text);
102 mInt->append(" ");
103 mInt->appendScalar(SkIntToScalar(x));
104 return mInt;
105 }
106
107 SkString* SkObjectParser::IRectToString(const SkIRect& rect) {
108 SkString* mRect = new SkString("SkIRect: ");
109 mRect->append("L: ");
110 mRect->appendS32(rect.left());
111 mRect->append(", T: ");
112 mRect->appendS32(rect.top());
113 mRect->append(", R: ");
114 mRect->appendS32(rect.right());
115 mRect->append(", B: ");
116 mRect->appendS32(rect.bottom());
117 return mRect;
118 }
119
120 SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) {
121 SkString* str = new SkString("SkMatrix: ");
122 #ifndef SK_IGNORE_TO_STRING
123 matrix.toString(str);
124 #endif
125 return str;
126 }
127
128 SkString* SkObjectParser::PaintToString(const SkPaint& paint) {
129 SkString* str = new SkString;
130 #ifndef SK_IGNORE_TO_STRING
131 paint.toString(str);
132 #endif
133 return str;
134 }
135
136 SkString* SkObjectParser::PathToString(const SkPath& path) {
137 SkString* mPath = new SkString;
138
139 mPath->appendf("Path (%d) (", path.getGenerationID());
140
141 static const char* gFillStrings[] = {
142 "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd"
143 };
144
145 mPath->append(gFillStrings[path.getFillType()]);
146 mPath->append(", ");
147
148 static const char* gConvexityStrings[] = {
149 "Unknown", "Convex", "Concave"
150 };
151 SkASSERT(SkPath::kConcave_Convexity == 2);
152
153 mPath->append(gConvexityStrings[path.getConvexity()]);
154 mPath->append(", ");
155
156 if (path.isRect(nullptr)) {
157 mPath->append("isRect, ");
158 } else {
159 mPath->append("isNotRect, ");
160 }
161
162 if (path.isOval(nullptr)) {
163 mPath->append("isOval, ");
164 } else {
165 mPath->append("isNotOval, ");
166 }
167
168 SkRRect rrect;
169 if (path.isRRect(&rrect)) {
170 mPath->append("isRRect, ");
171 } else {
172 mPath->append("isNotRRect, ");
173 }
174
175 mPath->appendS32(path.countVerbs());
176 mPath->append("V, ");
177 mPath->appendS32(path.countPoints());
178 mPath->append("P): ");
179
180 static const char* gVerbStrings[] = {
181 "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done"
182 };
183 static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 };
184 static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 };
185 SkASSERT(SkPath::kDone_Verb == 6);
186
187 SkPath::Iter iter(const_cast<SkPath&>(path), false);
188 SkPath::Verb verb;
189 SkPoint points[4];
190
191 for(verb = iter.next(points, false);
192 verb != SkPath::kDone_Verb;
193 verb = iter.next(points, false)) {
194
195 mPath->append(gVerbStrings[verb]);
196 mPath->append(" ");
197
198 for (int i = 0; i < gPtsPerVerb[verb]; ++i) {
199 mPath->append("(");
200 mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX);
201 mPath->append(", ");
202 mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY);
203 mPath->append(")");
204 }
205
206 if (SkPath::kConic_Verb == verb) {
207 mPath->append("(");
208 mPath->appendScalar(iter.conicWeight());
209 mPath->append(")");
210 }
211
212 mPath->append(" ");
213 }
214
215 SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bou nd: ");
216
217 if (boundStr) {
218 mPath->append(*boundStr);
219 delete boundStr;
220 }
221
222 return mPath;
223 }
224
225 SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) {
226 SkString* mPoints = new SkString("SkPoints pts[]: ");
227 for (unsigned int i = 0; i < count; i++) {
228 mPoints->append("(");
229 mPoints->appendScalar(pts[i].fX);
230 mPoints->append(",");
231 mPoints->appendScalar(pts[i].fY);
232 mPoints->append(")");
233 }
234 return mPoints;
235 }
236
237 SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) {
238 SkString* mMode = new SkString("SkCanvas::PointMode: ");
239 if (mode == SkCanvas::kPoints_PointMode) {
240 mMode->append("kPoints_PointMode");
241 } else if (mode == SkCanvas::kLines_PointMode) {
242 mMode->append("kLines_Mode");
243 } else if (mode == SkCanvas::kPolygon_PointMode) {
244 mMode->append("kPolygon_PointMode");
245 }
246 return mMode;
247 }
248
249 SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) {
250
251 SkString* mRect = new SkString;
252
253 if (nullptr == title) {
254 mRect->append("SkRect: ");
255 } else {
256 mRect->append(title);
257 }
258 mRect->append("(");
259 mRect->appendScalar(rect.left());
260 mRect->append(", ");
261 mRect->appendScalar(rect.top());
262 mRect->append(", ");
263 mRect->appendScalar(rect.right());
264 mRect->append(", ");
265 mRect->appendScalar(rect.bottom());
266 mRect->append(")");
267 return mRect;
268 }
269
270 SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) {
271
272 SkString* mRRect = new SkString;
273
274 if (nullptr == title) {
275 mRRect->append("SkRRect (");
276 if (rrect.isEmpty()) {
277 mRRect->append("empty");
278 } else if (rrect.isRect()) {
279 mRRect->append("rect");
280 } else if (rrect.isOval()) {
281 mRRect->append("oval");
282 } else if (rrect.isSimple()) {
283 mRRect->append("simple");
284 } else if (rrect.isNinePatch()) {
285 mRRect->append("nine-patch");
286 } else {
287 SkASSERT(rrect.isComplex());
288 mRRect->append("complex");
289 }
290 mRRect->append("): ");
291 } else {
292 mRRect->append(title);
293 }
294 mRRect->append("(");
295 mRRect->appendScalar(rrect.rect().left());
296 mRRect->append(", ");
297 mRRect->appendScalar(rrect.rect().top());
298 mRRect->append(", ");
299 mRRect->appendScalar(rrect.rect().right());
300 mRRect->append(", ");
301 mRRect->appendScalar(rrect.rect().bottom());
302 mRRect->append(") radii: (");
303 for (int i = 0; i < 4; ++i) {
304 const SkVector& radii = rrect.radii((SkRRect::Corner) i);
305 mRRect->appendScalar(radii.fX);
306 mRRect->append(", ");
307 mRRect->appendScalar(radii.fY);
308 if (i < 3) {
309 mRRect->append(", ");
310 }
311 }
312 mRRect->append(")");
313 return mRRect;
314 }
315
316 SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) {
317 SkString* mOp = new SkString("SkRegion::Op: ");
318 if (op == SkRegion::kDifference_Op) {
319 mOp->append("kDifference_Op");
320 } else if (op == SkRegion::kIntersect_Op) {
321 mOp->append("kIntersect_Op");
322 } else if (op == SkRegion::kUnion_Op) {
323 mOp->append("kUnion_Op");
324 } else if (op == SkRegion::kXOR_Op) {
325 mOp->append("kXOR_Op");
326 } else if (op == SkRegion::kReverseDifference_Op) {
327 mOp->append("kReverseDifference_Op");
328 } else if (op == SkRegion::kReplace_Op) {
329 mOp->append("kReplace_Op");
330 } else {
331 mOp->append("Unknown Type");
332 }
333 return mOp;
334 }
335
336 SkString* SkObjectParser::RegionToString(const SkRegion& region) {
337 SkString* mRegion = new SkString("SkRegion: Data unavailable.");
338 return mRegion;
339 }
340
341 SkString* SkObjectParser::SaveLayerFlagsToString(SkCanvas::SaveLayerFlags saveLa yerFlags) {
342 SkString* mFlags = new SkString("SkCanvas::SaveFlags: ");
343 if (saveLayerFlags & SkCanvas::kIsOpaque_SaveLayerFlag) {
344 mFlags->append("kIsOpaque_SaveLayerFlag ");
345 }
346 if (saveLayerFlags & SkCanvas::kPreserveLCDText_SaveLayerFlag) {
347 mFlags->append("kPreserveLCDText_SaveLayerFlag ");
348 }
349 return mFlags;
350 }
351
352 SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) {
353 SkString* mScalar = new SkString(text);
354 mScalar->append(" ");
355 mScalar->appendScalar(x);
356 return mScalar;
357 }
358
359 SkString* SkObjectParser::TextToString(const void* text, size_t byteLength,
360 SkPaint::TextEncoding encoding) {
361
362 SkString* decodedText = new SkString();
363 switch (encoding) {
364 case SkPaint::kUTF8_TextEncoding: {
365 decodedText->append("UTF-8: ");
366 decodedText->append((const char*)text, byteLength);
367 break;
368 }
369 case SkPaint::kUTF16_TextEncoding: {
370 decodedText->append("UTF-16: ");
371 size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text,
372 SkToS32(byteLength / 2),
373 nullptr);
374 SkAutoSTMalloc<0x100, char> utf8(sizeNeeded);
375 SkUTF16_ToUTF8((uint16_t*)text, SkToS32(byteLength / 2), utf8);
376 decodedText->append(utf8, sizeNeeded);
377 break;
378 }
379 case SkPaint::kUTF32_TextEncoding: {
380 decodedText->append("UTF-32: ");
381 const SkUnichar* begin = (const SkUnichar*)text;
382 const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLe ngth);
383 for (const SkUnichar* unichar = begin; unichar < end; ++unichar) {
384 decodedText->appendUnichar(*unichar);
385 }
386 break;
387 }
388 case SkPaint::kGlyphID_TextEncoding: {
389 decodedText->append("GlyphID: ");
390 const uint16_t* begin = (const uint16_t*)text;
391 const uint16_t* end = (const uint16_t*)((const char*)text + byteLeng th);
392 for (const uint16_t* glyph = begin; glyph < end; ++glyph) {
393 decodedText->append("0x");
394 decodedText->appendHex(*glyph);
395 decodedText->append(" ");
396 }
397 break;
398 }
399 default:
400 decodedText->append("Unknown text encoding.");
401 break;
402 }
403
404 return decodedText;
405 }
OLDNEW
« no previous file with comments | « src/utils/debugger/SkObjectParser.h ('k') | src/utils/debugger/SkOverdrawMode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698