Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef _LIB_OPENGL_RENDER_THREAD_INFO_H |
| 17 | #define _LIB_OPENGL_RENDER_THREAD_INFO_H |
| 18 | |
Kaiyi Li | 1b6feaa | 2022-03-25 10:12:38 -0700 | [diff] [blame] | 19 | #include <functional> |
| 20 | #include <memory> |
| 21 | #include <unordered_set> |
| 22 | |
Joshua Duong | ef2bbc2 | 2022-10-05 11:59:15 -0700 | [diff] [blame] | 23 | #include "aemu/base/files/Stream.h" |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 24 | |
| 25 | #if GFXSTREAM_ENABLE_HOST_GLES |
Lingfeng Yang | bfe3c72 | 2020-10-29 10:33:18 -0700 | [diff] [blame] | 26 | #include "renderControl_dec/renderControl_dec.h" |
Jason Macnak | 09ec44f | 2022-07-27 15:02:27 -0700 | [diff] [blame] | 27 | #include "RenderThreadInfoGl.h" |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 28 | #endif |
| 29 | |
Jason Macnak | 09ec44f | 2022-07-27 15:02:27 -0700 | [diff] [blame] | 30 | #include "RenderThreadInfoVk.h" |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 31 | |
Gurchetan Singh | fccd048 | 2024-01-17 18:04:19 -0800 | [diff] [blame] | 32 | #if GFXSTREAM_ENABLE_HOST_MAGMA |
Gurchetan Singh | a8df2a3 | 2023-09-11 16:40:55 -0700 | [diff] [blame] | 33 | #include "RenderThreadInfoMagma.h" |
| 34 | #endif |
| 35 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 36 | namespace gfxstream { |
| 37 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 38 | // A class used to model the state of each RenderThread related |
| 39 | struct RenderThreadInfo { |
| 40 | // Create new instance. Only call this once per thread. |
| 41 | // Future callls to get() will return this instance until |
| 42 | // it is destroyed. |
| 43 | RenderThreadInfo(); |
| 44 | |
| 45 | // Destructor. |
| 46 | ~RenderThreadInfo(); |
| 47 | |
| 48 | // Return the current thread's instance, if any, or NULL. |
| 49 | static RenderThreadInfo* get(); |
| 50 | |
| 51 | // Loop over all active render thread infos |
| 52 | static void forAllRenderThreadInfos(std::function<void(RenderThreadInfo*)>); |
| 53 | |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 54 | #if GFXSTREAM_ENABLE_HOST_GLES |
Jason Macnak | 09ec44f | 2022-07-27 15:02:27 -0700 | [diff] [blame] | 55 | void initGl(); |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 56 | #endif |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 57 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 58 | // The unique id of owner guest process of this render thread |
| 59 | uint64_t m_puid = 0; |
Jason Macnak | 4949145 | 2022-07-20 14:57:37 -0700 | [diff] [blame] | 60 | std::optional<std::string> m_processName; |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 61 | |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 62 | #if GFXSTREAM_ENABLE_HOST_GLES |
| 63 | renderControl_decoder_context_t m_rcDec; |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 64 | std::optional<gl::RenderThreadInfoGl> m_glInfo; |
Gurchetan Singh | 95b30dc | 2024-01-18 18:31:15 -0800 | [diff] [blame] | 65 | #endif |
| 66 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 67 | std::optional<vk::RenderThreadInfoVk> m_vkInfo; |
Gurchetan Singh | a8df2a3 | 2023-09-11 16:40:55 -0700 | [diff] [blame] | 68 | |
Gurchetan Singh | fccd048 | 2024-01-17 18:04:19 -0800 | [diff] [blame] | 69 | #if GFXSTREAM_ENABLE_HOST_MAGMA |
Matt Sandy | e815f35 | 2023-03-10 18:28:35 +0000 | [diff] [blame] | 70 | std::optional<RenderThreadInfoMagma> m_magmaInfo; |
Gurchetan Singh | a8df2a3 | 2023-09-11 16:40:55 -0700 | [diff] [blame] | 71 | #endif |
Jason Macnak | 22efd87 | 2022-07-20 16:54:23 -0700 | [diff] [blame] | 72 | |
Lingfeng Yang | 429aa7c | 2021-07-30 16:35:26 -0700 | [diff] [blame] | 73 | // Whether this thread was used to perform composition. |
| 74 | bool m_isCompositionThread = false; |
| 75 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 76 | // Functions to save / load a snapshot |
| 77 | // They must be called after Framebuffer snapshot |
| 78 | void onSave(android::base::Stream* stream); |
| 79 | bool onLoad(android::base::Stream* stream); |
Doug Horn | 05386c5 | 2021-01-08 13:51:36 -0800 | [diff] [blame] | 80 | |
| 81 | // Sometimes we can load render thread info before |
| 82 | // FrameBuffer repopulates the contexts. |
| 83 | void postLoadRefreshCurrentContextSurfacePtrs(); |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 86 | } // namespace gfxstream |
| 87 | |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 88 | #endif |