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