| Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2013 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef ANDROID_SURFACE_TEXTURE_MULTI_CONTEXT_GL_H | 
|  | 18 | #define ANDROID_SURFACE_TEXTURE_MULTI_CONTEXT_GL_H | 
|  | 19 |  | 
|  | 20 | #include "SurfaceTextureGL.h" | 
|  | 21 |  | 
|  | 22 | namespace android { | 
|  | 23 |  | 
|  | 24 | class SurfaceTextureMultiContextGLTest : public SurfaceTextureGLTest { | 
|  | 25 | protected: | 
|  | 26 | enum { SECOND_TEX_ID = 123 }; | 
|  | 27 | enum { THIRD_TEX_ID = 456 }; | 
|  | 28 |  | 
|  | 29 | SurfaceTextureMultiContextGLTest(): | 
|  | 30 | mSecondEglContext(EGL_NO_CONTEXT) { | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | virtual void SetUp() { | 
|  | 34 | SurfaceTextureGLTest::SetUp(); | 
|  | 35 |  | 
|  | 36 | // Set up the secondary context and texture renderer. | 
|  | 37 | mSecondEglContext = eglCreateContext(mEglDisplay, mGlConfig, | 
|  | 38 | EGL_NO_CONTEXT, getContextAttribs()); | 
|  | 39 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 40 | ASSERT_NE(EGL_NO_CONTEXT, mSecondEglContext); | 
|  | 41 |  | 
|  | 42 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, | 
|  | 43 | mSecondEglContext)); | 
|  | 44 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 45 | mSecondTextureRenderer = new TextureRenderer(SECOND_TEX_ID, mST); | 
|  | 46 | ASSERT_NO_FATAL_FAILURE(mSecondTextureRenderer->SetUp()); | 
|  | 47 |  | 
|  | 48 | // Set up the tertiary context and texture renderer. | 
|  | 49 | mThirdEglContext = eglCreateContext(mEglDisplay, mGlConfig, | 
|  | 50 | EGL_NO_CONTEXT, getContextAttribs()); | 
|  | 51 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 52 | ASSERT_NE(EGL_NO_CONTEXT, mThirdEglContext); | 
|  | 53 |  | 
|  | 54 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, | 
|  | 55 | mThirdEglContext)); | 
|  | 56 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 57 | mThirdTextureRenderer = new TextureRenderer(THIRD_TEX_ID, mST); | 
|  | 58 | ASSERT_NO_FATAL_FAILURE(mThirdTextureRenderer->SetUp()); | 
|  | 59 |  | 
|  | 60 | // Switch back to the primary context to start the tests. | 
|  | 61 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, | 
|  | 62 | mEglContext)); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | virtual void TearDown() { | 
|  | 66 | if (mThirdEglContext != EGL_NO_CONTEXT) { | 
|  | 67 | eglDestroyContext(mEglDisplay, mThirdEglContext); | 
|  | 68 | } | 
|  | 69 | if (mSecondEglContext != EGL_NO_CONTEXT) { | 
|  | 70 | eglDestroyContext(mEglDisplay, mSecondEglContext); | 
|  | 71 | } | 
|  | 72 | SurfaceTextureGLTest::TearDown(); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | EGLContext mSecondEglContext; | 
|  | 76 | sp<TextureRenderer> mSecondTextureRenderer; | 
|  | 77 |  | 
|  | 78 | EGLContext mThirdEglContext; | 
|  | 79 | sp<TextureRenderer> mThirdTextureRenderer; | 
|  | 80 | }; | 
|  | 81 |  | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | #endif |