From 4a22b28bea62852288e481f8e901939df94f87af Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 31 Oct 2018 00:00:31 -0700 Subject: minui: Refactor GRSurfaceFbdev. - Adds Create() that returns a GRSurfaceFbdev instance. - Moves away from using the copy ctor (precisely assignment operator) of GRSurfaceFbdev. - Moves the GRSurfaceFbdev deallocation code into GRSurfaceFbdev's dtor. - Manages MinuiBackendFbdev::gr_framebuffer with std::unique_ptr. Test: mmma -j bootable/recovery Test: `Run graphics test` on taimen. Change-Id: I8e67cda7bc3a2feec0790124d035caa36fb58a89 --- minui/graphics_fbdev.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'minui/graphics_fbdev.h') diff --git a/minui/graphics_fbdev.h b/minui/graphics_fbdev.h index be813dccb..934e584d7 100644 --- a/minui/graphics_fbdev.h +++ b/minui/graphics_fbdev.h @@ -19,37 +19,50 @@ #include #include +#include +#include + #include "graphics.h" #include "minui/minui.h" class GRSurfaceFbdev : public GRSurface { public: + // Creates and returns a GRSurfaceFbdev instance, or nullptr on error. + static std::unique_ptr Create(int width, int height, int row_bytes, + int pixel_bytes); + uint8_t* data() override { return buffer_; } + protected: + using GRSurface::GRSurface; + private: friend class MinuiBackendFbdev; // Points to the start of the buffer: either the mmap'd framebuffer or one allocated in-memory. - uint8_t* buffer_; + uint8_t* buffer_{ nullptr }; }; class MinuiBackendFbdev : public MinuiBackend { public: + MinuiBackendFbdev() = default; + ~MinuiBackendFbdev() override; + GRSurface* Init() override; GRSurface* Flip() override; void Blank(bool) override; - ~MinuiBackendFbdev() override; - MinuiBackendFbdev(); private: - void SetDisplayedFramebuffer(unsigned n); + void SetDisplayedFramebuffer(size_t n); - GRSurfaceFbdev gr_framebuffer[2]; + std::unique_ptr gr_framebuffer[2]; + // Points to the current surface (i.e. one of the two gr_framebuffer's). + GRSurfaceFbdev* gr_draw{ nullptr }; bool double_buffered; - GRSurfaceFbdev* gr_draw; - int displayed_buffer; + std::vector memory_buffer; + size_t displayed_buffer{ 0 }; fb_var_screeninfo vi; - int fb_fd; + int fb_fd{ -1 }; }; -- cgit v1.2.3