Merge changes from topic "gpuprio" into pi-dev

* changes:
  Add ThreadedRendererCompat for Launcher use
  Add ability to change context priority of RT GL context
This commit is contained in:
TreeHugger Robot
2018-04-06 13:30:33 +00:00
committed by Android (Google) Code Review
6 changed files with 69 additions and 2 deletions

View File

@@ -190,6 +190,10 @@ public final class ThreadedRenderer {
*/
public static final String DEBUG_FPS_DIVISOR = "debug.hwui.fps_divisor";
public static int EGL_CONTEXT_PRIORITY_HIGH_IMG = 0x3101;
public static int EGL_CONTEXT_PRIORITY_MEDIUM_IMG = 0x3102;
public static int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
static {
// Try to check OpenGL support early if possible.
isAvailable();
@@ -1140,6 +1144,16 @@ public final class ThreadedRenderer {
nHackySetRTAnimationsEnabled(divisor <= 1);
}
/**
* Changes the OpenGL context priority if IMG_context_priority extension is available. Must be
* called before any OpenGL context is created.
*
* @param priority The priority to use. Must be one of EGL_CONTEXT_PRIORITY_* values.
*/
public static void setContextPriority(int priority) {
nSetContextPriority(priority);
}
/** Not actually public - internal use only. This doc to make lint happy */
public static native void disableVsync();
@@ -1213,4 +1227,5 @@ public final class ThreadedRenderer {
private static native void nHackySetRTAnimationsEnabled(boolean enabled);
private static native void nSetDebuggingEnabled(boolean enabled);
private static native void nSetIsolatedProcess(boolean enabled);
private static native void nSetContextPriority(int priority);
}

View File

@@ -992,6 +992,10 @@ static void android_view_ThreadedRenderer_setIsolatedProcess(JNIEnv*, jclass, jb
Properties::isolatedProcess = isolated;
}
static void android_view_ThreadedRenderer_setContextPriority(JNIEnv*, jclass,
jint contextPriority) {
Properties::contextPriority = contextPriority;
}
// ----------------------------------------------------------------------------
// FrameMetricsObserver
@@ -1103,6 +1107,7 @@ static const JNINativeMethod gMethods[] = {
(void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled },
{ "nSetDebuggingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDebuggingEnabled },
{ "nSetIsolatedProcess", "(Z)V", (void*)android_view_ThreadedRenderer_setIsolatedProcess },
{ "nSetContextPriority", "(I)V", (void*)android_view_ThreadedRenderer_setContextPriority },
};
static JavaVM* mJvm = nullptr;

View File

@@ -65,6 +65,8 @@ bool Properties::runningInEmulator = false;
bool Properties::debuggingEnabled = false;
bool Properties::isolatedProcess = false;
int Properties::contextPriority = 0;
static int property_get_int(const char* key, int defaultValue) {
char buf[PROPERTY_VALUE_MAX] = {
'\0',

View File

@@ -271,6 +271,8 @@ public:
ANDROID_API static bool debuggingEnabled;
ANDROID_API static bool isolatedProcess;
ANDROID_API static int contextPriority;
private:
static ProfileType sProfileType;
static bool sDisableProfileBars;

View File

@@ -82,6 +82,7 @@ static struct {
bool pixelFormatFloat = false;
bool glColorSpace = false;
bool scRGB = false;
bool contextPriority = false;
} EglExtensions;
EglManager::EglManager(RenderThread& thread)
@@ -168,6 +169,7 @@ void EglManager::initExtensions() {
#else
EglExtensions.scRGB = extensions.has("EGL_EXT_gl_colorspace_scrgb");
#endif
EglExtensions.contextPriority = extensions.has("EGL_IMG_context_priority");
}
bool EglManager::hasEglContext() {
@@ -247,10 +249,18 @@ void EglManager::loadConfigs() {
}
void EglManager::createContext() {
EGLint attribs[] = {EGL_CONTEXT_CLIENT_VERSION, GLES_VERSION, EGL_NONE};
std::vector<EGLint> contextAttributes;
contextAttributes.reserve(5);
contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
contextAttributes.push_back(GLES_VERSION);
if (Properties::contextPriority != 0 && EglExtensions.contextPriority) {
contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
contextAttributes.push_back(Properties::contextPriority);
}
contextAttributes.push_back(EGL_NONE);
mEglContext = eglCreateContext(
mEglDisplay, EglExtensions.noConfigContext ? ((EGLConfig) nullptr) : mEglConfig,
EGL_NO_CONTEXT, attribs);
EGL_NO_CONTEXT, contextAttributes.data());
LOG_ALWAYS_FATAL_IF(mEglContext == EGL_NO_CONTEXT, "Failed to create context, error = %s",
eglErrorString());
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2018 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
*/
package com.android.systemui.shared.system;
import android.view.ThreadedRenderer;
/**
* @see ThreadedRenderer
*/
public class ThreadedRendererCompat {
public static int EGL_CONTEXT_PRIORITY_HIGH_IMG = 0x3101;
public static int EGL_CONTEXT_PRIORITY_MEDIUM_IMG = 0x3102;
public static int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
public static void setContextPriority(int priority) {
ThreadedRenderer.setContextPriority(priority);
}
}