rpi: fix build

Runtime untested, because I get this:

  [vo/rpi] Could not get DISPMANX objects.

This happened even when building older git versions, and on a RPI image
that hasn't changed in the recent years. I don't know how to make this
POS work again, so I guess if there's a bug in the new code, it will
remain broken.
This commit is contained in:
wm4 2017-08-11 13:02:13 +02:00
parent de3eecce7f
commit 697c4389a9
6 changed files with 63 additions and 59 deletions

View File

@ -36,6 +36,7 @@
#include "hwdec.h"
#include "common.h"
#include "ra_gl.h"
struct priv {
struct mp_log *log;
@ -125,13 +126,13 @@ static void disable_renderer(struct ra_hwdec *hw)
static void update_overlay(struct ra_hwdec *hw, bool check_window_only)
{
struct priv *p = hw->priv;
GL *gl = hw->gl;
GL *gl = ra_is_gl(hw->ra) ? ra_gl_get(hw->ra) : NULL;
MMAL_PORT_T *input = p->renderer->input[0];
struct mp_rect src = p->src;
struct mp_rect dst = p->dst;
int defs[4] = {0, 0, 0, 0};
int *z = mpgl_get_native_display(gl, "MPV_RPI_WINDOW");
int *z = gl ? mpgl_get_native_display(gl, "MPV_RPI_WINDOW") : NULL;
if (!z)
z = defs;
@ -285,7 +286,7 @@ static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
struct priv *p = hw->priv;
if (hw_image && !mp_image_params_equal(&p->params, &hw_image->params)) {
p->params = *params;
p->params = hw_image->params;
disable_renderer(hw);
mp_image_unrefp(&p->current_frame);
@ -300,7 +301,7 @@ static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
p->dst = *dst;
update_overlay(hw, false);
}
return;
return 0; // don't reupload
}
mp_image_unrefp(&p->current_frame);
@ -382,6 +383,5 @@ const struct ra_hwdec_driver ra_hwdec_rpi_overlay = {
.imgfmts = {IMGFMT_MMAL, IMGFMT_420P, 0},
.init = create,
.overlay_frame = overlay_frame,
.overlay_adjust = overlay_adjust,
.uninit = destroy,
};

View File

@ -66,7 +66,7 @@ struct mpgl_osd {
struct mpgl_osd_part *parts[MAX_OSD_PARTS];
const struct ra_format *fmt_table[SUBBITMAP_COUNT];
bool formats[SUBBITMAP_COUNT];
int64_t change_counter;
bool change_flag; // for reporting to API user only
// temporary
int stereo_mode;
struct mp_osd_res osd_res;
@ -81,6 +81,7 @@ struct mpgl_osd *mpgl_osd_init(struct ra *ra, struct mp_log *log,
.log = log,
.osd = osd,
.ra = ra,
.change_flag = true,
.scratch = talloc_zero_size(ctx, 1),
};
@ -189,7 +190,7 @@ static void gen_osd_cb(void *pctx, struct sub_bitmaps *imgs)
ok = false;
osd->change_id = imgs->change_id;
ctx->change_counter += 1;
ctx->change_flag = true;
}
osd->num_subparts = ok ? imgs->num_parts : 0;
@ -310,6 +311,8 @@ void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
gl_sc_blend(sc, factors[0], factors[1], factors[2], factors[3]);
gl_sc_dispatch_draw(sc, target.tex, part->vertices, part->num_vertices);
ctx->change_flag = false;
}
static void set_res(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mode)
@ -338,7 +341,7 @@ void mpgl_osd_generate(struct mpgl_osd *ctx, struct mp_osd_res res, double pts,
for (int n = 0; n < MAX_OSD_PARTS; n++) {
struct mpgl_osd_part *part = ctx->parts[n];
if (part->num_subparts != part->prev_num_subparts)
ctx->change_counter += 1;
ctx->change_flag = true;
part->prev_num_subparts = part->num_subparts;
}
}
@ -350,7 +353,9 @@ void mpgl_osd_resize(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mod
osd_resize(ctx->osd, ctx->osd_res);
}
int64_t mpgl_get_change_counter(struct mpgl_osd *ctx)
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts)
{
return ctx->change_counter;
mpgl_osd_generate(ctx, *res, pts, 0, 0);
return ctx->change_flag;
}

