Skip to content

Commit a958265

Browse files
author
Romain Guy
committed
Initialize egl_cache with an app writeable file
Change-Id: I5dda234feab0fedd6e4179a80715ae20dee1c833
1 parent 36a7f2a commit a958265

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.net.IConnectivityManager;
4646
import android.net.Proxy;
4747
import android.net.ProxyProperties;
48+
import android.opengl.GLUtils;
4849
import android.os.AsyncTask;
4950
import android.os.Bundle;
5051
import android.os.Debug;
@@ -3714,6 +3715,24 @@ final void handleTrimMemory(int level) {
37143715
}
37153716
}
37163717

3718+
private void setupGraphicsSupport(LoadedApk info) {
3719+
try {
3720+
int uid = Process.myUid();
3721+
String[] packages = getPackageManager().getPackagesForUid(uid);
3722+
3723+
// If there are several packages in this application we won't
3724+
// initialize the graphics disk caches
3725+
if (packages.length == 1) {
3726+
ContextImpl appContext = new ContextImpl();
3727+
appContext.init(info, null, this);
3728+
3729+
HardwareRenderer.setupDiskCache(appContext.getCacheDir());
3730+
}
3731+
} catch (RemoteException e) {
3732+
// Ignore
3733+
}
3734+
}
3735+
37173736
private void handleBindApplication(AppBindData data) {
37183737
mBoundApplication = data;
37193738
mConfiguration = new Configuration(data.config);
@@ -3737,7 +3756,7 @@ private void handleBindApplication(AppBindData data) {
37373756
HardwareRenderer.disable(false);
37383757
}
37393758
}
3740-
3759+
37413760
if (mProfiler.profileFd != null) {
37423761
mProfiler.startProfiling();
37433762
}
@@ -3773,6 +3792,8 @@ private void handleBindApplication(AppBindData data) {
37733792

37743793
data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
37753794

3795+
setupGraphicsSupport(data.info);
3796+
37763797
/**
37773798
* For system applications on userdebug/eng builds, log stack
37783799
* traces of disk and network access to dropbox for analysis.

core/java/android/view/HardwareRenderer.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import javax.microedition.khronos.egl.EGLSurface;
3535
import javax.microedition.khronos.opengles.GL;
3636

37+
import java.io.File;
38+
3739
import static javax.microedition.khronos.egl.EGL10.*;
3840

3941
/**
@@ -44,6 +46,11 @@
4446
public abstract class HardwareRenderer {
4547
static final String LOG_TAG = "HardwareRenderer";
4648

49+
/**
50+
* Name of the file that holds the shaders cache.
51+
*/
52+
private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache";
53+
4754
/**
4855
* Turn on to only refresh the parts of the screen that need updating.
4956
* When turned on the property defined by {@link #RENDER_DIRTY_REGIONS_PROPERTY}
@@ -199,6 +206,18 @@ public static boolean isAvailable() {
199206
*/
200207
abstract int getHeight();
201208

209+
/**
210+
* Sets the directory to use as a persistent storage for hardware rendering
211+
* resources.
212+
*
213+
* @param cacheDir A directory the current process can write to
214+
*/
215+
public static void setupDiskCache(File cacheDir) {
216+
nSetupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath());
217+
}
218+
219+
private static native void nSetupShadersDiskCache(String cacheFile);
220+
202221
/**
203222
* Interface used to receive callbacks whenever a view is drawn by
204223
* a hardware renderer instance.

core/jni/Android.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ LOCAL_SRC_FILES:= \
5353
android_view_InputQueue.cpp \
5454
android_view_KeyEvent.cpp \
5555
android_view_KeyCharacterMap.cpp \
56+
android_view_HardwareRenderer.cpp \
5657
android_view_GLES20Canvas.cpp \
5758
android_view_MotionEvent.cpp \
5859
android_view_PointerIcon.cpp \
@@ -160,6 +161,7 @@ LOCAL_C_INCLUDES += \
160161
$(JNI_H_INCLUDE) \
161162
$(LOCAL_PATH)/android/graphics \
162163
$(LOCAL_PATH)/../../libs/hwui \
164+
$(LOCAL_PATH)/../../opengl/libs \
163165
$(call include-path-for, bluedroid) \
164166
$(call include-path-for, libhardware)/hardware \
165167
$(call include-path-for, libhardware_legacy)/hardware_legacy \

core/jni/AndroidRuntime.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extern int register_android_graphics_Xfermode(JNIEnv* env);
116116
extern int register_android_graphics_PixelFormat(JNIEnv* env);
117117
extern int register_android_view_Display(JNIEnv* env);
118118
extern int register_android_view_GLES20Canvas(JNIEnv* env);
119+
extern int register_android_view_HardwareRenderer(JNIEnv* env);
119120
extern int register_android_view_Surface(JNIEnv* env);
120121
extern int register_android_view_TextureView(JNIEnv* env);
121122
extern int register_android_database_CursorWindow(JNIEnv* env);
@@ -1101,6 +1102,7 @@ static const RegJNIRec gRegJNI[] = {
11011102
REG_JNI(register_android_graphics_PixelFormat),
11021103
REG_JNI(register_android_graphics_Graphics),
11031104
REG_JNI(register_android_view_GLES20Canvas),
1105+
REG_JNI(register_android_view_HardwareRenderer),
11041106
REG_JNI(register_android_view_Surface),
11051107
REG_JNI(register_android_view_TextureView),
11061108
REG_JNI(register_com_google_android_gles_jni_EGLImpl),
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2010 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+
#define LOG_TAG "HardwareRenderer"
18+
19+
#include "jni.h"
20+
#include <nativehelper/JNIHelp.h>
21+
#include <android_runtime/AndroidRuntime.h>
22+
23+
#include <EGL/egl_cache.h>
24+
25+
namespace android {
26+
27+
// ----------------------------------------------------------------------------
28+
// Misc
29+
// ----------------------------------------------------------------------------
30+
31+
static void android_view_HardwareRenderer_setupShadersDiskCache(JNIEnv* env, jobject clazz,
32+
jstring diskCachePath) {
33+
34+
const char* cacheArray = env->GetStringUTFChars(diskCachePath, NULL);
35+
egl_cache_t::get()->setCacheFilename(cacheArray);
36+
env->ReleaseStringUTFChars(diskCachePath, cacheArray);
37+
}
38+
39+
// ----------------------------------------------------------------------------
40+
// JNI Glue
41+
// ----------------------------------------------------------------------------
42+
43+
const char* const kClassPathName = "android/view/HardwareRenderer";
44+
45+
static JNINativeMethod gMethods[] = {
46+
{ "nSetupShadersDiskCache", "(Ljava/lang/String;)V",
47+
(void*) android_view_HardwareRenderer_setupShadersDiskCache },
48+
};
49+
50+
int register_android_view_HardwareRenderer(JNIEnv* env) {
51+
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
52+
}
53+
54+
};

0 commit comments

Comments
 (0)