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

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: Minor review fixes, delay download until after login 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), blocking_pool_(blocking_pool) {
86 configurator_->AddObserver(this); 69 configurator_->AddObserver(this);
87 } 70 }
(...skipping 24 matching lines...) Expand all
112 } 95 }
113 } 96 }
114 97
115 void DisplayColorManager::LoadCalibrationForDisplay( 98 void DisplayColorManager::LoadCalibrationForDisplay(
116 const ui::DisplaySnapshot* display) { 99 const ui::DisplaySnapshot* display) {
117 if (display->display_id() == gfx::Display::kInvalidDisplayID) { 100 if (display->display_id() == gfx::Display::kInvalidDisplayID) {
118 LOG(WARNING) << "Trying to load calibration data for invalid display id"; 101 LOG(WARNING) << "Trying to load calibration data for invalid display id";
119 return; 102 return;
120 } 103 }
121 104
122 base::FilePath path = PathForDisplaySnapshot(display); 105 quirks::RequestIccProfilePath(
106 display->product_id(),
107 base::Bind(&DisplayColorManager::FinishLoadCalibrationForDisplay,
108 AsWeakPtr(), display->display_id(), display->product_id()));
109 }
110
111 void DisplayColorManager::FinishLoadCalibrationForDisplay(
112 int64_t display_id,
113 int64_t product_id,
114 const base::FilePath& path,
115 bool file_downloaded) {
116 std::string product_string = quirks::IdToHexString(product_id);
117 if (path.empty()) {
118 VLOG(1) << "No icc file found with product id: " << product_string
119 << " for display id: " << display_id;
120 return;
121 }
122
123 VLOG(1) << "Loading ICC file " << path.value() 123 VLOG(1) << "Loading ICC file " << path.value()
124 << " for display id: " << display->display_id() 124 << " for display id: " << display_id
125 << " with product id: " << display->product_id(); 125 << " with product id: " << product_string;
126 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( 127 base::PostTaskAndReplyWithResult(
131 blocking_pool_, FROM_HERE, request, 128 blocking_pool_, FROM_HERE, base::Bind(&ParseDisplayProfile, path),
132 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), 129 base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(),
133 display->display_id(), display->product_id(), 130 display_id, product_id));
134 base::Passed(std::move(data))));
135 } 131 }
136 132
137 void DisplayColorManager::UpdateCalibrationData( 133 void DisplayColorManager::UpdateCalibrationData(
138 int64_t display_id, 134 int64_t display_id,
139 int64_t product_id, 135 int64_t product_id,
140 scoped_ptr<ColorCalibrationData> data, 136 scoped_ptr<ColorCalibrationData> data) {
141 bool success) {
142 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); 137 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI);
143 if (success) { 138 if (data) {
144 // The map takes over ownership of the underlying memory. 139 // The map takes over ownership of the underlying memory.
145 calibration_map_[product_id] = data.release(); 140 calibration_map_[product_id] = data.release();
146 ApplyDisplayColorCalibration(display_id, product_id); 141 ApplyDisplayColorCalibration(display_id, product_id);
147 } 142 }
148 } 143 }
149 144
150 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {} 145 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {}
151 146
152 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {} 147 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {}
153 148
154 } // namespace ash 149 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698