diff --git a/include/gpu/GrConfig.h b/include/gpu/GrConfig.h index 26667b1c7e..04c3857d09 100644 --- a/include/gpu/GrConfig.h +++ b/include/gpu/GrConfig.h @@ -185,4 +185,11 @@ typedef unsigned __int64 uint64_t; #endif #endif +/** + * Enable batch debugging output as json + * TODO make this runtime configurable + */ +#if !defined(GR_BATCH_DEBUGGING_OUTPUT) + #define GR_BATCH_DEBUGGING_OUTPUT 0 +#endif #endif diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 54db1953d5..de7644465a 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -359,7 +359,7 @@ public: /** Get pointer to atlas texture for given mask format */ GrTexture* getFontAtlasTexture(GrMaskFormat format); - SkString dumpAuditTrailToJson() const { return fAuditTrail.toJson(); } + GrAuditTrail* getAuditTrail() { return &fAuditTrail; } private: GrGpu* fGpu; diff --git a/include/private/GrAuditTrail.h b/include/private/GrAuditTrail.h index 02b971ef44..bcd85e221c 100644 --- a/include/private/GrAuditTrail.h +++ b/include/private/GrAuditTrail.h @@ -8,6 +8,7 @@ #ifndef GrAuditTrail_DEFINED #define GrAuditTrail_DEFINED +#include "GrConfig.h" #include "SkString.h" #include "SkTArray.h" @@ -18,12 +19,13 @@ class GrAuditTrail { public: void addOp(SkString name) { + SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.push_back().fName = name; } SkString toJson() const; - void reset() { fOps.reset(); } + void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); } private: struct Op { @@ -34,4 +36,16 @@ private: SkTArray fOps; }; +#define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ + if (GR_BATCH_DEBUGGING_OUTPUT) { \ + invoke(__VA_ARGS__); \ + } + + +#define GR_AUDIT_TRAIL_ADDOP(audit_trail, opname) \ + GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addOp, opname); + +#define GR_AUDIT_TRAIL_RESET(audit_trail) \ + GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); + #endif diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp index 3c29d5647d..5a62a35794 100644 --- a/src/gpu/GrAuditTrail.cpp +++ b/src/gpu/GrAuditTrail.cpp @@ -10,7 +10,7 @@ SkString GrAuditTrail::toJson() const { SkString json; json.append("{\n"); - json.append("Ops: [\n"); + json.append("\"Ops\": [\n"); for (int i = 0; i < fOps.count(); i++) { json.append(fOps[i].toJson()); if (i < fOps.count() - 1) { @@ -25,7 +25,7 @@ SkString GrAuditTrail::toJson() const { SkString GrAuditTrail::Op::toJson() const { SkString json; json.append("{\n"); - json.appendf("%s\n", fName.c_str()); + json.appendf("\"Name\": \"%s\"\n", fName.c_str()); json.append("}\n"); return json; } diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h index 33d7f82ccb..4cdcace6ff 100644 --- a/src/gpu/GrTracing.h +++ b/src/gpu/GrTracing.h @@ -86,16 +86,18 @@ private: GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(target); \ SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \ -#define GR_CREATE_TRACE_MARKER_CONTEXT(name, context) \ +#define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context) \ /* Chromium tracing */ \ static int SK_MACRO_APPEND_LINE(name_counter) = 0; \ bool SK_MACRO_APPEND_LINE(gpuTracingEnabled); \ TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), \ &SK_MACRO_APPEND_LINE(gpuTracingEnabled)); \ if (SK_MACRO_APPEND_LINE(gpuTracingEnabled)) { \ - INTERNAL_GR_CREATE_TRACE_MARKER_SCOPED_C(name, SK_MACRO_APPEND_LINE(name_counter), context)\ + INTERNAL_GR_CREATE_TRACE_MARKER_SCOPED_C(classname "::" op, \ + SK_MACRO_APPEND_LINE(name_counter), context) \ } \ - INTERNAL_TRACE_EVENT_ADD_SCOPED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), name, \ + GR_AUDIT_TRAIL_ADDOP(context->getAuditTrail(), SkString(op)); \ + INTERNAL_TRACE_EVENT_ADD_SCOPED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), classname "::" op, \ "id", SK_MACRO_APPEND_LINE(name_counter)); #define INTERNAL_GR_CREATE_TRACE_MARKER_SCOPED_C(name, name_counter, context) \ diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index cd678af880..7c77dedecb 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -308,7 +308,7 @@ GrRenderTarget* SkGpuDevice::accessRenderTarget() { void SkGpuDevice::clearAll() { GrColor color = 0; - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); fDrawContext->clear(&rect, color, true); fNeedClear = false; @@ -355,7 +355,7 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { CHECK_SHOULD_DRAW(draw); - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); GrPaint grPaint; if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { @@ -446,7 +446,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, /////////////////////////////////////////////////////////////////////////////// void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRect", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext); CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); @@ -492,7 +492,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); @@ -555,7 +555,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDRRect", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); @@ -587,7 +587,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, ///////////////////////////////////////////////////////////////////////////// void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawOval", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext); CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); @@ -651,7 +651,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fClip, origSrcPath, paint, @@ -1287,7 +1287,7 @@ void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, int x, int y, const SkPaint& paint) { // clear of the source device must occur before CHECK_SHOULD_DRAW - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); SkGpuDevice* dev = static_cast(device); // TODO: If the source device covers the whole of this device, we could @@ -1452,7 +1452,7 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* producer, const SkIRect& center, const SkRect& dst, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawProducerNine", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext); CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw); @@ -1533,7 +1533,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, const uint16_t indices[], int indexCount, const SkPaint& paint) { CHECK_SHOULD_DRAW(draw); - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext); // If both textures and vertex-colors are nullptr, strokes hairlines with the paint's color. if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { @@ -1665,7 +1665,7 @@ void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS } CHECK_SHOULD_DRAW(draw); - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext); SkPaint p(paint); p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode))->unref(); @@ -1692,7 +1692,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { CHECK_SHOULD_DRAW(draw); - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext); GrPaint grPaint; if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { @@ -1708,7 +1708,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, const SkScalar pos[], int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPosText", fContext); CHECK_SHOULD_DRAW(draw); GrPaint grPaint; @@ -1725,7 +1725,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint, SkDrawFilter* drawFilter) { - GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawTextBlob", fContext); CHECK_SHOULD_DRAW(draw); SkDEBUGCODE(this->validate();) @@ -1743,6 +1743,12 @@ bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { void SkGpuDevice::flush() { DO_DEFERRED_CLEAR(); fRenderTarget->prepareForExternalIO(); + + // Clear batch debugging output + if (GR_BATCH_DEBUGGING_OUTPUT) { + SkDebugf("%s\n", fContext->getAuditTrail()->toJson().c_str()); + GR_AUDIT_TRAIL_RESET(fContext->getAuditTrail()); + } } ///////////////////////////////////////////////////////////////////////////////