1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2023 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "renderdoccmd.h"
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <ggp_c/ggp.h>
#include <replay/renderdoc_replay.h>
const uint64_t kMicrosecondsPerFrame = 16666L;
// struct appData: Global application data
static struct
{
// GGP
GgpEventQueue event_queue;
GgpEventHandle stream_state_changed_handle;
// General
bool quit;
} app_data = {0};
void Daemonise()
{
// don't change dir, but close stdin/stdout
daemon(1, 0);
}
WindowingData DisplayRemoteServerPreview(bool active, const rdcarray<WindowingSystem> &systems)
{
static WindowingData remoteServerPreview = {WindowingSystem::Unknown};
// No preview implemented.
return remoteServerPreview;
}
// ClockNowMicroSeconds(): Return current time in microseconds
static inline uint64_t ClockNowMicroSeconds()
{
struct timespec now = {};
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
uint64_t nanoseconds = (now.tv_sec * 1000000000LL) + now.tv_nsec;
uint64_t microseconds = nanoseconds / 1000LL;
return microseconds;
}
static void HandleStreamStateChanged(const GgpStreamStateChangedEvent *event, void *user_data)
{
switch(event->new_state)
{
case kGgpStreamStateChanged_Exited:
std::cout << "GGP client disconnected" << std::endl;
app_data.quit = true;
break;
case kGgpStreamStateChanged_Started: std::cout << "GGP client connected" << std::endl; break;
default:;
// Invalid, Starting, Suspended.
// Nothing to do.
}
}
// UnregisterCallback(): Handler unregistered
static void UnregisterCallback(void *user_data)
{
std::cout << "Unregistered callback" << std::endl;
}
// Initialize(): Initialize application
static void Initialize()
{
// Initialize event queue
app_data.event_queue = GgpEventQueueCreate();
std::cout << "GGP event queue created" << std::endl;
// Add client connection handlers
app_data.stream_state_changed_handle = GgpAddStreamStateChangedHandler(
app_data.event_queue, HandleStreamStateChanged, &app_data, UnregisterCallback, NULL);
}
// Finalize(): Clean up application resources
static void Finalize()
{
// Destroy the event queue
GgpEventQueueDestroy(app_data.event_queue, NULL);
std::cout << "GGP event queue destroyed" << std::endl;
// Remove client connection handlers.
GgpRemoveStreamStateChangedHandler(app_data.stream_state_changed_handle, NULL);
}
void DisplayRendererPreview(IReplayController *renderer, TextureDisplay &displayCfg, uint32_t width,
uint32_t height, uint32_t numLoops)
{
Initialize();
IReplayOutput *out = renderer->CreateOutput(CreateGgpWindowingData(), ReplayOutputType::Texture);
out->SetTextureDisplay(displayCfg);
// Wait until user closes the window, then exit
while(!app_data.quit)
{
uint64_t whenToResume = ClockNowMicroSeconds() + kMicrosecondsPerFrame;
while(GgpEventQueueProcessEvent(app_data.event_queue, 0))
{
}
renderer->SetFrameEvent(10000000, true);
out->Display();
// Sleep for 1/60 second (one frame)
uint64_t timeLeft = whenToResume - ClockNowMicroSeconds();
if(timeLeft > 0)
{
struct timespec sleepTime = {};
sleepTime.tv_nsec = timeLeft * 1000LL;
nanosleep(&sleepTime, NULL);
}
}
Finalize();
}
void sig_handler(int signo)
{
if(usingKillSignal)
killSignal = true;
else
exit(1);
}
int main(int argc, char *argv[])
{
setlocale(LC_CTYPE, "");
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
GlobalEnvironment env;
// add compiled-in support to version line
{
std::string support = "APIs supported at compile-time: ";
int count = 0;
#if defined(RENDERDOC_SUPPORT_VULKAN)
support += "Vulkan, ";
count++;
#endif
if(count == 0)
{
support += "None.";
}
else
{
// remove trailing ', '
support.pop_back();
support.pop_back();
support += ".";
}
add_version_line(support);
support = "Windowing systems supported at compile-time: ";
count = 0;
support += "GGP, ";
count++;
#if defined(RENDERDOC_SUPPORT_VULKAN)
support += "Vulkan KHR_display, ";
count++;
#endif
if(count == 0)
{
support += "None.";
}
else
{
// remove trailing ', '
support.pop_back();
support.pop_back();
support += ".";
}
add_version_line(support);
}
int ret = renderdoccmd(env, argc, argv);
return ret;
}
|