| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 |
| 5 #ifndef UI_DISPLAY_WIN_COLOR_PROFILE_READER_H_ |
| 6 #define UI_DISPLAY_WIN_COLOR_PROFILE_READER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/strings/string16.h" |
| 11 #include "ui/display/display_export.h" |
| 12 #include "ui/gfx/color_space.h" |
| 13 |
| 14 #include <map> |
| 15 #include <string> |
| 16 |
| 17 namespace display { |
| 18 namespace win { |
| 19 |
| 20 // Monitor ICC profiles are stored in the filesystem, and a blocking read from |
| 21 // file is required to read them. This is expensive and shouldn't be done on the |
| 22 // main thread, so this class manages asynchronously doing these readings and |
| 23 // calling back into its client when the profiles are noticed to have changed. |
| 24 class DISPLAY_EXPORT ColorProfileReader { |
| 25 public: |
| 26 class Client { |
| 27 public: |
| 28 virtual void OnColorProfilesChanged() = 0; |
| 29 }; |
| 30 |
| 31 ColorProfileReader(Client* client); |
| 32 ~ColorProfileReader(); |
| 33 |
| 34 // Check to see if the screen profile filenames have changed. If so, spawn a |
| 35 // task to update them. When the task has completed, this will call the |
| 36 // client's OnColorProfileReaderChanged on the main thread. |
| 37 void UpdateIfNeeded(); |
| 38 |
| 39 // Look up the color space for a given device name. If the device's color |
| 40 // profile has not yet been read, this will return sRGB (which is what the |
| 41 // file on disk will say most of the time). |
| 42 const gfx::ColorSpace& GetDisplayColorSpace(int64_t id) const; |
| 43 |
| 44 private: |
| 45 typedef std::map<base::string16, base::string16> DeviceToPathMap; |
| 46 typedef std::map<base::string16, std::string> DeviceToDataMap; |
| 47 |
| 48 // Enumerate displays and return a map to their ICC profile path. |
| 49 static DeviceToPathMap BuildDeviceToPathMap(); |
| 50 |
| 51 // Do the actual reading from the filesystem. This needs to be run off of the |
| 52 // main thread. |
| 53 static DeviceToDataMap ReadProfilesOnBackgroundThread( |
| 54 DeviceToPathMap new_device_to_path_map); |
| 55 |
| 56 // Called on the main thread when the read has completed. |
| 57 void ReadProfilesCompleted(DeviceToDataMap device_to_data_map); |
| 58 |
| 59 Client* const client_ = nullptr; |
| 60 bool update_in_flight_ = false; |
| 61 DeviceToPathMap device_to_path_map_; |
| 62 std::map<int64_t, gfx::ColorSpace> display_id_to_color_space_map_; |
| 63 const gfx::ColorSpace default_color_space_ = gfx::ColorSpace::CreateSRGB(); |
| 64 base::WeakPtrFactory<ColorProfileReader> weak_factory_; |
| 65 }; |
| 66 |
| 67 } // namespace win |
| 68 } // namespace display |
| 69 |
| 70 #endif // UI_DISPLAY_WIN_COLOR_PROFILE_READER_H_ |
| OLD | NEW |