blob: 016ab88bce87cfe797bd6db50d47be63e220b347 [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 Bao92bdb5a2018-10-21 12:12:37 -070020#include <stdint.h>
Tao Bao557fa1f2017-02-07 12:51:00 -080021
Tao Bao4a22b282018-10-31 00:00:31 -070022#include <memory>
23#include <vector>
24
Tao Baof65d48b2018-11-02 09:34:49 -070025#include <android-base/unique_fd.h>
26
Tao Bao557fa1f2017-02-07 12:51:00 -080027#include "graphics.h"
28#include "minui/minui.h"
29
Tao Bao92bdb5a2018-10-21 12:12:37 -070030class GRSurfaceFbdev : public GRSurface {
31 public:
Tao Bao4a22b282018-10-31 00:00:31 -070032 // 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 Bao92bdb5a2018-10-21 12:12:37 -070036 uint8_t* data() override {
37 return buffer_;
38 }
39
Tao Bao4a22b282018-10-31 00:00:31 -070040 protected:
41 using GRSurface::GRSurface;
42
Tao Bao92bdb5a2018-10-21 12:12:37 -070043 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 Bao4a22b282018-10-31 00:00:31 -070047 uint8_t* buffer_{ nullptr };
Tao Bao92bdb5a2018-10-21 12:12:37 -070048};
49
Tao Bao557fa1f2017-02-07 12:51:00 -080050class MinuiBackendFbdev : public MinuiBackend {
51 public:
Tao Bao4a22b282018-10-31 00:00:31 -070052 MinuiBackendFbdev() = default;
Tao Baof65d48b2018-11-02 09:34:49 -070053 ~MinuiBackendFbdev() override = default;
Tao Bao4a22b282018-10-31 00:00:31 -070054
Tao Bao557fa1f2017-02-07 12:51:00 -080055 GRSurface* Init() override;
56 GRSurface* Flip() override;
57 void Blank(bool) override;
Tao Bao557fa1f2017-02-07 12:51:00 -080058
59 private:
Tao Bao4a22b282018-10-31 00:00:31 -070060 void SetDisplayedFramebuffer(size_t n);
Tao Bao557fa1f2017-02-07 12:51:00 -080061
Tao Bao4a22b282018-10-31 00:00:31 -070062 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 Bao557fa1f2017-02-07 12:51:00 -080065 bool double_buffered;
Tao Bao4a22b282018-10-31 00:00:31 -070066 std::vector<uint8_t> memory_buffer;
67 size_t displayed_buffer{ 0 };
Tao Bao557fa1f2017-02-07 12:51:00 -080068 fb_var_screeninfo vi;
Tao Baof65d48b2018-11-02 09:34:49 -070069 android::base::unique_fd fb_fd;
Tao Bao557fa1f2017-02-07 12:51:00 -080070};