summaryrefslogtreecommitdiff
path: root/src/screen
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen')
-rw-r--r--src/screen/screen.c12
-rw-r--r--src/screen/view.c4
-rw-r--r--src/screen/view.h20
3 files changed, 26 insertions, 10 deletions
diff --git a/src/screen/screen.c b/src/screen/screen.c
index 21715a6..c0527c3 100644
--- a/src/screen/screen.c
+++ b/src/screen/screen.c
@@ -670,14 +670,12 @@ static void add_buffer_internal(struct camu_screen *scr, struct camu_video_buffe
struct camu_video_format *fmt = &buf->fmt.req;
if (buf->view.mode != CAMU_VIEW_NONE) {
video.view = buf->view;
-#if 0
- } else if (scr->videos.count > 0) {
- video.view = al_array_last(scr->videos).view;
- video.view.width = fmt->width;
- video.view.height = fmt->height;
-#endif
} else {
- camu_view_init(&video.view, fmt->width, fmt->height);
+ u8 rotation = buf->view.rotation;
+ if (rotation != CAMU_VIEW_ROTATION_0) {
+ log_info("Buffer has initial rotation of %s degrees.", camu_view_rotation_name(rotation));
+ }
+ camu_view_init(&video.view, fmt->width, fmt->height, rotation);
}
camu_view_calculate(&video.view, scr->width, scr->height);
al_array_push(scr->videos, video);
diff --git a/src/screen/view.c b/src/screen/view.c
index 81d19a9..fadc81c 100644
--- a/src/screen/view.c
+++ b/src/screen/view.c
@@ -19,10 +19,10 @@
#define VIEW_ON_ITS_SIDE(view) \
(view->rotation % CAMU_VIEW_ROTATION_180 == CAMU_VIEW_ROTATION_90)
-void camu_view_init(struct camu_view *view, u32 width, u32 height)
+void camu_view_init(struct camu_view *view, u32 width, u32 height, u8 rotation)
{
view->mode = CAMU_DEFAULT_VIEW;
- view->rotation = CAMU_VIEW_ROTATION_0;
+ view->rotation = rotation;
view->width = width;
view->height = height;
view->zindex = 0;
diff --git a/src/screen/view.h b/src/screen/view.h
index 5fd86c0..ae6a357 100644
--- a/src/screen/view.h
+++ b/src/screen/view.h
@@ -40,7 +40,25 @@ struct camu_view {
f64 fov;
};
-void camu_view_init(struct camu_view *view, u32 width, u32 height);
+static inline const char *camu_view_rotation_name(u8 rotation)
+{
+ switch (rotation) {
+ case CAMU_VIEW_ROTATION_0: return "0";
+ case CAMU_VIEW_ROTATION_90: return "90";
+ case CAMU_VIEW_ROTATION_180: return "180";
+ case CAMU_VIEW_ROTATION_270: return "270";
+ case CAMU_VIEW_ROTATION_360: return "360";
+ }
+ al_assert_and_return("");
+}
+
+// This handles wrapping backwards for negative numbers.
+static inline u8 camu_view_normalize_rotation(s32 rotation)
+{
+ return (u8)((rotation % CAMU_VIEW_ROTATION_360 + CAMU_VIEW_ROTATION_360) % CAMU_VIEW_ROTATION_360);
+}
+
+void camu_view_init(struct camu_view *view, u32 width, u32 height, u8 rotation);
void camu_view_calculate(struct camu_view *view, u32 window_width, u32 window_height);
bool camu_view_zoom_simple(struct camu_view *view, u32 window_width, u32 window_height, f64 x, f64 y, f64 v);
bool camu_view_pan_simple(struct camu_view *view, u32 window_width, u32 window_height, f64 dx, f64 dy);