1 /*
2  * Copyright (C) 2021 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 "renderthread/EglManager.h"
20 #include "renderthread/RenderEffectCapabilityQuery.h"
21 #include "tests/common/TestContext.h"
22 
23 #include <SkColorSpace.h>
24 
25 using namespace android;
26 using namespace android::uirenderer;
27 using namespace android::uirenderer::renderthread;
28 using namespace android::uirenderer::test;
29 
TEST(EglManager,doesSurfaceLeak)30 TEST(EglManager, doesSurfaceLeak) {
31     EglManager eglManager;
32     eglManager.initialize();
33 
34     ASSERT_TRUE(eglManager.hasEglContext());
35 
36     auto colorSpace = SkColorSpace::MakeSRGB();
37     for (int i = 0; i < 100; i++) {
38         TestContext context;
39         auto result =
40                 eglManager.createSurface(context.surface().get(), ColorMode::Default, colorSpace);
41         EXPECT_TRUE(result);
42         EGLSurface surface = result.unwrap();
43         eglManager.destroySurface(surface);
44     }
45 
46     eglManager.destroy();
47 }
48 
TEST(EglManager,verifyRenderEffectCacheSupported)49 TEST(EglManager, verifyRenderEffectCacheSupported) {
50     EglManager eglManager;
51     eglManager.initialize();
52     auto* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
53     auto* version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
54     // Make sure that EglManager initializes Properties::enableRenderEffectCache
55     // based on the given gl vendor and version within EglManager->initialize()
56     bool renderEffectCacheSupported = supportsRenderEffectCache(vendor, version);
57     EXPECT_EQ(renderEffectCacheSupported,
58               Properties::enableRenderEffectCache);
59     eglManager.destroy();
60 }