| 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 bool ParseDisplayProfile(const int64_t display_id, |
| 35 DisplayColorManager::ColorCalibrationData* data) { | 35 const int64_t product_id, |
| 36 DisplayColorManager::ColorCalibrationData* data) { |
| 37 quirks_client::QuirksClient::DownloadFinishedCallback* callback = nullptr; |
| 38 // TODO(glevin): Do we want to add a callback so that we can apply the icc |
| 39 // profile as soon as it's downloaded? |
| 40 base::FilePath path = |
| 41 quirks_client::QuirksClient::RequestIccProfilePath(product_id, callback); |
| 42 std::string product_string = base::StringPrintf("0x%08" PRIx64, product_id); |
| 43 if (path.empty()) { |
| 44 VLOG(1) << "No icc file found with product id: " << product_string |
| 45 << " for display id: " << display_id; |
| 46 } else { |
| 47 VLOG(1) << "Loading ICC file " << path.value() |
| 48 << " for display id: " << display_id |
| 49 << " with product id: " << product_string; |
| 50 } |
| 51 |
| 36 if (!base::PathExists(path)) // No icc file for this display; not an error. | 52 if (!base::PathExists(path)) // No icc file for this display; not an error. |
| 37 return false; | 53 return false; |
| 38 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | 54 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); |
| 39 | 55 |
| 40 if (!display_profile) { | 56 if (!display_profile) { |
| 41 LOG(WARNING) << "Unable to load ICC file: " << path.value(); | 57 LOG(WARNING) << "Unable to load ICC file: " << path.value(); |
| 42 return false; | 58 return false; |
| 43 } | 59 } |
| 44 | 60 |
| 45 size_t vcgt_channel_length = | 61 size_t vcgt_channel_length = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 return false; | 74 return false; |
| 59 } | 75 } |
| 60 | 76 |
| 61 data->lut.resize(vcgt_channel_length); | 77 data->lut.resize(vcgt_channel_length); |
| 62 for (size_t i = 0; i < vcgt_channel_length; ++i) { | 78 for (size_t i = 0; i < vcgt_channel_length; ++i) { |
| 63 data->lut[i].r = vcgt_data[i]; | 79 data->lut[i].r = vcgt_data[i]; |
| 64 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; | 80 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; |
| 65 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; | 81 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; |
| 66 } | 82 } |
| 67 qcms_profile_release(display_profile); | 83 qcms_profile_release(display_profile); |
| 84 VLOG(1) << "Gamma data successfully read from icc file"; |
| 68 return true; | 85 return true; |
| 69 } | 86 } |
| 70 | 87 |
| 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 | 88 } // namespace |
| 81 | 89 |
| 82 DisplayColorManager::DisplayColorManager( | 90 DisplayColorManager::DisplayColorManager( |
| 83 ui::DisplayConfigurator* configurator, | 91 ui::DisplayConfigurator* configurator, |
| 84 base::SequencedWorkerPool* blocking_pool) | 92 base::SequencedWorkerPool* blocking_pool) |
| 85 : configurator_(configurator), blocking_pool_(blocking_pool) { | 93 : configurator_(configurator), blocking_pool_(blocking_pool) { |
| 86 configurator_->AddObserver(this); | 94 configurator_->AddObserver(this); |
| 87 } | 95 } |
| 88 | 96 |
| 89 DisplayColorManager::~DisplayColorManager() { | 97 DisplayColorManager::~DisplayColorManager() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 } | 120 } |
| 113 } | 121 } |
| 114 | 122 |
| 115 void DisplayColorManager::LoadCalibrationForDisplay( | 123 void DisplayColorManager::LoadCalibrationForDisplay( |
| 116 const ui::DisplaySnapshot* display) { | 124 const ui::DisplaySnapshot* display) { |
| 117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { | 125 if (display->display_id() == gfx::Display::kInvalidDisplayID) { |
| 118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; | 126 LOG(WARNING) << "Trying to load calibration data for invalid display id"; |
| 119 return; | 127 return; |
| 120 } | 128 } |
| 121 | 129 |
| 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()); | 130 scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); |
| 128 base::Callback<bool(void)> request( | 131 base::Callback<bool(void)> request( |
| 129 base::Bind(&ParseFile, path, base::Unretained(data.get()))); | 132 base::Bind(&ParseDisplayProfile, display->display_id(), |
| 133 display->product_id(), base::Unretained(data.get()))); |
| 130 base::PostTaskAndReplyWithResult( | 134 base::PostTaskAndReplyWithResult( |
| 131 blocking_pool_, FROM_HERE, request, | 135 blocking_pool_, FROM_HERE, request, |
| 132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), | 136 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), |
| 133 display->display_id(), display->product_id(), | 137 display->display_id(), display->product_id(), |
| 134 base::Passed(std::move(data)))); | 138 base::Passed(std::move(data)))); |
| 135 } | 139 } |
| 136 | 140 |
| 137 void DisplayColorManager::UpdateCalibrationData( | 141 void DisplayColorManager::UpdateCalibrationData( |
| 138 int64_t display_id, | 142 int64_t display_id, |
| 139 int64_t product_id, | 143 int64_t product_id, |
| 140 scoped_ptr<ColorCalibrationData> data, | 144 scoped_ptr<ColorCalibrationData> data, |
| 141 bool success) { | 145 bool success) { |
| 142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 146 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
| 143 if (success) { | 147 if (success) { |
| 144 // The map takes over ownership of the underlying memory. | 148 // The map takes over ownership of the underlying memory. |
| 145 calibration_map_[product_id] = data.release(); | 149 calibration_map_[product_id] = data.release(); |
| 146 ApplyDisplayColorCalibration(display_id, product_id); | 150 ApplyDisplayColorCalibration(display_id, product_id); |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} | 154 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} |
| 151 | 155 |
| 152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} | 156 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} |
| 153 | 157 |
| 154 } // namespace ash | 158 } // namespace ash |
| OLD | NEW |