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

Unified Diff: ui/ozone/platform/drm/gpu/drm_device.cc

Issue 1182063002: Add support for more advanced color correction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@qcms-fixed-point-gamma
Patch Set: Address dcheng@ feedback 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_device.h ('k') | ui/ozone/platform/drm/gpu/drm_display.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/drm/gpu/drm_device.cc
diff --git a/ui/ozone/platform/drm/gpu/drm_device.cc b/ui/ozone/platform/drm/gpu/drm_device.cc
index 3a30fd23e5ac3cf4b83919525a8c01dcd60e39ed..80983666d032c18a2bc0a6c61fb2f749de276217 100644
--- a/ui/ozone/platform/drm/gpu/drm_device.cc
+++ b/ui/ozone/platform/drm/gpu/drm_device.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
+#include "base/posix/safe_strerror.h"
#include "base/task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
@@ -113,6 +114,108 @@ bool CanQueryForResources(int fd) {
return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources);
}
+// TODO(robert.bradford): Replace with libdrm structures after libdrm roll.
+// https://crbug.com/586475
+struct DrmColorLut {
+ uint16_t red;
+ uint16_t green;
+ uint16_t blue;
+ uint16_t reserved;
+};
+
+struct DrmColorCtm {
+ int64_t ctm_coeff[9];
+};
+
+typedef scoped_ptr<DrmColorLut, base::FreeDeleter> ScopedDrmColorLut;
dnicoara 2016/02/24 14:24:34 nit: Add a "Ptr" suffix to match the other ScopedD
robert.bradford 2016/02/24 15:22:05 Done.
+typedef scoped_ptr<DrmColorCtm, base::FreeDeleter> ScopedDrmColorCtm;
+
+ScopedDrmColorLut CreateLutBlob(const std::vector<GammaRampRGBEntry>& source) {
+ TRACE_EVENT0("drm", "CreateLutBlob");
+
+ ScopedDrmColorLut res(new DrmColorLut[source.size()]);
+ DrmColorLut* lut = res.get();
+ for (size_t i = 0; i < source.size(); ++i) {
+ lut[i].red = source[i].r;
+ lut[i].green = source[i].g;
+ lut[i].blue = source[i].b;
+ }
+ return res;
+}
+
+ScopedDrmColorCtm CreateCTMBlob(const std::vector<float>& correction_matrix) {
+ ScopedDrmColorCtm ctm(new DrmColorCtm);
dnicoara 2016/02/24 14:24:34 You're allocating with new() but freeing with free
robert.bradford 2016/02/24 15:22:05 You're right, malloc & free is best.
+
+ for (int i = 0; i < 9; ++i) {
+ if (correction_matrix[i] < 0) {
+ ctm->ctm_coeff[i] = static_cast<uint64_t>(
+ -correction_matrix[i] * (static_cast<uint64_t>(1) << 32));
+ ctm->ctm_coeff[i] |= static_cast<uint64_t>(1) << 63;
+ } else {
+ ctm->ctm_coeff[i] = static_cast<uint64_t>(
+ correction_matrix[i] * (static_cast<uint64_t>(1) << 32));
+ }
+ }
+ return ctm;
+}
+
+bool SetBlobProperty(int fd,
+ uint32_t object_id,
+ uint32_t object_type,
+ uint32_t prop_id,
+ const char* property_name,
+ unsigned char* data,
+ size_t length) {
+ uint32_t blob_id;
+ int res;
+ res = drmModeCreatePropertyBlob(fd, data, length, &blob_id);
+ if (res != 0) {
+ LOG(ERROR) << "Error creating property blob: " << base::safe_strerror(res)
+ << " for property " << property_name;
+ return false;
+ }
+ res = drmModeObjectSetProperty(fd, object_id, object_type, prop_id, blob_id);
+ if (res != 0) {
+ LOG(ERROR) << "Error updating property: " << base::safe_strerror(res)
+ << " for property " << property_name;
+ drmModeDestroyPropertyBlob(fd, blob_id);
+ return false;
+ }
+ drmModeDestroyPropertyBlob(fd, blob_id);
+ return true;
+}
+
+std::vector<GammaRampRGBEntry> ResampleLut(
+ const std::vector<GammaRampRGBEntry>& lut_in,
+ size_t desired_size) {
+ TRACE_EVENT1("drm", "ResampleLut", "desired_size", desired_size);
+ if (lut_in.size() == desired_size)
+ return lut_in;
+
+ std::vector<GammaRampRGBEntry> result;
+ result.resize(desired_size);
+
+ for (size_t i = 0; i < desired_size; ++i) {
+ size_t base_index = lut_in.size() * i / desired_size;
+ size_t remaining = lut_in.size() * i % desired_size;
+ if (base_index < lut_in.size() - 1) {
+ result[i].r = lut_in[base_index].r +
+ (lut_in[base_index + 1].r - lut_in[base_index].r) *
+ remaining / desired_size;
+ result[i].g = lut_in[base_index].g +
+ (lut_in[base_index + 1].g - lut_in[base_index].g) *
+ remaining / desired_size;
+ result[i].b = lut_in[base_index].b +
+ (lut_in[base_index + 1].b - lut_in[base_index].b) *
+ remaining / desired_size;
+ } else {
+ result[i] = lut_in[lut_in.size() - 1];
+ }
+ }
+
+ return result;
+}
+
} // namespace
class DrmDevice::PageFlipManager {
@@ -542,4 +645,74 @@ bool DrmDevice::SetGammaRamp(uint32_t crtc_id,
&g[0], &b[0]) == 0);
}
+bool DrmDevice::SetColorCorrection(
+ uint32_t crtc_id,
+ const std::vector<GammaRampRGBEntry>& degamma_lut,
+ const std::vector<GammaRampRGBEntry>& gamma_lut,
+ const std::vector<float>& correction_matrix) {
+ ScopedDrmObjectPropertyPtr crtc_props(drmModeObjectGetProperties(
+ file_.GetPlatformFile(), crtc_id, DRM_MODE_OBJECT_CRTC));
+ uint64_t degamma_lut_size = 0;
+ uint64_t gamma_lut_size = 0;
+
+ for (uint32_t i = 0; i < crtc_props->count_props; ++i) {
+ ScopedDrmPropertyPtr property(
+ drmModeGetProperty(file_.GetPlatformFile(), crtc_props->props[i]));
+ if (property && !strcmp(property->name, "DEGAMMA_LUT_SIZE")) {
+ degamma_lut_size = crtc_props->prop_values[i];
+ }
+ if (property && !strcmp(property->name, "GAMMA_LUT_SIZE")) {
+ gamma_lut_size = crtc_props->prop_values[i];
+ }
+
+ if (degamma_lut_size && gamma_lut_size)
+ break;
+ }
+
+ if (degamma_lut_size == 0 || gamma_lut_size == 0) {
+ LOG(WARNING) << "No available (de)gamma tables.";
+ return false;
+ }
+
+ ScopedDrmColorLut degamma_blob_data =
+ CreateLutBlob(ResampleLut(degamma_lut, degamma_lut_size));
+ ScopedDrmColorLut gamma_blob_data =
+ CreateLutBlob(ResampleLut(gamma_lut, gamma_lut_size));
+ ScopedDrmColorCtm ctm_blob_data = CreateCTMBlob(correction_matrix);
+
+ for (uint32_t i = 0; i < crtc_props->count_props; ++i) {
+ ScopedDrmPropertyPtr property(
+ drmModeGetProperty(file_.GetPlatformFile(), crtc_props->props[i]));
+ if (!property)
+ continue;
+
+ if (!strcmp(property->name, "DEGAMMA_LUT")) {
+ if (!SetBlobProperty(
+ file_.GetPlatformFile(), crtc_id, DRM_MODE_OBJECT_CRTC,
+ crtc_props->props[i], property->name,
+ reinterpret_cast<unsigned char*>(degamma_blob_data.get()),
+ sizeof(DrmColorLut) * degamma_lut_size))
+ return false;
+ }
+ if (!strcmp(property->name, "GAMMA_LUT")) {
+ if (!SetBlobProperty(
+ file_.GetPlatformFile(), crtc_id, DRM_MODE_OBJECT_CRTC,
+ crtc_props->props[i], property->name,
+ reinterpret_cast<unsigned char*>(gamma_blob_data.get()),
+ sizeof(DrmColorLut) * gamma_lut_size))
+ return false;
+ }
+ if (!strcmp(property->name, "CTM")) {
+ if (!SetBlobProperty(
+ file_.GetPlatformFile(), crtc_id, DRM_MODE_OBJECT_CRTC,
+ crtc_props->props[i], property->name,
+ reinterpret_cast<unsigned char*>(ctm_blob_data.get()),
+ sizeof(DrmColorCtm)))
+ return false;
+ }
+ }
+
+ return true;
+}
+
} // namespace ui
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_device.h ('k') | ui/ozone/platform/drm/gpu/drm_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698