OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [nanox/] [clientfb.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Microwindows direct client-side framebuffer mapping routines
3
 *
4
 * Copyright (c) 2001, 2002 by Greg Haerr <greg@censoft.com>
5
 */
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <unistd.h>
9
#include <fcntl.h>
10
#ifdef __ECOS
11
# include <pkgconf/system.h>
12
# ifdef CYGPKG_HAL_ARM
13
#  include <cyg/hal/lcd_support.h>
14
# endif
15
#else
16
#include <sys/ioctl.h>
17
#include <sys/mman.h>
18
#include <asm/page.h>           /* For definition of PAGE_SIZE */
19
#include <linux/fb.h>
20
#endif
21
#include "nano-X.h"
22
#include "device.h"
23
 
24
/* globals: assumes use of non-shared libnano-X.a for now*/
25
static int              frame_fd;       /* client side framebuffer fd*/
26
static unsigned char *  frame_map;      /* client side framebuffer mmap'd addr*/
27
static int              frame_len;      /* client side framebuffer length*/
28
static unsigned char *  physpixels;     /* start address of pixels*/
29
static GR_SCREEN_INFO   sinfo;
30
 
31
/* map framebuffer address into client memory*/
32
unsigned char *
33
GrOpenClientFramebuffer(void)
34
{
35
#ifndef __ECOS
36
        int     frame_offset;
37
        char *  fbdev;
38
        struct fb_fix_screeninfo finfo;
39
#endif
40
 
41
        /* if already open, return fb address*/
42
        if (physpixels)
43
                return physpixels;
44
 
45
        /*
46
         * For now, we'll just check whether or not Microwindows
47
         * is running its framebuffer driver to determine whether
48
         * to allow direct client-side framebuffer mapping.  In
49
         * the future, we could allow direct mapping for Microwindows
50
         * running on top of X, and finding the address of the
51
         * window within the Microwindows X window.
52
         */
53
        GrGetScreenInfo(&sinfo);
54
        if (!sinfo.fbdriver)
55
                return NULL;
56
 
57
#ifdef __ECOS
58
# ifdef CYGPKG_HAL_ARM
59
    {
60
        struct lcd_info li;
61
        lcd_getinfo(&li);
62
        physpixels = li.fb;
63
        return physpixels;
64
    }
65
# else
66
    /* This works for scr_ecospcsvga.c, at least    */
67
    {
68
        physpixels  = scrdev.addr;
69
        return physpixels;
70
    }
71
# endif        
72
#else
73
        /*
74
         * Try to open the framebuffer directly.
75
         */
76
        if (!(fbdev = getenv("FRAMEBUFFER")))
77
                fbdev = "/dev/fb0";
78
        frame_fd = open(fbdev, O_RDWR);
79
        if (frame_fd < 0) {
80
                printf("Can't open framebuffer device\n");
81
                return NULL;
82
        }
83
 
84
        /* Get the type of video hardware */
85
        if (ioctl(frame_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
86
                printf("Couldn't get fb hardware info\n");
87
                goto err;
88
        }
89
 
90
        // FIXME remove when mwin returns fb or X
91
        switch (finfo.visual) {
92
                case FB_VISUAL_TRUECOLOR:
93
                case FB_VISUAL_PSEUDOCOLOR:
94
                case FB_VISUAL_STATIC_PSEUDOCOLOR:
95
                case FB_VISUAL_DIRECTCOLOR:
96
                        break;
97
                default:
98
                        printf("Unsupported fb color map\n");
99
                        goto err;
100
        }
101
 
102
        /* Memory map the device, compensating for buggy PPC mmap() */
103
        frame_offset = (((long)finfo.smem_start) -
104
                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
105
        frame_len = finfo.smem_len + frame_offset;
106
        frame_map = (unsigned char *)mmap(NULL, frame_len, PROT_READ|PROT_WRITE,
107
                MAP_SHARED, frame_fd, 0);
108
        if (frame_map == (unsigned char *)-1) {
109
                printf("Unable to memory map the video hardware\n");
110
                frame_map = NULL;
111
                goto err;
112
        }
113
        physpixels = frame_map + frame_offset;
114
        return physpixels;
115
 
116
err:
117
        close(frame_fd);
118
        return NULL;
119
#endif // __ECOS
120
}
121
 
122
void
123
GrCloseClientFramebuffer(void)
124
{
125
#ifndef __ECOS
126
        if (frame_fd >= 0) {
127
                if (frame_map) {
128
                        munmap(frame_map, frame_len);
129
                        frame_map = NULL;
130
                        physpixels = NULL;
131
                }
132
                close(frame_fd);
133
                frame_fd = -1;
134
 
135
                /* reset sinfo struct*/
136
                sinfo.cols = 0;
137
        }
138
#endif
139
}
140
 
141
/*
142
 * Return client-side mapped framebuffer info for
143
 * passed window.  If not running framebuffer, the
144
 * physpixel and winpixel members will be NULL, and
145
 * everything else correct.
146
 */
147
void
148
GrGetWindowFBInfo(GR_WINDOW_ID wid, GR_WINDOW_FB_INFO *fbinfo)
149
{
150
        int                     physoffset;
151
        GR_WINDOW_INFO          info;
152
        static int              last_portrait = -1;
153
 
154
        /* re-get screen info on auto-portrait switch*/
155
        if (sinfo.cols == 0 || last_portrait != sinfo.portrait)
156
                GrGetScreenInfo(&sinfo);
157
        last_portrait = sinfo.portrait;
158
 
159
        /* must get window position anew each time*/
160
        GrGetWindowInfo(wid, &info);
161
 
162
        fbinfo->bpp = sinfo.bpp;
163
        fbinfo->bytespp = (sinfo.bpp+7)/8;
164
        fbinfo->pixtype = sinfo.pixtype;
165
        fbinfo->x = info.x;
166
        fbinfo->y = info.y;
167
        fbinfo->portrait_mode = sinfo.portrait;
168
 
169
        switch (fbinfo->portrait_mode) {
170
        case MWPORTRAIT_RIGHT:
171
        case MWPORTRAIT_LEFT:
172
                /*
173
                 * We reverse coords since Microwindows reports
174
                 * back the virtual xres/yres, and we want
175
                 * the physical xres/yres.
176
                 */
177
                // FIXME return xres and xvirtres in SCREENINFO?
178
                fbinfo->xres = sinfo.rows;      /* reverse coords*/
179
                fbinfo->yres = sinfo.cols;
180
                break;
181
        default:
182
                fbinfo->xres = sinfo.cols;
183
                fbinfo->yres = sinfo.rows;
184
                break;
185
        }
186
        fbinfo->xvirtres = sinfo.cols;
187
        fbinfo->yvirtres = sinfo.rows;
188
        fbinfo->pitch = fbinfo->xres * fbinfo->bytespp;
189
 
190
        /* fill in memory mapped addresses*/
191
        fbinfo->physpixels = physpixels;
192
 
193
        /* winpixels only valid for non-portrait modes*/
194
        physoffset = info.y*fbinfo->pitch + info.x*fbinfo->bytespp;
195
        fbinfo->winpixels = physpixels? (physpixels + physoffset): NULL;
196
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.