xref: /aosp_15_r20/external/angle/src/libANGLE/ShareGroup.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2023 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // ShareGroup.h: Defines the egl::ShareGroup class, representing the collection of contexts in a
8*8975f5c5SAndroid Build Coastguard Worker // share group.
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_SHAREGROUP_H_
11*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_SHAREGROUP_H_
12*8975f5c5SAndroid Build Coastguard Worker 
13*8975f5c5SAndroid Build Coastguard Worker #include <mutex>
14*8975f5c5SAndroid Build Coastguard Worker #include <vector>
15*8975f5c5SAndroid Build Coastguard Worker 
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
17*8975f5c5SAndroid Build Coastguard Worker 
18*8975f5c5SAndroid Build Coastguard Worker namespace gl
19*8975f5c5SAndroid Build Coastguard Worker {
20*8975f5c5SAndroid Build Coastguard Worker class Context;
21*8975f5c5SAndroid Build Coastguard Worker }  // namespace gl
22*8975f5c5SAndroid Build Coastguard Worker 
23*8975f5c5SAndroid Build Coastguard Worker namespace rx
24*8975f5c5SAndroid Build Coastguard Worker {
25*8975f5c5SAndroid Build Coastguard Worker class EGLImplFactory;
26*8975f5c5SAndroid Build Coastguard Worker class ShareGroupImpl;
27*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
28*8975f5c5SAndroid Build Coastguard Worker 
29*8975f5c5SAndroid Build Coastguard Worker namespace egl
30*8975f5c5SAndroid Build Coastguard Worker {
31*8975f5c5SAndroid Build Coastguard Worker using ContextMap = angle::HashMap<GLuint, gl::Context *>;
32*8975f5c5SAndroid Build Coastguard Worker 
33*8975f5c5SAndroid Build Coastguard Worker class ShareGroupState final : angle::NonCopyable
34*8975f5c5SAndroid Build Coastguard Worker {
35*8975f5c5SAndroid Build Coastguard Worker   public:
36*8975f5c5SAndroid Build Coastguard Worker     ShareGroupState();
37*8975f5c5SAndroid Build Coastguard Worker     ~ShareGroupState();
38*8975f5c5SAndroid Build Coastguard Worker 
getContexts()39*8975f5c5SAndroid Build Coastguard Worker     const ContextMap &getContexts() const { return mContexts; }
40*8975f5c5SAndroid Build Coastguard Worker     void addSharedContext(gl::Context *context);
41*8975f5c5SAndroid Build Coastguard Worker     void removeSharedContext(gl::Context *context);
42*8975f5c5SAndroid Build Coastguard Worker 
hasAnyContextWithRobustness()43*8975f5c5SAndroid Build Coastguard Worker     bool hasAnyContextWithRobustness() const { return mAnyContextWithRobustness; }
hasAnyContextWithDisplayTextureShareGroup()44*8975f5c5SAndroid Build Coastguard Worker     bool hasAnyContextWithDisplayTextureShareGroup() const
45*8975f5c5SAndroid Build Coastguard Worker     {
46*8975f5c5SAndroid Build Coastguard Worker         return mAnyContextWithDisplayTextureShareGroup;
47*8975f5c5SAndroid Build Coastguard Worker     }
48*8975f5c5SAndroid Build Coastguard Worker 
49*8975f5c5SAndroid Build Coastguard Worker   private:
50*8975f5c5SAndroid Build Coastguard Worker     // The list of contexts within the share group
51*8975f5c5SAndroid Build Coastguard Worker     ContextMap mContexts;
52*8975f5c5SAndroid Build Coastguard Worker 
53*8975f5c5SAndroid Build Coastguard Worker     // Whether any context in the share group has robustness enabled.  If any context in the share
54*8975f5c5SAndroid Build Coastguard Worker     // group is robust, any program created in any context of the share group must have robustness
55*8975f5c5SAndroid Build Coastguard Worker     // enabled.  This is because programs are shared between the share group contexts.
56*8975f5c5SAndroid Build Coastguard Worker     bool mAnyContextWithRobustness;
57*8975f5c5SAndroid Build Coastguard Worker 
58*8975f5c5SAndroid Build Coastguard Worker     // Whether any context in the share group uses display shared textures.  This functionality is
59*8975f5c5SAndroid Build Coastguard Worker     // provided by ANGLE_display_texture_share_group and allows textures to be shared between
60*8975f5c5SAndroid Build Coastguard Worker     // contexts that are not in the same share group.
61*8975f5c5SAndroid Build Coastguard Worker     bool mAnyContextWithDisplayTextureShareGroup;
62*8975f5c5SAndroid Build Coastguard Worker };
63*8975f5c5SAndroid Build Coastguard Worker 
64*8975f5c5SAndroid Build Coastguard Worker class ShareGroup final : angle::NonCopyable
65*8975f5c5SAndroid Build Coastguard Worker {
66*8975f5c5SAndroid Build Coastguard Worker   public:
67*8975f5c5SAndroid Build Coastguard Worker     ShareGroup(rx::EGLImplFactory *factory);
68*8975f5c5SAndroid Build Coastguard Worker 
69*8975f5c5SAndroid Build Coastguard Worker     void addRef();
70*8975f5c5SAndroid Build Coastguard Worker 
71*8975f5c5SAndroid Build Coastguard Worker     void release(const egl::Display *display);
72*8975f5c5SAndroid Build Coastguard Worker 
getImplementation()73*8975f5c5SAndroid Build Coastguard Worker     rx::ShareGroupImpl *getImplementation() const { return mImplementation; }
74*8975f5c5SAndroid Build Coastguard Worker 
generateFramebufferSerial()75*8975f5c5SAndroid Build Coastguard Worker     rx::UniqueSerial generateFramebufferSerial() { return mFramebufferSerialFactory.generate(); }
76*8975f5c5SAndroid Build Coastguard Worker 
getFrameCaptureShared()77*8975f5c5SAndroid Build Coastguard Worker     angle::FrameCaptureShared *getFrameCaptureShared() { return mFrameCaptureShared.get(); }
78*8975f5c5SAndroid Build Coastguard Worker 
79*8975f5c5SAndroid Build Coastguard Worker     void finishAllContexts();
80*8975f5c5SAndroid Build Coastguard Worker 
getContexts()81*8975f5c5SAndroid Build Coastguard Worker     const ContextMap &getContexts() const { return mState.getContexts(); }
82*8975f5c5SAndroid Build Coastguard Worker     void addSharedContext(gl::Context *context);
83*8975f5c5SAndroid Build Coastguard Worker     void removeSharedContext(gl::Context *context);
84*8975f5c5SAndroid Build Coastguard Worker 
85*8975f5c5SAndroid Build Coastguard Worker   protected:
86*8975f5c5SAndroid Build Coastguard Worker     ~ShareGroup();
87*8975f5c5SAndroid Build Coastguard Worker 
88*8975f5c5SAndroid Build Coastguard Worker   private:
89*8975f5c5SAndroid Build Coastguard Worker     size_t mRefCount;
90*8975f5c5SAndroid Build Coastguard Worker     rx::ShareGroupImpl *mImplementation;
91*8975f5c5SAndroid Build Coastguard Worker     rx::UniqueSerialFactory mFramebufferSerialFactory;
92*8975f5c5SAndroid Build Coastguard Worker 
93*8975f5c5SAndroid Build Coastguard Worker     // Note: we use a raw pointer here so we can exclude frame capture sources from the build.
94*8975f5c5SAndroid Build Coastguard Worker     std::unique_ptr<angle::FrameCaptureShared> mFrameCaptureShared;
95*8975f5c5SAndroid Build Coastguard Worker 
96*8975f5c5SAndroid Build Coastguard Worker     ShareGroupState mState;
97*8975f5c5SAndroid Build Coastguard Worker };
98*8975f5c5SAndroid Build Coastguard Worker 
99*8975f5c5SAndroid Build Coastguard Worker }  // namespace egl
100*8975f5c5SAndroid Build Coastguard Worker 
101*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_SHAREGROUP_H_
102