diff options
| author | 2018-10-19 13:24:08 -0700 | |
|---|---|---|
| committer | 2019-01-15 11:12:13 -0800 | |
| commit | 542307f7fe2e325bfdc6eb19e782d9cc04cb7718 (patch) | |
| tree | 69348156cb841b7b1429ccbb48f3ef028b6a0492 | |
| parent | 32cbe28e23132768631c10d400673f9818c287fc (diff) | |
SF: Move DisplaySurface into CompositionEngine
The CompositionEngine now provides the interface for a DisplaySurface.
For the moment SurfaceFlinger still provides implementations, but those
may be moved into CompositionEngine too.
Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 121291683
Change-Id: I446e57952d59abc137b3b23203b2e093f6262ef3
16 files changed, 103 insertions, 77 deletions
diff --git a/services/surfaceflinger/CompositionEngine/Android.bp b/services/surfaceflinger/CompositionEngine/Android.bp index 3862d8b2e8..64db6efe1f 100644 --- a/services/surfaceflinger/CompositionEngine/Android.bp +++ b/services/surfaceflinger/CompositionEngine/Android.bp @@ -36,6 +36,7 @@ cc_library { srcs: [ "src/CompositionEngine.cpp", "src/Display.cpp", + "src/DisplaySurface.cpp", "src/DumpHelpers.cpp", "src/Output.cpp", "src/OutputCompositionState.cpp", @@ -50,6 +51,7 @@ cc_library { srcs: [ "mock/CompositionEngine.cpp", "mock/Display.cpp", + "mock/DisplaySurface.cpp", "mock/Output.cpp", ], static_libs: [ diff --git a/services/surfaceflinger/DisplayHardware/DisplaySurface.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplaySurface.h index f744f5cf21..0e67acf2ee 100644 --- a/services/surfaceflinger/DisplayHardware/DisplaySurface.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplaySurface.h @@ -14,23 +14,27 @@ * limitations under the License. */ -#ifndef ANDROID_SF_DISPLAY_SURFACE_H -#define ANDROID_SF_DISPLAY_SURFACE_H +#pragma once #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/StrongPointer.h> -// --------------------------------------------------------------------------- namespace android { -// --------------------------------------------------------------------------- class Fence; class IGraphicBufferProducer; class String8; +namespace compositionengine { + +/** + * An abstraction for working with a display surface (buffer queue) + */ class DisplaySurface : public virtual RefBase { public: + virtual ~DisplaySurface(); + // beginFrame is called at the beginning of the composition loop, before // the configuration is known. The DisplaySurface should do anything it // needs to do to enable HWComposer to decide how to compose the frame. @@ -44,9 +48,9 @@ public: // GLES and HWC for this frame. enum CompositionType { COMPOSITION_UNKNOWN = 0, - COMPOSITION_GLES = 1, - COMPOSITION_HWC = 2, - COMPOSITION_MIXED = COMPOSITION_GLES | COMPOSITION_HWC + COMPOSITION_GLES = 1, + COMPOSITION_HWC = 2, + COMPOSITION_MIXED = COMPOSITION_GLES | COMPOSITION_HWC }; virtual status_t prepareFrame(CompositionType compositionType) = 0; @@ -70,15 +74,7 @@ public: virtual void resizeBuffers(const uint32_t w, const uint32_t h) = 0; virtual const sp<Fence>& getClientTargetAcquireFence() const = 0; - -protected: - DisplaySurface() {} - virtual ~DisplaySurface() {} }; -// --------------------------------------------------------------------------- +} // namespace compositionengine } // namespace android -// --------------------------------------------------------------------------- - -#endif // ANDROID_SF_DISPLAY_SURFACE_H - diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplaySurface.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/DisplaySurface.h index d6c9aa46b4..31b5f95c62 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplaySurface.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/DisplaySurface.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,13 @@ #pragma once +#include <compositionengine/DisplaySurface.h> #include <gmock/gmock.h> - #include <utils/String8.h> -#include "DisplayHardware/DisplaySurface.h" - -namespace android { -namespace mock { +namespace android::compositionengine::mock { -class DisplaySurface : public android::DisplaySurface { +class DisplaySurface : public compositionengine::DisplaySurface { public: DisplaySurface(); ~DisplaySurface() override; @@ -39,5 +36,4 @@ public: MOCK_CONST_METHOD0(getClientTargetAcquireFence, const sp<Fence>&()); }; -} // namespace mock -} // namespace android +} // namespace android::compositionengine::mock diff --git a/services/surfaceflinger/CompositionEngine/mock/DisplaySurface.cpp b/services/surfaceflinger/CompositionEngine/mock/DisplaySurface.cpp new file mode 100644 index 0000000000..bbbd7c1010 --- /dev/null +++ b/services/surfaceflinger/CompositionEngine/mock/DisplaySurface.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "compositionengine/mock/DisplaySurface.h" + +namespace android::compositionengine::mock { + +// The Google Mock documentation recommends explicit non-header instantiations +// for better compile time performance. +DisplaySurface::DisplaySurface() = default; +DisplaySurface::~DisplaySurface() = default; + +} // namespace android::compositionengine::mock diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplaySurface.cpp b/services/surfaceflinger/CompositionEngine/src/DisplaySurface.cpp index e6ac6bfb00..db6d4f2fed 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplaySurface.cpp +++ b/services/surfaceflinger/CompositionEngine/src/DisplaySurface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,10 @@ * limitations under the License. */ -#include "mock/DisplayHardware/MockDisplaySurface.h" +#include <compositionengine/DisplaySurface.h> -namespace android { -namespace mock { +namespace android::compositionengine { -// Explicit default instantiation is recommended. -DisplaySurface::DisplaySurface() = default; DisplaySurface::~DisplaySurface() = default; -} // namespace mock -} // namespace android +} // namespace android::compositionengine diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index c3e34d4574..80004a10be 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -33,6 +33,7 @@ #include <compositionengine/CompositionEngine.h> #include <compositionengine/Display.h> #include <compositionengine/DisplayCreationArgs.h> +#include <compositionengine/DisplaySurface.h> #include <compositionengine/impl/OutputCompositionState.h> #include <configstore/Utils.h> #include <cutils/properties.h> @@ -47,7 +48,6 @@ #include <utils/Log.h> #include <utils/RefBase.h> -#include "DisplayHardware/DisplaySurface.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/HWC2.h" #include "SurfaceFlinger.h" @@ -356,20 +356,20 @@ status_t DisplayDevice::prepareFrame(HWComposer& hwc, } } - DisplaySurface::CompositionType compositionType; + compositionengine::DisplaySurface::CompositionType compositionType; bool hasClient = hwc.hasClientComposition(id); bool hasDevice = hwc.hasDeviceComposition(id); if (hasClient && hasDevice) { - compositionType = DisplaySurface::COMPOSITION_MIXED; + compositionType = compositionengine::DisplaySurface::COMPOSITION_MIXED; } else if (hasClient) { - compositionType = DisplaySurface::COMPOSITION_GLES; + compositionType = compositionengine::DisplaySurface::COMPOSITION_GLES; } else if (hasDevice) { - compositionType = DisplaySurface::COMPOSITION_HWC; + compositionType = compositionengine::DisplaySurface::COMPOSITION_HWC; } else { // Nothing to do -- when turning the screen off we get a frame like // this. Call it a HWC frame since we won't be doing any GLES work but // will do a prepare/set cycle. - compositionType = DisplaySurface::COMPOSITION_HWC; + compositionType = compositionengine::DisplaySurface::COMPOSITION_HWC; } return mDisplaySurface->prepareFrame(compositionType); } diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 55b6106915..c606659126 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -44,7 +44,6 @@ namespace android { -class DisplaySurface; class Fence; class HWComposer; class IGraphicBufferProducer; @@ -57,6 +56,7 @@ struct DisplayInfo; namespace compositionengine { class Display; +class DisplaySurface; } // namespace compositionengine class DisplayDevice : public LightRefBase<DisplayDevice> { @@ -212,7 +212,7 @@ private: sp<ANativeWindow> mNativeWindow; // Current buffer that this display can render to. sp<GraphicBuffer> mGraphicBuffer; - sp<DisplaySurface> mDisplaySurface; + sp<compositionengine::DisplaySurface> mDisplaySurface; // File descriptor indicating that mGraphicBuffer is ready for display, i.e. // that drawing to the buffer is now complete. base::unique_fd mBufferReady; @@ -315,7 +315,7 @@ struct DisplayDeviceCreationArgs { bool isVirtual{false}; bool isSecure{false}; sp<ANativeWindow> nativeWindow; - sp<DisplaySurface> displaySurface; + sp<compositionengine::DisplaySurface> displaySurface; int displayInstallOrientation{DisplayState::eOrientationDefault}; bool hasWideColorGamut{false}; HdrCapabilities hdrCapabilities; diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h index 2431dfd7c7..18c524f104 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h @@ -17,15 +17,15 @@ #ifndef ANDROID_SF_FRAMEBUFFER_SURFACE_H #define ANDROID_SF_FRAMEBUFFER_SURFACE_H -#include "DisplayIdentification.h" -#include "DisplaySurface.h" -#include "HWComposerBufferCache.h" - #include <stdint.h> #include <sys/types.h> +#include <compositionengine/DisplaySurface.h> #include <gui/ConsumerBase.h> +#include "DisplayIdentification.h" +#include "HWComposerBufferCache.h" + // --------------------------------------------------------------------------- namespace android { // --------------------------------------------------------------------------- @@ -36,8 +36,7 @@ class HWComposer; // --------------------------------------------------------------------------- -class FramebufferSurface : public ConsumerBase, - public DisplaySurface { +class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface { public: FramebufferSurface(HWComposer& hwc, DisplayId displayId, const sp<IGraphicBufferConsumer>& consumer); diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index 27d3dc5609..1c2853a857 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -38,12 +38,16 @@ namespace android { #define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \ mDisplayName.c_str(), ##__VA_ARGS__) -static const char* dbgCompositionTypeStr(DisplaySurface::CompositionType type) { +static const char* dbgCompositionTypeStr(compositionengine::DisplaySurface::CompositionType type) { switch (type) { - case DisplaySurface::COMPOSITION_UNKNOWN: return "UNKNOWN"; - case DisplaySurface::COMPOSITION_GLES: return "GLES"; - case DisplaySurface::COMPOSITION_HWC: return "HWC"; - case DisplaySurface::COMPOSITION_MIXED: return "MIXED"; + case compositionengine::DisplaySurface::COMPOSITION_UNKNOWN: + return "UNKNOWN"; + case compositionengine::DisplaySurface::COMPOSITION_GLES: + return "GLES"; + case compositionengine::DisplaySurface::COMPOSITION_HWC: + return "HWC"; + case compositionengine::DisplaySurface::COMPOSITION_MIXED: + return "MIXED"; default: return "<INVALID>"; } } diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h index 33678df963..87ae7dd56b 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h @@ -20,13 +20,13 @@ #include <optional> #include <string> -#include "DisplayIdentification.h" -#include "DisplaySurface.h" -#include "HWComposerBufferCache.h" - +#include <compositionengine/DisplaySurface.h> #include <gui/ConsumerBase.h> #include <gui/IGraphicBufferProducer.h> +#include "DisplayIdentification.h" +#include "HWComposerBufferCache.h" + // --------------------------------------------------------------------------- namespace android { // --------------------------------------------------------------------------- @@ -73,7 +73,7 @@ class IProducerListener; * the HWC output buffer. When HWC composition is complete, the scratch buffer * is released and the output buffer is queued to the sink. */ -class VirtualDisplaySurface : public DisplaySurface, +class VirtualDisplaySurface : public compositionengine::DisplaySurface, public BnGraphicBufferProducer, private ConsumerBase { public: diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8d7ed5327c..fb15b249f6 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2520,7 +2520,7 @@ void SurfaceFlinger::processDisplayHotplugEventsLocked() { sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( const wp<IBinder>& displayToken, const std::optional<DisplayId>& displayId, - const DisplayDeviceState& state, const sp<DisplaySurface>& dispSurface, + const DisplayDeviceState& state, const sp<compositionengine::DisplaySurface>& dispSurface, const sp<IGraphicBufferProducer>& producer) { DisplayDeviceCreationArgs creationArgs(this, displayToken, displayId); creationArgs.sequenceId = state.sequenceId; @@ -2681,7 +2681,7 @@ void SurfaceFlinger::processDisplayChangesLocked() { if (draw.indexOfKey(curr.keyAt(i)) < 0) { const DisplayDeviceState& state(curr[i]); - sp<DisplaySurface> dispSurface; + sp<compositionengine::DisplaySurface> dispSurface; sp<IGraphicBufferProducer> producer; sp<IGraphicBufferProducer> bqProducer; sp<IGraphicBufferConsumer> bqConsumer; diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 17eed1cef4..2434a31e37 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -106,6 +106,10 @@ class TimeStats; class VSyncSource; struct CompositionInfo; +namespace compositionengine { +class DisplaySurface; +} // namespace compositionengine + namespace impl { class EventThread; } // namespace impl @@ -745,11 +749,11 @@ private: /* ------------------------------------------------------------------------ * Display management */ - sp<DisplayDevice> setupNewDisplayDeviceInternal(const wp<IBinder>& displayToken, - const std::optional<DisplayId>& displayId, - const DisplayDeviceState& state, - const sp<DisplaySurface>& dispSurface, - const sp<IGraphicBufferProducer>& producer); + sp<DisplayDevice> setupNewDisplayDeviceInternal( + const wp<IBinder>& displayToken, const std::optional<DisplayId>& displayId, + const DisplayDeviceState& state, + const sp<compositionengine::DisplaySurface>& dispSurface, + const sp<IGraphicBufferProducer>& producer); void processDisplayChangesLocked(); void processDisplayHotplugEventsLocked(); diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp index f63c911ace..ad31a400a9 100644 --- a/services/surfaceflinger/tests/unittests/Android.bp +++ b/services/surfaceflinger/tests/unittests/Android.bp @@ -46,7 +46,6 @@ cc_test { "SchedulerUtilsTest.cpp", "TimeStatsTest.cpp", "mock/DisplayHardware/MockComposer.cpp", - "mock/DisplayHardware/MockDisplaySurface.cpp", "mock/DisplayHardware/MockPowerAdvisor.cpp", "mock/gui/MockGraphicBufferConsumer.cpp", "mock/gui/MockGraphicBufferProducer.cpp", @@ -63,7 +62,6 @@ cc_test { "libcompositionengine", "libcompositionengine_mocks", "librenderengine_mocks", - ], header_libs: [ "libsurfaceflinger_headers", diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp index e41735097f..e972785433 100644 --- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp +++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp @@ -17,6 +17,7 @@ #undef LOG_TAG #define LOG_TAG "CompositionTest" +#include <compositionengine/mock/DisplaySurface.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <gui/IProducerListener.h> @@ -33,7 +34,6 @@ #include "TestableSurfaceFlinger.h" #include "mock/DisplayHardware/MockComposer.h" -#include "mock/DisplayHardware/MockDisplaySurface.h" #include "mock/MockDispSync.h" #include "mock/MockEventControlThread.h" #include "mock/MockEventThread.h" @@ -144,7 +144,8 @@ public: TestableSurfaceFlinger mFlinger; sp<DisplayDevice> mDisplay; sp<DisplayDevice> mExternalDisplay; - sp<mock::DisplaySurface> mDisplaySurface = new mock::DisplaySurface(); + sp<compositionengine::mock::DisplaySurface> mDisplaySurface = + new compositionengine::mock::DisplaySurface(); mock::NativeWindow* mNativeWindow = new mock::NativeWindow(); sp<GraphicBuffer> mBuffer = new GraphicBuffer(); @@ -326,11 +327,14 @@ struct BaseDisplayVariant { } static void setupHwcCompositionCallExpectations(CompositionTest* test) { - EXPECT_CALL(*test->mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC)).Times(1); + EXPECT_CALL(*test->mDisplaySurface, + prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC)) + .Times(1); } static void setupRECompositionCallExpectations(CompositionTest* test) { - EXPECT_CALL(*test->mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_GLES)) + EXPECT_CALL(*test->mDisplaySurface, + prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GLES)) .Times(1); EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence()) .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence)); diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp index ff84a620f7..b64a7fc240 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp @@ -19,6 +19,7 @@ #include <type_traits> +#include <compositionengine/mock/DisplaySurface.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <log/log.h> @@ -28,7 +29,6 @@ #include "DisplayIdentificationTest.h" #include "TestableSurfaceFlinger.h" #include "mock/DisplayHardware/MockComposer.h" -#include "mock/DisplayHardware/MockDisplaySurface.h" #include "mock/MockDispSync.h" #include "mock/MockEventControlThread.h" #include "mock/MockEventThread.h" @@ -1227,7 +1227,8 @@ public: template <typename Case> void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { const sp<BBinder> displayToken = new BBinder(); - const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface(); + const sp<compositionengine::mock::DisplaySurface> displaySurface = + new compositionengine::mock::DisplaySurface(); const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); // -------------------------------------------------------------------- @@ -1970,7 +1971,7 @@ TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); - auto displaySurface = new mock::DisplaySurface(); + auto displaySurface = new compositionengine::mock::DisplaySurface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); @@ -2014,7 +2015,7 @@ TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); - auto displaySurface = new mock::DisplaySurface(); + auto displaySurface = new compositionengine::mock::DisplaySurface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 9ff5e8d89a..c53142733c 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -218,7 +218,7 @@ public: auto setupNewDisplayDeviceInternal(const wp<IBinder>& displayToken, const std::optional<DisplayId>& displayId, const DisplayDeviceState& state, - const sp<DisplaySurface>& dispSurface, + const sp<compositionengine::DisplaySurface>& dispSurface, const sp<IGraphicBufferProducer>& producer) { return mFlinger->setupNewDisplayDeviceInternal(displayToken, displayId, state, dispSurface, producer); @@ -487,7 +487,7 @@ public: return *this; } - auto& setDisplaySurface(const sp<DisplaySurface>& displaySurface) { + auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { mCreationArgs.displaySurface = displaySurface; return *this; } |