• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UPDATER_UI_DRM_DRIVER_H
17 #define UPDATER_UI_DRM_DRIVER_H
18 #include <cerrno>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cstring>
22 #include <drm_fourcc.h>
23 #include <fcntl.h>
24 #include <linux/fb.h>
25 #include <poll.h>
26 #include <sys/mman.h>
27 #include <xf86drm.h>
28 #include <xf86drmMode.h>
29 
30 namespace updater {
31 struct BufferObject {
32     uint32_t width;
33     uint32_t height;
34     uint32_t pitch;
35     uint32_t handle;
36     uint32_t size;
37     uint8_t *vaddr;
38     uint32_t fbId;
39 };
40 
41 class DrmDriver {
42 protected:
DrmDriver()43     DrmDriver() : fd_(-1), conn_(nullptr), res_(nullptr) {}
44     virtual ~DrmDriver();
45     void FlipBuffer(const void* buf);
46     void LoadDrmDriver();
47 private:
48     int ModesetCreateFb(struct BufferObject *bo);
49     void ModesetDestroyFb(struct BufferObject *bo);
50     int DrmInit();
51     int fd_;
52     drmModeConnector *conn_;
53     drmModeRes *res_;
54     struct BufferObject buff_ {};
55 };
56 } // namespace updater
57 #endif
58