| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCanvasPriv.h" | 8 #include "SkCanvasPriv.h" |
| 9 #include "SkClipStack.h" | 9 #include "SkClipStack.h" |
| 10 #include "SkDebugCanvas.h" | 10 #include "SkDebugCanvas.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 fPaintFilterCanvas->addCanvas(canvas); | 219 fPaintFilterCanvas->addCanvas(canvas); |
| 220 canvas = fPaintFilterCanvas.get(); | 220 canvas = fPaintFilterCanvas.get(); |
| 221 | 221 |
| 222 } | 222 } |
| 223 | 223 |
| 224 if (fMegaVizMode) { | 224 if (fMegaVizMode) { |
| 225 this->markActiveCommands(index); | 225 this->markActiveCommands(index); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // If we have a GPU backend we can also visualize the batching information | 228 // If we have a GPU backend we can also visualize the batching information |
| 229 #if SK_SUPPORT_GPU | |
| 230 GrAuditTrail* at = nullptr; | 229 GrAuditTrail* at = nullptr; |
| 231 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); | 230 if (fDrawGpuBatchBounds || m != -1) { |
| 232 if (rt && (fDrawGpuBatchBounds || m != -1)) { | 231 at = this->getAuditTrail(canvas); |
| 233 GrContext* ctx = rt->getContext(); | |
| 234 if (ctx) { | |
| 235 at = ctx->getAuditTrail(); | |
| 236 } | |
| 237 } | 232 } |
| 238 #endif | |
| 239 | 233 |
| 240 for (int i = 0; i <= index; i++) { | 234 for (int i = 0; i <= index; i++) { |
| 241 if (i == index && fFilter) { | 235 if (i == index && fFilter) { |
| 242 canvas->clear(0xAAFFFFFF); | 236 canvas->clear(0xAAFFFFFF); |
| 243 } | 237 } |
| 244 | 238 |
| 245 #if SK_SUPPORT_GPU | 239 #if SK_SUPPORT_GPU |
| 246 GrAuditTrail::AutoCollectBatches* acb = nullptr; | 240 GrAuditTrail::AutoCollectBatches* acb = nullptr; |
| 247 if (at) { | 241 if (at) { |
| 248 acb = new GrAuditTrail::AutoCollectBatches(at, i); | 242 acb = new GrAuditTrail::AutoCollectBatches(at, i); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 for (int j = 0; j < childrenBounds[i].fBatches.count(); j++) { | 362 for (int j = 0; j < childrenBounds[i].fBatches.count(); j++) { |
| 369 const GrAuditTrail::BatchInfo::Batch& batch = childrenBounds[i].
fBatches[j]; | 363 const GrAuditTrail::BatchInfo::Batch& batch = childrenBounds[i].
fBatches[j]; |
| 370 if (batch.fClientID != index) { | 364 if (batch.fClientID != index) { |
| 371 paint.setColor(kOtherBatchBounds); | 365 paint.setColor(kOtherBatchBounds); |
| 372 } else { | 366 } else { |
| 373 paint.setColor(kOpBatchBounds); | 367 paint.setColor(kOpBatchBounds); |
| 374 } | 368 } |
| 375 canvas->drawRect(batch.fBounds, paint); | 369 canvas->drawRect(batch.fBounds, paint); |
| 376 } | 370 } |
| 377 } | 371 } |
| 378 | |
| 379 at->fullReset(); | |
| 380 } | 372 } |
| 381 | |
| 382 #endif | 373 #endif |
| 374 this->cleanupAuditTrail(canvas); |
| 383 } | 375 } |
| 384 | 376 |
| 385 void SkDebugCanvas::deleteDrawCommandAt(int index) { | 377 void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 386 SkASSERT(index < fCommandVector.count()); | 378 SkASSERT(index < fCommandVector.count()); |
| 387 delete fCommandVector[index]; | 379 delete fCommandVector[index]; |
| 388 fCommandVector.remove(index); | 380 fCommandVector.remove(index); |
| 389 } | 381 } |
| 390 | 382 |
| 391 SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { | 383 SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
| 392 SkASSERT(index < fCommandVector.count()); | 384 SkASSERT(index < fCommandVector.count()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 410 } | 402 } |
| 411 | 403 |
| 412 const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { | 404 const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
| 413 return fCommandVector; | 405 return fCommandVector; |
| 414 } | 406 } |
| 415 | 407 |
| 416 SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { | 408 SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
| 417 return fCommandVector; | 409 return fCommandVector; |
| 418 } | 410 } |
| 419 | 411 |
| 420 Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanva
s* canvas) { | 412 GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) { |
| 413 GrAuditTrail* at = nullptr; |
| 421 #if SK_SUPPORT_GPU | 414 #if SK_SUPPORT_GPU |
| 422 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); | 415 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); |
| 423 GrAuditTrail* at = nullptr; | |
| 424 if (rt) { | 416 if (rt) { |
| 425 GrContext* ctx = rt->getContext(); | 417 GrContext* ctx = rt->getContext(); |
| 426 if(ctx) { | 418 if (ctx) { |
| 427 at = ctx->getAuditTrail(); | 419 at = ctx->getAuditTrail(); |
| 428 | |
| 429 // loop over all of the commands and draw them, this is to collect r
eordering | |
| 430 // information | |
| 431 for (int i = 0; i < this->getSize() && i <= n; i++) { | |
| 432 GrAuditTrail::AutoCollectBatches enable(at, i); | |
| 433 fCommandVector[i]->execute(canvas); | |
| 434 } | |
| 435 | |
| 436 // in case there is some kind of global reordering | |
| 437 { | |
| 438 GrAuditTrail::AutoEnable ae(at); | |
| 439 canvas->flush(); | |
| 440 } | |
| 441 } | 420 } |
| 442 } | 421 } |
| 443 #endif | 422 #endif |
| 423 return at; |
| 424 } |
| 425 |
| 426 void SkDebugCanvas::drawAndCollectBatches(int n, SkCanvas* canvas) { |
| 427 GrAuditTrail* at = this->getAuditTrail(canvas); |
| 428 if (at) { |
| 429 #if SK_SUPPORT_GPU |
| 430 // loop over all of the commands and draw them, this is to collect reord
ering |
| 431 // information |
| 432 for (int i = 0; i < this->getSize() && i <= n; i++) { |
| 433 GrAuditTrail::AutoCollectBatches enable(at, i); |
| 434 fCommandVector[i]->execute(canvas); |
| 435 } |
| 436 |
| 437 // in case there is some kind of global reordering |
| 438 { |
| 439 GrAuditTrail::AutoEnable ae(at); |
| 440 canvas->flush(); |
| 441 } |
| 442 #endif |
| 443 } |
| 444 } |
| 445 |
| 446 void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) { |
| 447 GrAuditTrail* at = this->getAuditTrail(canvas); |
| 448 if (at) { |
| 449 #if SK_SUPPORT_GPU |
| 450 GrAuditTrail::AutoEnable ae(at); |
| 451 at->fullReset(); |
| 452 #endif |
| 453 } |
| 454 } |
| 455 |
| 456 Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanva
s* canvas) { |
| 457 this->drawAndCollectBatches(n, canvas); |
| 444 | 458 |
| 445 // now collect json | 459 // now collect json |
| 460 GrAuditTrail* at = this->getAuditTrail(canvas); |
| 446 Json::Value result = Json::Value(Json::objectValue); | 461 Json::Value result = Json::Value(Json::objectValue); |
| 447 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION)
; | 462 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION)
; |
| 448 Json::Value commands = Json::Value(Json::arrayValue); | 463 Json::Value commands = Json::Value(Json::arrayValue); |
| 449 for (int i = 0; i < this->getSize() && i <= n; i++) { | 464 for (int i = 0; i < this->getSize() && i <= n; i++) { |
| 450 commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); | 465 commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); |
| 451 #if SK_SUPPORT_GPU | 466 #if SK_SUPPORT_GPU |
| 452 if (at) { | 467 if (at) { |
| 453 // TODO if this is inefficient we could add a method to GrAuditTrail
which takes | 468 // TODO if this is inefficient we could add a method to GrAuditTrail
which takes |
| 454 // a Json::Value and is only compiled in this file | 469 // a Json::Value and is only compiled in this file |
| 455 Json::Value parsedFromString; | 470 Json::Value parsedFromString; |
| 456 Json::Reader reader; | 471 Json::Reader reader; |
| 457 SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString)
); | 472 SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString)
); |
| 458 | 473 |
| 459 commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString; | 474 commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString; |
| 460 } | 475 } |
| 461 #endif | 476 #endif |
| 462 } | 477 } |
| 463 #if SK_SUPPORT_GPU | 478 this->cleanupAuditTrail(canvas); |
| 464 if (at) { | |
| 465 GrAuditTrail::AutoEnable ae(at); | |
| 466 at->fullReset(); | |
| 467 } | |
| 468 #endif | |
| 469 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; | 479 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; |
| 470 return result; | 480 return result; |
| 471 } | 481 } |
| 472 | 482 |
| 483 Json::Value SkDebugCanvas::toJSONBatchList(int n, SkCanvas* canvas) { |
| 484 this->drawAndCollectBatches(n, canvas); |
| 485 |
| 486 Json::Value parsedFromString; |
| 487 GrAuditTrail* at = this->getAuditTrail(canvas); |
| 488 #if SK_SUPPORT_GPU |
| 489 if (at) { |
| 490 GrAuditTrail::AutoManageBatchList enable(at); |
| 491 Json::Reader reader; |
| 492 SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString)); |
| 493 } |
| 494 #endif |
| 495 this->cleanupAuditTrail(canvas); |
| 496 return parsedFromString; |
| 497 } |
| 498 |
| 473 void SkDebugCanvas::updatePaintFilterCanvas() { | 499 void SkDebugCanvas::updatePaintFilterCanvas() { |
| 474 if (!fOverdrawViz && !fOverrideFilterQuality) { | 500 if (!fOverdrawViz && !fOverrideFilterQuality) { |
| 475 fPaintFilterCanvas.reset(nullptr); | 501 fPaintFilterCanvas.reset(nullptr); |
| 476 return; | 502 return; |
| 477 } | 503 } |
| 478 | 504 |
| 479 const SkImageInfo info = this->imageInfo(); | 505 const SkImageInfo info = this->imageInfo(); |
| 480 fPaintFilterCanvas.reset(new DebugPaintFilterCanvas(info.width(), info.heigh
t(), fOverdrawViz, | 506 fPaintFilterCanvas.reset(new DebugPaintFilterCanvas(info.width(), info.heigh
t(), fOverdrawViz, |
| 481 fOverrideFilterQuality,
fFilterQuality)); | 507 fOverrideFilterQuality,
fFilterQuality)); |
| 482 } | 508 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 798 } |
| 773 | 799 |
| 774 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { | 800 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { |
| 775 if (fCalledAddStackData) { | 801 if (fCalledAddStackData) { |
| 776 fClipStackData.appendf("<br>"); | 802 fClipStackData.appendf("<br>"); |
| 777 addPathData(devPath, "pathOut"); | 803 addPathData(devPath, "pathOut"); |
| 778 return true; | 804 return true; |
| 779 } | 805 } |
| 780 return false; | 806 return false; |
| 781 } | 807 } |
| OLD | NEW |