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