• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 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 #include "libANGLE/renderer/gl/egl/ContextEGL.h"
8 
9 #include "libANGLE/renderer/gl/FramebufferGL.h"
10 #include "libANGLE/renderer/gl/StateManagerGL.h"
11 
12 namespace rx
13 {
14 
ContextEGL(const gl::State & state,gl::ErrorSet * errorSet,const std::shared_ptr<RendererEGL> & renderer,RobustnessVideoMemoryPurgeStatus robustnessVideoMemoryPurgeStatus)15 ContextEGL::ContextEGL(const gl::State &state,
16                        gl::ErrorSet *errorSet,
17                        const std::shared_ptr<RendererEGL> &renderer,
18                        RobustnessVideoMemoryPurgeStatus robustnessVideoMemoryPurgeStatus)
19     : ContextGL(state, errorSet, renderer, robustnessVideoMemoryPurgeStatus), mRendererEGL(renderer)
20 {}
21 
~ContextEGL()22 ContextEGL::~ContextEGL() {}
23 
onMakeCurrent(const gl::Context * context)24 angle::Result ContextEGL::onMakeCurrent(const gl::Context *context)
25 {
26     if (!context->isCurrent() && context->isExternal())
27     {
28         if (!mExtState)
29         {
30             mExtState        = std::make_unique<ExternalContextState>();
31             const auto &caps = getNativeCaps();
32             mExtState->textureBindings.resize(
33                 static_cast<size_t>(caps.maxCombinedTextureImageUnits));
34         }
35         getStateManager()->syncFromNativeContext(getNativeExtensions(), mExtState.get());
36 
37         // Use current FBO as the default framebuffer when the external context is current.
38         gl::Framebuffer *framebuffer = mState.getDefaultFramebuffer();
39         GetImplAs<FramebufferGL>(framebuffer)
40             ->updateDefaultFramebufferID(mExtState->framebufferBinding);
41     }
42     return ContextGL::onMakeCurrent(context);
43 }
44 
onUnMakeCurrent(const gl::Context * context)45 angle::Result ContextEGL::onUnMakeCurrent(const gl::Context *context)
46 {
47     if (context->saveAndRestoreState())
48     {
49         ASSERT(context->isExternal());
50         ASSERT(mExtState);
51         getStateManager()->restoreNativeContext(getNativeExtensions(), mExtState.get());
52     }
53 
54     return ContextGL::onUnMakeCurrent(context);
55 }
56 
getContext() const57 EGLContext ContextEGL::getContext() const
58 {
59     return mRendererEGL->getContext();
60 }
61 
62 }  // namespace rx
63