2017-02-07 21:51:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-10-21 21:12:37 +02:00
|
|
|
#pragma once
|
2017-02-07 21:51:00 +01:00
|
|
|
|
|
|
|
#include <linux/fb.h>
|
2018-11-27 01:28:07 +01:00
|
|
|
#include <stddef.h>
|
2018-10-21 21:12:37 +02:00
|
|
|
#include <stdint.h>
|
2017-02-07 21:51:00 +01:00
|
|
|
|
2018-10-31 08:00:31 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-11-02 17:34:49 +01:00
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
|
2017-02-07 21:51:00 +01:00
|
|
|
#include "graphics.h"
|
|
|
|
#include "minui/minui.h"
|
|
|
|
|
2018-10-21 21:12:37 +02:00
|
|
|
class GRSurfaceFbdev : public GRSurface {
|
|
|
|
public:
|
2018-10-31 08:00:31 +01:00
|
|
|
// Creates and returns a GRSurfaceFbdev instance, or nullptr on error.
|
2018-11-27 01:28:07 +01:00
|
|
|
static std::unique_ptr<GRSurfaceFbdev> Create(size_t width, size_t height, size_t row_bytes,
|
|
|
|
size_t pixel_bytes);
|
2018-10-31 08:00:31 +01:00
|
|
|
|
2018-10-21 21:12:37 +02:00
|
|
|
uint8_t* data() override {
|
|
|
|
return buffer_;
|
|
|
|
}
|
|
|
|
|
2018-10-31 08:00:31 +01:00
|
|
|
protected:
|
|
|
|
using GRSurface::GRSurface;
|
|
|
|
|
2018-10-21 21:12:37 +02:00
|
|
|
private:
|
|
|
|
friend class MinuiBackendFbdev;
|
|
|
|
|
|
|
|
// Points to the start of the buffer: either the mmap'd framebuffer or one allocated in-memory.
|
2018-10-31 08:00:31 +01:00
|
|
|
uint8_t* buffer_{ nullptr };
|
2018-10-21 21:12:37 +02:00
|
|
|
};
|
|
|
|
|
2017-02-07 21:51:00 +01:00
|
|
|
class MinuiBackendFbdev : public MinuiBackend {
|
|
|
|
public:
|
2018-10-31 08:00:31 +01:00
|
|
|
MinuiBackendFbdev() = default;
|
2018-11-02 17:34:49 +01:00
|
|
|
~MinuiBackendFbdev() override = default;
|
2018-10-31 08:00:31 +01:00
|
|
|
|
2017-02-07 21:51:00 +01:00
|
|
|
GRSurface* Init() override;
|
|
|
|
GRSurface* Flip() override;
|
|
|
|
void Blank(bool) override;
|
2021-09-27 05:30:26 +02:00
|
|
|
void Blank(bool blank, DrmConnector index) override;
|
2022-07-19 10:34:43 +02:00
|
|
|
bool HasMultipleConnectors() override;
|
2017-02-07 21:51:00 +01:00
|
|
|
|
|
|
|
private:
|
2018-10-31 08:00:31 +01:00
|
|
|
void SetDisplayedFramebuffer(size_t n);
|
2017-02-07 21:51:00 +01:00
|
|
|
|
2018-10-31 08:00:31 +01:00
|
|
|
std::unique_ptr<GRSurfaceFbdev> gr_framebuffer[2];
|
|
|
|
// Points to the current surface (i.e. one of the two gr_framebuffer's).
|
|
|
|
GRSurfaceFbdev* gr_draw{ nullptr };
|
2017-02-07 21:51:00 +01:00
|
|
|
bool double_buffered;
|
2018-10-31 08:00:31 +01:00
|
|
|
std::vector<uint8_t> memory_buffer;
|
|
|
|
size_t displayed_buffer{ 0 };
|
2017-02-07 21:51:00 +01:00
|
|
|
fb_var_screeninfo vi;
|
2018-11-02 17:34:49 +01:00
|
|
|
android::base::unique_fd fb_fd;
|
2017-02-07 21:51:00 +01:00
|
|
|
};
|