Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 1 | // Copyright (C) 2016 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | #include "RendererImpl.h" |
| 15 | |
Jason Macnak | 6402a1b | 2022-06-02 15:29:05 -0700 | [diff] [blame] | 16 | #include <assert.h> |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 17 | |
| 18 | #include <algorithm> |
| 19 | #include <utility> |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 20 | #include <variant> |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 21 | |
Jason Macnak | 6402a1b | 2022-06-02 15:29:05 -0700 | [diff] [blame] | 22 | #include "FrameBuffer.h" |
| 23 | #include "RenderChannelImpl.h" |
| 24 | #include "RenderThread.h" |
Joshua Duong | ef2bbc2 | 2022-10-05 11:59:15 -0700 | [diff] [blame] | 25 | #include "aemu/base/system/System.h" |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 26 | #include "aemu/base/threads/WorkerThread.h" |
Jason Macnak | 6402a1b | 2022-06-02 15:29:05 -0700 | [diff] [blame] | 27 | #include "host-common/logging.h" |
| 28 | #include "snapshot/common.h" |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 29 | |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 30 | #if GFXSTREAM_ENABLE_HOST_GLES |
| 31 | #include "gl/EmulatedEglFenceSync.h" |
| 32 | #endif |
| 33 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 34 | namespace gfxstream { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 35 | |
| 36 | // kUseSubwindowThread is used to determine whether the RenderWindow should use |
| 37 | // a separate thread to manage its subwindow GL/GLES context. |
| 38 | // For now, this feature is disabled entirely for the following |
| 39 | // reasons: |
| 40 | // |
| 41 | // - It must be disabled on Windows at all times, otherwise the main window |
| 42 | // becomes unresponsive after a few seconds of user interaction (e.g. trying |
| 43 | // to move it over the desktop). Probably due to the subtle issues around |
| 44 | // input on this platform (input-queue is global, message-queue is |
| 45 | // per-thread). Also, this messes considerably the display of the |
| 46 | // main window when running the executable under Wine. |
| 47 | // |
| 48 | // - On Linux/XGL and OSX/Cocoa, this used to be necessary to avoid corruption |
| 49 | // issues with the GL state of the main window when using the SDL UI. |
| 50 | // After the switch to Qt, this is no longer necessary and may actually cause |
| 51 | // undesired interactions between the UI thread and the RenderWindow thread: |
| 52 | // for example, in a multi-monitor setup the context might be recreated when |
| 53 | // dragging the window between monitors, triggering a Qt-specific callback |
| 54 | // in the context of RenderWindow thread, which will become blocked on the UI |
| 55 | // thread, which may in turn be blocked on something else. |
| 56 | static const bool kUseSubwindowThread = false; |
| 57 | |
| 58 | // This object manages the cleanup of guest process resources when the process |
| 59 | // exits. It runs the cleanup in a separate thread to never block the main |
| 60 | // render thread for a low-priority task. |
| 61 | class RendererImpl::ProcessCleanupThread { |
| 62 | public: |
| 63 | ProcessCleanupThread() |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 64 | : mCleanupWorker([](Cmd cmd) { |
| 65 | using android::base::WorkerProcessingResult; |
| 66 | struct { |
| 67 | WorkerProcessingResult operator()(CleanProcessResources resources) { |
| 68 | FrameBuffer::getFB()->cleanupProcGLObjects(resources.puid); |
Kaiyi Li | ca6b393 | 2022-10-07 12:29:18 -0700 | [diff] [blame] | 69 | // resources.resource are destroyed automatically when going out of the scope. |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 70 | return WorkerProcessingResult::Continue; |
| 71 | } |
| 72 | WorkerProcessingResult operator()(Exit) { |
| 73 | return WorkerProcessingResult::Stop; |
| 74 | } |
| 75 | } visitor; |
| 76 | return std::visit(visitor, std::move(cmd)); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 77 | }) { |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 78 | mCleanupWorker.start(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | ~ProcessCleanupThread() { |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 82 | mCleanupWorker.enqueue(Exit{}); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Kaiyi Li | ca6b393 | 2022-10-07 12:29:18 -0700 | [diff] [blame] | 85 | void cleanup(uint64_t processId, std::unique_ptr<ProcessResources> resource) { |
| 86 | mCleanupWorker.enqueue(CleanProcessResources{ |
| 87 | .puid = processId, |
| 88 | .resource = std::move(resource), |
| 89 | }); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void stop() { |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 93 | mCleanupWorker.enqueue(Exit{}); |
Jason Macnak | 08f5382 | 2023-07-27 09:50:27 -0700 | [diff] [blame] | 94 | mCleanupWorker.join(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void waitForCleanup() { |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 98 | mCleanupWorker.waitQueuedItems(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | private: |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 102 | struct CleanProcessResources { |
| 103 | uint64_t puid; |
Kaiyi Li | ca6b393 | 2022-10-07 12:29:18 -0700 | [diff] [blame] | 104 | std::unique_ptr<ProcessResources> resource; |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 105 | }; |
| 106 | struct Exit {}; |
| 107 | using Cmd = std::variant<CleanProcessResources, Exit>; |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(ProcessCleanupThread); |
| 109 | |
Kaiyi Li | 32c361c | 2022-10-07 11:29:26 -0700 | [diff] [blame] | 110 | android::base::WorkerThread<Cmd> mCleanupWorker; |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | RendererImpl::RendererImpl() { |
| 114 | mCleanupThread.reset(new ProcessCleanupThread()); |
| 115 | } |
| 116 | |
| 117 | RendererImpl::~RendererImpl() { |
| 118 | stop(true); |
Andrew Woloszyn | 0ea0173 | 2022-11-23 10:03:13 -0500 | [diff] [blame] | 119 | // We can't finish until the loader render thread has |
| 120 | // completed else can get a crash at the end of the destructor. |
| 121 | if (mLoaderRenderThread) { |
| 122 | mLoaderRenderThread->wait(); |
| 123 | } |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 124 | mRenderWindow.reset(); |
| 125 | } |
| 126 | |
Jason Macnak | 2687212 | 2024-02-23 10:46:09 -0800 | [diff] [blame] | 127 | bool RendererImpl::initialize(int width, int height, gfxstream::host::FeatureSet features, |
| 128 | bool useSubWindow, bool egl2egl) { |
Gurchetan Singh | ae7c701 | 2024-06-27 09:09:51 -0700 | [diff] [blame] | 129 | #ifdef CONFIG_AEMU |
Lingfeng Yang | bfe3c72 | 2020-10-29 10:33:18 -0700 | [diff] [blame] | 130 | if (android::base::getEnvironmentVariable("ANDROID_EMUGL_VERBOSE") == "1") { |
Serdar Kocdemir | 47d2bcc | 2024-06-26 14:03:04 +0100 | [diff] [blame] | 131 | set_gfxstream_enable_verbose_logs(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 132 | } |
Gurchetan Singh | ae7c701 | 2024-06-27 09:09:51 -0700 | [diff] [blame] | 133 | #endif |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 134 | |
| 135 | if (mRenderWindow) { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | std::unique_ptr<RenderWindow> renderWindow(new RenderWindow( |
Jason Macnak | 2687212 | 2024-02-23 10:46:09 -0800 | [diff] [blame] | 140 | width, height, features, kUseSubwindowThread, useSubWindow, egl2egl)); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 141 | if (!renderWindow) { |
| 142 | ERR("Could not create rendering window class\n"); |
| 143 | GL_LOG("Could not create rendering window class"); |
| 144 | return false; |
| 145 | } |
| 146 | if (!renderWindow->isValid()) { |
| 147 | ERR("Could not initialize emulated framebuffer\n"); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | mRenderWindow = std::move(renderWindow); |
| 152 | GL_LOG("OpenGL renderer initialized successfully"); |
| 153 | |
| 154 | // This render thread won't do anything but will only preload resources |
| 155 | // for the real threads to start faster. |
| 156 | mLoaderRenderThread.reset(new RenderThread(nullptr)); |
| 157 | mLoaderRenderThread->start(); |
| 158 | |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | void RendererImpl::stop(bool wait) { |
| 163 | android::base::AutoLock lock(mChannelsLock); |
| 164 | mStopped = true; |
| 165 | auto channels = std::move(mChannels); |
| 166 | lock.unlock(); |
| 167 | |
| 168 | if (const auto fb = FrameBuffer::getFB()) { |
| 169 | fb->setShuttingDown(); |
| 170 | } |
| 171 | for (const auto& c : channels) { |
| 172 | c->stopFromHost(); |
| 173 | } |
| 174 | // We're stopping the renderer, so there's no need to clean up resources |
| 175 | // of some pending processes: we'll destroy everything soon. |
| 176 | mCleanupThread->stop(); |
| 177 | |
| 178 | mStoppedChannels.insert(mStoppedChannels.end(), |
| 179 | std::make_move_iterator(channels.begin()), |
| 180 | std::make_move_iterator(channels.end())); |
| 181 | |
| 182 | if (!wait) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | // Each render channel is referenced in the corresponing pipe object, so |
| 187 | // even if we clear the |channels| vector they could still be alive |
| 188 | // for a while. This means we need to make sure to wait for render thread |
| 189 | // exit explicitly. |
| 190 | for (const auto& c : mStoppedChannels) { |
| 191 | c->renderThread()->wait(); |
| 192 | } |
Kaiyi Li | 3a894ad | 2024-01-02 11:14:38 -0800 | [diff] [blame] | 193 | mCleanupThread->waitForCleanup(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 194 | mStoppedChannels.clear(); |
| 195 | } |
| 196 | |
| 197 | void RendererImpl::finish() { |
| 198 | { |
| 199 | android::base::AutoLock lock(mChannelsLock); |
| 200 | mRenderWindow->setPaused(true); |
| 201 | } |
| 202 | cleanupRenderThreads(); |
| 203 | { |
| 204 | android::base::AutoLock lock(mChannelsLock); |
| 205 | mRenderWindow->setPaused(false); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void RendererImpl::cleanupRenderThreads() { |
| 210 | android::base::AutoLock lock(mChannelsLock); |
| 211 | const auto channels = std::move(mChannels); |
| 212 | assert(mChannels.empty()); |
| 213 | lock.unlock(); |
| 214 | for (const auto& c : channels) { |
| 215 | // Please DO NOT notify the guest about this event (DO NOT call |
| 216 | // stopFromHost() ), because this is used to kill old threads when |
| 217 | // loading from a snapshot, and the newly loaded guest should not |
| 218 | // be notified for those behavior. |
| 219 | c->stop(); |
| 220 | } |
| 221 | for (const auto& c : channels) { |
| 222 | c->renderThread()->wait(); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void RendererImpl::waitForProcessCleanup() { |
| 227 | mCleanupThread->waitForCleanup(); |
| 228 | // Recreate it to make sure we've started from scratch and that we've |
| 229 | // finished all in-progress cleanups as well. |
| 230 | mCleanupThread.reset(new ProcessCleanupThread()); |
| 231 | } |
| 232 | |
| 233 | RenderChannelPtr RendererImpl::createRenderChannel( |
Jason Macnak | 1220d96 | 2023-11-21 16:53:21 -0800 | [diff] [blame] | 234 | android::base::Stream* loadStream, uint32_t virtioGpuContextId) { |
| 235 | const auto channel = |
| 236 | std::make_shared<RenderChannelImpl>(loadStream, virtioGpuContextId); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 237 | { |
| 238 | android::base::AutoLock lock(mChannelsLock); |
| 239 | |
| 240 | if (mStopped) { |
| 241 | return nullptr; |
| 242 | } |
| 243 | |
| 244 | // Clean up the stopped channels. |
| 245 | mChannels.erase( |
| 246 | std::remove_if(mChannels.begin(), mChannels.end(), |
| 247 | [](const std::shared_ptr<RenderChannelImpl>& c) { |
| 248 | return c->renderThread()->isFinished(); |
| 249 | }), |
| 250 | mChannels.end()); |
| 251 | mChannels.emplace_back(channel); |
| 252 | |
| 253 | // Take the time to check if our loader thread is done as well. |
| 254 | if (mLoaderRenderThread && mLoaderRenderThread->isFinished()) { |
| 255 | mLoaderRenderThread->wait(); |
| 256 | mLoaderRenderThread.reset(); |
| 257 | } |
| 258 | |
Jason Macnak | e43e3a0 | 2021-10-14 10:35:33 -0700 | [diff] [blame] | 259 | GL_LOG("Started new RenderThread (total %" PRIu64 ") @%p", |
| 260 | static_cast<uint64_t>(mChannels.size()), channel->renderThread()); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return channel; |
| 264 | } |
| 265 | |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 266 | void RendererImpl::addListener(FrameBufferChangeEventListener* listener) { |
Erwin Jansen | 6d8804e | 2021-02-06 17:25:08 -0800 | [diff] [blame] | 267 | mRenderWindow->addListener(listener); |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void RendererImpl::removeListener(FrameBufferChangeEventListener* listener) { |
Erwin Jansen | 6d8804e | 2021-02-06 17:25:08 -0800 | [diff] [blame] | 271 | mRenderWindow->removeListener(listener); |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 274 | void* RendererImpl::addressSpaceGraphicsConsumerCreate( |
| 275 | struct asg_context context, |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 276 | android::base::Stream* loadStream, |
Gurchetan Singh | f60b2b7 | 2022-08-22 17:01:02 -0700 | [diff] [blame] | 277 | android::emulation::asg::ConsumerCallbacks callbacks, |
| 278 | uint32_t contextId, uint32_t capsetId, |
| 279 | std::optional<std::string> nameOpt) { |
| 280 | auto thread = new RenderThread(context, loadStream, callbacks, contextId, |
| 281 | capsetId, std::move(nameOpt)); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 282 | thread->start(); |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 283 | android::base::AutoLock lock(mAddressSpaceRenderThreadLock); |
| 284 | mAddressSpaceRenderThreads.emplace(thread); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 285 | return (void*)thread; |
| 286 | } |
| 287 | |
| 288 | void RendererImpl::addressSpaceGraphicsConsumerDestroy(void* consumer) { |
| 289 | RenderThread* thread = (RenderThread*)consumer; |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 290 | { |
| 291 | android::base::AutoLock lock(mAddressSpaceRenderThreadLock); |
| 292 | mAddressSpaceRenderThreads.erase(thread); |
| 293 | } |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 294 | thread->wait(); |
| 295 | delete thread; |
| 296 | } |
| 297 | |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 298 | void RendererImpl::addressSpaceGraphicsConsumerPreSave(void* consumer) { |
| 299 | RenderThread* thread = (RenderThread*)consumer; |
| 300 | thread->pausePreSnapshot(); |
| 301 | } |
| 302 | |
| 303 | void RendererImpl::addressSpaceGraphicsConsumerSave(void* consumer, android::base::Stream* stream) { |
| 304 | RenderThread* thread = (RenderThread*)consumer; |
| 305 | thread->save(stream); |
| 306 | } |
| 307 | |
| 308 | void RendererImpl::addressSpaceGraphicsConsumerPostSave(void* consumer) { |
| 309 | RenderThread* thread = (RenderThread*)consumer; |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 310 | thread->resume(true); |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void RendererImpl::addressSpaceGraphicsConsumerRegisterPostLoadRenderThread(void* consumer) { |
| 314 | RenderThread* thread = (RenderThread*)consumer; |
| 315 | mAdditionalPostLoadRenderThreads.push_back(thread); |
| 316 | } |
| 317 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 318 | void RendererImpl::pauseAllPreSave() { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 319 | { |
| 320 | android::base::AutoLock lock(mChannelsLock); |
| 321 | if (mStopped) { |
| 322 | return; |
| 323 | } |
| 324 | for (const auto& c : mChannels) { |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 325 | c->renderThread()->pausePreSnapshot(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 326 | } |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 327 | } |
| 328 | { |
| 329 | android::base::AutoLock lock(mAddressSpaceRenderThreadLock); |
| 330 | for (const auto& thread : mAddressSpaceRenderThreads) { |
| 331 | thread->pausePreSnapshot(); |
| 332 | } |
| 333 | } |
| 334 | waitForProcessCleanup(); |
| 335 | } |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 336 | |
Yahan Zhou | d1c7e1e | 2023-11-09 14:59:26 -0800 | [diff] [blame] | 337 | void RendererImpl::resumeAll(bool waitForSave) { |
| 338 | { |
| 339 | android::base::AutoLock lock(mAddressSpaceRenderThreadLock); |
| 340 | for (const auto t : mAdditionalPostLoadRenderThreads) { |
| 341 | t->resume(waitForSave); |
| 342 | } |
| 343 | } |
| 344 | { |
| 345 | android::base::AutoLock lock(mChannelsLock); |
| 346 | if (mStopped) { |
| 347 | return; |
| 348 | } |
| 349 | for (const auto& c : mChannels) { |
| 350 | c->renderThread()->resume(waitForSave); |
| 351 | } |
| 352 | for (const auto& thread : mAddressSpaceRenderThreads) { |
| 353 | thread->resume(waitForSave); |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 354 | } |
| 355 | mAdditionalPostLoadRenderThreads.clear(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | repaintOpenGLDisplay(); |
| 359 | } |
| 360 | |
| 361 | void RendererImpl::save(android::base::Stream* stream, |
| 362 | const android::snapshot::ITextureSaverPtr& textureSaver) { |
| 363 | stream->putByte(mStopped); |
| 364 | if (mStopped) { |
| 365 | return; |
| 366 | } |
| 367 | auto fb = FrameBuffer::getFB(); |
| 368 | assert(fb); |
| 369 | fb->onSave(stream, textureSaver); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | bool RendererImpl::load(android::base::Stream* stream, |
| 373 | const android::snapshot::ITextureLoaderPtr& textureLoader) { |
| 374 | |
| 375 | #ifdef SNAPSHOT_PROFILE |
| 376 | android::base::System::Duration startTime = |
| 377 | android::base::System::get()->getUnixTimeUs(); |
| 378 | #endif |
| 379 | waitForProcessCleanup(); |
| 380 | #ifdef SNAPSHOT_PROFILE |
| 381 | printf("Previous session cleanup time: %lld ms\n", |
| 382 | (long long)(android::base::System::get() |
| 383 | ->getUnixTimeUs() - |
| 384 | startTime) / |
| 385 | 1000); |
| 386 | #endif |
| 387 | |
| 388 | mStopped = stream->getByte(); |
| 389 | if (mStopped) { |
| 390 | return true; |
| 391 | } |
| 392 | auto fb = FrameBuffer::getFB(); |
| 393 | assert(fb); |
| 394 | |
| 395 | bool res = true; |
| 396 | |
Yahan Zhou | b136537 | 2022-12-20 11:29:56 -0800 | [diff] [blame] | 397 | res = fb->onLoad(stream, textureLoader); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 398 | #if GFXSTREAM_ENABLE_HOST_GLES |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 399 | gl::EmulatedEglFenceSync::onLoad(stream); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 400 | #endif |
Yahan Zhou | b136537 | 2022-12-20 11:29:56 -0800 | [diff] [blame] | 401 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 402 | return res; |
| 403 | } |
| 404 | |
| 405 | void RendererImpl::fillGLESUsages(android_studio::EmulatorGLESUsages* usages) { |
| 406 | auto fb = FrameBuffer::getFB(); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 407 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 408 | if (fb) fb->fillGLESUsages(usages); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 409 | #endif |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Yahan Zhou | a774b99 | 2022-12-20 14:12:02 -0800 | [diff] [blame] | 412 | int RendererImpl::getScreenshot(unsigned int nChannels, unsigned int* width, unsigned int* height, |
| 413 | uint8_t* pixels, size_t* cPixels, int displayId = 0, |
| 414 | int desiredWidth = 0, int desiredHeight = 0, |
| 415 | int desiredRotation = 0, Rect rect = {{0, 0}, {0, 0}}) { |
Erwin Jansen | cc105d7 | 2021-03-12 17:23:39 -0800 | [diff] [blame] | 416 | auto fb = FrameBuffer::getFB(); |
Erwin Jansen | 49539e3 | 2021-03-15 12:17:46 -0700 | [diff] [blame] | 417 | if (fb) { |
Erwin Jansen | cc105d7 | 2021-03-12 17:23:39 -0800 | [diff] [blame] | 418 | return fb->getScreenshot(nChannels, width, height, pixels, cPixels, |
| 419 | displayId, desiredWidth, desiredHeight, |
Weilun Du | c8dd917 | 2021-03-24 16:06:17 -0700 | [diff] [blame] | 420 | desiredRotation, rect); |
Erwin Jansen | 49539e3 | 2021-03-15 12:17:46 -0700 | [diff] [blame] | 421 | } |
Erwin Jansen | cc105d7 | 2021-03-12 17:23:39 -0800 | [diff] [blame] | 422 | *cPixels = 0; |
| 423 | return -1; |
| 424 | } |
| 425 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 426 | void RendererImpl::setMultiDisplay(uint32_t id, |
| 427 | int32_t x, |
| 428 | int32_t y, |
| 429 | uint32_t w, |
| 430 | uint32_t h, |
| 431 | uint32_t dpi, |
| 432 | bool add) { |
| 433 | auto fb = FrameBuffer::getFB(); |
| 434 | if (fb) { |
| 435 | if (add) { |
| 436 | fb->createDisplay(&id); |
| 437 | fb->setDisplayPose(id, x, y, w, h, dpi); |
| 438 | } else { |
| 439 | fb->destroyDisplay(id); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | void RendererImpl::setMultiDisplayColorBuffer(uint32_t id, uint32_t cb) { |
| 445 | auto fb = FrameBuffer::getFB(); |
| 446 | if (fb) { |
| 447 | fb->setDisplayColorBuffer(id, cb); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | RendererImpl::HardwareStrings RendererImpl::getHardwareStrings() { |
| 452 | assert(mRenderWindow); |
| 453 | |
| 454 | const char* vendor = nullptr; |
| 455 | const char* renderer = nullptr; |
| 456 | const char* version = nullptr; |
| 457 | if (!mRenderWindow->getHardwareStrings(&vendor, &renderer, &version)) { |
| 458 | return {}; |
| 459 | } |
| 460 | HardwareStrings res; |
| 461 | res.vendor = vendor ? vendor : ""; |
| 462 | res.renderer = renderer ? renderer : ""; |
| 463 | res.version = version ? version : ""; |
| 464 | return res; |
| 465 | } |
| 466 | |
| 467 | void RendererImpl::setPostCallback(RendererImpl::OnPostCallback onPost, |
| 468 | void* context, |
| 469 | bool useBgraReadback, |
| 470 | uint32_t displayId) { |
| 471 | assert(mRenderWindow); |
| 472 | mRenderWindow->setPostCallback(onPost, context, displayId, useBgraReadback); |
| 473 | } |
| 474 | |
| 475 | bool RendererImpl::asyncReadbackSupported() { |
| 476 | assert(mRenderWindow); |
| 477 | return mRenderWindow->asyncReadbackSupported(); |
| 478 | } |
| 479 | |
| 480 | RendererImpl::ReadPixelsCallback |
| 481 | RendererImpl::getReadPixelsCallback() { |
| 482 | assert(mRenderWindow); |
| 483 | return mRenderWindow->getReadPixelsCallback(); |
| 484 | } |
| 485 | |
| 486 | RendererImpl::FlushReadPixelPipeline |
| 487 | RendererImpl::getFlushReadPixelPipeline() { |
| 488 | assert(mRenderWindow); |
| 489 | return mRenderWindow->getFlushReadPixelPipeline(); |
| 490 | } |
| 491 | |
| 492 | bool RendererImpl::showOpenGLSubwindow(FBNativeWindowType window, |
| 493 | int wx, |
| 494 | int wy, |
| 495 | int ww, |
| 496 | int wh, |
| 497 | int fbw, |
| 498 | int fbh, |
| 499 | float dpr, |
| 500 | float zRot, |
| 501 | bool deleteExisting, |
| 502 | bool hideWindow) { |
| 503 | assert(mRenderWindow); |
| 504 | return mRenderWindow->setupSubWindow(window, wx, wy, ww, wh, fbw, fbh, dpr, |
| 505 | zRot, deleteExisting, hideWindow); |
| 506 | } |
| 507 | |
| 508 | bool RendererImpl::destroyOpenGLSubwindow() { |
| 509 | assert(mRenderWindow); |
| 510 | return mRenderWindow->removeSubWindow(); |
| 511 | } |
| 512 | |
| 513 | void RendererImpl::setOpenGLDisplayRotation(float zRot) { |
| 514 | assert(mRenderWindow); |
| 515 | mRenderWindow->setRotation(zRot); |
| 516 | } |
| 517 | |
| 518 | void RendererImpl::setOpenGLDisplayTranslation(float px, float py) { |
| 519 | assert(mRenderWindow); |
| 520 | mRenderWindow->setTranslation(px, py); |
| 521 | } |
| 522 | |
| 523 | void RendererImpl::repaintOpenGLDisplay() { |
| 524 | assert(mRenderWindow); |
| 525 | mRenderWindow->repaint(); |
| 526 | } |
| 527 | |
| 528 | bool RendererImpl::hasGuestPostedAFrame() { |
| 529 | if (mRenderWindow) { |
| 530 | return mRenderWindow->hasGuestPostedAFrame(); |
| 531 | } |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | void RendererImpl::resetGuestPostedAFrame() { |
| 536 | if (mRenderWindow) { |
| 537 | mRenderWindow->resetGuestPostedAFrame(); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | void RendererImpl::setScreenMask(int width, int height, const unsigned char* rgbaData) { |
| 542 | assert(mRenderWindow); |
| 543 | mRenderWindow->setScreenMask(width, height, rgbaData); |
| 544 | } |
| 545 | |
Kaiyi Li | ca6b393 | 2022-10-07 12:29:18 -0700 | [diff] [blame] | 546 | void RendererImpl::onGuestGraphicsProcessCreate(uint64_t puid) { |
| 547 | FrameBuffer::getFB()->createGraphicsProcessResources(puid); |
| 548 | } |
| 549 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 550 | void RendererImpl::cleanupProcGLObjects(uint64_t puid) { |
Kaiyi Li | ca6b393 | 2022-10-07 12:29:18 -0700 | [diff] [blame] | 551 | std::unique_ptr<ProcessResources> resource = |
| 552 | FrameBuffer::getFB()->removeGraphicsProcessResources(puid); |
| 553 | mCleanupThread->cleanup(puid, std::move(resource)); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static struct AndroidVirtioGpuOps sVirtioGpuOps = { |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 557 | .create_buffer_with_handle = |
| 558 | [](uint64_t size, uint32_t handle) { |
| 559 | FrameBuffer::getFB()->createBufferWithHandle(size, handle); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 560 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 561 | .create_color_buffer_with_handle = |
Aaron Ruby | 550b6bd | 2024-05-27 15:26:24 -0400 | [diff] [blame] | 562 | [](uint32_t width, uint32_t height, uint32_t format, uint32_t fwkFormat, uint32_t handle, |
| 563 | bool linear) { |
| 564 | FrameBuffer::getFB()->createColorBufferWithHandle( |
| 565 | width, height, (GLenum)format, (FrameworkFormat)fwkFormat, handle, linear); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 566 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 567 | .open_color_buffer = [](uint32_t handle) { FrameBuffer::getFB()->openColorBuffer(handle); }, |
| 568 | .close_buffer = [](uint32_t handle) { FrameBuffer::getFB()->closeBuffer(handle); }, |
| 569 | .close_color_buffer = [](uint32_t handle) { FrameBuffer::getFB()->closeColorBuffer(handle); }, |
| 570 | .update_buffer = |
| 571 | [](uint32_t handle, uint64_t offset, uint64_t size, void* bytes) { |
| 572 | FrameBuffer::getFB()->updateBuffer(handle, offset, size, bytes); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 573 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 574 | .update_color_buffer = |
| 575 | [](uint32_t handle, int x, int y, int width, int height, uint32_t format, uint32_t type, |
| 576 | void* pixels) { |
| 577 | FrameBuffer::getFB()->updateColorBuffer(handle, x, y, width, height, format, type, |
| 578 | pixels); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 579 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 580 | .read_buffer = |
| 581 | [](uint32_t handle, uint64_t offset, uint64_t size, void* bytes) { |
| 582 | FrameBuffer::getFB()->readBuffer(handle, offset, size, bytes); |
| 583 | }, |
| 584 | .read_color_buffer = |
| 585 | [](uint32_t handle, int x, int y, int width, int height, uint32_t format, uint32_t type, |
| 586 | void* pixels) { |
| 587 | FrameBuffer::getFB()->readColorBuffer(handle, x, y, width, height, format, type, |
| 588 | pixels); |
| 589 | }, |
| 590 | .read_color_buffer_yuv = |
| 591 | [](uint32_t handle, int x, int y, int width, int height, void* pixels, |
| 592 | uint32_t pixels_size) { |
| 593 | FrameBuffer::getFB()->readColorBufferYUV(handle, x, y, width, height, pixels, |
| 594 | pixels_size); |
| 595 | }, |
| 596 | .post_color_buffer = [](uint32_t handle) { FrameBuffer::getFB()->post(handle); }, |
| 597 | .async_post_color_buffer = |
| 598 | [](uint32_t handle, CpuCompletionCallback cb) { |
| 599 | FrameBuffer::getFB()->postWithCallback(handle, cb); |
| 600 | }, |
| 601 | .repost = []() { FrameBuffer::getFB()->repost(); }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 602 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 603 | .create_yuv_textures = |
| 604 | [](uint32_t type, uint32_t count, int width, int height, uint32_t* output) { |
| 605 | FrameBuffer::getFB()->createYUVTextures(type, count, width, height, output); |
| 606 | }, |
| 607 | .destroy_yuv_textures = |
| 608 | [](uint32_t type, uint32_t count, uint32_t* textures) { |
| 609 | FrameBuffer::getFB()->destroyYUVTextures(type, count, textures); |
| 610 | }, |
| 611 | .update_yuv_textures = |
| 612 | [](uint32_t type, uint32_t* textures, void* privData, void* func) { |
| 613 | FrameBuffer::getFB()->updateYUVTextures(type, textures, privData, func); |
| 614 | }, |
| 615 | .swap_textures_and_update_color_buffer = |
| 616 | [](uint32_t colorbufferhandle, int x, int y, int width, int height, uint32_t format, |
| 617 | uint32_t type, uint32_t texture_type, uint32_t* textures, void* metadata) { |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 618 | FrameBuffer::getFB()->swapTexturesAndUpdateColorBuffer( |
| 619 | colorbufferhandle, x, y, width, height, format, type, texture_type, textures); |
| 620 | }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 621 | #endif |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 622 | .get_last_posted_color_buffer = |
| 623 | []() { return FrameBuffer::getFB()->getLastPostedColorBuffer(); }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 624 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 625 | .bind_color_buffer_to_texture = |
| 626 | [](uint32_t handle) { FrameBuffer::getFB()->bindColorBufferToTexture2(handle); }, |
| 627 | .get_global_egl_context = []() { return FrameBuffer::getFB()->getGlobalEGLContext(); }, |
| 628 | .wait_for_gpu = [](uint64_t eglsync) { FrameBuffer::getFB()->waitForGpu(eglsync); }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 629 | #endif |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 630 | .wait_for_gpu_vulkan = |
| 631 | [](uint64_t device, uint64_t fence) { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 632 | FrameBuffer::getFB()->waitForGpuVulkan(device, fence); |
| 633 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 634 | .set_guest_managed_color_buffer_lifetime = |
| 635 | [](bool guestManaged) { |
Huan Song | f42409f | 2022-06-15 12:31:11 -0700 | [diff] [blame] | 636 | FrameBuffer::getFB()->setGuestManagedColorBufferLifetime(guestManaged); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 637 | }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 638 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 639 | .async_wait_for_gpu_with_cb = |
| 640 | [](uint64_t eglsync, FenceCompletionCallback cb) { |
Lingfeng Yang | 0a63dfd | 2021-07-14 13:27:56 -0700 | [diff] [blame] | 641 | FrameBuffer::getFB()->asyncWaitForGpuWithCb(eglsync, cb); |
| 642 | }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 643 | #endif |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 644 | .async_wait_for_gpu_vulkan_with_cb = |
| 645 | [](uint64_t device, uint64_t fence, FenceCompletionCallback cb) { |
Lingfeng Yang | 0a63dfd | 2021-07-14 13:27:56 -0700 | [diff] [blame] | 646 | FrameBuffer::getFB()->asyncWaitForGpuVulkanWithCb(device, fence, cb); |
| 647 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 648 | .async_wait_for_gpu_vulkan_qsri_with_cb = |
| 649 | [](uint64_t image, FenceCompletionCallback cb) { |
Lingfeng Yang | 9e75025 | 2021-07-15 16:50:37 -0700 | [diff] [blame] | 650 | FrameBuffer::getFB()->asyncWaitForGpuVulkanQsriWithCb(image, cb); |
| 651 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 652 | .wait_for_gpu_vulkan_qsri = |
| 653 | [](uint64_t image) { FrameBuffer::getFB()->waitForGpuVulkanQsri(image); }, |
Jason Macnak | 303479f | 2023-01-17 15:39:10 -0800 | [diff] [blame] | 654 | .update_color_buffer_from_framework_format = |
| 655 | [](uint32_t handle, int x, int y, int width, int height, uint32_t fwkFormat, |
| 656 | uint32_t format, uint32_t type, void* pixels, void* pMetadata) { |
| 657 | FrameBuffer::getFB()->updateColorBufferFromFrameworkFormat( |
Bo Hu | e1a53fa | 2023-06-27 13:53:46 -0700 | [diff] [blame] | 658 | handle, x, y, width, height, (FrameworkFormat)fwkFormat, format, type, pixels, |
| 659 | pMetadata); |
Jason Macnak | 303479f | 2023-01-17 15:39:10 -0800 | [diff] [blame] | 660 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 661 | .platform_import_resource = |
| 662 | [](uint32_t handle, uint32_t info, void* resource) { |
Josh Simonot | a1a29a8 | 2022-05-12 12:03:35 -0400 | [diff] [blame] | 663 | return FrameBuffer::getFB()->platformImportResource(handle, info, resource); |
Lingfeng Yang | da09c0b | 2021-07-22 16:05:38 -0700 | [diff] [blame] | 664 | }, |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 665 | .platform_resource_info = |
| 666 | [](uint32_t handle, int32_t* width, int32_t* height, int32_t* internal_format) { |
Lingfeng Yang | da09c0b | 2021-07-22 16:05:38 -0700 | [diff] [blame] | 667 | return FrameBuffer::getFB()->getColorBufferInfo(handle, width, height, internal_format); |
| 668 | }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 669 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | 63a26f9 | 2021-04-14 13:43:42 -0700 | [diff] [blame] | 670 | .platform_create_shared_egl_context = |
| 671 | []() { return FrameBuffer::getFB()->platformCreateSharedEglContext(); }, |
| 672 | .platform_destroy_shared_egl_context = |
| 673 | [](void* context) { |
Lingfeng Yang | da09c0b | 2021-07-22 16:05:38 -0700 | [diff] [blame] | 674 | return FrameBuffer::getFB()->platformDestroySharedEglContext(context); |
| 675 | }, |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 676 | #endif |
Gurchetan Singh | 1cc4e5c | 2024-06-14 01:24:17 +0000 | [diff] [blame] | 677 | .wait_sync_color_buffer = |
| 678 | [](uint32_t handle) { return FrameBuffer::getFB()->waitSyncColorBuffer(handle); }, |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | struct AndroidVirtioGpuOps* RendererImpl::getVirtioGpuOps() { |
| 682 | return &sVirtioGpuOps; |
| 683 | } |
| 684 | |
Lingfeng Yang | bfe3c72 | 2020-10-29 10:33:18 -0700 | [diff] [blame] | 685 | void RendererImpl::snapshotOperationCallback(int op, int stage) { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 686 | using namespace android::snapshot; |
| 687 | switch (op) { |
Lingfeng Yang | bfe3c72 | 2020-10-29 10:33:18 -0700 | [diff] [blame] | 688 | case SNAPSHOTTER_OPERATION_LOAD: |
| 689 | if (stage == SNAPSHOTTER_STAGE_START) { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 690 | #ifdef SNAPSHOT_PROFILE |
| 691 | android::base::System::Duration startTime = |
| 692 | android::base::System::get()->getUnixTimeUs(); |
| 693 | #endif |
| 694 | mRenderWindow->setPaused(true); |
| 695 | cleanupRenderThreads(); |
| 696 | #ifdef SNAPSHOT_PROFILE |
| 697 | printf("Previous session suspend time: %lld ms\n", |
| 698 | (long long)(android::base::System::get() |
| 699 | ->getUnixTimeUs() - |
| 700 | startTime) / |
| 701 | 1000); |
| 702 | #endif |
| 703 | } |
Lingfeng Yang | bfe3c72 | 2020-10-29 10:33:18 -0700 | [diff] [blame] | 704 | if (stage == SNAPSHOTTER_STAGE_END) { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 705 | mRenderWindow->setPaused(false); |
| 706 | } |
| 707 | break; |
| 708 | default: |
| 709 | break; |
| 710 | } |
| 711 | } |
| 712 | |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 713 | void RendererImpl::setVsyncHz(int vsyncHz) { |
Lingfeng Yang | 66d9610 | 2021-07-30 16:01:15 -0700 | [diff] [blame] | 714 | if (mRenderWindow) { |
| 715 | mRenderWindow->setVsyncHz(vsyncHz); |
| 716 | } |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | void RendererImpl::setDisplayConfigs(int configId, int w, int h, |
| 720 | int dpiX, int dpiY) { |
Huan Song | c3a1aeb | 2021-09-22 08:27:19 -0700 | [diff] [blame] | 721 | if (mRenderWindow) { |
| 722 | mRenderWindow->setDisplayConfigs(configId, w, h, dpiX, dpiY); |
| 723 | } |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | void RendererImpl::setDisplayActiveConfig(int configId) { |
Huan Song | c3a1aeb | 2021-09-22 08:27:19 -0700 | [diff] [blame] | 727 | if (mRenderWindow) { |
| 728 | mRenderWindow->setDisplayActiveConfig(configId); |
| 729 | } |
Joshua Duong | e3b2c5c | 2022-05-31 08:27:47 -0700 | [diff] [blame] | 730 | } |
Lingfeng Yang | 66d9610 | 2021-07-30 16:01:15 -0700 | [diff] [blame] | 731 | |
Jason Macnak | e70b8e3 | 2023-01-20 13:59:35 -0800 | [diff] [blame] | 732 | const void* RendererImpl::getEglDispatch() { |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 733 | #if GFXSTREAM_ENABLE_HOST_GLES |
Jason Macnak | e70b8e3 | 2023-01-20 13:59:35 -0800 | [diff] [blame] | 734 | return FrameBuffer::getFB()->getEglDispatch(); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 735 | #else |
| 736 | return nullptr; |
| 737 | #endif |
Jason Macnak | e70b8e3 | 2023-01-20 13:59:35 -0800 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | const void* RendererImpl::getGles2Dispatch() { |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 741 | #if GFXSTREAM_ENABLE_HOST_GLES |
Jason Macnak | e70b8e3 | 2023-01-20 13:59:35 -0800 | [diff] [blame] | 742 | return FrameBuffer::getFB()->getGles2Dispatch(); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 743 | #else |
| 744 | return nullptr; |
| 745 | #endif |
Jason Macnak | e70b8e3 | 2023-01-20 13:59:35 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 748 | } // namespace gfxstream |