Path: blob/main_old/samples/capture_replay/CaptureReplay.cpp
1693 views
//1// Copyright 2019 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// CaptureReplay: Template for replaying a frame capture with ANGLE.67#include "SampleApplication.h"89#include <functional>1011#include "util/frame_capture_test_utils.h"1213// Build the right context header based on replay ID14// This will expand to "angle_capture_context<#>.h"15#include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_SAMPLE_HEADER)1617// Assign the context numbered functions based on GN arg selecting replay ID18std::function<void()> SetupContextReplay = reinterpret_cast<void (*)()>(19ANGLE_MACRO_CONCAT(SetupContext,20ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));21std::function<void(int)> ReplayContextFrame = reinterpret_cast<void (*)(int)>(22ANGLE_MACRO_CONCAT(ReplayContext,23ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Frame)));24std::function<void()> ResetContextReplay = reinterpret_cast<void (*)()>(25ANGLE_MACRO_CONCAT(ResetContext,26ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));2728class CaptureReplaySample : public SampleApplication29{30public:31CaptureReplaySample(int argc, char **argv)32: SampleApplication("CaptureReplaySample",33argc,34argv,353,360,37kReplayDrawSurfaceWidth,38kReplayDrawSurfaceHeight)39{}4041bool initialize() override42{43// Set CWD to executable directory.44std::string exeDir = angle::GetExecutableDirectory();45if (!angle::SetCWD(exeDir.c_str()))46return false;47if (kIsBinaryDataCompressed)48{49SetBinaryDataDecompressCallback(angle::DecompressBinaryData);50}51SetBinaryDataDir(ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR);52SetupContextReplay();53return true;54}5556void destroy() override {}5758void draw() override59{60// Compute the current frame, looping from kReplayFrameStart to kReplayFrameEnd.61uint32_t frame =62kReplayFrameStart + (mCurrentFrame % ((kReplayFrameEnd - kReplayFrameStart) + 1));63if (mPreviousFrame > frame)64{65ResetContextReplay();66}67ReplayContextFrame(frame);68mPreviousFrame = frame;69mCurrentFrame++;70}7172private:73uint32_t mCurrentFrame = 0;74uint32_t mPreviousFrame = 0;75};7677int main(int argc, char **argv)78{79CaptureReplaySample app(argc, argv);80return app.run();81}828384