• 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 
31 class CaptureReplaySample : public SampleApplication
32 {
33   public:
CaptureReplaySample(int argc,char ** argv)34     CaptureReplaySample(int argc, char **argv)
35         : SampleApplication("CaptureReplaySample", argc, argv, 3, 0)
36     {}
37 
initialize()38     bool initialize() override
39     {
40         // Set CWD to executable directory.
41         std::string exeDir = angle::GetExecutableDirectory();
42         if (!angle::SetCWD(exeDir.c_str()))
43             return false;
44         if (kIsBinaryDataCompressed)
45         {
46             SetBinaryDataDecompressCallback(angle::DecompressBinaryData);
47         }
48         SetBinaryDataDir(ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR);
49         SetupContextReplay();
50 
51         eglSwapInterval(getDisplay(), 1);
52         return true;
53     }
54 
destroy()55     void destroy() override {}
56 
draw()57     void draw() override
58     {
59         // Compute the current frame, looping from kReplayFrameStart to kReplayFrameEnd.
60         uint32_t frame =
61             kReplayFrameStart + (mCurrentFrame % (kReplayFrameEnd - kReplayFrameStart));
62         ReplayContextFrame(frame);
63         mCurrentFrame++;
64     }
65 
66   private:
67     uint32_t mCurrentFrame = 0;
68 };
69 
main(int argc,char ** argv)70 int main(int argc, char **argv)
71 {
72     CaptureReplaySample app(argc, argv);
73     return app.run();
74 }
75