Merge "Create wrapper interface for SensorDevice"
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index 988d2a0..c447d31 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -162,6 +162,8 @@
static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
+ static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_PQ) ==
+ static_cast<int>(HAL_DATASPACE_BT2020_ITU_PQ));
static_assert(static_cast<int>(ADATASPACE_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_ADOBE_RGB));
static_assert(static_cast<int>(ADATASPACE_JFIF) == static_cast<int>(HAL_DATASPACE_V0_JFIF));
static_assert(static_cast<int>(ADATASPACE_BT601_625) == static_cast<int>(HAL_DATASPACE_V0_BT601_625));
diff --git a/libs/nativewindow/include/android/data_space.h b/libs/nativewindow/include/android/data_space.h
index bc4a914..30ac220 100644
--- a/libs/nativewindow/include/android/data_space.h
+++ b/libs/nativewindow/include/android/data_space.h
@@ -444,6 +444,15 @@
ADATASPACE_BT2020_PQ = 163971072, // STANDARD_BT2020 | TRANSFER_ST2084 | RANGE_FULL
/**
+ * ITU-R Recommendation 2020 (BT.2020)
+ *
+ * Ultra High-definition television
+ *
+ * Use limited range, SMPTE 2084 (PQ) transfer and BT2020 standard
+ */
+ ADATASPACE_BT2020_ITU_PQ = 298188800, // STANDARD_BT2020 | TRANSFER_ST2084 | RANGE_LIMITED
+
+ /**
* Adobe RGB
*
* Use full range, gamma 2.2 transfer and Adobe RGB primaries
diff --git a/libs/renderengine/skia/filters/LinearEffect.cpp b/libs/renderengine/skia/filters/LinearEffect.cpp
index 53136e4..c3a5a60 100644
--- a/libs/renderengine/skia/filters/LinearEffect.cpp
+++ b/libs/renderengine/skia/filters/LinearEffect.cpp
@@ -114,7 +114,8 @@
}
// Conversion from relative light to absolute light (maps from [0, 1] to [0, maxNits])
-static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, SkString& shader) {
+static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace,
+ ui::Dataspace outputDataspace, SkString& shader) {
switch (inputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
case HAL_DATASPACE_TRANSFER_ST2084:
shader.append(R"(
@@ -131,12 +132,26 @@
)");
break;
default:
- shader.append(R"(
- float3 ScaleLuminance(float3 xyz) {
- return xyz * in_libtonemap_inputMaxLuminance;
- }
- )");
- break;
+ switch (outputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
+ case HAL_DATASPACE_TRANSFER_ST2084:
+ case HAL_DATASPACE_TRANSFER_HLG:
+ // SDR -> HDR tonemap
+ shader.append(R"(
+ float3 ScaleLuminance(float3 xyz) {
+ return xyz * in_libtonemap_inputMaxLuminance;
+ }
+ )");
+ break;
+ default:
+ // Input and output are both SDR, so no tone-mapping is expected so
+ // no-op the luminance normalization.
+ shader.append(R"(
+ float3 ScaleLuminance(float3 xyz) {
+ return xyz * in_libtonemap_displayMaxLuminance;
+ }
+ )");
+ break;
+ }
}
}
@@ -174,7 +189,7 @@
toAidlDataspace(outputDataspace))
.c_str());
- generateLuminanceScalesForOOTF(inputDataspace, shader);
+ generateLuminanceScalesForOOTF(inputDataspace, outputDataspace, shader);
generateLuminanceNormalizationForOOTF(outputDataspace, shader);
shader.append(R"(
diff --git a/libs/tonemap/tonemap.cpp b/libs/tonemap/tonemap.cpp
index 350bca4..2cec773 100644
--- a/libs/tonemap/tonemap.cpp
+++ b/libs/tonemap/tonemap.cpp
@@ -26,10 +26,11 @@
// Flag containing the variant of tone map algorithm to use.
enum class ToneMapAlgorithm {
- AndroidO, // Default algorithm in place since Android O,
+ AndroidO, // Default algorithm in place since Android O,
+ Android13, // Algorithm used in Android 13.
};
-static const constexpr auto kToneMapAlgorithm = ToneMapAlgorithm::AndroidO;
+static const constexpr auto kToneMapAlgorithm = ToneMapAlgorithm::Android13;
static const constexpr auto kTransferMask =
static_cast<int32_t>(aidl::android::hardware::graphics::common::Dataspace::TRANSFER_MASK);
@@ -231,7 +232,158 @@
.value = buildUniformValue<float>(metadata.displayMaxLuminance)});
uniforms.push_back({.name = "in_libtonemap_inputMaxLuminance",
.value = buildUniformValue<float>(metadata.contentMaxLuminance)});
+ return uniforms;
+ }
+};
+class ToneMapper13 : public ToneMapper {
+public:
+ std::string generateTonemapGainShaderSkSL(
+ aidl::android::hardware::graphics::common::Dataspace sourceDataspace,
+ aidl::android::hardware::graphics::common::Dataspace destinationDataspace) override {
+ const int32_t sourceDataspaceInt = static_cast<int32_t>(sourceDataspace);
+ const int32_t destinationDataspaceInt = static_cast<int32_t>(destinationDataspace);
+
+ std::string program;
+ // Input uniforms
+ program.append(R"(
+ uniform float in_libtonemap_displayMaxLuminance;
+ uniform float in_libtonemap_inputMaxLuminance;
+ )");
+ switch (sourceDataspaceInt & kTransferMask) {
+ case kTransferST2084:
+ case kTransferHLG:
+ switch (destinationDataspaceInt & kTransferMask) {
+ case kTransferST2084:
+ program.append(R"(
+ float libtonemap_ToneMapTargetNits(float maxRGB) {
+ return maxRGB;
+ }
+ )");
+ break;
+ case kTransferHLG:
+ // PQ has a wider luminance range (10,000 nits vs. 1,000 nits) than HLG, so
+ // we'll clamp the luminance range in case we're mapping from PQ input to
+ // HLG output.
+ program.append(R"(
+ float libtonemap_ToneMapTargetNits(float maxRGB) {
+ return clamp(maxRGB, 0.0, 1000.0);
+ }
+ )");
+ break;
+
+ default:
+ switch (sourceDataspaceInt & kTransferMask) {
+ case kTransferST2084:
+ program.append(R"(
+ float libtonemap_OETFTone(float channel) {
+ channel = channel / 10000.0;
+ float m1 = (2610.0 / 4096.0) / 4.0;
+ float m2 = (2523.0 / 4096.0) * 128.0;
+ float c1 = (3424.0 / 4096.0);
+ float c2 = (2413.0 / 4096.0) * 32.0;
+ float c3 = (2392.0 / 4096.0) * 32.0;
+
+ float tmp = pow(channel, float(m1));
+ tmp = (c1 + c2 * tmp) / (1.0 + c3 * tmp);
+ return pow(tmp, float(m2));
+ }
+ )");
+ break;
+ case kTransferHLG:
+ program.append(R"(
+ float libtonemap_OETFTone(float channel) {
+ channel = channel / 1000.0;
+ const float a = 0.17883277;
+ const float b = 0.28466892;
+ const float c = 0.55991073;
+ return channel <= 1.0 / 12.0 ? sqrt(3.0 * channel) :
+ a * log(12.0 * channel - b) + c;
+ }
+ )");
+ break;
+ }
+ // Here we're mapping from HDR to SDR content, so interpolate using a
+ // Hermitian polynomial onto the smaller luminance range.
+ program.append(R"(
+ float libtonemap_ToneMapTargetNits(float maxRGB) {
+ float maxInLumi = in_libtonemap_inputMaxLuminance;
+ float maxOutLumi = in_libtonemap_displayMaxLuminance;
+
+ float nits = maxRGB;
+
+ float x1 = maxOutLumi * 0.65;
+ float y1 = x1;
+
+ float x3 = maxInLumi;
+ float y3 = maxOutLumi;
+
+ float x2 = x1 + (x3 - x1) * 4.0 / 17.0;
+ float y2 = maxOutLumi * 0.9;
+
+ float greyNorm1 = libtonemap_OETFTone(x1);
+ float greyNorm2 = libtonemap_OETFTone(x2);
+ float greyNorm3 = libtonemap_OETFTone(x3);
+
+ float slope1 = 0;
+ float slope2 = (y2 - y1) / (greyNorm2 - greyNorm1);
+ float slope3 = (y3 - y2 ) / (greyNorm3 - greyNorm2);
+
+ if (nits < x1) {
+ return nits;
+ }
+
+ if (nits > maxInLumi) {
+ return maxOutLumi;
+ }
+
+ float greyNits = libtonemap_OETFTone(nits);
+
+ if (greyNits <= greyNorm2) {
+ nits = (greyNits - greyNorm2) * slope2 + y2;
+ } else if (greyNits <= greyNorm3) {
+ nits = (greyNits - greyNorm3) * slope3 + y3;
+ } else {
+ nits = maxOutLumi;
+ }
+
+ return nits;
+ }
+ )");
+ break;
+ }
+ break;
+ default:
+ // Inverse tone-mapping and SDR-SDR mapping is not supported.
+ program.append(R"(
+ float libtonemap_ToneMapTargetNits(float maxRGB) {
+ return maxRGB;
+ }
+ )");
+ break;
+ }
+
+ program.append(R"(
+ float libtonemap_LookupTonemapGain(vec3 linearRGB, vec3 xyz) {
+ float maxRGB = max(linearRGB.r, max(linearRGB.g, linearRGB.b));
+ if (maxRGB <= 0.0) {
+ return 1.0;
+ }
+ return libtonemap_ToneMapTargetNits(maxRGB) / maxRGB;
+ }
+ )");
+ return program;
+ }
+
+ std::vector<ShaderUniform> generateShaderSkSLUniforms(const Metadata& metadata) override {
+ // Hardcode the max content luminance to a "reasonable" level
+ static const constexpr float kContentMaxLuminance = 4000.f;
+ std::vector<ShaderUniform> uniforms;
+ uniforms.reserve(2);
+ uniforms.push_back({.name = "in_libtonemap_displayMaxLuminance",
+ .value = buildUniformValue<float>(metadata.displayMaxLuminance)});
+ uniforms.push_back({.name = "in_libtonemap_inputMaxLuminance",
+ .value = buildUniformValue<float>(kContentMaxLuminance)});
return uniforms;
}
};
@@ -247,6 +399,8 @@
case ToneMapAlgorithm::AndroidO:
sToneMapper = std::unique_ptr<ToneMapper>(new ToneMapperO());
break;
+ case ToneMapAlgorithm::Android13:
+ sToneMapper = std::unique_ptr<ToneMapper>(new ToneMapper13());
}
});
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
index aabd88a..0d17b0c 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp
@@ -744,7 +744,6 @@
[getCallback] {
if (const auto callback = getCallback()) callback->onExpired();
});
- mIdleTimer->start();
}
}
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index 53472ef..0584024 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -355,10 +355,22 @@
std::function<void()> kernelTimerExpired) {
std::scoped_lock lock(mIdleTimerCallbacksMutex);
mIdleTimerCallbacks.emplace();
- mIdleTimerCallbacks->platform.onReset = platformTimerReset;
- mIdleTimerCallbacks->platform.onExpired = platformTimerExpired;
- mIdleTimerCallbacks->kernel.onReset = kernelTimerReset;
- mIdleTimerCallbacks->kernel.onExpired = kernelTimerExpired;
+ mIdleTimerCallbacks->platform.onReset = std::move(platformTimerReset);
+ mIdleTimerCallbacks->platform.onExpired = std::move(platformTimerExpired);
+ mIdleTimerCallbacks->kernel.onReset = std::move(kernelTimerReset);
+ mIdleTimerCallbacks->kernel.onExpired = std::move(kernelTimerExpired);
+ }
+
+ void startIdleTimer() {
+ if (mIdleTimer) {
+ mIdleTimer->start();
+ }
+ }
+
+ void stopIdleTimer() {
+ if (mIdleTimer) {
+ mIdleTimer->stop();
+ }
}
void resetIdleTimer(bool kernelOnly) {
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index f3c5b35..2a6de54 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -213,17 +213,32 @@
void setRefreshRateConfigs(std::shared_ptr<scheduler::RefreshRateConfigs> refreshRateConfigs)
EXCLUDES(mRefreshRateConfigsLock) {
- std::scoped_lock lock(mRefreshRateConfigsLock);
- mRefreshRateConfigs = std::move(refreshRateConfigs);
- mRefreshRateConfigs->setIdleTimerCallbacks(
- [this] { std::invoke(&Scheduler::idleTimerCallback, this, TimerState::Reset); },
- [this] { std::invoke(&Scheduler::idleTimerCallback, this, TimerState::Expired); },
- [this] {
- std::invoke(&Scheduler::kernelIdleTimerCallback, this, TimerState::Reset);
- },
- [this] {
- std::invoke(&Scheduler::kernelIdleTimerCallback, this, TimerState::Expired);
- });
+ // We need to stop the idle timer on the previous RefreshRateConfigs instance
+ // and cleanup the scheduler's state before we switch to the other RefreshRateConfigs.
+ {
+ std::scoped_lock lock(mRefreshRateConfigsLock);
+ if (mRefreshRateConfigs) mRefreshRateConfigs->stopIdleTimer();
+ }
+ {
+ std::scoped_lock lock(mFeatureStateLock);
+ mFeatures = {};
+ }
+ {
+ std::scoped_lock lock(mRefreshRateConfigsLock);
+ mRefreshRateConfigs = std::move(refreshRateConfigs);
+ mRefreshRateConfigs->setIdleTimerCallbacks(
+ [this] { std::invoke(&Scheduler::idleTimerCallback, this, TimerState::Reset); },
+ [this] {
+ std::invoke(&Scheduler::idleTimerCallback, this, TimerState::Expired);
+ },
+ [this] {
+ std::invoke(&Scheduler::kernelIdleTimerCallback, this, TimerState::Reset);
+ },
+ [this] {
+ std::invoke(&Scheduler::kernelIdleTimerCallback, this, TimerState::Expired);
+ });
+ mRefreshRateConfigs->startIdleTimer();
+ }
}
nsecs_t getVsyncPeriodFromRefreshRateConfigs() const EXCLUDES(mRefreshRateConfigsLock) {
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
index fb1d43b..d1dc076 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
@@ -22,9 +22,9 @@
namespace android::surfaceflinger {
-proto::TransactionState TransactionProtoParser::toProto(
- const TransactionState& t, std::function<int32_t(const sp<IBinder>&)> getLayerId,
- std::function<int32_t(const sp<IBinder>&)> getDisplayId) {
+proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t,
+ LayerHandleToIdFn getLayerId,
+ DisplayHandleToIdFn getDisplayId) {
proto::TransactionState proto;
proto.set_pid(t.originPid);
proto.set_uid(t.originUid);
@@ -42,10 +42,38 @@
return proto;
}
-proto::LayerState TransactionProtoParser::toProto(
- const layer_state_t& layer, std::function<int32_t(const sp<IBinder>&)> getLayerId) {
+proto::TransactionState TransactionProtoParser::toProto(
+ std::vector<std::pair<int32_t /* layerId */, TracingLayerState>> states) {
+ proto::TransactionState proto;
+ for (auto& [layerId, state] : states) {
+ proto::LayerState layerProto = toProto(state, nullptr);
+ if (layerProto.has_buffer_data()) {
+ proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
+ bufferProto->set_buffer_id(state.bufferId);
+ bufferProto->set_width(state.bufferWidth);
+ bufferProto->set_height(state.bufferHeight);
+ }
+ layerProto.set_has_sideband_stream(state.hasSidebandStream);
+ layerProto.set_layer_id(state.layerId);
+ layerProto.set_parent_id(state.parentId);
+ layerProto.set_relative_parent_id(state.relativeParentId);
+ if (layerProto.has_window_info_handle()) {
+ layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
+ }
+ proto.mutable_layer_changes()->Add(std::move(layerProto));
+ }
+ return proto;
+}
+
+proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer,
+ LayerHandleToIdFn getLayerId) {
proto::LayerState proto;
- proto.set_layer_id(layer.layerId);
+ if (getLayerId != nullptr) {
+ proto.set_layer_id(getLayerId(layer.surface));
+ } else {
+ proto.set_layer_id(layer.layerId);
+ }
+
proto.set_what(layer.what);
if (layer.what & layer_state_t::ePositionChanged) {
@@ -130,13 +158,13 @@
}
}
- if (layer.what & layer_state_t::eReparent) {
+ if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) {
int32_t layerId = layer.parentSurfaceControlForChild
? getLayerId(layer.parentSurfaceControlForChild->getHandle())
: -1;
proto.set_parent_id(layerId);
}
- if (layer.what & layer_state_t::eRelativeLayerChanged) {
+ if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) {
int32_t layerId = layer.relativeLayerSurfaceControl
? getLayerId(layer.relativeLayerSurfaceControl->getHandle())
: -1;
@@ -164,8 +192,12 @@
transformProto->set_ty(inputInfo->transform.ty());
windowInfoProto->set_replace_touchable_region_with_crop(
inputInfo->replaceTouchableRegionWithCrop);
- windowInfoProto->set_crop_layer_id(
- getLayerId(inputInfo->touchableRegionCropHandle.promote()));
+ if (getLayerId != nullptr) {
+ windowInfoProto->set_crop_layer_id(
+ getLayerId(inputInfo->touchableRegionCropHandle.promote()));
+ } else {
+ windowInfoProto->set_crop_layer_id(-1);
+ }
}
}
if (layer.what & layer_state_t::eBackgroundColorChanged) {
@@ -212,11 +244,13 @@
return proto;
}
-proto::DisplayState TransactionProtoParser::toProto(
- const DisplayState& display, std::function<int32_t(const sp<IBinder>&)> getDisplayId) {
+proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display,
+ DisplayHandleToIdFn getDisplayId) {
proto::DisplayState proto;
proto.set_what(display.what);
- proto.set_id(getDisplayId(display.token));
+ if (getDisplayId != nullptr) {
+ proto.set_id(getDisplayId(display.token));
+ }
if (display.what & DisplayState::eLayerStackChanged) {
proto.set_layer_stack(display.layerStack.id);
@@ -238,9 +272,18 @@
return proto;
}
-TransactionState TransactionProtoParser::fromProto(
- const proto::TransactionState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle,
- std::function<sp<IBinder>(int32_t)> getDisplayHandle) {
+proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
+ proto::LayerCreationArgs proto;
+ proto.set_layer_id(args.layerId);
+ proto.set_name(args.name);
+ proto.set_flags(args.flags);
+ proto.set_parent_id(args.parentId);
+ return proto;
+}
+
+TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto,
+ LayerIdToHandleFn getLayerHandle,
+ DisplayIdToHandleFn getDisplayHandle) {
TransactionState t;
t.originPid = proto.pid();
t.originUid = proto.uid();
@@ -251,7 +294,7 @@
t.states.reserve(static_cast<size_t>(layerCount));
for (int i = 0; i < layerCount; i++) {
ComposerState s;
- s.state = std::move(fromProto(proto.layer_changes(i), getLayerHandle));
+ fromProto(proto.layer_changes(i), getLayerHandle, s.state);
t.states.add(s);
}
@@ -263,88 +306,116 @@
return t;
}
-layer_state_t TransactionProtoParser::fromProto(
- const proto::LayerState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle) {
- layer_state_t layer;
- layer.layerId = proto.layer_id();
- layer.what = proto.what();
+void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
+ TracingLayerCreationArgs& outArgs) {
+ outArgs.layerId = proto.layer_id();
+ outArgs.name = proto.name();
+ outArgs.flags = proto.flags();
+ outArgs.parentId = proto.parent_id();
+}
- if (layer.what & layer_state_t::ePositionChanged) {
+void TransactionProtoParser::fromProto(const proto::LayerState& proto,
+ LayerIdToHandleFn getLayerHandle,
+ TracingLayerState& outState) {
+ fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState));
+ if (proto.what() & layer_state_t::eReparent) {
+ outState.parentId = proto.parent_id();
+ }
+ if (proto.what() & layer_state_t::eRelativeLayerChanged) {
+ outState.relativeParentId = proto.relative_parent_id();
+ }
+ if (proto.what() & layer_state_t::eInputInfoChanged) {
+ outState.inputCropId = proto.window_info_handle().crop_layer_id();
+ }
+ if (proto.what() & layer_state_t::eBufferChanged) {
+ const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
+ outState.bufferId = bufferProto.buffer_id();
+ outState.bufferWidth = bufferProto.width();
+ outState.bufferHeight = bufferProto.height();
+ }
+ if (proto.what() & layer_state_t::eSidebandStreamChanged) {
+ outState.hasSidebandStream = proto.has_sideband_stream();
+ }
+}
+
+void TransactionProtoParser::fromProto(const proto::LayerState& proto,
+ LayerIdToHandleFn getLayerHandle, layer_state_t& layer) {
+ layer.layerId = proto.layer_id();
+ layer.what |= proto.what();
+
+ if (getLayerHandle != nullptr) {
+ layer.surface = getLayerHandle(layer.layerId);
+ }
+
+ if (proto.what() & layer_state_t::ePositionChanged) {
layer.x = proto.x();
layer.y = proto.y();
}
- if (layer.what & layer_state_t::eLayerChanged) {
+ if (proto.what() & layer_state_t::eLayerChanged) {
layer.z = proto.z();
}
- if (layer.what & layer_state_t::eSizeChanged) {
+ if (proto.what() & layer_state_t::eSizeChanged) {
layer.w = proto.w();
layer.h = proto.h();
}
- if (layer.what & layer_state_t::eLayerStackChanged) {
+ if (proto.what() & layer_state_t::eLayerStackChanged) {
layer.layerStack.id = proto.layer_stack();
}
- if (layer.what & layer_state_t::eFlagsChanged) {
+ if (proto.what() & layer_state_t::eFlagsChanged) {
layer.flags = proto.flags();
layer.mask = proto.mask();
}
- if (layer.what & layer_state_t::eMatrixChanged) {
+ if (proto.what() & layer_state_t::eMatrixChanged) {
const proto::LayerState_Matrix22& matrixProto = proto.matrix();
layer.matrix.dsdx = matrixProto.dsdx();
layer.matrix.dsdy = matrixProto.dsdy();
layer.matrix.dtdx = matrixProto.dtdx();
layer.matrix.dtdy = matrixProto.dtdy();
}
- if (layer.what & layer_state_t::eCornerRadiusChanged) {
+ if (proto.what() & layer_state_t::eCornerRadiusChanged) {
layer.cornerRadius = proto.corner_radius();
}
- if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
+ if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
layer.backgroundBlurRadius = proto.background_blur_radius();
}
- if (layer.what & layer_state_t::eAlphaChanged) {
+ if (proto.what() & layer_state_t::eAlphaChanged) {
layer.alpha = proto.alpha();
}
- if (layer.what & layer_state_t::eColorChanged) {
+ if (proto.what() & layer_state_t::eColorChanged) {
const proto::LayerState_Color3& colorProto = proto.color();
layer.color.r = colorProto.r();
layer.color.g = colorProto.g();
layer.color.b = colorProto.b();
}
- if (layer.what & layer_state_t::eTransparentRegionChanged) {
+ if (proto.what() & layer_state_t::eTransparentRegionChanged) {
LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
}
- if (layer.what & layer_state_t::eTransformChanged) {
+ if (proto.what() & layer_state_t::eTransformChanged) {
layer.transform = proto.transform();
}
- if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
+ if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
layer.transformToDisplayInverse = proto.transform_to_display_inverse();
}
- if (layer.what & layer_state_t::eCropChanged) {
+ if (proto.what() & layer_state_t::eCropChanged) {
LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
}
- if (layer.what & layer_state_t::eBufferChanged) {
+ if (proto.what() & layer_state_t::eBufferChanged) {
const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
- layer.bufferData.buffer = new GraphicBuffer(bufferProto.width(), bufferProto.height(),
- HAL_PIXEL_FORMAT_RGBA_8888, 1, 0);
layer.bufferData.frameNumber = bufferProto.frame_number();
layer.bufferData.flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
layer.bufferData.cachedBuffer.id = bufferProto.cached_buffer_id();
}
- if (layer.what & layer_state_t::eSidebandStreamChanged) {
- native_handle_t* handle = native_handle_create(0, 0);
- layer.sidebandStream =
- proto.has_sideband_stream() ? NativeHandle::create(handle, true) : nullptr;
- }
- if (layer.what & layer_state_t::eApiChanged) {
+ if (proto.what() & layer_state_t::eApiChanged) {
layer.api = proto.api();
}
- if (layer.what & layer_state_t::eColorTransformChanged) {
+ if (proto.what() & layer_state_t::eColorTransformChanged) {
LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
}
- if (layer.what & layer_state_t::eBlurRegionsChanged) {
+ if (proto.what() & layer_state_t::eBlurRegionsChanged) {
layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
for (int i = 0; i < proto.blur_regions_size(); i++) {
android::BlurRegion region;
@@ -353,20 +424,20 @@
}
}
- if (layer.what & layer_state_t::eReparent) {
+ if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) {
int32_t layerId = proto.parent_id();
layer.parentSurfaceControlForChild =
new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
nullptr, layerId);
}
- if (layer.what & layer_state_t::eRelativeLayerChanged) {
+ if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) {
int32_t layerId = proto.relative_parent_id();
layer.relativeLayerSurfaceControl =
new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
nullptr, layerId);
}
- if ((layer.what & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
+ if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
gui::WindowInfo inputInfo;
const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
@@ -385,10 +456,12 @@
inputInfo.replaceTouchableRegionWithCrop =
windowInfoProto.replace_touchable_region_with_crop();
int32_t layerId = windowInfoProto.crop_layer_id();
- inputInfo.touchableRegionCropHandle = getLayerHandle(layerId);
+ if (getLayerHandle != nullptr) {
+ inputInfo.touchableRegionCropHandle = getLayerHandle(layerId);
+ }
layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
}
- if (layer.what & layer_state_t::eBackgroundColorChanged) {
+ if (proto.what() & layer_state_t::eBackgroundColorChanged) {
layer.bgColorAlpha = proto.bg_color_alpha();
layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
const proto::LayerState_Color3& colorProto = proto.color();
@@ -396,44 +469,43 @@
layer.color.g = colorProto.g();
layer.color.b = colorProto.b();
}
- if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
+ if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
layer.colorSpaceAgnostic = proto.color_space_agnostic();
}
- if (layer.what & layer_state_t::eShadowRadiusChanged) {
+ if (proto.what() & layer_state_t::eShadowRadiusChanged) {
layer.shadowRadius = proto.shadow_radius();
}
- if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
+ if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
}
- if (layer.what & layer_state_t::eFrameRateChanged) {
+ if (proto.what() & layer_state_t::eFrameRateChanged) {
layer.frameRate = proto.frame_rate();
layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
}
- if (layer.what & layer_state_t::eFixedTransformHintChanged) {
+ if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
layer.fixedTransformHint =
static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
}
- if (layer.what & layer_state_t::eAutoRefreshChanged) {
+ if (proto.what() & layer_state_t::eAutoRefreshChanged) {
layer.autoRefresh = proto.auto_refresh();
}
- if (layer.what & layer_state_t::eTrustedOverlayChanged) {
+ if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
layer.isTrustedOverlay = proto.is_trusted_overlay();
}
- if (layer.what & layer_state_t::eBufferCropChanged) {
+ if (proto.what() & layer_state_t::eBufferCropChanged) {
LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
}
- if (layer.what & layer_state_t::eDestinationFrameChanged) {
+ if (proto.what() & layer_state_t::eDestinationFrameChanged) {
LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
}
- if (layer.what & layer_state_t::eDropInputModeChanged) {
+ if (proto.what() & layer_state_t::eDropInputModeChanged) {
layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
}
- return layer;
}
-DisplayState TransactionProtoParser::fromProto(
- const proto::DisplayState& proto, std::function<sp<IBinder>(int32_t)> getDisplayHandle) {
+DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto,
+ DisplayIdToHandleFn getDisplayHandle) {
DisplayState display;
display.what = proto.what();
display.token = getDisplayHandle(proto.id());
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.h b/services/surfaceflinger/Tracing/TransactionProtoParser.h
index a2b8889..e8a139f 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.h
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.h
@@ -21,24 +21,53 @@
#include "TransactionState.h"
namespace android::surfaceflinger {
+
+struct TracingLayerCreationArgs {
+ int32_t layerId;
+ std::string name;
+ uint32_t flags;
+ int32_t parentId;
+};
+
+struct TracingLayerState : layer_state_t {
+ uint64_t bufferId;
+ uint32_t bufferHeight;
+ uint32_t bufferWidth;
+ bool hasSidebandStream;
+ int32_t parentId;
+ int32_t relativeParentId;
+ int32_t inputCropId;
+ std::string name;
+ uint32_t layerCreationFlags;
+};
+
class TransactionProtoParser {
public:
+ typedef std::function<sp<IBinder>(int32_t)> LayerIdToHandleFn;
+ typedef std::function<sp<IBinder>(int32_t)> DisplayIdToHandleFn;
+ typedef std::function<int32_t(const sp<IBinder>&)> LayerHandleToIdFn;
+ typedef std::function<int32_t(const sp<IBinder>&)> DisplayHandleToIdFn;
+
+ static proto::TransactionState toProto(const TransactionState&, LayerHandleToIdFn getLayerIdFn,
+ DisplayHandleToIdFn getDisplayIdFn);
static proto::TransactionState toProto(
- const TransactionState&, std::function<int32_t(const sp<IBinder>&)> getLayerIdFn,
- std::function<int32_t(const sp<IBinder>&)> getDisplayIdFn);
+ std::vector<std::pair<int32_t /* layerId */, TracingLayerState>>);
+
+ static proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args);
+
static TransactionState fromProto(const proto::TransactionState&,
- std::function<sp<IBinder>(int32_t)> getLayerHandleFn,
- std::function<sp<IBinder>(int32_t)> getDisplayHandleFn);
+ LayerIdToHandleFn getLayerHandleFn,
+ DisplayIdToHandleFn getDisplayHandleFn);
+ static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandleFn,
+ TracingLayerState& outState);
+ static void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs);
private:
- static proto::LayerState toProto(const layer_state_t&,
- std::function<int32_t(const sp<IBinder>&)> getLayerId);
- static proto::DisplayState toProto(const DisplayState&,
- std::function<int32_t(const sp<IBinder>&)> getDisplayId);
- static layer_state_t fromProto(const proto::LayerState&,
- std::function<sp<IBinder>(int32_t)> getLayerHandle);
- static DisplayState fromProto(const proto::DisplayState&,
- std::function<sp<IBinder>(int32_t)> getDisplayHandle);
+ static proto::LayerState toProto(const layer_state_t&, LayerHandleToIdFn getLayerId);
+ static proto::DisplayState toProto(const DisplayState&, DisplayHandleToIdFn getDisplayId);
+ static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandle,
+ layer_state_t& out);
+ static DisplayState fromProto(const proto::DisplayState&, DisplayIdToHandleFn getDisplayHandle);
};
} // namespace android::surfaceflinger
\ No newline at end of file
diff --git a/services/surfaceflinger/layerproto/transactions.proto b/services/surfaceflinger/layerproto/transactions.proto
index e7fb180..edeacfa 100644
--- a/services/surfaceflinger/layerproto/transactions.proto
+++ b/services/surfaceflinger/layerproto/transactions.proto
@@ -39,21 +39,28 @@
}
message TransactionTraceEntry {
- int64 elapsed_time = 1;
+ int64 elapsed_realtime_nanos = 1;
int64 vsync_id = 2;
repeated TransactionState transactions = 3;
+ repeated LayerCreationArgs new_layers = 4;
+ repeated DisplayState new_displays = 5;
+}
+
+message LayerCreationArgs {
+ int32 layer_id = 1;
+ string name = 2;
+ uint32 flags = 3;
+ int32 parent_id = 4;
}
message TransactionState {
- string tag = 2;
- int32 pid = 3;
- int32 uid = 4;
- int64 vsync_id = 5;
- int32 input_event_id = 6;
- int64 post_time = 7;
- repeated LayerState layer_changes = 9;
- repeated DisplayState new_displays = 10;
- repeated DisplayState display_changes = 11;
+ int32 pid = 1;
+ int32 uid = 2;
+ int64 vsync_id = 3;
+ int32 input_event_id = 4;
+ int64 post_time = 5;
+ repeated LayerState layer_changes = 6;
+ repeated DisplayState display_changes = 7;
}
// Keep insync with layer_state_t
@@ -130,8 +137,8 @@
eLayerSecure = 0x80;
eEnableBackpressure = 0x100;
};
- uint32 flags = 10;
- uint32 mask = 11;
+ uint32 flags = 9;
+ uint32 mask = 10;
message Matrix22 {
float dsdx = 1;
@@ -139,29 +146,29 @@
float dtdy = 3;
float dsdy = 4;
};
- Matrix22 matrix = 12;
- float corner_radius = 13;
- uint32 background_blur_radius = 14;
- int32 parent_id = 15;
- int32 relative_parent_id = 16;
+ Matrix22 matrix = 11;
+ float corner_radius = 12;
+ uint32 background_blur_radius = 13;
+ int32 parent_id = 14;
+ int32 relative_parent_id = 15;
- float alpha = 50;
+ float alpha = 16;
message Color3 {
float r = 1;
float g = 2;
float b = 3;
}
- Color3 color = 18;
- RegionProto transparent_region = 19;
- uint32 transform = 20;
- bool transform_to_display_inverse = 21;
- RectProto crop = 49;
+ Color3 color = 17;
+ RegionProto transparent_region = 18;
+ uint32 transform = 19;
+ bool transform_to_display_inverse = 20;
+ RectProto crop = 21;
message BufferData {
uint64 buffer_id = 1;
uint32 width = 2;
uint32 height = 3;
- uint64 frame_number = 5;
+ uint64 frame_number = 4;
enum BufferDataChange {
BufferDataChangeNone = 0;
@@ -169,14 +176,14 @@
frameNumberChanged = 0x02;
cachedBufferChanged = 0x04;
}
- uint32 flags = 6;
- uint64 cached_buffer_id = 7;
+ uint32 flags = 5;
+ uint64 cached_buffer_id = 6;
}
- BufferData buffer_data = 23;
- int32 api = 24;
- bool has_sideband_stream = 25;
- ColorTransformProto color_transform = 26;
- repeated BlurRegion blur_regions = 27;
+ BufferData buffer_data = 22;
+ int32 api = 23;
+ bool has_sideband_stream = 24;
+ ColorTransformProto color_transform = 25;
+ repeated BlurRegion blur_regions = 26;
message Transform {
float dsdx = 1;
@@ -189,38 +196,38 @@
message WindowInfo {
uint32 layout_params_flags = 1;
int32 layout_params_type = 2;
- RegionProto touchable_region = 4;
- int32 surface_inset = 5;
- bool focusable = 8;
- bool has_wallpaper = 9;
- float global_scale_factor = 10;
- int32 crop_layer_id = 13;
- bool replace_touchable_region_with_crop = 14;
- RectProto touchable_region_crop = 15;
- Transform transform = 16;
+ RegionProto touchable_region = 3;
+ int32 surface_inset = 4;
+ bool focusable = 5;
+ bool has_wallpaper = 6;
+ float global_scale_factor = 7;
+ int32 crop_layer_id = 8;
+ bool replace_touchable_region_with_crop = 9;
+ RectProto touchable_region_crop = 10;
+ Transform transform = 11;
}
- WindowInfo window_info_handle = 28;
- float bg_color_alpha = 31;
- int32 bg_color_dataspace = 32;
- bool color_space_agnostic = 33;
- float shadow_radius = 34;
- int32 frame_rate_selection_priority = 35;
- float frame_rate = 36;
- int32 frame_rate_compatibility = 37;
- int32 change_frame_rate_strategy = 38;
- uint32 fixed_transform_hint = 39;
- uint64 frame_number = 40;
- bool auto_refresh = 41;
- bool is_trusted_overlay = 42;
- RectProto buffer_crop = 44;
- RectProto destination_frame = 45;
+ WindowInfo window_info_handle = 27;
+ float bg_color_alpha = 28;
+ int32 bg_color_dataspace = 29;
+ bool color_space_agnostic = 30;
+ float shadow_radius = 31;
+ int32 frame_rate_selection_priority = 32;
+ float frame_rate = 33;
+ int32 frame_rate_compatibility = 34;
+ int32 change_frame_rate_strategy = 35;
+ uint32 fixed_transform_hint = 36;
+ uint64 frame_number = 37;
+ bool auto_refresh = 38;
+ bool is_trusted_overlay = 39;
+ RectProto buffer_crop = 40;
+ RectProto destination_frame = 41;
enum DropInputMode {
NONE = 0;
ALL = 1;
OBSCURED = 2;
};
- DropInputMode drop_input_mode = 48;
+ DropInputMode drop_input_mode = 42;
}
message DisplayState {
diff --git a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
index cebd451..6e00748 100644
--- a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
+++ b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
@@ -69,16 +69,16 @@
t1.displays.add(display);
}
- std::function<int32_t(const sp<IBinder>&)> getLayerIdFn = [&](const sp<IBinder>& handle) {
+ TransactionProtoParser::LayerHandleToIdFn getLayerIdFn = [&](const sp<IBinder>& handle) {
return (handle == layerHandle) ? 42 : -1;
};
- std::function<int32_t(const sp<IBinder>&)> getDisplayIdFn = [&](const sp<IBinder>& handle) {
+ TransactionProtoParser::DisplayHandleToIdFn getDisplayIdFn = [&](const sp<IBinder>& handle) {
return (handle == displayHandle) ? 43 : -1;
};
- std::function<sp<IBinder>(int32_t)> getLayerHandleFn = [&](int32_t id) {
+ TransactionProtoParser::LayerIdToHandleFn getLayerHandleFn = [&](int32_t id) {
return (id == 42) ? layerHandle : nullptr;
};
- std::function<sp<IBinder>(int32_t)> getDisplayHandleFn = [&](int32_t id) {
+ TransactionProtoParser::DisplayIdToHandleFn getDisplayHandleFn = [&](int32_t id) {
return (id == 43) ? displayHandle : nullptr;
};