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 <linux/fb.h> 20 #include <stddef.h> 21 #include <stdint.h> 22 23 #include <memory> 24 #include <vector> 25 26 #include <android-base/unique_fd.h> 27 28 #include "graphics.h" 29 #include "minui/minui.h" 30 31 class GRSurfaceFbdev : public GRSurface { 32 public: 33 // Creates and returns a GRSurfaceFbdev instance, or nullptr on error. 34 static std::unique_ptr<GRSurfaceFbdev> Create(size_t width, size_t height, size_t row_bytes, 35 size_t pixel_bytes); 36 data()37 uint8_t* data() override { 38 return buffer_; 39 } 40 41 protected: 42 using GRSurface::GRSurface; 43 44 private: 45 friend class MinuiBackendFbdev; 46 47 // Points to the start of the buffer: either the mmap'd framebuffer or one allocated in-memory. 48 uint8_t* buffer_{ nullptr }; 49 }; 50 51 class MinuiBackendFbdev : public MinuiBackend { 52 public: 53 MinuiBackendFbdev() = default; 54 ~MinuiBackendFbdev() override = default; 55 56 GRSurface* Init() override; 57 GRSurface* Flip() override; 58 void Blank(bool) override; 59 void Blank(bool blank, DrmConnector index) override; 60 bool HasMultipleConnectors() override; 61 62 private: 63 void SetDisplayedFramebuffer(size_t n); 64 65 std::unique_ptr<GRSurfaceFbdev> gr_framebuffer[2]; 66 // Points to the current surface (i.e. one of the two gr_framebuffer's). 67 GRSurfaceFbdev* gr_draw{ nullptr }; 68 bool double_buffered; 69 std::vector<uint8_t> memory_buffer; 70 size_t displayed_buffer{ 0 }; 71 fb_var_screeninfo vi; 72 android::base::unique_fd fb_fd; 73 }; 74