Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/drm/gpu/drm_device.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
| 11 #include <xf86drmMode.h> | 11 #include <xf86drmMode.h> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/posix/safe_strerror.h" | |
| 17 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 20 #include "third_party/skia/include/core/SkImageInfo.h" | 21 #include "third_party/skia/include/core/SkImageInfo.h" |
| 21 #include "ui/display/types/gamma_ramp_rgb_entry.h" | 22 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
| 22 #include "ui/ozone/platform/drm/common/drm_util.h" | 23 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 23 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_legacy.h" | 24 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_legacy.h" |
| 24 | 25 |
| 25 #if defined(USE_DRM_ATOMIC) | 26 #if defined(USE_DRM_ATOMIC) |
| 26 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_atomic.h" | 27 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_atomic.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } | 107 } |
| 107 | 108 |
| 108 bool CanQueryForResources(int fd) { | 109 bool CanQueryForResources(int fd) { |
| 109 drm_mode_card_res resources; | 110 drm_mode_card_res resources; |
| 110 memset(&resources, 0, sizeof(resources)); | 111 memset(&resources, 0, sizeof(resources)); |
| 111 // If there is no error getting DRM resources then assume this is a | 112 // If there is no error getting DRM resources then assume this is a |
| 112 // modesetting device. | 113 // modesetting device. |
| 113 return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources); | 114 return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources); |
| 114 } | 115 } |
| 115 | 116 |
| 117 struct _drm_color_lut { | |
|
dnicoara
2016/02/10 20:33:31
structs should follow the Chromium naming conventi
robert.bradford
2016/02/12 14:55:49
Yes ultimately but there is delay in getting chang
| |
| 118 __u16 red; | |
|
dnicoara
2016/02/10 20:33:31
Use uint16_t
robert.bradford
2016/02/12 14:55:49
Done.
| |
| 119 __u16 green; | |
| 120 __u16 blue; | |
| 121 __u16 reserved; | |
| 122 }; | |
| 123 | |
| 124 struct _drm_color_ctm { | |
|
dnicoara
2016/02/10 20:33:31
Same: DrmColorCtm
robert.bradford
2016/02/12 14:55:49
Done.
| |
| 125 __s64 ctm_coeff[9]; | |
|
dnicoara
2016/02/10 20:33:31
Use int64_t.
robert.bradford
2016/02/12 14:55:50
Done.
| |
| 126 }; | |
| 127 | |
| 128 std::vector<uint8_t> CreateLutBlob( | |
| 129 const std::vector<GammaRampRGBEntry>& source) { | |
| 130 TRACE_EVENT0("drm", "CreateLutBlob"); | |
| 131 std::vector<uint8_t> data; | |
| 132 | |
| 133 data.resize(source.size() * sizeof(struct _drm_color_lut)); | |
| 134 | |
| 135 struct _drm_color_lut* lut = | |
| 136 reinterpret_cast<struct _drm_color_lut*>(&data[0]); | |
| 137 | |
| 138 for (size_t i = 0; i < source.size(); ++i) { | |
| 139 lut[i].red = source[i].r; | |
| 140 lut[i].green = source[i].g; | |
| 141 lut[i].blue = source[i].b; | |
| 142 } | |
| 143 return data; | |
| 144 } | |
| 145 | |
| 146 std::vector<uint8_t> CreateCTMBlob( | |
| 147 const std::vector<float>& correction_matrix) { | |
| 148 std::vector<uint8_t> data; | |
| 149 data.resize(sizeof(struct _drm_color_ctm)); | |
| 150 struct _drm_color_ctm* ctm = | |
| 151 reinterpret_cast<struct _drm_color_ctm*>(&data[0]); | |
| 152 | |
| 153 for (int i = 0; i < 9; ++i) { | |
| 154 if (correction_matrix[i] < 0) { | |
| 155 ctm->ctm_coeff[i] = static_cast<uint64_t>( | |
| 156 -correction_matrix[i] * (static_cast<uint64_t>(1) << 32)); | |
| 157 ctm->ctm_coeff[i] |= static_cast<uint64_t>(1) << 63; | |
| 158 } else { | |
| 159 ctm->ctm_coeff[i] = static_cast<uint64_t>( | |
| 160 correction_matrix[i] * (static_cast<uint64_t>(1) << 32)); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 return data; | |
| 165 } | |
| 166 | |
| 167 bool SetBlobProperty(int fd, | |
| 168 uint32_t object_id, | |
| 169 uint32_t object_type, | |
| 170 uint32_t prop_id, | |
| 171 std::vector<uint8_t> data) { | |
| 172 uint32_t blob_id; | |
| 173 int res; | |
| 174 res = drmModeCreatePropertyBlob(fd, &data[0], data.size(), &blob_id); | |
|
dnicoara
2016/02/10 20:33:31
nit: Use vector_as_array(&data) from base/stl_util
dnicoara
2016/02/11 14:57:31
Actually, looks like this got deprecated in favor
robert.bradford
2016/02/12 14:55:49
Done.
| |
| 175 if (res != 0) { | |
| 176 LOG(ERROR) << "Error creating property blob: " << base::safe_strerror(res); | |
| 177 return false; | |
| 178 } | |
| 179 res = drmModeObjectSetProperty(fd, object_id, object_type, prop_id, blob_id); | |
| 180 if (res != 0) { | |
| 181 LOG(ERROR) << "Error updating property: " << base::safe_strerror(res); | |
| 182 drmModeDestroyPropertyBlob(fd, blob_id); | |
| 183 return false; | |
| 184 } | |
| 185 drmModeDestroyPropertyBlob(fd, blob_id); | |
| 186 return true; | |
| 187 } | |
| 188 | |
| 189 std::vector<GammaRampRGBEntry> ResampleLut( | |
| 190 const std::vector<GammaRampRGBEntry>& lut_in, | |
| 191 size_t desired_size) { | |
| 192 TRACE_EVENT1("drm", "ResampleLut", "desired_size", desired_size); | |
| 193 if (lut_in.size() == desired_size) | |
| 194 return lut_in; | |
| 195 | |
| 196 std::vector<GammaRampRGBEntry> result; | |
| 197 result.resize(desired_size); | |
| 198 | |
| 199 for (size_t i = 0; i < desired_size; ++i) { | |
| 200 size_t base_index = lut_in.size() * i / desired_size; | |
| 201 size_t remaining = lut_in.size() * i % desired_size; | |
| 202 if (base_index < lut_in.size() - 1) { | |
| 203 result[i].r = lut_in[base_index].r + | |
| 204 (lut_in[base_index + 1].r - lut_in[base_index].r) * | |
| 205 remaining / desired_size; | |
| 206 result[i].g = lut_in[base_index].g + | |
| 207 (lut_in[base_index + 1].g - lut_in[base_index].g) * | |
| 208 remaining / desired_size; | |
| 209 result[i].b = lut_in[base_index].b + | |
| 210 (lut_in[base_index + 1].b - lut_in[base_index].b) * | |
| 211 remaining / desired_size; | |
| 212 } else { | |
| 213 result[i] = lut_in[lut_in.size() - 1]; | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 return result; | |
| 218 } | |
| 219 | |
| 116 } // namespace | 220 } // namespace |
| 117 | 221 |
| 118 class DrmDevice::PageFlipManager { | 222 class DrmDevice::PageFlipManager { |
| 119 public: | 223 public: |
| 120 PageFlipManager() : next_id_(0) {} | 224 PageFlipManager() : next_id_(0) {} |
| 121 ~PageFlipManager() {} | 225 ~PageFlipManager() {} |
| 122 | 226 |
| 123 void OnPageFlip(uint32_t frame, | 227 void OnPageFlip(uint32_t frame, |
| 124 uint32_t seconds, | 228 uint32_t seconds, |
| 125 uint32_t useconds, | 229 uint32_t useconds, |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 g.push_back(lut[i].g); | 639 g.push_back(lut[i].g); |
| 536 b.push_back(lut[i].b); | 640 b.push_back(lut[i].b); |
| 537 } | 641 } |
| 538 | 642 |
| 539 DCHECK(file_.IsValid()); | 643 DCHECK(file_.IsValid()); |
| 540 TRACE_EVENT0("drm", "DrmDevice::SetGamma"); | 644 TRACE_EVENT0("drm", "DrmDevice::SetGamma"); |
| 541 return (drmModeCrtcSetGamma(file_.GetPlatformFile(), crtc_id, r.size(), &r[0], | 645 return (drmModeCrtcSetGamma(file_.GetPlatformFile(), crtc_id, r.size(), &r[0], |
| 542 &g[0], &b[0]) == 0); | 646 &g[0], &b[0]) == 0); |
| 543 } | 647 } |
| 544 | 648 |
| 649 bool DrmDevice::SetColorCorrection( | |
| 650 uint32_t crtc_id, | |
| 651 const std::vector<GammaRampRGBEntry>& degamma_lut, | |
| 652 const std::vector<GammaRampRGBEntry>& gamma_lut, | |
| 653 const std::vector<float>& correction_matrix) { | |
| 654 ScopedDrmObjectPropertyPtr crtc_props(drmModeObjectGetProperties( | |
| 655 file_.GetPlatformFile(), crtc_id, DRM_MODE_OBJECT_CRTC)); | |
| 656 uint64_t degamma_lut_size = 0; | |
| 657 uint64_t gamma_lut_size = 0; | |
| 658 | |
| 659 for (uint32_t i = 0; i < crtc_props->count_props; ++i) { | |
| 660 ScopedDrmPropertyPtr property( | |
| 661 drmModeGetProperty(file_.GetPlatformFile(), crtc_props->props[i])); | |
| 662 if (property && !strcmp(property->name, "DEGAMMA_LUT_SIZE")) { | |
| 663 degamma_lut_size = crtc_props->prop_values[i]; | |
| 664 } | |
| 665 if (property && !strcmp(property->name, "GAMMA_LUT_SIZE")) { | |
| 666 gamma_lut_size = crtc_props->prop_values[i]; | |
| 667 } | |
| 668 | |
| 669 if (degamma_lut_size && gamma_lut_size) | |
| 670 break; | |
| 671 } | |
| 672 | |
| 673 if (degamma_lut_size == 0 || gamma_lut_size == 0) { | |
| 674 LOG(WARNING) << "No available (de)gamma tables."; | |
| 675 return false; | |
| 676 } | |
| 677 | |
| 678 std::vector<uint8_t> degamma_blob_data = | |
| 679 CreateLutBlob(ResampleLut(degamma_lut, degamma_lut_size)); | |
| 680 std::vector<uint8_t> gamma_blob_data = | |
| 681 CreateLutBlob(ResampleLut(gamma_lut, gamma_lut_size)); | |
| 682 std::vector<uint8_t> ctm_blob_data = CreateCTMBlob(correction_matrix); | |
| 683 | |
| 684 for (uint32_t i = 0; i < crtc_props->count_props; ++i) { | |
| 685 ScopedDrmPropertyPtr property( | |
| 686 drmModeGetProperty(file_.GetPlatformFile(), crtc_props->props[i])); | |
| 687 if (property && !strcmp(property->name, "DEGAMMA_LUT")) { | |
|
dnicoara
2016/02/10 20:33:31
nit: Maybe check the property is valid once. Somet
robert.bradford
2016/02/12 14:55:49
Done.
| |
| 688 if (!SetBlobProperty(file_.GetPlatformFile(), crtc_id, | |
| 689 DRM_MODE_OBJECT_CRTC, crtc_props->props[i], | |
| 690 degamma_blob_data)) { | |
| 691 LOG(WARNING) << "Error setting degamma property."; | |
| 692 return false; | |
| 693 } | |
| 694 } | |
| 695 if (property && !strcmp(property->name, "GAMMA_LUT")) { | |
| 696 if (!SetBlobProperty(file_.GetPlatformFile(), crtc_id, | |
| 697 DRM_MODE_OBJECT_CRTC, crtc_props->props[i], | |
| 698 gamma_blob_data)) { | |
| 699 LOG(WARNING) << "Error setting gamma property."; | |
| 700 return false; | |
| 701 } | |
| 702 } | |
| 703 if (property && !strcmp(property->name, "CTM_MATRIX")) { | |
| 704 if (!SetBlobProperty(file_.GetPlatformFile(), crtc_id, | |
| 705 DRM_MODE_OBJECT_CRTC, crtc_props->props[i], | |
| 706 ctm_blob_data)) { | |
| 707 LOG(WARNING) << "Error setting correction matrix property."; | |
| 708 return false; | |
| 709 } | |
| 710 } | |
| 711 } | |
| 712 | |
| 713 return true; | |
| 714 } | |
| 715 | |
| 545 } // namespace ui | 716 } // namespace ui |
| OLD | NEW |