• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.view.cts.util;
18 
19 import static org.junit.Assert.assertTrue;
20 
21 import android.graphics.Rect;
22 import android.hardware.HardwareBuffer;
23 import android.view.Surface;
24 
25 public class ASurfaceControlTestUtils {
26     static {
27         System.loadLibrary("ctsview_jni");
28     }
29 
30     public interface TransactionCompleteListener {
onTransactionComplete(long latchTime, long presentTime)31         void onTransactionComplete(long latchTime, long presentTime);
32     }
33 
createSurfaceTransaction()34     public static long createSurfaceTransaction() {
35         long surfaceTransaction = nSurfaceTransaction_create();
36         assertTrue("failed to create surface transaction", surfaceTransaction != 0);
37         return surfaceTransaction;
38     }
39 
reparent(long surfaceControl, long newParentSurfaceControl)40     public static void reparent(long surfaceControl, long newParentSurfaceControl) {
41         long surfaceTransaction = createSurfaceTransaction();
42         nSurfaceTransaction_reparent(surfaceControl, newParentSurfaceControl, surfaceTransaction);
43         applyAndDeleteSurfaceTransaction(surfaceTransaction);
44     }
45 
applyAndDeleteSurfaceTransaction(long surfaceTransaction)46     public static void applyAndDeleteSurfaceTransaction(long surfaceTransaction) {
47         nSurfaceTransaction_apply(surfaceTransaction);
48         nSurfaceTransaction_delete(surfaceTransaction);
49     }
50 
setVisibility(long surfaceControl, boolean visible)51     public static void setVisibility(long surfaceControl, boolean visible) {
52         long surfaceTransaction = createSurfaceTransaction();
53         nSurfaceTransaction_setVisibility(surfaceControl, surfaceTransaction, visible);
54         applyAndDeleteSurfaceTransaction(surfaceTransaction);
55     }
56 
setBufferOpaque(long surfaceControl, boolean opaque)57     public static void setBufferOpaque(long surfaceControl, boolean opaque) {
58         long surfaceTransaction = createSurfaceTransaction();
59         nSurfaceTransaction_setBufferOpaque(surfaceControl, surfaceTransaction, opaque);
60         applyAndDeleteSurfaceTransaction(surfaceTransaction);
61     }
62 
setGeometry(long surfaceControl, int srcLeft, int srcTop, int srcRight, int srcBottom, int dstLeft, int dstTop, int dstRight, int dstBottom, int transform)63     public static void setGeometry(long surfaceControl, int srcLeft, int srcTop, int srcRight,
64             int srcBottom, int dstLeft, int dstTop, int dstRight, int dstBottom,
65             int transform) {
66         long surfaceTransaction = createSurfaceTransaction();
67         nSurfaceTransaction_setGeometry(surfaceControl, surfaceTransaction, srcLeft, srcTop,
68                 srcRight, srcBottom,
69                 dstLeft, dstTop, dstRight, dstBottom, transform);
70         applyAndDeleteSurfaceTransaction(surfaceTransaction);
71     }
72 
setZOrder(long surfaceControl, int z)73     public static void setZOrder(long surfaceControl, int z) {
74         long surfaceTransaction = createSurfaceTransaction();
75         nSurfaceTransaction_setZOrder(surfaceControl, surfaceTransaction, z);
76         applyAndDeleteSurfaceTransaction(surfaceTransaction);
77     }
78 
setBufferAlpha(long surfaceControl, double alpha)79     public static void setBufferAlpha(long surfaceControl, double alpha) {
80         long surfaceTransaction = createSurfaceTransaction();
81         nSurfaceTransaction_setBufferAlpha(surfaceControl, surfaceTransaction, alpha);
82         applyAndDeleteSurfaceTransaction(surfaceTransaction);
83     }
84 
setColor(long surfaceControl, float red, float green, float blue, float alpha)85     public static void setColor(long surfaceControl, float red, float green, float blue,
86             float alpha) {
87         long surfaceTransaction = createSurfaceTransaction();
88         nSurfaceTransaction_setColor(surfaceControl, surfaceTransaction, red, green, blue, alpha);
89         applyAndDeleteSurfaceTransaction(surfaceTransaction);
90     }
91 
setPosition(long surfaceControl, int x, int y)92     public static void setPosition(long surfaceControl, int x, int y) {
93         long surfaceTransaction = createSurfaceTransaction();
94         nSurfaceTransaction_setPosition(surfaceControl, surfaceTransaction, x, y);
95         applyAndDeleteSurfaceTransaction(surfaceTransaction);
96     }
97 
setScale(long surfaceControl, float xScale, float yScale)98     public static void setScale(long surfaceControl, float xScale, float yScale) {
99         long surfaceTransaction = createSurfaceTransaction();
100         nSurfaceTransaction_setScale(surfaceControl, surfaceTransaction, xScale, yScale);
101         applyAndDeleteSurfaceTransaction(surfaceTransaction);
102     }
103 
setBufferTransform(long surfaceControl, int bufferTransform)104     public static void setBufferTransform(long surfaceControl, int bufferTransform) {
105         long surfaceTransaction = createSurfaceTransaction();
106         nSurfaceTransaction_setBufferTransform(surfaceControl, surfaceTransaction,
107                 bufferTransform);
108         applyAndDeleteSurfaceTransaction(surfaceTransaction);
109     }
110 
setCrop(long surfaceControl, Rect crop)111     public static void setCrop(long surfaceControl, Rect crop) {
112         long surfaceTransaction = createSurfaceTransaction();
113         nSurfaceTransaction_setCrop(surfaceControl, surfaceTransaction, crop.left, crop.top,
114                 crop.right, crop.bottom);
115         applyAndDeleteSurfaceTransaction(surfaceTransaction);
116     }
117 
118     ///////////////////////////////////////////////////////////////////////////
119     // Native function prototypes
120     ///////////////////////////////////////////////////////////////////////////
121 
nSurfaceTransaction_create()122     public static native long nSurfaceTransaction_create();
nSurfaceTransaction_delete(long surfaceTransaction)123     public static native void nSurfaceTransaction_delete(long surfaceTransaction);
nSurfaceTransaction_apply(long surfaceTransaction)124     public static native void nSurfaceTransaction_apply(long surfaceTransaction);
nSurfaceControl_createFromWindow(Surface surface)125     public static native long nSurfaceControl_createFromWindow(Surface surface);
nSurfaceControl_create(long surfaceControl)126     public static native long nSurfaceControl_create(long surfaceControl);
nSurfaceControl_acquire(long surfaceControl)127     public static native void nSurfaceControl_acquire(long surfaceControl);
nSurfaceControl_release(long surfaceControl)128     public static native void nSurfaceControl_release(long surfaceControl);
nSurfaceTransaction_setSolidBuffer( long surfaceControl, long surfaceTransaction, int width, int height, int color)129     public static native long nSurfaceTransaction_setSolidBuffer(
130             long surfaceControl, long surfaceTransaction, int width, int height, int color);
nSurfaceTransaction_setBuffer(long surfaceControl, long surfaceTransaction, long buffer)131     public static native void nSurfaceTransaction_setBuffer(long surfaceControl,
132             long surfaceTransaction, long buffer);
nSurfaceTransaction_setQuadrantBuffer(long surfaceControl, long surfaceTransaction, int width, int height, int colorTopLeft, int colorTopRight, int colorBottomRight, int colorBottomLeft)133     public static native long nSurfaceTransaction_setQuadrantBuffer(long surfaceControl,
134             long surfaceTransaction, int width, int height, int colorTopLeft, int colorTopRight,
135             int colorBottomRight, int colorBottomLeft);
nSurfaceTransaction_releaseBuffer(long buffer)136     public static native void nSurfaceTransaction_releaseBuffer(long buffer);
nSurfaceTransaction_setVisibility( long surfaceControl, long surfaceTransaction, boolean show)137     public static native void nSurfaceTransaction_setVisibility(
138             long surfaceControl, long surfaceTransaction, boolean show);
nSurfaceTransaction_setBufferOpaque( long surfaceControl, long surfaceTransaction, boolean opaque)139     public static native void nSurfaceTransaction_setBufferOpaque(
140             long surfaceControl, long surfaceTransaction, boolean opaque);
nSurfaceTransaction_setGeometry( long surfaceControl, long surfaceTransaction, int srcRight, int srcTop, int srcLeft, int srcBottom, int dstRight, int dstTop, int dstLeft, int dstBottom, int transform)141     public static native void nSurfaceTransaction_setGeometry(
142             long surfaceControl, long surfaceTransaction, int srcRight, int srcTop, int srcLeft,
143             int srcBottom, int dstRight, int dstTop, int dstLeft, int dstBottom, int transform);
nSurfaceTransaction_setCrop(long surfaceControl, long surfaceTransaction, int left, int top, int right, int bottom)144     public static native void nSurfaceTransaction_setCrop(long surfaceControl,
145             long surfaceTransaction, int left, int top, int right, int bottom);
nSurfaceTransaction_setPosition(long surfaceControl, long surfaceTransaction, int left, int top)146     public static native void nSurfaceTransaction_setPosition(long surfaceControl,
147             long surfaceTransaction, int left, int top);
nSurfaceTransaction_setBufferTransform( long surfaceControl, long surfaceTransaction, int transform)148     public static native void nSurfaceTransaction_setBufferTransform(
149             long surfaceControl, long surfaceTransaction, int transform);
nSurfaceTransaction_setScale(long surfaceControl, long surfaceTransaction, float xScale, float yScale)150     public static native void nSurfaceTransaction_setScale(long surfaceControl,
151             long surfaceTransaction, float xScale, float yScale);
nSurfaceTransaction_setDamageRegion( long surfaceControl, long surfaceTransaction, int right, int top, int left, int bottom)152     public static native void nSurfaceTransaction_setDamageRegion(
153             long surfaceControl, long surfaceTransaction, int right, int top, int left, int bottom);
nSurfaceTransaction_setZOrder( long surfaceControl, long surfaceTransaction, int z)154     public static native void nSurfaceTransaction_setZOrder(
155             long surfaceControl, long surfaceTransaction, int z);
nSurfaceTransaction_setDesiredPresentTime(long surfaceTransaction, long desiredPresentTimeOffset)156     public static native long nSurfaceTransaction_setDesiredPresentTime(long surfaceTransaction,
157             long desiredPresentTimeOffset);
nSurfaceTransaction_setBufferAlpha(long surfaceControl, long surfaceTransaction, double alpha)158     public static native void nSurfaceTransaction_setBufferAlpha(long surfaceControl,
159             long surfaceTransaction, double alpha);
nSurfaceTransaction_reparent(long surfaceControl, long newParentSurfaceControl, long surfaceTransaction)160     public static native void nSurfaceTransaction_reparent(long surfaceControl,
161             long newParentSurfaceControl, long surfaceTransaction);
nSurfaceTransaction_setColor(long surfaceControl, long surfaceTransaction, float r, float g, float b, float alpha)162     public static native void nSurfaceTransaction_setColor(long surfaceControl,
163             long surfaceTransaction, float r, float g, float b, float alpha);
nSurfaceTransaction_setEnableBackPressure(long surfaceControl, long surfaceTransaction, boolean enableBackPressure)164     public static native void nSurfaceTransaction_setEnableBackPressure(long surfaceControl,
165             long surfaceTransaction, boolean enableBackPressure);
nSurfaceTransaction_setOnCompleteCallback(long surfaceTransaction, boolean waitForFence, TransactionCompleteListener listener)166     public static native void nSurfaceTransaction_setOnCompleteCallback(long surfaceTransaction,
167             boolean waitForFence, TransactionCompleteListener listener);
nSurfaceTransaction_setOnCommitCallback(long surfaceTransaction, TransactionCompleteListener listener)168     public static native void nSurfaceTransaction_setOnCommitCallback(long surfaceTransaction,
169             TransactionCompleteListener listener);
nSurfaceTransaction_setOnCompleteCallbackWithoutContext( long surfaceTransaction, boolean waitForFence, TransactionCompleteListener listener)170     public static native void nSurfaceTransaction_setOnCompleteCallbackWithoutContext(
171             long surfaceTransaction, boolean waitForFence, TransactionCompleteListener listener);
nSurfaceTransaction_setOnCommitCallbackWithoutContext( long surfaceTransaction, TransactionCompleteListener listener)172     public static native void nSurfaceTransaction_setOnCommitCallbackWithoutContext(
173             long surfaceTransaction, TransactionCompleteListener listener);
nSurfaceTransaction_setFrameTimeline(long surfaceTransaction, long vsyncId)174     public static native void nSurfaceTransaction_setFrameTimeline(long surfaceTransaction,
175             long vsyncId);
176 
getSolidBuffer(int width, int height, int color)177     public static native HardwareBuffer getSolidBuffer(int width, int height, int color);
getQuadrantBuffer(int width, int height, int colorTopLeft, int colorTopRight, int colorBottomRight, int colorBottomLeft)178     public static native HardwareBuffer getQuadrantBuffer(int width, int height,
179             int colorTopLeft, int colorTopRight, int colorBottomRight, int colorBottomLeft);
getBufferId(HardwareBuffer buffer)180     public static native long getBufferId(HardwareBuffer buffer);
181 }
182