Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(682)

Side by Side Diff: ash/display/display_color_manager_chromeos.cc

Issue 1528963002: Quirks Client for downloading and providing display profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sixth round of review fixes, sorting out thread issues Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/quirks_manager.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(const 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 =
29 quirks::RequestIccProfilePath(product_id, base::Bind(DoNothing));
30 std::string product_string = quirks::IdToHexString(product_id);
31 if (path.empty()) {
32 VLOG(1) << "No icc file found with product id: " << product_string
33 << " for display id: " << display_id;
34 return nullptr;
35 }
36
37 VLOG(1) << "Loading ICC file " << path.value()
38 << " for display id: " << display_id
39 << " with product id: " << product_string;
40
38 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); 41 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str());
39 42
40 if (!display_profile) { 43 if (!display_profile) {
41 LOG(WARNING) << "Unable to load ICC file: " << path.value(); 44 LOG(WARNING) << "Unable to load ICC file: " << path.value();
42 return false; 45 return nullptr;
43 } 46 }
44 47
45 size_t vcgt_channel_length = 48 size_t vcgt_channel_length =
46 qcms_profile_get_vcgt_channel_length(display_profile); 49 qcms_profile_get_vcgt_channel_length(display_profile);
47 if (!vcgt_channel_length) { 50 if (!vcgt_channel_length) {
48 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); 51 LOG(WARNING) << "No vcgt table in ICC file: " << path.value();
49 qcms_profile_release(display_profile); 52 qcms_profile_release(display_profile);
50 return false; 53 return nullptr;
51 } 54 }
52 55
53 std::vector<uint16_t> vcgt_data; 56 std::vector<uint16_t> vcgt_data;
54 vcgt_data.resize(vcgt_channel_length * 3); 57 vcgt_data.resize(vcgt_channel_length * 3);
55 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { 58 if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) {
56 LOG(WARNING) << "Unable to get vcgt data"; 59 LOG(WARNING) << "Unable to get vcgt data";
57 qcms_profile_release(display_profile); 60 qcms_profile_release(display_profile);
58 return false; 61 return nullptr;
59 } 62 }
60 63
64 scoped_ptr<DisplayColorManager::ColorCalibrationData> data(
65 new DisplayColorManager::ColorCalibrationData());
61 data->lut.resize(vcgt_channel_length); 66 data->lut.resize(vcgt_channel_length);
62 for (size_t i = 0; i < vcgt_channel_length; ++i) { 67 for (size_t i = 0; i < vcgt_channel_length; ++i) {
63 data->lut[i].r = vcgt_data[i]; 68 data->lut[i].r = vcgt_data[i];
64 data->lut[i].g = vcgt_data[vcgt_channel_length + i]; 69 data->lut[i].g = vcgt_data[vcgt_channel_length + i];
65 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; 70 data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i];
66 } 71 }
67 qcms_profile_release(display_profile); 72 qcms_profile_release(display_profile);
68 return true; 73 VLOG(1) << "Gamma data successfully read from icc file";
69 } 74 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 } 75 }
79 76
80 } // namespace 77 } // namespace
81 78
82 DisplayColorManager::DisplayColorManager( 79 DisplayColorManager::DisplayColorManager(
83 ui::DisplayConfigurator* configurator, 80 ui::DisplayConfigurator* configurator,
84 base::SequencedWorkerPool* blocking_pool) 81 base::SequencedWorkerPool* blocking_pool)
85 : configurator_(configurator), blocking_pool_(blocking_pool) { 82 : configurator_(configurator), blocking_pool_(blocking_pool) {
86 configurator_->AddObserver(this); 83 configurator_->AddObserver(this);
87 } 84 }
(...skipping 24 matching lines...) Expand all
112 } 109 }
113 } 110 }
114 111
115 void DisplayColorManager::LoadCalibrationForDisplay( 112 void DisplayColorManager::LoadCalibrationForDisplay(
116 const ui::DisplaySnapshot* display) { 113 const ui::DisplaySnapshot* display) {
117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { 114 if (display->display_id() == gfx::Display::kInvalidDisplayID) {
118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; 115 LOG(WARNING) << "Trying to load calibration data for invalid display id";
119 return; 116 return;
120 } 117 }
121 118
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());
128 base::Callback<bool(void)> request(
129 base::Bind(&ParseFile, path, base::Unretained(data.get())));
130 base::PostTaskAndReplyWithResult( 119 base::PostTaskAndReplyWithResult(
131 blocking_pool_, FROM_HERE, request, 120 blocking_pool_, FROM_HERE,
121 base::Bind(&ParseDisplayProfile, display->display_id(),
122 display->product_id()),
132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), 123 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(),
133 display->display_id(), display->product_id(), 124 display->display_id(), display->product_id()));
134 base::Passed(std::move(data))));
135 } 125 }
136 126
137 void DisplayColorManager::UpdateCalibrationData( 127 void DisplayColorManager::UpdateCalibrationData(
138 int64_t display_id, 128 int64_t display_id,
139 int64_t product_id, 129 int64_t product_id,
140 scoped_ptr<ColorCalibrationData> data, 130 scoped_ptr<ColorCalibrationData> data) {
141 bool success) {
142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); 131 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI);
143 if (success) { 132 if (data) {
144 // The map takes over ownership of the underlying memory. 133 // The map takes over ownership of the underlying memory.
145 calibration_map_[product_id] = data.release(); 134 calibration_map_[product_id] = data.release();
146 ApplyDisplayColorCalibration(display_id, product_id); 135 ApplyDisplayColorCalibration(display_id, product_id);
147 } 136 }
148 } 137 }
149 138
150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} 139 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {}
151 140
152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} 141 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {}
153 142
154 } // namespace ash 143 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698