1 /* 2 * Copyright (C) 2011 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.acceleration.cts; 18 19 import android.app.ActivityManager; 20 import android.content.Context; 21 import android.content.pm.ConfigurationInfo; 22 import android.content.pm.FeatureInfo; 23 import android.test.ActivityInstrumentationTestCase2; 24 import android.view.View; 25 26 abstract class BaseAccelerationTest<B extends BaseAcceleratedActivity> 27 extends ActivityInstrumentationTestCase2<B> { 28 29 protected B mActivity; 30 31 /** View with android:layerType="hardware" set */ 32 protected AcceleratedView mHardwareView; 33 34 /** View with android:layerType="software" set */ 35 protected AcceleratedView mSoftwareView; 36 37 /** View with setLayerType(HARDWARE) called */ 38 protected AcceleratedView mManualHardwareView; 39 40 /** View with setLayerType(SOFTWARE) called */ 41 protected AcceleratedView mManualSoftwareView; 42 BaseAccelerationTest(Class<B> clazz)43 BaseAccelerationTest(Class<B> clazz) { 44 super(clazz); 45 } 46 47 @Override setUp()48 protected void setUp() throws Exception { 49 super.setUp(); 50 mActivity = getActivity(); 51 mHardwareView = mActivity.getHardwareAcceleratedView(); 52 mSoftwareView = mActivity.getSoftwareAcceleratedView(); 53 mManualHardwareView = mActivity.getManualHardwareAcceleratedView(); 54 mManualSoftwareView = mActivity.getManualSoftwareAcceleratedView(); 55 } 56 testNotAttachedView()57 public void testNotAttachedView() { 58 // Views that are not attached can't be attached to an accelerated window. 59 View view = new View(mActivity); 60 assertFalse(view.isHardwareAccelerated()); 61 } 62 getGlEsVersion(Context context)63 protected static int getGlEsVersion(Context context) { 64 ActivityManager activityManager = 65 (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 66 ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo(); 67 if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) { 68 return getMajorVersion(configInfo.reqGlEsVersion); 69 } else { 70 return 1; // Lack of property means OpenGL ES version 1 71 } 72 } 73 74 /** @see FeatureInfo#getGlEsVersion() */ getMajorVersion(int glEsVersion)75 private static int getMajorVersion(int glEsVersion) { 76 return ((glEsVersion & 0xffff0000) >> 16); 77 } 78 } 79