blob: c772428dc79daf4998bf249c7ecc120dcb19988c [file] [log] [blame]
Tao Bao557fa1f2017-02-07 12:51:00 -08001/*
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 Bao92bdb5a2018-10-21 12:12:37 -070017#pragma once
Tao Bao557fa1f2017-02-07 12:51:00 -080018
19#include <linux/fb.h>
Tao Baodd789822018-11-26 16:28:07 -080020#include <stddef.h>
Tao Bao92bdb5a2018-10-21 12:12:37 -070021#include <stdint.h>
Tao Bao557fa1f2017-02-07 12:51:00 -080022
Tao Bao4a22b282018-10-31 00:00:31 -070023#include <memory>
24#include <vector>
25
Tao Baof65d48b2018-11-02 09:34:49 -070026#include <android-base/unique_fd.h>
27
Tao Bao557fa1f2017-02-07 12:51:00 -080028#include "graphics.h"
29#include "minui/minui.h"
30
Tao Bao92bdb5a2018-10-21 12:12:37 -070031class GRSurfaceFbdev : public GRSurface {
32 public:
Tao Bao4a22b282018-10-31 00:00:31 -070033 // Creates and returns a GRSurfaceFbdev instance, or nullptr on error.
Tao Baodd789822018-11-26 16:28:07 -080034 static std::unique_ptr<GRSurfaceFbdev> Create(size_t width, size_t height, size_t row_bytes,
35 size_t pixel_bytes);
Tao Bao4a22b282018-10-31 00:00:31 -070036
Tao Bao92bdb5a2018-10-21 12:12:37 -070037 uint8_t* data() override {
38 return buffer_;
39 }
40
Tao Bao4a22b282018-10-31 00:00:31 -070041 protected:
42 using GRSurface::GRSurface;
43
Tao Bao92bdb5a2018-10-21 12:12:37 -070044 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 Bao4a22b282018-10-31 00:00:31 -070048 uint8_t* buffer_{ nullptr };
Tao Bao92bdb5a2018-10-21 12:12:37 -070049};
50
Tao Bao557fa1f2017-02-07 12:51:00 -080051class MinuiBackendFbdev : public MinuiBackend {
52 public:
Tao Bao4a22b282018-10-31 00:00:31 -070053 MinuiBackendFbdev() = default;
Tao Baof65d48b2018-11-02 09:34:49 -070054 ~MinuiBackendFbdev() override = default;
Tao Bao4a22b282018-10-31 00:00:31 -070055
Tao Bao557fa1f2017-02-07 12:51:00 -080056 GRSurface* Init() override;
57 GRSurface* Flip() override;
58 void Blank(bool) override;
Weizhung Dingf4dfa1a2021-09-27 11:30:26 +080059 void Blank(bool blank, DrmConnector index) override;
Weizhung Dinge43c5032022-07-19 16:34:43 +080060 bool HasMultipleConnectors() override;
Tao Bao557fa1f2017-02-07 12:51:00 -080061
62 private:
Tao Bao4a22b282018-10-31 00:00:31 -070063 void SetDisplayedFramebuffer(size_t n);
Tao Bao557fa1f2017-02-07 12:51:00 -080064
Tao Bao4a22b282018-10-31 00:00:31 -070065 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 };
Tao Bao557fa1f2017-02-07 12:51:00 -080068 bool double_buffered;
Tao Bao4a22b282018-10-31 00:00:31 -070069 std::vector<uint8_t> memory_buffer;
70 size_t displayed_buffer{ 0 };
Tao Bao557fa1f2017-02-07 12:51:00 -080071 fb_var_screeninfo vi;
Tao Baof65d48b2018-11-02 09:34:49 -070072 android::base::unique_fd fb_fd;
Tao Bao557fa1f2017-02-07 12:51:00 -080073};