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

Side by Side Diff: src/utils/debugger/SkDrawCommand.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/SkDrawCommand.h ('k') | src/utils/debugger/SkObjectParser.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
10 #include "SkDrawCommand.h"
11 #include "SkObjectParser.h"
12 #include "SkPicture.h"
13 #include "SkTextBlob.h"
14 #include "SkTextBlobRunIterator.h"
15
16 // TODO(chudy): Refactor into non subclass model.
17
18 SkDrawCommand::SkDrawCommand(OpType type)
19 : fOpType(type)
20 , fVisible(true) {
21 }
22
23 SkDrawCommand::~SkDrawCommand() {
24 fInfo.deleteAll();
25 }
26
27 const char* SkDrawCommand::GetCommandString(OpType type) {
28 switch (type) {
29 case kBeginDrawPicture_OpType: return "BeginDrawPicture";
30 case kClipPath_OpType: return "ClipPath";
31 case kClipRegion_OpType: return "ClipRegion";
32 case kClipRect_OpType: return "ClipRect";
33 case kClipRRect_OpType: return "ClipRRect";
34 case kConcat_OpType: return "Concat";
35 case kDrawBitmap_OpType: return "DrawBitmap";
36 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
37 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
38 case kDrawClear_OpType: return "DrawClear";
39 case kDrawDRRect_OpType: return "DrawDRRect";
40 case kDrawImage_OpType: return "DrawImage";
41 case kDrawImageRect_OpType: return "DrawImageRect";
42 case kDrawOval_OpType: return "DrawOval";
43 case kDrawPaint_OpType: return "DrawPaint";
44 case kDrawPatch_OpType: return "DrawPatch";
45 case kDrawPath_OpType: return "DrawPath";
46 case kDrawPoints_OpType: return "DrawPoints";
47 case kDrawPosText_OpType: return "DrawPosText";
48 case kDrawPosTextH_OpType: return "DrawPosTextH";
49 case kDrawRect_OpType: return "DrawRect";
50 case kDrawRRect_OpType: return "DrawRRect";
51 case kDrawText_OpType: return "DrawText";
52 case kDrawTextBlob_OpType: return "DrawTextBlob";
53 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
54 case kDrawVertices_OpType: return "DrawVertices";
55 case kEndDrawPicture_OpType: return "EndDrawPicture";
56 case kRestore_OpType: return "Restore";
57 case kSave_OpType: return "Save";
58 case kSaveLayer_OpType: return "SaveLayer";
59 case kSetMatrix_OpType: return "SetMatrix";
60 default:
61 SkDebugf("OpType error 0x%08x\n", type);
62 SkASSERT(0);
63 break;
64 }
65 SkDEBUGFAIL("DrawType UNUSED\n");
66 return nullptr;
67 }
68
69 SkString SkDrawCommand::toString() const {
70 return SkString(GetCommandString(fOpType));
71 }
72
73 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
74 fColor = color;
75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
76 }
77
78 void SkClearCommand::execute(SkCanvas* canvas) const {
79 canvas->clear(fColor);
80 }
81
82 namespace {
83
84 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
85 const SkISize& size = canvas->getDeviceSize();
86
87 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
88
89 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
90 if (bounds.width() > bounds.height()) {
91 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
92 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()) );
93 } else {
94 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()) ,
95 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height() ));
96 }
97 canvas->translate(-bounds.centerX(), -bounds.centerY());
98 }
99
100
101 void render_path(SkCanvas* canvas, const SkPath& path) {
102 canvas->clear(0xFFFFFFFF);
103
104 const SkRect& bounds = path.getBounds();
105 if (bounds.isEmpty()) {
106 return;
107 }
108
109 SkAutoCanvasRestore acr(canvas, true);
110 xlate_and_scale_to_bounds(canvas, bounds);
111
112 SkPaint p;
113 p.setColor(SK_ColorBLACK);
114 p.setStyle(SkPaint::kStroke_Style);
115
116 canvas->drawPath(path, p);
117 }
118
119 void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRec t = nullptr) {
120 const SkISize& size = canvas->getDeviceSize();
121
122 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
123 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
124
125 if (input.width() > input.height()) {
126 yScale *= input.height() / (float) input.width();
127 } else {
128 xScale *= input.width() / (float) input.height();
129 }
130
131 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
132 xScale * input.width(),
133 yScale * input.height());
134
135 static const int kNumBlocks = 8;
136
137 canvas->clear(0xFFFFFFFF);
138 SkISize block = {
139 canvas->imageInfo().width()/kNumBlocks,
140 canvas->imageInfo().height()/kNumBlocks
141 };
142 for (int y = 0; y < kNumBlocks; ++y) {
143 for (int x = 0; x < kNumBlocks; ++x) {
144 SkPaint paint;
145 paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY);
146 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()),
147 SkIntToScalar(y*block.height()),
148 SkIntToScalar(block.width()),
149 SkIntToScalar(block.height()));
150 canvas->drawRect(r, paint);
151 }
152 }
153
154 canvas->drawBitmapRect(input, dst, nullptr);
155
156 if (srcRect) {
157 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
158 srcRect->fTop * yScale + SK_Scalar1,
159 srcRect->fRight * xScale + SK_Scalar1,
160 srcRect->fBottom * yScale + SK_Scalar1);
161 SkPaint p;
162 p.setColor(SK_ColorRED);
163 p.setStyle(SkPaint::kStroke_Style);
164
165 canvas->drawRect(r, p);
166 }
167 }
168
169 void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
170 canvas->clear(0xFFFFFFFF);
171 canvas->save();
172
173 const SkRect& bounds = rrect.getBounds();
174
175 xlate_and_scale_to_bounds(canvas, bounds);
176
177 SkPaint p;
178 p.setColor(SK_ColorBLACK);
179 p.setStyle(SkPaint::kStroke_Style);
180
181 canvas->drawRRect(rrect, p);
182 canvas->restore();
183 }
184
185 void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
186 canvas->clear(0xFFFFFFFF);
187 canvas->save();
188
189 const SkRect& bounds = outer.getBounds();
190
191 xlate_and_scale_to_bounds(canvas, bounds);
192
193 SkPaint p;
194 p.setColor(SK_ColorBLACK);
195 p.setStyle(SkPaint::kStroke_Style);
196
197 canvas->drawDRRect(outer, inner, p);
198 canvas->restore();
199 }
200
201 };
202
203
204 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool d oAA)
205 : INHERITED(kClipPath_OpType) {
206 fPath = path;
207 fOp = op;
208 fDoAA = doAA;
209
210 fInfo.push(SkObjectParser::PathToString(path));
211 fInfo.push(SkObjectParser::RegionOpToString(op));
212 fInfo.push(SkObjectParser::BoolToString(doAA));
213 }
214
215 void SkClipPathCommand::execute(SkCanvas* canvas) const {
216 canvas->clipPath(fPath, fOp, fDoAA);
217 }
218
219 bool SkClipPathCommand::render(SkCanvas* canvas) const {
220 render_path(canvas, fPath);
221 return true;
222 }
223
224 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op )
225 : INHERITED(kClipRegion_OpType) {
226 fRegion = region;
227 fOp = op;
228
229 fInfo.push(SkObjectParser::RegionToString(region));
230 fInfo.push(SkObjectParser::RegionOpToString(op));
231 }
232
233 void SkClipRegionCommand::execute(SkCanvas* canvas) const {
234 canvas->clipRegion(fRegion, fOp);
235 }
236
237 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool d oAA)
238 : INHERITED(kClipRect_OpType) {
239 fRect = rect;
240 fOp = op;
241 fDoAA = doAA;
242
243 fInfo.push(SkObjectParser::RectToString(rect));
244 fInfo.push(SkObjectParser::RegionOpToString(op));
245 fInfo.push(SkObjectParser::BoolToString(doAA));
246 }
247
248 void SkClipRectCommand::execute(SkCanvas* canvas) const {
249 canvas->clipRect(fRect, fOp, fDoAA);
250 }
251
252 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bo ol doAA)
253 : INHERITED(kClipRRect_OpType) {
254 fRRect = rrect;
255 fOp = op;
256 fDoAA = doAA;
257
258 fInfo.push(SkObjectParser::RRectToString(rrect));
259 fInfo.push(SkObjectParser::RegionOpToString(op));
260 fInfo.push(SkObjectParser::BoolToString(doAA));
261 }
262
263 void SkClipRRectCommand::execute(SkCanvas* canvas) const {
264 canvas->clipRRect(fRRect, fOp, fDoAA);
265 }
266
267 bool SkClipRRectCommand::render(SkCanvas* canvas) const {
268 render_rrect(canvas, fRRect);
269 return true;
270 }
271
272 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
273 : INHERITED(kConcat_OpType) {
274 fMatrix = matrix;
275
276 fInfo.push(SkObjectParser::MatrixToString(matrix));
277 }
278
279 void SkConcatCommand::execute(SkCanvas* canvas) const {
280 canvas->concat(fMatrix);
281 }
282
283 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
284 const SkPaint* paint)
285 : INHERITED(kDrawBitmap_OpType) {
286 fBitmap = bitmap;
287 fLeft = left;
288 fTop = top;
289 if (paint) {
290 fPaint = *paint;
291 fPaintPtr = &fPaint;
292 } else {
293 fPaintPtr = nullptr;
294 }
295
296 fInfo.push(SkObjectParser::BitmapToString(bitmap));
297 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
298 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
299 if (paint) {
300 fInfo.push(SkObjectParser::PaintToString(*paint));
301 }
302 }
303
304 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
305 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
306 }
307
308 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
309 render_bitmap(canvas, fBitmap);
310 return true;
311 }
312
313 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S kIRect& center,
314 const SkRect& dst, const SkPain t* paint)
315 : INHERITED(kDrawBitmapNine_OpType) {
316 fBitmap = bitmap;
317 fCenter = center;
318 fDst = dst;
319 if (paint) {
320 fPaint = *paint;
321 fPaintPtr = &fPaint;
322 } else {
323 fPaintPtr = nullptr;
324 }
325
326 fInfo.push(SkObjectParser::BitmapToString(bitmap));
327 fInfo.push(SkObjectParser::IRectToString(center));
328 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
329 if (paint) {
330 fInfo.push(SkObjectParser::PaintToString(*paint));
331 }
332 }
333
334 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
335 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
336 }
337
338 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
339 SkRect tmp = SkRect::Make(fCenter);
340 render_bitmap(canvas, fBitmap, &tmp);
341 return true;
342 }
343
344 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S kRect* src,
345 const SkRect& dst, const SkPain t* paint,
346 SkCanvas::SrcRectConstraint con straint)
347 : INHERITED(kDrawBitmapRect_OpType) {
348 fBitmap = bitmap;
349 if (src) {
350 fSrc = *src;
351 } else {
352 fSrc.setEmpty();
353 }
354 fDst = dst;
355
356 if (paint) {
357 fPaint = *paint;
358 fPaintPtr = &fPaint;
359 } else {
360 fPaintPtr = nullptr;
361 }
362 fConstraint = constraint;
363
364 fInfo.push(SkObjectParser::BitmapToString(bitmap));
365 if (src) {
366 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
367 }
368 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
369 if (paint) {
370 fInfo.push(SkObjectParser::PaintToString(*paint));
371 }
372 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
373 }
374
375 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
376 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fCo nstraint);
377 }
378
379 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
380 render_bitmap(canvas, fBitmap, this->srcRect());
381 return true;
382 }
383
384 SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkSc alar top,
385 const SkPaint* paint)
386 : INHERITED(kDrawImage_OpType)
387 , fImage(SkRef(image))
388 , fLeft(left)
389 , fTop(top) {
390
391 fInfo.push(SkObjectParser::ImageToString(image));
392 fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
393 fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
394
395 if (paint) {
396 fPaint.set(*paint);
397 fInfo.push(SkObjectParser::PaintToString(*paint));
398 }
399 }
400
401 void SkDrawImageCommand::execute(SkCanvas* canvas) const {
402 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
403 }
404
405 bool SkDrawImageCommand::render(SkCanvas* canvas) const {
406 SkAutoCanvasRestore acr(canvas, true);
407 canvas->clear(0xFFFFFFFF);
408
409 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
410 SkIntToScalar(fImage->wid th()),
411 SkIntToScalar(fImage->hei ght())));
412 this->execute(canvas);
413 return true;
414 }
415
416 SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRec t* src,
417 const SkRect& dst, const SkPaint* paint,
418 SkCanvas::SrcRectConstraint const raint)
419 : INHERITED(kDrawImageRect_OpType)
420 , fImage(SkRef(image))
421 , fDst(dst)
422 , fConstraint(constraint) {
423
424 if (src) {
425 fSrc.set(*src);
426 }
427
428 if (paint) {
429 fPaint.set(*paint);
430 }
431
432 fInfo.push(SkObjectParser::ImageToString(image));
433 if (src) {
434 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
435 }
436 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
437 if (paint) {
438 fInfo.push(SkObjectParser::PaintToString(*paint));
439 }
440 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
441 }
442
443 void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
444 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMa ybeNull(), fConstraint);
445 }
446
447 bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
448 SkAutoCanvasRestore acr(canvas, true);
449 canvas->clear(0xFFFFFFFF);
450
451 xlate_and_scale_to_bounds(canvas, fDst);
452
453 this->execute(canvas);
454 return true;
455 }
456
457 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
458 : INHERITED(kDrawOval_OpType) {
459 fOval = oval;
460 fPaint = paint;
461
462 fInfo.push(SkObjectParser::RectToString(oval));
463 fInfo.push(SkObjectParser::PaintToString(paint));
464 }
465
466 void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
467 canvas->drawOval(fOval, fPaint);
468 }
469
470 bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
471 canvas->clear(0xFFFFFFFF);
472 canvas->save();
473
474 xlate_and_scale_to_bounds(canvas, fOval);
475
476 SkPaint p;
477 p.setColor(SK_ColorBLACK);
478 p.setStyle(SkPaint::kStroke_Style);
479
480 canvas->drawOval(fOval, p);
481 canvas->restore();
482
483 return true;
484 }
485
486 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
487 : INHERITED(kDrawPaint_OpType) {
488 fPaint = paint;
489
490 fInfo.push(SkObjectParser::PaintToString(paint));
491 }
492
493 void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
494 canvas->drawPaint(fPaint);
495 }
496
497 bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
498 canvas->clear(0xFFFFFFFF);
499 canvas->drawPaint(fPaint);
500 return true;
501 }
502
503 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
504 : INHERITED(kDrawPath_OpType) {
505 fPath = path;
506 fPaint = paint;
507
508 fInfo.push(SkObjectParser::PathToString(path));
509 fInfo.push(SkObjectParser::PaintToString(paint));
510 }
511
512 void SkDrawPathCommand::execute(SkCanvas* canvas) const {
513 canvas->drawPath(fPath, fPaint);
514 }
515
516 bool SkDrawPathCommand::render(SkCanvas* canvas) const {
517 render_path(canvas, fPath);
518 return true;
519 }
520
521 SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
522 const SkMatrix* matrix,
523 const SkPaint* paint)
524 : INHERITED(kBeginDrawPicture_OpType)
525 , fPicture(SkRef(picture)) {
526
527 SkString* str = new SkString;
528 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
529 picture->cullRect().fLeft, picture->cullRect().fTop,
530 picture->cullRect().fRight, picture->cullRect().fBottom);
531 fInfo.push(str);
532
533 if (matrix) {
534 fMatrix.set(*matrix);
535 fInfo.push(SkObjectParser::MatrixToString(*matrix));
536 }
537
538 if (paint) {
539 fPaint.set(*paint);
540 fInfo.push(SkObjectParser::PaintToString(*paint));
541 }
542
543 }
544
545 void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
546 if (fPaint.isValid()) {
547 SkRect bounds = fPicture->cullRect();
548 if (fMatrix.isValid()) {
549 fMatrix.get()->mapRect(&bounds);
550 }
551 canvas->saveLayer(&bounds, fPaint.get());
552 }
553
554 if (fMatrix.isValid()) {
555 if (!fPaint.isValid()) {
556 canvas->save();
557 }
558 canvas->concat(*fMatrix.get());
559 }
560 }
561
562 bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
563 canvas->clear(0xFFFFFFFF);
564 canvas->save();
565
566 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
567
568 canvas->drawPicture(fPicture.get());
569
570 canvas->restore();
571
572 return true;
573 }
574
575 SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
576 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
577
578 void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
579 if (fRestore) {
580 canvas->restore();
581 }
582 }
583
584 SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
585 const SkPoint pts[], const SkPaint& pai nt)
586 : INHERITED(kDrawPoints_OpType) {
587 fMode = mode;
588 fCount = count;
589 fPts = new SkPoint[count];
590 memcpy(fPts, pts, count * sizeof(SkPoint));
591 fPaint = paint;
592
593 fInfo.push(SkObjectParser::PointsToString(pts, count));
594 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count) ,
595 "Points: "));
596 fInfo.push(SkObjectParser::PointModeToString(mode));
597 fInfo.push(SkObjectParser::PaintToString(paint));
598 }
599
600 void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
601 canvas->drawPoints(fMode, fCount, fPts, fPaint);
602 }
603
604 bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
605 canvas->clear(0xFFFFFFFF);
606 canvas->save();
607
608 SkRect bounds;
609
610 bounds.setEmpty();
611 for (unsigned int i = 0; i < fCount; ++i) {
612 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
613 }
614
615 xlate_and_scale_to_bounds(canvas, bounds);
616
617 SkPaint p;
618 p.setColor(SK_ColorBLACK);
619 p.setStyle(SkPaint::kStroke_Style);
620
621 canvas->drawPoints(fMode, fCount, fPts, p);
622 canvas->restore();
623
624 return true;
625 }
626
627 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
628 const SkPoint pos[], const SkPaint& p aint)
629 : INHERITED(kDrawPosText_OpType) {
630 size_t numPts = paint.countText(text, byteLength);
631
632 fText = new char[byteLength];
633 memcpy(fText, text, byteLength);
634 fByteLength = byteLength;
635
636 fPos = new SkPoint[numPts];
637 memcpy(fPos, pos, numPts * sizeof(SkPoint));
638
639 fPaint = paint;
640
641 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
642 // TODO(chudy): Test that this works.
643 fInfo.push(SkObjectParser::PointsToString(pos, 1));
644 fInfo.push(SkObjectParser::PaintToString(paint));
645 }
646
647 void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
648 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
649 }
650
651
652 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength ,
653 const SkScalar xpos[], SkScalar con stY,
654 const SkPaint& paint)
655 : INHERITED(kDrawPosTextH_OpType) {
656 size_t numPts = paint.countText(text, byteLength);
657
658 fText = new char[byteLength];
659 memcpy(fText, text, byteLength);
660 fByteLength = byteLength;
661
662 fXpos = new SkScalar[numPts];
663 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
664
665 fConstY = constY;
666 fPaint = paint;
667
668 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
669 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
670 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
671 fInfo.push(SkObjectParser::PaintToString(paint));
672 }
673
674 void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
675 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
676 }
677
678 static const char* gPositioningLabels[] = {
679 "kDefault_Positioning",
680 "kHorizontal_Positioning",
681 "kFull_Positioning",
682 };
683
684 SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
685 const SkPaint& paint)
686 : INHERITED(kDrawTextBlob_OpType)
687 , fBlob(SkRef(blob))
688 , fXPos(x)
689 , fYPos(y)
690 , fPaint(paint) {
691
692 SkAutoTDelete<SkString> runsStr(new SkString);
693 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
694 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
695 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
696 fInfo.push(runsStr);
697 fInfo.push(SkObjectParser::PaintToString(paint));
698
699 unsigned runs = 0;
700 SkPaint runPaint(paint);
701 SkTextBlobRunIterator iter(blob);
702 while (!iter.done()) {
703 SkAutoTDelete<SkString> tmpStr(new SkString);
704 tmpStr->printf("==== Run [%d] ====", runs++);
705 fInfo.push(tmpStr.release());
706
707 fInfo.push(SkObjectParser::IntToString(iter.glyphCount(), "GlyphCount: " ));
708 tmpStr.reset(new SkString("GlyphPositioning: "));
709 tmpStr->append(gPositioningLabels[iter.positioning()]);
710 fInfo.push(tmpStr.release());
711
712 iter.applyFontToPaint(&runPaint);
713 fInfo.push(SkObjectParser::PaintToString(runPaint));
714
715 iter.next();
716 }
717
718 runsStr->printf("Runs: %d", runs);
719 // runStr is owned by fInfo at this point.
720 runsStr.release();
721 }
722
723 void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
724 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
725 }
726
727 bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
728 canvas->clear(SK_ColorWHITE);
729 canvas->save();
730
731 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
732 xlate_and_scale_to_bounds(canvas, bounds);
733
734 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
735
736 canvas->restore();
737
738 return true;
739 }
740
741 SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor c olors[4],
742 const SkPoint texCoords[4], SkXfermode* x fermode,
743 const SkPaint& paint)
744 : INHERITED(kDrawPatch_OpType) {
745 memcpy(fCubics, cubics, sizeof(fCubics));
746 memcpy(fColors, colors, sizeof(fColors));
747 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
748 fXfermode.reset(xfermode);
749 fPaint = paint;
750
751 fInfo.push(SkObjectParser::PaintToString(paint));
752 }
753
754 void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
755 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
756 }
757
758 SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
759 : INHERITED(kDrawRect_OpType) {
760 fRect = rect;
761 fPaint = paint;
762
763 fInfo.push(SkObjectParser::RectToString(rect));
764 fInfo.push(SkObjectParser::PaintToString(paint));
765 }
766
767 void SkDrawRectCommand::execute(SkCanvas* canvas) const {
768 canvas->drawRect(fRect, fPaint);
769 }
770
771 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& pain t)
772 : INHERITED(kDrawRRect_OpType) {
773 fRRect = rrect;
774 fPaint = paint;
775
776 fInfo.push(SkObjectParser::RRectToString(rrect));
777 fInfo.push(SkObjectParser::PaintToString(paint));
778 }
779
780 void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
781 canvas->drawRRect(fRRect, fPaint);
782 }
783
784 bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
785 render_rrect(canvas, fRRect);
786 return true;
787 }
788
789 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
790 const SkRRect& inner,
791 const SkPaint& paint)
792 : INHERITED(kDrawDRRect_OpType) {
793 fOuter = outer;
794 fInner = inner;
795 fPaint = paint;
796
797 fInfo.push(SkObjectParser::RRectToString(outer));
798 fInfo.push(SkObjectParser::RRectToString(inner));
799 fInfo.push(SkObjectParser::PaintToString(paint));
800 }
801
802 void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
803 canvas->drawDRRect(fOuter, fInner, fPaint);
804 }
805
806 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
807 render_drrect(canvas, fOuter, fInner);
808 return true;
809 }
810
811 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScal ar x, SkScalar y,
812 const SkPaint& paint)
813 : INHERITED(kDrawText_OpType) {
814 fText = new char[byteLength];
815 memcpy(fText, text, byteLength);
816 fByteLength = byteLength;
817 fX = x;
818 fY = y;
819 fPaint = paint;
820
821 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
822 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
823 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
824 fInfo.push(SkObjectParser::PaintToString(paint));
825 }
826
827 void SkDrawTextCommand::execute(SkCanvas* canvas) const {
828 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
829 }
830
831 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe ngth,
832 const SkPath& path, const SkMat rix* matrix,
833 const SkPaint& paint)
834 : INHERITED(kDrawTextOnPath_OpType) {
835 fText = new char[byteLength];
836 memcpy(fText, text, byteLength);
837 fByteLength = byteLength;
838 fPath = path;
839 if (matrix) {
840 fMatrix = *matrix;
841 } else {
842 fMatrix.setIdentity();
843 }
844 fPaint = paint;
845
846 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
847 fInfo.push(SkObjectParser::PathToString(path));
848 if (matrix) {
849 fInfo.push(SkObjectParser::MatrixToString(*matrix));
850 }
851 fInfo.push(SkObjectParser::PaintToString(paint));
852 }
853
854 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
855 canvas->drawTextOnPath(fText, fByteLength, fPath,
856 fMatrix.isIdentity() ? nullptr : &fMatrix,
857 fPaint);
858 }
859
860 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver texCount,
861 const SkPoint vertices[], const SkP oint texs[],
862 const SkColor colors[], SkXfermode* xfermode,
863 const uint16_t indices[], int index Count,
864 const SkPaint& paint)
865 : INHERITED(kDrawVertices_OpType) {
866 fVmode = vmode;
867
868 fVertexCount = vertexCount;
869
870 fVertices = new SkPoint[vertexCount];
871 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
872
873 if (texs) {
874 fTexs = new SkPoint[vertexCount];
875 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
876 } else {
877 fTexs = nullptr;
878 }
879
880 if (colors) {
881 fColors = new SkColor[vertexCount];
882 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
883 } else {
884 fColors = nullptr;
885 }
886
887 fXfermode = xfermode;
888 if (fXfermode) {
889 fXfermode->ref();
890 }
891
892 if (indexCount > 0) {
893 fIndices = new uint16_t[indexCount];
894 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
895 } else {
896 fIndices = nullptr;
897 }
898
899 fIndexCount = indexCount;
900 fPaint = paint;
901
902 // TODO(chudy)
903 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
904 fInfo.push(SkObjectParser::PaintToString(paint));
905 }
906
907 SkDrawVerticesCommand::~SkDrawVerticesCommand() {
908 delete [] fVertices;
909 delete [] fTexs;
910 delete [] fColors;
911 SkSafeUnref(fXfermode);
912 delete [] fIndices;
913 }
914
915 void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
916 canvas->drawVertices(fVmode, fVertexCount, fVertices,
917 fTexs, fColors, fXfermode, fIndices,
918 fIndexCount, fPaint);
919 }
920
921 SkRestoreCommand::SkRestoreCommand()
922 : INHERITED(kRestore_OpType) {
923 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
924 }
925
926 void SkRestoreCommand::execute(SkCanvas* canvas) const {
927 canvas->restore();
928 }
929
930 SkSaveCommand::SkSaveCommand()
931 : INHERITED(kSave_OpType) {
932 }
933
934 void SkSaveCommand::execute(SkCanvas* canvas) const {
935 canvas->save();
936 }
937
938 SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec)
939 : INHERITED(kSaveLayer_OpType) {
940 if (rec.fBounds) {
941 fBounds = *rec.fBounds;
942 } else {
943 fBounds.setEmpty();
944 }
945
946 if (rec.fPaint) {
947 fPaint = *rec.fPaint;
948 fPaintPtr = &fPaint;
949 } else {
950 fPaintPtr = nullptr;
951 }
952 fSaveLayerFlags = rec.fSaveLayerFlags;
953
954 if (rec.fBounds) {
955 fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: "));
956 }
957 if (rec.fPaint) {
958 fInfo.push(SkObjectParser::PaintToString(*rec.fPaint));
959 }
960 fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags));
961 }
962
963 void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
964 canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBou nds,
965 fPaintPtr,
966 fSaveLayerFlags));
967 }
968
969 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
970 canvas->save();
971 }
972
973 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
974 : INHERITED(kSetMatrix_OpType) {
975 fUserMatrix.reset();
976 fMatrix = matrix;
977
978 fInfo.push(SkObjectParser::MatrixToString(matrix));
979 }
980
981 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
982 fUserMatrix = userMatrix;
983 }
984
985 void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
986 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
987 canvas->setMatrix(temp);
988 }
989
OLDNEW
« no previous file with comments | « src/utils/debugger/SkDrawCommand.h ('k') | src/utils/debugger/SkObjectParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698