Hash :
c95ffadf
Author :
Date :
2023-07-24T13:00:32
Perform Display terminate(InternalCleanup) from makeCurrent() Current state: - Call to `eglTerminate()` is canceled if there are Contexts current. - All not current Contexts are invalidated in `eglTerminate()` call. - Full Display termination will happen only when last Context is actually destroyed in `eglDestroyContext()` or last active thread terminates (Android only). Problem: - Context is not marked invalid after it is unmade from current when `eglTerminate()` was already called. - If `eglDestroyContext()` was called while context was current, it will be destroyed when unmade from current - in this case actual Display termination will NOT happen. After this change: - Context immediately invalidated after it is unmade from current when `eglTerminate()` was already called. - Full Display termination will happen after the last Context is unmade from current (all Contexts are invalid). Bug: angleproject:6798 Test: angle_end2end_tests --gtest_filter=EGLDisplayTest.ContextLeakAfterTerminate* Change-Id: Idcce94b041649db58d3d879858fba99109347baf Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4708328 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Igor Nazarov <i.nazarov@samsung.com> Reviewed-by: Geoff Lang <geofflang@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 100
//
// Copyright 2022 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 <gtest/gtest.h>
#include <vector>
#include "test_utils/ANGLETest.h"
using namespace angle;
class EGLDisplayTest : public ANGLETest<>
{
protected:
EGLConfig chooseConfig(EGLDisplay display)
{
const EGLint attribs[] = {EGL_RED_SIZE,
8,
EGL_GREEN_SIZE,
8,
EGL_BLUE_SIZE,
8,
EGL_ALPHA_SIZE,
8,
EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE,
EGL_PBUFFER_BIT,
EGL_NONE};
EGLConfig config = EGL_NO_CONFIG_KHR;
EGLint count = 0;
EXPECT_EGL_TRUE(eglChooseConfig(display, attribs, &config, 1, &count));
EXPECT_EGL_TRUE(count > 0);
return config;
}
EGLContext createContext(EGLDisplay display, EGLConfig config)
{
const EGLint attribs[] = {EGL_CONTEXT_MAJOR_VERSION, 2, EGL_NONE};
EGLContext context = eglCreateContext(display, config, nullptr, attribs);
EXPECT_NE(context, EGL_NO_CONTEXT);
return context;
}
EGLSurface createSurface(EGLDisplay display, EGLConfig config)
{
const EGLint attribs[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
EGLSurface surface = eglCreatePbufferSurface(display, config, attribs);
EXPECT_NE(surface, EGL_NO_SURFACE);
return surface;
}
};
// Tests that an EGLDisplay can be re-initialized.
TEST_P(EGLDisplayTest, InitializeTerminateInitialize)
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr) != EGL_FALSE);
EXPECT_EGL_TRUE(eglTerminate(display) != EGL_FALSE);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr) != EGL_FALSE);
}
// Tests current Context leaking when call eglTerminate() while it is current.
TEST_P(EGLDisplayTest, ContextLeakAfterTerminate)
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr));
EGLConfig config = chooseConfig(display);
EGLContext context = createContext(display, config);
EGLSurface surface = createSurface(display, config);
// Make "context" current.
EXPECT_EGL_TRUE(eglMakeCurrent(display, surface, surface, context));
// Terminate display while "context" is current.
EXPECT_EGL_TRUE(eglTerminate(display));
// Unmake "context" from current and allow Display to actually terminate.
(void)eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
// Get EGLDisplay again.
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// Check if Display was actually terminated.
EGLint val;
EXPECT_EGL_FALSE(eglQueryContext(display, context, EGL_CONTEXT_CLIENT_TYPE, &val));
EXPECT_EQ(eglGetError(), EGL_NOT_INITIALIZED);
}
ANGLE_INSTANTIATE_TEST(EGLDisplayTest,
WithNoFixture(ES2_D3D9()),
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_OPENGL()),
WithNoFixture(ES3_VULKAN()));