2 Copyright 2012 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "surfacevector.h"
23 #include "staticartwork.h"
28 SurfaceVector::SurfaceVector(OsdVector* vosd)
34 SurfaceVector::~SurfaceVector()
36 osd->removeSurface(this);
37 list<SVGCommand>::iterator itty=commands.begin();
38 while (itty!=commands.end())
40 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
41 ImageIndex ii=(*itty).getImageIndex();
43 osd->removeImageRef(ii);
45 LoadIndex li=(*itty).getLoadIndex();
46 if (li) osd->removeLoadIndexRef(li);
52 int SurfaceVector::getFontHeight()
54 return osd->getFontHeight();
57 float SurfaceVector::getCharWidth(wchar_t c)
59 return osd->getCharWidth(c);
62 wchar_t SurfaceVector::getWChar(const char* str, unsigned int *length)
71 } else if (str[1]=='\0'){
73 } else if (str[2]=='\0'){
77 memset((void*)&state,0,sizeof(state));
78 num_bytes=mbrtowc(tempo, str, max_length, &state);
79 if (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2))
89 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c){
90 return drawText(text, x, y, 0, c);
93 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
100 size_t length=strlen(text);
101 memset((void*)&state,0,sizeof(state));
102 command_mutex.Lock();
103 num_bytes=mbrtowc(tempo, run, length, &state);
104 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
106 unsigned int ref=osd->getStyleRef(c);
107 commands.push_back(SVGCommand::PaintGlyph(x+shift,y,*tempo,ref));
108 shift+=osd->getCharWidth(*tempo);
111 if (shift>width && width >0) {
112 command_mutex.Unlock();
115 num_bytes=mbrtowc(tempo, run, length, &state);
117 command_mutex.Unlock();
121 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
124 const char *run=text;
128 size_t length=strlen(text);
129 memset((void*)&state,0,sizeof(state));
131 num_bytes=mbrtowc(tempo, run, length, &state);
132 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
134 shift+=osd->getCharWidth(*tempo);
137 num_bytes=mbrtowc(tempo, run, length, &state);
139 return drawText(text, x-shift, y, c);
142 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
145 const char *run=text;
149 size_t length=strlen(text);
150 memset((void*)&state,0,sizeof(state));
152 num_bytes=mbrtowc(tempo, run, length, &state);
153 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
155 shift+=osd->getCharWidth(*tempo);
158 num_bytes=mbrtowc(tempo, run, length, &state);
160 return drawText(text, x-shift/2., y, c);
163 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
165 StaticArtwork index=sa_MAX; // This is for compatibility only
166 if (strcmp(fileName,"/vdr.jpg")==0) {
168 *height=100; // this is faked so that the system does use the old coordinate system
169 *width=ceil(190.f*osd->getPixelAspect());
170 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {
172 *width=720; // this is faked so that the system does use the old coordinate system
177 info.setStaticArtwork(index);
178 drawTVMedia(info,x,y,*width,*height,TopLeft);
183 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
185 command_mutex.Lock();
186 ImageIndex image=osd->getJpegRef(fileName,width,height);
187 commands.push_back(SVGCommand::PaintImage(x,y,*width,*height,image,0));
188 command_mutex.Unlock();
192 void SurfaceVector::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner)
194 command_mutex.Lock();
196 LoadIndex load_index=osd->getTVMediaRef(tvmedia,image);
197 if (width!=0 && height!=0) {
198 removeCommands(x,y,width,height);
201 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image %d %d", load_index,image);
202 commands.push_back(SVGCommand::PaintImage(x,y,width,height,image,0,corner));
205 commands.push_back(SVGCommand::PaintImageLoading(load_index,x,y,width,height,0,corner));
206 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image loading %d %d", load_index,image);
208 command_mutex.Unlock();
211 void SurfaceVector::drawClippingRectangle(float x, float y, float w, float h)
213 command_mutex.Lock();
214 commands.push_back(SVGCommand::PaintClipping((float)x,(float)y,(float)w,(float)h));
215 command_mutex.Unlock();
218 int SurfaceVector::create(UINT width, UINT height)
224 void SurfaceVector::display()
226 //nothing this is really mvp specific
229 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
231 command_mutex.Lock();
232 removeCommands(x,y,width,height); // remove commands below the box
233 unsigned int ref=osd->getStyleRef(c);
234 commands.push_back(SVGCommand::PaintPath(x,y,width,height,PIRectangle,ref));
235 command_mutex.Unlock();
239 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
241 command_mutex.Lock();
242 unsigned int ref=osd->getStyleRef(c);
243 commands.push_back(SVGCommand::PaintPath(x1,y,x2-x1,1,PIHorzLine,ref));
244 command_mutex.Unlock();
247 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c){
248 command_mutex.Lock();
249 unsigned int ref=osd->getStyleRef(c);
250 commands.push_back(SVGCommand::PaintPath(x,y1,1,y2-y1,PIVertLine,ref));
251 command_mutex.Unlock();
254 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm,const DisplayRegion & region)
256 //this is complicated
257 command_mutex.Lock();
259 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth()*bm.getHeight());
260 for (UINT j = 0; j < bm.getHeight(); ++j){
261 for (UINT i = 0; i < bm.getWidth(); ++i)
263 data[i+j*bm.getHeight()]=bm.getColour(i,j);
266 ImageIndex image=osd->getImagePalette(bm.getWidth(),bm.getHeight(),&(bm.rawData()[0]),
267 (const unsigned int*)&bm.palette.getColourVector()[0]); // data is freed by the OSD
269 float tx=x+region.windowx;
270 float ty=y+region.windowy;
271 float th=bm.getHeight();
272 float tw=bm.getWidth();
274 float scalex=720.f/((float) (region.framewidth+1));
275 float scaley=576.f/((float) (region.frameheight+1));
280 SVGCommand temp=SVGCommand::PaintImage(tx,ty,tw,th,image,0);
281 removeCommands(tx,ty,tw,th);
282 commands.push_back(temp);
283 command_mutex.Unlock();
286 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw){
287 if (!fastdraw) command_mutex.Lock();
288 unsigned int ref=osd->getStyleRef(c);
289 commands.push_back(SVGCommand::PaintPath(x,y,1,1,PIPoint,ref));
290 if (!fastdraw) command_mutex.Unlock();
292 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour)
294 command_mutex.Lock();
295 ImageIndex image=osd->getMonoBitmapRef(base,width,height);
296 unsigned int ref=osd->getStyleRef(nextColour);
297 removeCommands(dx,dy,width,height);
298 commands.push_back(SVGCommand::PaintImage(dx,dy,height,width,image,ref));
299 command_mutex.Unlock();
303 int SurfaceVector::removeCommands(float x,float y,float width,float height)
305 // we iterate through all old commands in order to remove commands hidden by this rectangle
306 list<SVGCommand>::iterator itty=commands.begin();
307 while (itty!=commands.end())
309 if ((*itty).Test(x,y,width,height) && (*itty).instr != DrawClipping) {
310 //Log::getInstance()->log("OSD", Log::DEBUG, "Remove command %d %g %g %g %g %d %d",(*itty).instr,
311 //(*itty).x,(*itty).y,(*itty).w,(*itty).h,(*itty).reference,(*itty).target.image);
312 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
313 ImageIndex ii=(*itty).getImageIndex();
314 if (ii) osd->removeImageRef(ii);
315 LoadIndex li=(*itty).getLoadIndex();
316 if (li) osd->removeLoadIndexRef(li);
317 itty=commands.erase(itty);
326 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
328 // ok this method really works in a pixel oriented way
329 command_mutex.Lock();
330 osd->updateOrAddSurface(this,dx-sx,dy-sy,swidth,sheight,commands);
331 command_mutex.Unlock();
336 /* This is for systems which need a locking of the drawing surface to speed up drawing */
337 void SurfaceVector::startFastDraw() {
338 command_mutex.Lock();
340 void SurfaceVector::endFastDraw() {
341 command_mutex.Unlock();
345 void SurfaceVector::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
347 command_mutex.Lock();
348 list<SVGCommand>::iterator itty=commands.begin();
349 while (itty!=commands.end())
351 if ((*itty).TTTest(ox,oy,x,y) ) {
352 itty=commands.erase(itty);
358 commands.push_back(SVGCommand::PaintTTchar(ox,oy,x,y,c.getInternal()));
359 command_mutex.Unlock();