Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: gpu/command_buffer/tests/egl_test.cc

Issue 1674223002: Only call gles2::Terminate when all Display objects are deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@egl_test_branch
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gmock/include/gmock/gmock.h" 5 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 #include <EGL/egl.h> 8 #include <EGL/egl.h>
9 #include <GLES2/gl2.h>
9 10
10 // This file tests EGL basic interface for command_buffer_gles2, the mode of 11 // This file tests EGL basic interface for command_buffer_gles2, the mode of
11 // command buffer where the code is compiled as a standalone dynamic library and 12 // command buffer where the code is compiled as a standalone dynamic library and
12 // exposed through EGL API. 13 // exposed through EGL API.
13 namespace gpu { 14 namespace gpu {
14 15
15 using testing::Test; 16 using testing::Test;
16 17
17 TEST_F(Test, BasicEGLInitialization) { 18 TEST_F(Test, BasicEGLInitialization) {
18 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); 19 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
19 ASSERT_NE(display, EGL_NO_DISPLAY); 20 ASSERT_NE(display, EGL_NO_DISPLAY);
20 21
21 // Test for no crash even though passing nullptrs for major, minor. 22 // Test for no crash even though passing nullptrs for major, minor.
22 EGLBoolean success = eglInitialize(display, nullptr, nullptr); 23 EGLBoolean success = eglInitialize(display, nullptr, nullptr);
23 ASSERT_TRUE(success); 24 ASSERT_TRUE(success);
24 25
25 EGLint major = 0; 26 EGLint major = 0;
26 EGLint minor = 0; 27 EGLint minor = 0;
27 success = eglInitialize(display, &major, &minor); 28 success = eglInitialize(display, &major, &minor);
28 ASSERT_TRUE(success); 29 ASSERT_TRUE(success);
29 ASSERT_EQ(major, 1); 30 ASSERT_EQ(major, 1);
30 ASSERT_EQ(minor, 4); 31 ASSERT_EQ(minor, 4);
31 32
32 success = eglTerminate(display); 33 success = eglTerminate(display);
33 ASSERT_TRUE(success); 34 ASSERT_TRUE(success);
34 } 35 }
35 36
36 } // namespace gpu 37 class TestContext {
38 public:
39 TestContext() {
piman 2016/02/08 17:36:08 nit: indent. 'public:' should be at +1, the constr
Sami Väisänen 2016/02/09 10:05:27 Acknowledged.
40 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
41
42 eglInitialize(display_, nullptr, nullptr);
43
44 static const EGLint configAttribs[] = {
45 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
46 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
47 EGL_RED_SIZE, 8,
48 EGL_GREEN_SIZE, 8,
49 EGL_BLUE_SIZE, 8,
50 EGL_ALPHA_SIZE, 8,
51 EGL_NONE
52 };
53 EGLint numConfigs;
54 EGLConfig config;
55 eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs);
56
57 static const EGLint surfaceAttribs[] = {
58 EGL_WIDTH, 1,
59 EGL_HEIGHT, 1,
60 EGL_NONE
61 };
62 surface_ = eglCreatePbufferSurface(display_, config, surfaceAttribs);
63
64 static const EGLint contextAttribs[] = {
65 EGL_CONTEXT_CLIENT_VERSION, 2,
66 EGL_NONE
67 };
68 context_ = eglCreateContext(display_, config, nullptr, contextAttribs);
69 }
70
71 ~TestContext() {
72 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
73 eglDestroyContext(display_, context_);
74 eglDestroySurface(display_, surface_);
75 eglTerminate(display_);
76 }
77
78 bool IsValid() const
79 {
piman 2016/02/08 17:36:08 nit: { goes to end of previous line.
Sami Väisänen 2016/02/09 10:05:27 Acknowledged.
80 return display_ != EGL_NO_DISPLAY &&
81 context_ != EGL_NO_CONTEXT &&
82 surface_ != EGL_NO_SURFACE;
83 }
84
85 void TestCallGL()
86 {
piman 2016/02/08 17:36:08 nit: ditto
Sami Väisänen 2016/02/09 10:05:27 Acknowledged.
87 eglMakeCurrent(display_, surface_, surface_, context_);
88
89 typedef GL_APICALL void GL_APIENTRY (*glEnableProc)(GLenum);
90
91 auto address = eglGetProcAddress("glEnable");
92 auto* glEnable = reinterpret_cast<glEnableProc>(address);
93 glEnable(GL_BLEND);
94
piman 2016/02/08 17:36:08 nit: remove redundant blank line
Sami Väisänen 2016/02/09 10:05:27 Acknowledged.
95 }
96
97 private:
98 TestContext(const TestContext&) = delete;
99 TestContext& operator=(const TestContext&) = delete;
100
101 private:
102 EGLDisplay display_;
103 EGLContext context_;
104 EGLSurface surface_;
105 };
106
107 // Test case for a workaround for an issue in gles2_conform_support.
108 //
109 // The problem is that every call to eglGetDisplay(EGL_DEFAULT_DISPLAY)
110 // returns a new display object and the construction of each display
111 // calls to establish a thread local store variable in where to store the
112 // current command buffer context.
113 // Likewise the destructor of display calls to free the same tls variable.
114 //
115 // When skia (nanobench) uses multiple instances of command buffer
116 // based contexts and one display is destroyed the TLS variable
117 // is also destroyed and subsequent command buffer GL calls using another
118 // context instance end up accessing free'ed TLS variable.
119 //
120 // Note that technically there's also a problem in SkCommandBufferContext
121 // since it calls eglTerminate for each display, but this is because
122 // the current command buffer egl implementation requires this.
123 // Overall this functionality is not aligned with the EGL spefication.
piman 2016/02/08 17:36:08 Can we fix that?
Sami Väisänen 2016/02/09 10:05:27 This would require some refactoring in the impleme
piman 2016/02/09 19:23:51 Right, can we do that? Otherwise it seems we're do
124 //
125 // This testcase tests that we can create multiple command buffer contexts
126 // and dispose them without affecting the other.
127 TEST(Test, MultipleDisplays) {
128
piman 2016/02/08 17:36:08 nit: no blank line
Sami Väisänen 2016/02/09 10:05:27 Acknowledged.
129 TestContext first;
130 ASSERT_TRUE(first.IsValid());
131
132 first.TestCallGL();
133
134 {
135 TestContext second;
136 ASSERT_TRUE(second.IsValid());
137
138 second.TestCallGL();
139 }
140
141 first.TestCallGL();
142 }
143
144 } // namespace gpu
145
OLDNEW
« no previous file with comments | « no previous file | gpu/gles2_conform_support/egl/display.cc » ('j') | gpu/gles2_conform_support/egl/display.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698