1/*
2 * Copyright (C) 2018 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
17package com.android.systemui.shared.system;
18
19import android.graphics.Matrix;
20import android.graphics.Rect;
21import android.os.IBinder;
22import android.view.Surface;
23import android.view.SurfaceControl;
24import android.view.SurfaceControl.Transaction;
25
26public class TransactionCompat {
27
28    final Transaction mTransaction;
29
30    final float[] mTmpValues = new float[9];
31
32    public TransactionCompat() {
33        mTransaction = new Transaction();
34    }
35
36    public void apply() {
37        mTransaction.apply();
38    }
39
40    public TransactionCompat show(SurfaceControlCompat surfaceControl) {
41        mTransaction.show(surfaceControl.mSurfaceControl);
42        return this;
43    }
44
45    public TransactionCompat hide(SurfaceControlCompat surfaceControl) {
46        mTransaction.hide(surfaceControl.mSurfaceControl);
47        return this;
48    }
49
50    public TransactionCompat setPosition(SurfaceControlCompat surfaceControl, float x, float y) {
51        mTransaction.setPosition(surfaceControl.mSurfaceControl, x, y);
52        return this;
53    }
54
55    public TransactionCompat setSize(SurfaceControlCompat surfaceControl, int w, int h) {
56        mTransaction.setSize(surfaceControl.mSurfaceControl, w, h);
57        return this;
58    }
59
60    public TransactionCompat setLayer(SurfaceControlCompat surfaceControl, int z) {
61        mTransaction.setLayer(surfaceControl.mSurfaceControl, z);
62        return this;
63    }
64
65    public TransactionCompat setAlpha(SurfaceControlCompat surfaceControl, float alpha) {
66        mTransaction.setAlpha(surfaceControl.mSurfaceControl, alpha);
67        return this;
68    }
69
70    public TransactionCompat setMatrix(SurfaceControlCompat surfaceControl, float dsdx, float dtdx,
71            float dtdy, float dsdy) {
72        mTransaction.setMatrix(surfaceControl.mSurfaceControl, dsdx, dtdx, dtdy, dsdy);
73        return this;
74    }
75
76    public TransactionCompat setMatrix(SurfaceControlCompat surfaceControl, Matrix matrix) {
77        mTransaction.setMatrix(surfaceControl.mSurfaceControl, matrix, mTmpValues);
78        return this;
79    }
80
81    public TransactionCompat setWindowCrop(SurfaceControlCompat surfaceControl, Rect crop) {
82        mTransaction.setWindowCrop(surfaceControl.mSurfaceControl, crop);
83        return this;
84    }
85
86    public TransactionCompat setFinalCrop(SurfaceControlCompat surfaceControl, Rect crop) {
87        mTransaction.setFinalCrop(surfaceControl.mSurfaceControl, crop);
88        return this;
89    }
90
91    public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
92            IBinder handle, long frameNumber) {
93        mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, handle, frameNumber);
94        return this;
95    }
96
97    public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
98            Surface barrier, long frameNumber) {
99        mTransaction.deferTransactionUntilSurface(surfaceControl.mSurfaceControl, barrier,
100                frameNumber);
101        return this;
102    }
103
104    public TransactionCompat setEarlyWakeup() {
105        mTransaction.setEarlyWakeup();
106        return this;
107    }
108
109    public TransactionCompat setColor(SurfaceControlCompat surfaceControl, float[] color) {
110        mTransaction.setColor(surfaceControl.mSurfaceControl, color);
111        return this;
112    }
113}