//--------------------------------------------------------------------------
/// BeginFrame is called when a new frame is started, and should setup the
/// collection process to log each API call issued during the frame.
/// \return Nothing.
//--------------------------------------------------------------------------
void MultithreadedTraceAnalyzerLayer::BeginFrame()
{
    bool bFrameCaptureWithSaveActive = GetParentLayerManager()->mCmdFrameCaptureWithSave.IsActive();

    // Check if automatic tracing is enabled for a specific frame. Determine which trace type by examining the result.
    int autotraceFlags = GetTraceTypeFlags();

    // Pick up new requests that are active and flip the switch to begin tracing calls.
    bool bLinkedTraceRequested = (mCmdLinkedTrace.IsActive() || bFrameCaptureWithSaveActive) || (autotraceFlags == kTraceType_Linked) || mbLinkedTraceForCapture;

    // If a linked trace is required, turn on both trace switches.
    bool bAPITraceNeeded = OnlyAPITraceRequested() || bLinkedTraceRequested || (autotraceFlags & kTraceType_API);
    bool bGPUTraceNeeded = OnlyGPUTraceRequested() || bLinkedTraceRequested || (autotraceFlags & kTraceType_GPU);

    mFramestartTime = mFramestartTimer.GetRaw();

    if (bAPITraceNeeded || bGPUTraceNeeded)
    {
        // Set the flag indicating that the frame is being traced. We'll be rendering the next frame when this flag is checked.
        mLastTracedFrameIndex = GetParentLayerManager()->GetFrameCount();

        // Clear out the previous trace data before tracing the new frame.
        Clear();

        // We need to enable tracing no matter what so that we go into the PreCall/PostCall.
        SetCollectTrace(true);

        if (bAPITraceNeeded)
        {
            // Enable global trace collection so API and GPU trace can happen.
            BeforeAPITrace();
            mbCollectingApiTrace = true;
        }

        if (bGPUTraceNeeded)
        {
            BeforeGPUTrace();

            // Enable GPU time collection
            ModernAPIFrameProfilerLayer* frameProfiler = GetParentLayerManager()->GetFrameProfilerLayer();
            frameProfiler->SetProfilingEnabled(true);
            mbCollectingGPUTrace = true;
        }
    }
}
//--------------------------------------------------------------------------
/// BeginFrame is called when a new frame is started, and should setup the
/// collection process to log each Mantle call issued during the frame.
/// \return Nothing.
//--------------------------------------------------------------------------
void MultithreadedTraceAnalyzerLayer::BeginFrame()
{
    // Check if automatic tracing is enabled for a specific frame. Determine which trace type by examining the result.
    int autotraceFlags = GetTraceTypeFlags();

    // Pick up new requests that are active and flip the switch to begin tracing calls.
    bool bLinkedTraceRequested = (mCmdLinkedTrace.IsActive() || mCmdLinkedTraceWithSave.IsActive()) || (autotraceFlags == kTraceType_Linked);

    // If a linked trace is required, turn on both trace switches.
    bool bAPITraceNeeded = m_apiTraceTXT.IsActive() || bLinkedTraceRequested || (autotraceFlags & kTraceType_API);
    bool bGPUTraceNeeded = m_cmdGPUTrace.IsActive() || bLinkedTraceRequested || (autotraceFlags & kTraceType_GPU);

    if (bAPITraceNeeded || bGPUTraceNeeded)
    {
        // Clear out the previous trace data before tracing the new frame.
        Clear();

        // We need to enable tracing no matter what so that we go into the PreCall/PostCall.
        InterceptorBase* interceptor = GetInterceptor();
        interceptor->SetCollectTrace(true);

        if (bAPITraceNeeded)
        {
            // Enable global trace collection so API and GPU trace can happen.
            BeforeAPITrace();
            mbCollectingApiTrace = true;
        }

        if (bGPUTraceNeeded)
        {
            BeforeGPUTrace();

            // Enable GPU time collection
            interceptor->SetProfilingEnabled(true);
            mbCollectingGPUTrace = true;
        }

        mFramestartTime = mFramestartTimer.GetRaw();
    }
}