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 |
| 18 | |
Tao Bao | dd78982 | 2018-11-26 16:28:07 -0800 | [diff] [blame] | 19 | #include <stddef.h> |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <memory> |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 24 | |
| 25 | #include <adf/adf.h> |
| 26 | |
| 27 | #include "graphics.h" |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 28 | #include "minui/minui.h" |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 29 | |
| 30 | class GRSurfaceAdf : public GRSurface { |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 31 | public: |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 32 | ~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 Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 37 | uint8_t* data() override { |
| 38 | return mmapped_buffer_; |
| 39 | } |
| 40 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 41 | private: |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 42 | friend class MinuiBackendAdf; |
| 43 | |
Tao Bao | dd78982 | 2018-11-26 16:28:07 -0800 | [diff] [blame] | 44 | GRSurfaceAdf(size_t width, size_t height, size_t row_bytes, size_t pixel_bytes, __u32 offset, |
| 45 | __u32 pitch, int fd) |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 46 | : GRSurface(width, height, row_bytes, pixel_bytes), offset(offset), pitch(pitch), fd(fd) {} |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 47 | |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 48 | const __u32 offset; |
| 49 | const __u32 pitch; |
| 50 | |
| 51 | int fd; |
| 52 | int fence_fd{ -1 }; |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 53 | uint8_t* mmapped_buffer_{ nullptr }; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | class MinuiBackendAdf : public MinuiBackend { |
| 57 | public: |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 58 | MinuiBackendAdf(); |
| 59 | ~MinuiBackendAdf() override; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 60 | GRSurface* Init() override; |
| 61 | GRSurface* Flip() override; |
| 62 | void Blank(bool) override; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 63 | |
| 64 | private: |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 65 | int InterfaceInit(); |
| 66 | int DeviceInit(adf_device* dev); |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 67 | void Sync(GRSurfaceAdf* surf); |
| 68 | |
| 69 | int intf_fd; |
| 70 | adf_id_t eng_id; |
| 71 | __u32 format; |
| 72 | adf_device dev; |
Tao Bao | 1b18cf5 | 2018-10-31 00:12:11 -0700 | [diff] [blame] | 73 | size_t current_surface; |
| 74 | size_t n_surfaces; |
| 75 | std::unique_ptr<GRSurfaceAdf> surfaces[2]; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 76 | }; |