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

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: Small DCHECK tweak, delay downloaded icc's on internal display Created 4 years, 9 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" 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
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::TYPE_UI, base::MessageLoop::current()->type());
oshima 2016/03/22 20:27:21 This may not be UI message loop in mustash. If y
stevenjb 2016/03/22 21:29:49 +1. ThreadChecker (like you are using in QuirksMan
Greg Levin 2016/03/23 00:16:18 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(), display->type()));
113 }
114
115 void DisplayColorManager::FinishLoadCalibrationForDisplay(
116 int64_t display_id,
117 int64_t product_id,
118 ui::DisplayConnectionType type,
119 const base::FilePath& path,
120 bool file_downloaded) {
121 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
122 std::string product_string = quirks::IdToHexString(product_id);
123 if (path.empty()) {
124 VLOG(1) << "No ICC file found with product id: " << product_string
125 << " for display id: " << display_id;
126 return;
127 }
128
129 if (file_downloaded && type == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) {
130 VLOG(1) << "Downloaded ICC file with product id: " << product_string
131 << " for internal display id: " << display_id
132 << ". Profile will be applied on next startup.";
133 return;
134 }
135
123 VLOG(1) << "Loading ICC file " << path.value() 136 VLOG(1) << "Loading ICC file " << path.value()
124 << " for display id: " << display->display_id() 137 << " for display id: " << display_id
125 << " with product id: " << display->product_id(); 138 << " with product id: " << product_string;
126 139
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( 140 base::PostTaskAndReplyWithResult(
131 blocking_pool_, FROM_HERE, request, 141 blocking_pool_, FROM_HERE, base::Bind(&ParseDisplayProfile, path),
132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), 142 base::Bind(&DisplayColorManager::UpdateCalibrationData,
133 display->display_id(), display->product_id(), 143 weak_ptr_factory_.GetWeakPtr(), display_id, product_id));
134 base::Passed(std::move(data))));
135 } 144 }
136 145
137 void DisplayColorManager::UpdateCalibrationData( 146 void DisplayColorManager::UpdateCalibrationData(
138 int64_t display_id, 147 int64_t display_id,
139 int64_t product_id, 148 int64_t product_id,
140 scoped_ptr<ColorCalibrationData> data, 149 scoped_ptr<ColorCalibrationData> data) {
141 bool success) { 150 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); 151 if (data) {
143 if (success) {
144 // The map takes over ownership of the underlying memory. 152 // The map takes over ownership of the underlying memory.
145 calibration_map_[product_id] = data.release(); 153 calibration_map_[product_id] = data.release();
146 ApplyDisplayColorCalibration(display_id, product_id); 154 ApplyDisplayColorCalibration(display_id, product_id);
147 } 155 }
148 } 156 }
149 157
150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} 158 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {}
151 159
152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} 160 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {}
153 161
154 } // namespace ash 162 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698