Merge "Add support to toggle different shader behaviors" into sc-dev

This commit is contained in:
Nader Jawad
2021-05-18 16:27:47 +00:00
committed by Android (Google) Code Review
10 changed files with 36 additions and 15 deletions

View File

@@ -1195,6 +1195,7 @@ public class HardwareRenderer {
// so not checking for isolated process here.
initHintSession();
nSetIsHighEndGfx(ActivityManager.isHighEndGfx());
// Defensively clear out the context in case we were passed a context that can leak
// if we live longer than it, e.g. an activity context.
mContext = null;
@@ -1315,6 +1316,8 @@ public class HardwareRenderer {
private static native void nSetSdrWhitePoint(long nativeProxy, float whitePoint);
private static native void nSetIsHighEndGfx(boolean isHighEndGfx);
private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size);
private static native void nDestroy(long nativeProxy, long rootRenderNode);

View File

@@ -157,7 +157,7 @@ static inline void applyMatrix(const SkMatrix& transform, SkRect* rect) {
static inline void mapRect(const RenderProperties& props, const SkRect& in, SkRect* out) {
if (in.isEmpty()) return;
SkRect temp(in);
if (Properties::stretchEffectBehavior == StretchEffectBehavior::UniformScale) {
if (Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) {
const StretchEffect& stretch = props.layerProperties().getStretchEffect();
if (!stretch.isEmpty()) {
applyMatrix(stretch.makeLinearStretch(props.getWidth(), props.getHeight()), &temp);

View File

@@ -137,10 +137,6 @@ bool Properties::load() {
targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
int stretchType = base::GetIntProperty(PROPERTY_STRETCH_EFFECT_TYPE, 0);
stretchType = std::clamp(stretchType, 0, static_cast<int>(StretchEffectBehavior::UniformScale));
stretchEffectBehavior = static_cast<StretchEffectBehavior>(stretchType);
return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
}

View File

@@ -171,8 +171,6 @@ enum DebugLevel {
*/
#define PROPERTY_TARGET_CPU_TIME_PERCENTAGE "debug.hwui.target_cpu_time_percent"
#define PROPERTY_STRETCH_EFFECT_TYPE "debug.hwui.stretch_mode"
/**
* Property for whether this is running in the emulator.
*/
@@ -278,9 +276,26 @@ public:
static bool useHintManager;
static int targetCpuTimePercentage;
static StretchEffectBehavior stretchEffectBehavior;
static StretchEffectBehavior getStretchEffectBehavior() {
return stretchEffectBehavior;
}
static void setIsHighEndGfx(bool isHighEndGfx) {
stretchEffectBehavior = isHighEndGfx ?
StretchEffectBehavior::ShaderHWUI :
StretchEffectBehavior::UniformScale;
}
/**
* Used for testing. Typical configuration of stretch behavior is done
* through setIsHighEndGfx
*/
static void setStretchEffectBehavior(StretchEffectBehavior behavior) {
stretchEffectBehavior = behavior;
}
private:
static StretchEffectBehavior stretchEffectBehavior;
static ProfileType sProfileType;
static bool sDisableProfileBars;
static RenderPipelineType sRenderPipelineType;

View File

@@ -478,7 +478,7 @@ void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform)
}
}
if (Properties::stretchEffectBehavior == StretchEffectBehavior::UniformScale) {
if (Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) {
const StretchEffect& stretch = properties().layerProperties().getStretchEffect();
if (!stretch.isEmpty()) {
matrix.multiply(

View File

@@ -111,7 +111,7 @@ public:
bool requiresLayer() const {
return !(isEmpty() ||
Properties::stretchEffectBehavior == StretchEffectBehavior::UniformScale);
Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale);
}
private:

View File

@@ -324,6 +324,11 @@ static void android_view_ThreadedRenderer_setSdrWhitePoint(JNIEnv* env, jobject
Properties::defaultSdrWhitePoint = sdrWhitePoint;
}
static void android_view_ThreadedRenderer_setIsHighEndGfx(JNIEnv* env, jobject clazz,
jboolean jIsHighEndGfx) {
Properties::setIsHighEndGfx(jIsHighEndGfx);
}
static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz,
jlong proxyPtr, jlongArray frameInfo, jint frameInfoSize) {
LOG_ALWAYS_FATAL_IF(frameInfoSize != UI_THREAD_FRAME_INFO_SIZE,
@@ -795,6 +800,7 @@ static const JNINativeMethod gMethods[] = {
{"nSetOpaque", "(JZ)V", (void*)android_view_ThreadedRenderer_setOpaque},
{"nSetColorMode", "(JI)V", (void*)android_view_ThreadedRenderer_setColorMode},
{"nSetSdrWhitePoint", "(JF)V", (void*)android_view_ThreadedRenderer_setSdrWhitePoint},
{"nSetIsHighEndGfx", "(Z)V", (void*)android_view_ThreadedRenderer_setIsHighEndGfx},
{"nSyncAndDrawFrame", "(J[JI)I", (void*)android_view_ThreadedRenderer_syncAndDrawFrame},
{"nDestroy", "(JJ)V", (void*)android_view_ThreadedRenderer_destroy},
{"nRegisterAnimatingRenderNode", "(JJ)V",

View File

@@ -574,7 +574,7 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
uirenderer::Rect bounds(props.getWidth(), props.getHeight());
bool useStretchShader =
Properties::stretchEffectBehavior != StretchEffectBehavior::UniformScale;
Properties::getStretchEffectBehavior() != StretchEffectBehavior::UniformScale;
if (useStretchShader && info.stretchEffectCount) {
handleStretchEffect(info, bounds);
}
@@ -680,7 +680,8 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
stretchTargetBounds(*effect, result.width, result.height,
childRelativeBounds,targetBounds);
if (Properties::stretchEffectBehavior == StretchEffectBehavior::Shader) {
if (Properties::getStretchEffectBehavior() ==
StretchEffectBehavior::Shader) {
JNIEnv* env = jnienv();
jobject localref = env->NewLocalRef(mWeakRef);

View File

@@ -248,7 +248,7 @@ void RenderNodeDrawable::drawContent(SkCanvas* canvas) const {
const StretchEffect& stretch = properties.layerProperties().getStretchEffect();
if (stretch.isEmpty() ||
Properties::stretchEffectBehavior == StretchEffectBehavior::UniformScale) {
Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) {
// If we don't have any stretch effects, issue the filtered
// canvas draw calls to make sure we still punch a hole
// with the same canvas transformation + clip into the target
@@ -327,7 +327,7 @@ void RenderNodeDrawable::setViewProperties(const RenderProperties& properties, S
canvas->concat(*properties.getTransformMatrix());
}
}
if (Properties::stretchEffectBehavior == StretchEffectBehavior::UniformScale) {
if (Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) {
const StretchEffect& stretch = properties.layerProperties().getStretchEffect();
if (!stretch.isEmpty()) {
canvas->concat(

View File

@@ -186,7 +186,7 @@ private:
void doFrame(int frameNr) override {
if (frameNr == 0) {
Properties::stretchEffectBehavior = stretchBehavior();
Properties::setStretchEffectBehavior(stretchBehavior());
if (forceLayer()) {
mListView->mutateStagingProperties().mutateLayerProperties().setType(
LayerType::RenderLayer);