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