Chromium Code Reviews| Index: ash/display/display_color_manager_chromeos.cc |
| diff --git a/ash/display/display_color_manager_chromeos.cc b/ash/display/display_color_manager_chromeos.cc |
| index 1241978958018acff967d30fbfd9dcb2d0c961dd..bbf723e4fc1783ac81e517f4a194ded98b28ddec 100644 |
| --- a/ash/display/display_color_manager_chromeos.cc |
| +++ b/ash/display/display_color_manager_chromeos.cc |
| @@ -6,40 +6,44 @@ |
| #include <utility> |
| -#include "base/bind.h" |
| -#include "base/bind_helpers.h" |
| -#include "base/command_line.h" |
| -#include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| -#include "base/format_macros.h" |
| -#include "base/logging.h" |
| #include "base/message_loop/message_loop.h" |
| -#include "base/path_service.h" |
| -#include "base/stl_util.h" |
| -#include "base/strings/stringprintf.h" |
| #include "base/task_runner_util.h" |
| -#include "base/threading/sequenced_worker_pool.h" |
| -#include "chromeos/chromeos_paths.h" |
| +#include "components/quirks/quirks_manager.h" |
| #include "third_party/qcms/src/qcms.h" |
| -#include "ui/display/types/display_snapshot.h" |
| #include "ui/display/types/gamma_ramp_rgb_entry.h" |
| -#include "ui/display/types/native_display_delegate.h" |
| -#include "ui/gfx/display.h" |
| -#include "ui/gfx/screen.h" |
| namespace ash { |
| namespace { |
| -bool ParseFile(const base::FilePath& path, |
| - DisplayColorManager::ColorCalibrationData* data) { |
| - if (!base::PathExists(path)) // No icc file for this display; not an error. |
| - return false; |
| +void DoNothing(const base::FilePath&) {} |
| + |
| +scoped_ptr<DisplayColorManager::ColorCalibrationData> ParseDisplayProfile( |
| + const int64_t display_id, |
| + const int64_t product_id) { |
| + // TODO(glevin): At some point, we may want to add a callback, and apply the |
| + // icc file as soon as it's downloaded. For now, we'll only apply it if it |
| + // exists at startup, and try to download it for next time if it doesn't. |
| + base::FilePath path = |
| + quirks::RequestIccProfilePath(product_id, base::Bind(DoNothing)); |
| + std::string product_string = quirks::IdToHexString(product_id); |
| + if (path.empty()) { |
| + VLOG(1) << "No icc file found with product id: " << product_string |
| + << " for display id: " << display_id; |
| + return nullptr; |
| + } |
| + |
| + VLOG(1) << "Loading ICC file " << path.value() |
| + << " for display id: " << display_id |
| + << " with product id: " << product_string; |
| + |
| + DCHECK(base::PathExists(path)); // Quirks should ensure this. |
|
stevenjb
2016/02/16 20:07:51
Don't do file operations here.
Greg Levin
2016/02/17 23:01:50
Done. Why not?
stevenjb
2016/02/17 23:38:54
Then we have to guarantee that this runs on a bloc
Greg Levin
2016/03/02 00:00:26
Acknowledged.
|
| qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); |
| if (!display_profile) { |
| LOG(WARNING) << "Unable to load ICC file: " << path.value(); |
| - return false; |
| + return nullptr; |
| } |
| size_t vcgt_channel_length = |
| @@ -47,7 +51,7 @@ bool ParseFile(const base::FilePath& path, |
| if (!vcgt_channel_length) { |
| LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); |
| qcms_profile_release(display_profile); |
| - return false; |
| + return nullptr; |
| } |
| std::vector<uint16_t> vcgt_data; |
| @@ -55,9 +59,11 @@ bool ParseFile(const base::FilePath& path, |
| if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { |
| LOG(WARNING) << "Unable to get vcgt data"; |
| qcms_profile_release(display_profile); |
| - return false; |
| + return nullptr; |
| } |
| + scoped_ptr<DisplayColorManager::ColorCalibrationData> data( |
| + new DisplayColorManager::ColorCalibrationData()); |
| data->lut.resize(vcgt_channel_length); |
| for (size_t i = 0; i < vcgt_channel_length; ++i) { |
| data->lut[i].r = vcgt_data[i]; |
| @@ -65,16 +71,8 @@ bool ParseFile(const base::FilePath& path, |
| data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; |
| } |
| qcms_profile_release(display_profile); |
| - return true; |
| -} |
| - |
| -base::FilePath PathForDisplaySnapshot(const ui::DisplaySnapshot* snapshot) { |
| - base::FilePath path; |
| - CHECK( |
| - PathService::Get(chromeos::DIR_DEVICE_COLOR_CALIBRATION_PROFILES, &path)); |
| - path = path.Append( |
| - base::StringPrintf("%08" PRIx64 ".icc", snapshot->product_id())); |
| - return path; |
| + VLOG(1) << "Gamma data successfully read from icc file"; |
| + return data; |
| } |
| } // namespace |
| @@ -119,28 +117,20 @@ void DisplayColorManager::LoadCalibrationForDisplay( |
| return; |
| } |
| - base::FilePath path = PathForDisplaySnapshot(display); |
| - VLOG(1) << "Loading ICC file " << path.value() |
| - << " for display id: " << display->display_id() |
| - << " with product id: " << display->product_id(); |
| - |
| - scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); |
| - base::Callback<bool(void)> request( |
| - base::Bind(&ParseFile, path, base::Unretained(data.get()))); |
| base::PostTaskAndReplyWithResult( |
| - blocking_pool_, FROM_HERE, request, |
| + blocking_pool_, FROM_HERE, |
|
stevenjb
2016/02/16 20:07:51
We shouldn't be assuming that this blocking pool i
Greg Levin
2016/02/17 23:01:50
Still fuzzy on this issue... hopefully discussion
|
| + base::Bind(&ParseDisplayProfile, display->display_id(), |
| + display->product_id()), |
| base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), |
| - display->display_id(), display->product_id(), |
| - base::Passed(std::move(data)))); |
| + display->display_id(), display->product_id())); |
| } |
| void DisplayColorManager::UpdateCalibrationData( |
| int64_t display_id, |
| int64_t product_id, |
| - scoped_ptr<ColorCalibrationData> data, |
| - bool success) { |
| + scoped_ptr<ColorCalibrationData> data) { |
| DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
| - if (success) { |
| + if (data) { |
| // The map takes over ownership of the underlying memory. |
| calibration_map_[product_id] = data.release(); |
| ApplyDisplayColorCalibration(display_id, product_id); |