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