summaryrefslogtreecommitdiff
path: root/viewport.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-08-17 12:17:46 +0000
committerrodri <rgl@antares-labs.eu>2024-08-17 12:17:46 +0000
commit56e8e3de24e7fea36f165b653a8efc8c38145d4c (patch)
treec1558a4ef810d82a11d31ab085dd849c7b5bba7f /viewport.c
parentd0a7561dd20847504b2449e17fd791f6c2800c84 (diff)
downloadlibgraphics-56e8e3de24e7fea36f165b653a8efc8c38145d4c.tar.gz
libgraphics-56e8e3de24e7fea36f165b653a8efc8c38145d4c.tar.bz2
libgraphics-56e8e3de24e7fea36f165b653a8efc8c38145d4c.zip
unify drawing routines and add clipped fb drawing support.
now changing the viewport offset will correctly show the portion of the framebuffer that's visible, including support for upscaled views.
Diffstat (limited to 'viewport.c')
-rw-r--r--viewport.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/viewport.c b/viewport.c
index 9e41e53..5214e53 100644
--- a/viewport.c
+++ b/viewport.c
@@ -15,13 +15,10 @@ viewport_draw(Viewport *v, Image *dst)
off = Pt(v->p.x, v->p.y);
/* no downsampling support yet */
- scale.x = max(min(v->bx.x, Dx(dst->r)/Dx(v->r)), 1);
- scale.y = max(min(v->by.y, Dy(dst->r)/Dy(v->r)), 1);
+ scale.x = max(v->bx.x, 1);
+ scale.y = max(v->by.y, 1);
- if(scale.x > 1 || scale.y > 1)
- v->fbctl->upscaledraw(v->fbctl, dst, off, scale);
- else
- v->fbctl->draw(v->fbctl, dst, off);
+ v->fbctl->draw(v->fbctl, dst, off, scale);
}
static void
@@ -31,13 +28,10 @@ viewport_memdraw(Viewport *v, Memimage *dst)
off = Pt(v->p.x, v->p.y);
/* no downsampling support yet */
- scale.x = max(min(v->bx.x, Dx(dst->r)/Dx(v->r)), 1);
- scale.y = max(min(v->by.y, Dy(dst->r)/Dy(v->r)), 1);
+ scale.x = max(v->bx.x, 1);
+ scale.y = max(v->by.y, 1);
- if(scale.x > 1 || scale.y > 1)
- v->fbctl->upscalememdraw(v->fbctl, dst, off, scale);
- else
- v->fbctl->memdraw(v->fbctl, dst, off);
+ v->fbctl->memdraw(v->fbctl, dst, off, scale);
}
static void
@@ -78,6 +72,11 @@ mkviewport(Rectangle r)
{
Viewport *v;
+ if(badrect(r)){
+ werrstr("bad viewport rectangle");
+ return nil;
+ }
+
v = emalloc(sizeof *v);
v->p = Pt2(0,0,1);
v->bx = Vec2(1,0);