blob: 4c98507f6819b68989de3caa5e4d7b7537f4be5b [file] [log] [blame]
Stéphane Marchesin1a92c442015-06-29 20:05:48 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tao Bao557fa1f2017-02-07 12:51:00 -080017#include "graphics_drm.h"
18
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070019#include <fcntl.h>
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070020#include <stdio.h>
21#include <stdlib.h>
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070022#include <sys/mman.h>
23#include <sys/types.h>
24#include <unistd.h>
Tao Bao76be34c2017-02-07 13:30:19 -080025
26#include <drm_fourcc.h>
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070027#include <xf86drm.h>
28#include <xf86drmMode.h>
29
Tao Bao0ecbd762017-01-16 21:16:58 -080030#include "minui/minui.h"
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070031
32#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
33
Tao Bao557fa1f2017-02-07 12:51:00 -080034MinuiBackendDrm::MinuiBackendDrm()
35 : GRSurfaceDrms(), main_monitor_crtc(nullptr), main_monitor_connector(nullptr), drm_fd(-1) {}
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070036
Tao Bao557fa1f2017-02-07 12:51:00 -080037void MinuiBackendDrm::DrmDisableCrtc(int drm_fd, drmModeCrtc* crtc) {
Tao Bao76be34c2017-02-07 13:30:19 -080038 if (crtc) {
39 drmModeSetCrtc(drm_fd, crtc->crtc_id,
40 0, // fb_id
41 0, 0, // x,y
42 nullptr, // connectors
43 0, // connector_count
44 nullptr); // mode
45 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070046}
47
Tianjie Xuccf00a22018-06-05 17:10:23 -070048int MinuiBackendDrm::DrmEnableCrtc(int drm_fd, drmModeCrtc* crtc, GRSurfaceDrm* surface) {
49 int ret = drmModeSetCrtc(drm_fd, crtc->crtc_id, surface->fb_id, 0, 0, // x,y
50 &main_monitor_connector->connector_id,
51 1, // connector_count
52 &main_monitor_crtc->mode);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070053
Tao Bao76be34c2017-02-07 13:30:19 -080054 if (ret) {
55 printf("drmModeSetCrtc failed ret=%d\n", ret);
56 }
Tianjie Xuccf00a22018-06-05 17:10:23 -070057
58 return ret;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070059}
60
Tao Bao557fa1f2017-02-07 12:51:00 -080061void MinuiBackendDrm::Blank(bool blank) {
Tao Bao76be34c2017-02-07 13:30:19 -080062 if (blank) {
Tao Bao557fa1f2017-02-07 12:51:00 -080063 DrmDisableCrtc(drm_fd, main_monitor_crtc);
Tao Bao76be34c2017-02-07 13:30:19 -080064 } else {
Tao Bao557fa1f2017-02-07 12:51:00 -080065 DrmEnableCrtc(drm_fd, main_monitor_crtc, GRSurfaceDrms[current_buffer]);
Tao Bao76be34c2017-02-07 13:30:19 -080066 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070067}
68
Tao Bao557fa1f2017-02-07 12:51:00 -080069void MinuiBackendDrm::DrmDestroySurface(GRSurfaceDrm* surface) {
Tao Bao76be34c2017-02-07 13:30:19 -080070 if (!surface) return;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070071
Tao Bao557fa1f2017-02-07 12:51:00 -080072 if (surface->data) {
73 munmap(surface->data, surface->row_bytes * surface->height);
Tao Bao76be34c2017-02-07 13:30:19 -080074 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070075
Tao Bao76be34c2017-02-07 13:30:19 -080076 if (surface->fb_id) {
77 int ret = drmModeRmFB(drm_fd, surface->fb_id);
78 if (ret) {
79 printf("drmModeRmFB failed ret=%d\n", ret);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070080 }
Tao Bao76be34c2017-02-07 13:30:19 -080081 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070082
Tao Bao76be34c2017-02-07 13:30:19 -080083 if (surface->handle) {
84 drm_gem_close gem_close = {};
85 gem_close.handle = surface->handle;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070086
Tao Bao76be34c2017-02-07 13:30:19 -080087 int ret = drmIoctl(drm_fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
88 if (ret) {
89 printf("DRM_IOCTL_GEM_CLOSE failed ret=%d\n", ret);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070090 }
Tao Bao76be34c2017-02-07 13:30:19 -080091 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070092
Tao Bao557fa1f2017-02-07 12:51:00 -080093 delete surface;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -070094}
95
96static int drm_format_to_bpp(uint32_t format) {
Tao Bao76be34c2017-02-07 13:30:19 -080097 switch (format) {
98 case DRM_FORMAT_ABGR8888:
99 case DRM_FORMAT_BGRA8888:
100 case DRM_FORMAT_RGBX8888:
101 case DRM_FORMAT_BGRX8888:
102 case DRM_FORMAT_XBGR8888:
103 case DRM_FORMAT_XRGB8888:
104 return 32;
105 case DRM_FORMAT_RGB565:
106 return 16;
107 default:
108 printf("Unknown format %d\n", format);
109 return 32;
110 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700111}
112
Tao Bao557fa1f2017-02-07 12:51:00 -0800113GRSurfaceDrm* MinuiBackendDrm::DrmCreateSurface(int width, int height) {
114 GRSurfaceDrm* surface = new GRSurfaceDrm;
115 *surface = {};
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700116
Tao Bao76be34c2017-02-07 13:30:19 -0800117 uint32_t format;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700118#if defined(RECOVERY_ABGR)
Tao Bao76be34c2017-02-07 13:30:19 -0800119 format = DRM_FORMAT_RGBA8888;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700120#elif defined(RECOVERY_BGRA)
Tao Bao76be34c2017-02-07 13:30:19 -0800121 format = DRM_FORMAT_ARGB8888;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700122#elif defined(RECOVERY_RGBX)
Tao Bao76be34c2017-02-07 13:30:19 -0800123 format = DRM_FORMAT_XBGR8888;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700124#else
Tao Bao76be34c2017-02-07 13:30:19 -0800125 format = DRM_FORMAT_RGB565;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700126#endif
127
Tao Bao76be34c2017-02-07 13:30:19 -0800128 drm_mode_create_dumb create_dumb = {};
129 create_dumb.height = height;
130 create_dumb.width = width;
131 create_dumb.bpp = drm_format_to_bpp(format);
132 create_dumb.flags = 0;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700133
Tao Bao76be34c2017-02-07 13:30:19 -0800134 int ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
135 if (ret) {
136 printf("DRM_IOCTL_MODE_CREATE_DUMB failed ret=%d\n", ret);
Tao Bao557fa1f2017-02-07 12:51:00 -0800137 DrmDestroySurface(surface);
Tao Bao76be34c2017-02-07 13:30:19 -0800138 return nullptr;
139 }
140 surface->handle = create_dumb.handle;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700141
Tao Bao76be34c2017-02-07 13:30:19 -0800142 uint32_t handles[4], pitches[4], offsets[4];
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700143
Tao Bao76be34c2017-02-07 13:30:19 -0800144 handles[0] = surface->handle;
145 pitches[0] = create_dumb.pitch;
146 offsets[0] = 0;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700147
Tao Bao76be34c2017-02-07 13:30:19 -0800148 ret =
149 drmModeAddFB2(drm_fd, width, height, format, handles, pitches, offsets, &(surface->fb_id), 0);
150 if (ret) {
151 printf("drmModeAddFB2 failed ret=%d\n", ret);
Tao Bao557fa1f2017-02-07 12:51:00 -0800152 DrmDestroySurface(surface);
Tao Bao76be34c2017-02-07 13:30:19 -0800153 return nullptr;
154 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700155
Tao Bao76be34c2017-02-07 13:30:19 -0800156 drm_mode_map_dumb map_dumb = {};
157 map_dumb.handle = create_dumb.handle;
158 ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb);
159 if (ret) {
160 printf("DRM_IOCTL_MODE_MAP_DUMB failed ret=%d\n", ret);
Tao Bao557fa1f2017-02-07 12:51:00 -0800161 DrmDestroySurface(surface);
Tao Bao76be34c2017-02-07 13:30:19 -0800162 return nullptr;
163 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700164
Tao Bao557fa1f2017-02-07 12:51:00 -0800165 surface->height = height;
166 surface->width = width;
167 surface->row_bytes = create_dumb.pitch;
168 surface->pixel_bytes = create_dumb.bpp / 8;
169 surface->data = static_cast<unsigned char*>(mmap(nullptr, surface->height * surface->row_bytes,
170 PROT_READ | PROT_WRITE, MAP_SHARED, drm_fd,
171 map_dumb.offset));
172 if (surface->data == MAP_FAILED) {
Tao Bao76be34c2017-02-07 13:30:19 -0800173 perror("mmap() failed");
Tao Bao557fa1f2017-02-07 12:51:00 -0800174 DrmDestroySurface(surface);
Tao Bao76be34c2017-02-07 13:30:19 -0800175 return nullptr;
176 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700177
Tao Bao76be34c2017-02-07 13:30:19 -0800178 return surface;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700179}
180
Tao Bao76be34c2017-02-07 13:30:19 -0800181static drmModeCrtc* find_crtc_for_connector(int fd, drmModeRes* resources,
182 drmModeConnector* connector) {
183 // Find the encoder. If we already have one, just use it.
184 drmModeEncoder* encoder;
185 if (connector->encoder_id) {
186 encoder = drmModeGetEncoder(fd, connector->encoder_id);
187 } else {
188 encoder = nullptr;
189 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700190
Tao Bao76be34c2017-02-07 13:30:19 -0800191 int32_t crtc;
192 if (encoder && encoder->crtc_id) {
193 crtc = encoder->crtc_id;
194 drmModeFreeEncoder(encoder);
195 return drmModeGetCrtc(fd, crtc);
196 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700197
Tao Bao76be34c2017-02-07 13:30:19 -0800198 // Didn't find anything, try to find a crtc and encoder combo.
199 crtc = -1;
200 for (int i = 0; i < connector->count_encoders; i++) {
201 encoder = drmModeGetEncoder(fd, connector->encoders[i]);
202
203 if (encoder) {
204 for (int j = 0; j < resources->count_crtcs; j++) {
205 if (!(encoder->possible_crtcs & (1 << j))) continue;
206 crtc = resources->crtcs[j];
207 break;
208 }
209 if (crtc >= 0) {
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700210 drmModeFreeEncoder(encoder);
211 return drmModeGetCrtc(fd, crtc);
Tao Bao76be34c2017-02-07 13:30:19 -0800212 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700213 }
Tao Bao76be34c2017-02-07 13:30:19 -0800214 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700215
Tao Bao76be34c2017-02-07 13:30:19 -0800216 return nullptr;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700217}
218
Tao Bao76be34c2017-02-07 13:30:19 -0800219static drmModeConnector* find_used_connector_by_type(int fd, drmModeRes* resources, unsigned type) {
220 for (int i = 0; i < resources->count_connectors; i++) {
221 drmModeConnector* connector = drmModeGetConnector(fd, resources->connectors[i]);
222 if (connector) {
223 if ((connector->connector_type == type) && (connector->connection == DRM_MODE_CONNECTED) &&
224 (connector->count_modes > 0)) {
225 return connector;
226 }
227 drmModeFreeConnector(connector);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700228 }
Tao Bao76be34c2017-02-07 13:30:19 -0800229 }
230 return nullptr;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700231}
232
Tao Bao76be34c2017-02-07 13:30:19 -0800233static drmModeConnector* find_first_connected_connector(int fd, drmModeRes* resources) {
234 for (int i = 0; i < resources->count_connectors; i++) {
235 drmModeConnector* connector;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700236
Tao Bao76be34c2017-02-07 13:30:19 -0800237 connector = drmModeGetConnector(fd, resources->connectors[i]);
238 if (connector) {
239 if ((connector->count_modes > 0) && (connector->connection == DRM_MODE_CONNECTED))
240 return connector;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700241
Tao Bao76be34c2017-02-07 13:30:19 -0800242 drmModeFreeConnector(connector);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700243 }
Tao Bao76be34c2017-02-07 13:30:19 -0800244 }
245 return nullptr;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700246}
247
Tao Bao557fa1f2017-02-07 12:51:00 -0800248drmModeConnector* MinuiBackendDrm::FindMainMonitor(int fd, drmModeRes* resources,
249 uint32_t* mode_index) {
Tao Bao76be34c2017-02-07 13:30:19 -0800250 /* Look for LVDS/eDP/DSI connectors. Those are the main screens. */
251 static constexpr unsigned kConnectorPriority[] = {
252 DRM_MODE_CONNECTOR_LVDS,
253 DRM_MODE_CONNECTOR_eDP,
254 DRM_MODE_CONNECTOR_DSI,
255 };
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700256
Tao Bao76be34c2017-02-07 13:30:19 -0800257 drmModeConnector* main_monitor_connector = nullptr;
258 unsigned i = 0;
259 do {
260 main_monitor_connector = find_used_connector_by_type(fd, resources, kConnectorPriority[i]);
261 i++;
262 } while (!main_monitor_connector && i < ARRAY_SIZE(kConnectorPriority));
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700263
Tao Bao76be34c2017-02-07 13:30:19 -0800264 /* If we didn't find a connector, grab the first one that is connected. */
265 if (!main_monitor_connector) {
266 main_monitor_connector = find_first_connected_connector(fd, resources);
267 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700268
Tao Bao76be34c2017-02-07 13:30:19 -0800269 /* If we still didn't find a connector, give up and return. */
270 if (!main_monitor_connector) return nullptr;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700271
Tao Bao76be34c2017-02-07 13:30:19 -0800272 *mode_index = 0;
273 for (int modes = 0; modes < main_monitor_connector->count_modes; modes++) {
274 if (main_monitor_connector->modes[modes].type & DRM_MODE_TYPE_PREFERRED) {
275 *mode_index = modes;
276 break;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700277 }
Tao Bao76be34c2017-02-07 13:30:19 -0800278 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700279
Tao Bao76be34c2017-02-07 13:30:19 -0800280 return main_monitor_connector;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700281}
282
Tao Bao557fa1f2017-02-07 12:51:00 -0800283void MinuiBackendDrm::DisableNonMainCrtcs(int fd, drmModeRes* resources, drmModeCrtc* main_crtc) {
Tao Bao76be34c2017-02-07 13:30:19 -0800284 for (int i = 0; i < resources->count_connectors; i++) {
285 drmModeConnector* connector = drmModeGetConnector(fd, resources->connectors[i]);
286 drmModeCrtc* crtc = find_crtc_for_connector(fd, resources, connector);
287 if (crtc->crtc_id != main_crtc->crtc_id) {
Tao Bao557fa1f2017-02-07 12:51:00 -0800288 DrmDisableCrtc(fd, crtc);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700289 }
Tao Bao76be34c2017-02-07 13:30:19 -0800290 drmModeFreeCrtc(crtc);
291 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700292}
293
Tao Bao557fa1f2017-02-07 12:51:00 -0800294GRSurface* MinuiBackendDrm::Init() {
Tao Bao76be34c2017-02-07 13:30:19 -0800295 drmModeRes* res = nullptr;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700296
Tao Bao76be34c2017-02-07 13:30:19 -0800297 /* Consider DRM devices in order. */
298 for (int i = 0; i < DRM_MAX_MINOR; i++) {
299 char* dev_name;
300 int ret = asprintf(&dev_name, DRM_DEV_NAME, DRM_DIR_NAME, i);
301 if (ret < 0) continue;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700302
Tao Bao76be34c2017-02-07 13:30:19 -0800303 drm_fd = open(dev_name, O_RDWR, 0);
304 free(dev_name);
305 if (drm_fd < 0) continue;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700306
Tao Bao76be34c2017-02-07 13:30:19 -0800307 uint64_t cap = 0;
308 /* We need dumb buffers. */
309 ret = drmGetCap(drm_fd, DRM_CAP_DUMB_BUFFER, &cap);
310 if (ret || cap == 0) {
311 close(drm_fd);
312 continue;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700313 }
314
Tao Bao76be34c2017-02-07 13:30:19 -0800315 res = drmModeGetResources(drm_fd);
316 if (!res) {
317 close(drm_fd);
318 continue;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700319 }
320
Tao Bao76be34c2017-02-07 13:30:19 -0800321 /* Use this device if it has at least one connected monitor. */
322 if (res->count_crtcs > 0 && res->count_connectors > 0) {
323 if (find_first_connected_connector(drm_fd, res)) break;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700324 }
325
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700326 drmModeFreeResources(res);
Tao Bao76be34c2017-02-07 13:30:19 -0800327 close(drm_fd);
328 res = nullptr;
329 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700330
Tao Bao76be34c2017-02-07 13:30:19 -0800331 if (drm_fd < 0 || res == nullptr) {
332 perror("cannot find/open a drm device");
333 return nullptr;
334 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700335
Tao Bao76be34c2017-02-07 13:30:19 -0800336 uint32_t selected_mode;
Tao Bao557fa1f2017-02-07 12:51:00 -0800337 main_monitor_connector = FindMainMonitor(drm_fd, res, &selected_mode);
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700338
Tao Bao76be34c2017-02-07 13:30:19 -0800339 if (!main_monitor_connector) {
340 printf("main_monitor_connector not found\n");
341 drmModeFreeResources(res);
342 close(drm_fd);
343 return nullptr;
344 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700345
Tao Bao76be34c2017-02-07 13:30:19 -0800346 main_monitor_crtc = find_crtc_for_connector(drm_fd, res, main_monitor_connector);
347
348 if (!main_monitor_crtc) {
349 printf("main_monitor_crtc not found\n");
350 drmModeFreeResources(res);
351 close(drm_fd);
352 return nullptr;
353 }
354
Tao Bao557fa1f2017-02-07 12:51:00 -0800355 DisableNonMainCrtcs(drm_fd, res, main_monitor_crtc);
Tao Bao76be34c2017-02-07 13:30:19 -0800356
357 main_monitor_crtc->mode = main_monitor_connector->modes[selected_mode];
358
359 int width = main_monitor_crtc->mode.hdisplay;
360 int height = main_monitor_crtc->mode.vdisplay;
361
362 drmModeFreeResources(res);
363
Tao Bao557fa1f2017-02-07 12:51:00 -0800364 GRSurfaceDrms[0] = DrmCreateSurface(width, height);
365 GRSurfaceDrms[1] = DrmCreateSurface(width, height);
366 if (!GRSurfaceDrms[0] || !GRSurfaceDrms[1]) {
367 // GRSurfaceDrms and drm_fd should be freed in d'tor.
Tao Bao76be34c2017-02-07 13:30:19 -0800368 return nullptr;
369 }
370
371 current_buffer = 0;
372
Tianjie Xuccf00a22018-06-05 17:10:23 -0700373 // We will likely encounter errors in the backend functions (i.e. Flip) if EnableCrtc fails.
374 if (DrmEnableCrtc(drm_fd, main_monitor_crtc, GRSurfaceDrms[1]) != 0) {
375 return nullptr;
376 }
Tao Bao76be34c2017-02-07 13:30:19 -0800377
Tao Bao557fa1f2017-02-07 12:51:00 -0800378 return GRSurfaceDrms[0];
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700379}
380
Tao Bao557fa1f2017-02-07 12:51:00 -0800381GRSurface* MinuiBackendDrm::Flip() {
382 int ret = drmModePageFlip(drm_fd, main_monitor_crtc->crtc_id,
383 GRSurfaceDrms[current_buffer]->fb_id, 0, nullptr);
Tao Bao76be34c2017-02-07 13:30:19 -0800384 if (ret < 0) {
385 printf("drmModePageFlip failed ret=%d\n", ret);
386 return nullptr;
387 }
388 current_buffer = 1 - current_buffer;
Tao Bao557fa1f2017-02-07 12:51:00 -0800389 return GRSurfaceDrms[current_buffer];
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700390}
391
Tao Bao557fa1f2017-02-07 12:51:00 -0800392MinuiBackendDrm::~MinuiBackendDrm() {
393 DrmDisableCrtc(drm_fd, main_monitor_crtc);
394 DrmDestroySurface(GRSurfaceDrms[0]);
395 DrmDestroySurface(GRSurfaceDrms[1]);
Tao Bao76be34c2017-02-07 13:30:19 -0800396 drmModeFreeCrtc(main_monitor_crtc);
397 drmModeFreeConnector(main_monitor_connector);
398 close(drm_fd);
399 drm_fd = -1;
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700400}