• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 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 // ContextCGL:
7 //   Mac-specific subclass of ContextGL.
8 //
9 
10 #include "libANGLE/renderer/gl/cgl/ContextCGL.h"
11 
12 #include "libANGLE/Context.h"
13 #include "libANGLE/Display.h"
14 #include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
15 
16 #if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
17 
18 namespace rx
19 {
20 
ContextCGL(DisplayCGL * display,const gl::State & state,gl::ErrorSet * errorSet,const std::shared_ptr<RendererGL> & renderer,bool usesDiscreteGPU)21 ContextCGL::ContextCGL(DisplayCGL *display,
22                        const gl::State &state,
23                        gl::ErrorSet *errorSet,
24                        const std::shared_ptr<RendererGL> &renderer,
25                        bool usesDiscreteGPU)
26     : ContextGL(state, errorSet, renderer, RobustnessVideoMemoryPurgeStatus::NOT_REQUESTED),
27       mUsesDiscreteGpu(usesDiscreteGPU),
28       mReleasedDiscreteGpu(false)
29 {
30     if (mUsesDiscreteGpu)
31     {
32         (void)display->referenceDiscreteGPU();
33     }
34 }
35 
releaseHighPowerGPU(gl::Context * context)36 egl::Error ContextCGL::releaseHighPowerGPU(gl::Context *context)
37 {
38     if (mUsesDiscreteGpu && !mReleasedDiscreteGpu)
39     {
40         mReleasedDiscreteGpu = true;
41         return GetImplAs<DisplayCGL>(context->getDisplay())->unreferenceDiscreteGPU();
42     }
43 
44     return egl::NoError();
45 }
46 
reacquireHighPowerGPU(gl::Context * context)47 egl::Error ContextCGL::reacquireHighPowerGPU(gl::Context *context)
48 {
49     if (mUsesDiscreteGpu && mReleasedDiscreteGpu)
50     {
51         mReleasedDiscreteGpu = false;
52         return GetImplAs<DisplayCGL>(context->getDisplay())->referenceDiscreteGPU();
53     }
54 
55     return egl::NoError();
56 }
57 
onDestroy(const gl::Context * context)58 void ContextCGL::onDestroy(const gl::Context *context)
59 {
60     if (mUsesDiscreteGpu && !mReleasedDiscreteGpu)
61     {
62         (void)GetImplAs<DisplayCGL>(context->getDisplay())->unreferenceDiscreteGPU();
63     }
64     ContextGL::onDestroy(context);
65 }
66 
67 }  // namespace rx
68 
69 #endif  // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
70