display_icc_profiles.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2018 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 UI_GFX_MAC_DISPLAY_ICC_PROFILES_H_
  5. #define UI_GFX_MAC_DISPLAY_ICC_PROFILES_H_
  6. #include <CoreGraphics/CoreGraphics.h>
  7. #include "base/containers/flat_map.h"
  8. #include "base/mac/scoped_cftyperef.h"
  9. #include "base/no_destructor.h"
  10. #include "ui/gfx/color_space.h"
  11. #include "ui/gfx/color_space_export.h"
  12. namespace gfx {
  13. // A map from ColorSpace objects to the display ICC profile data from which the
  14. // ColorSpace was derived.
  15. // - The color space for an IOSurface, when composited by CoreAnimation, is
  16. // specified via ICC profile metadata.
  17. // - The power cost of compositing an IOSurface that has the same color space
  18. // as the display it is being composited to is substantially less (~0.5 W for
  19. // fullscreen updates at 60fps) than the cost of compositing an IOSurface
  20. // that has a different color space than the display is being composited to.
  21. // - This power savings is realized only if the ICC profile metadata on the
  22. // IOSurface matches, byte-for-byte, the profile of the CGDirectDisplayID it
  23. // is being displayed on.
  24. // - This structure maintains a map from ColorSpace objects to ICC profile data
  25. // for all displays in the system (and auto-updates as displays change).
  26. class COLOR_SPACE_EXPORT DisplayICCProfiles {
  27. public:
  28. static DisplayICCProfiles* GetInstance();
  29. DisplayICCProfiles(const DisplayICCProfiles&) = delete;
  30. DisplayICCProfiles& operator=(const DisplayICCProfiles&) = delete;
  31. // This will return null if |color_space| does not correspond to a display.
  32. base::ScopedCFTypeRef<CFDataRef> GetDataForColorSpace(
  33. const ColorSpace& color_space);
  34. private:
  35. friend class base::NoDestructor<DisplayICCProfiles>;
  36. static void DisplayReconfigurationCallBack(CGDirectDisplayID display,
  37. CGDisplayChangeSummaryFlags flags,
  38. void* user_info);
  39. DisplayICCProfiles();
  40. ~DisplayICCProfiles();
  41. void UpdateIfNeeded();
  42. base::flat_map<ColorSpace, base::ScopedCFTypeRef<CFDataRef>> map_;
  43. bool needs_update_ = true;
  44. };
  45. } // namespace gfx
  46. #endif // UI_GFX_MAC_DISPLAY_ICC_PROFILES_H_