gfx/skia/trunk/src/utils/debugger/SkDrawCommand.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2012 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkDrawCommand.h"
michael@0 11 #include "SkObjectParser.h"
michael@0 12
michael@0 13 // TODO(chudy): Refactor into non subclass model.
michael@0 14
michael@0 15 SkDrawCommand::SkDrawCommand(DrawType type)
michael@0 16 : fDrawType(type)
michael@0 17 , fVisible(true) {
michael@0 18 }
michael@0 19
michael@0 20 SkDrawCommand::SkDrawCommand() {
michael@0 21 fVisible = true;
michael@0 22 }
michael@0 23
michael@0 24 SkDrawCommand::~SkDrawCommand() {
michael@0 25 fInfo.deleteAll();
michael@0 26 }
michael@0 27
michael@0 28 const char* SkDrawCommand::GetCommandString(DrawType type) {
michael@0 29 switch (type) {
michael@0 30 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
michael@0 31 case DRAW_CLEAR: return "Clear";
michael@0 32 case CLIP_PATH: return "Clip Path";
michael@0 33 case CLIP_REGION: return "Clip Region";
michael@0 34 case CLIP_RECT: return "Clip Rect";
michael@0 35 case CLIP_RRECT: return "Clip RRect";
michael@0 36 case CONCAT: return "Concat";
michael@0 37 case DRAW_BITMAP: return "Draw Bitmap";
michael@0 38 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
michael@0 39 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
michael@0 40 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
michael@0 41 case DRAW_DATA: return "Draw Data";
michael@0 42 case DRAW_OVAL: return "Draw Oval";
michael@0 43 case DRAW_PAINT: return "Draw Paint";
michael@0 44 case DRAW_PATH: return "Draw Path";
michael@0 45 case DRAW_PICTURE: return "Draw Picture";
michael@0 46 case DRAW_POINTS: return "Draw Points";
michael@0 47 case DRAW_POS_TEXT: return "Draw Pos Text";
michael@0 48 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
michael@0 49 case DRAW_RECT: return "Draw Rect";
michael@0 50 case DRAW_RRECT: return "Draw RRect";
michael@0 51 case DRAW_SPRITE: return "Draw Sprite";
michael@0 52 case DRAW_TEXT: return "Draw Text";
michael@0 53 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
michael@0 54 case DRAW_VERTICES: return "Draw Vertices";
michael@0 55 case RESTORE: return "Restore";
michael@0 56 case ROTATE: return "Rotate";
michael@0 57 case SAVE: return "Save";
michael@0 58 case SAVE_LAYER: return "Save Layer";
michael@0 59 case SCALE: return "Scale";
michael@0 60 case SET_MATRIX: return "Set Matrix";
michael@0 61 case SKEW: return "Skew";
michael@0 62 case TRANSLATE: return "Translate";
michael@0 63 case NOOP: return "NoOp";
michael@0 64 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
michael@0 65 case COMMENT: return "Comment";
michael@0 66 case END_COMMENT_GROUP: return "EndCommentGroup";
michael@0 67 case DRAW_DRRECT: return "Draw DRRect";
michael@0 68 case PUSH_CULL: return "PushCull";
michael@0 69 case POP_CULL: return "PopCull";
michael@0 70 default:
michael@0 71 SkDebugf("DrawType error 0x%08x\n", type);
michael@0 72 SkASSERT(0);
michael@0 73 break;
michael@0 74 }
michael@0 75 SkDEBUGFAIL("DrawType UNUSED\n");
michael@0 76 return NULL;
michael@0 77 }
michael@0 78
michael@0 79 SkString SkDrawCommand::toString() {
michael@0 80 return SkString(GetCommandString(fDrawType));
michael@0 81 }
michael@0 82
michael@0 83 SkClearCommand::SkClearCommand(SkColor color) {
michael@0 84 fColor = color;
michael@0 85 fDrawType = DRAW_CLEAR;
michael@0 86 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
michael@0 87 }
michael@0 88
michael@0 89 void SkClearCommand::execute(SkCanvas* canvas) {
michael@0 90 canvas->clear(fColor);
michael@0 91 }
michael@0 92
michael@0 93 namespace {
michael@0 94
michael@0 95 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
michael@0 96 const SkISize& size = canvas->getDeviceSize();
michael@0 97
michael@0 98 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
michael@0 99
michael@0 100 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
michael@0 101 if (bounds.width() > bounds.height()) {
michael@0 102 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
michael@0 103 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
michael@0 104 } else {
michael@0 105 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
michael@0 106 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
michael@0 107 }
michael@0 108 canvas->translate(-bounds.centerX(), -bounds.centerY());
michael@0 109 }
michael@0 110
michael@0 111
michael@0 112 void render_path(SkCanvas* canvas, const SkPath& path) {
michael@0 113 canvas->clear(0xFFFFFFFF);
michael@0 114 canvas->save();
michael@0 115
michael@0 116 const SkRect& bounds = path.getBounds();
michael@0 117
michael@0 118 xlate_and_scale_to_bounds(canvas, bounds);
michael@0 119
michael@0 120 SkPaint p;
michael@0 121 p.setColor(SK_ColorBLACK);
michael@0 122 p.setStyle(SkPaint::kStroke_Style);
michael@0 123
michael@0 124 canvas->drawPath(path, p);
michael@0 125 canvas->restore();
michael@0 126 }
michael@0 127
michael@0 128 void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
michael@0 129 const SkISize& size = canvas->getDeviceSize();
michael@0 130
michael@0 131 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
michael@0 132 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
michael@0 133
michael@0 134 if (input.width() > input.height()) {
michael@0 135 yScale *= input.height() / (float) input.width();
michael@0 136 } else {
michael@0 137 xScale *= input.width() / (float) input.height();
michael@0 138 }
michael@0 139
michael@0 140 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
michael@0 141 xScale * input.width(),
michael@0 142 yScale * input.height());
michael@0 143
michael@0 144 canvas->clear(0xFFFFFFFF);
michael@0 145 canvas->drawBitmapRect(input, NULL, dst);
michael@0 146
michael@0 147 if (NULL != srcRect) {
michael@0 148 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
michael@0 149 srcRect->fTop * yScale + SK_Scalar1,
michael@0 150 srcRect->fRight * xScale + SK_Scalar1,
michael@0 151 srcRect->fBottom * yScale + SK_Scalar1);
michael@0 152 SkPaint p;
michael@0 153 p.setColor(SK_ColorRED);
michael@0 154 p.setStyle(SkPaint::kStroke_Style);
michael@0 155
michael@0 156 canvas->drawRect(r, p);
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
michael@0 161 canvas->clear(0xFFFFFFFF);
michael@0 162 canvas->save();
michael@0 163
michael@0 164 const SkRect& bounds = rrect.getBounds();
michael@0 165
michael@0 166 xlate_and_scale_to_bounds(canvas, bounds);
michael@0 167
michael@0 168 SkPaint p;
michael@0 169 p.setColor(SK_ColorBLACK);
michael@0 170 p.setStyle(SkPaint::kStroke_Style);
michael@0 171
michael@0 172 canvas->drawRRect(rrect, p);
michael@0 173 canvas->restore();
michael@0 174 }
michael@0 175
michael@0 176 void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
michael@0 177 canvas->clear(0xFFFFFFFF);
michael@0 178 canvas->save();
michael@0 179
michael@0 180 const SkRect& bounds = outer.getBounds();
michael@0 181
michael@0 182 xlate_and_scale_to_bounds(canvas, bounds);
michael@0 183
michael@0 184 SkPaint p;
michael@0 185 p.setColor(SK_ColorBLACK);
michael@0 186 p.setStyle(SkPaint::kStroke_Style);
michael@0 187
michael@0 188 canvas->drawDRRect(outer, inner, p);
michael@0 189 canvas->restore();
michael@0 190 }
michael@0 191
michael@0 192 };
michael@0 193
michael@0 194
michael@0 195 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA) {
michael@0 196 fPath = path;
michael@0 197 fOp = op;
michael@0 198 fDoAA = doAA;
michael@0 199 fDrawType = CLIP_PATH;
michael@0 200
michael@0 201 fInfo.push(SkObjectParser::PathToString(path));
michael@0 202 fInfo.push(SkObjectParser::RegionOpToString(op));
michael@0 203 fInfo.push(SkObjectParser::BoolToString(doAA));
michael@0 204 }
michael@0 205
michael@0 206 void SkClipPathCommand::execute(SkCanvas* canvas) {
michael@0 207 canvas->clipPath(fPath, fOp, fDoAA);
michael@0 208 }
michael@0 209
michael@0 210 bool SkClipPathCommand::render(SkCanvas* canvas) const {
michael@0 211 render_path(canvas, fPath);
michael@0 212 return true;
michael@0 213 }
michael@0 214
michael@0 215 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op) {
michael@0 216 fRegion = region;
michael@0 217 fOp = op;
michael@0 218 fDrawType = CLIP_REGION;
michael@0 219
michael@0 220 fInfo.push(SkObjectParser::RegionToString(region));
michael@0 221 fInfo.push(SkObjectParser::RegionOpToString(op));
michael@0 222 }
michael@0 223
michael@0 224 void SkClipRegionCommand::execute(SkCanvas* canvas) {
michael@0 225 canvas->clipRegion(fRegion, fOp);
michael@0 226 }
michael@0 227
michael@0 228 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA) {
michael@0 229 fRect = rect;
michael@0 230 fOp = op;
michael@0 231 fDoAA = doAA;
michael@0 232 fDrawType = CLIP_RECT;
michael@0 233
michael@0 234 fInfo.push(SkObjectParser::RectToString(rect));
michael@0 235 fInfo.push(SkObjectParser::RegionOpToString(op));
michael@0 236 fInfo.push(SkObjectParser::BoolToString(doAA));
michael@0 237 }
michael@0 238
michael@0 239 void SkClipRectCommand::execute(SkCanvas* canvas) {
michael@0 240 canvas->clipRect(fRect, fOp, fDoAA);
michael@0 241 }
michael@0 242
michael@0 243 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
michael@0 244 fRRect = rrect;
michael@0 245 fOp = op;
michael@0 246 fDoAA = doAA;
michael@0 247 fDrawType = CLIP_RRECT;
michael@0 248
michael@0 249 fInfo.push(SkObjectParser::RRectToString(rrect));
michael@0 250 fInfo.push(SkObjectParser::RegionOpToString(op));
michael@0 251 fInfo.push(SkObjectParser::BoolToString(doAA));
michael@0 252 }
michael@0 253
michael@0 254 void SkClipRRectCommand::execute(SkCanvas* canvas) {
michael@0 255 canvas->clipRRect(fRRect, fOp, fDoAA);
michael@0 256 }
michael@0 257
michael@0 258 bool SkClipRRectCommand::render(SkCanvas* canvas) const {
michael@0 259 render_rrect(canvas, fRRect);
michael@0 260 return true;
michael@0 261 }
michael@0 262
michael@0 263 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) {
michael@0 264 fMatrix = matrix;
michael@0 265 fDrawType = CONCAT;
michael@0 266
michael@0 267 fInfo.push(SkObjectParser::MatrixToString(matrix));
michael@0 268 }
michael@0 269
michael@0 270 void SkConcatCommand::execute(SkCanvas* canvas) {
michael@0 271 canvas->concat(fMatrix);
michael@0 272 }
michael@0 273
michael@0 274 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
michael@0 275 const SkPaint* paint) {
michael@0 276 fBitmap = bitmap;
michael@0 277 fLeft = left;
michael@0 278 fTop = top;
michael@0 279 if (NULL != paint) {
michael@0 280 fPaint = *paint;
michael@0 281 fPaintPtr = &fPaint;
michael@0 282 } else {
michael@0 283 fPaintPtr = NULL;
michael@0 284 }
michael@0 285 fDrawType = DRAW_BITMAP;
michael@0 286
michael@0 287 fInfo.push(SkObjectParser::BitmapToString(bitmap));
michael@0 288 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
michael@0 289 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
michael@0 290 if (NULL != paint) {
michael@0 291 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 292 }
michael@0 293 }
michael@0 294
michael@0 295 void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
michael@0 296 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
michael@0 297 }
michael@0 298
michael@0 299 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
michael@0 300 render_bitmap(canvas, fBitmap);
michael@0 301 return true;
michael@0 302 }
michael@0 303
michael@0 304 SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
michael@0 305 const SkMatrix& matrix,
michael@0 306 const SkPaint* paint) {
michael@0 307 fBitmap = bitmap;
michael@0 308 fMatrix = matrix;
michael@0 309 if (NULL != paint) {
michael@0 310 fPaint = *paint;
michael@0 311 fPaintPtr = &fPaint;
michael@0 312 } else {
michael@0 313 fPaintPtr = NULL;
michael@0 314 }
michael@0 315 fDrawType = DRAW_BITMAP_MATRIX;
michael@0 316
michael@0 317 fInfo.push(SkObjectParser::BitmapToString(bitmap));
michael@0 318 fInfo.push(SkObjectParser::MatrixToString(matrix));
michael@0 319 if (NULL != paint) {
michael@0 320 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 321 }
michael@0 322 }
michael@0 323
michael@0 324 void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
michael@0 325 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
michael@0 326 }
michael@0 327
michael@0 328 bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
michael@0 329 render_bitmap(canvas, fBitmap);
michael@0 330 return true;
michael@0 331 }
michael@0 332
michael@0 333 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
michael@0 334 const SkRect& dst, const SkPaint* paint) {
michael@0 335 fBitmap = bitmap;
michael@0 336 fCenter = center;
michael@0 337 fDst = dst;
michael@0 338 if (NULL != paint) {
michael@0 339 fPaint = *paint;
michael@0 340 fPaintPtr = &fPaint;
michael@0 341 } else {
michael@0 342 fPaintPtr = NULL;
michael@0 343 }
michael@0 344 fDrawType = DRAW_BITMAP_NINE;
michael@0 345
michael@0 346 fInfo.push(SkObjectParser::BitmapToString(bitmap));
michael@0 347 fInfo.push(SkObjectParser::IRectToString(center));
michael@0 348 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
michael@0 349 if (NULL != paint) {
michael@0 350 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 351 }
michael@0 352 }
michael@0 353
michael@0 354 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
michael@0 355 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
michael@0 356 }
michael@0 357
michael@0 358 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
michael@0 359 render_bitmap(canvas, fBitmap);
michael@0 360 return true;
michael@0 361 }
michael@0 362
michael@0 363 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
michael@0 364 const SkRect& dst, const SkPaint* paint,
michael@0 365 SkCanvas::DrawBitmapRectFlags flags) {
michael@0 366 fBitmap = bitmap;
michael@0 367 if (NULL != src) {
michael@0 368 fSrc = *src;
michael@0 369 } else {
michael@0 370 fSrc.setEmpty();
michael@0 371 }
michael@0 372 fDst = dst;
michael@0 373
michael@0 374 if (NULL != paint) {
michael@0 375 fPaint = *paint;
michael@0 376 fPaintPtr = &fPaint;
michael@0 377 } else {
michael@0 378 fPaintPtr = NULL;
michael@0 379 }
michael@0 380 fFlags = flags;
michael@0 381
michael@0 382 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
michael@0 383
michael@0 384 fInfo.push(SkObjectParser::BitmapToString(bitmap));
michael@0 385 if (NULL != src) {
michael@0 386 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
michael@0 387 }
michael@0 388 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
michael@0 389 if (NULL != paint) {
michael@0 390 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 391 }
michael@0 392 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
michael@0 393 }
michael@0 394
michael@0 395 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) {
michael@0 396 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
michael@0 397 }
michael@0 398
michael@0 399 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
michael@0 400 render_bitmap(canvas, fBitmap, this->srcRect());
michael@0 401 return true;
michael@0 402 }
michael@0 403
michael@0 404 SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length) {
michael@0 405 fData = new char[length];
michael@0 406 memcpy(fData, data, length);
michael@0 407 fLength = length;
michael@0 408 fDrawType = DRAW_DATA;
michael@0 409
michael@0 410 // TODO: add display of actual data?
michael@0 411 SkString* str = new SkString;
michael@0 412 str->appendf("length: %d", (int) length);
michael@0 413 fInfo.push(str);
michael@0 414 }
michael@0 415
michael@0 416 void SkDrawDataCommand::execute(SkCanvas* canvas) {
michael@0 417 canvas->drawData(fData, fLength);
michael@0 418 }
michael@0 419
michael@0 420 SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
michael@0 421 : INHERITED(BEGIN_COMMENT_GROUP)
michael@0 422 , fDescription(description) {
michael@0 423 SkString* temp = new SkString;
michael@0 424 temp->appendf("Description: %s", description);
michael@0 425 fInfo.push(temp);
michael@0 426 }
michael@0 427
michael@0 428 SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
michael@0 429 : INHERITED(COMMENT)
michael@0 430 , fKywd(kywd)
michael@0 431 , fValue(value) {
michael@0 432 SkString* temp = new SkString;
michael@0 433 temp->appendf("%s: %s", kywd, value);
michael@0 434 fInfo.push(temp);
michael@0 435 }
michael@0 436
michael@0 437 SkEndCommentGroupCommand::SkEndCommentGroupCommand() : INHERITED(END_COMMENT_GROUP) {
michael@0 438 }
michael@0 439
michael@0 440 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) {
michael@0 441 fOval = oval;
michael@0 442 fPaint = paint;
michael@0 443 fDrawType = DRAW_OVAL;
michael@0 444
michael@0 445 fInfo.push(SkObjectParser::RectToString(oval));
michael@0 446 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 447 }
michael@0 448
michael@0 449 void SkDrawOvalCommand::execute(SkCanvas* canvas) {
michael@0 450 canvas->drawOval(fOval, fPaint);
michael@0 451 }
michael@0 452
michael@0 453 bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
michael@0 454 canvas->clear(0xFFFFFFFF);
michael@0 455 canvas->save();
michael@0 456
michael@0 457 xlate_and_scale_to_bounds(canvas, fOval);
michael@0 458
michael@0 459 SkPaint p;
michael@0 460 p.setColor(SK_ColorBLACK);
michael@0 461 p.setStyle(SkPaint::kStroke_Style);
michael@0 462
michael@0 463 canvas->drawOval(fOval, p);
michael@0 464 canvas->restore();
michael@0 465
michael@0 466 return true;
michael@0 467 }
michael@0 468
michael@0 469 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) {
michael@0 470 fPaint = paint;
michael@0 471 fDrawType = DRAW_PAINT;
michael@0 472
michael@0 473 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 474 }
michael@0 475
michael@0 476 void SkDrawPaintCommand::execute(SkCanvas* canvas) {
michael@0 477 canvas->drawPaint(fPaint);
michael@0 478 }
michael@0 479
michael@0 480 bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
michael@0 481 canvas->clear(0xFFFFFFFF);
michael@0 482 canvas->drawPaint(fPaint);
michael@0 483 return true;
michael@0 484 }
michael@0 485
michael@0 486 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) {
michael@0 487 fPath = path;
michael@0 488 fPaint = paint;
michael@0 489 fDrawType = DRAW_PATH;
michael@0 490
michael@0 491 fInfo.push(SkObjectParser::PathToString(path));
michael@0 492 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 493 }
michael@0 494
michael@0 495 void SkDrawPathCommand::execute(SkCanvas* canvas) {
michael@0 496 canvas->drawPath(fPath, fPaint);
michael@0 497 }
michael@0 498
michael@0 499 bool SkDrawPathCommand::render(SkCanvas* canvas) const {
michael@0 500 render_path(canvas, fPath);
michael@0 501 return true;
michael@0 502 }
michael@0 503
michael@0 504 SkDrawPictureCommand::SkDrawPictureCommand(SkPicture& picture) :
michael@0 505 fPicture(picture) {
michael@0 506 fDrawType = DRAW_PICTURE;
michael@0 507 SkString* temp = new SkString;
michael@0 508 temp->appendf("SkPicture: W: %d H: %d", picture.width(), picture.height());
michael@0 509 fInfo.push(temp);
michael@0 510 }
michael@0 511
michael@0 512 void SkDrawPictureCommand::execute(SkCanvas* canvas) {
michael@0 513 canvas->drawPicture(fPicture);
michael@0 514 }
michael@0 515
michael@0 516 bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
michael@0 517 canvas->clear(0xFFFFFFFF);
michael@0 518 canvas->save();
michael@0 519
michael@0 520 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture.width()),
michael@0 521 SkIntToScalar(fPicture.height()));
michael@0 522 xlate_and_scale_to_bounds(canvas, bounds);
michael@0 523
michael@0 524 canvas->drawPicture(const_cast<SkPicture&>(fPicture));
michael@0 525
michael@0 526 canvas->restore();
michael@0 527
michael@0 528 return true;
michael@0 529 }
michael@0 530
michael@0 531 SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
michael@0 532 const SkPoint pts[], const SkPaint& paint) {
michael@0 533 fMode = mode;
michael@0 534 fCount = count;
michael@0 535 fPts = new SkPoint[count];
michael@0 536 memcpy(fPts, pts, count * sizeof(SkPoint));
michael@0 537 fPaint = paint;
michael@0 538 fDrawType = DRAW_POINTS;
michael@0 539
michael@0 540 fInfo.push(SkObjectParser::PointsToString(pts, count));
michael@0 541 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
michael@0 542 "Points: "));
michael@0 543 fInfo.push(SkObjectParser::PointModeToString(mode));
michael@0 544 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 545 }
michael@0 546
michael@0 547 void SkDrawPointsCommand::execute(SkCanvas* canvas) {
michael@0 548 canvas->drawPoints(fMode, fCount, fPts, fPaint);
michael@0 549 }
michael@0 550
michael@0 551 bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
michael@0 552 canvas->clear(0xFFFFFFFF);
michael@0 553 canvas->save();
michael@0 554
michael@0 555 SkRect bounds;
michael@0 556
michael@0 557 bounds.setEmpty();
michael@0 558 for (unsigned int i = 0; i < fCount; ++i) {
michael@0 559 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
michael@0 560 }
michael@0 561
michael@0 562 xlate_and_scale_to_bounds(canvas, bounds);
michael@0 563
michael@0 564 SkPaint p;
michael@0 565 p.setColor(SK_ColorBLACK);
michael@0 566 p.setStyle(SkPaint::kStroke_Style);
michael@0 567
michael@0 568 canvas->drawPoints(fMode, fCount, fPts, p);
michael@0 569 canvas->restore();
michael@0 570
michael@0 571 return true;
michael@0 572 }
michael@0 573
michael@0 574 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
michael@0 575 const SkPoint pos[], const SkPaint& paint) {
michael@0 576 size_t numPts = paint.countText(text, byteLength);
michael@0 577
michael@0 578 fText = new char[byteLength];
michael@0 579 memcpy(fText, text, byteLength);
michael@0 580 fByteLength = byteLength;
michael@0 581
michael@0 582 fPos = new SkPoint[numPts];
michael@0 583 memcpy(fPos, pos, numPts * sizeof(SkPoint));
michael@0 584
michael@0 585 fPaint = paint;
michael@0 586 fDrawType = DRAW_POS_TEXT;
michael@0 587
michael@0 588 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
michael@0 589 // TODO(chudy): Test that this works.
michael@0 590 fInfo.push(SkObjectParser::PointsToString(pos, 1));
michael@0 591 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 592 }
michael@0 593
michael@0 594 void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
michael@0 595 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
michael@0 596 }
michael@0 597
michael@0 598
michael@0 599 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
michael@0 600 const SkScalar xpos[], SkScalar constY,
michael@0 601 const SkPaint& paint) {
michael@0 602 size_t numPts = paint.countText(text, byteLength);
michael@0 603
michael@0 604 fText = new char[byteLength];
michael@0 605 memcpy(fText, text, byteLength);
michael@0 606 fByteLength = byteLength;
michael@0 607
michael@0 608 fXpos = new SkScalar[numPts];
michael@0 609 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
michael@0 610
michael@0 611 fConstY = constY;
michael@0 612 fPaint = paint;
michael@0 613 fDrawType = DRAW_POS_TEXT_H;
michael@0 614
michael@0 615 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
michael@0 616 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
michael@0 617 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
michael@0 618 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 619 }
michael@0 620
michael@0 621 void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
michael@0 622 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
michael@0 623 }
michael@0 624
michael@0 625 SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) {
michael@0 626 fRect = rect;
michael@0 627 fPaint = paint;
michael@0 628 fDrawType = DRAW_RECT;
michael@0 629
michael@0 630 fInfo.push(SkObjectParser::RectToString(rect));
michael@0 631 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 632 }
michael@0 633
michael@0 634 void SkDrawRectCommand::execute(SkCanvas* canvas) {
michael@0 635 canvas->drawRect(fRect, fPaint);
michael@0 636 }
michael@0 637
michael@0 638 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) {
michael@0 639 fRRect = rrect;
michael@0 640 fPaint = paint;
michael@0 641 fDrawType = DRAW_RRECT;
michael@0 642
michael@0 643 fInfo.push(SkObjectParser::RRectToString(rrect));
michael@0 644 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 645 }
michael@0 646
michael@0 647 void SkDrawRRectCommand::execute(SkCanvas* canvas) {
michael@0 648 canvas->drawRRect(fRRect, fPaint);
michael@0 649 }
michael@0 650
michael@0 651 bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
michael@0 652 render_rrect(canvas, fRRect);
michael@0 653 return true;
michael@0 654 }
michael@0 655
michael@0 656 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
michael@0 657 const SkRRect& inner,
michael@0 658 const SkPaint& paint) {
michael@0 659 fOuter = outer;
michael@0 660 fInner = inner;
michael@0 661 fPaint = paint;
michael@0 662 fDrawType = DRAW_DRRECT;
michael@0 663
michael@0 664 fInfo.push(SkObjectParser::RRectToString(outer));
michael@0 665 fInfo.push(SkObjectParser::RRectToString(inner));
michael@0 666 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 667 }
michael@0 668
michael@0 669 void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
michael@0 670 canvas->drawDRRect(fOuter, fInner, fPaint);
michael@0 671 }
michael@0 672
michael@0 673 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
michael@0 674 render_drrect(canvas, fOuter, fInner);
michael@0 675 return true;
michael@0 676 }
michael@0 677
michael@0 678 SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
michael@0 679 const SkPaint* paint) {
michael@0 680 fBitmap = bitmap;
michael@0 681 fLeft = left;
michael@0 682 fTop = top;
michael@0 683 if (NULL != paint) {
michael@0 684 fPaint = *paint;
michael@0 685 fPaintPtr = &fPaint;
michael@0 686 } else {
michael@0 687 fPaintPtr = NULL;
michael@0 688 }
michael@0 689 fDrawType = DRAW_SPRITE;
michael@0 690
michael@0 691 fInfo.push(SkObjectParser::BitmapToString(bitmap));
michael@0 692 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
michael@0 693 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
michael@0 694 if (NULL != paint) {
michael@0 695 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 696 }
michael@0 697 }
michael@0 698
michael@0 699 void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
michael@0 700 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
michael@0 701 }
michael@0 702
michael@0 703 bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
michael@0 704 render_bitmap(canvas, fBitmap);
michael@0 705 return true;
michael@0 706 }
michael@0 707
michael@0 708 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
michael@0 709 const SkPaint& paint) {
michael@0 710 fText = new char[byteLength];
michael@0 711 memcpy(fText, text, byteLength);
michael@0 712 fByteLength = byteLength;
michael@0 713 fX = x;
michael@0 714 fY = y;
michael@0 715 fPaint = paint;
michael@0 716 fDrawType = DRAW_TEXT;
michael@0 717
michael@0 718 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
michael@0 719 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
michael@0 720 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
michael@0 721 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 722 }
michael@0 723
michael@0 724 void SkDrawTextCommand::execute(SkCanvas* canvas) {
michael@0 725 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
michael@0 726 }
michael@0 727
michael@0 728 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
michael@0 729 const SkPath& path, const SkMatrix* matrix,
michael@0 730 const SkPaint& paint) {
michael@0 731 fText = new char[byteLength];
michael@0 732 memcpy(fText, text, byteLength);
michael@0 733 fByteLength = byteLength;
michael@0 734 fPath = path;
michael@0 735 if (NULL != matrix) {
michael@0 736 fMatrix = *matrix;
michael@0 737 } else {
michael@0 738 fMatrix.setIdentity();
michael@0 739 }
michael@0 740 fPaint = paint;
michael@0 741 fDrawType = DRAW_TEXT_ON_PATH;
michael@0 742
michael@0 743 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
michael@0 744 fInfo.push(SkObjectParser::PathToString(path));
michael@0 745 if (NULL != matrix) {
michael@0 746 fInfo.push(SkObjectParser::MatrixToString(*matrix));
michael@0 747 }
michael@0 748 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 749 }
michael@0 750
michael@0 751 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
michael@0 752 canvas->drawTextOnPath(fText, fByteLength, fPath,
michael@0 753 fMatrix.isIdentity() ? NULL : &fMatrix,
michael@0 754 fPaint);
michael@0 755 }
michael@0 756
michael@0 757 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
michael@0 758 const SkPoint vertices[], const SkPoint texs[],
michael@0 759 const SkColor colors[], SkXfermode* xfermode,
michael@0 760 const uint16_t indices[], int indexCount,
michael@0 761 const SkPaint& paint) {
michael@0 762 fVmode = vmode;
michael@0 763
michael@0 764 fVertexCount = vertexCount;
michael@0 765
michael@0 766 fVertices = new SkPoint[vertexCount];
michael@0 767 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
michael@0 768
michael@0 769 if (NULL != texs) {
michael@0 770 fTexs = new SkPoint[vertexCount];
michael@0 771 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
michael@0 772 } else {
michael@0 773 fTexs = NULL;
michael@0 774 }
michael@0 775
michael@0 776 if (NULL != colors) {
michael@0 777 fColors = new SkColor[vertexCount];
michael@0 778 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
michael@0 779 } else {
michael@0 780 fColors = NULL;
michael@0 781 }
michael@0 782
michael@0 783 fXfermode = xfermode;
michael@0 784 if (NULL != fXfermode) {
michael@0 785 fXfermode->ref();
michael@0 786 }
michael@0 787
michael@0 788 if (indexCount > 0) {
michael@0 789 fIndices = new uint16_t[indexCount];
michael@0 790 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
michael@0 791 } else {
michael@0 792 fIndices = NULL;
michael@0 793 }
michael@0 794
michael@0 795 fIndexCount = indexCount;
michael@0 796 fPaint = paint;
michael@0 797 fDrawType = DRAW_VERTICES;
michael@0 798
michael@0 799 // TODO(chudy)
michael@0 800 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
michael@0 801 fInfo.push(SkObjectParser::PaintToString(paint));
michael@0 802 }
michael@0 803
michael@0 804 SkDrawVerticesCommand::~SkDrawVerticesCommand() {
michael@0 805 delete [] fVertices;
michael@0 806 delete [] fTexs;
michael@0 807 delete [] fColors;
michael@0 808 SkSafeUnref(fXfermode);
michael@0 809 delete [] fIndices;
michael@0 810 }
michael@0 811
michael@0 812 void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
michael@0 813 canvas->drawVertices(fVmode, fVertexCount, fVertices,
michael@0 814 fTexs, fColors, fXfermode, fIndices,
michael@0 815 fIndexCount, fPaint);
michael@0 816 }
michael@0 817
michael@0 818 SkRestoreCommand::SkRestoreCommand() {
michael@0 819 fDrawType = RESTORE;
michael@0 820 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
michael@0 821 }
michael@0 822
michael@0 823 void SkRestoreCommand::execute(SkCanvas* canvas) {
michael@0 824 canvas->restore();
michael@0 825 }
michael@0 826
michael@0 827 void SkRestoreCommand::trackSaveState(int* state) {
michael@0 828 (*state)--;
michael@0 829 }
michael@0 830
michael@0 831 SkRotateCommand::SkRotateCommand(SkScalar degrees) {
michael@0 832 fDegrees = degrees;
michael@0 833 fDrawType = ROTATE;
michael@0 834
michael@0 835 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
michael@0 836 }
michael@0 837
michael@0 838 void SkRotateCommand::execute(SkCanvas* canvas) {
michael@0 839 canvas->rotate(fDegrees);
michael@0 840 }
michael@0 841
michael@0 842 SkSaveCommand::SkSaveCommand(SkCanvas::SaveFlags flags) {
michael@0 843 fFlags = flags;
michael@0 844 fDrawType = SAVE;
michael@0 845 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
michael@0 846 }
michael@0 847
michael@0 848 void SkSaveCommand::execute(SkCanvas* canvas) {
michael@0 849 canvas->save(fFlags);
michael@0 850 }
michael@0 851
michael@0 852 void SkSaveCommand::trackSaveState(int* state) {
michael@0 853 (*state)++;
michael@0 854 }
michael@0 855
michael@0 856 SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
michael@0 857 SkCanvas::SaveFlags flags) {
michael@0 858 if (NULL != bounds) {
michael@0 859 fBounds = *bounds;
michael@0 860 } else {
michael@0 861 fBounds.setEmpty();
michael@0 862 }
michael@0 863
michael@0 864 if (NULL != paint) {
michael@0 865 fPaint = *paint;
michael@0 866 fPaintPtr = &fPaint;
michael@0 867 } else {
michael@0 868 fPaintPtr = NULL;
michael@0 869 }
michael@0 870 fFlags = flags;
michael@0 871 fDrawType = SAVE_LAYER;
michael@0 872
michael@0 873 if (NULL != bounds) {
michael@0 874 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
michael@0 875 }
michael@0 876 if (NULL != paint) {
michael@0 877 fInfo.push(SkObjectParser::PaintToString(*paint));
michael@0 878 }
michael@0 879 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
michael@0 880 }
michael@0 881
michael@0 882 void SkSaveLayerCommand::execute(SkCanvas* canvas) {
michael@0 883 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
michael@0 884 fPaintPtr,
michael@0 885 fFlags);
michael@0 886 }
michael@0 887
michael@0 888 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
michael@0 889 canvas->save();
michael@0 890 }
michael@0 891
michael@0 892 void SkSaveLayerCommand::trackSaveState(int* state) {
michael@0 893 (*state)++;
michael@0 894 }
michael@0 895
michael@0 896 SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy) {
michael@0 897 fSx = sx;
michael@0 898 fSy = sy;
michael@0 899 fDrawType = SCALE;
michael@0 900
michael@0 901 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
michael@0 902 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
michael@0 903 }
michael@0 904
michael@0 905 void SkScaleCommand::execute(SkCanvas* canvas) {
michael@0 906 canvas->scale(fSx, fSy);
michael@0 907 }
michael@0 908
michael@0 909 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) {
michael@0 910 fMatrix = matrix;
michael@0 911 fDrawType = SET_MATRIX;
michael@0 912
michael@0 913 fInfo.push(SkObjectParser::MatrixToString(matrix));
michael@0 914 }
michael@0 915
michael@0 916 void SkSetMatrixCommand::execute(SkCanvas* canvas) {
michael@0 917 canvas->setMatrix(fMatrix);
michael@0 918 }
michael@0 919
michael@0 920 SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy) {
michael@0 921 fSx = sx;
michael@0 922 fSy = sy;
michael@0 923 fDrawType = SKEW;
michael@0 924
michael@0 925 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
michael@0 926 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
michael@0 927 }
michael@0 928
michael@0 929 void SkSkewCommand::execute(SkCanvas* canvas) {
michael@0 930 canvas->skew(fSx, fSy);
michael@0 931 }
michael@0 932
michael@0 933 SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy) {
michael@0 934 fDx = dx;
michael@0 935 fDy = dy;
michael@0 936 fDrawType = TRANSLATE;
michael@0 937
michael@0 938 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
michael@0 939 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
michael@0 940 }
michael@0 941
michael@0 942 void SkTranslateCommand::execute(SkCanvas* canvas) {
michael@0 943 canvas->translate(fDx, fDy);
michael@0 944 }
michael@0 945
michael@0 946 SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
michael@0 947 : fCullRect(cullRect) {
michael@0 948 fDrawType = PUSH_CULL;
michael@0 949 fInfo.push(SkObjectParser::RectToString(cullRect));
michael@0 950 }
michael@0 951
michael@0 952 void SkPushCullCommand::execute(SkCanvas* canvas) {
michael@0 953 canvas->pushCull(fCullRect);
michael@0 954 }
michael@0 955
michael@0 956 void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
michael@0 957 canvas->pushCull(fCullRect);
michael@0 958
michael@0 959 SkPaint p;
michael@0 960 p.setColor(SK_ColorCYAN);
michael@0 961 p.setStyle(SkPaint::kStroke_Style);
michael@0 962 canvas->drawRect(fCullRect, p);
michael@0 963 }
michael@0 964
michael@0 965 SkPopCullCommand::SkPopCullCommand() {
michael@0 966 fDrawType = POP_CULL;
michael@0 967 }
michael@0 968
michael@0 969 void SkPopCullCommand::execute(SkCanvas* canvas) {
michael@0 970 canvas->popCull();
michael@0 971 }

mercurial