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

Side by Side Diff: samples/android_sample/jni/graphics.cc

Issue 11467028: Migrate files to embedder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review fixes Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « samples/android_sample/jni/graphics.h ('k') | samples/android_sample/jni/input_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 #include "jni/graphics.h"
6
7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h>
9
10 #include "jni/log.h"
11
12 Graphics::Graphics(android_app* application, Timer* timer)
13 : application_(application),
14 timer_(timer),
15 width_(0),
16 height_(0),
17 display_(EGL_NO_DISPLAY),
18 surface_(EGL_NO_SURFACE),
19 context_(EGL_NO_CONTEXT) {
20 }
21
22 const int32_t& Graphics::height() {
23 return height_;
24 }
25
26 const int32_t& Graphics::width() {
27 return width_;
28 }
29
30 int32_t Graphics::Start() {
31 EGLint format, numConfigs, errorResult;
32 EGLConfig config;
33 const EGLint attributes[] = {
34 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
35 EGL_NONE
36 };
37 static const EGLint ctx_attribs[] = {
38 EGL_CONTEXT_CLIENT_VERSION, 2,
39 EGL_NONE
40 };
41
42 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
43 if (display_ != EGL_NO_DISPLAY) {
44 LOGI("eglInitialize");
45 if (eglInitialize(display_, NULL, NULL)) {
46 LOGI("eglChooseConfig");
47 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) &&
48 numConfigs > 0) {
49 LOGI("eglGetConfigAttrib");
50 if (eglGetConfigAttrib(display_, config,
51 EGL_NATIVE_VISUAL_ID, &format)) {
52 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format);
53 surface_ = eglCreateWindowSurface(display_, config,
54 (EGLNativeWindowType)application_->window, NULL);
55 if (surface_ != EGL_NO_SURFACE) {
56 LOGI("eglCreateContext");
57 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT,
58 ctx_attribs);
59 if (context_ != EGL_NO_CONTEXT) {
60 if (eglMakeCurrent(display_, surface_, surface_, context_) &&
61 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) &&
62 width_ > 0 &&
63 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) &&
64 height_ > 0) {
65 glViewport(0, 0, width_, height_);
66 return 0;
67 }
68 }
69 }
70 }
71 }
72 }
73 }
74 LOGE("Error starting graphics");
75 Stop();
76 return -1;
77 }
78
79 void Graphics::Stop() {
80 LOGI("Stopping graphics");
81 if (display_ != EGL_NO_DISPLAY) {
82 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
83 if (context_ != EGL_NO_CONTEXT) {
84 eglDestroyContext(display_, context_);
85 context_ = EGL_NO_CONTEXT;
86 }
87 if (surface_ != EGL_NO_SURFACE) {
88 eglDestroySurface(display_, surface_);
89 surface_ = EGL_NO_SURFACE;
90 }
91 eglTerminate(display_);
92 display_ = EGL_NO_DISPLAY;
93 }
94 }
95
96 int32_t Graphics::Update() {
97 return 0;
98 }
OLDNEW
« no previous file with comments | « samples/android_sample/jni/graphics.h ('k') | samples/android_sample/jni/input_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698