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