chromium/ui/display/util/display_util.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "ui/display/util/display_util.h"

#include <stddef.h>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "components/device_event_log/device_event_log.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/display/util/edid_parser.h"
#include "ui/gfx/icc_profile.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ui/display/display_features.h"
#endif

namespace display {

namespace {

base::flat_set<int64_t>* internal_display_ids() {}

// A list of bogus sizes in mm that should be ignored.
// See crbug.com/136533. The first element maintains the minimum
// size required to be valid size.
constexpr int kInvalidDisplaySizeList[][2] =;

// Used in the GetColorSpaceFromEdid function to collect data on whether the
// color space extracted from an EDID blob passed the sanity checks.
void EmitEdidColorSpaceChecksOutcomeUma(EdidColorSpaceChecksOutcome outcome) {}

// Returns true if each and all matrix values are within |epsilon| distance.
bool NearlyEqual(const skcms_Matrix3x3& lhs,
                 const skcms_Matrix3x3& rhs,
                 float epsilon) {}

}  // namespace

bool IsDisplaySizeValid(const gfx::Size& physical_size) {}

int64_t GenerateDisplayID(uint16_t manufacturer_id,
                          uint32_t product_code_hash,
                          uint8_t output_index) {}

gfx::ColorSpace GetColorSpaceFromEdid(const display::EdidParser& edid_parser) {}

bool CompareDisplayIds(int64_t id1, int64_t id2) {}

bool IsInternalDisplayId(int64_t display_id) {}

const base::flat_set<int64_t>& GetInternalDisplayIds() {}

// static
bool HasInternalDisplay() {}

void SetInternalDisplayIds(base::flat_set<int64_t> display_ids) {}

gfx::ColorSpace ForcedColorProfileStringToColorSpace(const std::string& value) {}

gfx::ColorSpace GetForcedDisplayColorProfile() {}

bool HasForceDisplayColorProfile() {}

#if BUILDFLAG(IS_CHROMEOS)
// Constructs the raster DisplayColorSpaces out of |snapshot_color_space|,
// including the HDR ones if present and |allow_high_bit_depth| is set.
gfx::DisplayColorSpaces CreateDisplayColorSpaces(
    const gfx::ColorSpace& snapshot_color_space,
    bool allow_high_bit_depth,
    const std::optional<gfx::HDRStaticMetadata>& hdr_static_metadata) {
  if (HasForceDisplayColorProfile()) {
    return gfx::DisplayColorSpaces(GetForcedDisplayColorProfile(),
                                   DisplaySnapshot::PrimaryFormat());
  }

  // 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());
  }

  // Make all displays report that they have sRGB primaries. Hardware color
  // management will convert to the device's color primaries.
  skcms_Matrix3x3 primary_matrix = SkNamedGamut::kSRGB;

  // Reconstruct the native colorspace with an IEC61966 2.1 transfer function
  // for SDR content (matching that of sRGB).
  gfx::ColorSpace sdr_color_space = gfx::ColorSpace::CreateCustom(
      primary_matrix, gfx::ColorSpace::TransferID::SRGB);

  // Use that color space for all content.
  gfx::DisplayColorSpaces display_color_spaces = gfx::DisplayColorSpaces(
      sdr_color_space, DisplaySnapshot::PrimaryFormat());

  // Claim 10% HDR headroom if HDR is available.
  if (allow_high_bit_depth && snapshot_color_space.IsHDR()) {
    gfx::ColorSpace hdr_color_space = gfx::ColorSpace::CreateCustom(
        primary_matrix, gfx::ColorSpace::TransferID::SRGB_HDR);

    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);
    display_color_spaces.SetHDRMaxLuminanceRelative(1.1f);
  }

#if BUILDFLAG(IS_CHROMEOS_ASH)
  if (allow_high_bit_depth &&
      snapshot_color_space == gfx::ColorSpace::CreateHDR10() &&
      base::FeatureList::IsEnabled(
          display::features::kEnableExternalDisplayHDR10Mode)) {
    // This forces the main UI plane to be always HDR10 regardless of
    // ContentColorUsage. BT2020 primaries and PQ transfer function require a
    // 10-bit buffer.
    display_color_spaces = gfx::DisplayColorSpaces(
        gfx::ColorSpace::CreateHDR10(), gfx::BufferFormat::RGBA_1010102);
    // TODO(b/165822222): Set initial luminance values based on display
    // brightness
    display_color_spaces.SetHDRMaxLuminanceRelative(
        hdr_static_metadata->max /
        display_color_spaces.GetSDRMaxLuminanceNits());
  }
#endif
  return display_color_spaces;
}
#endif  // BUILDFLAG(IS_CHROMEOS)

int ConnectorIndex8(int device_index, int display_index) {}

uint16_t ConnectorIndex16(uint8_t device_index, uint8_t display_index) {}

}  // namespace display