blob: f3aad6bfca66c65ad3def6cfa7f99fd0300a7d25 [file] [log] [blame]
Tao Bao557fa1f2017-02-07 12:51:00 -08001/*
2 * Copyright (C) 2017 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 Bao92bdb5a2018-10-21 12:12:37 -070017#pragma once
Tao Bao557fa1f2017-02-07 12:51:00 -080018
19#include <stdint.h>
20
21#include <xf86drmMode.h>
22
23#include "graphics.h"
24#include "minui/minui.h"
25
26class GRSurfaceDrm : public GRSurface {
Tao Bao92bdb5a2018-10-21 12:12:37 -070027 public:
28 uint8_t* data() override {
29 return mmapped_buffer_;
30 }
31
Tao Bao557fa1f2017-02-07 12:51:00 -080032 private:
Tao Bao92bdb5a2018-10-21 12:12:37 -070033 friend class MinuiBackendDrm;
34
Tao Bao557fa1f2017-02-07 12:51:00 -080035 uint32_t fb_id;
36 uint32_t handle;
Tao Bao92bdb5a2018-10-21 12:12:37 -070037 uint8_t* mmapped_buffer_{ nullptr };
Tao Bao557fa1f2017-02-07 12:51:00 -080038};
39
40class MinuiBackendDrm : public MinuiBackend {
41 public:
42 GRSurface* Init() override;
43 GRSurface* Flip() override;
44 void Blank(bool) override;
45 ~MinuiBackendDrm() override;
46 MinuiBackendDrm();
47
48 private:
49 void DrmDisableCrtc(int drm_fd, drmModeCrtc* crtc);
Tianjie Xuccf00a22018-06-05 17:10:23 -070050 int DrmEnableCrtc(int drm_fd, drmModeCrtc* crtc, GRSurfaceDrm* surface);
Tao Bao557fa1f2017-02-07 12:51:00 -080051 GRSurfaceDrm* DrmCreateSurface(int width, int height);
52 void DrmDestroySurface(GRSurfaceDrm* surface);
53 void DisableNonMainCrtcs(int fd, drmModeRes* resources, drmModeCrtc* main_crtc);
54 drmModeConnector* FindMainMonitor(int fd, drmModeRes* resources, uint32_t* mode_index);
55
56 GRSurfaceDrm* GRSurfaceDrms[2];
57 int current_buffer;
58 drmModeCrtc* main_monitor_crtc;
59 drmModeConnector* main_monitor_connector;
60 int drm_fd;
61};