blob: 79d8d2acbf1b6ae2ff47e43f7675cf1a9138cd2c [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
18
Tao Baodd789822018-11-26 16:28:07 -080019#include <stddef.h>
Tao Bao92bdb5a2018-10-21 12:12:37 -070020#include <stdint.h>
Tao Bao1b18cf52018-10-31 00:12:11 -070021#include <sys/types.h>
22
23#include <memory>
Tao Bao557fa1f2017-02-07 12:51:00 -080024
25#include <adf/adf.h>
26
27#include "graphics.h"
Tao Bao92bdb5a2018-10-21 12:12:37 -070028#include "minui/minui.h"
Tao Bao557fa1f2017-02-07 12:51:00 -080029
30class GRSurfaceAdf : public GRSurface {
Tao Bao92bdb5a2018-10-21 12:12:37 -070031 public:
Tao Bao1b18cf52018-10-31 00:12:11 -070032 ~GRSurfaceAdf() override;
33
34 static std::unique_ptr<GRSurfaceAdf> Create(int intf_fd, const drm_mode_modeinfo* mode,
35 __u32 format, int* err);
36
Tao Bao92bdb5a2018-10-21 12:12:37 -070037 uint8_t* data() override {
38 return mmapped_buffer_;
39 }
40
Tao Bao557fa1f2017-02-07 12:51:00 -080041 private:
Tao Bao92bdb5a2018-10-21 12:12:37 -070042 friend class MinuiBackendAdf;
43
Tao Baodd789822018-11-26 16:28:07 -080044 GRSurfaceAdf(size_t width, size_t height, size_t row_bytes, size_t pixel_bytes, __u32 offset,
45 __u32 pitch, int fd)
Tao Bao1b18cf52018-10-31 00:12:11 -070046 : GRSurface(width, height, row_bytes, pixel_bytes), offset(offset), pitch(pitch), fd(fd) {}
Tao Bao557fa1f2017-02-07 12:51:00 -080047
Tao Bao1b18cf52018-10-31 00:12:11 -070048 const __u32 offset;
49 const __u32 pitch;
50
51 int fd;
52 int fence_fd{ -1 };
Tao Bao92bdb5a2018-10-21 12:12:37 -070053 uint8_t* mmapped_buffer_{ nullptr };
Tao Bao557fa1f2017-02-07 12:51:00 -080054};
55
56class MinuiBackendAdf : public MinuiBackend {
57 public:
Tao Bao1b18cf52018-10-31 00:12:11 -070058 MinuiBackendAdf();
59 ~MinuiBackendAdf() override;
Tao Bao557fa1f2017-02-07 12:51:00 -080060 GRSurface* Init() override;
61 GRSurface* Flip() override;
62 void Blank(bool) override;
Tao Bao557fa1f2017-02-07 12:51:00 -080063
64 private:
Tao Bao557fa1f2017-02-07 12:51:00 -080065 int InterfaceInit();
66 int DeviceInit(adf_device* dev);
Tao Bao557fa1f2017-02-07 12:51:00 -080067 void Sync(GRSurfaceAdf* surf);
68
69 int intf_fd;
70 adf_id_t eng_id;
71 __u32 format;
72 adf_device dev;
Tao Bao1b18cf52018-10-31 00:12:11 -070073 size_t current_surface;
74 size_t n_surfaces;
75 std::unique_ptr<GRSurfaceAdf> surfaces[2];
Tao Bao557fa1f2017-02-07 12:51:00 -080076};