diff options
5 files changed, 309 insertions, 135 deletions
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h index 8402149c57..a45be8a7a2 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h @@ -55,6 +55,16 @@ struct GenericLayerMetadataEntry { std::vector<uint8_t> value; std::string dumpAsString() const; + + struct Hasher { + size_t operator()(const GenericLayerMetadataEntry& entry) const { + size_t hash = 0; + for (const auto value : entry.value) { + hashCombineSingleHashed(hash, value); + } + return hash; + } + }; }; inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) { @@ -70,6 +80,8 @@ using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMeta /* * Used by LayerFE::getCompositionState + * Note that fields that affect HW composer state may need to be mirrored into + * android::compositionengine::impl::planner::LayerState */ struct LayerFECompositionState { // If set to true, forces client composition on all output layers until diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h index 6c02759bf8..ca70750451 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h @@ -48,6 +48,8 @@ class HWComposer; namespace compositionengine::impl { +// Note that fields that affect HW composer state may need to be mirrored into +// android::compositionengine::impl::planner::LayerState struct OutputLayerCompositionState { // The portion of the layer that is not obscured by opaque layers on top Region visibleRegion; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h index d005ca37a9..e422f579f5 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h @@ -57,13 +57,16 @@ enum class LayerStateField : uint32_t { BufferTransform = 1u << 5, BlendMode = 1u << 6, Alpha = 1u << 7, - VisibleRegion = 1u << 8, - Dataspace = 1u << 9, - ColorTransform = 1u << 10, - CompositionType = 1u << 11, - SidebandStream = 1u << 12, - Buffer = 1u << 13, - SolidColor = 1u << 14, + LayerMetadata = 1u << 8, + VisibleRegion = 1u << 9, + Dataspace = 1u << 10, + PixelFormat = 1u << 11, + ColorTransform = 1u << 12, + SurfaceDamage = 1u << 13, + CompositionType = 1u << 14, + SidebandStream = 1u << 15, + Buffer = 1u << 16, + SolidColor = 1u << 17, }; // clang-format on @@ -95,6 +98,7 @@ public: using ReadFromLayerState = std::function<T(const compositionengine::OutputLayer* layer)>; using ToStrings = std::function<std::vector<std::string>(const T&)>; using Equals = std::function<bool(const T&, const T&)>; + using Hashes = std::function<size_t(const T&)>; static ToStrings getDefaultToStrings() { return [](const T& value) { @@ -107,14 +111,38 @@ public: return [](const T& value) { return std::vector<std::string>{toString(value)}; }; } + static ToStrings getRegionToStrings() { + return [](const Region& region) { + using namespace std::string_literals; + std::string dump; + region.dump(dump, ""); + std::vector<std::string> split = base::Split(dump, "\n"s); + split.erase(split.begin()); // Strip the header + split.pop_back(); // Strip the last (empty) line + for (std::string& line : split) { + line.erase(0, 4); // Strip leading padding before each rect + } + return split; + }; + } + static Equals getDefaultEquals() { return [](const T& lhs, const T& rhs) { return lhs == rhs; }; } + static Equals getRegionEquals() { + return [](const Region& lhs, const Region& rhs) { return lhs.hasSameRects(rhs); }; + } + + static Hashes getDefaultHashes() { + return [](const T& value) { return std::hash<T>{}(value); }; + } + OutputLayerState(ReadFromLayerState reader, ToStrings toStrings = OutputLayerState::getDefaultToStrings(), - Equals equals = OutputLayerState::getDefaultEquals()) - : mReader(reader), mToStrings(toStrings), mEquals(equals) {} + Equals equals = OutputLayerState::getDefaultEquals(), + Hashes hashes = OutputLayerState::getDefaultHashes()) + : mReader(reader), mToStrings(toStrings), mEquals(equals), mHashes(hashes) {} ~OutputLayerState() override = default; @@ -138,7 +166,7 @@ public: size_t getHash() const override { if (!mHash) { - mHash = std::hash<T>{}(mValue); + mHash = mHashes(mValue); } return *mHash; } @@ -172,6 +200,7 @@ private: const ReadFromLayerState mReader; const ToStrings mToStrings; const Equals mEquals; + const Hashes mHashes; T mValue = {}; mutable std::optional<size_t> mHash = {}; }; @@ -263,39 +292,80 @@ private: OutputLayerState<float, LayerStateField::Alpha> mAlpha{ [](auto layer) { return layer->getLayerFE().getCompositionState()->alpha; }}; - // TODO(b/180638831): Generic layer metadata - - // Output-dependent per-frame state - - OutputLayerState<Region, LayerStateField::VisibleRegion> - mVisibleRegion{[](auto layer) { return layer->getState().visibleRegion; }, - [](const Region& region) { - using namespace std::string_literals; - std::string dump; - region.dump(dump, ""); - std::vector<std::string> split = base::Split(dump, "\n"s); - split.erase(split.begin()); // Strip the header - split.pop_back(); // Strip the last (empty) line - for (std::string& line : split) { - line.erase(0, 4); // Strip leading padding before each rect + using LayerMetadataState = + OutputLayerState<GenericLayerMetadataMap, LayerStateField::LayerMetadata>; + LayerMetadataState + mLayerMetadata{[](auto layer) { + return layer->getLayerFE().getCompositionState()->metadata; + }, + [](const GenericLayerMetadataMap& metadata) { + std::vector<std::string> result; + if (metadata.empty()) { + result.push_back("{}"); + return result; + } + result.push_back("{"); + for (const auto& [key, value] : metadata) { + std::string keyValueDump; + keyValueDump.append(" "); + keyValueDump.append(key); + keyValueDump.append("="); + keyValueDump.append(value.dumpAsString()); + result.push_back(keyValueDump); } - return split; + result.push_back("}"); + return result; }, - [](const Region& lhs, const Region& rhs) { - return lhs.hasSameRects(rhs); + LayerMetadataState::getDefaultEquals(), + [](const GenericLayerMetadataMap& metadata) { + size_t hash = 0; + for (const auto& [key, value] : metadata) { + size_t entryHash = 0; + hashCombineSingleHashed(entryHash, + std::hash<std::string>{}(key)); + hashCombineSingleHashed(entryHash, + GenericLayerMetadataEntry::Hasher{}( + value)); + hash ^= entryHash; + } + return hash; }}; + // Output-dependent per-frame state + + using VisibleRegionState = OutputLayerState<Region, LayerStateField::VisibleRegion>; + VisibleRegionState mVisibleRegion{[](auto layer) { return layer->getState().visibleRegion; }, + VisibleRegionState::getRegionToStrings(), + VisibleRegionState::getRegionEquals()}; + using DataspaceState = OutputLayerState<ui::Dataspace, LayerStateField::Dataspace>; DataspaceState mOutputDataspace{[](auto layer) { return layer->getState().dataspace; }, DataspaceState::getHalToStrings()}; - // TODO(b/180638831): Buffer format - // Output-independent per-frame state + using PixelFormatState = OutputLayerState<hardware::graphics::composer::hal::PixelFormat, + LayerStateField::PixelFormat>; + PixelFormatState + mPixelFormat{[](auto layer) { + return layer->getLayerFE().getCompositionState()->buffer + ? static_cast<hardware::graphics::composer::hal::PixelFormat>( + layer->getLayerFE() + .getCompositionState() + ->buffer->getPixelFormat()) + : hardware::graphics::composer::hal::PixelFormat::RGBA_8888; + }, + PixelFormatState::getHalToStrings()}; + OutputLayerState<mat4, LayerStateField::ColorTransform> mColorTransform; - // TODO(b/180638831): Surface damage + using SurfaceDamageState = OutputLayerState<Region, LayerStateField::SurfaceDamage>; + SurfaceDamageState + mSurfaceDamage{[](auto layer) { + return layer->getLayerFE().getCompositionState()->surfaceDamage; + }, + SurfaceDamageState::getRegionToStrings(), + SurfaceDamageState::getRegionEquals()}; using CompositionTypeState = OutputLayerState<hardware::graphics::composer::hal::Composition, LayerStateField::CompositionType>; @@ -339,10 +409,12 @@ private: return std::vector<std::string>{stream.str()}; }}; - std::array<StateInterface*, 13> getNonUniqueFields() { - std::array<const StateInterface*, 13> constFields = + static const constexpr size_t kNumNonUniqueFields = 16; + + std::array<StateInterface*, kNumNonUniqueFields> getNonUniqueFields() { + std::array<const StateInterface*, kNumNonUniqueFields> constFields = const_cast<const LayerState*>(this)->getNonUniqueFields(); - std::array<StateInterface*, 13> fields; + std::array<StateInterface*, kNumNonUniqueFields> fields; std::transform(constFields.cbegin(), constFields.cend(), fields.begin(), [](const StateInterface* constField) { return const_cast<StateInterface*>(constField); @@ -350,12 +422,12 @@ private: return fields; } - std::array<const StateInterface*, 13> getNonUniqueFields() const { + std::array<const StateInterface*, kNumNonUniqueFields> getNonUniqueFields() const { return { - &mDisplayFrame, &mSourceCrop, &mZOrder, &mBufferTransform, - &mBlendMode, &mAlpha, &mVisibleRegion, &mOutputDataspace, - &mColorTransform, &mCompositionType, &mSidebandStream, &mBuffer, - &mSolidColor, + &mDisplayFrame, &mSourceCrop, &mZOrder, &mBufferTransform, + &mBlendMode, &mAlpha, &mLayerMetadata, &mVisibleRegion, + &mOutputDataspace, &mPixelFormat, &mColorTransform, &mSurfaceDamage, + &mCompositionType, &mSidebandStream, &mBuffer, &mSolidColor, }; } }; diff --git a/services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp b/services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp index e976c9b226..7c32e944fc 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp @@ -157,9 +157,11 @@ bool operator==(const LayerState& lhs, const LayerState& rhs) { return lhs.mId == rhs.mId && lhs.mName == rhs.mName && lhs.mDisplayFrame == rhs.mDisplayFrame && lhs.mSourceCrop == rhs.mSourceCrop && lhs.mZOrder == rhs.mZOrder && lhs.mBufferTransform == rhs.mBufferTransform && lhs.mBlendMode == rhs.mBlendMode && - lhs.mAlpha == rhs.mAlpha && lhs.mVisibleRegion == rhs.mVisibleRegion && - lhs.mOutputDataspace == rhs.mOutputDataspace && + lhs.mAlpha == rhs.mAlpha && lhs.mLayerMetadata == rhs.mLayerMetadata && + lhs.mVisibleRegion == rhs.mVisibleRegion && + lhs.mOutputDataspace == rhs.mOutputDataspace && lhs.mPixelFormat == rhs.mPixelFormat && lhs.mColorTransform == rhs.mColorTransform && + lhs.mSurfaceDamage == rhs.mSurfaceDamage && lhs.mCompositionType == rhs.mCompositionType && lhs.mSidebandStream == rhs.mSidebandStream && lhs.mBuffer == rhs.mBuffer && (lhs.mCompositionType.get() != hal::Composition::SOLID_COLOR || diff --git a/services/surfaceflinger/CompositionEngine/tests/planner/LayerStateTest.cpp b/services/surfaceflinger/CompositionEngine/tests/planner/LayerStateTest.cpp index d5a7234372..c1b25e6147 100644 --- a/services/surfaceflinger/CompositionEngine/tests/planner/LayerStateTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/planner/LayerStateTest.cpp @@ -24,6 +24,9 @@ #include <gtest/gtest.h> #include <log/log.h> +#include "android/hardware_buffer.h" +#include "compositionengine/LayerFECompositionState.h" + namespace android::compositionengine::impl::planner { namespace { @@ -48,7 +51,15 @@ const mat4 sMat4One = mat4::scale(vec4(2.f, 3.f, 1.f, 1.f)); native_handle_t* const sFakeSidebandStreamOne = reinterpret_cast<native_handle_t*>(10); native_handle_t* const sFakeSidebandStreamTwo = reinterpret_cast<native_handle_t*>(11); const half4 sHalf4One = half4(0.2f, 0.3f, 0.4f, 0.5f); -const half4 sHalf4Two = half4(0.5f, 0.4f, 0.43, 0.2f); +const half4 sHalf4Two = half4(0.5f, 0.4f, 0.3f, 0.2f); +const std::string sMetadataKeyOne = std::string("Meta!"); +const std::string sMetadataKeyTwo = std::string("Data!"); +const GenericLayerMetadataEntry sMetadataValueOne = GenericLayerMetadataEntry{ + .value = std::vector<uint8_t>({1, 2}), +}; +const GenericLayerMetadataEntry sMetadataValueTwo = GenericLayerMetadataEntry{ + .value = std::vector<uint8_t>({1, 3}), +}; struct LayerStateTest : public testing::Test { LayerStateTest() { @@ -75,6 +86,21 @@ struct LayerStateTest : public testing::Test { EXPECT_CALL(layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState)); } + void verifyUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs) { + EXPECT_EQ(lhs.getHash(), rhs.getHash()); + + EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), lhs.getDifferingFields(rhs)); + EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), rhs.getDifferingFields(lhs)); + } + + void verifyNonUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs, + Flags<LayerStateField> fields) { + EXPECT_NE(lhs.getHash(), rhs.getHash()); + + EXPECT_EQ(fields, lhs.getDifferingFields(rhs)); + EXPECT_EQ(fields, rhs.getDifferingFields(lhs)); + } + mock::LayerFE mLayerFE; mock::OutputLayer mOutputLayer; std::unique_ptr<LayerState> mLayerState; @@ -129,14 +155,7 @@ TEST_F(LayerStateTest, compareId) { EXPECT_NE(mLayerState->getId(), otherLayerState->getId()); // Id is a unique field, so it's not computed in the hash for a layer state. - EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); - - // Similarly, Id cannot be included in differing fields. - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - otherLayerState->getDifferingFields(*mLayerState)); - + verifyUniqueDifferingFields(*mLayerState, *otherLayerState); EXPECT_FALSE(mLayerState->compare(*otherLayerState)); EXPECT_FALSE(otherLayerState->compare(*mLayerState)); } @@ -181,14 +200,7 @@ TEST_F(LayerStateTest, compareName) { EXPECT_NE(mLayerState->getName(), otherLayerState->getName()); // Name is a unique field, so it's not computed in the hash for a layer state. - EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); - - // Similarly, Name cannot be included in differing fields. - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - otherLayerState->getDifferingFields(*mLayerState)); - + verifyUniqueDifferingFields(*mLayerState, *otherLayerState); EXPECT_FALSE(mLayerState->compare(*otherLayerState)); EXPECT_FALSE(otherLayerState->compare(*mLayerState)); } @@ -239,13 +251,7 @@ TEST_F(LayerStateTest, compareDisplayFrame) { EXPECT_NE(mLayerState->getDisplayFrame(), otherLayerState->getDisplayFrame()); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), - otherLayerState->getDifferingFields(*mLayerState)); - + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::DisplayFrame); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); } @@ -316,13 +322,8 @@ TEST_F(LayerStateTest, compareCompositionType) { EXPECT_NE(mLayerState->getCompositionType(), otherLayerState->getCompositionType()); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), - otherLayerState->getDifferingFields(*mLayerState)); - + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, + LayerStateField::CompositionType); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); } @@ -360,12 +361,8 @@ TEST_F(LayerStateTest, compareBuffer) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - // Buffers are not included in differing fields or in hashes. - EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), - otherLayerState->getDifferingFields(*mLayerState)); + // A buffer is not a unique field, but the assertions are the same. + verifyUniqueDifferingFields(*mLayerState, *otherLayerState); // Buffers are explicitly excluded from comparison EXPECT_FALSE(mLayerState->compare(*otherLayerState)); @@ -405,12 +402,7 @@ TEST_F(LayerStateTest, compareSourceCrop) { layerFECompositionState); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SourceCrop); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -449,12 +441,7 @@ TEST_F(LayerStateTest, compareZOrder) { layerFECompositionState); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::ZOrder); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -493,12 +480,8 @@ TEST_F(LayerStateTest, compareBufferTransform) { layerFECompositionState); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, + LayerStateField::BufferTransform); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -537,12 +520,7 @@ TEST_F(LayerStateTest, compareBlendMode) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::BlendMode); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -581,12 +559,46 @@ TEST_F(LayerStateTest, compareAlpha) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Alpha); + + EXPECT_TRUE(mLayerState->compare(*otherLayerState)); + EXPECT_TRUE(otherLayerState->compare(*mLayerState)); +} + +TEST_F(LayerStateTest, updateLayerMetadata) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne; + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); + + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo; + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState, + layerFECompositionStateTwo); + Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer); + EXPECT_EQ(Flags<LayerStateField>(LayerStateField::LayerMetadata), updates); +} - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), - otherLayerState->getDifferingFields(*mLayerState)); +TEST_F(LayerStateTest, compareLayerMetadata) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne; + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo; + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState, + layerFECompositionStateTwo); + auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); + + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::LayerMetadata); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -625,12 +637,7 @@ TEST_F(LayerStateTest, compareVisibleRegion) { layerFECompositionState); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::VisibleRegion); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -669,12 +676,65 @@ TEST_F(LayerStateTest, compareDataspace) { layerFECompositionState); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Dataspace); + + EXPECT_TRUE(mLayerState->compare(*otherLayerState)); + EXPECT_TRUE(otherLayerState->compare(*mLayerState)); +} + +TEST_F(LayerStateTest, updatePixelFormat) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.buffer = + new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_8888, + AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, + "buffer1"); + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); + + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.buffer = + new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBX_8888, + AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, + "buffer2"); + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState, + layerFECompositionStateTwo); + Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer); + EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Buffer) | + Flags<LayerStateField>(LayerStateField::PixelFormat), + updates); +} - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), - otherLayerState->getDifferingFields(*mLayerState)); +TEST_F(LayerStateTest, comparePixelFormat) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.buffer = + new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_8888, + AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, + "buffer1"); + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.buffer = + new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBX_8888, + AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, + "buffer2"); + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState, + layerFECompositionStateTwo); + auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); + + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, + Flags<LayerStateField>(LayerStateField::PixelFormat)); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -717,12 +777,48 @@ TEST_F(LayerStateTest, compareColorTransform) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::ColorTransform); + + EXPECT_TRUE(mLayerState->compare(*otherLayerState)); + EXPECT_TRUE(otherLayerState->compare(*mLayerState)); +} + +TEST_F(LayerStateTest, updateSurfaceDamage) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.surfaceDamage = sRegionOne; + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), - otherLayerState->getDifferingFields(*mLayerState)); + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + OutputLayerCompositionState outputLayerCompositionStateTwo; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.surfaceDamage = sRegionTwo; + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo, + layerFECompositionStateTwo); + Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer); + EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SurfaceDamage), updates); +} + +TEST_F(LayerStateTest, compareSurfaceDamage) { + OutputLayerCompositionState outputLayerCompositionState; + LayerFECompositionState layerFECompositionState; + layerFECompositionState.surfaceDamage = sRegionOne; + setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState, + layerFECompositionState); + mLayerState = std::make_unique<LayerState>(&mOutputLayer); + mock::OutputLayer newOutputLayer; + mock::LayerFE newLayerFE; + OutputLayerCompositionState outputLayerCompositionStateTwo; + LayerFECompositionState layerFECompositionStateTwo; + layerFECompositionStateTwo.surfaceDamage = sRegionTwo; + setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo, + layerFECompositionStateTwo); + auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); + + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SurfaceDamage); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -761,12 +857,7 @@ TEST_F(LayerStateTest, compareSidebandStream) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SidebandStream); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); @@ -805,12 +896,7 @@ TEST_F(LayerStateTest, compareSolidColor) { layerFECompositionStateTwo); auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer); - EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); - - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), - mLayerState->getDifferingFields(*otherLayerState)); - EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), - otherLayerState->getDifferingFields(*mLayerState)); + verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SolidColor); EXPECT_TRUE(mLayerState->compare(*otherLayerState)); EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |