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" |
11 #include "SkDrawCommand.h" | 11 #include "SkDrawCommand.h" |
12 #include "SkDevice.h" | 12 #include "SkDevice.h" |
13 #include "SkPaintFilterCanvas.h" | 13 #include "SkPaintFilterCanvas.h" |
14 #include "SkOverdrawMode.h" | 14 #include "SkOverdrawMode.h" |
15 | 15 |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "GrAuditTrail.h" | 17 #include "GrAuditTrail.h" |
18 #include "GrContext.h" | 18 #include "GrContext.h" |
19 #include "GrRenderTarget.h" | 19 #include "GrRenderTarget.h" |
20 #include "SkGpuDevice.h" | 20 #include "SkGpuDevice.h" |
21 #endif | 21 #endif |
22 | 22 |
23 #define SKDEBUGCANVAS_VERSION 1 | 23 #define SKDEBUGCANVAS_VERSION 1 |
24 #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" | 24 #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" |
25 #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" | 25 #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" |
26 #define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail" | |
26 | 27 |
27 class DebugPaintFilterCanvas : public SkPaintFilterCanvas { | 28 class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
28 public: | 29 public: |
29 DebugPaintFilterCanvas(int width, | 30 DebugPaintFilterCanvas(int width, |
30 int height, | 31 int height, |
31 bool overdrawViz, | 32 bool overdrawViz, |
32 bool overrideFilterQuality, | 33 bool overrideFilterQuality, |
33 SkFilterQuality quality) | 34 SkFilterQuality quality) |
34 : INHERITED(width, height) | 35 : INHERITED(width, height) |
35 , fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Create() : nullptr) | 36 , fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Create() : nullptr) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 325 |
325 canvas->restoreToCount(saveCount); | 326 canvas->restoreToCount(saveCount); |
326 | 327 |
327 if (fPaintFilterCanvas) { | 328 if (fPaintFilterCanvas) { |
328 fPaintFilterCanvas->removeAll(); | 329 fPaintFilterCanvas->removeAll(); |
329 } | 330 } |
330 | 331 |
331 #if SK_SUPPORT_GPU | 332 #if SK_SUPPORT_GPU |
332 // draw any batches if required and issue a full reset onto GrAuditTrail | 333 // draw any batches if required and issue a full reset onto GrAuditTrail |
333 if (at) { | 334 if (at) { |
335 // just in case there is global reordering, we flush the canvas before q uerying | |
336 // GrAuditTrail | |
337 canvas->flush(); | |
338 | |
334 // we pick three colorblind-safe colors, 75% alpha | 339 // we pick three colorblind-safe colors, 75% alpha |
335 static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9 A); | 340 static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9 A); |
336 static const SkColor kOpBatchBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0 x1C); | 341 static const SkColor kOpBatchBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0 x1C); |
337 static const SkColor kOtherBatchBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F , 0x00); | 342 static const SkColor kOtherBatchBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F , 0x00); |
338 | 343 |
339 // get the render target of the top device so we can ignore batches draw n offscreen | 344 // get the render target of the top device so we can ignore batches draw n offscreen |
340 SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_t esting(); | 345 SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_t esting(); |
341 SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd); | 346 SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd); |
342 uint32_t rtID = gbd->accessRenderTarget()->getUniqueID(); | 347 uint32_t rtID = gbd->accessRenderTarget()->getUniqueID(); |
343 | 348 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 | 411 |
407 const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { | 412 const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
408 return fCommandVector; | 413 return fCommandVector; |
409 } | 414 } |
410 | 415 |
411 SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { | 416 SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
412 return fCommandVector; | 417 return fCommandVector; |
413 } | 418 } |
414 | 419 |
415 Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanva s* canvas) { | 420 Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanva s* canvas) { |
421 #if SK_SUPPORT_GPU | |
422 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); | |
423 GrAuditTrail* at = nullptr; | |
424 if (rt) { | |
425 GrContext* ctx = rt->getContext(); | |
426 if(ctx) { | |
427 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 canvas->flush(); | |
438 } | |
439 } | |
440 #endif | |
441 | |
442 // now collect json | |
416 Json::Value result = Json::Value(Json::objectValue); | 443 Json::Value result = Json::Value(Json::objectValue); |
417 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION) ; | 444 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION) ; |
418 Json::Value commands = Json::Value(Json::arrayValue); | 445 Json::Value commands = Json::Value(Json::arrayValue); |
419 for (int i = 0; i < this->getSize() && i <= n; i++) { | 446 for (int i = 0; i < this->getSize() && i <= n; i++) { |
420 commands[i] = this->getDrawCommandAt(i)->drawToAndCollectJSON(canvas, ur lDataManager, | 447 commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); |
421 i); | 448 #if SK_SUPPORT_GPU |
449 if (at) { | |
450 // TODO if this is inefficient we could add a method to GrAuditTrail which takes | |
451 // a Json::Value and is only compiled in this file | |
452 Json::Value parsedFromString; | |
453 Json::Reader reader; | |
454 SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson(i).c_s tr(), | |
ethannicholas
2016/03/04 18:24:07
Better to use SkAssertResult and do this in one st
| |
455 parsedFromString) ; | |
456 SkASSERT(parsingSuccessful); | |
457 | |
458 commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString; | |
459 } | |
460 #endif | |
422 } | 461 } |
462 #if SK_SUPPORT_GPU | |
463 if (at) { | |
464 at->fullReset(); | |
465 } | |
466 #endif | |
423 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; | 467 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; |
424 return result; | 468 return result; |
425 } | 469 } |
426 | 470 |
427 void SkDebugCanvas::updatePaintFilterCanvas() { | 471 void SkDebugCanvas::updatePaintFilterCanvas() { |
428 if (!fOverdrawViz && !fOverrideFilterQuality) { | 472 if (!fOverdrawViz && !fOverrideFilterQuality) { |
429 fPaintFilterCanvas.reset(nullptr); | 473 fPaintFilterCanvas.reset(nullptr); |
430 return; | 474 return; |
431 } | 475 } |
432 | 476 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 } | 770 } |
727 | 771 |
728 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { | 772 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { |
729 if (fCalledAddStackData) { | 773 if (fCalledAddStackData) { |
730 fClipStackData.appendf("<br>"); | 774 fClipStackData.appendf("<br>"); |
731 addPathData(devPath, "pathOut"); | 775 addPathData(devPath, "pathOut"); |
732 return true; | 776 return true; |
733 } | 777 } |
734 return false; | 778 return false; |
735 } | 779 } |
OLD | NEW |