• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 package android.vr.cts;
17 
18 import java.nio.IntBuffer;
19 
20 import javax.microedition.khronos.egl.EGLConfig;
21 import javax.microedition.khronos.opengles.GL10;
22 
23 import android.opengl.GLES20;
24 
25 import java.util.concurrent.CountDownLatch;
26 
27 public class RendererProtectedTexturesTest extends RendererBasicTest {
28 
29     private String vertexShaderCode = "attribute vec4 vPosition; \n"
30             + "void main(){              \n"
31             +    "gl_Position = vPosition; \n"
32             + "}                         \n";
33 
34     private String fragmentShaderCode = "precision mediump float;  \n"
35             + "sampler2D protectedTexture;\n"
36             + "void main(){              \n"
37             + " gl_FragColor = texture2D(protectedTexture, vec2(0.76953125, 0.22265625)); \n"
38             + "}  \n";
39 
40     public static int GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT = 0x00000010;
41     public static int GL_TEXTURE_PROTECTED_EXT = 0x8BFA;
42 
43     private IntBuffer mTexture;
44 
RendererProtectedTexturesTest(CountDownLatch latch)45     public RendererProtectedTexturesTest(CountDownLatch latch) {
46         super(latch);
47     }
48 
49     @Override
onSurfaceCreated(GL10 gl, EGLConfig config)50     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
51         GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
52         initShapes();
53         int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
54         int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
55         mProgram = GLES20.glCreateProgram();
56         GLES20.glAttachShader(mProgram, vertexShader);
57         GLES20.glAttachShader(mProgram, fragmentShader);
58         GLES20.glLinkProgram(mProgram);
59         int[] linkStatus = new int[1];
60         GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linkStatus, 0);
61         if (linkStatus[0] != GLES20.GL_TRUE) {
62            //do nothing
63         }
64 
65         // Create and bind a protected texture.
66         mTexture = IntBuffer.allocate(1);
67         GLES20.glGenTextures(1, mTexture);
68         GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
69         GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.get(0));
70         GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL_TEXTURE_PROTECTED_EXT, GLES20.GL_TRUE);
71         int loc = GLES20.glGetUniformLocation(mProgram, "protectedTexture");
72         GLES20.glUniform1i(loc, 2);
73     }
74 }
75 
76