From bbcb38df4f7477aa0a38da00a0757586a0125954 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Thu, 19 Jun 2014 10:19:29 -0700 Subject: [PATCH] Allow gpu debug markers to be placed by using a GrContext If a marker is placed using a GrContext, it will add a marker to both the drawBuffer and gpu targets of that context. BUG=skia: R=bsalomon@google.com Author: egdaniel@google.com Review URL: https://codereview.chromium.org/340893002 --- include/gpu/GrContext.h | 4 ++++ src/gpu/GrContext.cpp | 15 +++++++++++++++ src/gpu/GrTracing.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/gpu/SkGpuDevice.cpp | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index acf146f..608ec50 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -26,6 +26,7 @@ class GrDrawTarget; class GrEffect; class GrFontCache; class GrGpu; +class GrGpuTraceMarker; class GrIndexBuffer; class GrIndexBufferAllocPool; class GrInOrderDrawBuffer; @@ -925,6 +926,9 @@ public: void enableGpuTracing() { fGpuTracingEnabled = true; } void disableGpuTracing() { fGpuTracingEnabled = false; } + void addGpuTraceMarker(const GrGpuTraceMarker* marker); + void removeGpuTraceMarker(const GrGpuTraceMarker* marker); + /** * Stencil buffers add themselves to the cache using addStencilBuffer. findStencilBuffer is * called to check the cache for a SB that matches an RT's criteria. diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index e823a98..6c90c17 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -28,6 +28,7 @@ #include "GrStencilBuffer.h" #include "GrStrokeInfo.h" #include "GrTextStrike.h" +#include "GrTraceMarker.h" #include "GrTracing.h" #include "SkDashPathPriv.h" #include "SkGr.h" @@ -1904,6 +1905,20 @@ GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKe return resource; } +void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { + fGpu->addGpuTraceMarker(marker); + if (NULL != fDrawBuffer) { + fDrawBuffer->addGpuTraceMarker(marker); + } +} + +void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { + fGpu->removeGpuTraceMarker(marker); + if (NULL != fDrawBuffer) { + fDrawBuffer->removeGpuTraceMarker(marker); + } +} + /////////////////////////////////////////////////////////////////////////////// #if GR_CACHE_STATS void GrContext::printCacheStats() const { diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h index cfce039..311042f 100644 --- a/src/gpu/GrTracing.h +++ b/src/gpu/GrTracing.h @@ -9,6 +9,8 @@ #define GrTracing_DEFINED #include "GrDrawTarget.h" +#include "GrGpu.h" +#include "GrInOrderDrawBuffer.h" #include "GrTraceMarker.h" #include "SkTraceEvent.h" @@ -37,6 +39,28 @@ private: SkTLazy fTraceMarker; }; +class GrGpuTraceMarkerGeneratorContext : public ::SkNoncopyable { +public: + GrGpuTraceMarkerGeneratorContext(GrContext* context) : fContext(context) {} + + ~GrGpuTraceMarkerGeneratorContext() { + if (fTraceMarker.isValid()) { + fContext->removeGpuTraceMarker(fTraceMarker.get()); + } + } + + void initialize(const char* marker_str, int* marker_counter) { + GrGpuTraceMarker* traceMarker = fTraceMarker.init(); + traceMarker->fMarker = marker_str; + traceMarker->fID = *marker_counter; + fContext->addGpuTraceMarker(traceMarker); + } + +private: + GrContext* fContext; + SkTLazy fTraceMarker; +}; + /** * GR_CREATE_TRACE_MARKER will place begin and end trace markers for both * cpu and gpu (if gpu tracing enabled) for the current scope. @@ -48,12 +72,12 @@ private: INTERNAL_GR_CREATE_TRACE_MARKER(SK_MACRO_APPEND_LINE(static_name), \ SK_MACRO_APPEND_LINE(name_counter), \ target) \ + sk_atomic_inc(&SK_MACRO_APPEND_LINE(name_counter)); \ #define INTERNAL_GR_CREATE_TRACE_MARKER(name, name_counter, target) \ GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \ TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"),name, \ "id", name_counter) \ - sk_atomic_inc(&name_counter); \ #define GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \ GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(target); \ @@ -61,5 +85,24 @@ private: SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \ } \ +#define GR_CREATE_TRACE_MARKER_CONTEXT(name, context) \ + static const char* SK_MACRO_APPEND_LINE(static_name) = name; \ + static int SK_MACRO_APPEND_LINE(name_counter) = 0; \ + INTERNAL_GR_CREATE_TRACE_MARKER_C(SK_MACRO_APPEND_LINE(static_name), \ + SK_MACRO_APPEND_LINE(name_counter), \ + context) \ + sk_atomic_inc(&SK_MACRO_APPEND_LINE(name_counter)); \ + +#define INTERNAL_GR_CREATE_TRACE_MARKER_C(name, name_counter, context) \ + GR_CREATE_GPU_TRACE_MARKER_C(name, name_counter, context) \ + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"),name, \ + "id", name_counter) \ + +#define GR_CREATE_GPU_TRACE_MARKER_C(name, name_counter, context) \ + GrGpuTraceMarkerGeneratorContext SK_MACRO_APPEND_LINE(TMG)(context); \ + if (context->isGpuTracingEnabled()) { \ + SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \ + } \ + #endif diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 72b0737..d0c32eb7 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -18,6 +18,7 @@ #include "GrLayerCache.h" #include "GrPictureUtils.h" #include "GrStrokeInfo.h" +#include "GrTracing.h" #include "SkGrTexturePixelRef.h" @@ -420,6 +421,8 @@ 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); + CHECK_FOR_ANNOTATION(paint); CHECK_SHOULD_DRAW(draw, false); @@ -1711,6 +1714,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, const SkScalar pos[], SkScalar constY, int scalarsPerPos, const SkPaint& paint) { + GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); CHECK_SHOULD_DRAW(draw, false); if (fMainTextContext->canDraw(paint)) { -- 2.7.4