Use libbase API to access system properties in libhwui
Calls to licutils properties API are replaced by calls to libbase
properties API. This will make it easier to make a host target for
libhwui as libbase provides a host implementation for its properties
API.
Bug: 117921091
Test: N/A
Change-Id: I15b4fe1a16d2bc7b271387d8cf3403940b8aae2d
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index 9fe53d3..43d1c95 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -54,6 +54,7 @@
shared_libs: [
"liblog",
"libcutils",
+ "libbase",
"libstatslog",
"libutils",
"libEGL",
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index af20c4f..2196b0f 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -23,8 +23,8 @@
#include <algorithm>
#include <cstdlib>
+#include <android-base/properties.h>
#include <cutils/compiler.h>
-#include <cutils/properties.h>
#include <log/log.h>
namespace android {
@@ -67,64 +67,54 @@
int Properties::contextPriority = 0;
int Properties::defaultRenderAhead = -1;
-static int property_get_int(const char* key, int defaultValue) {
- char buf[PROPERTY_VALUE_MAX] = {
- '\0',
- };
-
- if (property_get(key, buf, "") > 0) {
- return atoi(buf);
- }
- return defaultValue;
-}
-
bool Properties::load() {
- char property[PROPERTY_VALUE_MAX];
bool prevDebugLayersUpdates = debugLayersUpdates;
bool prevDebugOverdraw = debugOverdraw;
debugOverdraw = false;
- if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
- INIT_LOGD(" Overdraw debug enabled: %s", property);
- if (!strcmp(property, "show")) {
+ std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
+ if (debugOverdrawProperty != "") {
+ INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
+ if (debugOverdrawProperty == "show") {
debugOverdraw = true;
overdrawColorSet = OverdrawColorSet::Default;
- } else if (!strcmp(property, "show_deuteranomaly")) {
+ } else if (debugOverdrawProperty == "show_deuteranomaly") {
debugOverdraw = true;
overdrawColorSet = OverdrawColorSet::Deuteranomaly;
}
}
sProfileType = ProfileType::None;
- if (property_get(PROPERTY_PROFILE, property, "") > 0) {
- if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
+ std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
+ if (profileProperty != "") {
+ if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
sProfileType = ProfileType::Bars;
- } else if (!strcmp(property, "true")) {
+ } else if (profileProperty == "true") {
sProfileType = ProfileType::Console;
}
}
- debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
+ debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
- showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
+ showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
- debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
+ debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
- skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
- useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
- enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
+ skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
+ useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
+ enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
- filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
+ filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
- skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
+ skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
SkAndroidFrameworkTraceUtil::setEnableTracing(
- property_get_bool(PROPERTY_SKIA_ATRACE_ENABLED, false));
+ base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
- runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
+ runningInEmulator = base::GetBoolProperty(PROPERTY_QEMU_KERNEL, false);
- defaultRenderAhead = std::max(-1, std::min(2, property_get_int(PROPERTY_RENDERAHEAD,
+ defaultRenderAhead = std::max(-1, std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD,
render_ahead().value_or(0))));
return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
@@ -175,9 +165,8 @@
return sRenderPipelineType;
}
bool useVulkan = use_vulkan().value_or(false);
- char prop[PROPERTY_VALUE_MAX];
- property_get(PROPERTY_RENDERER, prop, useVulkan ? "skiavk" : "skiagl");
- if (!strcmp(prop, "skiavk")) {
+ std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
+ if (rendererProperty == "skiavk") {
return RenderPipelineType::SkiaVulkan;
}
return RenderPipelineType::SkiaGL;
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 71b07c9..d3ecb54d 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -18,7 +18,6 @@
#define ANDROID_HWUI_PROPERTIES_H
#include <cutils/compiler.h>
-#include <cutils/properties.h>
/**
* This file contains the list of system properties used to configure libhwui.
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
index 1f9ab5a..0668281 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
@@ -30,6 +30,8 @@
#include <unistd.h>
+#include <android-base/properties.h>
+
using namespace android::uirenderer::renderthread;
namespace android {
@@ -240,12 +242,11 @@
SkCanvas* SkiaPipeline::tryCapture(SkSurface* surface) {
if (CC_UNLIKELY(Properties::skpCaptureEnabled)) {
- char prop[PROPERTY_VALUE_MAX] = {'\0'};
if (mCaptureSequence <= 0) {
- property_get(PROPERTY_CAPTURE_SKP_FILENAME, prop, "0");
+ std::string prop = base::GetProperty(PROPERTY_CAPTURE_SKP_FILENAME, "0");
if (prop[0] != '0' && mCapturedFile != prop) {
mCapturedFile = prop;
- mCaptureSequence = property_get_int32(PROPERTY_CAPTURE_SKP_FRAMES, 1);
+ mCaptureSequence = base::GetIntProperty(PROPERTY_CAPTURE_SKP_FRAMES, 1);
}
}
if (mCaptureSequence > 0 || mPictureCapturedCallback) {