Merge changes from topic "cp_slim"

* changes:
  Lazy load Properties::isDrawingEnabled.
  Backport 'add config to disable snapshots'.
  Backport 'Add ability to disable GL draws'.
This commit is contained in:
Brett Chabot 2021-11-03 18:00:49 +00:00 committed by Gerrit Code Review
commit a90cb087c0
9 changed files with 123 additions and 5 deletions

View File

@ -5054,4 +5054,7 @@
<!-- the number of the max cached processes in the system. -->
<integer name="config_customizedMaxCachedProcesses">32</integer>
<!-- Whether this device should support taking app snapshots on closure -->
<bool name="config_disableTaskSnapshots">false</bool>
</resources>

View File

@ -4403,7 +4403,7 @@
<java-symbol type="string" name="view_and_control_notification_title" />
<java-symbol type="string" name="view_and_control_notification_content" />
<java-symbol type="array" name="config_accessibility_allowed_install_source" />
<!-- Translation -->
<java-symbol type="string" name="ui_translation_accessibility_translated_text" />
<java-symbol type="string" name="ui_translation_accessibility_translation_finished" />
@ -4430,4 +4430,7 @@
<java-symbol type="array" name="config_sharedLibrariesLoadedAfterApp" />
<java-symbol type="integer" name="config_customizedMaxCachedProcesses" />
<java-symbol type="bool" name="config_disableTaskSnapshots" />
</resources>

View File

@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
@ -1075,6 +1076,53 @@ public class HardwareRenderer {
ProcessInitializer.sInstance.setContext(context);
}
/**
* Returns true if HardwareRender will produce output.
*
* This value is global to the process and affects all uses of HardwareRenderer,
* including
* those created by the system such as those used by the View tree when using hardware
* accelerated rendering.
*
* Default is true in all production environments, but may be false in testing-focused
* emulators or if {@link #setDrawingEnabled(boolean)} is used.
*
* Backported from android T.
*
* @hide
*/
@UnsupportedAppUsage
public static boolean isDrawingEnabled() {
return nIsDrawingEnabled();
}
/**
* Toggles whether or not HardwareRenderer will produce drawing output globally in the current
* process.
*
* This applies to all HardwareRenderer instances, including those created by the platform such
* as those used by the system for hardware accelerated View rendering.
*
* The capability to disable drawing output is intended for test environments, primarily
* headless ones. By setting this to false, tests that launch activities or interact with Views
* can be quicker with less RAM usage by skipping the final step of View drawing. All View
* lifecycle events will occur as normal, only the final step of rendering on the GPU to the
* display will be skipped.
*
* This can be toggled on and off at will, so screenshot tests can also run in this same
* environment by toggling drawing back on and forcing a frame to be drawn such as by calling
* view#invalidate(). Once drawn and the screenshot captured, this can then be turned back off.
*
* Backported from android T.
*
* @hide
*/
// TODO: Add link to androidx's Screenshot library for help with this
@UnsupportedAppUsage
public static void setDrawingEnabled(boolean drawingEnabled) {
nSetDrawingEnabled(drawingEnabled);
}
private static final class DestroyContextRunnable implements Runnable {
private final long mNativeInstance;
@ -1393,4 +1441,8 @@ public class HardwareRenderer {
private static native void nInitDisplayInfo(int width, int height, float refreshRate,
int wideColorDataspace, long appVsyncOffsetNanos, long presentationDeadlineNanos);
private static native void nSetDrawingEnabled(boolean drawingEnabled);
private static native boolean nIsDrawingEnabled();
}

View File

@ -88,6 +88,8 @@ bool Properties::enableWebViewOverlays = false;
StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
bool Properties::load() {
bool prevDebugLayersUpdates = debugLayersUpdates;
bool prevDebugOverdraw = debugOverdraw;
@ -141,6 +143,9 @@ bool Properties::load() {
enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, false);
// call isDrawingEnabled to force loading of the property
isDrawingEnabled();
return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
}
@ -210,5 +215,19 @@ void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnit
sRenderPipelineType = type;
}
void Properties::setDrawingEnabled(bool newDrawingEnabled) {
drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
enableRTAnimations = newDrawingEnabled;
}
bool Properties::isDrawingEnabled() {
if (drawingEnabled == DrawingEnabled::NotInitialized) {
bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
enableRTAnimations = drawingEnabledProp;
}
return drawingEnabled == DrawingEnabled::On;
}
} // namespace uirenderer
} // namespace android

View File

