1 /* 2 * Copyright (C) 2021 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 #pragma once 18 19 #include <cstdint> 20 #include <functional> 21 #include <mutex> 22 #include <optional> 23 #include <string> 24 25 namespace android { 26 // Manages flags for SurfaceFlinger, including default values, system properties, and Mendel 27 // experiment configuration values. Can be called from any thread. 28 class FlagManager { 29 private: 30 // Effectively making the constructor private, while allowing std::make_unique to work 31 struct ConstructorTag {}; 32 33 public: 34 static const FlagManager& getInstance(); 35 static FlagManager& getMutableInstance(); 36 37 FlagManager(ConstructorTag); 38 virtual ~FlagManager(); 39 40 void markBootCompleted(); 41 void dump(std::string& result) const; 42 43 void setUnitTestMode(); 44 45 /// Legacy server flags /// 46 bool test_flag() const; 47 bool use_adpf_cpu_hint() const; 48 bool use_skia_tracing() const; 49 50 /// Trunk stable server (R/W) flags /// 51 bool refresh_rate_overlay_on_external_display() const; 52 bool adpf_gpu_sf() const; 53 bool adpf_use_fmq_channel() const; 54 bool adpf_native_session_manager() const; 55 bool adpf_use_fmq_channel_fixed() const; 56 bool graphite_renderengine_preview_rollout() const; 57 58 /// Trunk stable readonly flags /// 59 bool arr_setframerate_gte_enum() const; 60 bool adpf_fmq_sf() const; 61 bool connected_display() const; 62 bool frame_rate_category_mrr() const; 63 bool enable_small_area_detection() const; 64 bool stable_edid_ids() const; 65 bool misc1() const; 66 bool vrr_config() const; 67 bool hdcp_level_hal() const; 68 bool multithreaded_present() const; 69 bool add_sf_skipped_frames_to_trace() const; 70 bool use_known_refresh_rate_for_fps_consistency() const; 71 bool cache_when_source_crop_layer_only_moved() const; 72 bool enable_fro_dependent_features() const; 73 bool display_protected() const; 74 bool fp16_client_target() const; 75 bool game_default_frame_rate() const; 76 bool enable_layer_command_batching() const; 77 bool vulkan_renderengine() const; 78 bool vrr_bugfix_24q4() const; 79 bool vrr_bugfix_dropped_frame() const; 80 bool renderable_buffer_usage() const; 81 bool restore_blur_step() const; 82 bool dont_skip_on_early_ro() const; 83 bool no_vsyncs_on_screen_off() const; 84 bool protected_if_client() const; 85 bool idle_screen_refresh_rate_timeout() const; 86 bool graphite_renderengine() const; 87 bool filter_frames_before_trace_starts() const; 88 bool latch_unsignaled_with_auto_refresh_changed() const; 89 bool deprecate_vsync_sf() const; 90 bool allow_n_vsyncs_in_targeter() const; 91 bool detached_mirror() const; 92 bool commit_not_composited() const; 93 bool correct_dpi_with_display_size() const; 94 bool local_tonemap_screenshots() const; 95 bool override_trusted_overlay() const; 96 bool flush_buffer_slots_to_uncache() const; 97 bool force_compile_graphite_renderengine() const; 98 bool trace_frame_rate_override() const; 99 bool true_hdr_screenshots() const; 100 bool display_config_error_hal() const; 101 bool connected_display_hdr() const; 102 bool deprecate_frame_tracker() const; 103 bool skip_invisible_windows_in_input() const; 104 bool begone_bright_hlg() const; 105 bool luts_api() const; 106 bool window_blur_kawase2() const; 107 108 protected: 109 // overridden for unit tests 110 virtual std::optional<bool> getBoolProperty(const char*) const; 111 virtual bool getServerConfigurableFlag(const char*) const; 112 113 private: 114 friend class TestableFlagManager; 115 116 FlagManager(const FlagManager&) = delete; 117 118 void dumpFlag(std::string& result, bool readonly, const char* name, 119 std::function<bool()> getter) const; 120 121 std::atomic_bool mBootCompleted = false; 122 std::atomic_bool mUnitTestMode = false; 123 124 static std::unique_ptr<FlagManager> mInstance; 125 static std::once_flag mOnce; 126 }; 127 } // namespace android 128