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

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

Issue 1914343003: Reland: ash: reset color management when new screens are hotplugged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add an error when trying to set a gamma table without driver support Created 4 years, 7 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.cc » ('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 1df20c6c5d9ec1702cce442285d059911cf356f4..3a20367ed762c29243f0fcbe70ae6ed4e170e75c 100644
--- a/ui/ozone/platform/drm/gpu/drm_device.cc
+++ b/ui/ozone/platform/drm/gpu/drm_device.cc
@@ -185,6 +185,9 @@ using ScopedDrmColorCtmPtr = std::unique_ptr<DrmColorCtm, base::FreeDeleter>;
ScopedDrmColorLutPtr CreateLutBlob(
const std::vector<GammaRampRGBEntry>& source) {
TRACE_EVENT0("drm", "CreateLutBlob");
+ if (source.empty())
+ return nullptr;
+
ScopedDrmColorLutPtr lut(
static_cast<DrmColorLut*>(malloc(sizeof(DrmColorLut) * source.size())));
DrmColorLut* p = lut.get();
@@ -198,6 +201,9 @@ ScopedDrmColorLutPtr CreateLutBlob(
ScopedDrmColorCtmPtr CreateCTMBlob(
const std::vector<float>& correction_matrix) {
+ if (correction_matrix.empty())
+ return nullptr;
+
ScopedDrmColorCtmPtr ctm(
static_cast<DrmColorCtm*>(malloc(sizeof(DrmColorCtm))));
for (size_t i = 0; i < arraysize(ctm->ctm_coeff); ++i) {
@@ -220,29 +226,38 @@ bool SetBlobProperty(int fd,
const char* property_name,
unsigned char* data,
size_t length) {
- uint32_t blob_id;
+ uint32_t blob_id = 0;
int res;
- res = CreatePropertyBlob(fd, data, length, &blob_id);
- if (res != 0) {
- LOG(ERROR) << "Error creating property blob: " << base::safe_strerror(res)
- << " for property " << property_name;
- return false;
+
+ if (data) {
+ res = CreatePropertyBlob(fd, data, length, &blob_id);
+ if (res != 0) {
+ LOG(ERROR) << "Error creating property blob: " << base::safe_strerror(res)
+ << " for property " << property_name;
+ return false;
+ }
}
+
+ bool success = 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;
- DestroyPropertyBlob(fd, blob_id);
- return false;
+ } else {
+ success = true;
}
- DestroyPropertyBlob(fd, blob_id);
- return true;
+ if (blob_id != 0)
+ DestroyPropertyBlob(fd, blob_id);
+ return success;
}
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.empty())
+ return std::vector<GammaRampRGBEntry>();
+
if (lut_in.size() == desired_size)
return lut_in;
@@ -674,23 +689,43 @@ bool DrmDevice::DropMaster() {
bool DrmDevice::SetGammaRamp(uint32_t crtc_id,
const std::vector<GammaRampRGBEntry>& lut) {
ScopedDrmCrtcPtr crtc = GetCrtc(crtc_id);
+ size_t gamma_size = static_cast<size_t>(crtc->gamma_size);
+
+ if (gamma_size == 0 && lut.empty())
+ return true;
+
+ if (gamma_size == 0) {
+ LOG(ERROR) << "Gamma table not supported";
+ return false;
+ }
// TODO(robert.bradford) resample the incoming ramp to match what the kernel
// expects.
- if (static_cast<size_t>(crtc->gamma_size) != lut.size()) {
+ if (!lut.empty() && gamma_size != lut.size()) {
LOG(ERROR) << "Gamma table size mismatch: supplied " << lut.size()
- << " expected " << crtc->gamma_size;
+ << " expected " << gamma_size;
+ return false;
}
std::vector<uint16_t> r, g, b;
- r.reserve(lut.size());
- g.reserve(lut.size());
- b.reserve(lut.size());
-
- for (size_t i = 0; i < lut.size(); ++i) {
- r.push_back(lut[i].r);
- g.push_back(lut[i].g);
- b.push_back(lut[i].b);
+ r.reserve(gamma_size);
+ g.reserve(gamma_size);
+ b.reserve(gamma_size);
+
+ if (lut.empty()) {
+ // Create a linear gamma ramp table to deactivate the feature.
+ for (size_t i = 0; i < gamma_size; ++i) {
+ uint16_t value = (i * ((1 << 16) - 1)) / (gamma_size - 1);
+ r.push_back(value);
+ g.push_back(value);
+ b.push_back(value);
+ }
+ } else {
+ for (size_t i = 0; i < gamma_size; ++i) {
+ r.push_back(lut[i].r);
+ g.push_back(lut[i].g);
+ b.push_back(lut[i].b);
+ }
}
DCHECK(file_.IsValid());
@@ -723,9 +758,10 @@ bool DrmDevice::SetColorCorrection(
break;
}
+ // If we can't find the degamma & gamma lut size, it means the properties
+ // aren't available. We should then use the legacy gamma ramp ioctl.
if (degamma_lut_size == 0 || gamma_lut_size == 0) {
- LOG(WARNING) << "No available (de)gamma tables.";
- return false;
+ return SetGammaRamp(crtc_id, gamma_lut);
}
ScopedDrmColorLutPtr degamma_blob_data =
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_device.h ('k') | ui/ozone/platform/drm/gpu/drm_display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698