~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/util/render/renderMachine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /*
 
2
  puts the yuv images onto a surface
 
3
  Copyright (C) 2000  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "renderMachine.h"
 
15
 
 
16
 
 
17
 
 
18
 
 
19
RenderMachine::RenderMachine() {
 
20
 
 
21
#ifndef SDL_WRAPPER 
 
22
  surface=new X11Surface();
 
23
#endif
 
24
#ifdef SDL_WRAPPER 
 
25
  surface=new SDLSurface();
 
26
#endif
 
27
 
 
28
 
 
29
  pictureArray=NULL;
 
30
 
 
31
  startTime=new TimeStamp();
 
32
  endTime=new TimeStamp();
 
33
 
 
34
  initialMode = _IMAGE_DESK;
 
35
}
 
36
 
 
37
 
 
38
RenderMachine::~RenderMachine() {
 
39
 
 
40
 
 
41
  closeWindow();
 
42
  delete surface;
 
43
 
 
44
  delete startTime;
 
45
  delete endTime;
 
46
 
 
47
}
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
 
 
54
void RenderMachine::waitRestTime() {
 
55
  endTime->gettimeofday();
 
56
  startTime->minus(endTime,endTime);
 
57
  endTime->waitForIt();
 
58
 
 
59
}
 
60
 
 
61
 
 
62
 
 
63
 
 
64
int RenderMachine::openWindow(int width, 
 
65
                              int height,const char *title) {
 
66
 
 
67
  if (surface->open(width,height,title)) {
 
68
    pictureArray=new PictureArray(width, height);
 
69
    
 
70
    return switchToMode(initialMode);
 
71
  }
 
72
  return false;
 
73
}
 
74
 
 
75
 
 
76
void RenderMachine::closeWindow() {
 
77
  
 
78
  if (surface->isOpen()==false) {
 
79
    return;
 
80
  }
 
81
  if (pictureArray != NULL) {
 
82
    delete pictureArray;
 
83
    pictureArray=NULL;
 
84
  }
 
85
  surface->close();
 
86
}
 
87
 
 
88
/**
 
89
   important method. This is our only way to switch from
 
90
   fullscreen back to the desktop screen.
 
91
   This method is called if the video end (normal or by user request)
 
92
   We dont have a callback, thus after the image stops, we would
 
93
   never get events.
 
94
*/
 
95
void RenderMachine::flushWindow() {
 
96
 
 
97
  // we always switch back to desk mode.
 
98
  if (IS_FULL(surface->getImageMode())) {
 
99
    switchToMode(surface->getImageMode() ^ _IMAGE_DESK ^ _IMAGE_FULL);
 
100
  }
 
101
 
 
102
 
 
103
}
 
104
 
 
105
 
 
106
 
 
107
 
 
108
void RenderMachine::putImage(YUVPicture* pic,
 
109
                             TimeStamp* waitTime,
 
110
                             TimeStamp* ) {
 
111
  if (pic == NULL) {
 
112
    cout << "pic is null"<<endl;
 
113
    return;
 
114
  }
 
115
  startTime->gettimeofday();
 
116
  startTime->addOffset(waitTime);
 
117
 
 
118
  // need dither?
 
119
  surface->dither(pic);
 
120
 
 
121
  int nextMode;
 
122
  if (surface->checkEvent(&nextMode) == true) {
 
123
    switchToMode(nextMode);
 
124
  }
 
125
  surface->putImage(pic);
 
126
  waitRestTime();
 
127
}
 
128
 
 
129
 
 
130
int RenderMachine::switchToMode(int mode) {
 
131
  if (surface->getImageMode() != mode) {
 
132
    surface->closeImage();
 
133
    if (mode != _IMAGE_NONE) {
 
134
      surface->openImage(mode);
 
135
    }
 
136
    
 
137
    else {
 
138
      cout << "no imageMode, no open, that's life"<<endl;
 
139
      return false;
 
140
    }
 
141
  }
 
142
  return true;
 
143
}
 
144
 
 
145
 
 
146
 
 
147
PictureArray* RenderMachine::lockPictureArray() {
 
148
  return pictureArray;
 
149
}
 
150
 
 
151
 
 
152
void RenderMachine::unlockPictureArray(PictureArray* pictureArray) {
 
153
 
 
154
  // chance to switch mode
 
155
  
 
156
  
 
157
  // put picture out
 
158
  if (surface->getImageMode() != _IMAGE_NONE) {
 
159
    YUVPicture* pic=pictureArray->getYUVPictureCallback();
 
160
    if (pic != NULL) {
 
161
      TimeStamp* waitTime=pic->getWaitTime();
 
162
      TimeStamp* earlyTime=pic->getEarlyTime();
 
163
      putImage(pic,waitTime,earlyTime);
 
164
    }
 
165
  } else {
 
166
    cout << "no mode selected"<<endl;
 
167
  }
 
168
}
 
169
 
 
170
 
 
171
void RenderMachine::config(const char* key, 
 
172
                           const char* value,void* user_data) {
 
173
  if (strcmp(key,"getDepth")==0) {
 
174
    int* val=(int*)user_data;
 
175
    *val=surface->getDepth();
 
176
  }
 
177
  if (surface != NULL) {
 
178
    int mode = surface->getImageMode();
 
179
    if (strcmp(key,"toggleFullscreen")==0) {
 
180
      if (surface->findImage(mode ^ _IMAGE_FULL) != NULL) {
 
181
        if (surface->isOpen())
 
182
          switchToMode(mode ^ _IMAGE_FULL);
 
183
        else
 
184
          initialMode = _IMAGE_FULL;
 
185
      }
 
186
    }
 
187
    if (strcmp(key,"toggleDouble")==0) {
 
188
      if (surface->findImage(mode ^ _IMAGE_DOUBLE) != NULL) {
 
189
        if (surface->isOpen())
 
190
          switchToMode(mode ^ _IMAGE_DOUBLE);
 
191
        else
 
192
          initialMode = _IMAGE_DOUBLE;
 
193
      }
 
194
    }
 
195
  }
 
196
 
 
197
  surface->config(key,value,user_data);
 
198
}
 
199
 
 
200
 
 
201