target_color_params.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_TARGET_COLOR_PARAMS_H_
  5. #define CC_PAINT_TARGET_COLOR_PARAMS_H_
  6. #include <string>
  7. #include "cc/paint/paint_export.h"
  8. #include "ui/gfx/color_space.h"
  9. namespace cc {
  10. // Color parameters for a target for rasterization.
  11. struct CC_PAINT_EXPORT TargetColorParams {
  12. TargetColorParams() = default;
  13. TargetColorParams(const TargetColorParams&) = default;
  14. TargetColorParams& operator=(const TargetColorParams&) = default;
  15. ~TargetColorParams() = default;
  16. // Constructor to use in tests to specify just a color space.
  17. explicit TargetColorParams(const gfx::ColorSpace& color_space)
  18. : color_space(color_space) {}
  19. // The target buffer's color space.
  20. gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
  21. // The maximum SDR luminance of the target, in nits.
  22. float sdr_max_luminance_nits = gfx::ColorSpace::kDefaultSDRWhiteLevel;
  23. // The maximum HDR luminance of the target, in multiples of the SDR maximum
  24. // luminance (a non-HDR-capable display will have a value of 1).
  25. float hdr_max_luminance_relative = 1.f;
  26. // Whether or not tone mapping should be applied.
  27. bool enable_tone_mapping = true;
  28. bool operator==(const TargetColorParams& other) const {
  29. return color_space == other.color_space &&
  30. sdr_max_luminance_nits == other.sdr_max_luminance_nits &&
  31. hdr_max_luminance_relative == other.hdr_max_luminance_relative;
  32. }
  33. bool operator!=(const TargetColorParams& other) const {
  34. return !(*this == other);
  35. }
  36. bool operator<(const TargetColorParams& other) const {
  37. return std::tie(color_space, sdr_max_luminance_nits,
  38. hdr_max_luminance_relative) <
  39. std::tie(other.color_space, other.sdr_max_luminance_nits,
  40. other.hdr_max_luminance_relative);
  41. }
  42. size_t GetHash() const;
  43. std::string ToString() const;
  44. };
  45. } // namespace cc
  46. #endif // CC_PAINT_TARGET_COLOR_PARAMS_H_