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