Hash :
01ee134b
Author :
Date :
2023-08-02T13:43:36
Revert "GL: Remove EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE" This reverts commit 4e0250f1926d25e39023c4ad7862ed358a0ec4b6. Reason for revert: Chromium change was reverted. crbug.com/1468956 Original change's description: > GL: Remove EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE > > Now that Chromium no longer uses it. > > Bug: angleproject:5509 > Change-Id: Ibb8d9cdc4d67dad77ca50437423b18d81e838203 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4724768 > Reviewed-by: Peng Huang <penghuang@chromium.org> > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Bug: angleproject:5509 Change-Id: Id8143b1715ec8162be9351437fbd34a2aa4c2e00 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4742521 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "libANGLE/renderer/gl/egl/ContextEGL.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
namespace rx
{
ContextEGL::ContextEGL(const gl::State &state,
gl::ErrorSet *errorSet,
const std::shared_ptr<RendererEGL> &renderer,
RobustnessVideoMemoryPurgeStatus robustnessVideoMemoryPurgeStatus)
: ContextGL(state, errorSet, renderer, robustnessVideoMemoryPurgeStatus), mRendererEGL(renderer)
{}
ContextEGL::~ContextEGL() {}
angle::Result ContextEGL::onMakeCurrent(const gl::Context *context)
{
// If this context is wrapping an external native context, save state from
// that external context when first making this context current.
if (!mIsCurrent && context->isExternal())
{
// TODO: The following is done if saveAndRestoreState() until chrome is switched to using
// glAcquireExternalContextANGLE and drops usage of EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE.
// After that, this code can be removed. http://anglebug.com/5509
if (context->saveAndRestoreState())
{
acquireExternalContext(context);
}
}
mIsCurrent = true;
return ContextGL::onMakeCurrent(context);
}
void ContextEGL::acquireExternalContext(const gl::Context *context)
{
ASSERT(context->isExternal());
if (!mExtState)
{
mExtState = std::make_unique<ExternalContextState>();
const auto &caps = getCaps();
mExtState->textureBindings.resize(static_cast<size_t>(caps.maxCombinedTextureImageUnits));
}
getStateManager()->syncFromNativeContext(getNativeExtensions(), mExtState.get());
// Use current FBO as the default framebuffer when the external context is current.
// First save the current ID of the default framebuffer to restore in
// onUnMakeCurrent().
gl::Framebuffer *framebuffer = mState.getDefaultFramebuffer();
auto framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
mPrevDefaultFramebufferID = framebufferGL->getFramebufferID();
framebufferGL->updateDefaultFramebufferID(mExtState->framebufferBinding);
}
angle::Result ContextEGL::onUnMakeCurrent(const gl::Context *context)
{
mIsCurrent = false;
if (context->isExternal() && context->saveAndRestoreState())
{
releaseExternalContext(context);
}
return ContextGL::onUnMakeCurrent(context);
}
void ContextEGL::releaseExternalContext(const gl::Context *context)
{
ASSERT(context->isExternal());
ASSERT(mExtState);
getStateManager()->restoreNativeContext(getNativeExtensions(), mExtState.get());
// If the default framebuffer exists, update its ID (note that there can
// be multiple consecutive onUnMakeCurrent() calls in destruction, and
// the default FBO will have been unset by the first one).
gl::Framebuffer *framebuffer = mState.getDefaultFramebuffer();
if (framebuffer)
{
auto framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
framebufferGL->updateDefaultFramebufferID(mPrevDefaultFramebufferID);
}
}
EGLContext ContextEGL::getContext() const
{
return mRendererEGL->getContext();
}
} // namespace rx