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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/dri_wrapper.h"
9 #include <xf86drmMode.h>
11 #include "base/logging.h"
15 DriWrapper::DriWrapper(const char* device_path) {
16 fd_ = open(device_path, O_RDWR | O_CLOEXEC);
19 DriWrapper::~DriWrapper() {
24 drmModeCrtc* DriWrapper::GetCrtc(uint32_t crtc_id) {
26 return drmModeGetCrtc(fd_, crtc_id);
29 void DriWrapper::FreeCrtc(drmModeCrtc* crtc) {
30 drmModeFreeCrtc(crtc);
33 bool DriWrapper::SetCrtc(uint32_t crtc_id,
36 drmModeModeInfo* mode) {
38 return !drmModeSetCrtc(fd_, crtc_id, framebuffer, 0, 0, connectors, 1, mode);
41 bool DriWrapper::SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) {
43 return !drmModeSetCrtc(fd_,
53 bool DriWrapper::DisableCrtc(uint32_t crtc_id) {
55 return !drmModeSetCrtc(fd_, crtc_id, 0, 0, 0, NULL, 0, NULL);
58 bool DriWrapper::AddFramebuffer(const drmModeModeInfo& mode,
63 uint32_t* framebuffer) {
65 return !drmModeAddFB(fd_,
75 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) {
77 return !drmModeRmFB(fd_, framebuffer);
80 bool DriWrapper::PageFlip(uint32_t crtc_id,
84 return !drmModePageFlip(fd_,
87 DRM_MODE_PAGE_FLIP_EVENT,
91 drmModePropertyRes* DriWrapper::GetProperty(drmModeConnector* connector,
93 for (int i = 0; i < connector->count_props; ++i) {
94 drmModePropertyRes* property = drmModeGetProperty(fd_, connector->props[i]);
98 if (strcmp(property->name, name) == 0)
101 drmModeFreeProperty(property);
107 bool DriWrapper::SetProperty(uint32_t connector_id,
108 uint32_t property_id,
111 return !drmModeConnectorSetProperty(fd_, connector_id, property_id, value);
114 void DriWrapper::FreeProperty(drmModePropertyRes* prop) {
115 drmModeFreeProperty(prop);
118 drmModePropertyBlobRes* DriWrapper::GetPropertyBlob(drmModeConnector* connector,
121 for (int i = 0; i < connector->count_props; ++i) {
122 drmModePropertyRes* property = drmModeGetProperty(fd_, connector->props[i]);
126 if (strcmp(property->name, name) == 0 &&
127 property->flags & DRM_MODE_PROP_BLOB) {
128 drmModePropertyBlobRes* blob =
129 drmModeGetPropertyBlob(fd_, connector->prop_values[i]);
130 drmModeFreeProperty(property);
134 drmModeFreeProperty(property);
140 void DriWrapper::FreePropertyBlob(drmModePropertyBlobRes* blob) {
141 drmModeFreePropertyBlob(blob);
144 bool DriWrapper::SetCursor(uint32_t crtc_id,
149 return !drmModeSetCursor(fd_, crtc_id, handle, width, height);
152 bool DriWrapper::MoveCursor(uint32_t crtc_id, int x, int y) {
154 return !drmModeMoveCursor(fd_, crtc_id, x, y);