• 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 
17 package android.view.cts;
18 
19 import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
20 import static android.opengl.GLES20.GL_SCISSOR_TEST;
21 import static android.opengl.GLES20.glClear;
22 import static android.opengl.GLES20.glClearColor;
23 import static android.opengl.GLES20.glEnable;
24 import static android.opengl.GLES20.glScissor;
25 
26 import android.graphics.Color;
27 import android.opengl.GLSurfaceView;
28 
29 import java.util.concurrent.CountDownLatch;
30 
31 import javax.microedition.khronos.egl.EGLConfig;
32 import javax.microedition.khronos.opengles.GL10;
33 
34 public class PixelCopyGLProducerCtsActivity extends GLSurfaceViewCtsActivity {
35     private static class QuadColorGLRenderer implements GLSurfaceView.Renderer {
36 
37         private final int mTopLeftColor;
38         private final int mTopRightColor;
39         private final int mBottomLeftColor;
40         private final int mBottomRightColor;
41 
42         private CountDownLatch mFence;
43 
44         private int mWidth, mHeight;
45 
QuadColorGLRenderer(int topLeft, int topRight, int bottomLeft, int bottomRight)46         public QuadColorGLRenderer(int topLeft, int topRight, int bottomLeft, int bottomRight) {
47             mTopLeftColor = topLeft;
48             mTopRightColor = topRight;
49             mBottomLeftColor = bottomLeft;
50             mBottomRightColor = bottomRight;
51         }
52 
53         @Override
onSurfaceCreated(GL10 gl, EGLConfig config)54         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
55         }
56 
57         @Override
onSurfaceChanged(GL10 gl, int width, int height)58         public void onSurfaceChanged(GL10 gl, int width, int height) {
59             mWidth = width;
60             mHeight = height;
61         }
62 
63         @Override
onDrawFrame(GL10 gl)64         public void onDrawFrame(GL10 gl) {
65             int cx = mWidth / 2;
66             int cy = mHeight / 2;
67 
68             glEnable(GL_SCISSOR_TEST);
69 
70             glScissor(0, cy, cx, mHeight - cy);
71             clearColor(mTopLeftColor);
72 
73             glScissor(cx, cy, mWidth - cx, mHeight - cy);
74             clearColor(mTopRightColor);
75 
76             glScissor(0, 0, cx, cy);
77             clearColor(mBottomLeftColor);
78 
79             glScissor(cx, 0, mWidth - cx, cy);
80             clearColor(mBottomRightColor);
81 
82             if (mFence != null) {
83                 mFence.countDown();
84             }
85         }
86 
clearColor(int color)87         private void clearColor(int color) {
88             glClearColor(Color.red(color) / 255.0f,
89                     Color.green(color) / 255.0f,
90                     Color.blue(color) / 255.0f,
91                     Color.alpha(color) / 255.0f);
92             glClear(GL_COLOR_BUFFER_BIT);
93         }
94     }
95 
96     private QuadColorGLRenderer mRenderer;
97 
98     @Override
configureGLSurfaceView()99     protected void configureGLSurfaceView() {
100         mView.setEGLContextClientVersion(2);
101         mRenderer = new QuadColorGLRenderer(
102                 Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
103         mView.setRenderer(mRenderer);
104         mView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
105         mView.getHolder().setFixedSize(100, 100);
106     }
107 
setSwapFence(CountDownLatch swapFence)108     public void setSwapFence(CountDownLatch swapFence) {
109         mRenderer.mFence = swapFence;
110     }
111 }
112