OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/display_color_manager_chromeos.h" | 5 #include "ash/display/display_color_manager_chromeos.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | |
12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
14 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 16 #include "base/path_service.h" |
18 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
19 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
20 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
22 #include "chromeos/chromeos_paths.h" | 21 #include "chromeos/chromeos_paths.h" |
22 #include "components/quirks_client/quirks_client.h" | |
23 #include "third_party/qcms/src/qcms.h" | 23 #include "third_party/qcms/src/qcms.h" |
24 #include "ui/display/types/display_snapshot.h" | 24 #include "ui/display/types/display_snapshot.h" |
25 #include "ui/display/types/gamma_ramp_rgb_entry.h" | 25 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
26 #include "ui/display/types/native_display_delegate.h" | 26 #include "ui/display/types/native_display_delegate.h" |
27 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
29 | 29 |
30 namespace ash { | 30 namespace ash { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 bool ParseFile(const base::FilePath& path, | 34 class FakeDisplaySnapshot : public ui::DisplaySnapshot { |
35 DisplayColorManager::ColorCalibrationData* data) { | 35 public: |
36 FakeDisplaySnapshot(int64_t product_id) | |
37 : ui::DisplaySnapshot(0, gfx::Point(0, 0), gfx::Size(0, 0), | |
38 ui::DISPLAY_CONNECTION_TYPE_NONE, false, false, | |
39 "test", base::FilePath(), | |
40 std::vector<const ui::DisplayMode*>(), | |
41 nullptr, nullptr) { | |
42 product_id_ = product_id; | |
43 } | |
44 ~FakeDisplaySnapshot() override{}; | |
45 | |
46 // DisplaySnapshot override: | |
47 std::string ToString() const override { return display_name_; } | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(FakeDisplaySnapshot); | |
50 }; | |
51 | |
52 bool ParseDisplayProfile(const int64_t display_id, | |
53 const int64_t product_id, | |
54 DisplayColorManager::ColorCalibrationData* data) { | |
55 quirks_client::QuirksClient::DownloadFinishedCallback* callback = nullptr; | |
56 // TODO(glevin): Do we want to add a callback so that we can apply the icc | |
57 // profile as soon as it's downloaded? | |
58 base::FilePath path = | |
59 quirks_client::QuirksClient::RequestIccProfilePath(product_id, callback); | |
60 std::string product_string = base::StringPrintf("0x%08" PRIx64, product_id); | |
61 if (path.empty()) { | |
62 VLOG(1) << "No icc file found with product id: " << product_string | |
63 << " for display id: " << display_id; | |
64 } else { | |
65 VLOG(1) << "Loading ICC file " << path.value() | |
66 << " for display id: " << display_id | |
67 << " with product id: " << product_string; | |
68 } | |
69 | |
36 if (!base::PathExists(path)) // No icc file for this display; not an error. | 70 if (!base::PathExists(path)) // No icc file for this display; not an error. |
37 return false; | 71 return false; |
38 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | 72 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); |
39 | 73 |
40 if (!display_profile) { | 74 if (!display_profile) { |
41 LOG(WARNING) << "Unable to load ICC file: " << path.value(); | 75 LOG(WARNING) << "Unable to load ICC file: " << path.value(); |
42 return false; | 76 return false; |
43 } | 77 } |
44 | 78 |
45 size_t vcgt_channel_length = | 79 size_t vcgt_channel_length = |
(...skipping 12 matching lines...) Expand all Loading... | |
58 return false; | 92 return false; |
59 } | 93 } |
60 | 94 |
61 data->lut.resize(vcgt_channel_length); | 95 data->lut.resize(vcgt_channel_length); |
62 for (size_t i = 0; i < vcgt_channel_length; ++i) { | 96 for (size_t i = 0; i < vcgt_channel_length; ++i) { |
63 data->lut[i].r = vcgt_data[i]; | 97 data->lut[i].r = vcgt_data[i]; |
64 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; | 98 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; |
65 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; | 99 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; |
66 } | 100 } |
67 qcms_profile_release(display_profile); | 101 qcms_profile_release(display_profile); |
102 VLOG(1) << "Gamma data successfully read from icc file"; | |
68 return true; | 103 return true; |
69 } | 104 } |
70 | 105 |
71 base::FilePath PathForDisplaySnapshot(const ui::DisplaySnapshot* snapshot) { | |
72 base::FilePath path; | |
73 CHECK( | |
74 PathService::Get(chromeos::DIR_DEVICE_COLOR_CALIBRATION_PROFILES, &path)); | |
75 path = path.Append( | |
76 base::StringPrintf("%08" PRIx64 ".icc", snapshot->product_id())); | |
77 return path; | |
78 } | |
79 | |
80 } // namespace | 106 } // namespace |
81 | 107 |
82 DisplayColorManager::DisplayColorManager( | 108 DisplayColorManager::DisplayColorManager( |
83 ui::DisplayConfigurator* configurator, | 109 ui::DisplayConfigurator* configurator, |
84 base::SequencedWorkerPool* blocking_pool) | 110 base::SequencedWorkerPool* blocking_pool) |
85 : configurator_(configurator), blocking_pool_(blocking_pool) { | 111 : configurator_(configurator), blocking_pool_(blocking_pool) { |
86 configurator_->AddObserver(this); | 112 configurator_->AddObserver(this); |
87 } | 113 } |
88 | 114 |
89 DisplayColorManager::~DisplayColorManager() { | 115 DisplayColorManager::~DisplayColorManager() { |
(...skipping 22 matching lines...) Expand all Loading... | |
112 } | 138 } |
113 } | 139 } |
114 | 140 |
115 void DisplayColorManager::LoadCalibrationForDisplay( | 141 void DisplayColorManager::LoadCalibrationForDisplay( |
116 const ui::DisplaySnapshot* display) { | 142 const ui::DisplaySnapshot* display) { |
117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { | 143 if (display->display_id() == gfx::Display::kInvalidDisplayID) { |
118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; | 144 LOG(WARNING) << "Trying to load calibration data for invalid display id"; |
119 return; | 145 return; |
120 } | 146 } |
121 | 147 |
122 base::FilePath path = PathForDisplaySnapshot(display); | |
123 VLOG(1) << "Loading ICC file " << path.value() | |
124 << " for display id: " << display->display_id() | |
125 << " with product id: " << display->product_id(); | |
126 | |
127 scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); | 148 scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); |
128 base::Callback<bool(void)> request( | 149 base::Callback<bool(void)> request( |
129 base::Bind(&ParseFile, path, base::Unretained(data.get()))); | 150 base::Bind(&ParseDisplayProfile, display->display_id(), |
151 display->product_id(), base::Unretained(data.get()))); | |
130 base::PostTaskAndReplyWithResult( | 152 base::PostTaskAndReplyWithResult( |
131 blocking_pool_, FROM_HERE, request, | 153 blocking_pool_, FROM_HERE, request, |
stevenjb
2016/01/12 19:48:34
I don't understand how this was ever correct. This
| |
132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), | 154 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), |
133 display->display_id(), display->product_id(), | 155 display->display_id(), display->product_id(), |
134 base::Passed(std::move(data)))); | 156 base::Passed(std::move(data)))); |
135 } | 157 } |
136 | 158 |
159 // TODO!!! Remove! | |
160 // Temporary debugging function for ChromeOS on Linux. Provides an entry point | |
161 // into ParseDisplayProfile() from the same thread / earlier up the stack from | |
162 // it's actual calling location (which isn't hit due to lack of display device) | |
163 void DisplayColorManager::LoadCalibrationForDisplayQuirksTest() { | |
164 FakeDisplaySnapshot fake_snapshot(0x06af5c10); | |
165 LoadCalibrationForDisplay(&fake_snapshot); | |
166 } | |
167 | |
137 void DisplayColorManager::UpdateCalibrationData( | 168 void DisplayColorManager::UpdateCalibrationData( |
138 int64_t display_id, | 169 int64_t display_id, |
139 int64_t product_id, | 170 int64_t product_id, |
140 scoped_ptr<ColorCalibrationData> data, | 171 scoped_ptr<ColorCalibrationData> data, |
141 bool success) { | 172 bool success) { |
142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 173 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
143 if (success) { | 174 if (success) { |
144 // The map takes over ownership of the underlying memory. | 175 // The map takes over ownership of the underlying memory. |
145 calibration_map_[product_id] = data.release(); | 176 calibration_map_[product_id] = data.release(); |
146 ApplyDisplayColorCalibration(display_id, product_id); | 177 ApplyDisplayColorCalibration(display_id, product_id); |
147 } | 178 } |
148 } | 179 } |
149 | 180 |
150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} | 181 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} |
151 | 182 |
152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} | 183 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} |
153 | 184 |
154 } // namespace ash | 185 } // namespace ash |
OLD | NEW |