• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CaptureReplay: Template for replaying a frame capture with ANGLE.
7 
8 #include "SampleApplication.h"
9 
10 #include <functional>
11 
12 #include "util/frame_capture_utils.h"
13 
14 #define ANGLE_MACRO_STRINGIZE_AUX(a) #a
15 #define ANGLE_MACRO_STRINGIZE(a) ANGLE_MACRO_STRINGIZE_AUX(a)
16 #define ANGLE_MACRO_CONCAT_AUX(a, b) a##b
17 #define ANGLE_MACRO_CONCAT(a, b) ANGLE_MACRO_CONCAT_AUX(a, b)
18 
19 // Build the right context header based on replay ID
20 // This will expand to "angle_capture_context<#>.h"
21 #include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_SAMPLE_HEADER)
22 
23 // Assign the context numbered functions based on GN arg selecting replay ID
24 std::function<void()> SetupContextReplay = reinterpret_cast<void (*)()>(
25     ANGLE_MACRO_CONCAT(SetupContext,
26                        ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));
27 std::function<void(int)> ReplayContextFrame = reinterpret_cast<void (*)(int)>(
28     ANGLE_MACRO_CONCAT(ReplayContext,
29                        ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Frame)));
30 std::function<void()> ResetContextReplay = reinterpret_cast<void (*)()>(
31     ANGLE_MACRO_CONCAT(ResetContext,
32                        ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));
33 
34 class CaptureReplaySample : public SampleApplication
35 {
36   public:
CaptureReplaySample(int argc,char ** argv)37     CaptureReplaySample(int argc, char **argv)
38         : SampleApplication("CaptureReplaySample", argc, argv, 3, 0)
39     {}
40 
initialize()41     bool initialize() override
42     {
43         // Set CWD to executable directory.
44         std::string exeDir = angle::GetExecutableDirectory();
45         if (!angle::SetCWD(exeDir.c_str()))
46             return false;
47         if (kIsBinaryDataCompressed)
48         {
49             SetBinaryDataDecompressCallback(angle::DecompressBinaryData);
50         }
51         SetBinaryDataDir(ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR);
52         SetupContextReplay();
53 
54         eglSwapInterval(getDisplay(), 1);
55         return true;
56     }
57 
destroy()58     void destroy() override {}
59 
draw()60     void draw() override
61     {
62         // Compute the current frame, looping from kReplayFrameStart to kReplayFrameEnd.
63         uint32_t frame =
64             kReplayFrameStart + (mCurrentFrame % ((kReplayFrameEnd - kReplayFrameStart) + 1));
65         if (mPreviousFrame > frame)
66         {
67             ResetContextReplay();
68         }
69         ReplayContextFrame(frame);
70         mPreviousFrame = frame;
71         mCurrentFrame++;
72     }
73 
74   private:
75     uint32_t mCurrentFrame  = 0;
76     uint32_t mPreviousFrame = 0;
77 };
78 
main(int argc,char ** argv)79 int main(int argc, char **argv)
80 {
81     CaptureReplaySample app(argc, argv);
82     return app.run();
83 }
84