2016-01-08 15:19:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrAuditTrail_DEFINED
|
|
|
|
#define GrAuditTrail_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/gpu/GrConfig.h"
|
|
|
|
#include "include/gpu/GrGpuResource.h"
|
|
|
|
#include "include/private/GrRenderTargetProxy.h"
|
|
|
|
#include "include/private/SkTArray.h"
|
|
|
|
#include "include/private/SkTHash.h"
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-12-01 14:36:50 +00:00
|
|
|
class GrOp;
|
2019-01-28 18:41:19 +00:00
|
|
|
class SkJSONWriter;
|
2016-01-08 15:19:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
|
|
|
|
* to json.
|
2016-02-18 21:45:39 +00:00
|
|
|
*
|
|
|
|
* Capturing this information is expensive and consumes a lot of memory, therefore it is important
|
2017-10-09 19:45:33 +00:00
|
|
|
* to enable auditing only when required and disable it promptly. The AutoEnable class helps to
|
2016-02-18 21:45:39 +00:00
|
|
|
* ensure that the audit trail is disabled in a timely fashion. Once the information has been dealt
|
|
|
|
* with, be sure to call reset(), or the log will simply keep growing.
|
2016-01-08 15:19:47 +00:00
|
|
|
*/
|
|
|
|
class GrAuditTrail {
|
|
|
|
public:
|
2017-10-09 19:45:33 +00:00
|
|
|
GrAuditTrail()
|
2016-02-29 15:44:02 +00:00
|
|
|
: fClientID(kGrAuditTrailInvalidID)
|
|
|
|
, fEnabled(false) {}
|
2016-01-12 20:59:28 +00:00
|
|
|
|
2016-02-18 21:45:39 +00:00
|
|
|
class AutoEnable {
|
|
|
|
public:
|
|
|
|
AutoEnable(GrAuditTrail* auditTrail)
|
|
|
|
: fAuditTrail(auditTrail) {
|
|
|
|
SkASSERT(!fAuditTrail->isEnabled());
|
|
|
|
fAuditTrail->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoEnable() {
|
|
|
|
SkASSERT(fAuditTrail->isEnabled());
|
|
|
|
fAuditTrail->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrAuditTrail* fAuditTrail;
|
|
|
|
};
|
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
class AutoManageOpList {
|
2016-02-26 16:07:50 +00:00
|
|
|
public:
|
2016-12-20 21:14:45 +00:00
|
|
|
AutoManageOpList(GrAuditTrail* auditTrail)
|
|
|
|
: fAutoEnable(auditTrail), fAuditTrail(auditTrail) {}
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
~AutoManageOpList() { fAuditTrail->fullReset(); }
|
2016-02-26 16:07:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
AutoEnable fAutoEnable;
|
|
|
|
GrAuditTrail* fAuditTrail;
|
|
|
|
};
|
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
class AutoCollectOps {
|
2016-02-29 15:44:02 +00:00
|
|
|
public:
|
2016-12-20 21:14:45 +00:00
|
|
|
AutoCollectOps(GrAuditTrail* auditTrail, int clientID)
|
|
|
|
: fAutoEnable(auditTrail), fAuditTrail(auditTrail) {
|
2016-02-29 15:44:02 +00:00
|
|
|
fAuditTrail->setClientID(clientID);
|
2016-01-12 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
~AutoCollectOps() { fAuditTrail->setClientID(kGrAuditTrailInvalidID); }
|
2016-01-08 15:19:47 +00:00
|
|
|
|
2016-02-29 15:44:02 +00:00
|
|
|
private:
|
|
|
|
AutoEnable fAutoEnable;
|
|
|
|
GrAuditTrail* fAuditTrail;
|
|
|
|
};
|
2016-01-12 20:59:28 +00:00
|
|
|
|
2016-03-02 16:11:34 +00:00
|
|
|
void pushFrame(const char* framename) {
|
|
|
|
SkASSERT(fEnabled);
|
|
|
|
fCurrentStackTrace.push_back(SkString(framename));
|
|
|
|
}
|
|
|
|
|
2017-05-17 13:36:38 +00:00
|
|
|
void addOp(const GrOp*, GrRenderTargetProxy::UniqueID proxyID);
|
2016-01-12 14:45:24 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
void opsCombined(const GrOp* consumer, const GrOp* consumed);
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
// Because op combining is heavily dependent on sequence of draw calls, these calls will only
|
|
|
|
// produce valid information for the given draw sequence which preceeded them. Specifically, ops
|
|
|
|
// of future draw calls may combine with previous ops and thus would invalidate the json. What
|
|
|
|
// this means is that for some sequence of draw calls N, the below toJson calls will only
|
|
|
|
// produce JSON which reflects N draw calls. This JSON may or may not be accurate for N + 1 or
|
|
|
|
// N - 1 draws depending on the actual combining algorithm used.
|
2019-01-28 18:41:19 +00:00
|
|
|
void toJson(SkJSONWriter& writer) const;
|
2016-02-29 15:44:02 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
// returns a json string of all of the ops associated with a given client id
|
2019-01-28 18:41:19 +00:00
|
|
|
void toJson(SkJSONWriter& writer, int clientID) const;
|
2016-01-08 15:19:47 +00:00
|
|
|
|
2016-02-18 21:45:39 +00:00
|
|
|
bool isEnabled() { return fEnabled; }
|
|
|
|
void setEnabled(bool enabled) { fEnabled = enabled; }
|
|
|
|
|
2016-02-29 15:44:02 +00:00
|
|
|
void setClientID(int clientID) { fClientID = clientID; }
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-02-29 19:15:06 +00:00
|
|
|
// We could just return our internal bookkeeping struct if copying the data out becomes
|
|
|
|
// a performance issue, but until then its nice to decouple
|
2016-12-20 21:14:45 +00:00
|
|
|
struct OpInfo {
|
|
|
|
struct Op {
|
2017-03-31 14:03:45 +00:00
|
|
|
int fClientID;
|
2016-02-29 19:15:06 +00:00
|
|
|
SkRect fBounds;
|
|
|
|
};
|
2017-03-31 14:03:45 +00:00
|
|
|
|
|
|
|
SkRect fBounds;
|
|
|
|
GrSurfaceProxy::UniqueID fProxyUniqueID;
|
|
|
|
SkTArray<Op> fOps;
|
2016-02-29 19:15:06 +00:00
|
|
|
};
|
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
void getBoundsByClientID(SkTArray<OpInfo>* outInfo, int clientID);
|
|
|
|
void getBoundsByOpListID(OpInfo* outInfo, int opListID);
|
2016-02-29 19:15:06 +00:00
|
|
|
|
2016-03-01 15:47:56 +00:00
|
|
|
void fullReset();
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-02-29 15:44:02 +00:00
|
|
|
static const int kGrAuditTrailInvalidID;
|
2016-01-08 15:19:47 +00:00
|
|
|
|
|
|
|
private:
|
2016-01-14 18:58:07 +00:00
|
|
|
// TODO if performance becomes an issue, we can move to using SkVarAlloc
|
2016-12-20 21:14:45 +00:00
|
|
|
struct Op {
|
2019-01-28 18:41:19 +00:00
|
|
|
void toJson(SkJSONWriter& writer) const;
|
2016-02-29 15:44:02 +00:00
|
|
|
SkString fName;
|
2016-03-02 16:11:34 +00:00
|
|
|
SkTArray<SkString> fStackTrace;
|
2016-02-29 15:44:02 +00:00
|
|
|
SkRect fBounds;
|
|
|
|
int fClientID;
|
2016-12-20 21:14:45 +00:00
|
|
|
int fOpListID;
|
2016-02-29 15:44:02 +00:00
|
|
|
int fChildID;
|
2016-01-08 15:19:47 +00:00
|
|
|
};
|
2016-12-20 21:14:45 +00:00
|
|
|
typedef SkTArray<std::unique_ptr<Op>, true> OpPool;
|
2016-01-08 15:19:47 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
typedef SkTArray<Op*> Ops;
|
2016-01-14 18:58:07 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
struct OpNode {
|
2017-05-17 13:36:38 +00:00
|
|
|
OpNode(const GrSurfaceProxy::UniqueID& proxyID) : fProxyUniqueID(proxyID) { }
|
2019-01-28 18:41:19 +00:00
|
|
|
void toJson(SkJSONWriter& writer) const;
|
2017-03-31 14:03:45 +00:00
|
|
|
|
2016-11-11 17:38:40 +00:00
|
|
|
SkRect fBounds;
|
2017-03-31 14:03:45 +00:00
|
|
|
Ops fChildren;
|
|
|
|
const GrSurfaceProxy::UniqueID fProxyUniqueID;
|
2016-01-14 18:58:07 +00:00
|
|
|
};
|
2016-12-20 21:14:45 +00:00
|
|
|
typedef SkTArray<std::unique_ptr<OpNode>, true> OpList;
|
2016-01-14 18:58:07 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
void copyOutFromOpList(OpInfo* outOpInfo, int opListID);
|
2016-03-02 16:32:37 +00:00
|
|
|
|
2016-02-26 16:07:50 +00:00
|
|
|
template <typename T>
|
2019-01-28 18:41:19 +00:00
|
|
|
static void JsonifyTArray(SkJSONWriter& writer, const char* name, const T& array);
|
2016-10-27 16:30:08 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
OpPool fOpPool;
|
2016-03-08 18:43:41 +00:00
|
|
|
SkTHashMap<uint32_t, int> fIDLookup;
|
2016-12-20 21:14:45 +00:00
|
|
|
SkTHashMap<int, Ops*> fClientIDLookup;
|
|
|
|
OpList fOpList;
|
2016-03-02 16:11:34 +00:00
|
|
|
SkTArray<SkString> fCurrentStackTrace;
|
2016-02-29 15:44:02 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
// The client can pass in an optional client ID which we will use to mark the ops
|
2016-02-29 15:44:02 +00:00
|
|
|
int fClientID;
|
|
|
|
bool fEnabled;
|
2016-01-08 15:19:47 +00:00
|
|
|
};
|
|
|
|
|
2016-02-18 21:45:39 +00:00
|
|
|
#define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
|
2018-11-30 20:33:19 +00:00
|
|
|
if (audit_trail->isEnabled()) audit_trail->invoke(__VA_ARGS__)
|
2016-01-11 18:39:11 +00:00
|
|
|
|
2016-01-12 20:59:28 +00:00
|
|
|
#define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \
|
2018-11-30 20:33:19 +00:00
|
|
|
GR_AUDIT_TRAIL_INVOKE_GUARD((audit_trail), pushFrame, framename)
|
2016-01-11 18:39:11 +00:00
|
|
|
|
|
|
|
#define GR_AUDIT_TRAIL_RESET(audit_trail) \
|
2016-03-02 16:11:34 +00:00
|
|
|
//GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, fullReset);
|
2016-01-11 18:39:11 +00:00
|
|
|
|
2017-05-17 13:36:38 +00:00
|
|
|
#define GR_AUDIT_TRAIL_ADD_OP(audit_trail, op, proxy_id) \
|
2018-11-30 20:33:19 +00:00
|
|
|
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addOp, op, proxy_id)
|
2016-01-12 14:45:24 +00:00
|
|
|
|
2016-12-20 21:14:45 +00:00
|
|
|
#define GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(audit_trail, combineWith, op) \
|
2018-11-30 20:33:19 +00:00
|
|
|
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, opsCombined, combineWith, op)
|
2016-02-26 16:07:50 +00:00
|
|
|
|
2016-01-08 15:19:47 +00:00
|
|
|
#endif
|