From b2ac9af464a5690761ac982eaa5082e09b4207e7 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Fri, 22 Aug 2008 18:40:48 +0200 Subject: basic rewrite of nv30 demo --- screen.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 screen.c (limited to 'screen.c') 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 +#include +#include +#include + +/* 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; +} -- cgit v1.2.3