Index: src/gpu/GrInOrderDrawBuffer.cpp |
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp |
index d9cbc914b015a78c655a3fc7f877fd6f65bf958c..1421af788f37dce601f968f9ff5540aac7b045fc 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(); |
} |