OLD | NEW |
| 1 // Copyright (c) 2012, 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 |
1 #include "jni/graphics.h" | 5 #include "jni/graphics.h" |
| 6 |
2 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
3 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
4 | 9 |
| 10 #include "jni/log.h" |
| 11 |
5 Graphics::Graphics(android_app* application, Timer* timer) | 12 Graphics::Graphics(android_app* application, Timer* timer) |
6 : application_(application), | 13 : application_(application), |
7 timer_(timer), | 14 timer_(timer), |
8 width_(0), | 15 width_(0), |
9 height_(0), | 16 height_(0), |
10 display_(EGL_NO_DISPLAY), | 17 display_(EGL_NO_DISPLAY), |
11 surface_(EGL_NO_SURFACE), | 18 surface_(EGL_NO_SURFACE), |
12 context_(EGL_NO_CONTEXT) { | 19 context_(EGL_NO_CONTEXT) { |
13 } | 20 } |
14 | 21 |
(...skipping 12 matching lines...) Expand all Loading... |
27 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 34 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
28 EGL_NONE | 35 EGL_NONE |
29 }; | 36 }; |
30 static const EGLint ctx_attribs[] = { | 37 static const EGLint ctx_attribs[] = { |
31 EGL_CONTEXT_CLIENT_VERSION, 2, | 38 EGL_CONTEXT_CLIENT_VERSION, 2, |
32 EGL_NONE | 39 EGL_NONE |
33 }; | 40 }; |
34 | 41 |
35 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 42 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
36 if (display_ != EGL_NO_DISPLAY) { | 43 if (display_ != EGL_NO_DISPLAY) { |
37 Log::Print("eglInitialize"); | 44 LOGI("eglInitialize"); |
38 if (eglInitialize(display_, NULL, NULL)) { | 45 if (eglInitialize(display_, NULL, NULL)) { |
39 Log::Print("eglChooseConfig"); | 46 LOGI("eglChooseConfig"); |
40 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) && | 47 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) && |
41 numConfigs > 0) { | 48 numConfigs > 0) { |
42 Log::Print("eglGetConfigAttrib"); | 49 LOGI("eglGetConfigAttrib"); |
43 if (eglGetConfigAttrib(display_, config, | 50 if (eglGetConfigAttrib(display_, config, |
44 EGL_NATIVE_VISUAL_ID, &format)) { | 51 EGL_NATIVE_VISUAL_ID, &format)) { |
45 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format); | 52 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format); |
46 surface_ = eglCreateWindowSurface(display_, config, | 53 surface_ = eglCreateWindowSurface(display_, config, |
47 (EGLNativeWindowType)application_->window, NULL); | 54 (EGLNativeWindowType)application_->window, NULL); |
48 if (surface_ != EGL_NO_SURFACE) { | 55 if (surface_ != EGL_NO_SURFACE) { |
49 Log::Print("eglCreateContext"); | 56 LOGI("eglCreateContext"); |
50 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, | 57 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, |
51 ctx_attribs); | 58 ctx_attribs); |
52 if (context_ != EGL_NO_CONTEXT) { | 59 if (context_ != EGL_NO_CONTEXT) { |
53 if (eglMakeCurrent(display_, surface_, surface_, context_) && | 60 if (eglMakeCurrent(display_, surface_, surface_, context_) && |
54 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) && | 61 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) && |
55 width_ > 0 && | 62 width_ > 0 && |
56 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) && | 63 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) && |
57 height_ > 0) { | 64 height_ > 0) { |
58 glViewport(0, 0, width_, height_); | 65 glViewport(0, 0, width_, height_); |
59 return 0; | 66 return 0; |
60 } | 67 } |
61 } | 68 } |
62 } | 69 } |
63 } | 70 } |
64 } | 71 } |
65 } | 72 } |
66 } | 73 } |
67 Log::PrintErr("Error starting graphics"); | 74 LOGE("Error starting graphics"); |
68 Stop(); | 75 Stop(); |
69 return -1; | 76 return -1; |
70 } | 77 } |
71 | 78 |
72 void Graphics::Stop() { | 79 void Graphics::Stop() { |
73 Log::Print("Stopping graphics"); | 80 LOGI("Stopping graphics"); |
74 if (display_ != EGL_NO_DISPLAY) { | 81 if (display_ != EGL_NO_DISPLAY) { |
75 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | 82 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
76 if (context_ != EGL_NO_CONTEXT) { | 83 if (context_ != EGL_NO_CONTEXT) { |
77 eglDestroyContext(display_, context_); | 84 eglDestroyContext(display_, context_); |
78 context_ = EGL_NO_CONTEXT; | 85 context_ = EGL_NO_CONTEXT; |
79 } | 86 } |
80 if (surface_ != EGL_NO_SURFACE) { | 87 if (surface_ != EGL_NO_SURFACE) { |
81 eglDestroySurface(display_, surface_); | 88 eglDestroySurface(display_, surface_); |
82 surface_ = EGL_NO_SURFACE; | 89 surface_ = EGL_NO_SURFACE; |
83 } | 90 } |
84 eglTerminate(display_); | 91 eglTerminate(display_); |
85 display_ = EGL_NO_DISPLAY; | 92 display_ = EGL_NO_DISPLAY; |
86 } | 93 } |
87 } | 94 } |
88 | 95 |
89 int32_t Graphics::Update() { | 96 int32_t Graphics::Update() { |
90 return 0; | 97 return 0; |
91 } | 98 } |
92 | |
OLD | NEW |