| 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" | |
| 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" | 9 #include "base/files/file_util.h" |
| 14 #include "base/format_macros.h" | |
| 15 #include "base/logging.h" | |
| 16 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 17 #include "base/path_service.h" | |
| 18 #include "base/stl_util.h" | |
| 19 #include "base/strings/stringprintf.h" | |
| 20 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 12 #include "components/quirks_client/quirks_client.h" |
| 22 #include "chromeos/chromeos_paths.h" | |
| 23 #include "third_party/qcms/src/qcms.h" | 13 #include "third_party/qcms/src/qcms.h" |
| 24 #include "ui/display/types/display_snapshot.h" | |
| 25 #include "ui/display/types/gamma_ramp_rgb_entry.h" | 14 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
| 26 #include "ui/display/types/native_display_delegate.h" | |
| 27 #include "ui/gfx/display.h" | |
| 28 #include "ui/gfx/screen.h" | |
| 29 | 15 |
| 30 namespace ash { | 16 namespace ash { |
| 31 | 17 |
| 32 namespace { | 18 namespace { |
| 33 | 19 |
| 34 bool ParseFile(const base::FilePath& path, | 20 void DoNothing(base::FilePath) {} |
| 35 DisplayColorManager::ColorCalibrationData* data) { | 21 |
| 36 if (!base::PathExists(path)) // No icc file for this display; not an error. | 22 scoped_ptr<DisplayColorManager::ColorCalibrationData> ParseDisplayProfile( |
| 37 return false; | 23 const int64_t display_id, |
| 24 const int64_t product_id) { |
| 25 // TODO(glevin): At some point, we may want to add a callback, and apply the |
| 26 // icc file as soon as it's downloaded. For now, we'll only apply it if it |
| 27 // exists at startup, and try to download it for next time if it doesn't. |
| 28 base::FilePath path = quirks_client::QuirksClient::RequestIccProfilePath( |
| 29 product_id, base::Bind(DoNothing)); |
| 30 std::string product_string = |
| 31 quirks_client::QuirksClient::IdToHexString(product_id); |
| 32 if (path.empty()) { |
| 33 VLOG(1) << "No icc file found with product id: " << product_string |
| 34 << " for display id: " << display_id; |
| 35 return nullptr; |
| 36 } |
| 37 |
| 38 VLOG(1) << "Loading ICC file " << path.value() |
| 39 << " for display id: " << display_id |
| 40 << " with product id: " << product_string; |
| 41 |
| 42 DCHECK(base::PathExists(path)); // Quirks Client should ensure this. |
| 38 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | 43 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); |
| 39 | 44 |
| 40 if (!display_profile) { | 45 if (!display_profile) { |
| 41 LOG(WARNING) << "Unable to load ICC file: " << path.value(); | 46 LOG(WARNING) << "Unable to load ICC file: " << path.value(); |
| 42 return false; | 47 return nullptr; |
| 43 } | 48 } |
| 44 | 49 |
| 45 size_t vcgt_channel_length = | 50 size_t vcgt_channel_length = |
| 46 qcms_profile_get_vcgt_channel_length(display_profile); | 51 qcms_profile_get_vcgt_channel_length(display_profile); |
| 47 if (!vcgt_channel_length) { | 52 if (!vcgt_channel_length) { |
| 48 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); | 53 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); |
| 49 qcms_profile_release(display_profile); | 54 qcms_profile_release(display_profile); |
| 50 return false; | 55 return nullptr; |
| 51 } | 56 } |
| 52 | 57 |
| 53 std::vector<uint16_t> vcgt_data; | 58 std::vector<uint16_t> vcgt_data; |
| 54 vcgt_data.resize(vcgt_channel_length * 3); | 59 vcgt_data.resize(vcgt_channel_length * 3); |
| 55 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { | 60 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { |
| 56 LOG(WARNING) << "Unable to get vcgt data"; | 61 LOG(WARNING) << "Unable to get vcgt data"; |
| 57 qcms_profile_release(display_profile); | 62 qcms_profile_release(display_profile); |
| 58 return false; | 63 return nullptr; |
| 59 } | 64 } |
| 60 | 65 |
| 66 scoped_ptr<DisplayColorManager::ColorCalibrationData> data( |
| 67 new DisplayColorManager::ColorCalibrationData()); |
| 61 data->lut.resize(vcgt_channel_length); | 68 data->lut.resize(vcgt_channel_length); |
| 62 for (size_t i = 0; i < vcgt_channel_length; ++i) { | 69 for (size_t i = 0; i < vcgt_channel_length; ++i) { |
| 63 data->lut[i].r = vcgt_data[i]; | 70 data->lut[i].r = vcgt_data[i]; |
| 64 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; | 71 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; |
| 65 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; | 72 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; |
| 66 } | 73 } |
| 67 qcms_profile_release(display_profile); | 74 qcms_profile_release(display_profile); |
| 68 return true; | 75 VLOG(1) << "Gamma data successfully read from icc file"; |
| 69 } | 76 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 } | 77 } |
| 79 | 78 |
| 80 } // namespace | 79 } // namespace |
| 81 | 80 |
| 82 DisplayColorManager::DisplayColorManager( | 81 DisplayColorManager::DisplayColorManager( |
| 83 ui::DisplayConfigurator* configurator, | 82 ui::DisplayConfigurator* configurator, |
| 84 base::SequencedWorkerPool* blocking_pool) | 83 base::SequencedWorkerPool* blocking_pool) |
| 85 : configurator_(configurator), blocking_pool_(blocking_pool) { | 84 : configurator_(configurator), blocking_pool_(blocking_pool) { |
| 86 configurator_->AddObserver(this); | 85 configurator_->AddObserver(this); |
| 87 } | 86 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 void DisplayColorManager::LoadCalibrationForDisplay( | 114 void DisplayColorManager::LoadCalibrationForDisplay( |
| 116 const ui::DisplaySnapshot* display) { | 115 const ui::DisplaySnapshot* display) { |
| 117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { | 116 if (display->display_id() == gfx::Display::kInvalidDisplayID) { |
| 118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; | 117 LOG(WARNING) << "Trying to load calibration data for invalid display id"; |
| 119 return; | 118 return; |
| 120 } | 119 } |
| 121 | 120 |
| 122 base::FilePath path = PathForDisplaySnapshot(display); | 121 base::Callback<scoped_ptr<DisplayColorManager::ColorCalibrationData>(void)> |
| 123 VLOG(1) << "Loading ICC file " << path.value() | 122 request(base::Bind(&ParseDisplayProfile, display->display_id(), |
| 124 << " for display id: " << display->display_id() | 123 display->product_id())); |
| 125 << " with product id: " << display->product_id(); | |
| 126 | |
| 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( | 124 base::PostTaskAndReplyWithResult( |
| 131 blocking_pool_, FROM_HERE, request, | 125 blocking_pool_, FROM_HERE, request, |
| 132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), | 126 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), |
| 133 display->display_id(), display->product_id(), | 127 display->display_id(), display->product_id())); |
| 134 base::Passed(std::move(data)))); | |
| 135 } | 128 } |
| 136 | 129 |
| 137 void DisplayColorManager::UpdateCalibrationData( | 130 void DisplayColorManager::UpdateCalibrationData( |
| 138 int64_t display_id, | 131 int64_t display_id, |
| 139 int64_t product_id, | 132 int64_t product_id, |
| 140 scoped_ptr<ColorCalibrationData> data, | 133 scoped_ptr<DisplayColorManager::ColorCalibrationData> data) { |
| 141 bool success) { | |
| 142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 134 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
| 143 if (success) { | 135 if (data) { |
| 144 // The map takes over ownership of the underlying memory. | 136 // The map takes over ownership of the underlying memory. |
| 145 calibration_map_[product_id] = data.release(); | 137 calibration_map_[product_id] = data.release(); |
| 146 ApplyDisplayColorCalibration(display_id, product_id); | 138 ApplyDisplayColorCalibration(display_id, product_id); |
| 147 } | 139 } |
| 148 } | 140 } |
| 149 | 141 |
| 150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} | 142 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} |
| 151 | 143 |
| 152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} | 144 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} |
| 153 | 145 |
| 154 } // namespace ash | 146 } // namespace ash |
| OLD | NEW |