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