Merge "Initialize egl_cache with an app writeable file" into ics-mr1

This commit is contained in:
Romain Guy
2011-11-10 15:02:07 -08:00
committed by Android (Google) Code Review
5 changed files with 99 additions and 1 deletions

View File

@ -45,6 +45,7 @@ import android.graphics.Canvas;
import android.net.IConnectivityManager;
import android.net.Proxy;
import android.net.ProxyProperties;
import android.opengl.GLUtils;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Debug;
@ -3714,6 +3715,24 @@ public final class ActivityThread {
}
}
private void setupGraphicsSupport(LoadedApk info) {
try {
int uid = Process.myUid();
String[] packages = getPackageManager().getPackagesForUid(uid);
// If there are several packages in this application we won't
// initialize the graphics disk caches
if (packages.length == 1) {
ContextImpl appContext = new ContextImpl();
appContext.init(info, null, this);
HardwareRenderer.setupDiskCache(appContext.getCacheDir());
}
} catch (RemoteException e) {
// Ignore
}
}
private void handleBindApplication(AppBindData data) {
mBoundApplication = data;
mConfiguration = new Configuration(data.config);
@ -3737,7 +3756,7 @@ public final class ActivityThread {
HardwareRenderer.disable(false);
}
}
if (mProfiler.profileFd != null) {
mProfiler.startProfiling();
}
@ -3773,6 +3792,8 @@ public final class ActivityThread {
data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
setupGraphicsSupport(data.info);
/**
* For system applications on userdebug/eng builds, log stack
* traces of disk and network access to dropbox for analysis.

View File

@ -34,6 +34,8 @@ import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL;
import java.io.File;
import static javax.microedition.khronos.egl.EGL10.*;
/**
@ -44,6 +46,11 @@ import static javax.microedition.khronos.egl.EGL10.*;
public abstract class HardwareRenderer {
static final String LOG_TAG = "HardwareRenderer";
/**
* Name of the file that holds the shaders cache.
*/
private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache";
/**
* Turn on to only refresh the parts of the screen that need updating.
* When turned on the property defined by {@link #RENDER_DIRTY_REGIONS_PROPERTY}
@ -199,6 +206,18 @@ public abstract class HardwareRenderer {
*/
abstract int getHeight();
/**
* Sets the directory to use as a persistent storage for hardware rendering
* resources.
*
* @param cacheDir A directory the current process can write to
*/
public static void setupDiskCache(File cacheDir) {
nSetupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath());
}
private static native void nSetupShadersDiskCache(String cacheFile);
/**
* Interface used to receive callbacks whenever a view is drawn by
* a hardware renderer instance.

View File

@ -53,6 +53,7 @@ LOCAL_SRC_FILES:= \
android_view_InputQueue.cpp \
android_view_KeyEvent.cpp \
android_view_KeyCharacterMap.cpp \
android_view_HardwareRenderer.cpp \
android_view_GLES20Canvas.cpp \
android_view_MotionEvent.cpp \
android_view_PointerIcon.cpp \
@ -160,6 +161,7 @@ LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
$(LOCAL_PATH)/android/graphics \
$(LOCAL_PATH)/../../libs/hwui \
$(LOCAL_PATH)/../../opengl/libs \
$(call include-path-for, bluedroid) \
$(call include-path-for, libhardware)/hardware \
$(call include-path-for, libhardware_legacy)/hardware_legacy \

View File

@ -116,6 +116,7 @@ extern int register_android_graphics_Xfermode(JNIEnv* env);
extern int register_android_graphics_PixelFormat(JNIEnv* env);
extern int register_android_view_Display(JNIEnv* env);
extern int register_android_view_GLES20Canvas(JNIEnv* env);
extern int register_android_view_HardwareRenderer(JNIEnv* env);
extern int register_android_view_Surface(JNIEnv* env);
extern int register_android_view_TextureView(JNIEnv* env);
extern int register_android_database_CursorWindow(JNIEnv* env);
@ -1101,6 +1102,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_graphics_PixelFormat),
REG_JNI(register_android_graphics_Graphics),
REG_JNI(register_android_view_GLES20Canvas),
REG_JNI(register_android_view_HardwareRenderer),
REG_JNI(register_android_view_Surface),
REG_JNI(register_android_view_TextureView),
REG_JNI(register_com_google_android_gles_jni_EGLImpl),

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "HardwareRenderer"
#include "jni.h"
#include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
#include <EGL/egl_cache.h>
namespace android {
// ----------------------------------------------------------------------------
// Misc
// ----------------------------------------------------------------------------
static void android_view_HardwareRenderer_setupShadersDiskCache(JNIEnv* env, jobject clazz,
jstring diskCachePath) {
const char* cacheArray = env->GetStringUTFChars(diskCachePath, NULL);
egl_cache_t::get()->setCacheFilename(cacheArray);
env->ReleaseStringUTFChars(diskCachePath, cacheArray);
}
// ----------------------------------------------------------------------------
// JNI Glue
// ----------------------------------------------------------------------------
const char* const kClassPathName = "android/view/HardwareRenderer";
static JNINativeMethod gMethods[] = {
{ "nSetupShadersDiskCache", "(Ljava/lang/String;)V",
(void*) android_view_HardwareRenderer_setupShadersDiskCache },
};
int register_android_view_HardwareRenderer(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}
};