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

Side by Side Diff: runtime/embedders/openglui/android/android_graphics_handler.cc

Issue 12186002: Canvas API. There are still a number of things to do: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "embedders/openglui/android/android_graphics_handler.h" 5 #include "embedders/openglui/android/android_graphics_handler.h"
6 #include "embedders/openglui/common/log.h" 6 #include "embedders/openglui/common/log.h"
7 7
8 AndroidGraphicsHandler::AndroidGraphicsHandler(android_app* application) 8 AndroidGraphicsHandler::AndroidGraphicsHandler(android_app* application)
9 : GLGraphicsHandler(), 9 : GraphicsHandler(),
10 application_(application), 10 application_(application),
11 display_(EGL_NO_DISPLAY), 11 display_(EGL_NO_DISPLAY),
12 surface_(EGL_NO_SURFACE), 12 surface_(EGL_NO_SURFACE),
13 context_(EGL_NO_CONTEXT) { 13 context_(EGL_NO_CONTEXT) {
14 } 14 }
15 15
16 int32_t AndroidGraphicsHandler::Start() { 16 int32_t AndroidGraphicsHandler::Start() {
17 EGLint format, numConfigs; 17 EGLint format, numConfigs;
18 EGLConfig config; 18 EGLConfig config;
19 const EGLint attributes[] = { 19 const EGLint attributes[] = {
20 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 20 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
21 EGL_NONE 21 EGL_NONE
22 }; 22 };
23 static const EGLint ctx_attribs[] = { 23 static const EGLint ctx_attribs[] = {
24 EGL_CONTEXT_CLIENT_VERSION, 2, 24 EGL_CONTEXT_CLIENT_VERSION, 2,
25 EGL_NONE 25 EGL_NONE
26 }; 26 };
27 27
28 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); 28 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
29 if (display_ != EGL_NO_DISPLAY) { 29 if (display_ != EGL_NO_DISPLAY) {
30 LOGI("eglInitialize"); 30 LOGI("eglInitialize");
31 if (eglInitialize(display_, NULL, NULL)) { 31 if (eglInitialize(display_, NULL, NULL)) {
32 LOGI("eglChooseConfig"); 32 LOGI("eglChooseConfig");
33 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) && 33 if (eglChooseConfig(display_, attributes, &config, 1, &numConfigs) &&
34 numConfigs > 0) { 34 numConfigs > 0) {
35 LOGI("eglGetConfigAttrib"); 35 LOGI("eglGetConfigAttrib returned %d configs\n", numConfigs);
36 if (eglGetConfigAttrib(display_, config, 36 if (eglGetConfigAttrib(display_, config,
37 EGL_NATIVE_VISUAL_ID, &format)) { 37 EGL_NATIVE_VISUAL_ID, &format)) {
38 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format); 38 ANativeWindow_setBuffersGeometry(application_->window, 0, 0, format);
39 surface_ = eglCreateWindowSurface(display_, config, 39 surface_ = eglCreateWindowSurface(display_, config,
40 (EGLNativeWindowType)application_->window, NULL); 40 (EGLNativeWindowType)application_->window, NULL);
41 if (surface_ != EGL_NO_SURFACE) { 41 if (surface_ != EGL_NO_SURFACE) {
42 LOGI("eglCreateContext"); 42 LOGI("eglCreateContext");
43 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, 43 context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT,
44 ctx_attribs); 44 ctx_attribs);
45 if (context_ != EGL_NO_CONTEXT) { 45 if (context_ != EGL_NO_CONTEXT) {
46 if (eglMakeCurrent(display_, surface_, surface_, context_) && 46 if (eglMakeCurrent(display_, surface_, surface_, context_) &&
47 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) && 47 eglQuerySurface(display_, surface_, EGL_WIDTH, &width_) &&
48 width_ > 0 && 48 width_ > 0 &&
49 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) && 49 eglQuerySurface(display_, surface_, EGL_HEIGHT, &height_) &&
50 height_ > 0) { 50 height_ > 0) {
51 LOGI("Got dimensions %d x %d\n", width_, height_);
51 SetViewport(0, 0, width_, height_); 52 SetViewport(0, 0, width_, height_);
52 return 0; 53 LOGI("GL version %s\n", glGetString(GL_VERSION));
54 LOGI("GLSL version: %s\n",
55 glGetString(GL_SHADING_LANGUAGE_VERSION));
56 return GraphicsHandler::Start();
53 } 57 }
54 } 58 }
55 } 59 }
56 } 60 }
57 } 61 }
58 } 62 }
59 } 63 }
60 LOGE("Error starting graphics"); 64 LOGE("Error starting graphics");
61 Stop(); 65 Stop();
62 return -1; 66 return -1;
63 } 67 }
64 68
65 void AndroidGraphicsHandler::Stop() { 69 void AndroidGraphicsHandler::Stop() {
66 LOGI("Stopping graphics"); 70 LOGI("Stopping graphics");
71 GraphicsHandler::Stop();
67 if (display_ != EGL_NO_DISPLAY) { 72 if (display_ != EGL_NO_DISPLAY) {
68 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 73 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
69 if (context_ != EGL_NO_CONTEXT) { 74 if (context_ != EGL_NO_CONTEXT) {
70 eglDestroyContext(display_, context_); 75 eglDestroyContext(display_, context_);
71 context_ = EGL_NO_CONTEXT; 76 context_ = EGL_NO_CONTEXT;
72 } 77 }
73 if (surface_ != EGL_NO_SURFACE) { 78 if (surface_ != EGL_NO_SURFACE) {
74 eglDestroySurface(display_, surface_); 79 eglDestroySurface(display_, surface_);
75 surface_ = EGL_NO_SURFACE; 80 surface_ = EGL_NO_SURFACE;
76 } 81 }
77 eglTerminate(display_); 82 eglTerminate(display_);
78 display_ = EGL_NO_DISPLAY; 83 display_ = EGL_NO_DISPLAY;
79 } 84 }
80 } 85 }
81 86
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/android/android_graphics_handler.h ('k') | runtime/embedders/openglui/android/eventloop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698