Skip to content

Commit

Permalink
Get menu to be same width/height as first canvas
Browse files Browse the repository at this point in the history
pass on geometry changed to ui so it can adjust when 1st canvas adjusts
fixed backwards vdc/vic index bug in videoarch.c
updated children of root menu since top/left will change
  • Loading branch information
randyrossi committed Feb 6, 2020
1 parent 56772f2 commit 7912001
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 79 deletions.
23 changes: 13 additions & 10 deletions fbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool FrameBufferLayer::initialized_ = false;
DISPMANX_DISPLAY_HANDLE_T FrameBufferLayer::dispman_display_;

FrameBufferLayer::FrameBufferLayer() :
width_(0), height_(0), pitch_(0), layer_(0), transparency_(false),
fb_width_(0), fb_height_(0), fb_pitch_(0), layer_(0), transparency_(false),
hstretch_(1.6), vstretch_(1.0),
valign_(0), vpadding_(0), halign_(0), hpadding_(0),
h_center_offset_(0), v_center_offset_(0),
Expand Down Expand Up @@ -142,18 +142,18 @@ int FrameBufferLayer::Allocate(int pixelmode, uint8_t **pixels,
pitch_multiplier = 2;

// pitch is in bytes
*pitch = pitch_ = ALIGN_UP(width * pitch_multiplier, 32);
*pitch = fb_pitch_ = ALIGN_UP(width * pitch_multiplier, 32);

width_ = width;
height_ = height;
fb_width_ = width;
fb_height_ = height;

ret = vc_dispmanx_display_get_info(dispman_display_, &dispman_info);
assert(ret == 0);

display_width_ = dispman_info.width;
display_height_ = dispman_info.height;

*pixels = pixels_ = (uint8_t*) malloc(pitch_ * height * bytes_per_pixel_);
*pixels = pixels_ = (uint8_t*) malloc(fb_pitch_ * height * bytes_per_pixel_);

// Allocate the VC resources along with the frame buffer

Expand Down Expand Up @@ -191,7 +191,7 @@ int FrameBufferLayer::Allocate(int pixelmode, uint8_t **pixels,
void FrameBufferLayer::Clear() {
assert (allocated_);

memset(pixels_, 0, height_ * pitch_ * bytes_per_pixel_);
memset(pixels_, 0, fb_height_ * fb_pitch_ * bytes_per_pixel_);
}

void FrameBufferLayer::Free() {
Expand All @@ -203,9 +203,9 @@ void FrameBufferLayer::Free() {
Hide();
}

width_ = 0;
height_ = 0;
pitch_ = 0;
fb_width_ = 0;
fb_height_ = 0;
fb_pitch_ = 0;
free(pixels_);

ret = vc_dispmanx_resource_delete(dispman_resource_[0]);
Expand Down Expand Up @@ -355,7 +355,7 @@ void FrameBufferLayer::FrameReady(int to_offscreen) {
// on screen resource (if !swap).
vc_dispmanx_resource_write_data(dispman_resource_[rnum],
mode_,
pitch_,
fb_pitch_,
pixels_,
&copy_dst_rect_);
}
Expand Down Expand Up @@ -465,10 +465,13 @@ void FrameBufferLayer::SetCenterOffset(int cx, int cy) {
}

void FrameBufferLayer::GetDimensions(int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h) {
*display_w = display_width_;
*display_h = display_height_;
*fb_w = fb_width_;
*fb_h = fb_height_;
*src_w = src_w_;
*src_h = src_h_;
*dst_w = dst_w_;
Expand Down
12 changes: 8 additions & 4 deletions fbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ class FrameBufferLayer {
// Used to force a fb into a smaller space (for things like PIP or side-by-side.
void SetPadding(double leftPadding, double rightPadding, double topPadding, double bottomPadding);

void GetDimensions(int *display_w, int *display_h, int *src_w, int *src_h, int *dst_w, int *dst_h);
// Retrieve dimensions for this layer.
void GetDimensions(int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h);

// initializes the bcm_host interface
static void Initialize();
Expand Down Expand Up @@ -123,9 +127,9 @@ class FrameBufferLayer {

static bool initialized_;

int width_;
int height_;
int pitch_;
int fb_width_;
int fb_height_;
int fb_pitch_;
int layer_;
int transparency_;
double hstretch_;
Expand Down
7 changes: 6 additions & 1 deletion kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ void circle_kernel_core_init_complete(int core) {
}

void circle_get_fbl_dimensions(int layer, int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h) {
static_kernel->circle_get_fbl_dimensions(layer, display_w, display_h,
fb_w, fb_h,
src_w, src_h, dst_w, dst_h);
}
};
Expand Down Expand Up @@ -1538,8 +1540,11 @@ void CKernel::circle_kernel_core_init_complete(int core) {

void CKernel::circle_get_fbl_dimensions(int layer,
int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h) {
return fbl[layer].GetDimensions(display_w, display_h, src_w, src_h,
return fbl[layer].GetDimensions(display_w, display_h,
fb_w, fb_h,
src_w, src_h,
dst_w, dst_h);
}
1 change: 1 addition & 0 deletions kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class CKernel : public ViceStdioApp {
void circle_kernel_core_init_complete(int core);
unsigned circle_get_arm_clock();
void circle_get_fbl_dimensions(int layer, int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h);

Expand Down
1 change: 1 addition & 0 deletions third_party/common/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ extern void circle_set_userport(uint8_t value);
extern void circle_kernel_core_init_complete(int core);
extern void circle_get_fbl_dimensions(int layer,
int *display_w, int *display_h,
int *fb_w, int *fb_h,
int *src_w, int *src_h,
int *dst_w, int *dst_h);

Expand Down
15 changes: 12 additions & 3 deletions third_party/common/emux_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,27 @@ void emux_apply_video_adjustments(int layer,
canvas_state[index].gfx_h + 2;

canvas_state[index].overlay_x = canvas_state[index].left;
}

if (layer != FB_LAYER_UI) {
circle_set_src_rect_fbl(layer,
circle_set_src_rect_fbl(layer,
canvas_state[index].left,
canvas_state[index].top,
canvas_state[index].vis_w,
canvas_state[index].vis_h);
}

if (layer == FB_LAYER_UI) {
// For the UI, we inherit the same cutout as the VIC
circle_set_src_rect_fbl(layer,
canvas_state[vic_canvas_index].left,
canvas_state[vic_canvas_index].top,
canvas_state[vic_canvas_index].vis_w,
canvas_state[vic_canvas_index].vis_h);
}

circle_set_center_offset(layer,
hcenter, vcenter);

emux_geometry_changed(layer);
}

void emu_joy_interrupt_abs(int port, int device,
Expand Down
2 changes: 1 addition & 1 deletion third_party/common/emux_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,6 @@ int is_composite();

void emux_add_userport_joys(struct menu_item* parent);

void emux_geometry_changed(int layer, int canvas_index);
void emux_geometry_changed(int layer);

#endif
78 changes: 47 additions & 31 deletions third_party/common/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,12 @@ static int compute_trim_stretch(int display_dim, int fb_dim,
}

static void do_integer_scaling(int layer, int canvas_index, int dimension) {
int dpx, dpy, dx, dy, sx, sy;
int dpx, dpy, fbw, fbh, dx, dy, sx, sy;
circle_get_fbl_dimensions(layer,
&dpx, &dpy, &sx, &sy, &dx, &dy);
&dpx, &dpy,
&fbw, &fbh,
&sx, &sy,
&dx, &dy);
int dst_trim;
int dst_stretch;
int dst_new_fb;
Expand Down Expand Up @@ -3593,47 +3596,60 @@ const char* function_to_string(int button_func) {
}
}

void emux_geometry_changed(int layer, int canvas_index) {
void emux_geometry_changed(int layer) {

// Update the allowed min for border trim items. This lets the user
// start padding the edges with negative trim values.
// These are expressed in terms of percentage of the max because they
// are going into the range item.
int max_padding_w_px = MIN(
canvas_state[canvas_index].extra_offscreen_border_left,
canvas_state[canvas_index].extra_offscreen_border_right);
int max_padding_h_px = canvas_state[canvas_index].first_displayed_line;

// Express these pixel values as negative percentage of border amts (for the menu item)
int max_padding_w = -((double)max_padding_w_px / (double)canvas_state[canvas_index].max_border_w) * 100.0;
int max_padding_h = -((double)max_padding_h_px / (double)canvas_state[canvas_index].max_border_h) * 100.0;

// Update the allowed max h stretch based on the display width and height
int dpx, dpy, dx, dy, sx, sy;
circle_get_fbl_dimensions(layer,
&dpx, &dpy, &sx, &sy, &dx, &dy);
double max_scale = ceil((double)dpx / (double)dpy);

int canvas_index = -1;
if (layer == FB_LAYER_VIC) {
h_border_trim_item_0->min = max_padding_w;
v_border_trim_item_0->min = max_padding_h;
h_stretch_item_0->max = max_scale * 1000;
canvas_index = vic_canvas_index;
} else if (layer == FB_LAYER_VDC) {
h_border_trim_item_1->min = max_padding_w;
v_border_trim_item_1->min = max_padding_h;
h_stretch_item_1->max = max_scale * 1000;
canvas_index = vdc_canvas_index;
}

// Stuff these into the canvas state
canvas_state[canvas_index].max_padding_w = max_padding_w;
canvas_state[canvas_index].max_padding_h = max_padding_w;
canvas_state[canvas_index].max_padding_w_px = max_padding_w_px;
canvas_state[canvas_index].max_padding_h_px = max_padding_w_px;
canvas_state[canvas_index].max_stretch_h = max_scale * 1000;
int dpx, dpy, fbw, fbh, dx, dy, sx, sy;
circle_get_fbl_dimensions(layer,
&dpx, &dpy,
&fbw, &fbh,
&sx, &sy,
&dx, &dy);

if (canvas_index >= 0) {
int max_padding_w_px = MIN(
canvas_state[canvas_index].extra_offscreen_border_left,
canvas_state[canvas_index].extra_offscreen_border_right);
int max_padding_h_px = canvas_state[canvas_index].first_displayed_line;

// Express these pixel values as negative percentage of border amts (for the menu item)
int max_padding_w = -((double)max_padding_w_px / (double)canvas_state[canvas_index].max_border_w) * 100.0;
int max_padding_h = -((double)max_padding_h_px / (double)canvas_state[canvas_index].max_border_h) * 100.0;

// Update the allowed max h stretch based on the display width and height
double max_scale = ceil((double)dpx / (double)dpy);

if (layer == FB_LAYER_VIC) {
h_border_trim_item_0->min = max_padding_w;
v_border_trim_item_0->min = max_padding_h;
h_stretch_item_0->max = max_scale * 1000;
} else if (layer == FB_LAYER_VDC) {
h_border_trim_item_1->min = max_padding_w;
v_border_trim_item_1->min = max_padding_h;
h_stretch_item_1->max = max_scale * 1000;
}

// Stuff these into the canvas state
canvas_state[canvas_index].max_padding_w = max_padding_w;
canvas_state[canvas_index].max_padding_h = max_padding_w;
canvas_state[canvas_index].max_padding_w_px = max_padding_w_px;
canvas_state[canvas_index].max_padding_h_px = max_padding_w_px;
canvas_state[canvas_index].max_stretch_h = max_scale * 1000;
}

if (layer == FB_LAYER_VIC) {
// When the first display changes, we need to update the UI since
// it's frame buffer dimensions must match.
ui_geometry_changed(dpx, dpy, sx, sy, dx, dy);
ui_geometry_changed(dpx, dpy, fbw, fbh, sx, sy, dx, dy);
}
}
Loading

0 comments on commit 7912001

Please sign in to comment.