OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "embedders/openglui/android/android_graphics_handler.h" |
| 6 #include "embedders/openglui/common/log.h" |
| 7 |
| 8 AndroidGraphicsHandler::AndroidGraphicsHandler(android_app* application) |
| 9 : GLGraphicsHandler(), |
| 10 application_(application), |
| 11 display_(EGL_NO_DISPLAY), |
| 12 surface_(EGL_NO_SURFACE), |
| 13 context_(EGL_NO_CONTEXT) { |
| 14 } |
| 15 |
| 16 int32_t AndroidGraphicsHandler::Start() { |
| 17 EGLint format, numConfigs; |
| 18 EGLConfig config; |
| 19 const EGLint attributes[] = { |
| 20 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 21 EGL_NONE |
| 22 }; |
| 23 static const EGLint ctx_attribs[] = { |
| 24 EGL_CONTEXT_CLIENT_VERSION, 2, |
| 25 EGL_NONE |
| 26 }; |
| 27 |
| 28 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 29 if (display_ != EGL_NO_DISPLAY) { |
| 30 LOGI("eglInitialize"); |
| 31 if (eglInitialize(display_, NULL, NULL)) { |
| 32 LOGI("eglChooseConfig"); |
| 33 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) && |
| 34 numConfigs > 0) { |
| 35 LOGI("eglGetConfigAttrib"); |
| 36 if (eglGetConfigAttrib(display_, config, |
| 37 EGL_NATIVE_VISUAL_ID, &format)) { |
| 38 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format); |
| 39 surface_ = eglCreateWindowSurface(display_, config, |
| 40 (EGLNativeWindowType)application_->window, NULL); |
| 41 if (surface_ != EGL_NO_SURFACE) { |
| 42 LOGI("eglCreateContext"); |
| 43 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, |
| 44 ctx_attribs); |
| 45 if (context_ != EGL_NO_CONTEXT) { |
| 46 if (eglMakeCurrent(display_, surface_, surface_, context_) && |
| 47 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) && |
| 48 width_ > 0 && |
| 49 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) && |
| 50 height_ > 0) { |
| 51 SetViewport(0, 0, width_, height_); |
| 52 return 0; |
| 53 } |
| 54 } |
| 55 } |
| 56 } |
| 57 } |
| 58 } |
| 59 } |
| 60 LOGE("Error starting graphics"); |
| 61 Stop(); |
| 62 return -1; |
| 63 } |
| 64 |
| 65 void AndroidGraphicsHandler::Stop() { |
| 66 LOGI("Stopping graphics"); |
| 67 if (display_ != EGL_NO_DISPLAY) { |
| 68 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 69 if (context_ != EGL_NO_CONTEXT) { |
| 70 eglDestroyContext(display_, context_); |
| 71 context_ = EGL_NO_CONTEXT; |
| 72 } |
| 73 if (surface_ != EGL_NO_SURFACE) { |
| 74 eglDestroySurface(display_, surface_); |
| 75 surface_ = EGL_NO_SURFACE; |
| 76 } |
| 77 eglTerminate(display_); |
| 78 display_ = EGL_NO_DISPLAY; |
| 79 } |
| 80 } |
| 81 |
OLD | NEW |