~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libvo/vo_s3fb.c

  • Committer: William Grant
  • Date: 2007-02-03 03:16:07 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: william.grant@ubuntu.org.au-20070203031607-08gc2ompbz6spt9i
Update to 1.0rc1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
LIBVO_EXTERN(s3fb)
41
41
 
42
 
     static int fd = -1;
43
 
     static struct fb_fix_screeninfo fb_finfo;
44
 
     static struct fb_var_screeninfo fb_vinfo;
45
 
     static uint32_t in_width, in_height, in_format, in_depth, in_s3_format,
 
42
typedef struct vga_type {
 
43
  int cr38, cr39, cr53;
 
44
  unsigned char *mmio;
 
45
} vga_t;
 
46
 
 
47
static vga_t *v = NULL;
 
48
static int fd = -1;
 
49
static struct fb_fix_screeninfo fb_finfo;
 
50
static struct fb_var_screeninfo fb_vinfo;
 
51
static uint32_t in_width, in_height, in_format, in_depth, in_s3_format,
46
52
  screenwidth, screenheight, screendepth, screenstride,
47
53
  vidwidth, vidheight, vidx, vidy, page, offset, sreg;
48
 
     static char *inpage, *inpage0, *smem = NULL;
49
 
     static void (*alpha_func)();
 
54
static char *inpage, *inpage0, *smem = NULL;
 
55
static void (*alpha_func)();
50
56
 
51
57
static void clear_screen();
52
58
 
80
86
#define S3V_MMIO_REGSIZE           0x8000  /* 32KB */
81
87
#define S3_NEWMMIO_VGABASE      (S3_NEWMMIO_REGBASE + 0x8000)
82
88
 
83
 
#define OUTREG(mmreg, value) *(unsigned int *)(&v.mmio[mmreg]) = value
84
 
 
85
 
typedef struct vga_type {
86
 
  int cr38, cr39, cr53;
87
 
  unsigned char *mmio;
88
 
} vga_t;
 
89
#define OUTREG(mmreg, value) *(unsigned int *)(&v->mmio[mmreg]) = value
89
90
 
90
91
int readcrtc(int reg) {
91
92
  outb(reg, 0x3d4);
97
98
  outb(value, 0x3d5);   
98
99
}
99
100
 
100
 