View File

@ -19,6 +19,7 @@ bool mpgl_osd_draw_prepare(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc);
void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc, struct fbodst target);
int64_t mpgl_get_change_counter(struct mpgl_osd *ctx);
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts);
#endif

View File

@ -180,6 +180,8 @@ struct gl_video {
struct gl_lcms *cms;
int fb_depth; // actual bits available in GL main framebuffer
struct m_color clear_color;
bool force_clear_color;
struct gl_shader_cache *sc;
@ -3000,7 +3002,7 @@ void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
bool has_frame = !!frame->current;
if (!has_frame || !mp_rect_equals(&p->dst_rect, &target_rc)) {
struct m_color c = p->opts.background;
struct m_color c = p->clear_color;
float color[4] = {c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0};
p->ra->fns->clear(p->ra, target.tex, color, &target_rc);
}
@ -3120,6 +3122,19 @@ done:
pass_report_performance(p);
}
// Use this color instead of the global option.
void gl_video_set_clear_color(struct gl_video *p, struct m_color c)
{
p->force_clear_color = true;
p->clear_color = c;
}
bool gl_video_check_osd_change(struct gl_video *p, struct mp_osd_res *res,
double pts)
{
return p->osd ? mpgl_osd_check_change(p->osd, res, pts) : false;
}
void gl_video_resize(struct gl_video *p,
struct mp_rect *src, struct mp_rect *dst,
struct mp_osd_res *osd)
@ -3605,6 +3620,9 @@ static void reinit_from_options(struct gl_video *p)
// referenced by them.
p->opts = *(struct gl_video_opts *)p->opts_cache->opts;
if (!p->force_clear_color)
p->clear_color = p->opts.background;
check_gl_features(p);
uninit_rendering(p);
gl_sc_set_cache_dir(p->sc, p->opts.shader_cache_dir);

View File

@ -168,6 +168,9 @@ void gl_video_perfdata(struct gl_video *p, struct voctrl_performance_data *out);
struct mp_csp_equalizer;
struct mp_csp_equalizer *gl_video_eq_ptr(struct gl_video *p);
void gl_video_eq_update(struct gl_video *p);
void gl_video_set_clear_color(struct gl_video *p, struct m_color color);
bool gl_video_check_osd_change(struct gl_video *p, struct mp_osd_res *osd,
double pts);
float gl_video_scale_ambient_lux(float lmin, float lmax,
float rmin, float rmax, float lux);

View File

