OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/display/display_color_manager_chromeos.h" | |
6 | |
7 #include "ash/display/display_info.h" | |
oshima
2015/04/15 23:56:13
do you need this?
robert.bradford
2015/04/17 16:42:45
Done.
| |
8 #include "base/bind.h" | |
9 #include "base/bind_helpers.h" | |
10 #include "base/command_line.h" | |
11 #include "base/files/file_path.h" | |
12 #include "base/logging.h" | |
13 #include "chromeos/chromeos_switches.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 #include "third_party/qcms/src/qcms.h" | |
16 #include "ui/display/types/display_snapshot.h" | |
17 #include "ui/gfx/display.h" | |
18 #include "ui/gfx/screen.h" | |
19 | |
20 using content::BrowserThread; | |
21 | |
22 namespace ash { | |
23 | |
24 namespace { | |
25 | |
26 DisplayColorManager::ColorCalibrationData* ParseFile( | |
27 const base::FilePath& path) { | |
28 qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | |
29 | |
30 if (!display_profile) { | |
31 LOG(WARNING) << "Unable to load ICC file: " << path.value(); | |
32 return nullptr; | |
33 } | |
34 | |
35 size_t vcgt_size = qcms_profile_vcgt_size(display_profile); | |
36 if (!vcgt_size) { | |
37 LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); | |
38 return nullptr; | |
39 } | |
40 | |
41 DisplayColorManager::ColorCalibrationData* data = | |
42 new DisplayColorManager::ColorCalibrationData(); | |
43 data->r.resize(vcgt_size); | |
44 data->g.resize(vcgt_size); | |
45 data->b.resize(vcgt_size); | |
46 if (!qcms_profile_vcgt_channels(display_profile, &data->r[0], &data->g[0], | |
47 &data->b[0])) { | |
48 LOG(WARNING) << "Unable to get vcgt data"; | |
49 delete data; | |
50 qcms_profile_release(display_profile); | |
51 return nullptr; | |
52 } | |
53 | |
54 qcms_profile_release(display_profile); | |
55 return data; | |
oshima
2015/04/15 23:56:13
how big the data is? If it's small, just using str
robert.bradford
2015/04/17 16:42:46
The data will be 3 * 256 * 2 bytes.
| |
56 } | |
57 | |
58 } // namespace | |
59 | |
60 DisplayColorManager::DisplayColorManager(ui::DisplayConfigurator* configurator) | |
61 : configurator_(configurator) { | |
62 configurator_->AddObserver(this); | |
63 LoadInternalFromCommandLine(); | |
64 } | |
65 | |
66 DisplayColorManager::~DisplayColorManager() { | |
67 configurator_->RemoveObserver(this); | |
68 | |
69 for (auto it : calibration_map_) { | |
70 delete it.second; | |
71 calibration_map_.erase(it.first); | |
72 } | |
73 } | |
74 | |
75 void DisplayColorManager::OnDisplayModeChanged( | |
76 const ui::DisplayConfigurator::DisplayStateList& display_states) { | |
77 for (const ui::DisplaySnapshot* state : display_states) { | |
78 ApplyDisplayColorCalibration(state->display_id()); | |
79 } | |
oshima
2015/04/15 23:56:13
nit: nuke {}
robert.bradford
2015/04/17 16:42:46
Done.
| |
80 } | |
81 | |
82 void DisplayColorManager::ApplyDisplayColorCalibration(uint64_t display_id) { | |
83 if (calibration_map_.find(display_id) != calibration_map_.end()) { | |
84 ColorCalibrationData* ramp = calibration_map_[display_id]; | |
85 if (!configurator_->SetGammaRamp(display_id, ramp->r, ramp->g, ramp->b)) { | |
86 LOG(WARNING) << "Error applying gamma ramp"; | |
87 } | |
oshima
2015/04/15 23:56:13
ditto
robert.bradford
2015/04/17 16:42:45
Done.
| |
88 } | |
89 } | |
90 | |
91 void DisplayColorManager::LoadInternalFromCommandLine() { | |
92 const base::CommandLine* command_line = | |
93 base::CommandLine::ForCurrentProcess(); | |
94 if (command_line->HasSwitch( | |
95 chromeos::switches::kInternalDisplayColorProfileFile)) { | |
96 const base::FilePath& path = command_line->GetSwitchValuePath( | |
97 chromeos::switches::kInternalDisplayColorProfileFile); | |
98 VLOG(1) << "Loading ICC file : " << path.value() | |
99 << "for internal display id: " << gfx::Display::InternalDisplayId(); | |
100 BrowserThread::PostTask( | |
101 BrowserThread::FILE, FROM_HERE, | |
102 base::Bind(&DisplayColorManager::LoadFromPath, this, path, | |
103 gfx::Display::InternalDisplayId())); | |
oshima
2015/04/15 23:56:13
FILE thread is obsolete. Please use SequencedWorke
robert.bradford
2015/04/17 16:42:45
Ended up using base::PostTaskAndReplyWithResult wi
| |
104 } | |
105 } | |
106 | |
107 void DisplayColorManager::UpdateCalibrationData( | |
108 uint64_t display_id, | |
109 scoped_ptr<ColorCalibrationData> data) { | |
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
111 // The map takes over ownership of the underlying memory. | |
112 calibration_map_[display_id] = data.release(); | |
113 } | |
114 | |
115 void DisplayColorManager::LoadFromPath(const base::FilePath& path, | |
116 uint64_t display_id) { | |
117 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
118 scoped_ptr<ColorCalibrationData> data = make_scoped_ptr(ParseFile(path)); | |
119 BrowserThread::PostTask( | |
120 BrowserThread::UI, FROM_HERE, | |
121 base::Bind(&DisplayColorManager::UpdateCalibrationData, this, display_id, | |
122 base::Passed(&data))); | |
123 } | |
124 | |
125 DisplayColorManager::ColorCalibrationData::ColorCalibrationData() { | |
126 } | |
127 | |
128 DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() { | |
129 } | |
130 | |
131 } // namespace ash | |
OLD | NEW |