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