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

Unified Diff: ash/content/display/display_color_manager_chromeos.cc

Issue 1028563003: Load and apply a vcgt table from an ICC file to the internal display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix spang/oshima nits Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ash/content/display/display_color_manager_chromeos.cc
diff --git a/ash/content/display/display_color_manager_chromeos.cc b/ash/content/display/display_color_manager_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53628382e2c5fb4b3e62963554db183f6955d8fb
--- /dev/null
+++ b/ash/content/display/display_color_manager_chromeos.cc
@@ -0,0 +1,132 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/content/display/display_color_manager_chromeos.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "chromeos/chromeos_switches.h"
+#include "content/public/browser/browser_thread.h"
+#include "third_party/qcms/src/qcms.h"
+#include "ui/display/types/display_snapshot.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/screen.h"
+
+using content::BrowserThread;
+
+namespace ash {
+
+namespace {
+
+bool ParseFile(const base::FilePath& path,
+ DisplayColorManager::ColorCalibrationData* data) {
+ 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;
+ }
+
+ size_t vcgt_size = qcms_profile_get_vcgt_channel_length(display_profile);
+ if (!vcgt_size) {
+ LOG(WARNING) << "No vcgt table in ICC file: " << path.value();
+ return false;
+ }
+
+ data->r.resize(vcgt_size);
+ data->g.resize(vcgt_size);
+ data->b.resize(vcgt_size);
+ if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &data->r[0],
+ &data->g[0], &data->b[0])) {
+ LOG(WARNING) << "Unable to get vcgt data";
+ qcms_profile_release(display_profile);
+ return false;
+ }
+
+ qcms_profile_release(display_profile);
+ return true;
+}
+
+} // namespace
+
+DisplayColorManager::DisplayColorManager(ui::DisplayConfigurator* configurator)
+ : configurator_(configurator) {
+ configurator_->AddObserver(this);
+ LoadInternalFromCommandLine();
+}
+
+DisplayColorManager::~DisplayColorManager() {
+ configurator_->RemoveObserver(this);
+
+ for (auto it : calibration_map_) {
+ delete it.second;
+ calibration_map_.erase(it.first);
+ }
+}
+
+void DisplayColorManager::OnDisplayModeChanged(
+ const ui::DisplayConfigurator::DisplayStateList& display_states) {
+ for (const ui::DisplaySnapshot* state : display_states)
+ ApplyDisplayColorCalibration(state->display_id());
+}
+
+void DisplayColorManager::ApplyDisplayColorCalibration(uint64_t display_id) {
+ if (calibration_map_.find(display_id) != calibration_map_.end()) {
+ ColorCalibrationData* ramp = calibration_map_[display_id];
+ if (!configurator_->SetGammaRamp(display_id, ramp->r, ramp->g, ramp->b))
+ LOG(WARNING) << "Error applying gamma ramp";
+ }
+}
+
+void DisplayColorManager::LoadInternalFromCommandLine() {
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(
+ chromeos::switches::kInternalDisplayColorProfileFile)) {
+ const base::FilePath& path = command_line->GetSwitchValuePath(
+ chromeos::switches::kInternalDisplayColorProfileFile);
+ VLOG(1) << "Loading ICC file : " << path.value()
+ << "for internal display id: " << gfx::Display::InternalDisplayId();
+ LoadCalibrationForDisplay(gfx::Display::InternalDisplayId(), path);
+ }
+}
+
+void DisplayColorManager::LoadCalibrationForDisplay(
+ int64_t display_id,
+ const base::FilePath& path) {
+ if (display_id == gfx::Display::kInvalidDisplayID) {
+ LOG(WARNING) << "Trying to load calibration data for invalid display id";
+ return;
+ }
+
+ scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData());
+ base::Callback<bool(void)> request(
+ base::Bind(&ParseFile, path, base::Unretained(data.get())));
+ base::PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(), FROM_HERE, request,
+ base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(),
+ display_id, base::Passed(data.Pass())));
+}
+
+void DisplayColorManager::UpdateCalibrationData(
+ uint64_t display_id,
+ scoped_ptr<ColorCalibrationData> data,
+ bool success) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (success) {
+ // The map takes over ownership of the underlying memory.
+ calibration_map_[display_id] = data.release();
+ }
+}
+
+DisplayColorManager::ColorCalibrationData::ColorCalibrationData() {
+}
+
+DisplayColorManager::ColorCalibrationData::~ColorCalibrationData() {
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698