From 0a456231ef2e06007c70043500c13186397a450c Mon Sep 17 00:00:00 2001 From: Lloyd Pique Date: Thu, 16 Jan 2020 17:51:13 -0800 Subject: CE: Cleanups for conversion warnings 1) If converting from float to int, adds an explicit cast as well as considers rounding. 2) Adjust some arguments from int32_t to uint32_t where that makes sense. 3) Adds explicit casts from int32_t to uint32_t where a cast is necessary. 4) Converts constants used in the tests to the right type (float instead of double, unsigned instead of signed). Test: Builds with "-Wconversion" enabled locally Bug: 129481165 Change-Id: I405af72c22f37865537bdefa3f589b4b2930f56c --- .../include/compositionengine/Output.h | 2 +- .../include/compositionengine/impl/Output.h | 2 +- .../include/compositionengine/mock/Output.h | 2 +- .../CompositionEngine/src/HwcBufferCache.cpp | 2 +- .../CompositionEngine/src/Output.cpp | 6 ++--- .../CompositionEngine/src/OutputLayer.cpp | 3 ++- .../CompositionEngine/src/RenderSurface.cpp | 3 ++- .../tests/CompositionEngineTest.cpp | 6 ++--- .../CompositionEngine/tests/OutputTest.cpp | 28 +++++++++++----------- 9 files changed, 28 insertions(+), 26 deletions(-) (limited to 'services/surfaceflinger/CompositionEngine') diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h index 076fdad708..a280c751b9 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h @@ -162,7 +162,7 @@ public: virtual void setCompositionEnabled(bool) = 0; // Sets the projection state to use - virtual void setProjection(const ui::Transform&, int32_t orientation, const Rect& frame, + virtual void setProjection(const ui::Transform&, uint32_t orientation, const Rect& frame, const Rect& viewport, const Rect& scissor, bool needsFiltering) = 0; // Sets the bounds to use virtual void setBounds(const ui::Size&) = 0; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h index 159e928761..6dbfb5fb1b 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h @@ -36,7 +36,7 @@ public: bool isValid() const override; std::optional getDisplayId() const override; void setCompositionEnabled(bool) override; - void setProjection(const ui::Transform&, int32_t orientation, const Rect& frame, + void setProjection(const ui::Transform&, uint32_t orientation, const Rect& frame, const Rect& viewport, const Rect& scissor, bool needsFiltering) override; void setBounds(const ui::Size&) override; void setLayerStackFilter(uint32_t layerStackId, bool isInternal) override; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h index 7f5bd0603c..367e8ca3c8 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h @@ -38,7 +38,7 @@ public: MOCK_METHOD1(setCompositionEnabled, void(bool)); MOCK_METHOD6(setProjection, - void(const ui::Transform&, int32_t, const Rect&, const Rect&, const Rect&, bool)); + void(const ui::Transform&, uint32_t, const Rect&, const Rect&, const Rect&, bool)); MOCK_METHOD1(setBounds, void(const ui::Size&)); MOCK_METHOD2(setLayerStackFilter, void(uint32_t, bool)); diff --git a/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp b/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp index 995a0ca71f..1e7c97cc35 100644 --- a/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp +++ b/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp @@ -35,7 +35,7 @@ void HwcBufferCache::getHwcBuffer(int slot, const sp& buffer, uin slot >= BufferQueue::NUM_BUFFER_SLOTS) { *outSlot = 0; } else { - *outSlot = slot; + *outSlot = static_cast(slot); } auto& currentBuffer = mBuffers[*outSlot]; diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp index 01413b9478..cd0a942985 100644 --- a/services/surfaceflinger/CompositionEngine/src/Output.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp @@ -101,7 +101,7 @@ void Output::setCompositionEnabled(bool enabled) { dirtyEntireOutput(); } -void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, +void Output::setProjection(const ui::Transform& transform, uint32_t orientation, const Rect& frame, const Rect& viewport, const Rect& scissor, bool needsFiltering) { auto& outputState = editState(); outputState.transform = transform; @@ -433,7 +433,7 @@ void Output::ensureOutputLayerIfVisible(std::shared_ptr 0.0f) { // if the layer casts a shadow, offset the layers visible region and // calculate the shadow region. - const int32_t inset = layerFEState.shadowRadius * -1.0f; + const auto inset = static_cast(ceilf(layerFEState.shadowRadius) * -1.0f); Rect visibleRectWithShadows(visibleRect); visibleRectWithShadows.inset(inset, inset, inset, inset); visibleRegion.set(visibleRectWithShadows); @@ -457,7 +457,7 @@ void Output::ensureOutputLayerIfVisible(std::shared_ptr(error)); } - if (auto error = hwcLayer->setInfo(outputIndependentState.type, outputIndependentState.appId); + if (auto error = hwcLayer->setInfo(static_cast(outputIndependentState.type), + static_cast(outputIndependentState.appId)); error != HWC2::Error::None) { ALOGE("[%s] Failed to set info %s (%d)", getLayerFE().getDebugName(), to_string(error).c_str(), static_cast(error)); diff --git a/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp b/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp index 10512eb9e9..e981172581 100644 --- a/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp +++ b/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp @@ -91,7 +91,8 @@ const sp& RenderSurface::getClientTargetAcquireFence() const { } void RenderSurface::setDisplaySize(const ui::Size& size) { - mDisplaySurface->resizeBuffers(size.width, size.height); + mDisplaySurface->resizeBuffers(static_cast(size.width), + static_cast(size.height)); mSize = size; } diff --git a/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp b/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp index ebcd0a0594..bcaa529427 100644 --- a/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp @@ -139,14 +139,14 @@ TEST_F(CompositionEnginePresentTest, worksAsExpected) { struct CompositionEngineUpdateCursorAsyncTest : public CompositionEngineTest { public: CompositionEngineUpdateCursorAsyncTest() { - EXPECT_CALL(*mOutput1, getOutputLayerCount()).WillRepeatedly(Return(0)); + EXPECT_CALL(*mOutput1, getOutputLayerCount()).WillRepeatedly(Return(0u)); EXPECT_CALL(*mOutput1, getOutputLayerOrderedByZByIndex(_)).Times(0); - EXPECT_CALL(*mOutput2, getOutputLayerCount()).WillRepeatedly(Return(1)); + EXPECT_CALL(*mOutput2, getOutputLayerCount()).WillRepeatedly(Return(1u)); EXPECT_CALL(*mOutput2, getOutputLayerOrderedByZByIndex(0)) .WillRepeatedly(Return(&mOutput2OutputLayer1)); - EXPECT_CALL(*mOutput3, getOutputLayerCount()).WillRepeatedly(Return(2)); + EXPECT_CALL(*mOutput3, getOutputLayerCount()).WillRepeatedly(Return(2u)); EXPECT_CALL(*mOutput3, getOutputLayerOrderedByZByIndex(0)) .WillRepeatedly(Return(&mOutput3OutputLayer1)); EXPECT_CALL(*mOutput3, getOutputLayerOrderedByZByIndex(1)) diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp index 24311c7e5b..2049f4b164 100644 --- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp @@ -64,8 +64,8 @@ constexpr auto TR_IDENT = 0u; constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; const mat4 kIdentity; -const mat4 kNonIdentityHalf = mat4() * 0.5; -const mat4 kNonIdentityQuarter = mat4() * 0.25; +const mat4 kNonIdentityHalf = mat4() * 0.5f; +const mat4 kNonIdentityQuarter = mat4() * 0.25f; constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting = static_cast(0x100); @@ -984,7 +984,7 @@ struct OutputCollectVisibleLayersTest : public testing::Test { }; OutputCollectVisibleLayersTest() { - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) .WillRepeatedly(Return(&mLayer1.outputLayer)); EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) @@ -1008,7 +1008,7 @@ struct OutputCollectVisibleLayersTest : public testing::Test { TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) { mRefreshArgs.layers.clear(); - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); EXPECT_CALL(mOutput, finalizePendingOutputLayers()); @@ -1058,7 +1058,7 @@ struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test { EXPECT_CALL(*mLayer, editFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillRepeatedly(Return(true)); - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) .WillRepeatedly(Return(&mOutputLayer)); @@ -1623,7 +1623,7 @@ TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) { // When the outputColorSetting is set to kUnmanaged, the implementation sets // a simple default color profile without looking at anything else. - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); EXPECT_CALL(mOutput, setColorProfile(ColorProfileEq( ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, @@ -1638,7 +1638,7 @@ TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) { struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile : public OutputUpdateColorProfileTest { OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() { - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; } @@ -1686,7 +1686,7 @@ TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile : public OutputUpdateColorProfileTest { OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() { - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); EXPECT_CALL(*mDisplayColorProfile, getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _)) .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN), @@ -1742,7 +1742,7 @@ struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); } @@ -1864,7 +1864,7 @@ struct OutputUpdateColorProfileTest_ForceOutputColorOverrides mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020; - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); } @@ -1917,7 +1917,7 @@ struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest { OutputUpdateColorProfileTest_Hdr() { mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); } @@ -2197,7 +2197,7 @@ struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ; - EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); + EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ)) .WillRepeatedly(Return(false)); @@ -2838,7 +2838,7 @@ struct OutputComposeSurfacesTest : public testing::Test { const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; -const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; +const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f}; const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}}; const HdrCapabilities OutputComposeSurfacesTest:: kHdrCapabilities{{}, @@ -3412,7 +3412,7 @@ TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqu EXPECT_EQ(mLayers[1].mRELayerSettings.geometry.boundaries, requests[0].geometry.boundaries); EXPECT_FALSE(requests[0].source.buffer.buffer); EXPECT_EQ((half3{0.f, 0.f, 0.f}), requests[0].source.solidColor); - EXPECT_EQ(half{0.f}, requests[0].alpha); + EXPECT_EQ(0.f, static_cast(requests[0].alpha)); EXPECT_EQ(true, requests[0].disableBlending); EXPECT_EQ(mLayers[2].mRELayerSettings, requests[1]); -- cgit v1.2.3