vp-build/srcpkgs/electron9/files/patches/chromium-upstream-0001-Reve...

437 lines
18 KiB
Diff

From 44f5d255245153ac3f5aa4b6530810ca93ff46e6 Mon Sep 17 00:00:00 2001
From: Miguel Casas <mcasas@chromium.org>
Date: Mon, 22 Jun 2020 20:24:57 +0000
Subject: [PATCH 01/12] Revert "ui: fill in SDR/HDR DisplayColorSpaces, CrOS"
This reverts commit 07199ff111cb3b31da0752adc62ffbe05101dfde.
Said commit inadvertently instructed the compositor to use the
EDID-provided ColorSpace as target for rastering, causing colours
to be accurate, but washed out.
Original Commit description ----------------------------------------
This CL adds code for populating the necessary gfx::DisplayColorSpaces
in CreateManagedDisplayInfo for supporting SDR and HDR target color
spaces (depending on the monitor capabilities and the big hdr flag).
It needs a sibling CL to allow AR/B30 FBs on CrOs crrev.com/c/2078655,
Tested with that CL and by playing an HDR video: the primary
framebuffer format in /sys/kernel/debug/dri/0//state correctly changes
to XB30, whereas when there are not HDR quads in the BufferQueue, it's
XR24.
Bug: 958166
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2072621
Reviewed-by: ccameron <ccameron@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745461}
(cherry picked from commit f807a5774bc1af6ef43c408bd0a1a0b0d55e2c4a)
Bug: b:158126931, 958166
Change-Id: Iee5c9a431a9c0f9f6a5b4d229ab70183c264ad9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2232761
Auto-Submit: Miguel Casas <mcasas@chromium.org>
Reviewed-by: ccameron <ccameron@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#775775}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2258293
Reviewed-by: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/branch-heads/4103@{#724}
Cr-Branched-From: 8ad47e8d21f6866e4a37f47d83a860d41debf514-refs/heads/master@{#756066}
---
ui/compositor/compositor.cc | 10 ++
ui/display/fake/fake_display_snapshot.cc | 21 +--
ui/display/fake/fake_display_snapshot.h | 8 +-
ui/display/manager/display_change_observer.cc | 69 ++-------
ui/display/manager/display_change_observer.h | 2 -
.../display_change_observer_unittest.cc | 134 +-----------------
6 files changed, 25 insertions(+), 219 deletions(-)
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index e94d022afcc..dd4f89d7676 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -444,6 +444,16 @@ void Compositor::SetDisplayColorSpaces(
if (display_color_spaces_ == display_color_spaces)
return;
display_color_spaces_ = display_color_spaces;
+ // TODO(crbug.com/1012846): Remove this flag and provision when HDR is fully
+ // supported on ChromeOS.
+#if defined(OS_CHROMEOS)
+ if (display_color_spaces_.SupportsHDR() &&
+ !base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableUseHDRTransferFunction)) {
+ display_color_spaces_ =
+ gfx::DisplayColorSpaces(gfx::ColorSpace::CreateSRGB());
+ }
+#endif
host_->SetRasterColorSpace(display_color_spaces_.GetRasterColorSpace());
// Always force the ui::Compositor to re-draw all layers, because damage
diff --git a/ui/display/fake/fake_display_snapshot.cc b/ui/display/fake/fake_display_snapshot.cc
index 3568c296327..94da2c4e398 100644
--- a/ui/display/fake/fake_display_snapshot.cc
+++ b/ui/display/fake/fake_display_snapshot.cc
@@ -163,8 +163,7 @@ std::unique_ptr<FakeDisplaySnapshot> Builder::Build() {
id_, origin_, physical_size, type_, is_aspect_preserving_scaling_,
has_overscan_, privacy_screen_state_, has_color_correction_matrix_,
color_correction_in_linear_space_, name_, std::move(modes_),
- current_mode_, native_mode_, product_code_, maximum_cursor_size_,
- color_space_, bits_per_channel_);
+ current_mode_, native_mode_, product_code_, maximum_cursor_size_);
}
Builder& Builder::SetId(int64_t id) {
@@ -265,16 +264,6 @@ Builder& Builder::SetPrivacyScreen(PrivacyScreenState state) {
return *this;
}
-Builder& Builder::SetColorSpace(const gfx::ColorSpace& color_space) {
- color_space_ = color_space;
- return *this;
-}
-
-Builder& Builder::SetBitsPerChannel(uint32_t bits_per_channel) {
- bits_per_channel_ = bits_per_channel;
- return *this;
-}
-
const DisplayMode* Builder::AddOrFindDisplayMode(const gfx::Size& size) {
for (auto& mode : modes_) {
if (mode->size() == size)
@@ -316,9 +305,7 @@ FakeDisplaySnapshot::FakeDisplaySnapshot(
const DisplayMode* current_mode,
const DisplayMode* native_mode,
int64_t product_code,
- const gfx::Size& maximum_cursor_size,
- const gfx::ColorSpace& color_space,
- uint32_t bits_per_channel)
+ const gfx::Size& maximum_cursor_size)
: DisplaySnapshot(display_id,
origin,
physical_size,
@@ -328,8 +315,8 @@ FakeDisplaySnapshot::FakeDisplaySnapshot(
privacy_screen_state,
has_color_correction_matrix,
color_correction_in_linear_space,
- color_space,
- bits_per_channel,
+ gfx::ColorSpace(),
+ 8u /* bits_per_channel */,
display_name,
base::FilePath(),
std::move(modes),
diff --git a/ui/display/fake/fake_display_snapshot.h b/ui/display/fake/fake_display_snapshot.h
index d521fb34078..833ac744d08 100644
--- a/ui/display/fake/fake_display_snapshot.h
+++ b/ui/display/fake/fake_display_snapshot.h
@@ -70,8 +70,6 @@ class FAKE_DISPLAY_EXPORT FakeDisplaySnapshot : public DisplaySnapshot {
// Sets physical_size for high DPI display.
Builder& SetHighDPI();
Builder& SetPrivacyScreen(PrivacyScreenState state);
- Builder& SetColorSpace(const gfx::ColorSpace& color_space);
- Builder& SetBitsPerChannel(uint32_t bits_per_channel);
private:
// Returns a display mode with |size|. If there is no existing mode, insert
@@ -96,8 +94,6 @@ class FAKE_DISPLAY_EXPORT FakeDisplaySnapshot : public DisplaySnapshot {
DisplayModeList modes_;
const DisplayMode* current_mode_ = nullptr;
const DisplayMode* native_mode_ = nullptr;
- gfx::ColorSpace color_space_;
- uint32_t bits_per_channel_ = 8u;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
@@ -116,9 +112,7 @@ class FAKE_DISPLAY_EXPORT FakeDisplaySnapshot : public DisplaySnapshot {
const DisplayMode* current_mode,
const DisplayMode* native_mode,
int64_t product_code,
- const gfx::Size& maximum_cursor_size,
- const gfx::ColorSpace& color_space,
- uint32_t bits_per_channel);
+ const gfx::Size& maximum_cursor_size);
~FakeDisplaySnapshot() override;
// Creates a display snapshot from the provided |spec| string. Returns null if
diff --git a/ui/display/manager/display_change_observer.cc b/ui/display/manager/display_change_observer.cc
index 28dbd10ec19..799d896d8e7 100644
--- a/ui/display/manager/display_change_observer.cc
+++ b/ui/display/manager/display_change_observer.cc
@@ -77,55 +77,6 @@ ManagedDisplayInfo::ManagedDisplayModeList GetModeListWithAllRefreshRates(
return display_mode_list;
}
-// Constructs the raster DisplayColorSpaces out of |snapshot_color_space|,
-// including the HDR ones if present and |allow_high_bit_depth| is set.
-gfx::DisplayColorSpaces FillDisplayColorSpaces(
- const gfx::ColorSpace& snapshot_color_space,
- bool allow_high_bit_depth) {
- // ChromeOS VMs (e.g. amd64-generic or betty) have INVALID Primaries; just
- // pass the color space along.
- if (!snapshot_color_space.IsValid()) {
- return gfx::DisplayColorSpaces(snapshot_color_space,
- DisplaySnapshot::PrimaryFormat());
- }
-
- constexpr auto kSDRTransferId = gfx::ColorSpace::TransferID::IEC61966_2_1;
- const auto primary_id = snapshot_color_space.GetPrimaryID();
-
- gfx::ColorSpace sdr_color_space;
- if (primary_id == gfx::ColorSpace::PrimaryID::CUSTOM) {
- skcms_Matrix3x3 primary_matrix{};
- snapshot_color_space.GetPrimaryMatrix(&primary_matrix);
- sdr_color_space =
- gfx::ColorSpace::CreateCustom(primary_matrix, kSDRTransferId);
- } else {
- sdr_color_space = gfx::ColorSpace(primary_id, kSDRTransferId);
- }
- gfx::DisplayColorSpaces display_color_spaces(
- sdr_color_space, DisplaySnapshot::PrimaryFormat());
-
- if (allow_high_bit_depth) {
- gfx::ColorSpace hdr_color_space;
- if (primary_id == gfx::ColorSpace::PrimaryID::CUSTOM) {
- skcms_Matrix3x3 primary_matrix{};
- snapshot_color_space.GetPrimaryMatrix(&primary_matrix);
- hdr_color_space = gfx::ColorSpace::CreatePiecewiseHDR(
- primary_id, 0.99, 2.0, &primary_matrix);
- } else {
- hdr_color_space =
- gfx::ColorSpace::CreatePiecewiseHDR(primary_id, 0.99, 2.0);
- }
-
- display_color_spaces.SetOutputColorSpaceAndBufferFormat(
- gfx::ContentColorUsage::kHDR, false /* needs_alpha */, hdr_color_space,
- gfx::BufferFormat::RGBA_1010102);
- display_color_spaces.SetOutputColorSpaceAndBufferFormat(
- gfx::ContentColorUsage::kHDR, true /* needs_alpha */, hdr_color_space,
- gfx::BufferFormat::RGBA_1010102);
- }
- return display_color_spaces;
-}
-
} // namespace
// static
@@ -386,23 +337,21 @@ ManagedDisplayInfo DisplayChangeObserver::CreateManagedDisplayInfo(
if (dpi)
new_info.set_device_dpi(dpi);
-#if !defined(OS_CHROMEOS)
// TODO(crbug.com/1012846): This should configure the HDR color spaces.
gfx::DisplayColorSpaces display_color_spaces(
snapshot->color_space(), DisplaySnapshot::PrimaryFormat());
new_info.set_display_color_spaces(display_color_spaces);
new_info.set_bits_per_channel(snapshot->bits_per_channel());
-#else
- // TODO(crbug.com/1012846): Remove kEnableUseHDRTransferFunction usage when
- // HDR is fully supported on ChromeOS.
- const bool allow_high_bit_depth =
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableUseHDRTransferFunction);
- new_info.set_display_color_spaces(
- FillDisplayColorSpaces(snapshot->color_space(), allow_high_bit_depth));
+
+ // TODO(crbug.com/1012846): Remove this flag and provision when HDR is fully
+ // supported on ChromeOS.
+#if defined(OS_CHROMEOS)
constexpr int32_t kNormalBitDepth = 8;
- new_info.set_bits_per_channel(
- allow_high_bit_depth ? snapshot->bits_per_channel() : kNormalBitDepth);
+ if (new_info.bits_per_channel() > kNormalBitDepth &&
+ !base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableUseHDRTransferFunction)) {
+ new_info.set_bits_per_channel(kNormalBitDepth);
+ }
#endif
new_info.set_refresh_rate(mode_info->refresh_rate());
diff --git a/ui/display/manager/display_change_observer.h b/ui/display/manager/display_change_observer.h
index 5c17ce60977..0e896e24e5e 100644
--- a/ui/display/manager/display_change_observer.h
+++ b/ui/display/manager/display_change_observer.h
@@ -60,8 +60,6 @@ class DISPLAY_MANAGER_EXPORT DisplayChangeObserver
DISPLAY_EXPORT static float FindDeviceScaleFactor(float dpi);
private:
- friend class DisplayChangeObserverTest;
-
void UpdateInternalDisplay(
const DisplayConfigurator::DisplayStateList& display_states);
diff --git a/ui/display/manager/display_change_observer_unittest.cc b/ui/display/manager/display_change_observer_unittest.cc
index 1b2907137f9..bb900209bac 100644
--- a/ui/display/manager/display_change_observer_unittest.cc
+++ b/ui/display/manager/display_change_observer_unittest.cc
@@ -14,11 +14,8 @@
#include "ui/display/display_switches.h"
#include "ui/display/fake/fake_display_snapshot.h"
#include "ui/display/manager/display_configurator.h"
-#include "ui/display/manager/display_manager.h"
#include "ui/display/manager/managed_display_info.h"
-#include "ui/display/screen.h"
#include "ui/display/types/display_mode.h"
-#include "ui/events/devices/device_data_manager.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
@@ -63,13 +60,6 @@ class DisplayChangeObserverTest : public testing::Test,
Test::SetUp();
}
- // Pass through method to be called by individual test cases.
- ManagedDisplayInfo CreateManagedDisplayInfo(DisplayChangeObserver* observer,
- const DisplaySnapshot* snapshot,
- const DisplayMode* mode_info) {
- return observer->CreateManagedDisplayInfo(snapshot, mode_info);
- }
-
private:
base::test::ScopedFeatureList scoped_feature_list_;
@@ -185,8 +175,7 @@ TEST_P(DisplayChangeObserverTest, GetEmptyExternalManagedDisplayModeList) {
FakeDisplaySnapshot display_snapshot(
123, gfx::Point(), gfx::Size(), DISPLAY_CONNECTION_TYPE_UNKNOWN, false,
false, PrivacyScreenState::kNotSupported, false, false, std::string(), {},
- nullptr, nullptr, 0, gfx::Size(), gfx::ColorSpace(),
- /*bits_per_channel=*/8u);
+ nullptr, nullptr, 0, gfx::Size());
ManagedDisplayInfo::ManagedDisplayModeList display_modes =
DisplayChangeObserver::GetExternalManagedDisplayModeList(
@@ -305,127 +294,6 @@ TEST_P(DisplayChangeObserverTest,
}
}
-TEST_P(DisplayChangeObserverTest, InvalidDisplayColorSpaces) {
- const std::unique_ptr<DisplaySnapshot> display_snapshot =
- FakeDisplaySnapshot::Builder()
- .SetId(123)
- .SetName("AmazingFakeDisplay")
- .SetNativeMode(MakeDisplayMode(1920, 1080, true, 60))
- .SetColorSpace(gfx::ColorSpace())
- .Build();
-
- ui::DeviceDataManager::CreateInstance();
- DisplayManager manager(nullptr);
- const auto display_mode = MakeDisplayMode(1920, 1080, true, 60);
- DisplayChangeObserver observer(&manager);
- const ManagedDisplayInfo display_info = CreateManagedDisplayInfo(
- &observer, display_snapshot.get(), display_mode.get());
-
- EXPECT_EQ(display_info.bits_per_channel(), 8u);
- const auto display_color_spaces = display_info.display_color_spaces();
- EXPECT_FALSE(display_color_spaces.SupportsHDR());
-
- EXPECT_EQ(
- DisplaySnapshot::PrimaryFormat(),
- display_color_spaces.GetOutputBufferFormat(gfx::ContentColorUsage::kSRGB,
- /*needs_alpha=*/true));
-
- const auto color_space = display_color_spaces.GetRasterColorSpace();
- // DisplayColorSpaces will fix an invalid ColorSpace to return sRGB.
- EXPECT_TRUE(color_space.IsValid());
- EXPECT_EQ(color_space, gfx::ColorSpace::CreateSRGB());
-}
-
-TEST_P(DisplayChangeObserverTest, SDRDisplayColorSpaces) {
- const std::unique_ptr<DisplaySnapshot> display_snapshot =
- FakeDisplaySnapshot::Builder()
- .SetId(123)
- .SetName("AmazingFakeDisplay")
- .SetNativeMode(MakeDisplayMode(1920, 1080, true, 60))
- .SetColorSpace(gfx::ColorSpace::CreateSRGB())
- .Build();
-
- ui::DeviceDataManager::CreateInstance();
- DisplayManager manager(nullptr);
- const auto display_mode = MakeDisplayMode(1920, 1080, true, 60);
- DisplayChangeObserver observer(&manager);
- const ManagedDisplayInfo display_info = CreateManagedDisplayInfo(
- &observer, display_snapshot.get(), display_mode.get());
-
- EXPECT_EQ(display_info.bits_per_channel(), 8u);
-
- const auto display_color_spaces = display_info.display_color_spaces();
- EXPECT_FALSE(display_color_spaces.SupportsHDR());
-
- EXPECT_EQ(
- DisplaySnapshot::PrimaryFormat(),
- display_color_spaces.GetOutputBufferFormat(gfx::ContentColorUsage::kSRGB,
- /*needs_alpha=*/true));
-
- const auto color_space = display_color_spaces.GetRasterColorSpace();
- EXPECT_TRUE(color_space.IsValid());
- EXPECT_EQ(color_space.GetPrimaryID(), gfx::ColorSpace::PrimaryID::BT709);
- EXPECT_EQ(color_space.GetTransferID(),
- gfx::ColorSpace::TransferID::IEC61966_2_1);
-}
-
-#if defined(OS_CHROMEOS)
-TEST_P(DisplayChangeObserverTest, HDRDisplayColorSpaces) {
- // TODO(crbug.com/1012846): Remove this flag and provision when HDR is fully
- // supported on ChromeOS.
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kEnableUseHDRTransferFunction);
-
- const std::unique_ptr<DisplaySnapshot> display_snapshot =
- FakeDisplaySnapshot::Builder()
- .SetId(123)
- .SetName("AmazingFakeDisplay")
- .SetNativeMode(MakeDisplayMode(1920, 1080, true, 60))
- .SetColorSpace(gfx::ColorSpace::CreateHDR10(100.0f))
- .SetBitsPerChannel(10u)
- .Build();
-
- ui::DeviceDataManager::CreateInstance();
- DisplayManager manager(nullptr);
- const auto display_mode = MakeDisplayMode(1920, 1080, true, 60);
- DisplayChangeObserver observer(&manager);
- const ManagedDisplayInfo display_info = CreateManagedDisplayInfo(
- &observer, display_snapshot.get(), display_mode.get());
-
- EXPECT_EQ(display_info.bits_per_channel(), 10u);
-
- const auto display_color_spaces = display_info.display_color_spaces();
- EXPECT_TRUE(display_color_spaces.SupportsHDR());
-
- // |display_color_spaces| still supports SDR rendering.
- EXPECT_EQ(
- DisplaySnapshot::PrimaryFormat(),
- display_color_spaces.GetOutputBufferFormat(gfx::ContentColorUsage::kSRGB,
- /*needs_alpha=*/true));
-
- const auto sdr_color_space =
- display_color_spaces.GetOutputColorSpace(gfx::ContentColorUsage::kSRGB,
- /*needs_alpha=*/true);
- EXPECT_TRUE(sdr_color_space.IsValid());
- EXPECT_EQ(sdr_color_space.GetPrimaryID(), gfx::ColorSpace::PrimaryID::BT2020);
- EXPECT_EQ(sdr_color_space.GetTransferID(),
- gfx::ColorSpace::TransferID::IEC61966_2_1);
-
- EXPECT_EQ(
- display_color_spaces.GetOutputBufferFormat(gfx::ContentColorUsage::kHDR,
- /*needs_alpha=*/true),
- gfx::BufferFormat::RGBA_1010102);
-
- const auto hdr_color_space =
- display_color_spaces.GetOutputColorSpace(gfx::ContentColorUsage::kHDR,
- /*needs_alpha=*/true);
- EXPECT_TRUE(hdr_color_space.IsValid());
- EXPECT_EQ(hdr_color_space.GetPrimaryID(), gfx::ColorSpace::PrimaryID::BT2020);
- EXPECT_EQ(hdr_color_space.GetTransferID(),
- gfx::ColorSpace::TransferID::PIECEWISE_HDR);
-}
-#endif
-
INSTANTIATE_TEST_SUITE_P(All,
DisplayChangeObserverTest,
::testing::Values(false, true));
--
2.28.0