@ -35,6 +35,7 @@
#include "common/common.h"
#include "common/msg.h"
#include "opengl/common.h"
#include "options/m_config.h"
#include "osdep/timer.h"
#include "vo.h"
@ -42,11 +43,13 @@
#include "video/mp_image.h"
#include "sub/osd.h"
#include "opengl/osd.h"
#include "opengl/ra_gl.h"
#include "opengl/video.h"
struct mp_egl_rpi {
struct mp_log *log;
struct GL *gl;
struct ra *ra;
EGLDisplay egl_display;
EGLConfig egl_config;
EGLContext egl_context;
@ -68,9 +71,8 @@ struct priv {
struct mp_osd_res osd_res;
struct mp_egl_rpi egl;
struct gl_shader_cache *sc;
struct gl_video *gl_video;
struct mpgl_osd *osd;
int64_t osd_change_counter;
MMAL_COMPONENT_T *renderer;
bool renderer_enabled;
@ -210,6 +212,10 @@ static int mp_egl_rpi_init(struct mp_egl_rpi *p, DISPMANX_ELEMENT_HANDLE_T windo
if (!p->gl->version && !p->gl->es)
goto fail;
p->ra = ra_create_gl(p->gl, p->log);
if (!p->ra)
goto fail;
return 0;
fail:
@ -241,54 +247,28 @@ static size_t layout_buffer(struct mp_image *mpi, MMAL_BUFFER_HEADER_T *buffer,
return size;
}
#define GLSL(x) gl_sc_add(p->sc, #x "\n");
#define GLSLF(...) gl_sc_addf(p->sc, __VA_ARGS__)
static void update_osd(struct vo *vo)
{
struct priv *p = vo->priv;
if (!p->enable_osd)
return;
mpgl_osd_generate(p->osd, p->osd_res, p->osd_pts, 0, 0);
int64_t osd_change_counter = mpgl_get_change_counter(p->osd);
if (p->osd_change_counter == osd_change_counter) {
if (!gl_video_check_osd_change(p->gl_video, &p->osd_res, p->osd_pts)) {
p->skip_osd = true;
return;
}
p->osd_change_counter = osd_change_counter;
MP_STATS(vo, "start rpi_osd");
p->egl.gl->ClearColor(0, 0, 0, 0);
p->egl.gl->Clear(GL_COLOR_BUFFER_BIT);
for (int n = 0; n < MAX_OSD_PARTS; n++) {
enum sub_bitmap_format fmt = mpgl_osd_get_part_format(p->osd, n);
if (!fmt)
continue;
gl_sc_uniform_sampler(p->sc, "osdtex", GL_TEXTURE_2D, 0);
switch (fmt) {
case SUBBITMAP_RGBA: {
GLSLF("// OSD (RGBA)\n");
GLSL(color = texture(osdtex, texcoord).bgra;)
break;
}
case SUBBITMAP_LIBASS: {
GLSLF("// OSD (libass)\n");
GLSL(color =
vec4(ass_color.rgb, ass_color.a * texture(osdtex, texcoord).r);)
break;
}
default:
abort();
}
gl_sc_set_vao(p->sc, mpgl_osd_get_vao(p->osd));
gl_sc_generate(p->sc);
mpgl_osd_draw_part(p->osd, p->osd_res.w, -p->osd_res.h, n);
gl_sc_reset(p->sc);
}
struct vo_frame frame = {
.pts = p->osd_pts,
};
struct fbodst target = {
.tex = ra_create_wrapped_fb(p->egl.ra, 0, p->osd_res.w, p->osd_res.h),
.flip = true,
};
gl_video_render_frame(p->gl_video, &frame, target);
ra_tex_free(p->egl.ra, &target.tex);
MP_STATS(vo, "stop rpi_osd");
}
@ -347,10 +327,9 @@ static void destroy_overlays(struct vo *vo)
vc_dispmanx_element_remove(p->update, p->window);
p->window = 0;
mpgl_osd_destroy(p->osd);
p->osd = NULL;
gl_sc_destroy(p->sc);
p->sc = NULL;
gl_video_uninit(p->gl_video);
p->gl_video = NULL;
ra_free(&p->egl.ra);
mp_egl_rpi_destroy(&p->egl);
if (p->osd_overlay)
@ -431,9 +410,8 @@ static int create_overlays(struct vo *vo)
MP_FATAL(vo, "EGL/GLES initialization for OSD renderer failed.\n");
return -1;
}
p->sc = gl_sc_create(p->egl.gl, vo->log),
p->osd = mpgl_osd_init(p->egl.gl, vo->log, vo->osd);
p->osd_change_counter = -1; // force initial overlay rendering
p->gl_video = gl_video_init(p->egl.ra, vo->log, vo->global);
gl_video_set_osd_source(p->gl_video, vo->osd);
}
p->display_fps = 0;
@ -751,7 +729,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
vo->want_redraw = true;
return VO_TRUE;
case VOCTRL_REDRAW_FRAME:
p->osd_change_counter = -1;
update_osd(vo);
return VO_TRUE;
case VOCTRL_SCREENSHOT_WIN: