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(): |
Pablo Ceballos | 53390e1 | 2015-08-04 11:25:59 -0700 | [diff] [blame] | 30 | mSecondEglContext(EGL_NO_CONTEXT), |
| 31 | mThirdEglContext(EGL_NO_CONTEXT) { |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | virtual void SetUp() { |
| 35 | SurfaceTextureGLTest::SetUp(); |
| 36 | |
| 37 | // Set up the secondary context and texture renderer. |
| 38 | mSecondEglContext = eglCreateContext(mEglDisplay, mGlConfig, |
| 39 | EGL_NO_CONTEXT, getContextAttribs()); |
| 40 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 41 | ASSERT_NE(EGL_NO_CONTEXT, mSecondEglContext); |
| 42 | |
| 43 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 44 | mSecondEglContext)); |
| 45 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 46 | mSecondTextureRenderer = new TextureRenderer(SECOND_TEX_ID, mST); |
| 47 | ASSERT_NO_FATAL_FAILURE(mSecondTextureRenderer->SetUp()); |
| 48 | |
| 49 | // Set up the tertiary context and texture renderer. |
| 50 | mThirdEglContext = eglCreateContext(mEglDisplay, mGlConfig, |
| 51 | EGL_NO_CONTEXT, getContextAttribs()); |
| 52 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 53 | ASSERT_NE(EGL_NO_CONTEXT, mThirdEglContext); |
| 54 | |
| 55 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 56 | mThirdEglContext)); |
| 57 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 58 | mThirdTextureRenderer = new TextureRenderer(THIRD_TEX_ID, mST); |
| 59 | ASSERT_NO_FATAL_FAILURE(mThirdTextureRenderer->SetUp()); |
| 60 | |
| 61 | // Switch back to the primary context to start the tests. |
| 62 | ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 63 | mEglContext)); |
| 64 | } |
| 65 | |
| 66 | virtual void TearDown() { |
| 67 | if (mThirdEglContext != EGL_NO_CONTEXT) { |
| 68 | eglDestroyContext(mEglDisplay, mThirdEglContext); |
| 69 | } |
| 70 | if (mSecondEglContext != EGL_NO_CONTEXT) { |
| 71 | eglDestroyContext(mEglDisplay, mSecondEglContext); |
| 72 | } |
| 73 | SurfaceTextureGLTest::TearDown(); |
| 74 | } |
| 75 | |
| 76 | EGLContext mSecondEglContext; |
| 77 | sp<TextureRenderer> mSecondTextureRenderer; |
| 78 | |
| 79 | EGLContext mThirdEglContext; |
| 80 | sp<TextureRenderer> mThirdTextureRenderer; |
| 81 | }; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | #endif |