Path: blob/main_old/src/tests/egl_tests/EGLProtectedContentTest.cpp
1693 views
//1// Copyright 2021 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// EGLProtectedContentTest.cpp:6// EGL extension EGL_EXT_protected_content7//89#include <gtest/gtest.h>1011#include <chrono>12#include <iostream>13#include <thread>14#include "test_utils/ANGLETest.h"15#include "util/EGLWindow.h"16#include "util/OSWindow.h"1718using namespace std::chrono_literals;1920using namespace angle;2122GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLProtectedContentTest);2324class EGLProtectedContentTest : public ANGLETest25{26public:27EGLProtectedContentTest() : mDisplay(EGL_NO_DISPLAY) {}2829void testSetUp() override30{31EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};32mDisplay = eglGetPlatformDisplayEXT(33EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);34EXPECT_TRUE(mDisplay != EGL_NO_DISPLAY);35EXPECT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));36mMajorVersion = GetParam().majorVersion;37}3839void testTearDown() override40{41if (mDisplay != EGL_NO_DISPLAY)42{43eglTerminate(mDisplay);44eglReleaseThread();45mDisplay = EGL_NO_DISPLAY;46}47ASSERT_EGL_SUCCESS() << "Error during test TearDown";48}4950bool chooseConfig(EGLConfig *config)51{52EGLint clientVersion = mMajorVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT;53EGLint attribs[] = {EGL_RED_SIZE,548,55EGL_GREEN_SIZE,568,57EGL_BLUE_SIZE,588,59EGL_ALPHA_SIZE,608,61EGL_RENDERABLE_TYPE,62clientVersion,63EGL_SURFACE_TYPE,64(EGL_PBUFFER_BIT | EGL_WINDOW_BIT),65EGL_BIND_TO_TEXTURE_RGBA,66EGL_TRUE,67EGL_NONE};6869EGLint count = 0;70bool result = eglChooseConfig(mDisplay, attribs, config, 1, &count);71EXPECT_EGL_TRUE(result);72EXPECT_EGL_TRUE(count > 0);73return result;74}7576bool createContext(EGLBoolean isProtected, EGLConfig config, EGLContext *context)77{78bool result = false;79EGLint attribsProtected[] = {EGL_CONTEXT_MAJOR_VERSION, mMajorVersion,80EGL_PROTECTED_CONTENT_EXT, EGL_TRUE, EGL_NONE};81EGLint attribsUnProtected[] = {EGL_CONTEXT_MAJOR_VERSION, mMajorVersion, EGL_NONE};8283*context = eglCreateContext(mDisplay, config, nullptr,84(isProtected ? attribsProtected : attribsUnProtected));85result = (*context != EGL_NO_CONTEXT);86EXPECT_TRUE(result);87return result;88}8990bool createPbufferSurface(EGLBoolean isProtected, EGLConfig config, EGLSurface *surface)91{92bool result = false;93EGLint attribsProtected[] = {EGL_WIDTH,94kWidth,95EGL_HEIGHT,96kHeight,97EGL_TEXTURE_FORMAT,98EGL_TEXTURE_RGBA,99EGL_TEXTURE_TARGET,100EGL_TEXTURE_2D,101EGL_PROTECTED_CONTENT_EXT,102EGL_TRUE,103EGL_NONE};104EGLint attribsUnProtected[] = {EGL_WIDTH,105kWidth,106EGL_HEIGHT,107kHeight,108EGL_TEXTURE_FORMAT,109EGL_TEXTURE_RGBA,110EGL_TEXTURE_TARGET,111EGL_TEXTURE_2D,112EGL_NONE};113114*surface = eglCreatePbufferSurface(mDisplay, config,115(isProtected ? attribsProtected : attribsUnProtected));116result = (*surface != EGL_NO_SURFACE);117EXPECT_TRUE(result);118return result;119}120121bool createWindowSurface(EGLBoolean isProtected,122EGLConfig config,123EGLNativeWindowType win,124EGLSurface *surface)125{126bool result = false;127EGLint attribsProtected[] = {EGL_PROTECTED_CONTENT_EXT, EGL_TRUE, EGL_NONE};128EGLint attribsUnProtected[] = {EGL_NONE};129130*surface = eglCreateWindowSurface(mDisplay, config, win,131(isProtected ? attribsProtected : attribsUnProtected));132result = (*surface != EGL_NO_SURFACE);133EXPECT_TRUE(result);134return result;135}136137bool createImage(EGLBoolean isProtected,138EGLContext context,139EGLenum target,140EGLClientBuffer buffer,141EGLImage *image)142{143bool result = false;144EGLAttrib attribsProtected[] = {EGL_PROTECTED_CONTENT_EXT, EGL_TRUE, EGL_NONE};145146*image = eglCreateImage(mDisplay, context, target, buffer,147(isProtected ? attribsProtected : nullptr));148EXPECT_EGL_SUCCESS();149result = (*image != EGL_NO_SURFACE);150EXPECT_TRUE(result);151return result;152}153154bool createTexture(EGLBoolean isProtected, GLuint *textureId)155{156bool result = false;157GLuint texture = 0;158glGenTextures(1, &texture);159glBindTexture(GL_TEXTURE_2D, texture);160glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,161nullptr);162EXPECT_GL_NO_ERROR();163if (isProtected)164{165glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_PROTECTED_EXT, GL_TRUE);166// GL_INVALID_OPERATION expected when context is not protected too.167GLenum error = glGetError();168if (error == GL_INVALID_OPERATION)169{170return false;171}172}173glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight);174EXPECT_GL_NO_ERROR();175glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);176glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);177result = (texture != 0);178EXPECT_TRUE(result);179*textureId = texture;180return result;181}182183bool createTextureFromImage(EGLImage image, GLuint *textureId)184{185bool result = false;186GLuint texture = 0;187glGenTextures(1, &texture);188glBindTexture(GL_TEXTURE_2D, texture);189glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);190EXPECT_GL_NO_ERROR();191glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);192glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);193result = (texture != 0);194EXPECT_TRUE(result);195*textureId = texture;196return result;197}198199bool createTextureFromPbuffer(EGLSurface pBuffer, GLuint *textureId)200{201bool result = false;202GLuint texture = 0;203glGenTextures(1, &texture);204glBindTexture(GL_TEXTURE_2D, texture);205glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);206glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);207glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);208glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);209EXPECT_GL_NO_ERROR();210EXPECT_TRUE(texture != 0);211result = eglBindTexImage(mDisplay, pBuffer, EGL_BACK_BUFFER);212glViewport(0, 0, kWidth, kHeight);213*textureId = texture;214return result;215}216217bool fillTexture(GLuint textureId, GLColor color)218{219GLuint pixels[kWidth * kHeight];220for (uint32_t i = 0; i < (kWidth * kHeight); i++)221{222pixels[i] = *(GLuint *)(color.data());223}224glBindTexture(GL_TEXTURE_2D, textureId);225glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,226(void *)pixels);227EXPECT_GL_NO_ERROR();228return true;229}230231bool renderTexture(GLuint textureId)232{233const char *kVertexShader = R"(234precision highp float;235attribute vec4 position;236varying vec2 texcoord;237238void main()239{240gl_Position = vec4(position.xy, 0.0, 1.0);241texcoord = (position.xy * 0.5) + 0.5;242}243)";244const char *kFragmentShader = R"(245precision highp float;246uniform sampler2D tex;247varying vec2 texcoord;248249void main()250{251gl_FragColor = texture2D(tex, texcoord);252}253)";254255GLuint program = CompileProgram(kVertexShader, kFragmentShader);256glUseProgram(program);257glBindTexture(GL_TEXTURE_2D, textureId);258glActiveTexture(GL_TEXTURE0);259GLint texture2DUniformLocation = glGetUniformLocation(program, "tex");260glUniform1i(texture2DUniformLocation, 0);261drawQuad(program, "position", 0.5f);262glDeleteProgram(program);263EXPECT_GL_NO_ERROR();264return true;265}266267bool createRenderbuffer(GLuint *renderbuffer)268{269bool result = false;270*renderbuffer = 0;271glGenRenderbuffers(1, renderbuffer);272glBindRenderbuffer(GL_RENDERBUFFER, *renderbuffer);273glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, kWidth, kHeight);274EXPECT_GL_NO_ERROR();275result = (*renderbuffer != 0);276EXPECT_TRUE(result);277return result;278}279280bool createRenderbufferFromImage(EGLImage image, GLuint *renderbuffer)281{282bool result = false;283*renderbuffer = 0;284glGenRenderbuffers(1, renderbuffer);285glBindRenderbuffer(GL_RENDERBUFFER, *renderbuffer);286glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, image);287EXPECT_GL_NO_ERROR();288result = (*renderbuffer != 0);289EXPECT_TRUE(result);290return result;291}292293bool createAndroidClientBuffer(bool useProtected,294bool useRenderbuffer,295bool useTexture,296EGLClientBuffer *clientBuffer)297{298bool result = false;299EGLint nativeBufferUsage =3000 | (useProtected ? EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID : 0) |301(useRenderbuffer ? EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID : 0) |302(useTexture ? EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID : 0);303304EGLint attribs[] = {EGL_WIDTH,305kWidth,306EGL_HEIGHT,307kHeight,308EGL_RED_SIZE,3098,310EGL_GREEN_SIZE,3118,312EGL_BLUE_SIZE,3138,314EGL_ALPHA_SIZE,3158,316EGL_NATIVE_BUFFER_USAGE_ANDROID,317nativeBufferUsage,318EGL_NONE};319320*clientBuffer = eglCreateNativeClientBufferANDROID(attribs);321EXPECT_EGL_SUCCESS();322result = (*clientBuffer != nullptr);323EXPECT_TRUE(result);324return result;325}326327void pbufferTest(bool isProtectedContext, bool isProtectedSurface);328void windowTest(bool isProtectedContext, bool isProtectedSurface);329void textureTest(bool isProtectedContext, bool isProtectedTexture);330void textureFromImageTest(bool isProtectedContext, bool isProtectedTexture);331void textureFromPbufferTest(bool isProtectedContext, bool isProtectedTexture);332void textureFromAndroidNativeBufferTest(bool isProtectedContext, bool isProtectedTexture);333334void checkSwapBuffersResult(const std::string color,335bool isProtectedContext,336bool isProtectedSurface)337{338std::this_thread::sleep_for(1s);339if (isProtectedContext)340{341if (isProtectedSurface)342{343std::cout << "Operator should see color: " << color << std::endl;344}345else346{347std::cout << "Operator should see color: BLACK" << std::endl;348}349}350else351{352if (isProtectedSurface)353{354std::cout << "Operator should see color: BLACK" << std::endl;355}356else357{358std::cout << "Operator should see color: " << color << std::endl;359}360}361}362363EGLDisplay mDisplay = EGL_NO_DISPLAY;364EGLint mMajorVersion = 0;365static const EGLint kWidth = 16;366static const EGLint kHeight = 16;367};368369void EGLProtectedContentTest::pbufferTest(bool isProtectedContext, bool isProtectedSurface)370{371ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));372373EGLConfig config = EGL_NO_CONFIG_KHR;374EXPECT_TRUE(chooseConfig(&config));375ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);376377EGLContext context = EGL_NO_CONTEXT;378EXPECT_TRUE(createContext(isProtectedContext, config, &context));379ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";380381EGLSurface pBufferSurface = EGL_NO_SURFACE;382EXPECT_TRUE(createPbufferSurface(isProtectedSurface, config, &pBufferSurface));383ASSERT_EGL_SUCCESS() << "eglCreatePbufferSurface failed.";384385EXPECT_TRUE(eglMakeCurrent(mDisplay, pBufferSurface, pBufferSurface, context));386ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";387388glClearColor(1.0, 0.0, 0.0, 1.0);389glClear(GL_COLOR_BUFFER_BIT);390391glFinish();392ASSERT_GL_NO_ERROR() << "glFinish failed";393EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);394395EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));396ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";397398eglDestroySurface(mDisplay, pBufferSurface);399pBufferSurface = EGL_NO_SURFACE;400401eglDestroyContext(mDisplay, context);402context = EGL_NO_CONTEXT;403}404405// Unprotected context with Unprotected PbufferSurface406TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedPbufferSurface)407{408pbufferTest(false, false);409}410411void EGLProtectedContentTest::windowTest(bool isProtectedContext, bool isProtectedSurface)412{413ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));414415EGLConfig config = EGL_NO_CONFIG_KHR;416EXPECT_TRUE(chooseConfig(&config));417ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);418419EGLContext context = EGL_NO_CONTEXT;420EXPECT_TRUE(createContext(isProtectedContext, config, &context));421ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";422423OSWindow *osWindow = OSWindow::New();424osWindow->initialize("ProtectedContentTest", kWidth, kHeight);425EGLSurface windowSurface = EGL_NO_SURFACE;426EGLBoolean createWinSurfaceResult = createWindowSurface(427isProtectedSurface, config, osWindow->getNativeWindow(), &windowSurface);428EXPECT_TRUE(createWinSurfaceResult);429ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";430431EXPECT_TRUE(eglMakeCurrent(mDisplay, windowSurface, windowSurface, context));432ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";433434// Red435glClearColor(1.0, 0.0, 0.0, 1.0);436glClear(GL_COLOR_BUFFER_BIT);437ASSERT_GL_NO_ERROR() << "glClear failed";438eglSwapBuffers(mDisplay, windowSurface);439ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";440checkSwapBuffersResult("RED", isProtectedContext, isProtectedSurface);441442// Green443glClearColor(0.0, 1.0, 0.0, 1.0);444glClear(GL_COLOR_BUFFER_BIT);445ASSERT_GL_NO_ERROR() << "glClear failed";446eglSwapBuffers(mDisplay, windowSurface);447ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";448checkSwapBuffersResult("GREEN", isProtectedContext, isProtectedSurface);449450// Blue451glClearColor(0.0, 0.0, 1.0, 1.0);452glClear(GL_COLOR_BUFFER_BIT);453ASSERT_GL_NO_ERROR() << "glClear failed";454eglSwapBuffers(mDisplay, windowSurface);455ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";456checkSwapBuffersResult("BLUE", isProtectedContext, isProtectedSurface);457458EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));459ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";460461eglDestroySurface(mDisplay, windowSurface);462windowSurface = EGL_NO_SURFACE;463osWindow->destroy();464OSWindow::Delete(&osWindow);465466eglDestroyContext(mDisplay, context);467context = EGL_NO_CONTEXT;468}469470// Unprotected context with Unprotected WindowSurface471TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedWindowSurface)472{473windowTest(false, false);474}475476// Protected context with Protected WindowSurface477TEST_P(EGLProtectedContentTest, ProtectedContextWithProtectedWindowSurface)478{479windowTest(true, true);480}481482void EGLProtectedContentTest::textureTest(bool isProtectedContext, bool isProtectedTexture)483{484ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));485486bool isProtectedSurface = isProtectedTexture;487488EGLConfig config = EGL_NO_CONFIG_KHR;489EXPECT_TRUE(chooseConfig(&config));490ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);491492EGLContext context = EGL_NO_CONTEXT;493EXPECT_TRUE(createContext(isProtectedContext, config, &context));494ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";495496OSWindow *osWindow = OSWindow::New();497osWindow->initialize("ProtectedContentTest", kWidth, kHeight);498EGLSurface windowSurface = EGL_NO_SURFACE;499EGLBoolean createWinSurfaceResult = createWindowSurface(500isProtectedSurface, config, osWindow->getNativeWindow(), &windowSurface);501EXPECT_TRUE(createWinSurfaceResult);502ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";503glViewport(0, 0, kWidth, kHeight);504505EXPECT_TRUE(eglMakeCurrent(mDisplay, windowSurface, windowSurface, context));506ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";507508if (IsGLExtensionEnabled("GL_EXT_protected_textures"))509{510GLuint texture = 0;511bool result = createTexture(isProtectedTexture, &texture);512if (isProtectedTexture && !isProtectedContext)513{514std::cout << "Can't create protected Texture for Unprotected Context" << std::endl;515ASSERT_FALSE(result);516}517else518{519ASSERT_TRUE(result);520521EXPECT_TRUE(fillTexture(texture, GLColor::red));522EXPECT_TRUE(renderTexture(texture));523524eglSwapBuffers(mDisplay, windowSurface);525ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";526checkSwapBuffersResult("RED", isProtectedContext, isProtectedSurface);527528glBindTexture(GL_TEXTURE_2D, 0);529glDeleteTextures(1, &texture);530}531}532else533{534std::cout << "Skipping tests, GL_EXT_protected_textures not supported" << std::endl;535}536537EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));538ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";539540eglDestroySurface(mDisplay, windowSurface);541windowSurface = EGL_NO_SURFACE;542osWindow->destroy();543OSWindow::Delete(&osWindow);544545eglDestroyContext(mDisplay, context);546context = EGL_NO_CONTEXT;547}548549// Unprotected context with unprotected texture550TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedTexture)551{552textureTest(false, false);553}554555// Protected context with protected texture556TEST_P(EGLProtectedContentTest, ProtectedContextWithProtectedTexture)557{558textureTest(true, true);559}560561void EGLProtectedContentTest::textureFromImageTest(bool isProtectedContext, bool isProtectedTexture)562{563ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));564565bool isProtectedSurface = isProtectedTexture;566567EGLConfig config = EGL_NO_CONFIG_KHR;568EXPECT_TRUE(chooseConfig(&config));569ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);570571EGLContext context = EGL_NO_CONTEXT;572EXPECT_TRUE(createContext(isProtectedContext, config, &context));573ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";574575OSWindow *osWindow = OSWindow::New();576osWindow->initialize("ProtectedContentTest", kWidth, kHeight);577EGLSurface windowSurface = EGL_NO_SURFACE;578EGLBoolean createWinSurfaceResult = createWindowSurface(579isProtectedSurface, config, osWindow->getNativeWindow(), &windowSurface);580EXPECT_TRUE(createWinSurfaceResult);581ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";582583EXPECT_TRUE(eglMakeCurrent(mDisplay, windowSurface, windowSurface, context));584ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";585glViewport(0, 0, kWidth, kHeight);586587if (IsGLExtensionEnabled("GL_OES_EGL_image") &&588IsGLExtensionEnabled("GL_EXT_protected_textures"))589{590GLuint srcTexture = 0;591if (isProtectedTexture && !isProtectedContext)592{593std::cout << "Can't create protected Texture for Unprotected Context, Skipping"594<< std::endl;595ASSERT_FALSE(createTexture(isProtectedTexture, &srcTexture));596}597else598{599ASSERT_TRUE(createTexture(isProtectedTexture, &srcTexture));600EXPECT_TRUE(fillTexture(srcTexture, GLColor::red));601602EGLImage image = EGL_NO_IMAGE;603EXPECT_TRUE(createImage(isProtectedTexture, context, EGL_GL_TEXTURE_2D,604(void *)(static_cast<intptr_t>(srcTexture)), &image));605606GLuint dstTexture = 0;607EXPECT_TRUE(createTextureFromImage(image, &dstTexture));608EXPECT_TRUE(renderTexture(dstTexture));609610eglSwapBuffers(mDisplay, windowSurface);611ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";612checkSwapBuffersResult("RED", isProtectedContext, isProtectedSurface);613614glBindTexture(GL_TEXTURE_2D, 0);615glDeleteTextures(1, &dstTexture);616glDeleteTextures(1, &srcTexture);617618eglDestroyImage(mDisplay, image);619image = EGL_NO_IMAGE;620}621}622else623{624std::cout << "Skipping tests, GL_OES_EGL_image or GL_EXT_protected_textures not supported"625<< std::endl;626}627628EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));629ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";630631eglDestroySurface(mDisplay, windowSurface);632windowSurface = EGL_NO_SURFACE;633osWindow->destroy();634OSWindow::Delete(&osWindow);635636eglDestroyContext(mDisplay, context);637context = EGL_NO_CONTEXT;638}639640// Unprotected context with unprotected texture from EGL image641TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedTextureFromImage)642{643textureFromImageTest(false, false);644}645646// Protected context with protected texture from EGL image647TEST_P(EGLProtectedContentTest, ProtectedContextWithProtectedTextureFromImage)648{649textureFromImageTest(true, true);650}651652void EGLProtectedContentTest::textureFromPbufferTest(bool isProtectedContext,653bool isProtectedTexture)654{655ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));656657bool isProtectedSurface = isProtectedTexture;658659EGLConfig config = EGL_NO_CONFIG_KHR;660EXPECT_TRUE(chooseConfig(&config));661ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);662663EGLContext context = EGL_NO_CONTEXT;664EXPECT_TRUE(createContext(isProtectedContext, config, &context));665ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";666667EGLSurface pBufferSurface = EGL_NO_SURFACE;668EXPECT_TRUE(createPbufferSurface(isProtectedSurface, config, &pBufferSurface));669ASSERT_EGL_SUCCESS() << "eglCreatePbufferSurface failed.";670671EXPECT_TRUE(eglMakeCurrent(mDisplay, pBufferSurface, pBufferSurface, context));672ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";673674glViewport(0, 0, kWidth, kHeight);675glClearColor(1.0, 0.0, 0.0, 1.0);676glClear(GL_COLOR_BUFFER_BIT);677678glFinish();679ASSERT_GL_NO_ERROR() << "glFinish failed";680681OSWindow *osWindow = OSWindow::New();682osWindow->initialize("ProtectedContentTest", kWidth, kHeight);683EGLSurface windowSurface = EGL_NO_SURFACE;684EGLBoolean createWinSurfaceResult = createWindowSurface(685isProtectedSurface, config, osWindow->getNativeWindow(), &windowSurface);686EXPECT_TRUE(createWinSurfaceResult);687ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";688689EXPECT_TRUE(eglMakeCurrent(mDisplay, windowSurface, windowSurface, context));690ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";691glViewport(0, 0, kWidth, kHeight);692693if (IsGLExtensionEnabled("GL_EXT_protected_textures"))694{695GLuint texture = 0;696EXPECT_TRUE(createTextureFromPbuffer(pBufferSurface, &texture));697EXPECT_TRUE(renderTexture(texture));698699eglSwapBuffers(mDisplay, windowSurface);700ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";701checkSwapBuffersResult("RED", isProtectedContext, isProtectedTexture);702703eglReleaseTexImage(mDisplay, pBufferSurface, EGL_BACK_BUFFER);704glDeleteTextures(1, &texture);705}706else707{708std::cout << "Skipping tests, GL_EXT_protected_textures not supported" << std::endl;709}710711EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));712ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";713714eglDestroySurface(mDisplay, windowSurface);715windowSurface = EGL_NO_SURFACE;716osWindow->destroy();717OSWindow::Delete(&osWindow);718719eglDestroySurface(mDisplay, pBufferSurface);720pBufferSurface = EGL_NO_SURFACE;721722eglDestroyContext(mDisplay, context);723context = EGL_NO_CONTEXT;724}725726// Unprotected context with unprotected texture from BindTex of PBufferSurface727TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedTextureFromPBuffer)728{729textureFromPbufferTest(false, false);730}731732// Protected context with protected texture from BindTex of PBufferSurface733TEST_P(EGLProtectedContentTest, ProtectedContextWithProtectedTextureFromPbuffer)734{735textureFromPbufferTest(true, true);736}737738void EGLProtectedContentTest::textureFromAndroidNativeBufferTest(bool isProtectedContext,739bool isProtectedTexture)740{741ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_protected_content"));742ANGLE_SKIP_TEST_IF(743!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_get_native_client_buffer"));744ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_image_native_buffer"));745746bool isProtectedSurface = isProtectedTexture;747748EGLConfig config = EGL_NO_CONFIG_KHR;749EXPECT_TRUE(chooseConfig(&config));750ANGLE_SKIP_TEST_IF(config == EGL_NO_CONFIG_KHR);751752EGLContext context = EGL_NO_CONTEXT;753EXPECT_TRUE(createContext(isProtectedContext, config, &context));754ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";755756OSWindow *osWindow = OSWindow::New();757osWindow->initialize("ProtectedContentTest", kWidth, kHeight);758EGLSurface windowSurface = EGL_NO_SURFACE;759EGLBoolean createWinSurfaceResult = createWindowSurface(760isProtectedSurface, config, osWindow->getNativeWindow(), &windowSurface);761EXPECT_TRUE(createWinSurfaceResult);762ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";763764EXPECT_TRUE(eglMakeCurrent(mDisplay, windowSurface, windowSurface, context));765ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";766glViewport(0, 0, kWidth, kHeight);767768if (IsGLExtensionEnabled("GL_EXT_protected_textures"))769{770EGLClientBuffer clientBuffer = nullptr;771EXPECT_TRUE(createAndroidClientBuffer(isProtectedTexture, false, true, &clientBuffer));772773EGLImage image = EGL_NO_IMAGE;774EXPECT_TRUE(createImage(isProtectedTexture, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,775clientBuffer, &image));776777GLuint texture = 0;778if (isProtectedTexture && !isProtectedContext)779{780std::cout << "Can't create protected Texture for Unprotected Context, Skipping"781<< std::endl;782ASSERT_FALSE(createTextureFromImage(image, &texture));783}784else785{786EXPECT_TRUE(createTextureFromImage(image, &texture));787EXPECT_TRUE(fillTexture(texture, GLColor::red));788EXPECT_TRUE(renderTexture(texture));789790eglSwapBuffers(mDisplay, windowSurface);791ASSERT_EGL_SUCCESS() << "eglSwapBuffers failed.";792checkSwapBuffersResult("RED", isProtectedContext, isProtectedTexture);793794glBindTexture(GL_TEXTURE_2D, 0);795glDeleteTextures(1, &texture);796797eglDestroyImage(mDisplay, image);798image = EGL_NO_IMAGE;799}800}801else802{803std::cout << "Skipping tests, GL_EXT_protected_textures not supported" << std::endl;804}805806EXPECT_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));807ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";808809eglDestroySurface(mDisplay, windowSurface);810windowSurface = EGL_NO_SURFACE;811osWindow->destroy();812OSWindow::Delete(&osWindow);813814eglDestroyContext(mDisplay, context);815context = EGL_NO_CONTEXT;816}817818// Unprotected context with unprotected texture from EGL image from Android native buffer819TEST_P(EGLProtectedContentTest, UnprotectedContextWithUnprotectedTextureFromAndroidNativeBuffer)820{821textureFromAndroidNativeBufferTest(false, false);822}823824// Protected context with protected texture from EGL image from Android native buffer825TEST_P(EGLProtectedContentTest, ProtectedContextWithProtectedTextureFromAndroidNativeBuffer)826{827textureFromAndroidNativeBufferTest(true, true);828}829830ANGLE_INSTANTIATE_TEST(EGLProtectedContentTest,831WithNoFixture(ES2_OPENGLES()),832WithNoFixture(ES3_OPENGLES()),833WithNoFixture(ES2_VULKAN()),834WithNoFixture(ES3_VULKAN()));835836837