convert framebuffer to class (#19800)

* class FrameBuffer

* fix build error

* remove bootlog
albatross
Dean Lee 2021-01-28 21:47:05 +08:00 committed by GitHub
parent 4f995b35d5
commit 6583206ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 35 deletions

View File

@ -12,6 +12,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <memory>
#include <thread> #include <thread>
#include <curl/curl.h> #include <curl/curl.h>
@ -183,7 +184,7 @@ struct Updater {
int fb_w, fb_h; int fb_w, fb_h;
FramebufferState *fb = NULL; std::unique_ptr<FrameBuffer> fb;
NVGcontext *vg = NULL; NVGcontext *vg = NULL;
int font_regular; int font_regular;
int font_semibold; int font_semibold;
@ -227,11 +228,9 @@ struct Updater {
void ui_init() { void ui_init() {
touch_init(&touch); touch_init(&touch);
fb = framebuffer_init("updater", 0x00001000, false, fb = std::make_unique<FrameBuffer>("updater", 0x00001000, false, &fb_w, &fb_h);
&fb_w, &fb_h);
assert(fb);
framebuffer_set_power(fb, HWC_POWER_MODE_NORMAL); fb->set_power(HWC_POWER_MODE_NORMAL);
vg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG); vg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
assert(vg); assert(vg);
@ -751,7 +750,7 @@ struct Updater {
glDisable(GL_BLEND); glDisable(GL_BLEND);
framebuffer_swap(fb); fb->swap();
assert(glGetError() == GL_NO_ERROR); assert(glGetError() == GL_NO_ERROR);

View File

@ -1,6 +1,6 @@
#include "framebuffer.h"
#include "util.h" #include "util.h"
#include <cstdio> #include <cstdio>
#include <cstdlib>
#include <cassert> #include <cassert>
#include <ui/DisplayInfo.h> #include <ui/DisplayInfo.h>
@ -32,7 +32,7 @@ struct FramebufferState {
EGLContext context; EGLContext context;
}; };
void framebuffer_swap(FramebufferState *s) { void FrameBuffer::swap() {
eglSwapBuffers(s->display, s->surface); eglSwapBuffers(s->display, s->surface);
assert(glGetError() == GL_NO_ERROR); assert(glGetError() == GL_NO_ERROR);
} }
@ -43,17 +43,15 @@ bool set_brightness(int brightness) {
return 0 == write_file("/sys/class/leds/lcd-backlight/brightness", bright, strlen(bright)); return 0 == write_file("/sys/class/leds/lcd-backlight/brightness", bright, strlen(bright));
} }
void framebuffer_set_power(FramebufferState *s, int mode) { void FrameBuffer::set_power(int mode) {
SurfaceComposerClient::setDisplayPowerMode(s->dtoken, mode); SurfaceComposerClient::setDisplayPowerMode(s->dtoken, mode);
} }
FramebufferState* framebuffer_init( FrameBuffer::FrameBuffer(const char *name, uint32_t layer, int alpha, int *out_w, int *out_h) {
const char* name, int32_t layer, int alpha,
int *out_w, int *out_h) {
status_t status; status_t status;
int success; int success;
FramebufferState *s = new FramebufferState; s = new FramebufferState;
s->session = new SurfaceComposerClient(); s->session = new SurfaceComposerClient();
assert(s->session != NULL); assert(s->session != NULL);
@ -141,6 +139,11 @@ FramebufferState* framebuffer_init(
if (out_w) *out_w = w; if (out_w) *out_w = w;
if (out_h) *out_h = h; if (out_h) *out_h = h;
}
return s;
FrameBuffer::~FrameBuffer() {
eglDestroyContext(s->display, s->context);
eglDestroySurface(s->display, s->surface);
eglTerminate(s->display);
delete s;
} }

View File

@ -1,13 +1,7 @@
#pragma once #pragma once
typedef struct FramebufferState FramebufferState; #include <cstdlib>
FramebufferState* framebuffer_init(
const char* name, int32_t layer, int alpha,
int *out_w, int *out_h);
void framebuffer_set_power(FramebufferState *s, int mode);
void framebuffer_swap(FramebufferState *s);
bool set_brightness(int brightness); bool set_brightness(int brightness);
/* Display power modes */ /* Display power modes */
@ -35,3 +29,14 @@ enum {
* functionality. */ * functionality. */
HWC_POWER_MODE_DOZE_SUSPEND = 3, HWC_POWER_MODE_DOZE_SUSPEND = 3,
}; };
struct FramebufferState;
class FrameBuffer {
public:
FrameBuffer(const char *name, uint32_t layer, int alpha, int *out_w, int *out_h);
~FrameBuffer();
void set_power(int mode);
void swap();
private:
FramebufferState *s;
};

View File

@ -3,7 +3,7 @@ Import('env', 'qt_env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc',
src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c'] src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c']
libs = [common, 'zmq', 'capnp', 'kj', 'm', 'OpenCL', cereal, messaging, gpucommon, visionipc] libs = [gpucommon, common, 'zmq', 'capnp', 'kj', 'm', 'OpenCL', cereal, messaging, visionipc]
if qt_env is None: if qt_env is None:
libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware',

View File

@ -4,7 +4,7 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <memory>
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
@ -30,7 +30,7 @@ int main(int argc, char** argv) {
// spinner // spinner
int fb_w, fb_h; int fb_w, fb_h;
FramebufferState *fb = framebuffer_init("text", 0x00001000, false, std::unique_ptr<FrameBuffer> fb = std::make_unique<FrameBuffer>("text", 0x00001000, false,
&fb_w, &fb_h); &fb_w, &fb_h);
assert(fb); assert(fb);
@ -41,7 +41,7 @@ int main(int argc, char** argv) {
assert(font >= 0); assert(font >= 0);
// Awake // Awake
framebuffer_set_power(fb, HWC_POWER_MODE_NORMAL); fb->set_power(HWC_POWER_MODE_NORMAL);
set_brightness(255); set_brightness(255);
glClearColor(0.1, 0.1, 0.1, 1.0); glClearColor(0.1, 0.1, 0.1, 1.0);
@ -106,7 +106,7 @@ int main(int argc, char** argv) {
// Draw to screen // Draw to screen
nvgEndFrame(vg); nvgEndFrame(vg);
framebuffer_swap(fb); fb->swap();
assert(glGetError() == GL_NO_ERROR); assert(glGetError() == GL_NO_ERROR);

View File

@ -53,7 +53,7 @@ static void handle_display_state(UIState *s, bool user_input) {
s->awake = should_wake; s->awake = should_wake;
int display_mode = s->awake ? HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF; int display_mode = s->awake ? HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF;
LOGW("setting display mode %d", display_mode); LOGW("setting display mode %d", display_mode);
framebuffer_set_power(s->fb, display_mode); s->fb->set_power(display_mode);
if (s->awake) { if (s->awake) {
system("service call window 18 i32 1"); system("service call window 18 i32 1");
@ -178,7 +178,7 @@ int main(int argc, char* argv[]) {
// warn on sub 15fps // warn on sub 15fps
LOGW("slow frame(%llu) time: %.2f", (s->sm)->frame, u2-u1); LOGW("slow frame(%llu) time: %.2f", (s->sm)->frame, u2-u1);
} }
framebuffer_swap(s->fb); s->fb->swap();
} }
handle_display_state(s, true); handle_display_state(s, true);

View File

@ -288,9 +288,8 @@ void GLWindow::wake() {
handle_display_state(&ui_state, true); handle_display_state(&ui_state, true);
} }
FramebufferState* framebuffer_init(const char* name, int32_t layer, int alpha, FrameBuffer::FrameBuffer(const char *name, uint32_t layer, int alpha, int *out_w, int *out_h) {
int *out_w, int *out_h) {
*out_w = vwp_w; *out_w = vwp_w;
*out_h = vwp_h; *out_h = vwp_h;
return (FramebufferState*)1; // not null
} }
FrameBuffer::~FrameBuffer() {}

View File

@ -46,8 +46,7 @@ void ui_init(UIState *s) {
s->started = false; s->started = false;
s->status = STATUS_OFFROAD; s->status = STATUS_OFFROAD;
s->fb = framebuffer_init("ui", 0, true, &s->fb_w, &s->fb_h); s->fb = std::make_unique<FrameBuffer>("ui", 0, true, &s->fb_w, &s->fb_h);
assert(s->fb);
ui_nvg_init(s); ui_nvg_init(s);

View File

@ -144,7 +144,7 @@ typedef struct UIState {
VisionBuf * last_frame; VisionBuf * last_frame;
// framebuffer // framebuffer
FramebufferState *fb; std::unique_ptr<FrameBuffer> fb;
int fb_w, fb_h; int fb_w, fb_h;
// NVG // NVG