gfx/skia/trunk/src/utils/debugger/SkDebugCanvas.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 "SkColorPriv.h"
michael@0 11 #include "SkDebugCanvas.h"
michael@0 12 #include "SkDrawCommand.h"
michael@0 13 #include "SkDrawFilter.h"
michael@0 14 #include "SkDevice.h"
michael@0 15 #include "SkXfermode.h"
michael@0 16
michael@0 17 SkDebugCanvas::SkDebugCanvas(int width, int height)
michael@0 18 : INHERITED(width, height)
michael@0 19 , fWidth(width)
michael@0 20 , fHeight(height)
michael@0 21 , fFilter(false)
michael@0 22 , fMegaVizMode(false)
michael@0 23 , fIndex(0)
michael@0 24 , fOverdrawViz(false)
michael@0 25 , fOverdrawFilter(NULL)
michael@0 26 , fOverrideTexFiltering(false)
michael@0 27 , fTexOverrideFilter(NULL)
michael@0 28 , fOutstandingSaveCount(0) {
michael@0 29 fUserMatrix.reset();
michael@0 30
michael@0 31 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped
michael@0 32 // operations. This can lead to problems in the debugger which expects all
michael@0 33 // the operations in the captured skp to appear in the debug canvas. To
michael@0 34 // circumvent this we create a wide open clip here (an empty clip rect
michael@0 35 // is not sufficient).
michael@0 36 // Internally, the SkRect passed to clipRect is converted to an SkIRect and
michael@0 37 // rounded out. The following code creates a nearly maximal rect that will
michael@0 38 // not get collapsed by the coming conversions (Due to precision loss the
michael@0 39 // inset has to be surprisingly large).
michael@0 40 SkIRect largeIRect = SkIRect::MakeLargest();
michael@0 41 largeIRect.inset(1024, 1024);
michael@0 42 SkRect large = SkRect::Make(largeIRect);
michael@0 43 #ifdef SK_DEBUG
michael@0 44 large.roundOut(&largeIRect);
michael@0 45 SkASSERT(!largeIRect.isEmpty());
michael@0 46 #endif
michael@0 47 // call the base class' version to avoid adding a draw command
michael@0 48 this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyle);
michael@0 49 }
michael@0 50
michael@0 51 SkDebugCanvas::~SkDebugCanvas() {
michael@0 52 fCommandVector.deleteAll();
michael@0 53 SkSafeUnref(fOverdrawFilter);
michael@0 54 SkSafeUnref(fTexOverrideFilter);
michael@0 55 }
michael@0 56
michael@0 57 void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
michael@0 58 fCommandVector.push(command);
michael@0 59 }
michael@0 60
michael@0 61 void SkDebugCanvas::draw(SkCanvas* canvas) {
michael@0 62 if (!fCommandVector.isEmpty()) {
michael@0 63 drawTo(canvas, fCommandVector.count() - 1);
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) {
michael@0 68 canvas->concat(fUserMatrix);
michael@0 69 }
michael@0 70
michael@0 71 int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) {
michael@0 72 SkBitmap bitmap;
michael@0 73 bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1));
michael@0 74
michael@0 75 SkCanvas canvas(bitmap);
michael@0 76 canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
michael@0 77 applyUserTransform(&canvas);
michael@0 78
michael@0 79 int layer = 0;
michael@0 80 SkColor prev = bitmap.getColor(0,0);
michael@0 81 for (int i = 0; i < index; i++) {
michael@0 82 if (fCommandVector[i]->isVisible()) {
michael@0 83 fCommandVector[i]->execute(&canvas);
michael@0 84 }
michael@0 85 if (prev != bitmap.getColor(0,0)) {
michael@0 86 layer = i;
michael@0 87 }
michael@0 88 prev = bitmap.getColor(0,0);
michael@0 89 }
michael@0 90 return layer;
michael@0 91 }
michael@0 92
michael@0 93 static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) {
michael@0 94 // This table encodes the color progression of the overdraw visualization
michael@0 95 static const SkPMColor gTable[] = {
michael@0 96 SkPackARGB32(0x00, 0x00, 0x00, 0x00),
michael@0 97 SkPackARGB32(0xFF, 128, 158, 255),
michael@0 98 SkPackARGB32(0xFF, 170, 185, 212),
michael@0 99 SkPackARGB32(0xFF, 213, 195, 170),
michael@0 100 SkPackARGB32(0xFF, 255, 192, 127),
michael@0 101 SkPackARGB32(0xFF, 255, 185, 85),
michael@0 102 SkPackARGB32(0xFF, 255, 165, 42),
michael@0 103 SkPackARGB32(0xFF, 255, 135, 0),
michael@0 104 SkPackARGB32(0xFF, 255, 95, 0),
michael@0 105 SkPackARGB32(0xFF, 255, 50, 0),
michael@0 106 SkPackARGB32(0xFF, 255, 0, 0)
michael@0 107 };
michael@0 108
michael@0 109 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) {
michael@0 110 if (gTable[i] == dst) {
michael@0 111 return gTable[i+1];
michael@0 112 }
michael@0 113 }
michael@0 114
michael@0 115 return gTable[SK_ARRAY_COUNT(gTable)-1];
michael@0 116 }
michael@0 117
michael@0 118 // The OverdrawFilter modifies every paint to use an SkProcXfermode which
michael@0 119 // in turn invokes OverdrawXferModeProc
michael@0 120 class SkOverdrawFilter : public SkDrawFilter {
michael@0 121 public:
michael@0 122 SkOverdrawFilter() {
michael@0 123 fXferMode = SkProcXfermode::Create(OverdrawXferModeProc);
michael@0 124 }
michael@0 125
michael@0 126 virtual ~SkOverdrawFilter() {
michael@0 127 delete fXferMode;
michael@0 128 }
michael@0 129
michael@0 130 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
michael@0 131 p->setXfermode(fXferMode);
michael@0 132 return true;
michael@0 133 }
michael@0 134
michael@0 135 protected:
michael@0 136 SkXfermode* fXferMode;
michael@0 137
michael@0 138 private:
michael@0 139 typedef SkDrawFilter INHERITED;
michael@0 140 };
michael@0 141
michael@0 142 // SkTexOverrideFilter modifies every paint to use the specified
michael@0 143 // texture filtering mode
michael@0 144 class SkTexOverrideFilter : public SkDrawFilter {
michael@0 145 public:
michael@0 146 SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) {
michael@0 147 }
michael@0 148
michael@0 149 void setFilterLevel(SkPaint::FilterLevel filterLevel) {
michael@0 150 fFilterLevel = filterLevel;
michael@0 151 }
michael@0 152
michael@0 153 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
michael@0 154 p->setFilterLevel(fFilterLevel);
michael@0 155 return true;
michael@0 156 }
michael@0 157
michael@0 158 protected:
michael@0 159 SkPaint::FilterLevel fFilterLevel;
michael@0 160
michael@0 161 private:
michael@0 162 typedef SkDrawFilter INHERITED;
michael@0 163 };
michael@0 164
michael@0 165 class SkDebugClipVisitor : public SkCanvas::ClipVisitor {
michael@0 166 public:
michael@0 167 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
michael@0 168
michael@0 169 virtual void clipRect(const SkRect& r, SkRegion::Op, bool doAA) SK_OVERRIDE {
michael@0 170 SkPaint p;
michael@0 171 p.setColor(SK_ColorRED);
michael@0 172 p.setStyle(SkPaint::kStroke_Style);
michael@0 173 p.setAntiAlias(doAA);
michael@0 174 fCanvas->drawRect(r, p);
michael@0 175 }
michael@0 176 virtual void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) SK_OVERRIDE {
michael@0 177 SkPaint p;
michael@0 178 p.setColor(SK_ColorGREEN);
michael@0 179 p.setStyle(SkPaint::kStroke_Style);
michael@0 180 p.setAntiAlias(doAA);
michael@0 181 fCanvas->drawRRect(rr, p);
michael@0 182 }
michael@0 183 virtual void clipPath(const SkPath& path, SkRegion::Op, bool doAA) SK_OVERRIDE {
michael@0 184 SkPaint p;
michael@0 185 p.setColor(SK_ColorBLUE);
michael@0 186 p.setStyle(SkPaint::kStroke_Style);
michael@0 187 p.setAntiAlias(doAA);
michael@0 188 fCanvas->drawPath(path, p);
michael@0 189 }
michael@0 190
michael@0 191 protected:
michael@0 192 SkCanvas* fCanvas;
michael@0 193
michael@0 194 private:
michael@0 195 typedef SkCanvas::ClipVisitor INHERITED;
michael@0 196 };
michael@0 197
michael@0 198 // set up the saveLayer commands so that the active ones
michael@0 199 // return true in their 'active' method
michael@0 200 void SkDebugCanvas::markActiveCommands(int index) {
michael@0 201 fActiveLayers.rewind();
michael@0 202 fActiveCulls.rewind();
michael@0 203
michael@0 204 for (int i = 0; i < fCommandVector.count(); ++i) {
michael@0 205 fCommandVector[i]->setActive(false);
michael@0 206 }
michael@0 207
michael@0 208 for (int i = 0; i < index; ++i) {
michael@0 209 SkDrawCommand::Action result = fCommandVector[i]->action();
michael@0 210 if (SkDrawCommand::kPushLayer_Action == result) {
michael@0 211 fActiveLayers.push(fCommandVector[i]);
michael@0 212 } else if (SkDrawCommand::kPopLayer_Action == result) {
michael@0 213 fActiveLayers.pop();
michael@0 214 } else if (SkDrawCommand::kPushCull_Action == result) {
michael@0 215 fActiveCulls.push(fCommandVector[i]);
michael@0 216 } else if (SkDrawCommand::kPopCull_Action == result) {
michael@0 217 fActiveCulls.pop();
michael@0 218 }
michael@0 219 }
michael@0 220
michael@0 221 for (int i = 0; i < fActiveLayers.count(); ++i) {
michael@0 222 fActiveLayers[i]->setActive(true);
michael@0 223 }
michael@0 224
michael@0 225 for (int i = 0; i < fActiveCulls.count(); ++i) {
michael@0 226 fActiveCulls[i]->setActive(true);
michael@0 227 }
michael@0 228 }
michael@0 229
michael@0 230 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
michael@0 231 SkASSERT(!fCommandVector.isEmpty());
michael@0 232 SkASSERT(index < fCommandVector.count());
michael@0 233 int i = 0;
michael@0 234
michael@0 235 // This only works assuming the canvas and device are the same ones that
michael@0 236 // were previously drawn into because they need to preserve all saves
michael@0 237 // and restores.
michael@0 238 // The visibility filter also requires a full re-draw - otherwise we can
michael@0 239 // end up drawing the filter repeatedly.
michael@0 240 if (fIndex < index && !fFilter && !fMegaVizMode) {
michael@0 241 i = fIndex + 1;
michael@0 242 } else {
michael@0 243 for (int j = 0; j < fOutstandingSaveCount; j++) {
michael@0 244 canvas->restore();
michael@0 245 }
michael@0 246 canvas->clear(SK_ColorTRANSPARENT);
michael@0 247 canvas->resetMatrix();
michael@0 248 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
michael@0 249 SkIntToScalar(fHeight));
michael@0 250 canvas->clipRect(rect, SkRegion::kReplace_Op );
michael@0 251 applyUserTransform(canvas);
michael@0 252 fOutstandingSaveCount = 0;
michael@0 253 }
michael@0 254
michael@0 255 // The setting of the draw filter has to go here (rather than in
michael@0 256 // SkRasterWidget) due to the canvas restores this class performs.
michael@0 257 // Since the draw filter is stored in the layer stack if we
michael@0 258 // call setDrawFilter on anything but the root layer odd things happen.
michael@0 259 if (fOverdrawViz) {
michael@0 260 if (NULL == fOverdrawFilter) {
michael@0 261 fOverdrawFilter = new SkOverdrawFilter;
michael@0 262 }
michael@0 263
michael@0 264 if (fOverdrawFilter != canvas->getDrawFilter()) {
michael@0 265 canvas->setDrawFilter(fOverdrawFilter);
michael@0 266 }
michael@0 267 } else if (fOverrideTexFiltering) {
michael@0 268 if (NULL == fTexOverrideFilter) {
michael@0 269 fTexOverrideFilter = new SkTexOverrideFilter;
michael@0 270 }
michael@0 271
michael@0 272 if (fTexOverrideFilter != canvas->getDrawFilter()) {
michael@0 273 canvas->setDrawFilter(fTexOverrideFilter);
michael@0 274 }
michael@0 275 } else {
michael@0 276 canvas->setDrawFilter(NULL);
michael@0 277 }
michael@0 278
michael@0 279 if (fMegaVizMode) {
michael@0 280 this->markActiveCommands(index);
michael@0 281 }
michael@0 282
michael@0 283 for (; i <= index; i++) {
michael@0 284 if (i == index && fFilter) {
michael@0 285 SkPaint p;
michael@0 286 p.setColor(0xAAFFFFFF);
michael@0 287 canvas->save();
michael@0 288 canvas->resetMatrix();
michael@0 289 SkRect mask;
michael@0 290 mask.set(SkIntToScalar(0), SkIntToScalar(0),
michael@0 291 SkIntToScalar(fWidth), SkIntToScalar(fHeight));
michael@0 292 canvas->clipRect(mask, SkRegion::kReplace_Op, false);
michael@0 293 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
michael@0 294 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
michael@0 295 canvas->restore();
michael@0 296 }
michael@0 297
michael@0 298 if (fCommandVector[i]->isVisible()) {
michael@0 299 if (fMegaVizMode && fCommandVector[i]->active()) {
michael@0 300 // "active" commands execute their visualization behaviors:
michael@0 301 // All active saveLayers get replaced with saves so all draws go to the
michael@0 302 // visible canvas.
michael@0 303 // All active culls draw their cull box
michael@0 304 fCommandVector[i]->vizExecute(canvas);
michael@0 305 } else {
michael@0 306 fCommandVector[i]->execute(canvas);
michael@0 307 }
michael@0 308
michael@0 309 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
michael@0 310 }
michael@0 311 }
michael@0 312
michael@0 313 if (fMegaVizMode) {
michael@0 314 SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
michael@0 315 r.outset(SK_Scalar1, SK_Scalar1);
michael@0 316
michael@0 317 canvas->save();
michael@0 318 // nuke the CTM
michael@0 319 canvas->setMatrix(SkMatrix::I());
michael@0 320 // turn off clipping
michael@0 321 canvas->clipRect(r, SkRegion::kReplace_Op);
michael@0 322
michael@0 323 // visualize existing clips
michael@0 324 SkDebugClipVisitor visitor(canvas);
michael@0 325
michael@0 326 canvas->replayClips(&visitor);
michael@0 327
michael@0 328 canvas->restore();
michael@0 329 }
michael@0 330 fMatrix = canvas->getTotalMatrix();
michael@0 331 if (!canvas->getClipDeviceBounds(&fClip)) {
michael@0 332 fClip.setEmpty();
michael@0 333 }
michael@0 334 fIndex = index;
michael@0 335 }
michael@0 336
michael@0 337 void SkDebugCanvas::deleteDrawCommandAt(int index) {
michael@0 338 SkASSERT(index < fCommandVector.count());
michael@0 339 delete fCommandVector[index];
michael@0 340 fCommandVector.remove(index);
michael@0 341 }
michael@0 342
michael@0 343 SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
michael@0 344 SkASSERT(index < fCommandVector.count());
michael@0 345 return fCommandVector[index];
michael@0 346 }
michael@0 347
michael@0 348 void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) {
michael@0 349 SkASSERT(index < fCommandVector.count());
michael@0 350 delete fCommandVector[index];
michael@0 351 fCommandVector[index] = command;
michael@0 352 }
michael@0 353
michael@0 354 SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
michael@0 355 SkASSERT(index < fCommandVector.count());
michael@0 356 return fCommandVector[index]->Info();
michael@0 357 }
michael@0 358
michael@0 359 bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
michael@0 360 SkASSERT(index < fCommandVector.count());
michael@0 361 return fCommandVector[index]->isVisible();
michael@0 362 }
michael@0 363
michael@0 364 const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
michael@0 365 return fCommandVector;
michael@0 366 }
michael@0 367
michael@0 368 SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() {
michael@0 369 return fCommandVector;
michael@0 370 }
michael@0 371
michael@0 372 // TODO(chudy): Free command string memory.
michael@0 373 SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
michael@0 374 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
michael@0 375 if (!fCommandVector.isEmpty()) {
michael@0 376 for (int i = 0; i < fCommandVector.count(); i ++) {
michael@0 377 commandString->push_back() = fCommandVector[i]->toString();
michael@0 378 }
michael@0 379 }
michael@0 380 return commandString;
michael@0 381 }
michael@0 382
michael@0 383 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) {
michael@0 384 if (NULL == fTexOverrideFilter) {
michael@0 385 fTexOverrideFilter = new SkTexOverrideFilter;
michael@0 386 }
michael@0 387
michael@0 388 fOverrideTexFiltering = overrideTexFiltering;
michael@0 389 fTexOverrideFilter->setFilterLevel(level);
michael@0 390 }
michael@0 391
michael@0 392 void SkDebugCanvas::clear(SkColor color) {
michael@0 393 addDrawCommand(new SkClearCommand(color));
michael@0 394 }
michael@0 395
michael@0 396 void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
michael@0 397 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
michael@0 398 }
michael@0 399
michael@0 400 void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
michael@0 401 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
michael@0 402 }
michael@0 403
michael@0 404 void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
michael@0 405 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
michael@0 406 }
michael@0 407
michael@0 408 void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) {
michael@0 409 this->addDrawCommand(new SkClipRegionCommand(region, op));
michael@0 410 }
michael@0 411
michael@0 412 void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
michael@0 413 addDrawCommand(new SkConcatCommand(matrix));
michael@0 414 this->INHERITED::didConcat(matrix);
michael@0 415 }
michael@0 416
michael@0 417 void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
michael@0 418 SkScalar top, const SkPaint* paint = NULL) {
michael@0 419 addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
michael@0 420 }
michael@0 421
michael@0 422 void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
michael@0 423 const SkRect* src, const SkRect& dst,
michael@0 424 const SkPaint* paint,
michael@0 425 SkCanvas::DrawBitmapRectFlags flags) {
michael@0 426 addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, flags));
michael@0 427 }
michael@0 428
michael@0 429 void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
michael@0 430 const SkMatrix& matrix, const SkPaint* paint) {
michael@0 431 addDrawCommand(new SkDrawBitmapMatrixCommand(bitmap, matrix, paint));
michael@0 432 }
michael@0 433
michael@0 434 void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
michael@0 435 const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
michael@0 436 addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
michael@0 437 }
michael@0 438
michael@0 439 void SkDebugCanvas::drawData(const void* data, size_t length) {
michael@0 440 addDrawCommand(new SkDrawDataCommand(data, length));
michael@0 441 }
michael@0 442
michael@0 443 void SkDebugCanvas::beginCommentGroup(const char* description) {
michael@0 444 addDrawCommand(new SkBeginCommentGroupCommand(description));
michael@0 445 }
michael@0 446
michael@0 447 void SkDebugCanvas::addComment(const char* kywd, const char* value) {
michael@0 448 addDrawCommand(new SkCommentCommand(kywd, value));
michael@0 449 }
michael@0 450
michael@0 451 void SkDebugCanvas::endCommentGroup() {
michael@0 452 addDrawCommand(new SkEndCommentGroupCommand());
michael@0 453 }
michael@0 454
michael@0 455 void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
michael@0 456 addDrawCommand(new SkDrawOvalCommand(oval, paint));
michael@0 457 }
michael@0 458
michael@0 459 void SkDebugCanvas::drawPaint(const SkPaint& paint) {
michael@0 460 addDrawCommand(new SkDrawPaintCommand(paint));
michael@0 461 }
michael@0 462
michael@0 463 void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
michael@0 464 addDrawCommand(new SkDrawPathCommand(path, paint));
michael@0 465 }
michael@0 466
michael@0 467 void SkDebugCanvas::drawPicture(SkPicture& picture) {
michael@0 468 addDrawCommand(new SkDrawPictureCommand(picture));
michael@0 469 }
michael@0 470
michael@0 471 void SkDebugCanvas::drawPoints(PointMode mode, size_t count,
michael@0 472 const SkPoint pts[], const SkPaint& paint) {
michael@0 473 addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
michael@0 474 }
michael@0 475
michael@0 476 void SkDebugCanvas::drawPosText(const void* text, size_t byteLength,
michael@0 477 const SkPoint pos[], const SkPaint& paint) {
michael@0 478 addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
michael@0 479 }
michael@0 480
michael@0 481 void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength,
michael@0 482 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
michael@0 483 addDrawCommand(
michael@0 484 new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
michael@0 485 }
michael@0 486
michael@0 487 void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
michael@0 488 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
michael@0 489 addDrawCommand(new SkDrawRectCommand(rect, paint));
michael@0 490 }
michael@0 491
michael@0 492 void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
michael@0 493 addDrawCommand(new SkDrawRRectCommand(rrect, paint));
michael@0 494 }
michael@0 495
michael@0 496 void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
michael@0 497 const SkPaint& paint) {
michael@0 498 this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
michael@0 499 }
michael@0 500
michael@0 501 void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
michael@0 502 const SkPaint* paint = NULL) {
michael@0 503 addDrawCommand(new SkDrawSpriteCommand(bitmap, left, top, paint));
michael@0 504 }
michael@0 505
michael@0 506 void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
michael@0 507 SkScalar y, const SkPaint& paint) {
michael@0 508 addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
michael@0 509 }
michael@0 510
michael@0 511 void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength,
michael@0 512 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
michael@0 513 addDrawCommand(
michael@0 514 new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
michael@0 515 }
michael@0 516
michael@0 517 void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
michael@0 518 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
michael@0 519 SkXfermode*, const uint16_t indices[], int indexCount,
michael@0 520 const SkPaint& paint) {
michael@0 521 addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices,
michael@0 522 texs, colors, NULL, indices, indexCount, paint));
michael@0 523 }
michael@0 524
michael@0 525 void SkDebugCanvas::onPushCull(const SkRect& cullRect) {
michael@0 526 this->addDrawCommand(new SkPushCullCommand(cullRect));
michael@0 527 }
michael@0 528
michael@0 529 void SkDebugCanvas::onPopCull() {
michael@0 530 this->addDrawCommand(new SkPopCullCommand());
michael@0 531 }
michael@0 532
michael@0 533 void SkDebugCanvas::willRestore() {
michael@0 534 this->addDrawCommand(new SkRestoreCommand());
michael@0 535 this->INHERITED::willRestore();
michael@0 536 }
michael@0 537
michael@0 538 void SkDebugCanvas::didRotate(SkScalar degrees) {
michael@0 539 addDrawCommand(new SkRotateCommand(degrees));
michael@0 540 this->INHERITED::didRotate(degrees);
michael@0 541 }
michael@0 542
michael@0 543 void SkDebugCanvas::willSave(SaveFlags flags) {
michael@0 544 this->addDrawCommand(new SkSaveCommand(flags));
michael@0 545 this->INHERITED::willSave(flags);
michael@0 546 }
michael@0 547
michael@0 548 SkCanvas::SaveLayerStrategy SkDebugCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
michael@0 549 SaveFlags flags) {
michael@0 550 this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
michael@0 551 this->INHERITED::willSaveLayer(bounds, paint, flags);
michael@0 552 // No need for a full layer.
michael@0 553 return kNoLayer_SaveLayerStrategy;
michael@0 554 }
michael@0 555
michael@0 556 void SkDebugCanvas::didScale(SkScalar sx, SkScalar sy) {
michael@0 557 addDrawCommand(new SkScaleCommand(sx, sy));
michael@0 558 this->INHERITED::didScale(sx, sy);
michael@0 559 }
michael@0 560
michael@0 561 void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
michael@0 562 addDrawCommand(new SkSetMatrixCommand(matrix));
michael@0 563 this->INHERITED::didSetMatrix(matrix);
michael@0 564 }
michael@0 565
michael@0 566 void SkDebugCanvas::didSkew(SkScalar sx, SkScalar sy) {
michael@0 567 addDrawCommand(new SkSkewCommand(sx, sy));
michael@0 568 this->INHERITED::didSkew(sx, sy);
michael@0 569 }
michael@0 570
michael@0 571 void SkDebugCanvas::didTranslate(SkScalar dx, SkScalar dy) {
michael@0 572 addDrawCommand(new SkTranslateCommand(dx, dy));
michael@0 573 this->INHERITED::didTranslate(dx, dy);
michael@0 574 }
michael@0 575
michael@0 576 void SkDebugCanvas::toggleCommand(int index, bool toggle) {
michael@0 577 SkASSERT(index < fCommandVector.count());
michael@0 578 fCommandVector[index]->setVisible(toggle);
michael@0 579 }

mercurial