@ -187,6 +187,12 @@ enum DebugLevel {
*/
#define PROPERTY_WEBVIEW_OVERLAYS_ENABLED "debug.hwui.webview_overlays_enabled"
/**
* Property for globally GL drawing state. Can be overridden per process with
* setDrawingEnabled.
*/
#define PROPERTY_DRAWING_ENABLED "debug.hwui.drawing_enabled"
///////////////////////////////////////////////////////////////////////////////
// Misc
///////////////////////////////////////////////////////////////////////////////
@ -208,6 +214,8 @@ enum class StretchEffectBehavior {
UniformScale // Uniform scale stretch everywhere
};
enum class DrawingEnabled { NotInitialized, On, Off };
/**
* Renderthread-only singleton which manages several static rendering properties. Most of these
* are driven by system properties which are queried once at initialization, and again if init()
@ -301,6 +309,11 @@ public:
stretchEffectBehavior = behavior;
}
// Represents if drawing is enabled. Should only be Off in headless testing environments
static DrawingEnabled drawingEnabled;
static bool isDrawingEnabled();
static void setDrawingEnabled(bool enable);
private:
static StretchEffectBehavior stretchEffectBehavior;
static ProfileType sProfileType;

View File

@ -817,6 +817,14 @@ static void android_view_ThreadedRenderer_initDisplayInfo(JNIEnv*, jclass, jint
DeviceInfo::setPresentationDeadlineNanos(presentationDeadlineNanos);
}
static void android_view_ThreadedRenderer_setDrawingEnabled(JNIEnv*, jclass, jboolean enabled) {
Properties::setDrawingEnabled(enabled);
}
static jboolean android_view_ThreadedRenderer_isDrawingEnabled(JNIEnv*, jclass) {
return Properties::isDrawingEnabled();
}
// ----------------------------------------------------------------------------
// HardwareRendererObserver
// ----------------------------------------------------------------------------
@ -953,6 +961,9 @@ static const JNINativeMethod gMethods[] = {
{"preload", "()V", (void*)android_view_ThreadedRenderer_preload},
{"isWebViewOverlaysEnabled", "()Z",
(void*)android_view_ThreadedRenderer_isWebViewOverlaysEnabled},
{"nSetDrawingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDrawingEnabled},
{"nIsDrawingEnabled", "()Z", (void*)android_view_ThreadedRenderer_isDrawingEnabled},
};
static JavaVM* mJvm = nullptr;

View File

@ -256,7 +256,7 @@ void CanvasContext::setStopped(bool stopped) {
}
void CanvasContext::allocateBuffers() {
if (mNativeSurface) {
if (mNativeSurface && Properties::isDrawingEnabled()) {
ANativeWindow_tryAllocateBuffers(mNativeSurface->getNativeWindow());
}
}
@ -480,7 +480,8 @@ nsecs_t CanvasContext::draw() {
SkRect dirty;
mDamageAccumulator.finish(&dirty);
if (dirty.isEmpty() && Properties::skipEmptyFrames && !surfaceRequiresRedraw()) {
if (!Properties::isDrawingEnabled() ||
(dirty.isEmpty() && Properties::skipEmptyFrames && !surfaceRequiresRedraw())) {
mCurrentFrameInfo->addFlag(FrameInfoFlags::SkippedFrame);
if (auto grContext = getGrContext()) {
// Submit to ensure that any texture uploads complete and Skia can

View File

@ -90,9 +90,17 @@ public:
* and false otherwise (e.g. cache limits have been exceeded).
*/
bool pinImages(std::vector<SkImage*>& mutableImages) {
if (!Properties::isDrawingEnabled()) {
return true;
}
return mRenderPipeline->pinImages(mutableImages);
}
bool pinImages(LsaVector<sk_sp<Bitmap>>& images) { return mRenderPipeline->pinImages(images); }
bool pinImages(LsaVector<sk_sp<Bitmap>>& images) {
if (!Properties::isDrawingEnabled()) {
return true;
}
return mRenderPipeline->pinImages(images);
}
/**
* Unpin any image that had be previously pinned to the GPU cache

View File

@ -118,6 +118,11 @@ class TaskSnapshotController {
*/
private final boolean mIsRunningOnWear;
/**
* Flag indicating if device configuration has disabled app snapshots.
*/
private final boolean mConfigDisableTaskSnapshots;
TaskSnapshotController(WindowManagerService service) {
mService = service;
mPersister = new TaskSnapshotPersister(mService, Environment::getDataSystemCeDirectory);
@ -131,6 +136,8 @@ class TaskSnapshotController {
PackageManager.FEATURE_WATCH);
mHighResTaskSnapshotScale = mService.mContext.getResources().getFloat(
com.android.internal.R.dimen.config_highResTaskSnapshotScale);
mConfigDisableTaskSnapshots = mService.mContext.getResources().getBoolean(
com.android.internal.R.bool.config_disableTaskSnapshots);
}
void systemReady() {
@ -488,7 +495,8 @@ class TaskSnapshotController {
}
boolean shouldDisableSnapshots() {
return mIsRunningOnWear || mIsRunningOnTv || mIsRunningOnIoT;
return mIsRunningOnWear || mIsRunningOnTv || mIsRunningOnIoT
|| mConfigDisableTaskSnapshots;
}
/**