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 17 package android.graphics.cts; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.pm.ActivityInfo; 22 import android.content.res.AssetManager; 23 import android.content.res.Configuration; 24 import android.os.Bundle; 25 import android.util.Log; 26 import android.view.Surface; 27 import android.view.SurfaceHolder; 28 import android.view.SurfaceView; 29 import android.view.WindowManager; 30 31 /** 32 * Activity for VulkanPreTransformTest. 33 */ 34 public class VulkanPreTransformCtsActivity extends Activity implements SurfaceHolder.Callback { 35 static { 36 System.loadLibrary("ctsgraphics_jni"); 37 } 38 39 private static final String TAG = VulkanPreTransformCtsActivity.class.getSimpleName(); 40 41 private static boolean sOrientationRequested = false; 42 43 protected Surface mSurface; 44 45 @Override onCreate(Bundle savedInstanceState)46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 Log.d(TAG, "onCreate!"); 49 setActivityOrientation(); 50 setContentView(R.layout.vulkan_pretransform_layout); 51 SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceview); 52 surfaceView.getHolder().addCallback(this); 53 } 54 setActivityOrientation()55 private void setActivityOrientation() { 56 if (sOrientationRequested) { 57 // it might be called again because changing the orientation kicks off onCreate again!. 58 return; 59 } 60 61 if (getRotation() == Surface.ROTATION_0) { 62 if (getResources().getConfiguration().orientation 63 == Configuration.ORIENTATION_LANDSCAPE) { 64 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 65 } else { 66 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 67 } 68 } 69 70 sOrientationRequested = true; 71 } 72 getRotation()73 public int getRotation() { 74 return ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 75 .getDefaultDisplay() 76 .getRotation(); 77 } 78 testVulkanPreTransform(boolean setPreTransform)79 public void testVulkanPreTransform(boolean setPreTransform) { 80 synchronized (this) { 81 if (mSurface == null) { 82 try { 83 // Wait for surfaceCreated callback on UI thread. 84 this.wait(); 85 } catch (Exception e) { 86 } 87 } 88 } 89 nCreateNativeTest(getAssets(), mSurface, setPreTransform); 90 sOrientationRequested = false; 91 } 92 nCreateNativeTest( AssetManager manager, Surface surface, boolean setPreTransform)93 private static native void nCreateNativeTest( 94 AssetManager manager, Surface surface, boolean setPreTransform); 95 96 @Override surfaceCreated(SurfaceHolder holder)97 public void surfaceCreated(SurfaceHolder holder) { 98 synchronized (this) { 99 mSurface = holder.getSurface(); 100 this.notify(); 101 } 102 } 103 104 @Override surfaceChanged(SurfaceHolder holder, int format, int width, int height)105 public void surfaceChanged(SurfaceHolder holder, int format, 106 int width, int height) { 107 } 108 109 @Override surfaceDestroyed(SurfaceHolder holder)110 public void surfaceDestroyed(SurfaceHolder holder) { 111 } 112 } 113