Skip to content

Commit

Permalink
minui: Move graphics_{adf,drm,fbdev} into classes.
Browse files Browse the repository at this point in the history
This CL defines minui_backend as an interface, and expresses the three
backends (adf, drm and fbdev) as subclasses to the interface.

Test: 'Run graphics test' on N9, Pixel C and N5X.
Change-Id: I0e23951c7b2e2ff918957a8d9fc8b0085b6e5952
  • Loading branch information
Tao Bao committed Feb 11, 2017
1 parent df464db commit 557fa1f
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 271 deletions.
78 changes: 38 additions & 40 deletions minui/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
#include <stdlib.h>
#include <string.h>

#include <memory>

#include "font_10x18.h"
#include "graphics_adf.h"
#include "graphics_drm.h"
#include "graphics_fbdev.h"
#include "minui/minui.h"

static GRFont* gr_font = NULL;
static minui_backend* gr_backend = NULL;
static MinuiBackend* gr_backend = nullptr;

static int overscan_percent = OVERSCAN_PERCENT;
static int overscan_offset_x = 0;
Expand Down Expand Up @@ -308,59 +313,52 @@ static void gr_init_font(void)
}

void gr_flip() {
gr_draw = gr_backend->flip(gr_backend);
gr_draw = gr_backend->Flip();
}

int gr_init(void)
{
gr_init_font();
int gr_init() {
gr_init_font();

gr_backend = open_adf();
if (gr_backend) {
gr_draw = gr_backend->init(gr_backend);
if (!gr_draw) {
gr_backend->exit(gr_backend);
}
}
auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendAdf>() };
gr_draw = backend->Init();

if (!gr_draw) {
gr_backend = open_drm();
gr_draw = gr_backend->init(gr_backend);
}
if (!gr_draw) {
backend = std::make_unique<MinuiBackendDrm>();
gr_draw = backend->Init();
}

if (!gr_draw) {
gr_backend = open_fbdev();
gr_draw = gr_backend->init(gr_backend);
if (gr_draw == NULL) {
return -1;
}
}
if (!gr_draw) {
backend = std::make_unique<MinuiBackendFbdev>();
gr_draw = backend->Init();
}

overscan_offset_x = gr_draw->width * overscan_percent / 100;
overscan_offset_y = gr_draw->height * overscan_percent / 100;
if (!gr_draw) {
return -1;
}

gr_flip();
gr_flip();
gr_backend = backend.release();

return 0;
overscan_offset_x = gr_draw->width * overscan_percent / 100;
overscan_offset_y = gr_draw->height * overscan_percent / 100;

gr_flip();
gr_flip();

return 0;
}

void gr_exit(void)
{
gr_backend->exit(gr_backend);
void gr_exit() {
delete gr_backend;
}

int gr_fb_width(void)
{
return gr_draw->width - 2*overscan_offset_x;
int gr_fb_width() {
return gr_draw->width - 2 * overscan_offset_x;
}

int gr_fb_height(void)
{
return gr_draw->height - 2*overscan_offset_y;
int gr_fb_height() {
return gr_draw->height - 2 * overscan_offset_y;
}

void gr_fb_blank(bool blank)
{
gr_backend->blank(gr_backend, blank);
void gr_fb_blank(bool blank) {
gr_backend->Blank(blank);
}
29 changes: 12 additions & 17 deletions minui/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,20 @@

#include "minui/minui.h"

// TODO: lose the function pointers.
struct minui_backend {
// Initializes the backend and returns a GRSurface* to draw into.
GRSurface* (*init)(minui_backend*);
class MinuiBackend {
public:
// Initializes the backend and returns a GRSurface* to draw into.
virtual GRSurface* Init() = 0;

// Causes the current drawing surface (returned by the most recent
// call to flip() or init()) to be displayed, and returns a new
// drawing surface.
GRSurface* (*flip)(minui_backend*);
// Causes the current drawing surface (returned by the most recent call to Flip() or Init()) to
// be displayed, and returns a new drawing surface.
virtual GRSurface* Flip() = 0;

// Blank (or unblank) the screen.
void (*blank)(minui_backend*, bool);
// Blank (or unblank) the screen.
virtual void Blank(bool) = 0;

// Device cleanup when drawing is done.
void (*exit)(minui_backend*);
// Device cleanup when drawing is done.
virtual ~MinuiBackend() {};
};

minui_backend* open_fbdev();
minui_backend* open_adf();
minui_backend* open_drm();

#endif
#endif // _GRAPHICS_H_
Loading

0 comments on commit 557fa1f

Please sign in to comment.