xref: /aosp_15_r20/external/angle/src/libANGLE/ShareGroup.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 #include "libANGLE/ShareGroup.h"
11 
12 #include <algorithm>
13 #include <iterator>
14 
15 #include <EGL/eglext.h>
16 #include <platform/PlatformMethods.h>
17 
18 #include "common/debug.h"
19 #include "common/platform_helpers.h"
20 #include "libANGLE/Context.h"
21 #include "libANGLE/capture/FrameCapture.h"
22 #include "libANGLE/renderer/DisplayImpl.h"
23 #include "libANGLE/renderer/ShareGroupImpl.h"
24 
25 namespace egl
26 {
27 // ShareGroupState
ShareGroupState()28 ShareGroupState::ShareGroupState()
29     : mAnyContextWithRobustness(false), mAnyContextWithDisplayTextureShareGroup(false)
30 {}
31 ShareGroupState::~ShareGroupState() = default;
32 
addSharedContext(gl::Context * context)33 void ShareGroupState::addSharedContext(gl::Context *context)
34 {
35     mContexts.insert(std::pair(context->id().value, context));
36 
37     if (context->isRobustnessEnabled())
38     {
39         mAnyContextWithRobustness = true;
40     }
41     if (context->getState().hasDisplayTextureShareGroup())
42     {
43         mAnyContextWithDisplayTextureShareGroup = true;
44     }
45 }
46 
removeSharedContext(gl::Context * context)47 void ShareGroupState::removeSharedContext(gl::Context *context)
48 {
49     mContexts.erase(context->id().value);
50 }
51 
52 // ShareGroup
ShareGroup(rx::EGLImplFactory * factory)53 ShareGroup::ShareGroup(rx::EGLImplFactory *factory)
54     : mRefCount(1),
55       mImplementation(factory->createShareGroup(mState)),
56       mFrameCaptureShared(new angle::FrameCaptureShared)
57 {}
58 
~ShareGroup()59 ShareGroup::~ShareGroup()
60 {
61     SafeDelete(mImplementation);
62 }
63 
addRef()64 void ShareGroup::addRef()
65 {
66     // This is protected by global lock, so no atomic is required
67     mRefCount++;
68 }
69 
release(const Display * display)70 void ShareGroup::release(const Display *display)
71 {
72     if (--mRefCount == 0)
73     {
74         if (mImplementation)
75         {
76             mImplementation->onDestroy(display);
77         }
78         delete this;
79     }
80 }
81 
finishAllContexts()82 void ShareGroup::finishAllContexts()
83 {
84     for (auto shareContext : mState.getContexts())
85     {
86         if (shareContext.second->hasBeenCurrent() && !shareContext.second->isDestroyed())
87         {
88             shareContext.second->finish();
89         }
90     }
91 }
92 
addSharedContext(gl::Context * context)93 void ShareGroup::addSharedContext(gl::Context *context)
94 {
95     mState.addSharedContext(context);
96     mImplementation->onContextAdd();
97 }
98 
removeSharedContext(gl::Context * context)99 void ShareGroup::removeSharedContext(gl::Context *context)
100 {
101     mState.removeSharedContext(context);
102 }
103 }  // namespace egl
104