blob: bf9842878176378ecb8e7a2eb269d2d8059525e3 [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
19#include <stdint.h>
Tao Bao1b18cf52018-10-31 00:12:11 -070020#include <sys/types.h>
21
22#include <memory>
Tao Bao557fa1f2017-02-07 12:51:00 -080023
24#include <adf/adf.h>
25
26#include "graphics.h"
Tao Bao92bdb5a2018-10-21 12:12:37 -070027#include "minui/minui.h"
Tao Bao557fa1f2017-02-07 12:51:00 -080028
29class GRSurfaceAdf : public GRSurface {
Tao Bao92bdb5a2018-10-21 12:12:37 -070030 public:
Tao Bao1b18cf52018-10-31 00:12:11 -070031 ~GRSurfaceAdf() override;
32
33 static std::unique_ptr<GRSurfaceAdf> Create(int intf_fd, const drm_mode_modeinfo* mode,
34 __u32 format, int* err);
35
Tao Bao92bdb5a2018-10-21 12:12:37 -070036 uint8_t* data() override {
37 return mmapped_buffer_;
38 }
39
Tao Bao557fa1f2017-02-07 12:51:00 -080040 private:
Tao Bao92bdb5a2018-10-21 12:12:37 -070041 friend class MinuiBackendAdf;
42
Tao Bao1b18cf52018-10-31 00:12:11 -070043 GRSurfaceAdf(int width, int height, int row_bytes, int pixel_bytes, __u32 offset, __u32 pitch,
44 int fd)
45 : GRSurface(width, height, row_bytes, pixel_bytes), offset(offset), pitch(pitch), fd(fd) {}
Tao Bao557fa1f2017-02-07 12:51:00 -080046
Tao Bao1b18cf52018-10-31 00:12:11 -070047 const __u32 offset;
48 const __u32 pitch;
49
50 int fd;
51 int fence_fd{ -1 };
Tao Bao92bdb5a2018-10-21 12:12:37 -070052 uint8_t* mmapped_buffer_{ nullptr };
Tao Bao557fa1f2017-02-07 12:51:00 -080053};
54
55class MinuiBackendAdf : public MinuiBackend {
56 public:
Tao Bao1b18cf52018-10-31 00:12:11 -070057 MinuiBackendAdf();
58 ~MinuiBackendAdf() override;
Tao Bao557fa1f2017-02-07 12:51:00 -080059 GRSurface* Init() override;
60 GRSurface* Flip() override;
61 void Blank(bool) override;
Tao Bao557fa1f2017-02-07 12:51:00 -080062
63 private:
Tao Bao557fa1f2017-02-07 12:51:00 -080064 int InterfaceInit();
65 int DeviceInit(adf_device* dev);
Tao Bao557fa1f2017-02-07 12:51:00 -080066 void Sync(GRSurfaceAdf* surf);
67
68 int intf_fd;
69 adf_id_t eng_id;
70 __u32 format;
71 adf_device dev;
Tao Bao1b18cf52018-10-31 00:12:11 -070072 size_t current_surface;
73 size_t n_surfaces;
74 std::unique_ptr<GRSurfaceAdf> surfaces[2];
Tao Bao557fa1f2017-02-07 12:51:00 -080075};