#ifndef PlatformInstrumentation_h
#define PlatformInstrumentation_h
#include "platform/PlatformExport.h"
#include "platform/TraceEvent.h"
#include "wtf/MainThread.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class PLATFORM_EXPORT PlatformInstrumentationClient {
public:
virtual ~PlatformInstrumentationClient();
virtual void willDecodeImage(const String& imageType) = 0;
virtual void didDecodeImage() = 0;
virtual void willResizeImage(bool shouldCache) = 0;
virtual void didResizeImage() = 0;
};
class PLATFORM_EXPORT PlatformInstrumentation {
public:
class LazyPixelRefTracker: TraceEvent::TraceScopedTrackableObject<void*> {
public:
LazyPixelRefTracker(void* instance)
: TraceEvent::TraceScopedTrackableObject<void*>(CategoryName, LazyPixelRef, instance)
{
}
};
static const char ImageDecodeEvent[];
static const char ImageResizeEvent[];
static const char DrawLazyPixelRefEvent[];
static const char DecodeLazyPixelRefEvent[];
static const char ImageTypeArgument[];
static const char CachedArgument[];
static const char LazyPixelRef[];
static void setClient(PlatformInstrumentationClient*);
static bool hasClient() { return m_client; }
static void willDecodeImage(const String& imageType);
static void didDecodeImage();
static void willResizeImage(bool shouldCache);
static void didResizeImage();
static void didDrawLazyPixelRef(unsigned long long lazyPixelRefId);
static void willDecodeLazyPixelRef(unsigned long long lazyPixelRefId);
static void didDecodeLazyPixelRef(unsigned long long lazyPixelRefId);
private:
static const char CategoryName[];
static PlatformInstrumentationClient* m_client;
};
#define FAST_RETURN_IF_NO_CLIENT_OR_NOT_MAIN_THREAD() if (!m_client || !isMainThread()) return;
inline void PlatformInstrumentation::willDecodeImage(const String& imageType)
{
TRACE_EVENT_BEGIN1(CategoryName, ImageDecodeEvent, ImageTypeArgument, TRACE_STR_COPY(imageType.ascii().data()));
FAST_RETURN_IF_NO_CLIENT_OR_NOT_MAIN_THREAD();
m_client->willDecodeImage(imageType);
}
inline void PlatformInstrumentation::didDecodeImage()
{
TRACE_EVENT_END0(CategoryName, ImageDecodeEvent);
FAST_RETURN_IF_NO_CLIENT_OR_NOT_MAIN_THREAD();
m_client->didDecodeImage();
}
inline void PlatformInstrumentation::willResizeImage(bool shouldCache)
{
TRACE_EVENT_BEGIN1(CategoryName, ImageResizeEvent, CachedArgument, shouldCache);
FAST_RETURN_IF_NO_CLIENT_OR_NOT_MAIN_THREAD();
m_client->willResizeImage(shouldCache);
}
inline void PlatformInstrumentation::didResizeImage()
{
TRACE_EVENT_END0(CategoryName, ImageResizeEvent);
FAST_RETURN_IF_NO_CLIENT_OR_NOT_MAIN_THREAD();
m_client->didResizeImage();
}
inline void PlatformInstrumentation::didDrawLazyPixelRef(unsigned long long lazyPixelRefId)
{
TRACE_EVENT_INSTANT1(CategoryName, DrawLazyPixelRefEvent, LazyPixelRef, lazyPixelRefId);
}
inline void PlatformInstrumentation::willDecodeLazyPixelRef(unsigned long long lazyPixelRefId)
{
TRACE_EVENT_BEGIN1(CategoryName, DecodeLazyPixelRefEvent, LazyPixelRef, lazyPixelRefId);
}
inline void PlatformInstrumentation::didDecodeLazyPixelRef(unsigned long long lazyPixelRefId)
{
TRACE_EVENT_END1(CategoryName, DecodeLazyPixelRefEvent, LazyPixelRef, lazyPixelRefId);
}
}
#endif