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

Side by Side Diff: remoting/client/jni/egl_thread_context.cc

Issue 2175913002: [Remoting Android] Make EglThreadContext create OpenGL ES 3 context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 5 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
« no previous file with comments | « remoting/client/jni/egl_thread_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/client/jni/egl_thread_context.h" 5 #include "remoting/client/jni/egl_thread_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace remoting { 9 namespace remoting {
10 10
11 EglThreadContext::EglThreadContext() { 11 EglThreadContext::EglThreadContext() {
12 DCHECK(thread_checker_.CalledOnValidThread()); 12 DCHECK(thread_checker_.CalledOnValidThread());
13 CHECK(eglGetCurrentDisplay() == EGL_NO_DISPLAY); 13 CHECK(eglGetCurrentDisplay() == EGL_NO_DISPLAY);
14 CHECK(eglGetCurrentContext() == EGL_NO_CONTEXT); 14 CHECK(eglGetCurrentContext() == EGL_NO_CONTEXT);
15 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); 15 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
16 if (!display_ || !eglInitialize(display_, NULL, NULL)) { 16 if (!display_ || !eglInitialize(display_, NULL, NULL)) {
17 LOG(FATAL) << "Failed to initialize EGL display."; 17 LOG(FATAL) << "Failed to initialize EGL display: " << eglGetError();
18 } 18 }
19 19
20 const EGLint config_attribs[] = { 20 if (CreateContextWithClientVersion(EGL_OPENGL_ES3_BIT, GlVersion::ES_3)) {
21 EGL_RED_SIZE, 8, 21 client_version_ = GlVersion::ES_3;
22 EGL_GREEN_SIZE, 8, 22 } else if (CreateContextWithClientVersion(EGL_OPENGL_ES2_BIT,
23 EGL_BLUE_SIZE, 8, 23 GlVersion::ES_2)) {
24 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 24 LOG(WARNING) << "OpenGL ES 3 context not supported."
25 EGL_NONE 25 << "Falled back to OpenGL ES 2";
26 }; 26 client_version_ = GlVersion::ES_2;
27 27 } else {
28 EGLint numConfigs; 28 LOG(FATAL) << "Failed to create context: " << eglGetError();
29 if (!eglChooseConfig(display_, config_attribs, &config_, 1, &numConfigs)) {
30 LOG(FATAL) << "Failed to choose config.";
31 }
32 const EGLint context_attribs[] = {
33 EGL_CONTEXT_CLIENT_VERSION, 2,
34 EGL_NONE
35 };
36 context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT,
37 context_attribs);
38 if (!context_) {
39 LOG(FATAL) << "Failed to create context.";
40 } 29 }
41 } 30 }
42 31
43 EglThreadContext::~EglThreadContext() { 32 EglThreadContext::~EglThreadContext() {
44 DCHECK(thread_checker_.CalledOnValidThread()); 33 DCHECK(thread_checker_.CalledOnValidThread());
45 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 34 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
46 eglDestroyContext(display_, context_); 35 eglDestroyContext(display_, context_);
47 if (surface_) { 36 if (surface_) {
48 eglDestroySurface(display_, surface_); 37 eglDestroySurface(display_, surface_);
49 } 38 }
50 eglTerminate(display_); 39 eglTerminate(display_);
51 } 40 }
52 41
53 void EglThreadContext::BindToWindow(EGLNativeWindowType window) { 42 void EglThreadContext::BindToWindow(EGLNativeWindowType window) {
54 DCHECK(thread_checker_.CalledOnValidThread()); 43 DCHECK(thread_checker_.CalledOnValidThread());
55 if (surface_) { 44 if (surface_) {
56 eglDestroySurface(display_, surface_); 45 eglDestroySurface(display_, surface_);
57 surface_ = EGL_NO_SURFACE; 46 surface_ = EGL_NO_SURFACE;
58 } 47 }
59 if (window) { 48 if (window) {
60 surface_ = eglCreateWindowSurface(display_, config_, window, NULL); 49 surface_ = eglCreateWindowSurface(display_, config_, window, NULL);
61 if (!surface_) { 50 if (!surface_) {
62 LOG(FATAL) << "Failed to create window surface."; 51 LOG(FATAL) << "Failed to create window surface: " << eglGetError();
63 } 52 }
64 } else { 53 } else {
65 surface_ = EGL_NO_SURFACE; 54 surface_ = EGL_NO_SURFACE;
66 } 55 }
67 if (!eglMakeCurrent(display_, surface_, surface_, context_)) { 56 if (!eglMakeCurrent(display_, surface_, surface_, context_)) {
68 LOG(FATAL) << "Failed to make current."; 57 LOG(FATAL) << "Failed to make current: " << eglGetError();
69 } 58 }
70 } 59 }
71 60
72 bool EglThreadContext::IsWindowBound() const { 61 bool EglThreadContext::IsWindowBound() const {
73 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
74 return surface_ != EGL_NO_SURFACE; 63 return surface_ != EGL_NO_SURFACE;
75 } 64 }
76 65
77 void EglThreadContext::SwapBuffers() { 66 bool EglThreadContext::SwapBuffers() {
78 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
79 DCHECK(IsWindowBound()); 68 if (!IsWindowBound()) {
69 return false;
70 }
80 if (!eglSwapBuffers(display_, surface_)) { 71 if (!eglSwapBuffers(display_, surface_)) {
81 LOG(FATAL) << "Failed to swap buffer."; 72 // Not fatal since the surface may be destroyed on a different thread
73 // earlier than the window is unbound. The context can still be reused
74 // after rebinding to the right window.
75 LOG(WARNING) << "Failed to swap buffer: " << eglGetError();
76 return false;
82 } 77 }
78 return true;
79 }
80
81 bool EglThreadContext::CreateContextWithClientVersion(
82 int renderable_type,
83 GlVersion client_version) {
84 DCHECK(client_version != GlVersion::UNKNOWN);
85 EGLint config_attribs[] = {
86 EGL_RED_SIZE, 8,
87 EGL_GREEN_SIZE, 8,
88 EGL_BLUE_SIZE, 8,
89 EGL_RENDERABLE_TYPE, renderable_type,
90 EGL_NONE
91 };
92
93 EGLint num_configs;
94 if (!eglChooseConfig(display_, config_attribs, &config_, 1, &num_configs)) {
95 LOG(WARNING) << "Failed to choose config: " << eglGetError();
96 return false;
97 }
98
99 EGLint context_attribs[] = {
100 EGL_CONTEXT_CLIENT_VERSION, static_cast<int>(client_version),
101 EGL_NONE
102 };
103 context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT,
104 context_attribs);
105 return context_ != EGL_NO_CONTEXT;
83 } 106 }
84 107
85 } // namespace remoting 108 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/egl_thread_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698