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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/jni/egl_thread_context.cc
diff --git a/remoting/client/jni/egl_thread_context.cc b/remoting/client/jni/egl_thread_context.cc
index 53bf9c9b9ad6d26446b05bc47bbd46f2fed63145..87dbf7ab70ab05358a6c72ce70b8c600aae22838 100644
--- a/remoting/client/jni/egl_thread_context.cc
+++ b/remoting/client/jni/egl_thread_context.cc
@@ -14,29 +14,19 @@ EglThreadContext::EglThreadContext() {
CHECK(eglGetCurrentContext() == EGL_NO_CONTEXT);
display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (!display_ || !eglInitialize(display_, NULL, NULL)) {
- LOG(FATAL) << "Failed to initialize EGL display.";
+ LOG(FATAL) << "Failed to initialize EGL display: " << eglGetError();
}
- const EGLint config_attribs[] = {
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
-
- EGLint numConfigs;
- if (!eglChooseConfig(display_, config_attribs, &config_, 1, &numConfigs)) {
- LOG(FATAL) << "Failed to choose config.";
+ if (CreateContextWithClientVersion(EGL_OPENGL_ES3_BIT, 3)) {
+ client_version_ = 3;
+ return;
}
- const EGLint context_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
- context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT,
- context_attribs);
- if (!context_) {
- LOG(FATAL) << "Failed to create context.";
+ LOG(WARNING) << "Failed to create context for OpenGL ES 3. Falling back to "
+ << "OpenGL ES 2.";
+ if (CreateContextWithClientVersion(EGL_OPENGL_ES2_BIT, 2)) {
+ client_version_ = 2;
+ } else {
Sergey Ulanov 2016/07/22 20:12:34 nit: for consistency return above and remove else.
Yuwei 2016/07/22 21:22:39 Done.
+ LOG(FATAL) << "Failed to create context: " << eglGetError();
}
}
@@ -59,13 +49,13 @@ void EglThreadContext::BindToWindow(EGLNativeWindowType window) {
if (window) {
surface_ = eglCreateWindowSurface(display_, config_, window, NULL);
if (!surface_) {
- LOG(FATAL) << "Failed to create window surface.";
+ LOG(FATAL) << "Failed to create window surface: " << eglGetError();
}
} else {
surface_ = EGL_NO_SURFACE;
}
if (!eglMakeCurrent(display_, surface_, surface_, context_)) {
- LOG(FATAL) << "Failed to make current.";
+ LOG(FATAL) << "Failed to make current: " << eglGetError();
}
}
@@ -74,12 +64,53 @@ bool EglThreadContext::IsWindowBound() const {
return surface_ != EGL_NO_SURFACE;
}
-void EglThreadContext::SwapBuffers() {
+bool EglThreadContext::SwapBuffers() {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(IsWindowBound());
+ if (!IsWindowBound()) {
+ return false;
+ }
if (!eglSwapBuffers(display_, surface_)) {
- LOG(FATAL) << "Failed to swap buffer.";
+ // Not fatal since the surface may be destroyed on a different thread
+ // earlier than the window is unbound. The context can still be reused
+ // after rebinding to the right window.
+ LOG(WARNING) << "Failed to swap buffer: " << eglGetError();
+ return false;
+ }
+ return true;
+}
+
+bool EglThreadContext::CreateContextWithClientVersion(
+ unsigned int renderable_type,
+ int client_version) {
+ EGLint config_attribs[] = {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_RENDERABLE_TYPE, renderable_type,
+ EGL_NONE
+ };
+
+ EGLint numConfigs;
Sergey Ulanov 2016/07/22 20:12:34 num_configs
Yuwei 2016/07/22 21:22:39 Done.
+ if (!eglChooseConfig(display_, config_attribs, &config_, 1, &numConfigs)) {
+ LOG(WARNING) << "Failed to choose config: " << eglGetError();
+ return false;
+ }
+
+ EGLint context_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, client_version,
+ EGL_NONE
+ };
+ context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT,
+ context_attribs);
+ if (!context_) {
+ LOG(WARNING) << "Failed to create context: " << eglGetError();
Lambros 2016/07/22 20:36:07 You can maybe remove this log, as you are already
Yuwei 2016/07/22 21:22:39 Done.
+ return false;
}
+ return true;
+}
+
+int EglThreadContext::GetClientVersion() const {
+ return client_version_;
}
} // namespace remoting
« remoting/client/jni/egl_thread_context.h ('K') | « 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