Home | History | Annotate | Download | only in EGLTest
      1 /*
      2  * Copyright (C) 2011 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 #include <gtest/gtest.h>
     18 
     19 #include <utils/String8.h>
     20 
     21 #include <EGL/egl.h>
     22 #include <gui/Surface.h>
     23 
     24 
     25 namespace android {
     26 
     27 class EGLTest : public ::testing::Test {
     28 protected:
     29     EGLDisplay mEglDisplay;
     30 
     31 protected:
     32     EGLTest() :
     33             mEglDisplay(EGL_NO_DISPLAY) {
     34     }
     35 
     36     virtual void SetUp() {
     37         mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     38         ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
     39         ASSERT_EQ(EGL_SUCCESS, eglGetError());
     40 
     41         EGLint majorVersion;
     42         EGLint minorVersion;
     43         EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
     44         ASSERT_EQ(EGL_SUCCESS, eglGetError());
     45         RecordProperty("EglVersionMajor", majorVersion);
     46         RecordProperty("EglVersionMajor", minorVersion);
     47     }
     48 
     49     virtual void TearDown() {
     50         EGLBoolean success = eglTerminate(mEglDisplay);
     51         ASSERT_EQ(EGL_TRUE, success);
     52         ASSERT_EQ(EGL_SUCCESS, eglGetError());
     53     }
     54 };
     55 
     56 TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
     57 
     58     EGLint numConfigs;
     59     EGLConfig config;
     60     EGLBoolean success;
     61     EGLint attrs[] = {
     62             EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
     63             EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
     64             EGL_NONE
     65     };
     66 
     67     success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
     68     ASSERT_EQ(EGL_TRUE, success);
     69     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     70     ASSERT_GE(numConfigs, 1);
     71 
     72     EGLint components[3];
     73 
     74     success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
     75     ASSERT_EQ(EGL_TRUE, success);
     76     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     77     success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
     78     ASSERT_EQ(EGL_TRUE, success);
     79     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     80     success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
     81     ASSERT_EQ(EGL_TRUE, success);
     82     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     83 
     84     EXPECT_GE(components[0], 8);
     85     EXPECT_GE(components[1], 8);
     86     EXPECT_GE(components[2], 8);
     87 }
     88 
     89 TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) {
     90     EGLint numConfigs;
     91     EGLConfig config;
     92     EGLint attrs[] = {
     93         EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
     94         EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
     95         EGL_RED_SIZE,           8,
     96         EGL_GREEN_SIZE,         8,
     97         EGL_BLUE_SIZE,          8,
     98         EGL_ALPHA_SIZE,         8,
     99         EGL_NONE
    100     };
    101     EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs));
    102 
    103     struct DummyConsumer : public BnConsumerListener {
    104         virtual void onFrameAvailable() {}
    105         virtual void onBuffersReleased() {}
    106         virtual void onSidebandStreamChanged() {}
    107     };
    108 
    109     // Create a EGLSurface
    110     sp<IGraphicBufferProducer> producer;
    111     sp<IGraphicBufferConsumer> consumer;
    112     BufferQueue::createBufferQueue(&producer, &consumer);
    113     consumer->consumerConnect(new DummyConsumer, false);
    114     sp<Surface> mSTC = new Surface(producer);
    115     sp<ANativeWindow> mANW = mSTC;
    116 
    117     EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config,
    118                                 mANW.get(), NULL);
    119     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    120     ASSERT_NE(EGL_NO_SURFACE, eglSurface) ;
    121 
    122     // do not destroy eglSurface
    123     // eglTerminate is called in the tear down and should destroy it for us
    124 }
    125 
    126 TEST_F(EGLTest, EGLConfigRGBA8888First) {
    127 
    128     EGLint numConfigs;
    129     EGLConfig config;
    130     EGLBoolean success;
    131     EGLint attrs[] = {
    132             EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
    133             EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
    134             EGL_RED_SIZE,           8,
    135             EGL_GREEN_SIZE,         8,
    136             EGL_BLUE_SIZE,          8,
    137             EGL_ALPHA_SIZE,         8,
    138             EGL_NONE
    139     };
    140 
    141     success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
    142     ASSERT_EQ(EGL_TRUE, success);
    143     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    144     ASSERT_GE(numConfigs, 1);
    145 
    146     EGLint components[4];
    147 
    148     success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
    149     ASSERT_EQ(EGL_TRUE, success);
    150     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    151     success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
    152     ASSERT_EQ(EGL_TRUE, success);
    153     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    154     success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
    155     ASSERT_EQ(EGL_TRUE, success);
    156     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    157     success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
    158     ASSERT_EQ(EGL_TRUE, success);
    159     ASSERT_EQ(EGL_SUCCESS, eglGetError());
    160 
    161     EXPECT_GE(components[0], 8);
    162     EXPECT_GE(components[1], 8);
    163     EXPECT_GE(components[2], 8);
    164     EXPECT_GE(components[3], 8);
    165 }
    166 
    167 
    168 }
    169