diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 17 | ||||
-rw-r--r-- | src/gpu/GrDrawTarget.cpp | 26 | ||||
-rw-r--r-- | src/gpu/GrDrawTarget.h | 34 | ||||
-rw-r--r-- | src/gpu/GrInOrderDrawBuffer.cpp | 87 | ||||
-rw-r--r-- | src/gpu/GrInOrderDrawBuffer.h | 9 | ||||
-rw-r--r-- | src/gpu/GrTraceMarker.cpp | 117 | ||||
-rw-r--r-- | src/gpu/GrTraceMarker.h | 69 | ||||
-rw-r--r-- | src/gpu/GrTracing.h | 66 | ||||
-rw-r--r-- | src/gpu/gl/GrGLInterface.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 17 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 6 | ||||
-rw-r--r-- | src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp | 2 |
13 files changed, 377 insertions, 79 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c016d062ab..08d1b2f239 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -25,6 +25,7 @@ #include "GrSoftwarePathRenderer.h" #include "GrStencilBuffer.h" #include "GrTextStrike.h" +#include "GrTracing.h" #include "SkRTConf.h" #include "SkRRect.h" #include "SkStrokeRec.h" @@ -101,6 +102,7 @@ GrContext::GrContext() { fOvalRenderer = NULL; fViewMatrix.reset(); fMaxTextureSizeOverride = 1 << 20; + fGpuTracingEnabled = false; } bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { @@ -770,6 +772,8 @@ void GrContext::drawRect(const GrPaint& paint, AutoCheckFlush acf(this); GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); + GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); + SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); if (NULL != matrix) { @@ -890,6 +894,8 @@ void GrContext::drawRectToRect(const GrPaint& paint, AutoCheckFlush acf(this); GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); + GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); + target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); } @@ -945,6 +951,8 @@ void GrContext::drawVertices(const GrPaint& paint, GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); + GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); + GrDrawState* drawState = target->drawState(); int colorOffset = -1, texOffset = -1; @@ -998,6 +1006,8 @@ void GrContext::drawRRect(const GrPaint& paint, AutoCheckFlush acf(this); GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); + GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); + if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect, stroke)) { SkPath path; path.addRRect(rect); @@ -1018,6 +1028,8 @@ void GrContext::drawOval(const GrPaint& paint, AutoCheckFlush acf(this); GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); + GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); + if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke)) { SkPath path; path.addOval(oval); @@ -1099,6 +1111,8 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrok GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); GrDrawState* drawState = target->drawState(); + GR_CREATE_TRACE_MARKER("GrContext::drawPath", target); + bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->isMultisampled(); if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { @@ -1134,6 +1148,9 @@ void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& const SkStrokeRec& origStroke) { SkASSERT(!path.isEmpty()); + GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); + + // An Assumption here is that path renderer would use some form of tweaking // the src color (either the input alpha or in the frag shader) to implement // aa. If we have some future driver-mojo path AA that can do the right diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 3502542079..8d3ded2d65 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -89,7 +89,7 @@ void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) { GrDrawTarget::GrDrawTarget(GrContext* context) : fClip(NULL) , fContext(context) - , fPushGpuTraceCount(0) { + , fGpuTraceMarkerCount(0) { SkASSERT(NULL != context); fDrawState = &fDefaultDrawState; @@ -578,25 +578,21 @@ void GrDrawTarget::drawPaths(size_t pathCount, const GrPath** paths, dstCopy.texture() ? &dstCopy : NULL); } -void GrDrawTarget::instantGpuTraceEvent(const char* marker) { +void GrDrawTarget::addGpuTraceMarker(GrGpuTraceMarker* marker) { if (this->caps()->gpuTracingSupport()) { - this->onInstantGpuTraceEvent(marker); + SkASSERT(fGpuTraceMarkerCount >= 0); + this->fActiveTraceMarkers.add(*marker); + this->didAddGpuTraceMarker(); + ++fGpuTraceMarkerCount; } } -void GrDrawTarget::pushGpuTraceEvent(const char* marker) { - SkASSERT(fPushGpuTraceCount >= 0); +void GrDrawTarget::removeGpuTraceMarker(GrGpuTraceMarker* marker) { if (this->caps()->gpuTracingSupport()) { - this->onPushGpuTraceEvent(marker); - ++fPushGpuTraceCount; - } -} - -void GrDrawTarget::popGpuTraceEvent() { - SkASSERT(fPushGpuTraceCount >= 1); - if (this->caps()->gpuTracingSupport()) { - this->onPopGpuTraceEvent(); - --fPushGpuTraceCount; + SkASSERT(fGpuTraceMarkerCount >= 1); + this->fActiveTraceMarkers.remove(*marker); + this->didRemoveGpuTraceMarker(); + --fGpuTraceMarkerCount; } } diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index 03e603a5b5..f7b5fe8921 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -9,8 +9,10 @@ #define GrDrawTarget_DEFINED #include "GrClipData.h" +#include "GrContext.h" #include "GrDrawState.h" #include "GrIndexBuffer.h" +#include "GrTraceMarker.h" #include "SkClipStack.h" #include "SkMatrix.h" @@ -436,18 +438,12 @@ public: GrRenderTarget* renderTarget = NULL) = 0; /** - * instantGpuTraceEvent places a single "sign post" type marker into command stream. The - * argument marker will be the name of the annotation that is added. + * Called at start and end of gpu trace marking + * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start + * and end of a code block respectively */ - void instantGpuTraceEvent(const char* marker); - /** - * The following two functions are used for marking groups of commands. Use pushGpuTraceEvent - * to set the beginning of a command set, and popGpuTraceEvent is be called at end of the - * command set. The argument marker is the name for the annotation that is added. The push and - * pops can be used hierarchically, but every push must have a match pop. - */ - void pushGpuTraceEvent(const char* marker); - void popGpuTraceEvent(); + void addGpuTraceMarker(GrGpuTraceMarker* marker); + void removeGpuTraceMarker(GrGpuTraceMarker* marker); /** * Copies a pixel rectangle from one surface to another. This call may finalize @@ -509,6 +505,10 @@ public: const GrDeviceCoordTexture* dstCopy) { this->onDrawPaths(pathCount, paths, transforms, fill, stroke, dstCopy); } + + inline bool isGpuTracingEnabled() const { + return this->getContext()->isGpuTracingEnabled(); + } //////////////////////////////////////////////////////////////////////////// @@ -786,6 +786,8 @@ protected: // Subclass must initialize this in its constructor. SkAutoTUnref<const GrDrawTargetCaps> fCaps; + const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } + /** * Used to communicate draws to subclass's onDraw function. */ @@ -894,9 +896,8 @@ private: SkPath::FillType, SkStrokeRec::Style, const GrDeviceCoordTexture* dstCopy) = 0; - virtual void onInstantGpuTraceEvent(const char* marker) = 0; - virtual void onPushGpuTraceEvent(const char* marker) = 0; - virtual void onPopGpuTraceEvent() = 0; + virtual void didAddGpuTraceMarker() = 0; + virtual void didRemoveGpuTraceMarker() = 0; // helpers for reserving vertex and index space. bool reserveVertexSpace(size_t vertexSize, @@ -932,8 +933,9 @@ private: GrDrawState fDefaultDrawState; // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. GrContext* fContext; - // To keep track that we always have at least as many debug marker pushes as pops - int fPushGpuTraceCount; + // To keep track that we always have at least as many debug marker adds as removes + int fGpuTraceMarkerCount; + GrTraceMarkerSet fActiveTraceMarkers; typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp index d9cbc914b0..1421af788f 100644 --- a/src/gpu/GrInOrderDrawBuffer.cpp +++ b/src/gpu/GrInOrderDrawBuffer.cpp @@ -118,6 +118,23 @@ static void set_vertex_attributes(GrDrawState* drawState, }; +enum { + kTraceCmdBit = 0x80, + kCmdMask = 0x7f, +}; + +static uint8_t add_trace_bit(uint8_t cmd) { + return cmd | kTraceCmdBit; +} + +static uint8_t strip_trace_bit(uint8_t cmd) { + return cmd & kCmdMask; +} + +static bool cmd_has_trace_marker(uint8_t cmd) { + return cmd & kTraceCmdBit; +} + void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, const SkMatrix* matrix, const SkRect* localRect, @@ -256,7 +273,7 @@ int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { } // Check if there is a draw info that is compatible that uses the same VB from the pool and // the same IB - if (kDraw_Cmd != fCmds.back()) { + if (kDraw_Cmd != strip_trace_bit(fCmds.back())) { return 0; } @@ -291,6 +308,17 @@ int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); draw->adjustInstanceCount(instancesToConcat); + + // update last fGpuCmdMarkers to include any additional trace markers that have been added + if (this->getActiveTraceMarkers().count() > 0) { + if (cmd_has_trace_marker(fCmds.back())) { + fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); + } else { + fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); + fCmds.back() = add_trace_bit(fCmds.back()); + } + } + return instancesToConcat; } @@ -483,18 +511,6 @@ void GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color, renderTarget->ref(); } -void GrInOrderDrawBuffer::onInstantGpuTraceEvent(const char* marker) { - // TODO: adds command to buffer -} - -void GrInOrderDrawBuffer::onPushGpuTraceEvent(const char* marker) { - // TODO: adds command to buffer -} - -void GrInOrderDrawBuffer::onPopGpuTraceEvent() { - // TODO: adds command to buffer -} - void GrInOrderDrawBuffer::reset() { SkASSERT(1 == fGeoPoolStateStack.count()); this->resetVertexSource(); @@ -518,6 +534,7 @@ void GrInOrderDrawBuffer::reset() { fClips.reset(); fClipOrigins.reset(); fCopySurfaces.reset(); + fGpuCmdMarkers.reset(); fClipSet = true; } @@ -558,9 +575,17 @@ void GrInOrderDrawBuffer::flush() { int currDrawPath = 0; int currDrawPaths = 0; int currCopySurface = 0; + int currCmdMarker = 0; for (int c = 0; c < numCmds; ++c) { - switch (fCmds[c]) { + GrGpuTraceMarker newMarker("", -1); + if (cmd_has_trace_marker(fCmds[c])) { + SkString traceString = fGpuCmdMarkers[currCmdMarker].toString(); + newMarker.fMarker = traceString.c_str(); + fDstGpu->addGpuTraceMarker(&newMarker); + ++currCmdMarker; + } + switch (strip_trace_bit(fCmds[c])) { case kDraw_Cmd: { const DrawRecord& draw = fDraws[currDraw]; fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); @@ -568,7 +593,6 @@ void GrInOrderDrawBuffer::flush() { fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); } fDstGpu->executeDraw(draw); - ++currDraw; break; } @@ -620,6 +644,9 @@ void GrInOrderDrawBuffer::flush() { ++currCopySurface; break; } + if (cmd_has_trace_marker(fCmds[c])) { + fDstGpu->removeGpuTraceMarker(&newMarker); + } } // we should have consumed all the states, clips, etc. SkASSERT(fStates.count() == currState); @@ -628,6 +655,7 @@ void GrInOrderDrawBuffer::flush() { SkASSERT(fClears.count() == currClear); SkASSERT(fDraws.count() == currDraw); SkASSERT(fCopySurfaces.count() == currCopySurface); + SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); fDstGpu->setDrawState(prevDrawState); prevDrawState->unref(); @@ -883,45 +911,56 @@ bool GrInOrderDrawBuffer::needsNewClip() const { return false; } +void GrInOrderDrawBuffer::addToCmdBuffer(uint8_t cmd) { + SkASSERT(!cmd_has_trace_marker(cmd)); + const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); + if (activeTraceMarkers.count() > 0) { + fCmds.push_back(add_trace_bit(cmd)); + fGpuCmdMarkers.push_back(activeTraceMarkers); + } else { + fCmds.push_back(cmd); + } +} + void GrInOrderDrawBuffer::recordClip() { - fClips.push_back() = *this->getClip()->fClipStack; + fClips.push_back(*this->getClip()->fClipStack); fClipOrigins.push_back() = this->getClip()->fOrigin; fClipSet = false; - fCmds.push_back(kSetClip_Cmd); + this->addToCmdBuffer(kSetClip_Cmd); } void GrInOrderDrawBuffer::recordState() { fStates.push_back().saveFrom(this->getDrawState()); - fCmds.push_back(kSetState_Cmd); + this->addToCmdBuffer(kSetState_Cmd); } GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { - fCmds.push_back(kDraw_Cmd); + this->addToCmdBuffer(kDraw_Cmd); return &fDraws.push_back(info); } GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { - fCmds.push_back(kStencilPath_Cmd); + this->addToCmdBuffer(kStencilPath_Cmd); return &fStencilPaths.push_back(); } GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { - fCmds.push_back(kDrawPath_Cmd); + this->addToCmdBuffer(kDrawPath_Cmd); return &fDrawPath.push_back(); } GrInOrderDrawBuffer::DrawPaths* GrInOrderDrawBuffer::recordDrawPaths() { - fCmds.push_back(kDrawPaths_Cmd); + this->addToCmdBuffer(kDrawPaths_Cmd); return &fDrawPaths.push_back(); } GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { - fCmds.push_back(kClear_Cmd); + this->addToCmdBuffer(kClear_Cmd); return &fClears.push_back(); } GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { - fCmds.push_back(kCopySurface_Cmd); + this->addToCmdBuffer(kCopySurface_Cmd); return &fCopySurfaces.push_back(); } diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h index 4576484181..72d0f9656e 100644 --- a/src/gpu/GrInOrderDrawBuffer.h +++ b/src/gpu/GrInOrderDrawBuffer.h @@ -184,10 +184,8 @@ private: bool quickInsideClip(const SkRect& devBounds); - virtual void onInstantGpuTraceEvent(const char* marker) SK_OVERRIDE; - virtual void onPushGpuTraceEvent(const char* marker) SK_OVERRIDE; - virtual void onPopGpuTraceEvent() SK_OVERRIDE; - + virtual void didAddGpuTraceMarker() SK_OVERRIDE {} + virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} // Attempts to concat instances from info onto the previous draw. info must represent an // instanced draw. The caller must have already recorded a new draw state and clip if necessary. @@ -232,6 +230,7 @@ private: GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces; GrSTAllocator<kClipPreallocCnt, SkClipStack> fClips; GrSTAllocator<kClipPreallocCnt, SkIPoint> fClipOrigins; + SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; GrDrawTarget* fDstGpu; @@ -264,6 +263,8 @@ private: virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } + void addToCmdBuffer(uint8_t cmd); + bool fFlushing; uint32_t fDrawID; diff --git a/src/gpu/GrTraceMarker.cpp b/src/gpu/GrTraceMarker.cpp new file mode 100644 index 0000000000..470f36409f --- /dev/null +++ b/src/gpu/GrTraceMarker.cpp @@ -0,0 +1,117 @@ + +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrTraceMarker.h" +#include "GrTracing.h" +#include "SkString.h" +#include "SkTSort.h" + +//////////////////////////////////////////////////////////////////////////////// + +class GrTraceMarkerSet::Iter { +public: + Iter() {}; + Iter& operator=(const Iter& i) { + fCurrentIndex = i.fCurrentIndex; + fMarkers = i.fMarkers; + return *this; + } + bool operator==(const Iter& i) const { + return fCurrentIndex == i.fCurrentIndex && fMarkers == i.fMarkers; + } + bool operator!=(const Iter& i) const { return !(*this == i); } + const GrGpuTraceMarker& operator*() const { return fMarkers->fMarkerArray[fCurrentIndex]; } + Iter& operator++() { + SkASSERT(*this != fMarkers->end()); + ++fCurrentIndex; + return *this; + } + +private: + friend class GrTraceMarkerSet; + Iter(const GrTraceMarkerSet* markers, int index) + : fMarkers(markers), fCurrentIndex(index) { + SkASSERT(markers); + } + + const GrTraceMarkerSet* fMarkers; + int fCurrentIndex; +}; + +//////////////////////////////////////////////////////////////////////////////// + +GrTraceMarkerSet::GrTraceMarkerSet(const GrTraceMarkerSet& other) { + this->addSet(other); +} + +void GrTraceMarkerSet::add(const GrGpuTraceMarker& marker) { + this->fMarkerArray.push(marker); +} + +void GrTraceMarkerSet::addSet(const GrTraceMarkerSet& markerSet) { + for (Iter iter = markerSet.begin(); iter != markerSet.end(); ++iter) { + this->add(*iter); + } +} + +void GrTraceMarkerSet::remove(const GrGpuTraceMarker& marker) { + SkASSERT(-1 != fMarkerArray.find(marker)); + int index = this->fMarkerArray.find(marker); + this->fMarkerArray.remove(index); +} + +int GrTraceMarkerSet::count() const { + return this->fMarkerArray.count(); +} + +SkString GrTraceMarkerSet::toString() const { + SkTQSort<GrGpuTraceMarker>(this->fMarkerArray.begin(), this->fMarkerArray.end() - 1); + SkString marker_string; + const char* prevMarkerName = ""; + int prevMarkerID = -1; + int counter = 0; + const int numMarkers = this->fMarkerArray.count(); + + // check used for GrGpuGL device after we've already collapsed all markers + if (1 == numMarkers && -1 == this->fMarkerArray[0].fID) { + marker_string.append(this->fMarkerArray[0].fMarker); + return marker_string; + } + + for (int i = 0; i < numMarkers; ++i ) { + GrGpuTraceMarker& currMarker = this->fMarkerArray[i]; + const char* currCmd = currMarker.fMarker; + if (currCmd != prevMarkerName) { + if (counter != 0) { + marker_string.append(") "); + } + marker_string.append(currCmd); + marker_string.append("("); + marker_string.appendS32(currMarker.fID); + prevMarkerName = currCmd; + } else if (currMarker.fID != prevMarkerID) { + marker_string.append(", "); + marker_string.appendS32(currMarker.fID); + } + prevMarkerID = currMarker.fID; + ++counter; + } + if (counter > 0) { + marker_string.append(")"); + } + return marker_string; +} + +GrTraceMarkerSet::Iter GrTraceMarkerSet::begin() const { + return Iter(this, 0); +} + +GrTraceMarkerSet::Iter GrTraceMarkerSet::end() const { + return Iter(this, this->fMarkerArray.count()); +} + diff --git a/src/gpu/GrTraceMarker.h b/src/gpu/GrTraceMarker.h new file mode 100644 index 0000000000..38e87fd0fb --- /dev/null +++ b/src/gpu/GrTraceMarker.h @@ -0,0 +1,69 @@ + +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkTDArray.h" + +#ifndef GrTraceMarkerSet_DEFINED +#define GrTraceMarkerSet_DEFINED + +class GrGpuTraceMarker { +public: + GrGpuTraceMarker() {}; + GrGpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idCounter) {} + + bool operator<(const GrGpuTraceMarker& rhs) const { + return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && this->fID < rhs.fID); + } + + bool operator==(const GrGpuTraceMarker& rhs) const { + return (this->fID == rhs.fID && this->fMarker == rhs.fMarker); + } + + const char* fMarker; + int fID; +}; + +/////////////////////////////////////////////////////////////////////////////// + +class SkString; + +class GrTraceMarkerSet { +public: + GrTraceMarkerSet() {} + + GrTraceMarkerSet(const GrTraceMarkerSet& other); + + // Adds marker to the set. + void add(const GrGpuTraceMarker& marker); + // Adds all markers from one set into this set. + void addSet(const GrTraceMarkerSet& markerSet); + + void remove(const GrGpuTraceMarker& marker); + + int count() const; + + /** + * First sorts fMarkerArray and returns a string of the format + * MarkerName1(#,#,...)%MarkerName2(#,#,...):... where MarkerName is the + * marker string used in the TraceMarker and the (#,#,..) is a list of instance + * id's for the the given marker string + */ + SkString toString() const; + + class Iter; + + Iter begin() const; + + Iter end() const; + +private: + mutable SkTDArray<GrGpuTraceMarker> fMarkerArray; +}; + +#endif + diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h new file mode 100644 index 0000000000..4a79f25b76 --- /dev/null +++ b/src/gpu/GrTracing.h @@ -0,0 +1,66 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTracing_DEFINED +#define GrTracing_DEFINED + +#include "GrDrawTarget.h" +#include "GrTraceMarker.h" +#include "SkTraceEvent.h" + +/** + * Marker generation class used for adding and removing markers around code blocks + */ +class GrGpuTraceMarkerGenerator : public ::SkNoncopyable { +public: + GrGpuTraceMarkerGenerator(GrDrawTarget* target) : fTarget(target) {} + + ~GrGpuTraceMarkerGenerator() { + if (fTraceMarker.isValid()) { + fTarget->removeGpuTraceMarker(fTraceMarker.get()); + } + } + + void initialize(const char* marker_str, int* marker_counter) { + GrGpuTraceMarker* traceMarker = fTraceMarker.init(); + traceMarker->fMarker = marker_str; + traceMarker->fID = *marker_counter; + fTarget->addGpuTraceMarker(traceMarker); + } + +private: + GrDrawTarget* fTarget; + SkTLazy<GrGpuTraceMarker> 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. + * marker is of type const char* and target is of type GrDrawTarget* + */ +#define GR_CREATE_TRACE_MARKER(name, target) \ + static const char* SK_MACRO_APPEND_LINE(static_name) = name; \ + static int SK_MACRO_APPEND_LINE(name_counter) = 0; \ + INTERNAL_GR_CREATE_TRACE_MARKER(SK_MACRO_APPEND_LINE(static_name), \ + SK_MACRO_APPEND_LINE(name_counter), \ + target) \ + +#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); \ + if (target->isGpuTracingEnabled()) { \ + SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \ + } \ + + +#endif + diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp index c0ff716d19..f40821f3da 100644 --- a/src/gpu/gl/GrGLInterface.cpp +++ b/src/gpu/gl/GrGLInterface.cpp @@ -479,7 +479,6 @@ bool GrGLInterface::validate() const { } } -#if 0 if (fExtensions.has("GL_EXT_debug_marker")) { if (NULL == fFunctions.fInsertEventMarker || NULL == fFunctions.fPushGroupMarker || @@ -487,6 +486,5 @@ bool GrGLInterface::validate() const { RETURN_FALSE_INTERFACE } } -#endif return true; } diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 0aa072cd84..8c6145a567 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -2754,24 +2754,19 @@ bool GrGpuGL::onCanCopySurface(GrSurface* dst, return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); } -void GrGpuGL::onInstantGpuTraceEvent(const char* marker) { +void GrGpuGL::didAddGpuTraceMarker() { if (this->caps()->gpuTracingSupport()) { - // GL_CALL(InsertEventMarker(0, marker)); + const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers(); + SkString markerString = markerArray.toString(); + GL_CALL(PushGroupMarker(0, markerString.c_str())); } } -void GrGpuGL::onPushGpuTraceEvent(const char* marker) { +void GrGpuGL::didRemoveGpuTraceMarker() { if (this->caps()->gpuTracingSupport()) { - // GL_CALL(PushGroupMarker(0, marker)); + GL_CALL(PopGroupMarker()); } } - -void GrGpuGL::onPopGpuTraceEvent() { - if (this->caps()->gpuTracingSupport()) { - // GL_CALL(PopGroupMarker()); - } -} - /////////////////////////////////////////////////////////////////////////////// GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 9c823f90ab..574bf24c09 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -166,10 +166,8 @@ private: virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; // GrDrawTarget ovverides - virtual void onInstantGpuTraceEvent(const char* marker) SK_OVERRIDE; - virtual void onPushGpuTraceEvent(const char* marker) SK_OVERRIDE; - virtual void onPopGpuTraceEvent() SK_OVERRIDE; - + virtual void didAddGpuTraceMarker() SK_OVERRIDE; + virtual void didRemoveGpuTraceMarker() SK_OVERRIDE; // binds texture unit in GL void setTextureUnit(int unitIdx); diff --git a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp index eacd2a3647..b0d8eee306 100644 --- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp +++ b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp @@ -193,7 +193,7 @@ static GrGLInterface* create_es_interface(GrGLVersion version, if (extensions.has("GL_EXT_debug_marker")) { functions->fInsertEventMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glInsertEventMarkerEXT"); functions->fPushGroupMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glPushGroupMarkerEXT"); - functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGropuMarkerEXT"); + functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGroupMarkerEXT"); } return interface; @@ -393,7 +393,7 @@ static GrGLInterface* create_desktop_interface(GrGLVersion version, if (extensions.has("GL_EXT_debug_marker")) { functions->fInsertEventMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glInsertEventMarkerEXT"); functions->fPushGroupMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glPushGroupMarkerEXT"); - functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGropuMarkerEXT"); + functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGroupMarkerEXT"); } return interface; diff --git a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp index 2d91404538..681eab468c 100644 --- a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp +++ b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp @@ -156,7 +156,7 @@ const GrGLInterface* GrGLCreateANGLEInterface() { #if GL_EXT_debug_marker functions->fInsertEventMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glInsertEventMarkerEXT"); functions->fPushGroupMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glPushGroupMarkerEXT"); - functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGropuMarkerEXT"); + functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGroupMarkerEXT"); #endif interface->fExtensions.init(kGLES_GrGLStandard, |