Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include <GLES/gl.h> | 9 #include <GLES/gl.h> |
| 10 | 10 |
| 11 #include "GLWindowContext_android.h" | 11 #include "GLWindowContext_android.h" |
| 12 | 12 |
| 13 #include <android/native_window_jni.h> | |
|
djsollen
2016/06/09 18:34:21
add this back since you can remove it from the hea
| |
| 14 | |
| 15 namespace sk_app { | 13 namespace sk_app { |
| 16 | 14 |
| 17 // Most of the following 3 functions (GLWindowContext::Create, constructor, desc tructor) | 15 // Most of the following 3 functions (GLWindowContext::Create, constructor, desc tructor) |
| 18 // are copied from Unix/Win platform with unix/win changed to android | 16 // are copied from Unix/Win platform with unix/win changed to android |
| 19 | 17 |
| 20 // platform-dependent create | 18 // platform-dependent create |
| 21 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams & params) { | 19 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams & params) { |
| 22 GLWindowContext_android* ctx = new GLWindowContext_android(platformData, par ams); | 20 GLWindowContext_android* ctx = new GLWindowContext_android(platformData, par ams); |
| 23 if (!ctx->isValid()) { | 21 if (!ctx->isValid()) { |
| 24 delete ctx; | 22 delete ctx; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 36 // any config code here (particularly for msaa)? | 34 // any config code here (particularly for msaa)? |
| 37 | 35 |
| 38 this->initializeContext(platformData, params); | 36 this->initializeContext(platformData, params); |
| 39 } | 37 } |
| 40 | 38 |
| 41 GLWindowContext_android::~GLWindowContext_android() { | 39 GLWindowContext_android::~GLWindowContext_android() { |
| 42 this->destroyContext(); | 40 this->destroyContext(); |
| 43 } | 41 } |
| 44 | 42 |
| 45 void GLWindowContext_android::onInitializeContext(void* platformData, const Disp layParams& params) { | 43 void GLWindowContext_android::onInitializeContext(void* platformData, const Disp layParams& params) { |
| 46 ContextPlatformData_android* androidPlatformData = | 44 if (platformData != nullptr) { |
| 47 reinterpret_cast<ContextPlatformData_android*>(platformData); | 45 ContextPlatformData_android* androidPlatformData = |
| 46 reinterpret_cast<ContextPlatformData_android*>(platformData); | |
| 47 fNativeWindow = androidPlatformData->fNativeWindow; | |
| 48 } else { | |
| 49 SkASSERT(fNativeWindow); | |
| 50 } | |
| 48 | 51 |
| 49 fWidth = ANativeWindow_getWidth(androidPlatformData->fNativeWindow); | 52 |
| 50 fHeight = ANativeWindow_getHeight(androidPlatformData->fNativeWindow); | 53 fWidth = ANativeWindow_getWidth(fNativeWindow); |
| 54 fHeight = ANativeWindow_getHeight(fNativeWindow); | |
| 51 | 55 |
| 52 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 56 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 53 | 57 |
| 54 EGLint majorVersion; | 58 EGLint majorVersion; |
| 55 EGLint minorVersion; | 59 EGLint minorVersion; |
| 56 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 60 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
| 57 | 61 |
| 58 SkAssertResult(eglBindAPI(EGL_OPENGL_ES_API)); | 62 SkAssertResult(eglBindAPI(EGL_OPENGL_ES_API)); |
| 59 | 63 |
| 60 EGLint numConfigs = 0; | 64 EGLint numConfigs = 0; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 74 | 78 |
| 75 static const EGLint kEGLContextAttribsForOpenGLES[] = { | 79 static const EGLint kEGLContextAttribsForOpenGLES[] = { |
| 76 EGL_CONTEXT_CLIENT_VERSION, 2, | 80 EGL_CONTEXT_CLIENT_VERSION, 2, |
| 77 EGL_NONE | 81 EGL_NONE |
| 78 }; | 82 }; |
| 79 fEGLContext = eglCreateContext( | 83 fEGLContext = eglCreateContext( |
| 80 fDisplay, surfaceConfig, nullptr, kEGLContextAttribsForOpenGLES); | 84 fDisplay, surfaceConfig, nullptr, kEGLContextAttribsForOpenGLES); |
| 81 SkASSERT(EGL_NO_CONTEXT != fEGLContext); | 85 SkASSERT(EGL_NO_CONTEXT != fEGLContext); |
| 82 | 86 |
| 83 fSurface = eglCreateWindowSurface( | 87 fSurface = eglCreateWindowSurface( |
| 84 fDisplay, surfaceConfig, androidPlatformData->fNativeWindow, nullptr ); | 88 fDisplay, surfaceConfig, fNativeWindow, nullptr); |
| 85 SkASSERT(EGL_NO_SURFACE != fSurface); | 89 SkASSERT(EGL_NO_SURFACE != fSurface); |
| 86 | 90 |
| 87 SkAssertResult(eglMakeCurrent(fDisplay, fSurface, fSurface, fEGLContext)); | 91 SkAssertResult(eglMakeCurrent(fDisplay, fSurface, fSurface, fEGLContext)); |
| 88 // GLWindowContext::initializeContext will call GrGLCreateNativeInterface so we | 92 // GLWindowContext::initializeContext will call GrGLCreateNativeInterface so we |
| 89 // won't call it here. | 93 // won't call it here. |
| 90 | 94 |
| 91 glClearStencil(0); | 95 glClearStencil(0); |
| 92 glClearColor(0, 0, 0, 0); | 96 glClearColor(0, 0, 0, 0); |
| 93 glStencilMask(0xffffffff); | 97 glStencilMask(0xffffffff); |
| 94 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 98 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 113 fSurface = EGL_NO_SURFACE; | 117 fSurface = EGL_NO_SURFACE; |
| 114 } | 118 } |
| 115 | 119 |
| 116 void GLWindowContext_android::onSwapBuffers() { | 120 void GLWindowContext_android::onSwapBuffers() { |
| 117 if (fDisplay && fEGLContext && fSurface) { | 121 if (fDisplay && fEGLContext && fSurface) { |
| 118 eglSwapBuffers(fDisplay, fSurface); | 122 eglSwapBuffers(fDisplay, fSurface); |
| 119 } | 123 } |
| 120 } | 124 } |
| 121 | 125 |
| 122 } | 126 } |
| OLD | NEW |