Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 1 | /* |
| 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 Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 17 | #pragma once |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 18 | |
| 19 | #include <stdint.h> |
| 20 | |
| 21 | #include <xf86drmMode.h> |
| 22 | |
| 23 | #include "graphics.h" |
| 24 | #include "minui/minui.h" |
| 25 | |
| 26 | class GRSurfaceDrm : public GRSurface { |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 27 | public: |
| 28 | uint8_t* data() override { |
| 29 | return mmapped_buffer_; |
| 30 | } |
| 31 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 32 | private: |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 33 | friend class MinuiBackendDrm; |
| 34 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 35 | uint32_t fb_id; |
| 36 | uint32_t handle; |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 37 | uint8_t* mmapped_buffer_{ nullptr }; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | class 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 Xu | ccf00a2 | 2018-06-05 17:10:23 -0700 | [diff] [blame] | 50 | int DrmEnableCrtc(int drm_fd, drmModeCrtc* crtc, GRSurfaceDrm* surface); |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 51 | 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 | }; |