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" | |
11 #include "base/command_line.h" | |
12 #include "base/files/file_path.h" | |
13 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
14 #include "base/format_macros.h" | |
15 #include "base/logging.h" | 11 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | |
18 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
19 #include "base/strings/stringprintf.h" | |
20 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
22 #include "chromeos/chromeos_paths.h" | 16 #include "components/quirks/quirks_manager.h" |
23 #include "third_party/qcms/src/qcms.h" | 17 #include "third_party/qcms/src/qcms.h" |
24 #include "ui/display/types/display_snapshot.h" | 18 #include "ui/display/types/display_snapshot.h" |
25 #include "ui/display/types/gamma_ramp_rgb_entry.h" | 19 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
26 #include "ui/display/types/native_display_delegate.h" | |
27 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
28 #include "ui/gfx/screen.h" | |
29 | 21 |
30 namespace ash { | 22 namespace ash { |
31 | 23 |
32 namespace { | 24 namespace { |
33 | 25 |
34 bool ParseFile(const base::FilePath& path, | 26 scoped_ptr<DisplayColorManager::ColorCalibrationData> ParseDisplayProfile( |
35 DisplayColorManager::ColorCalibrationData* data) { | 27 const base::FilePath& path) { |
36 if (!base::PathExists(path)) // No icc file for this display; not an error. | |
37 return false; | |
38 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | 28 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); |
39 | |
40 if (!display_profile) { | 29 if (!display_profile) { |
41 LOG(WARNING) << "Unable to load ICC file: " << path.value(); | 30 LOG(WARNING) << "Unable to load ICC file: " << path.value(); |
42 return false; | 31 return nullptr; |
43 } | 32 } |
44 | 33 |
45 size_t vcgt_channel_length = | 34 size_t vcgt_channel_length = |
46 qcms_profile_get_vcgt_channel_length(display_profile); | 35 qcms_profile_get_vcgt_channel_length(display_profile); |
47 if (!vcgt_channel_length) { | 36 if (!vcgt_channel_length) { |
48 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); | 37 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); |
49 qcms_profile_release(display_profile); | 38 qcms_profile_release(display_profile); |
50 return false; | 39 return nullptr; |
51 } | 40 } |
52 | 41 |
53 std::vector<uint16_t> vcgt_data; | 42 std::vector<uint16_t> vcgt_data; |
54 vcgt_data.resize(vcgt_channel_length * 3); | 43 vcgt_data.resize(vcgt_channel_length * 3); |
55 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { | 44 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { |
56 LOG(WARNING) << "Unable to get vcgt data"; | 45 LOG(WARNING) << "Unable to get vcgt data"; |
57 qcms_profile_release(display_profile); | 46 qcms_profile_release(display_profile); |
58 return false; | 47 return nullptr; |
59 } | 48 } |
60 | 49 |
50 scoped_ptr<DisplayColorManager::ColorCalibrationData> data( | |
51 new DisplayColorManager::ColorCalibrationData()); | |
61 data->lut.resize(vcgt_channel_length); | 52 data->lut.resize(vcgt_channel_length); |
62 for (size_t i = 0; i < vcgt_channel_length; ++i) { | 53 for (size_t i = 0; i < vcgt_channel_length; ++i) { |
63 data->lut[i].r = vcgt_data[i]; | 54 data->lut[i].r = vcgt_data[i]; |
64 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; | 55 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; |
65 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; | 56 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; |
66 } | 57 } |
67 qcms_profile_release(display_profile); | 58 qcms_profile_release(display_profile); |
68 return true; | 59 VLOG(1) << "Gamma data successfully read from icc file"; |
69 } | 60 return data; |
70 | |
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 } | 61 } |
79 | 62 |
80 } // namespace | 63 } // namespace |
81 | 64 |
82 DisplayColorManager::DisplayColorManager( | 65 DisplayColorManager::DisplayColorManager( |
83 ui::DisplayConfigurator* configurator, | 66 ui::DisplayConfigurator* configurator, |
84 base::SequencedWorkerPool* blocking_pool) | 67 base::SequencedWorkerPool* blocking_pool) |
85 : configurator_(configurator), blocking_pool_(blocking_pool) { | 68 : configurator_(configurator), |
69 blocking_pool_(blocking_pool), | |
70 weak_ptr_factory_(this) { | |
86 configurator_->AddObserver(this); | 71 configurator_->AddObserver(this); |
87 } | 72 } |
88 | 73 |
89 DisplayColorManager::~DisplayColorManager() { | 74 DisplayColorManager::~DisplayColorManager() { |
90 configurator_->RemoveObserver(this); | 75 configurator_->RemoveObserver(this); |
91 STLDeleteValues(&calibration_map_); | 76 STLDeleteValues(&calibration_map_); |
92 } | 77 } |
93 | 78 |
94 void DisplayColorManager::OnDisplayModeChanged( | 79 void DisplayColorManager::OnDisplayModeChanged( |
95 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 80 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
(...skipping 11 matching lines...) Expand all Loading... | |
107 int64_t product_id) { | 92 int64_t product_id) { |
108 if (calibration_map_.find(product_id) != calibration_map_.end()) { | 93 if (calibration_map_.find(product_id) != calibration_map_.end()) { |
109 ColorCalibrationData* ramp = calibration_map_[product_id]; | 94 ColorCalibrationData* ramp = calibration_map_[product_id]; |
110 if (!configurator_->SetGammaRamp(display_id, ramp->lut)) | 95 if (!configurator_->SetGammaRamp(display_id, ramp->lut)) |
111 LOG(WARNING) << "Error applying gamma ramp"; | 96 LOG(WARNING) << "Error applying gamma ramp"; |
112 } | 97 } |
113 } | 98 } |
114 | 99 |
115 void DisplayColorManager::LoadCalibrationForDisplay( | 100 void DisplayColorManager::LoadCalibrationForDisplay( |
116 const ui::DisplaySnapshot* display) { | 101 const ui::DisplaySnapshot* display) { |
102 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | |
Bernhard Bauer
2016/03/22 09:58:05
Nit: Put the expected value first, for nicer error
Greg Levin
2016/03/22 17:49:29
Done, but...
Is this the right check to be doing h
Bernhard Bauer
2016/03/22 18:46:34
Hm... I would probably require that this class is
stevenjb
2016/03/22 21:29:49
Yeah, I think that is probably not the best test.
Greg Levin
2016/03/23 00:16:17
Done.
| |
117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { | 103 if (display->display_id() == gfx::Display::kInvalidDisplayID) { |
118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; | 104 LOG(WARNING) << "Trying to load calibration data for invalid display id"; |
119 return; | 105 return; |
120 } | 106 } |
121 | 107 |
122 base::FilePath path = PathForDisplaySnapshot(display); | 108 quirks::QuirksManager::Get()->RequestIccProfilePath( |
109 display->product_id(), | |
110 base::Bind(&DisplayColorManager::FinishLoadCalibrationForDisplay, | |
111 weak_ptr_factory_.GetWeakPtr(), display->display_id(), | |
112 display->product_id())); | |
113 } | |
114 | |
115 void DisplayColorManager::FinishLoadCalibrationForDisplay( | |
116 int64_t display_id, | |
117 int64_t product_id, | |
118 const base::FilePath& path, | |
119 bool file_downloaded) { | |
120 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | |
121 std::string product_string = quirks::IdToHexString(product_id); | |
122 if (path.empty()) { | |
123 VLOG(1) << "No icc file found with product id: " << product_string | |
124 << " for display id: " << display_id; | |
125 return; | |
126 } | |
127 | |
123 VLOG(1) << "Loading ICC file " << path.value() | 128 VLOG(1) << "Loading ICC file " << path.value() |
124 << " for display id: " << display->display_id() | 129 << " for display id: " << display_id |
125 << " with product id: " << display->product_id(); | 130 << " with product id: " << product_string; |
126 | 131 |
127 scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); | |
128 base::Callback<bool(void)> request( | |
129 base::Bind(&ParseFile, path, base::Unretained(data.get()))); | |
130 base::PostTaskAndReplyWithResult( | 132 base::PostTaskAndReplyWithResult( |
131 blocking_pool_, FROM_HERE, request, | 133 blocking_pool_, FROM_HERE, base::Bind(&ParseDisplayProfile, path), |
132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), | 134 base::Bind(&DisplayColorManager::UpdateCalibrationData, |
133 display->display_id(), display->product_id(), | 135 weak_ptr_factory_.GetWeakPtr(), display_id, product_id)); |
134 base::Passed(std::move(data)))); | |
135 } | 136 } |
136 | 137 |
137 void DisplayColorManager::UpdateCalibrationData( | 138 void DisplayColorManager::UpdateCalibrationData( |
138 int64_t display_id, | 139 int64_t display_id, |
139 int64_t product_id, | 140 int64_t product_id, |
140 scoped_ptr<ColorCalibrationData> data, | 141 scoped_ptr<ColorCalibrationData> data) { |
141 bool success) { | |
142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
143 if (success) { | 143 if (data) { |
144 // The map takes over ownership of the underlying memory. | 144 // The map takes over ownership of the underlying memory. |
145 calibration_map_[product_id] = data.release(); | 145 calibration_map_[product_id] = data.release(); |
146 ApplyDisplayColorCalibration(display_id, product_id); | 146 ApplyDisplayColorCalibration(display_id, product_id); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} | 150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} |
151 | 151 |
152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} | 152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} |
153 | 153 |
154 } // namespace ash | 154 } // namespace ash |
OLD | NEW |