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 #ifndef ANDROID_HWUI_PROPERTIES_H
18 #define ANDROID_HWUI_PROPERTIES_H
19 
20 #include <cutils/compiler.h>
21 
22 /**
23  * This file contains the list of system properties used to configure libhwui.
24  */
25 
26 namespace android {
27 namespace uirenderer {
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // Compile-time properties
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 // Textures used by layers must have dimensions multiples of this number
34 #define LAYER_SIZE 64
35 
36 // Defines the size in bits of the stencil buffer for the framebuffer
37 // Note: Only 1 bit is required for clipping but more bits are required
38 // to properly implement overdraw debugging
39 #define STENCIL_BUFFER_SIZE 8
40 
41 ///////////////////////////////////////////////////////////////////////////////
42 // Debug properties
43 ///////////////////////////////////////////////////////////////////////////////
44 
45 /**
46  * Debug level for app developers. The value is a numeric value defined
47  * by the DebugLevel enum below.
48  */
49 #define PROPERTY_DEBUG "debug.hwui.level"
50 
51 /**
52  * Debug levels. Debug levels are used as flags.
53  */
54 enum DebugLevel {
55     kDebugDisabled = 0,
56     kDebugMemory = 1,
57     kDebugCaches = 2,
58     kDebugMoreCaches = kDebugMemory | kDebugCaches
59 };
60 
61 /**
62  * Used to enable/disable layers update debugging. The accepted values are
63  * "true" and "false". The default value is "false".
64  */
65 #define PROPERTY_DEBUG_LAYERS_UPDATES "debug.hwui.show_layers_updates"
66 
67 /**
68  * Used to enable/disable overdraw debugging.
69  *
70  * The accepted values are
71  * "show", to show overdraw
72  * "show_deuteranomaly", to show overdraw if you suffer from Deuteranomaly
73  * "count", to show an overdraw counter
74  * "false", to disable overdraw debugging
75  *
76  * The default value is "false".
77  */
78 #define PROPERTY_DEBUG_OVERDRAW "debug.hwui.overdraw"
79 
80 /**
81  *  System property used to enable or disable hardware rendering profiling.
82  * The default value of this property is assumed to be false.
83  *
84  * When profiling is enabled, the adb shell dumpsys gfxinfo command will
85  * output extra information about the time taken to execute by the last
86  * frames.
87  *
88  * Possible values:
89  * "true", to enable profiling
90  * "visual_bars", to enable profiling and visualize the results on screen
91  * "false", to disable profiling
92  */
93 #define PROPERTY_PROFILE "debug.hwui.profile"
94 #define PROPERTY_PROFILE_VISUALIZE_BARS "visual_bars"
95 
96 /**
97  * Turn on to draw dirty regions every other frame.
98  *
99  * Possible values:
100  * "true", to enable dirty regions debugging
101  * "false", to disable dirty regions debugging
102  */
103 #define PROPERTY_DEBUG_SHOW_DIRTY_REGIONS "debug.hwui.show_dirty_regions"
104 
105 /**
106  * Setting this property will enable or disable the dropping of frames with
107  * empty damage. Default is "true".
108  */
109 #define PROPERTY_SKIP_EMPTY_DAMAGE "debug.hwui.skip_empty_damage"
110 
111 /**
112  * Controls whether or not HWUI will use the EGL_EXT_buffer_age extension
113  * to do partial invalidates. Setting this to "false" will fall back to
114  * using BUFFER_PRESERVED instead
115  * Default is "true"
116  */
117 #define PROPERTY_USE_BUFFER_AGE "debug.hwui.use_buffer_age"
118 
119 /**
120  * Setting this to "false" will force HWUI to always do full-redraws of the surface.
121  * This will disable the use of EGL_EXT_buffer_age and BUFFER_PRESERVED.
122  * Default is "true"
123  */
124 #define PROPERTY_ENABLE_PARTIAL_UPDATES "debug.hwui.use_partial_updates"
125 
126 #define PROPERTY_FILTER_TEST_OVERHEAD "debug.hwui.filter_test_overhead"
127 
128 /**
129  * Indicates whether PBOs can be used to back pixel buffers.
130  * Accepted values are "true" and "false". Default is true.
131  */
132 #define PROPERTY_ENABLE_GPU_PIXEL_BUFFERS "debug.hwui.use_gpu_pixel_buffers"
133 
134 /**
135  * Allows to set rendering pipeline mode to OpenGL (default), Skia OpenGL
136  * or Vulkan.
137  */
138 #define PROPERTY_RENDERER "debug.hwui.renderer"
139 
140 /**
141  * Allows to collect a recording of Skia drawing commands.
142  */
143 #define PROPERTY_CAPTURE_SKP_ENABLED "debug.hwui.capture_skp_enabled"
144 
145 /**
146  * Allows broad recording of Skia drawing commands.
147  *
148  * If disabled, a very minimal set of trace events *may* be recorded.
149  * If enabled, a much broader set of trace events *may* be recorded.
150  *
151  * In either case, trace events are only recorded if an appropriately configured tracing session is
152  * active.
153  *
154  * Use debug.hwui.skia_use_perfetto_track_events to determine if ATrace (default) or Perfetto is
155  * used as the tracing backend.
156  */
157 #define PROPERTY_SKIA_TRACING_ENABLED "debug.hwui.skia_tracing_enabled"
158 
159 /**
160  * Switches Skia's tracing to use Perfetto's Track Event system instead of ATrace.
161  *
162  * If disabled, ATrace will be used by default, which will record trace events from any of Skia's
163  * tracing categories if overall system tracing is active and the "gfx" and "view" ATrace categories
164  * are enabled.
165  *
166  * If enabled, then Perfetto's Track Event system will be used instead, which will only record if an
167  * active Perfetto tracing session is targeting the correct apps and Skia tracing categories with
168  * the Track Event data source enabled. This approach may be used to selectively filter out
169  * undesired Skia tracing categories, and events will contain more data fields.
170  */
171 #define PROPERTY_SKIA_USE_PERFETTO_TRACK_EVENTS "debug.hwui.skia_use_perfetto_track_events"
172 
173 /**
174  * Defines how many frames in a sequence to capture.
175  */
176 #define PROPERTY_CAPTURE_SKP_FRAMES "debug.hwui.capture_skp_frames"
177 
178 /**
179  * File name and location, where a SKP recording will be saved.
180  */
181 #define PROPERTY_CAPTURE_SKP_FILENAME "debug.hwui.skp_filename"
182 
183 /**
184  * Controls whether HWUI will send timing hints to HintManager for
185  * better CPU scheduling. Accepted values are "true" and "false".
186  */
187 #define PROPERTY_USE_HINT_MANAGER "debug.hwui.use_hint_manager"
188 
189 /**
190  * Percentage of frame time that's used for CPU work. The rest is
191  * reserved for GPU work. This is used with use_hint_manager to
192  * provide timing hints to HintManager. Accepted values are
193  * integer from 1-100.
194  */
195 #define PROPERTY_TARGET_CPU_TIME_PERCENTAGE "debug.hwui.target_cpu_time_percent"
196 
197 /**
198  * Property for whether this is running in the emulator.
199  */
200 #define PROPERTY_IS_EMULATOR "ro.boot.qemu"
201 
202 /**
203  * Turns on the Skia GPU option "reduceOpsTaskSplitting" which improves GPU
204  * efficiency but may increase VRAM consumption. Default is "true".
205  */
206 #define PROPERTY_REDUCE_OPS_TASK_SPLITTING "renderthread.skia.reduceopstasksplitting"
207 
208 /**
209  * Enable WebView Overlays feature.
210  */
211 #define PROPERTY_WEBVIEW_OVERLAYS_ENABLED "debug.hwui.webview_overlays_enabled"
212 
213 /**
214  * Property for globally GL drawing state. Can be overridden per process with
215  * setDrawingEnabled.
216  */
217 #define PROPERTY_DRAWING_ENABLED "debug.hwui.drawing_enabled"
218 
219 #define PROPERTY_MEMORY_POLICY "debug.hwui.app_memory_policy"
220 
221 #define PROPERTY_8BIT_HDR_HEADROOM "debug.hwui.8bit_hdr_headroom"
222 
223 ///////////////////////////////////////////////////////////////////////////////
224 // Misc
225 ///////////////////////////////////////////////////////////////////////////////
226 
227 // Converts a number of mega-bytes into bytes
228 #define MB(s) ((s)*1024 * 1024)
229 // Converts a number of kilo-bytes into bytes
230 #define KB(s) ((s)*1024)
231 
232 enum class ProfileType { None, Console, Bars };
233 
234 enum class OverdrawColorSet { Default = 0, Deuteranomaly };
235 
236 enum class RenderPipelineType { SkiaGL, SkiaVulkan, NotInitialized = 128 };
237 
238 enum class StretchEffectBehavior {
239     ShaderHWUI,   // Stretch shader in HWUI only, matrix scale in SF
240     Shader,       // Stretch shader in both HWUI and SF
241     UniformScale  // Uniform scale stretch everywhere
242 };
243 
244 enum class DrawingEnabled { NotInitialized, On, Off };
245 
246 /**
247  * Renderthread-only singleton which manages several static rendering properties. Most of these
248  * are driven by system properties which are queried once at initialization, and again if init()
249  * is called.
250  */
251 class Properties {
252 public:
253     static bool load();
254 
255     static bool debugLayersUpdates;
256     static bool debugOverdraw;
257     static bool showDirtyRegions;
258     // TODO: Remove after stabilization period
259     static bool skipEmptyFrames;
260     static bool useBufferAge;
261     static bool enablePartialUpdates;
262     static bool enableRenderEffectCache;
263 
264     // TODO: Move somewhere else?
265     static constexpr float textGamma = 1.45f;
266 
267     static DebugLevel debugLevel;
268     static OverdrawColorSet overdrawColorSet;
269 
270     // Override the value for a subset of properties in this class
271     static void overrideProperty(const char* name, const char* value);
272 
273     static float overrideLightRadius;
274     static float overrideLightPosY;
275     static float overrideLightPosZ;
276     static float overrideAmbientRatio;
277     static int overrideAmbientShadowStrength;
278     static int overrideSpotShadowStrength;
279 
280     static ProfileType getProfileType();
281     static RenderPipelineType peekRenderPipelineType();
282     static RenderPipelineType getRenderPipelineType();
283 
284     static bool enableHighContrastText;
285 
286     // Should be used only by test apps
287     static bool waitForGpuCompletion;
288     static bool forceDrawFrame;
289 
290     // Should only be set by automated tests to try and filter out
291     // any overhead they add
292     static bool filterOutTestOverhead;
293 
294     // Workaround a device lockup in edge cases by switching to async mode
295     // instead of the default vsync (b/38372997). Only system_server should hit this.
296     // Any existing RenderProxy & Surface combination will be unaffected, only things
297     // created after changing this.
298     static bool disableVsync;
299 
300     static bool skpCaptureEnabled;
301 
302     // For experimentation b/68769804
303     static bool enableRTAnimations;
304 
305     // Used for testing only to change the render pipeline.
306     static void overrideRenderPipelineType(RenderPipelineType);
307 
308     static bool runningInEmulator;
309 
310     static bool debuggingEnabled;
311     static bool isolatedProcess;
312 
313     static int contextPriority;
314 
315     static float defaultSdrWhitePoint;
316 
317     static bool useHintManager;
318     static int targetCpuTimePercentage;
319 
320     static bool enableWebViewOverlays;
321 
322     static bool isHighEndGfx;
323     static bool isLowRam;
324     static bool isSystemOrPersistent;
325 
326     static float maxHdrHeadroomOn8bit;
327 
getStretchEffectBehavior()328     static StretchEffectBehavior getStretchEffectBehavior() {
329         return stretchEffectBehavior;
330     }
331 
setIsHighEndGfx(bool isHighEndGfx)332     static void setIsHighEndGfx(bool isHighEndGfx) {
333         Properties::isHighEndGfx = isHighEndGfx;
334         stretchEffectBehavior = isHighEndGfx ?
335             StretchEffectBehavior::ShaderHWUI :
336             StretchEffectBehavior::UniformScale;
337     }
338 
setIsLowRam(bool isLowRam)339     static void setIsLowRam(bool isLowRam) { Properties::isLowRam = isLowRam; }
340 
setIsSystemOrPersistent(bool isSystemOrPersistent)341     static void setIsSystemOrPersistent(bool isSystemOrPersistent) {
342         Properties::isSystemOrPersistent = isSystemOrPersistent;
343     }
344 
345     /**
346      * Used for testing. Typical configuration of stretch behavior is done
347      * through setIsHighEndGfx
348      */
setStretchEffectBehavior(StretchEffectBehavior behavior)349     static void setStretchEffectBehavior(StretchEffectBehavior behavior) {
350         stretchEffectBehavior = behavior;
351     }
352 
353     // Represents if drawing is enabled. Should only be Off in headless testing environments
354     static DrawingEnabled drawingEnabled;
355     static bool isDrawingEnabled();
356     static void setDrawingEnabled(bool enable);
357 
358 private:
359     static StretchEffectBehavior stretchEffectBehavior;
360     static ProfileType sProfileType;
361     static bool sDisableProfileBars;
362     static RenderPipelineType sRenderPipelineType;
363 };  // class Caches
364 
365 }  // namespace uirenderer
366 }  // namespace android
367 
368 #endif  // ANDROID_HWUI_PROPERTIES_H
369