summaryrefslogtreecommitdiff
path: root/screen.c
diff options
context:
space:
mode:
authorPatrice Mandin <pmandin@caramail.com>2008-08-22 18:40:48 +0200
committerPatrice Mandin <pmandin@caramail.com>2008-08-22 18:40:48 +0200
commitb2ac9af464a5690761ac982eaa5082e09b4207e7 (patch)
tree28e51ccf7395d3efc0e434573c77b3813ae8e025 /screen.c
basic rewrite of nv30 demo
Diffstat (limited to 'screen.c')
-rw-r--r--screen.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/screen.c b/screen.c
new file mode 100644
index 0000000..ffd2efc
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,94 @@
+/* Definitions for front buffer */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <xf86drm.h>
+#include <nouveau_drm.h>
+
+/* Global variables */
+
+int screen_width;
+int screen_height;
+int screen_bpp;
+int screen_offset;
+
+int screen_pitch;
+
+uint32_t vram_base_phys = 0;
+uint32_t vram_size = 0;
+uint32_t tt_base_phys = 0;
+uint32_t tt_size = 0;
+
+int drm_fd = -1;
+
+/* Local variables */
+
+static int drm_ready = 0;
+static drm_context_t drm_context;
+
+/* Local functions */
+
+static uint64_t get_param(unsigned int param);
+
+/* Functions */
+
+int screen_open(int width, int height, int bpp)
+{
+ int ret;
+
+ drm_fd = drmOpen("nouveau", 0);
+ if (drm_fd < 0) {
+ drmError(drm_fd, __func__);
+ fprintf(stderr, "failed to open drm\n");
+ return 1;
+ }
+
+ ret=drmCreateContext(drm_fd, &drm_context);
+ if (ret) {
+ drmError(ret, __func__);
+ fprintf(stderr, "failed to create context: %d\n", ret);
+ return 1;
+ }
+
+ screen_width = width;
+ screen_height = height;
+ screen_bpp = bpp;
+ screen_offset = 0; /* Can we get front buffer offset in vram? */
+ screen_pitch = screen_width*(screen_bpp/8);
+ screen_pitch = (screen_pitch | 255)+1; /* Align on 256 bytes boundary */
+
+ printf("Screen: %dx%dx%d, pitch=%d, offset=0x%08x\n",
+ screen_width, screen_height, screen_bpp,
+ screen_pitch, screen_offset
+ );
+
+ vram_base_phys = (uint32_t) get_param(NOUVEAU_GETPARAM_FB_PHYSICAL);
+ vram_size = (uint32_t) get_param(NOUVEAU_GETPARAM_FB_SIZE);
+ printf("VRAM:\t%p 0x%08x\n", vram_base_phys, vram_size);
+
+ tt_base_phys = (uint32_t) get_param(NOUVEAU_GETPARAM_AGP_PHYSICAL);
+ tt_size = (uint32_t) get_param(NOUVEAU_GETPARAM_AGP_SIZE);
+ printf("TT:\t%p 0x%08x\n", tt_base_phys, tt_size);
+
+ drm_ready=1;
+ return 0;
+}
+
+void screen_close(void)
+{
+ if (drm_ready) {
+ drmDestroyContext(drm_fd, drm_context);
+ }
+ if (drm_fd>=0) {
+ drmClose(drm_fd);
+ }
+}
+
+static uint64_t get_param(unsigned int param)
+{
+ struct drm_nouveau_getparam getp;
+
+ getp.param = param;
+ drmCommandWriteRead(drm_fd, DRM_NOUVEAU_GETPARAM, &getp, sizeof(getp));
+ return getp.value;
+}