blob: 5df923fca0d817ac14130dc5610a6b8f377984b2 [file] [log] [blame]
Andrew F. Davis8eaa2bf2018-07-24 08:20:35 -05001/*
2 * Copyright (C) Texas Instruments Incorporated - http://www.ti.com/
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
17#pragma once
18
19#include <condition_variable>
20#include <mutex>
21
22#include <cstdbool>
23#include <cstdint>
24
25#include <hardware/hwcomposer.h>
26#include <kms++/kms++.h>
27
28#include <xf86drm.h>
29#include <xf86drmMode.h>
30
31#include "drmfb.h"
32
33#define MAX_DISPLAYS 4
34#define DSS_AVAILABLE_PIPES 4
35
36typedef struct display_config {
37 unsigned int xres;
38 unsigned int yres;
39 unsigned int fps;
40 unsigned int xdpi;
41 unsigned int ydpi;
42} display_config_t;
43
44enum disp_role {
45 DISP_ROLE_PRIMARY = 0,
46 DISP_ROLE_SECONDARY,
47};
48
49typedef struct drm_plane_props {
50 hwc_layer_1_t* layer;
51
52 kms::Plane* plane;
53 uint64_t crtc_id;
54
55 uint64_t crtc_x;
56 uint64_t crtc_y;
57 uint64_t crtc_w;
58 uint64_t crtc_h;
59 uint64_t src_x;
60 uint64_t src_y;
61 uint64_t src_w;
62 uint64_t src_h;
63
64 uint64_t rotation;
65 uint64_t zorder;
66 uint64_t pre_mult_alpha;
67
68 DRMFramebuffer* fb_info;
69} drm_plane_props_t;
70
71class KMSDisplay {
72public:
73 KMSDisplay() :
74 card(NULL),
75 con(NULL),
76 crtc(NULL),
77 mode() {}
78
79 kms::Card* card;
80 kms::Connector* con;
81 kms::Crtc* crtc;
82 kms::Videomode mode;
83};
84
85class HWCDisplay
86{
87public:
88 HWCDisplay(enum disp_role role);
89 ~HWCDisplay(){};
90
91 void setup_composition_pipes();
92
93 int update_display(drm_plane_props_t* planeProp);
94
95 std::vector<display_config_t> configs;
96 uint32_t active_config;
97
98 enum disp_role role;
99
100 drm_plane_props_t planeProps[DSS_AVAILABLE_PIPES];
101
102 KMSDisplay disp_link;
103
104 const hwc_procs_t* cb_procs;
105
106 bool is_dummy;
107
108 int set_vsync_state(bool state);
109 void blank(int blank);
110 int get_display_configs(uint32_t* configs, size_t* numConfigs);
111 int get_display_attributes(uint32_t cfg, const uint32_t* attributes, int32_t* values);
112
113 static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void* data);
114 static void vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void* data);
115
116private:
117 std::vector<DRMFramebuffer*> pending_fb_infos;
118 std::vector<DRMFramebuffer*> current_fb_infos;
119
120 bool vsync_on;
121 bool blanked;
122
123 std::mutex mutex;
124 std::condition_variable cond_flip;
125 volatile bool is_flip_pending;
126};