• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <functional>
20 #include <memory>
21 #include <unordered_set>
22 
23 #include "RenderContext.h"
24 #include "StalePtrRegistry.h"
25 #include "SyncThread.h"
26 #include "VkDecoder.h"
27 #include "WindowSurface.h"
28 #include "base/Stream.h"
29 #include "gles1_dec/GLESv1Decoder.h"
30 #include "gles2_dec/GLESv2Decoder.h"
31 #include "renderControl_dec/renderControl_dec.h"
32 
33 typedef uint32_t HandleType;
34 typedef std::unordered_set<HandleType> ThreadContextSet;
35 typedef std::unordered_set<HandleType> WindowSurfaceSet;
36 
37 // A class used to model the state of each RenderThread related
38 struct RenderThreadInfo {
39     // Create new instance. Only call this once per thread.
40     // Future callls to get() will return this instance until
41     // it is destroyed.
42     RenderThreadInfo();
43 
44     // Destructor.
45     ~RenderThreadInfo();
46 
47     // Return the current thread's instance, if any, or NULL.
48     static RenderThreadInfo* get();
49 
50     // Loop over all active render thread infos
51     static void forAllRenderThreadInfos(std::function<void(RenderThreadInfo*)>);
52 
53     // Current EGL context, draw surface and read surface.
54     HandleType currContextHandleFromLoad;
55     HandleType currDrawSurfHandleFromLoad;
56     HandleType currReadSurfHandleFromLoad;
57 
58     RenderContextPtr currContext;
59     WindowSurfacePtr currDrawSurf;
60     WindowSurfacePtr currReadSurf;
61 
62     // Decoder states.
63     GLESv1Decoder                   m_glDec;
64     GLESv2Decoder                   m_gl2Dec;
65     renderControl_decoder_context_t m_rcDec;
66     std::unique_ptr<VkDecoder> m_vkDec;
67 
68     // All the contexts that are created by this render thread.
69     // New emulator manages contexts in guest process level,
70     // m_contextSet should be deprecated. It is only kept for
71     // backward compatibility reason.
72     ThreadContextSet                m_contextSet;
73     // all the window surfaces that are created by this render thread
74     WindowSurfaceSet                m_windowSet;
75 
76     // The unique id of owner guest process of this render thread
77     uint64_t                        m_puid = 0;
78 
79     // Functions to save / load a snapshot
80     // They must be called after Framebuffer snapshot
81     void onSave(android::base::Stream* stream);
82     bool onLoad(android::base::Stream* stream);
83 
84     // Sometimes we can load render thread info before
85     // FrameBuffer repopulates the contexts.
86     void postLoadRefreshCurrentContextSurfacePtrs();
87 };
88 
89 #endif
90