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
This commit is contained in:
egdaniel 2014-06-19 10:19:29 -07:00 committed by Commit bot
parent 3f73e8c8d5
commit bbcb38df4f
4 changed files with 67 additions and 1 deletions

View File

@ -26,6 +26,7 @@ class GrDrawTarget;
class GrEffect; class GrEffect;
class GrFontCache; class GrFontCache;
class GrGpu; class GrGpu;
class GrGpuTraceMarker;
class GrIndexBuffer; class GrIndexBuffer;
class GrIndexBufferAllocPool; class GrIndexBufferAllocPool;
class GrInOrderDrawBuffer; class GrInOrderDrawBuffer;
@ -925,6 +926,9 @@ public:
void enableGpuTracing() { fGpuTracingEnabled = true; } void enableGpuTracing() { fGpuTracingEnabled = true; }
void disableGpuTracing() { fGpuTracingEnabled = false; } 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 * 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. * called to check the cache for a SB that matches an RT's criteria.

View File

@ -28,6 +28,7 @@
#include "GrStencilBuffer.h" #include "GrStencilBuffer.h"
#include "GrStrokeInfo.h" #include "GrStrokeInfo.h"
#include "GrTextStrike.h" #include "GrTextStrike.h"
#include "GrTraceMarker.h"
#include "GrTracing.h" #include "GrTracing.h"
#include "SkDashPathPriv.h" #include "SkDashPathPriv.h"
#include "SkGr.h" #include "SkGr.h"
@ -1904,6 +1905,20 @@ GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKe
return resource; 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 #if GR_CACHE_STATS
void GrContext::printCacheStats() const { void GrContext::printCacheStats() const {

View File

@ -9,6 +9,8 @@
#define GrTracing_DEFINED #define GrTracing_DEFINED
#include "GrDrawTarget.h" #include "GrDrawTarget.h"
#include "GrGpu.h"
#include "GrInOrderDrawBuffer.h"
#include "GrTraceMarker.h" #include "GrTraceMarker.h"
#include "SkTraceEvent.h" #include "SkTraceEvent.h"
@ -37,6 +39,28 @@ private:
SkTLazy<GrGpuTraceMarker> fTraceMarker; SkTLazy<GrGpuTraceMarker> 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<GrGpuTraceMarker> fTraceMarker;
};
/** /**
* GR_CREATE_TRACE_MARKER will place begin and end trace markers for both * GR_CREATE_TRACE_MARKER will place begin and end trace markers for both
* cpu and gpu (if gpu tracing enabled) for the current scope. * 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), \ INTERNAL_GR_CREATE_TRACE_MARKER(SK_MACRO_APPEND_LINE(static_name), \
SK_MACRO_APPEND_LINE(name_counter), \ SK_MACRO_APPEND_LINE(name_counter), \
target) \ target) \
sk_atomic_inc(&SK_MACRO_APPEND_LINE(name_counter)); \
#define INTERNAL_GR_CREATE_TRACE_MARKER(name, name_counter, target) \ #define INTERNAL_GR_CREATE_TRACE_MARKER(name, name_counter, target) \
GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \ GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"),name, \ TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"),name, \
"id", name_counter) \ "id", name_counter) \
sk_atomic_inc(&name_counter); \
#define GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \ #define GR_CREATE_GPU_TRACE_MARKER(name, name_counter, target) \
GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(target); \ GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(target); \
@ -61,5 +85,24 @@ private:
SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \ 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 #endif

View File

@ -18,6 +18,7 @@
#include "GrLayerCache.h" #include "GrLayerCache.h"
#include "GrPictureUtils.h" #include "GrPictureUtils.h"
#include "GrStrokeInfo.h" #include "GrStrokeInfo.h"
#include "GrTracing.h"
#include "SkGrTexturePixelRef.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, void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
const SkPaint& paint) { const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRect", fContext);
CHECK_FOR_ANNOTATION(paint); CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw, false); CHECK_SHOULD_DRAW(draw, false);
@ -1711,6 +1714,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
size_t byteLength, const SkScalar pos[], size_t byteLength, const SkScalar pos[],
SkScalar constY, int scalarsPerPos, SkScalar constY, int scalarsPerPos,
const SkPaint& paint) { const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
CHECK_SHOULD_DRAW(draw, false); CHECK_SHOULD_DRAW(draw, false);
if (fMainTextContext->canDraw(paint)) { if (fMainTextContext->canDraw(paint)) {