blob: 5e20d8a518818d576f7ed87d62f2d738d6f66c1a [file] [log] [blame]
Lingfeng Yangee4aea32020-10-29 08:52:13 -07001/*
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 Li1b6feaa2022-03-25 10:12:38 -070019#include <functional>
20#include <memory>
21#include <unordered_set>
22
Joshua Duongef2bbc22022-10-05 11:59:15 -070023#include "aemu/base/files/Stream.h"
Gurchetan Singh95b30dc2024-01-18 18:31:15 -080024
25#if GFXSTREAM_ENABLE_HOST_GLES
Lingfeng Yangbfe3c722020-10-29 10:33:18 -070026#include "renderControl_dec/renderControl_dec.h"
Jason Macnak09ec44f2022-07-27 15:02:27 -070027#include "RenderThreadInfoGl.h"
Gurchetan Singh95b30dc2024-01-18 18:31:15 -080028#endif
29
Jason Macnak09ec44f2022-07-27 15:02:27 -070030#include "RenderThreadInfoVk.h"
Lingfeng Yangee4aea32020-10-29 08:52:13 -070031
Gurchetan Singhfccd0482024-01-17 18:04:19 -080032#if GFXSTREAM_ENABLE_HOST_MAGMA
Gurchetan Singha8df2a32023-09-11 16:40:55 -070033#include "RenderThreadInfoMagma.h"
34#endif
35
Jason Macnaked0c9e62023-03-30 15:58:24 -070036namespace gfxstream {
37
Lingfeng Yangee4aea32020-10-29 08:52:13 -070038// A class used to model the state of each RenderThread related
39struct 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 Singh95b30dc2024-01-18 18:31:15 -080054#if GFXSTREAM_ENABLE_HOST_GLES
Jason Macnak09ec44f2022-07-27 15:02:27 -070055 void initGl();
Gurchetan Singh95b30dc2024-01-18 18:31:15 -080056#endif
Lingfeng Yangee4aea32020-10-29 08:52:13 -070057
Lingfeng Yangee4aea32020-10-29 08:52:13 -070058 // The unique id of owner guest process of this render thread
59 uint64_t m_puid = 0;
Jason Macnak49491452022-07-20 14:57:37 -070060 std::optional<std::string> m_processName;
Lingfeng Yangee4aea32020-10-29 08:52:13 -070061
Gurchetan Singh95b30dc2024-01-18 18:31:15 -080062#if GFXSTREAM_ENABLE_HOST_GLES
63 renderControl_decoder_context_t m_rcDec;
Jason Macnaked0c9e62023-03-30 15:58:24 -070064 std::optional<gl::RenderThreadInfoGl> m_glInfo;
Gurchetan Singh95b30dc2024-01-18 18:31:15 -080065#endif
66
Jason Macnaked0c9e62023-03-30 15:58:24 -070067 std::optional<vk::RenderThreadInfoVk> m_vkInfo;
Gurchetan Singha8df2a32023-09-11 16:40:55 -070068
Gurchetan Singhfccd0482024-01-17 18:04:19 -080069#if GFXSTREAM_ENABLE_HOST_MAGMA
Matt Sandye815f352023-03-10 18:28:35 +000070 std::optional<RenderThreadInfoMagma> m_magmaInfo;
Gurchetan Singha8df2a32023-09-11 16:40:55 -070071#endif
Jason Macnak22efd872022-07-20 16:54:23 -070072
Lingfeng Yang429aa7c2021-07-30 16:35:26 -070073 // Whether this thread was used to perform composition.
74 bool m_isCompositionThread = false;
75
Lingfeng Yangee4aea32020-10-29 08:52:13 -070076 // 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 Horn05386c52021-01-08 13:51:36 -080080
81 // Sometimes we can load render thread info before
82 // FrameBuffer repopulates the contexts.
83 void postLoadRefreshCurrentContextSurfacePtrs();
Lingfeng Yangee4aea32020-10-29 08:52:13 -070084};
85
Jason Macnaked0c9e62023-03-30 15:58:24 -070086} // namespace gfxstream
87
Lingfeng Yangee4aea32020-10-29 08:52:13 -070088#endif