From 60d1a19324b2c0d5cee01f5467fd708aaef7e24f Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 7 Mar 2018 14:52:28 -0800 Subject: Implement Display Layer Stats V0.1 Try to collect data for analyzing how many display controller layers we need and what we use them for. This change will collect additional data from per frame point of view. Test: adb shell dumpsys SurfaceFlinger --enable-layer-stats Test: adb shell dumpsys SurfaceFlinger --disable-layer-stats Test: adb shell dumpsys SurfaceFlinger --clear-layer-stats Test: adb shell dumpsys SurfaceFlinger --dump-layer-stats Bug: b/75953772 Change-Id: Ib48777df7e1fed637be7eb1aefbdf1808d1daccd --- libs/ui/DebugUtils.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libs/ui/DebugUtils.cpp') diff --git a/libs/ui/DebugUtils.cpp b/libs/ui/DebugUtils.cpp index d7e191db89..d5654ccfe3 100644 --- a/libs/ui/DebugUtils.cpp +++ b/libs/ui/DebugUtils.cpp @@ -234,6 +234,33 @@ std::string decodeColorMode(ColorMode colorMode) { return android::base::StringPrintf("Unknown color mode %d", colorMode); } +std::string decodeColorTransform(android_color_transform colorTransform) { + switch (colorTransform) { + case HAL_COLOR_TRANSFORM_IDENTITY: + return std::string("Identity"); + + case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX: + return std::string("Arbitrary matrix"); + + case HAL_COLOR_TRANSFORM_VALUE_INVERSE: + return std::string("Inverse value"); + + case HAL_COLOR_TRANSFORM_GRAYSCALE: + return std::string("Grayscale"); + + case HAL_COLOR_TRANSFORM_CORRECT_PROTANOPIA: + return std::string("Correct protanopia"); + + case HAL_COLOR_TRANSFORM_CORRECT_DEUTERANOPIA: + return std::string("Correct deuteranopia"); + + case HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA: + return std::string("Correct tritanopia"); + } + + return android::base::StringPrintf("Unknown color transform %d", colorTransform); +} + // Converts a PixelFormat to a human-readable string. Max 11 chars. // (Could use a table of prefab String8 objects.) std::string decodePixelFormat(android::PixelFormat format) { -- cgit v1.2.3-59-g8ed1b From 9f034475d961892e4c10e6ff7ecee96e464be00c Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Wed, 28 Mar 2018 15:29:00 -0700 Subject: Add proper namespace to GraphicTypes. Renamed GraphicsTypes.h to GraphicTypes.h and added proper namespace to avoid naming conflict. BUG: 77156734 Test: Build and flash Change-Id: Ibd9f454b5b72d5f8c6d94a3869a60a1bf821f106 --- libs/gui/ISurfaceComposer.cpp | 2 ++ libs/gui/Surface.cpp | 2 ++ libs/gui/SurfaceComposerClient.cpp | 2 ++ libs/gui/include/gui/ISurfaceComposer.h | 8 +++--- libs/gui/include/gui/SurfaceComposerClient.h | 9 ++++--- libs/gui/tests/Surface_test.cpp | 1 + libs/ui/DebugUtils.cpp | 2 +- libs/ui/include/ui/DebugUtils.h | 4 +-- libs/ui/include/ui/GraphicTypes.h | 30 ++++++++++++++++++++++ libs/ui/include/ui/GraphicsTypes.h | 26 ------------------- services/surfaceflinger/DisplayDevice.cpp | 7 ++--- services/surfaceflinger/DisplayDevice.h | 10 ++++---- services/surfaceflinger/DisplayHardware/HWC2.cpp | 18 +++---------- services/surfaceflinger/DisplayHardware/HWC2.h | 11 ++++---- .../surfaceflinger/DisplayHardware/HWComposer.cpp | 8 +++--- .../surfaceflinger/DisplayHardware/HWComposer.h | 6 ++--- services/surfaceflinger/RenderArea.h | 4 +-- services/surfaceflinger/SurfaceFlinger.cpp | 1 + services/surfaceflinger/SurfaceFlinger.h | 10 ++++---- services/surfaceflinger/tests/hwc2/Hwc2Test.cpp | 4 +-- 20 files changed, 85 insertions(+), 80 deletions(-) create mode 100644 libs/ui/include/ui/GraphicTypes.h delete mode 100644 libs/ui/include/ui/GraphicsTypes.h (limited to 'libs/ui/DebugUtils.cpp') diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 0244bb512e..e22bc708c9 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -43,6 +43,8 @@ namespace android { +using ui::ColorMode; + class BpSurfaceComposer : public BpInterface { public: diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 2e1c24b755..6a1aebd6d6 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -44,6 +44,8 @@ namespace android { +using ui::ColorMode; + Surface::Surface(const sp& bufferProducer, bool controlledByApp) : mGraphicBufferProducer(bufferProducer), mCrop(Rect::EMPTY_RECT), diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 4c041bc4f5..bbf681ea90 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -43,6 +43,8 @@ #include namespace android { + +using ui::ColorMode; // --------------------------------------------------------------------------- ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService); diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index afe9358c0a..3591090172 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -161,10 +161,10 @@ public: virtual status_t setActiveConfig(const sp& display, int id) = 0; virtual status_t getDisplayColorModes(const sp& display, - Vector* outColorModes) = 0; - virtual ColorMode getActiveColorMode(const sp& display) = 0; + Vector* outColorModes) = 0; + virtual ui::ColorMode getActiveColorMode(const sp& display) = 0; virtual status_t setActiveColorMode(const sp& display, - ColorMode colorMode) = 0; + ui::ColorMode colorMode) = 0; /* Capture the specified screen. requires READ_FRAME_BUFFER permission * This function will fail if there is a secure window on screen. diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index b45ce4f86c..ffc22f6437 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -89,13 +89,14 @@ public: // Gets the list of supported color modes for the given display static status_t getDisplayColorModes(const sp& display, - Vector* outColorModes); + Vector* outColorModes); // Gets the active color mode for the given display - static ColorMode getActiveColorMode(const sp& display); + static ui::ColorMode getActiveColorMode(const sp& display); // Sets the active color mode for the given display - static status_t setActiveColorMode(const sp& display, ColorMode colorMode); + static status_t setActiveColorMode(const sp& display, + ui::ColorMode colorMode); /* Triggers screen on/off or low power mode and waits for it to complete */ static void setDisplayPowerMode(const sp& display, int mode); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index df391ed4bb..2c02ba657d 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -42,6 +42,7 @@ using namespace std::chrono_literals; // retrieve wide-color and hdr settings from configstore using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; +using ui::ColorMode; using Transaction = SurfaceComposerClient::Transaction; diff --git a/libs/ui/DebugUtils.cpp b/libs/ui/DebugUtils.cpp index d5654ccfe3..58fed84ea8 100644 --- a/libs/ui/DebugUtils.cpp +++ b/libs/ui/DebugUtils.cpp @@ -22,7 +22,7 @@ #include using android::base::StringPrintf; -using android::ColorMode; +using android::ui::ColorMode; std::string decodeStandard(android_dataspace dataspace) { const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); diff --git a/libs/ui/include/ui/DebugUtils.h b/libs/ui/include/ui/DebugUtils.h index 769009317f..5e5df43740 100644 --- a/libs/ui/include/ui/DebugUtils.h +++ b/libs/ui/include/ui/DebugUtils.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include @@ -29,7 +29,7 @@ std::string decodeStandard(android_dataspace dataspace); std::string decodeTransfer(android_dataspace dataspace); std::string decodeRange(android_dataspace dataspace); std::string dataspaceDetails(android_dataspace dataspace); -std::string decodeColorMode(android::ColorMode colormode); +std::string decodeColorMode(android::ui::ColorMode colormode); std::string decodeColorTransform(android_color_transform colorTransform); std::string decodePixelFormat(android::PixelFormat format); std::string to_string(const android::Rect& rect); diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h new file mode 100644 index 0000000000..39893b268a --- /dev/null +++ b/libs/ui/include/ui/GraphicTypes.h @@ -0,0 +1,30 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#include +#include + +// android::ui::* in this header file will alias different types as +// the HIDL interface is updated. +namespace android { +namespace ui { + +using android::hardware::graphics::common::V1_0::ColorMode; + +} // namespace ui +} // namespace android diff --git a/libs/ui/include/ui/GraphicsTypes.h b/libs/ui/include/ui/GraphicsTypes.h deleted file mode 100644 index fa9a812d97..0000000000 --- a/libs/ui/include/ui/GraphicsTypes.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2018 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. - */ - -#pragma once - -#include -#include - -namespace android { - -using android::hardware::graphics::common::V1_0::ColorMode; - -} // namespace android diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index e4161bbdb9..e1d7f81656 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -49,13 +49,12 @@ #include #include -// ---------------------------------------------------------------------------- -using namespace android; -// ---------------------------------------------------------------------------- +namespace android { // retrieve triple buffer setting from configstore using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; +using android::ui::ColorMode; /* * Initialize the display to the specified values. @@ -485,3 +484,5 @@ DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isS viewport.makeInvalid(); frame.makeInvalid(); } + +} // namespace android diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index c1ef2e890a..31bb4d0778 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -33,7 +33,7 @@ #include #include -#include +#include #include "RenderArea.h" #include "RenderEngine/Surface.h" @@ -163,8 +163,8 @@ public: void setPowerMode(int mode); bool isDisplayOn() const; - ColorMode getActiveColorMode() const; - void setActiveColorMode(ColorMode mode); + ui::ColorMode getActiveColorMode() const; + void setActiveColorMode(ui::ColorMode mode); android_color_transform_t getColorTransform() const; void setColorTransform(const mat4& transform); void setCompositionDataSpace(android_dataspace dataspace); @@ -240,7 +240,7 @@ private: // Current active config int mActiveConfig; // current active color mode - ColorMode mActiveColorMode; + ui::ColorMode mActiveColorMode; // Current color transform android_color_transform_t mColorTransform; @@ -291,7 +291,7 @@ public: bool needsFiltering() const override { return mDevice->needsFiltering(); } Rect getSourceCrop() const override { return mSourceCrop; } bool getWideColorSupport() const override { return mDevice->getWideColorSupport(); } - ColorMode getActiveColorMode() const override { + ui::ColorMode getActiveColorMode() const override { return mDevice->getActiveColorMode(); } diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp index 0c77aba498..98daec3e47 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp @@ -362,20 +362,10 @@ Error Display::getChangedCompositionTypes( return Error::None; } -Error Display::getColorModes(std::vector* outModes) const +Error Display::getColorModes(std::vector* outModes) const { - std::vector modes; - auto intError = mComposer.getColorModes(mId, &modes); - uint32_t numModes = modes.size(); - auto error = static_cast(intError); - if (error != Error::None) { - return error; - } - - outModes->resize(numModes); - for (size_t i = 0; i < numModes; i++) { - (*outModes)[i] = modes[i]; - } + auto intError = mComposer.getColorModes(mId, outModes); + return static_cast(intError); return Error::None; } @@ -537,7 +527,7 @@ Error Display::setClientTarget(uint32_t slot, const sp& target, return static_cast(intError); } -Error Display::setColorMode(android::ColorMode mode) +Error Display::setColorMode(android::ui::ColorMode mode) { auto intError = mComposer.setColorMode(mId, mode); return static_cast(intError); diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index 5b53b54d71..71c094a035 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -211,7 +211,7 @@ public: [[clang::warn_unused_result]] Error getChangedCompositionTypes( std::unordered_map* outTypes); [[clang::warn_unused_result]] Error getColorModes( - std::vector* outModes) const; + std::vector* outModes) const; // Doesn't call into the HWC2 device, so no errors are possible std::vector> getConfigs() const; @@ -235,7 +235,8 @@ public: uint32_t slot, const android::sp& target, const android::sp& acquireFence, android_dataspace_t dataspace); - [[clang::warn_unused_result]] Error setColorMode(android::ColorMode mode); + [[clang::warn_unused_result]] Error setColorMode( + android::ui::ColorMode mode); [[clang::warn_unused_result]] Error setColorTransform( const android::mat4& matrix, android_color_transform_t hint); [[clang::warn_unused_result]] Error setOutputBuffer( @@ -246,8 +247,8 @@ public: [[clang::warn_unused_result]] Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests); [[clang::warn_unused_result]] Error presentOrValidate(uint32_t* outNumTypes, - uint32_t* outNumRequests, - android::sp* outPresentFence, uint32_t* state); + uint32_t* outNumRequests, + android::sp* outPresentFence, uint32_t* state); // Other Display methods diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 6d5917db2f..6bf2ee9362 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -311,8 +311,8 @@ std::shared_ptr return config; } -std::vector HWComposer::getColorModes(int32_t displayId) const { - std::vector modes; +std::vector HWComposer::getColorModes(int32_t displayId) const { + std::vector modes; if (!isValidDisplay(displayId)) { ALOGE("getColorModes: Attempted to access invalid display %d", @@ -324,13 +324,13 @@ std::vector HWComposer::getColorModes(int32_t displayId) const { if (error != HWC2::Error::None) { ALOGE("getColorModes failed for display %d: %s (%d)", displayId, to_string(error).c_str(), static_cast(error)); - return std::vector(); + return std::vector(); } return modes; } -status_t HWComposer::setActiveColorMode(int32_t displayId, ColorMode mode) { +status_t HWComposer::setActiveColorMode(int32_t displayId, ui::ColorMode mode) { if (!isValidDisplay(displayId)) { ALOGE("setActiveColorMode: Display %d is not valid", displayId); return BAD_INDEX; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index c442b2f191..0366a0d164 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -159,9 +159,9 @@ public: std::shared_ptr getActiveConfig(int32_t displayId) const; - std::vector getColorModes(int32_t displayId) const; + std::vector getColorModes(int32_t displayId) const; - status_t setActiveColorMode(int32_t displayId, ColorMode mode); + status_t setActiveColorMode(int32_t displayId, ui::ColorMode mode); bool isUsingVrComposer() const; diff --git a/services/surfaceflinger/RenderArea.h b/services/surfaceflinger/RenderArea.h index b9c4909d5a..bf0707f13b 100644 --- a/services/surfaceflinger/RenderArea.h +++ b/services/surfaceflinger/RenderArea.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "Transform.h" @@ -32,7 +32,7 @@ public: int getReqWidth() const { return mReqWidth; }; Transform::orientation_flags getRotationFlags() const { return mRotationFlags; }; virtual bool getWideColorSupport() const = 0; - virtual ColorMode getActiveColorMode() const = 0; + virtual ui::ColorMode getActiveColorMode() const = 0; status_t updateDimensions(); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index b9e5d3fcdf..82b8bc099a 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -104,6 +104,7 @@ namespace android { using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; +using ui::ColorMode; namespace { class ConditionalLock { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 99bbb13211..b3f39b721a 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -413,9 +413,9 @@ private: Vector* configs); virtual int getActiveConfig(const sp& display); virtual status_t getDisplayColorModes(const sp& display, - Vector* configs); - virtual ColorMode getActiveColorMode(const sp& display); - virtual status_t setActiveColorMode(const sp& display, ColorMode colorMode); + Vector* configs); + virtual ui::ColorMode getActiveColorMode(const sp& display); + virtual status_t setActiveColorMode(const sp& display, ui::ColorMode colorMode); virtual void setPowerMode(const sp& display, int mode); virtual status_t setActiveConfig(const sp& display, int id); virtual status_t clearAnimationFrameStats(); @@ -465,7 +465,7 @@ private: bool stateLockHeld); // Called on the main thread in response to setActiveColorMode() - void setActiveColorModeInternal(const sp& hw, ColorMode colorMode); + void setActiveColorModeInternal(const sp& hw, ui::ColorMode colorMode); // Returns whether the transaction actually modified any state bool handleMessageTransaction(); @@ -638,7 +638,7 @@ private: // Given a dataSpace, returns the appropriate color_mode to use // to display that dataSpace. - ColorMode pickColorMode(android_dataspace dataSpace) const; + ui::ColorMode pickColorMode(android_dataspace dataSpace) const; android_dataspace bestTargetDataSpace(android_dataspace a, android_dataspace b, bool hasHdr) const; diff --git a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp index 86e2e1ec30..b3f1b69f71 100644 --- a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp +++ b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #define HWC2_INCLUDE_STRINGIFICATION #define HWC2_USE_CPP11 @@ -35,7 +35,7 @@ #include "Hwc2TestClientTarget.h" #include "Hwc2TestVirtualDisplay.h" -using android::ColorMode; +using android::ui::ColorMode; void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, hwc2_display_t display, int32_t connected); -- cgit v1.2.3-59-g8ed1b From 9758ae05d7dfc7c02d0b4086b1343fae4ccd8470 Mon Sep 17 00:00:00 2001 From: Valerie Hau Date: Tue, 9 Oct 2018 16:05:09 -0700 Subject: Support DISPLAY_P3 dataspace to BT2020 in SF Adding support to fallback to ColorMode BT2020 with SRGB when P3 layers are present when external display supports BT2020 with SRGB transfer function. (Before fallback was to BT709_sRGB) Bug: 115335239 Test: ./libsurfaceflinger_unittest --gtest_filter=GetBestColorModeTest.* Change-Id: Iec7154d411cb3dcc4fd1158199bc45207799bb27 --- libs/ui/Android.bp | 4 +- libs/ui/DebugUtils.cpp | 3 + libs/ui/include/ui/GraphicTypes.h | 5 +- services/surfaceflinger/Android.bp | 2 + services/surfaceflinger/DisplayDevice.cpp | 7 +- .../surfaceflinger/DisplayHardware/ComposerHal.cpp | 64 ++++++++++------ .../surfaceflinger/DisplayHardware/ComposerHal.h | 4 +- services/surfaceflinger/SurfaceFlinger.cpp | 8 ++ .../tests/unittests/DisplayTransactionTest.cpp | 88 ++++++++++++++++++++++ .../tests/unittests/TestableSurfaceFlinger.h | 12 +++ .../unittests/mock/DisplayHardware/MockComposer.h | 4 +- 11 files changed, 169 insertions(+), 32 deletions(-) (limited to 'libs/ui/DebugUtils.cpp') diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 7b35409943..0a0c8ca014 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -78,7 +78,7 @@ cc_library_shared { shared_libs: [ "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.common@1.1", + "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.1", "android.hardware.configstore@1.0", @@ -97,7 +97,7 @@ cc_library_shared { ], export_shared_lib_headers: [ - "android.hardware.graphics.common@1.1", + "android.hardware.graphics.common@1.2", ], static_libs: [ diff --git a/libs/ui/DebugUtils.cpp b/libs/ui/DebugUtils.cpp index 61df02d41d..ee06d930d8 100644 --- a/libs/ui/DebugUtils.cpp +++ b/libs/ui/DebugUtils.cpp @@ -234,6 +234,9 @@ std::string decodeColorMode(ColorMode colorMode) { case ColorMode::BT2020: return std::string("ColorMode::BT2020"); + case ColorMode::DISPLAY_BT2020: + return std::string("ColorMode::DISPLAY_BT2020"); + case ColorMode::BT2100_PQ: return std::string("ColorMode::BT2100_PQ"); diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index 0fa819dce8..1d53ac8550 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include // android::ui::* in this header file will alias different types as @@ -25,10 +26,10 @@ namespace android { namespace ui { using android::hardware::graphics::common::V1_0::Hdr; -using android::hardware::graphics::common::V1_1::ColorMode; -using android::hardware::graphics::common::V1_1::Dataspace; using android::hardware::graphics::common::V1_1::PixelFormat; using android::hardware::graphics::common::V1_1::RenderIntent; +using android::hardware::graphics::common::V1_2::ColorMode; +using android::hardware::graphics::common::V1_2::Dataspace; } // namespace ui } // namespace android diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 339f83b5f0..16003a258c 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -30,6 +30,7 @@ cc_defaults { "android.hardware.configstore@1.1", "android.hardware.configstore@1.2", "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.common@1.2", "android.hardware.graphics.composer@2.1", "android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.3", @@ -79,6 +80,7 @@ cc_defaults { ], export_shared_lib_headers: [ "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.common@1.2", "android.hardware.graphics.composer@2.1", "android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.3", diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 60cad02e87..6f645df73f 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -37,8 +37,8 @@ #include #include #include -#include #include +#include #include "DisplayHardware/DisplaySurface.h" #include "DisplayHardware/HWComposer.h" @@ -66,7 +66,8 @@ uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; namespace { // ordered list of known SDR color modes -const std::array sSdrColorModes = { +const std::array sSdrColorModes = { + ColorMode::DISPLAY_BT2020, ColorMode::DISPLAY_P3, ColorMode::SRGB, }; @@ -96,6 +97,8 @@ Dataspace colorModeToDataspace(ColorMode mode) { return Dataspace::SRGB; case ColorMode::DISPLAY_P3: return Dataspace::DISPLAY_P3; + case ColorMode::DISPLAY_BT2020: + return Dataspace::DISPLAY_BT2020; case ColorMode::BT2100_HLG: return Dataspace::BT2020_HLG; case ColorMode::BT2100_PQ: diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp index 163b26cd36..f0bccaabf1 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp @@ -354,16 +354,26 @@ Error Composer::getColorModes(Display display, { Error error = kDefaultError; - if (mClient_2_2) { - mClient_2_2->getColorModes_2_2(display, - [&](const auto& tmpError, const auto& tmpModes) { - error = tmpError; - if (error != Error::NONE) { - return; - } + if (mClient_2_3) { + mClient_2_3->getColorModes_2_3(display, [&](const auto& tmpError, const auto& tmpModes) { + error = tmpError; + if (error != Error::NONE) { + return; + } - *outModes = tmpModes; - }); + *outModes = tmpModes; + }); + } else if (mClient_2_2) { + mClient_2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) { + error = tmpError; + if (error != Error::NONE) { + return; + } + + for (types::V1_1::ColorMode colorMode : tmpModes) { + outModes->push_back(static_cast(colorMode)); + } + }); } else { mClient->getColorModes(display, [&](const auto& tmpError, const auto& tmpModes) { @@ -555,8 +565,11 @@ Error Composer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { hardware::Return ret(kDefaultError); - if (mClient_2_2) { - ret = mClient_2_2->setColorMode_2_2(display, mode, renderIntent); + if (mClient_2_3) { + ret = mClient_2_3->setColorMode_2_3(display, mode, renderIntent); + } else if (mClient_2_2) { + ret = mClient_2_2->setColorMode_2_2(display, static_cast(mode), + renderIntent); } else { ret = mClient->setColorMode(display, static_cast(mode)); @@ -934,15 +947,22 @@ Error Composer::getRenderIntents(Display display, ColorMode colorMode, } Error error = kDefaultError; - mClient_2_2->getRenderIntents(display, colorMode, - [&](const auto& tmpError, const auto& tmpKeys) { + + auto getRenderIntentsLambda = [&](const auto& tmpError, const auto& tmpKeys) { error = tmpError; if (error != Error::NONE) { return; } *outRenderIntents = tmpKeys; - }); + }; + + if (mClient_2_3) { + mClient_2_3->getRenderIntents_2_3(display, colorMode, getRenderIntentsLambda); + } else { + mClient_2_2->getRenderIntents(display, static_cast(colorMode), + getRenderIntentsLambda); + } return error; } @@ -955,14 +975,14 @@ Error Composer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatri } Error error = kDefaultError; - mClient_2_2->getDataspaceSaturationMatrix(dataspace, [&](const auto& tmpError, const auto& tmpMatrix) { - error = tmpError; - if (error != Error::NONE) { - return; - } - - *outMatrix = mat4(tmpMatrix.data()); - }); + mClient_2_2->getDataspaceSaturationMatrix(static_cast(dataspace), + [&](const auto& tmpError, const auto& tmpMatrix) { + error = tmpError; + if (error != Error::NONE) { + return; + } + *outMatrix = mat4(tmpMatrix.data()); + }); return error; } diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h index 94be6e93a9..4188352a76 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h @@ -49,10 +49,10 @@ using types::V1_0::ColorTransform; using types::V1_0::Hdr; using types::V1_0::Transform; -using types::V1_1::ColorMode; -using types::V1_1::Dataspace; using types::V1_1::PixelFormat; using types::V1_1::RenderIntent; +using types::V1_2::ColorMode; +using types::V1_2::Dataspace; using V2_1::Config; using V2_1::Display; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index f0723e897b..bd28978bb2 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -124,6 +124,7 @@ bool isWideColorMode(const ColorMode colorMode) { case ColorMode::ADOBE_RGB: case ColorMode::DCI_P3: case ColorMode::BT2020: + case ColorMode::DISPLAY_BT2020: case ColorMode::BT2100_PQ: case ColorMode::BT2100_HLG: return true; @@ -2008,6 +2009,7 @@ void SurfaceFlinger::rebuildLayerStacks() { // can only be one of // - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced) // - Dataspace::DISPLAY_P3 +// - Dataspace::DISPLAY_BT2020 // The returned HDR data space is one of // - Dataspace::UNKNOWN // - Dataspace::BT2020_HLG @@ -2021,6 +2023,12 @@ Dataspace SurfaceFlinger::getBestDataspace(const sp& displa switch (layer->getDataSpace()) { case Dataspace::V0_SCRGB: case Dataspace::V0_SCRGB_LINEAR: + case Dataspace::BT2020: + case Dataspace::BT2020_ITU: + case Dataspace::BT2020_LINEAR: + case Dataspace::DISPLAY_BT2020: + bestDataSpace = Dataspace::DISPLAY_BT2020; + break; case Dataspace::DISPLAY_P3: bestDataSpace = Dataspace::DISPLAY_P3; break; diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp index b474e42260..d32627a7d3 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp @@ -22,6 +22,7 @@ #include +#include #include "TestableSurfaceFlinger.h" #include "mock/DisplayHardware/MockComposer.h" #include "mock/DisplayHardware/MockDisplaySurface.h" @@ -996,6 +997,93 @@ TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) { EXPECT_FALSE(hasDrawingDisplayState(existing.token())); } +/* ------------------------------------------------------------------------ + * DisplayDevice::GetBestColorMode + */ +class GetBestColorModeTest : public DisplayTransactionTest { +public: + GetBestColorModeTest() + : DisplayTransactionTest(), + mInjector(FakeDisplayDeviceInjector(mFlinger, DisplayDevice::DISPLAY_PRIMARY, 0)) {} + + void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; } + + void addHwcColorModesMapping(ui::ColorMode colorMode, + std::vector renderIntents) { + mHwcColorModes[colorMode] = renderIntents; + } + + void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; } + + void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; } + + void getBestColorMode() { + mInjector.setHwcColorModes(mHwcColorModes); + mInjector.setHasWideColorGamut(mHasWideColorGamut); + auto displayDevice = mInjector.inject(); + + displayDevice->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace, + &mOutColorMode, &mOutRenderIntent); + } + + ui::Dataspace mOutDataspace; + ui::ColorMode mOutColorMode; + ui::RenderIntent mOutRenderIntent; + +private: + ui::Dataspace mInputDataspace; + ui::RenderIntent mInputRenderIntent; + bool mHasWideColorGamut = false; + std::unordered_map> mHwcColorModes; + FakeDisplayDeviceInjector mInjector; +}; + +TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) { + addHwcColorModesMapping(ui::ColorMode::SRGB, + std::vector(1, RenderIntent::COLORIMETRIC)); + setInputDataspace(ui::Dataspace::DISPLAY_P3); + setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); + setHasWideColorGamut(true); + + getBestColorMode(); + + ASSERT_EQ(ui::Dataspace::SRGB, mOutDataspace); + ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode); + ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); +} + +TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) { + addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3, + std::vector(1, RenderIntent::COLORIMETRIC)); + addHwcColorModesMapping(ui::ColorMode::SRGB, + std::vector(1, RenderIntent::COLORIMETRIC)); + addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, + std::vector(1, RenderIntent::COLORIMETRIC)); + setInputDataspace(ui::Dataspace::DISPLAY_P3); + setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); + setHasWideColorGamut(true); + + getBestColorMode(); + + ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace); + ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode); + ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); +} + +TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) { + addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, + std::vector(1, RenderIntent::COLORIMETRIC)); + setInputDataspace(ui::Dataspace::DISPLAY_P3); + setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); + setHasWideColorGamut(true); + + getBestColorMode(); + + ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace); + ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode); + ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); +} + /* ------------------------------------------------------------------------ * SurfaceFlinger::setupNewDisplayDeviceInternal */ diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 2046439889..62afde9b0f 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -369,6 +369,18 @@ public: return *this; } + auto& setHwcColorModes( + const std::unordered_map> + hwcColorModes) { + mCreationArgs.hwcColorModes = hwcColorModes; + return *this; + } + + auto& setHasWideColorGamut(bool hasWideColorGamut) { + mCreationArgs.hasWideColorGamut = hasWideColorGamut; + return *this; + } + sp inject() { DisplayDeviceState state; state.type = mCreationArgs.type; diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h index ecf3181695..c0395c01ce 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h @@ -30,10 +30,10 @@ namespace mock { using android::hardware::graphics::common::V1_0::ColorTransform; using android::hardware::graphics::common::V1_0::Hdr; using android::hardware::graphics::common::V1_0::Transform; -using android::hardware::graphics::common::V1_1::ColorMode; -using android::hardware::graphics::common::V1_1::Dataspace; using android::hardware::graphics::common::V1_1::PixelFormat; using android::hardware::graphics::common::V1_1::RenderIntent; +using android::hardware::graphics::common::V1_2::ColorMode; +using android::hardware::graphics::common::V1_2::Dataspace; using android::hardware::graphics::composer::V2_1::Config; using android::hardware::graphics::composer::V2_1::Display; -- cgit v1.2.3-59-g8ed1b