blob: 934e584d71139051742038b06a831a16c8880b54 [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 Bao557fa1f2017-02-07 12:51:00 -080025#include "graphics.h"
26#include "minui/minui.h"
27
Tao Bao92bdb5a2018-10-21 12:12:37 -070028class GRSurfaceFbdev : public GRSurface {
29 public:
Tao Bao4a22b282018-10-31 00:00:31 -070030 // Creates and returns a GRSurfaceFbdev instance, or nullptr on error.
31 static std::unique_ptr<GRSurfaceFbdev> Create(int width, int height, int row_bytes,
32 int pixel_bytes);
33
Tao Bao92bdb5a2018-10-21 12:12:37 -070034 uint8_t* data() override {
35 return buffer_;
36 }
37
Tao Bao4a22b282018-10-31 00:00:31 -070038 protected:
39 using GRSurface::GRSurface;
40
Tao Bao92bdb5a2018-10-21 12:12:37 -070041 private:
42 friend class MinuiBackendFbdev;
43
44 // Points to the start of the buffer: either the mmap'd framebuffer or one allocated in-memory.
Tao Bao4a22b282018-10-31 00:00:31 -070045 uint8_t* buffer_{ nullptr };
Tao Bao92bdb5a2018-10-21 12:12:37 -070046};
47
Tao Bao557fa1f2017-02-07 12:51:00 -080048class MinuiBackendFbdev : public MinuiBackend {
49 public:
Tao Bao4a22b282018-10-31 00:00:31 -070050 MinuiBackendFbdev() = default;
51 ~MinuiBackendFbdev() override;
52
Tao Bao557fa1f2017-02-07 12:51:00 -080053 GRSurface* Init() override;
54 GRSurface* Flip() override;
55 void Blank(bool) override;
Tao Bao557fa1f2017-02-07 12:51:00 -080056
57 private:
Tao Bao4a22b282018-10-31 00:00:31 -070058 void SetDisplayedFramebuffer(size_t n);
Tao Bao557fa1f2017-02-07 12:51:00 -080059
Tao Bao4a22b282018-10-31 00:00:31 -070060 std::unique_ptr<GRSurfaceFbdev> gr_framebuffer[2];
61 // Points to the current surface (i.e. one of the two gr_framebuffer's).
62 GRSurfaceFbdev* gr_draw{ nullptr };
Tao Bao557fa1f2017-02-07 12:51:00 -080063 bool double_buffered;
Tao Bao4a22b282018-10-31 00:00:31 -070064 std::vector<uint8_t> memory_buffer;
65 size_t displayed_buffer{ 0 };
Tao Bao557fa1f2017-02-07 12:51:00 -080066 fb_var_screeninfo vi;
Tao Bao4a22b282018-10-31 00:00:31 -070067 int fb_fd{ -1 };
Tao Bao557fa1f2017-02-07 12:51:00 -080068};