int enable(vga_t *v) {
 
101
// enable S3 registers
 
102
int enable() {
101
103
  int fd;
102
104
 
103
 
  // enable registers
104
 
  if (iopl(3) != 0)
105
 
    return 0;
106
 
  v->cr38 = readcrtc(0x38);
107
 
  v->cr39 = readcrtc(0x39);
108
 
  v->cr53 = readcrtc(0x53);
109
 
  writecrtc(0x38, 0x48);
110
 
  writecrtc(0x39, 0xa5);
111
 
  writecrtc(0x53, 0x08);
112
 
  fd = open("/dev/mem", O_RDWR);
113
 
  v->mmio = mmap(0, S3_NEWMMIO_REGSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
 
105
  if (v)
 
106
    return 1;
 
107
  errno = 0;
 
108
  v = malloc(sizeof(vga_t));
 
109
  if (v) {
 
110
    if (ioperm(0x3d4, 2, 1) == 0) {
 
111
      fd = open("/dev/mem", O_RDWR);
 
112
      if (fd != -1) {
 
113
        v->mmio = mmap(0, S3_NEWMMIO_REGSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
114
114
                 S3_MEMBASE + S3_NEWMMIO_REGBASE);
115
 
  close(fd);
116
 
  return 1;
 
115
        close(fd);
 
116
        if (v->mmio != MAP_FAILED) {
 
117
          v->cr38 = readcrtc(0x38);
 
118
          v->cr39 = readcrtc(0x39);
 
119
          v->cr53 = readcrtc(0x53);
 
120
          writecrtc(0x38, 0x48);
 
121
          writecrtc(0x39, 0xa5);
 
122
          writecrtc(0x53, 0x08);
 
123
          return 1;
 
124
        }
 
125
      }
 
126
      iopl(0);
 
127
    }
 
128
    free(v);
 
129
    v = NULL;
 
130
  }
117
131
}
118
132
 
119
 
void disable(vga_t *v) {
120
 
  writecrtc(0x53, v->cr53);
121
 
  writecrtc(0x39, v->cr39);
122
 
  writecrtc(0x38, v->cr38);
123
 
  iopl(0);
124
 
  munmap(v->mmio, S3_NEWMMIO_REGSIZE);
 
133
void disable() {
 
134
  if (v) {
 
135
    writecrtc(0x53, v->cr53);
 
136
    writecrtc(0x39, v->cr39);
 
137
    writecrtc(0x38, v->cr38);
 
138
    ioperm(0x3d4, 2, 0);
 
139
    munmap(v->mmio, S3_NEWMMIO_REGSIZE);
 
140
    free(v);
 
141
    v = NULL;
 
142
  }
125
143
}
126
144
 
127
145
int yuv_on(int format, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int crop, int xres, int yres, int line_length, int offset) {
128
146
  int tmp, pitch, start, src_wc, src_hc, bpp;
129
 
  vga_t v;
130
147
 
131
148
  if (format == 0 || format == 7)
132
149
    bpp = 4;
140
157
  pitch = src_w * bpp;
141
158
   
142
159
  // video card memory layout:
143
 
  // 0-n: visable screen memory, n = width * height * bytes per pixel
 
160
  // 0-n: visible screen memory, n = width * height * bytes per pixel
144
161
  // n-m: scaler source memory, n is aligned to a page boundary
145
162
  // m+: scaler source memory for multiple buffers
146
163
 
151
168
  // start is the top left viewable scaler input pixel
152
169
  start = offset + crop * pitch + crop * bpp;
153
170
   
154
 
  if (!enable(&v))
155
 
    return 0;
156
 
   
157
171
  OUTREG(COL_CHROMA_KEY_CONTROL_REG, 0x47000000);
158
172
  OUTREG(CHROMA_KEY_UPPER_BOUND_REG, 0x0);
159
173
  OUTREG(BLEND_CONTROL_REG, 0x00000020);
191
205
  writecrtc(0x93, (pitch + 7) / 8);
192
206
   
193
207
  writecrtc(0x67, readcrtc(0x67) | 0x4);
194
 
 
195
 
  disable(&v);
196
208
   
197
209
  return offset;
198
210
}
199
211
 
200
212
void yuv_off() {
201
 
  vga_t v;
202
 
 
203
 
  enable(&v);
204
 
 
205
213
  writecrtc(0x67, readcrtc(0x67) & ~0xc);
206
 
  memset(v.mmio + 0x8180, 0, 0x80);
 
214
  memset(v->mmio + 0x8180, 0, 0x80);
207
215
  OUTREG(0x81b8, 0x900);
208
216
  OUTREG(0x81bc, 0x900);
209
217
  OUTREG(0x81c8, 0x900);
213
221
  OUTREG(0x81fc, 0x00010001);
214
222
  writecrtc(0x92, 0);
215
223
  writecrtc(0x93, 0);
216
 
  disable(&v);
217
224
}
218
225
 
219
226
static int preinit(const char *arg)
263
270
  smem = mmap(0, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
264
271
  sreg = fb_finfo.smem_start;
265
272
 
266
 
  if((long)smem == -1) {
 
273
  if(smem == (void *)-1) {
267
274
    mp_msg(MSGT_VO, MSGL_FATAL, "s3fb: Couldn't map memory areas: %s\n", strerror(errno));
268
275
    smem = NULL;
269
276
    close(fd);
271
278
    return -1;
272
279
  }
273
280
 
274
 
  return 0;
 
281
  if (!enable()) {
 
282
    mp_msg(MSGT_VO, MSGL_FATAL, "s3fb: Couldn't map S3 registers: %s\n", strerror(errno));
 
283
    close(fd);
 
284
    fd = -1;
 
285
    return -1;
 
286
  }
 
287
 
 
288
  return 0; // Success
275
289
}
276
290
 
 
291
/* And close our mess */
277
292
static void uninit(void)
278
293
{
279
294
  if (inpage0) {
282
297
    inpage0 = NULL;
283
298
  }
284
299
   
285
 
  /* And close our mess */
286
300
  if(smem) {
287
301
    munmap(smem, fb_finfo.smem_len);
288
302
    smem = NULL;
289
303
  }
 
304
   
 
305
  disable();
290
306
 
291
307
  if(fd != -1) {
292
308
    close(fd);