2 Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
22 #include "osdopengl.h"
\r
24 #include "videovpeogl.h"
\r
25 #include "surfaceopengl.h"
\r
28 #include "message.h"
\r
29 #include "command.h"
\r
32 #define BACKBUFFER_WIDTH 1920
\r
33 #define BACKBUFFER_HEIGHT 1080
\r
41 OsdOpenGL::OsdOpenGL()
\r
45 external_driving=false;
\r
47 lastrendertime=getTimeMS();
\r
51 #ifdef BENCHMARK_FPS
\r
52 last_benchmark_time=getTimeMS();
\r
53 num_benchmark_frames=0;
\r
59 OsdOpenGL::~OsdOpenGL()
\r
72 int OsdOpenGL::getFD()
\r
74 if (!initted) return 0;
\r
78 Surface * OsdOpenGL::createNewSurface() {
\r
79 return (Surface*)new SurfaceOpenGL();
\r
82 int OsdOpenGL::init(void* device)
\r
84 if (initted) return 0;
\r
85 Video* video = Video::getInstance();
\r
86 //window=*((HWND*)device);
\r
88 // May be this device specific part should go to a device specific child class
\r
90 //init broadcom chipset (Move to video?)
\r
93 //First get connection to egl
\r
94 egl_display=eglGetDisplay(EGL_DEFAULT_DISPLAY);
\r
96 if (egl_display==EGL_NO_DISPLAY) {
\r
97 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());
\r
104 if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {
\r
105 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());
\r
110 const char *query_str=eglQueryString(egl_display,EGL_CLIENT_APIS);
\r
111 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
112 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
\r
113 query_str=eglQueryString(egl_display,EGL_EXTENSIONS);
\r
114 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
115 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
\r
117 const EGLint attributs[]={
\r
118 EGL_RED_SIZE,8,EGL_GREEN_SIZE, 8,EGL_BLUE_SIZE, 8,EGL_ALPHA_SIZE, 8,
\r
119 EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT,
\r
120 EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
\r
122 }; // Here, we might have to select the resolution!
\r
127 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {
\r
128 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x",eglGetError());
\r
133 const EGLint attr_context[]={
\r
134 EGL_CONTEXT_CLIENT_VERSION,2,
\r
138 egl_context=eglCreateContext(egl_display,egl_ourconfig,EGL_NO_CONTEXT,attr_context);
\r
139 if (egl_context==EGL_NO_CONTEXT) {
\r
140 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x",eglGetError());
\r
145 // warning broadcom specific, get display size!
\r
146 display_width=display_height=0;
\r
147 if (graphics_get_display_size(0, &display_width, &display_height)<0) {
\r
148 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
\r
152 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);
\r
153 VC_RECT_T dst_rect ={0,0,display_width,display_height};
\r
154 VC_RECT_T src_rect={0,0,display_width<<16,display_height<<16};
\r
155 DISPMANX_DISPLAY_HANDLE_T bcm_display;
\r
156 DISPMANX_ELEMENT_HANDLE_T bcm_element;
\r
157 DISPMANX_UPDATE_HANDLE_T bcm_update;
\r
160 bcm_display=vc_dispmanx_display_open(0);
\r
161 bcm_update=vc_dispmanx_update_start(0);
\r
162 bcm_element=vc_dispmanx_element_add(bcm_update,bcm_display,
\r
164 &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);
\r
166 vc_dispmanx_update_submit_sync(bcm_update);
\r
167 static EGL_DISPMANX_WINDOW_T nativewindow;
\r
168 nativewindow.element=bcm_element;
\r
169 nativewindow.height=display_height;
\r
170 nativewindow.width=display_width;
\r
172 egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );
\r
173 if (egl_surface==EGL_NO_SURFACE) {
\r
174 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
\r
179 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
\r
180 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
\r
186 query_str=(const char*)glGetString(GL_VERSION) ;
\r
187 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
188 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",glGetError());
\r
190 query_str=(const char*)glGetString(GL_VENDOR) ;
\r
191 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
192 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",glGetError());
\r
194 query_str=(const char*)glGetString(GL_RENDERER) ;
\r
195 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
196 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",glGetError());
\r
198 query_str=(const char*)glGetString(GL_EXTENSIONS) ;
\r
199 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
200 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",glGetError());
\r
205 //Now we will create the Screen
\r
206 screen = (Surface*) new SurfaceOpenGL(Surface::SCREEN);
\r
208 screen->create(video->getScreenWidth(), video->getScreenHeight());
\r
210 initted = 1; // must set this here or create surface won't work
\r
212 //glGenBuffers(1, &vB);
\r
213 //glGenBuffers(1, &iB);
\r
215 //Preparing the Shaders
\r
217 if (!osd_shader.init()) {
\r
218 Log::getInstance()->log("OSD", Log::WARN, "Init Osd Shader failed");
\r
222 if (!yuv400_shader.init()) {
\r
223 Log::getInstance()->log("OSD", Log::WARN, "Init Yuv400 Shader failed");
\r
228 if (!yuv444_shader.init()) {
\r
229 Log::getInstance()->log("OSD", Log::WARN, "Init Yuv444 Shader failed");
\r
234 /* gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER);
\r
235 osd_shader=CreateShader(osd_frag_shader, GL_FRAGMENT_SHADER);
\r
237 // Create the program for osd rendering
\r
238 osd_program=glCreateProgram();
\r
239 if (osd_program==0) {
\r
240 Log::getInstance()->log("OSD", Log::WARN, "Creating glsl program failed!%d",glGetError());
\r
243 glAttachShader(osd_program,gen_shader);
\r
244 glAttachShader(osd_program,osd_shader);
\r
245 glBindAttribLocation(osd_program,0,"vec_pos");
\r
246 glBindAttribLocation(osd_program,1,"tex_coord");
\r
250 glLinkProgram(osd_program);
\r
255 glGetProgramiv(osd_program,GL_LINK_STATUS, &link_status);
\r
257 if (!link_status) {
\r
259 glGetProgramInfoLog(osd_program,1024,NULL,buffer);
\r
260 Log::getInstance()->log("OSD", Log::WARN, "Compiling Programm failed!");
\r
261 Log::getInstance()->log("OSD", Log::WARN, "%s",buffer);
\r
262 glDeleteProgram(osd_program);
\r
266 osd_sampler_loc=glGetUniformLocation(osd_program,"texture");
\r
267 // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",osd_sampler_loc,glGetError());
\r
269 // create the program for yuv frame rendering
\r
270 frame_shader=CreateShader(frame_frag_shader, GL_FRAGMENT_SHADER);
\r
272 frame_program=glCreateProgram();
\r
273 if (frame_program==0) {
\r
274 Log::getInstance()->log("OSD", Log::WARN, "Creating glsl program failed!%d",glGetError());
\r
277 glAttachShader(frame_program,gen_shader);
\r
278 glAttachShader(frame_program,frame_shader);
\r
279 glBindAttribLocation(frame_program,0,"vec_pos");
\r
280 glBindAttribLocation(frame_program,1,"tex_coord");
\r
284 glLinkProgram(frame_program);
\r
285 //GLint link_status;
\r
286 glGetProgramiv(frame_program,GL_LINK_STATUS, &link_status);
\r
288 if (!link_status) {
\r
290 glGetProgramInfoLog(frame_program,1024,NULL,buffer);
\r
291 Log::getInstance()->log("OSD", Log::WARN, "Compiling Programm failed!");
\r
292 Log::getInstance()->log("OSD", Log::WARN, "%s",buffer);
\r
293 glDeleteProgram(frame_program);
\r
297 frame_sampler_locY=glGetUniformLocation(frame_program,"textureY");
\r
298 // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locY,glGetError());
\r
299 frame_sampler_locU=glGetUniformLocation(frame_program,"textureU");
\r
300 //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError());
\r
301 frame_sampler_locV=glGetUniformLocation(frame_program,"textureV");
\r
305 glClearColor(0.0f,0.0f,0.0f,1.f);
\r
306 eglSwapInterval(egl_display, 1 );
\r
308 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
310 if (((VideoVPEOGL*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init opengl stuff
\r
325 void OsdOpenGL::InitVertexBuffer(float scalex,float scaley)
\r
327 Video* video=Video::getInstance();
\r
330 OSDCOLOR osdcolor={1.f,1.f,1.f,1.f};
\r
332 // osdvertices[0].c=osdcolor;
\r
333 osdvertices[0].x= (scalex);
\r
334 osdvertices[0].y=-scaley;
\r
335 osdvertices[0].z=0.5;
\r
336 osdvertices[0].u=texx;
\r
337 osdvertices[0].v=texy;
\r
338 // osdvertices[1].c=osdcolor;
\r
339 osdvertices[1].x=(scalex);
\r
340 osdvertices[1].y=(scaley);
\r
341 osdvertices[1].z=0.5f;
\r
342 osdvertices[1].u=texx;
\r
343 osdvertices[1].v=0.f;
\r
344 // osdvertices[0].c=osdcolor;
\r
345 osdvertices[2].x=(-scalex);
\r
346 osdvertices[2].y=-scaley;
\r
347 osdvertices[2].z=0.5f;
\r
348 osdvertices[2].u=0.f;
\r
349 osdvertices[2].v=texy;
\r
350 // osdvertices[3].c=osdcolor;
\r
351 osdvertices[3].x=-scalex;
\r
352 osdvertices[3].y=(scaley);
\r
353 osdvertices[3].z=0.5f;
\r
354 osdvertices[3].u=0.f;
\r
355 osdvertices[3].v=0.f;
\r
367 // glBindBuffer(GL_ARRAY_BUFFER, vB);
\r
368 // glBufferData(GL_ARRAY_BUFFER, sizeof(osdvertices), osdvertices, GL_STATIC_DRAW);
\r
371 // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iB);
\r
372 //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(osdindices), osdindices, GL_STATIC_DRAW);
\r
379 int OsdOpenGL::shutdown()
\r
381 if (!initted) return 0;
\r
384 (((VideoVPEOGL*)Video::getInstance())->shutdownUsingOSDObjects());
\r
387 osd_shader.deinit();
\r
388 yuv400_shader.deinit();
\r
389 yuv444_shader.deinit();
\r
391 glClear(GL_COLOR_BUFFER_BIT);
\r
392 eglSwapBuffers(egl_display, egl_surface);
\r
393 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
394 eglDestroySurface(egl_display,egl_surface);
\r
395 eglDestroyContext(egl_display,egl_context);
\r
396 eglTerminate(egl_display );
\r
401 void OsdOpenGL::screenShot(const char* fileName)
\r
403 screen->screenShot(fileName);
\r
406 void OsdOpenGL::threadMethod()
\r
408 // We have to claim the gl context for this thread
\r
411 //glmutex.Unlock();
\r
412 VPEOGLFrame *frame=NULL;
\r
414 VideoVPEOGL* video =(VideoVPEOGL*) Video::getInstance();
\r
418 unsigned int waittime=10;
\r
420 if (!frame) frame=video->getReadyOGLFrame();
\r
422 InternalRendering(frame);
\r
423 // MILLISLEEP(1500);
\r
424 lastrendertime=getTimeMS();
\r
425 video->returnOGLFrame(frame); //please recycle it
\r
428 long long time1=getTimeMS();
\r
429 if ((time1-lastrendertime)>200) {//5 fps for OSD updates are enough, avoids tearing
\r
430 InternalRendering(NULL);
\r
431 lastrendertime=getTimeMS();
\r
434 frame=video->getReadyOGLFrame();
\r
440 struct timespec target_time;
\r
441 clock_gettime(CLOCK_REALTIME,&target_time);
\r
442 target_time.tv_nsec+=1000000LL*ts;
\r
443 if (target_time.tv_nsec>999999999) {
\r
444 target_time.tv_nsec-=1000000000L;
\r
445 target_time.tv_sec+=1;
\r
447 threadWaitForSignalTimed(&target_time);
\r
451 //eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
455 void OsdOpenGL::threadPostStopCleanup()
\r
462 // This function is called from the WinMain function in order to get Screen updates
\r
463 void OsdOpenGL::Render()
\r
465 if (!initted) return ;
\r
466 VPEOGLFrame* frame=NULL;
\r
467 if (external_driving) {
\r
468 long long time1=getTimeMS();
\r
469 if ((time1-lastrendertime)>200) {//5 fps for OSD updates are enough, avoids tearing
\r
470 InternalRendering(NULL);
\r
471 lastrendertime=getTimeMS();
\r
473 //Sleep(5); //Sleep for 5 ms, in order to avoid blocking the other threads
\r
476 struct timespec ts;
\r
477 clock_gettime(CLOCK_MONOTONIC, &ts);
\r
478 long long time1=ts.tv_sec*1000+ts.tv_nsec/1000000LL;
\r
479 if ((time1-lastrendertime)>100) {//10 fps for OSD updates are enough, avoids tearing
\r
480 InternalRendering(NULL);
\r
481 lastrendertime=getTimeMS();
\r
490 void OsdOpenGL::RenderDS(VPEOGLFrame* frame){
\r
491 if (!initted) return;
\r
492 if (external_driving) {
\r
493 InternalRendering(frame);
\r
494 lastrendertime=getTimeMS();
\r
499 void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){
\r
501 /* HRESULT losty=d3ddevice->TestCooperativeLevel();
\r
502 if (losty==D3DERR_DEVICELOST) {
\r
505 return; //Device Lost
\r
507 if (losty==D3DERR_DEVICENOTRESET){
\r
512 WaitForSingleObject(event,INFINITE);
\r
517 LPDIRECT3DSURFACE9 targetsurf;
\r
520 targetsurf=swapsurf;
\r
521 d3ddevice->SetRenderTarget(0,swapsurf);//Stupid VMR manipulates the render target
\r
525 targetsurf=d3drtsurf;
\r
526 d3ddevice->SetRenderTarget(0,d3drtsurf);//Stupid VMR manipulates the render target
\r
528 D3DSURFACE_DESC targetdesc;
\r
529 targetsurf->GetDesc(&targetdesc);
\r
531 if (external_driving) {
\r
532 //Copy video to Backbuffer
\r
533 if (present!=NULL ) {
\r
534 VideoWin* video =(VideoWin*) Video::getInstance();
\r
535 /*calculating destination rect *
\r
536 RECT destrect={0,0,/*video->getScreenWidth()* targetdesc.Width,
\r
537 /*video->getScreenHeight()*targetdesc.Height};
\r
538 UCHAR mode=video->getMode();
\r
540 case Video::EIGHTH:
\r
541 destrect.right=destrect.right/2;
\r
542 destrect.bottom=destrect.bottom/2;
\r
543 case Video::QUARTER:
\r
544 destrect.right=destrect.right/2+video->getPosx()*2;
\r
545 destrect.bottom=destrect.bottom/2+video->getPosy()*2;
\r
546 destrect.left=video->getPosx()*2;
\r
547 destrect.top=video->getPosy()*2;
\r
548 d3ddevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
\r
551 D3DSURFACE_DESC surf_desc;
\r
552 present->GetDesc(&surf_desc);//for chop sides
\r
553 RECT sourcerect= {0,0,surf_desc.Width,surf_desc.Height};
\r
554 if (video->getPseudoTVsize()==Video::ASPECT4X3
\r
555 && video->getMode()==Video::NORMAL
\r
556 && video->getAspectRatio()==Video::ASPECT16X9) {
\r
557 unsigned int correction=((double) (surf_desc.Width))*4.*9./3./16.;
\r
558 sourcerect.left=(surf_desc.Width-correction)/2;
\r
559 sourcerect.right=sourcerect.left+correction;
\r
561 d3ddevice->StretchRect(present,&sourcerect,targetsurf ,&destrect,filter_type);
\r
565 VideoWin* video =(VideoWin*) Video::getInstance();
\r
567 if (!video->isVideoOn()) d3ddevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
\r
571 //InitVertexBuffer(display_width,display_height);
\r
572 InitVertexBuffer(1.f,1.f);
\r
575 glViewport(0, 0, display_width,display_height);
\r
577 glClearColor(0.0f,0.0f,0.0f,1.f);
\r
578 glClear(GL_COLOR_BUFFER_BIT);
\r
585 //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());
\r
586 /* glUseProgram(frame_program);
\r
587 //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());
\r
588 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);
\r
589 glEnableVertexAttribArray(0);
\r
590 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));
\r
591 glEnableVertexAttribArray(1);
\r
594 //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError());
\r
597 glActiveTexture(GL_TEXTURE2);
\r
598 glBindTexture(GL_TEXTURE_2D,frame->textures[2]);
\r
599 glUniform1i(frame_sampler_locV,2);
\r
600 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
\r
601 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
\r
604 glActiveTexture(GL_TEXTURE1);
\r
605 glBindTexture(GL_TEXTURE_2D,frame->textures[1]);
\r
606 glUniform1i(frame_sampler_locU,1);
\r
607 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
\r
608 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
\r
611 glActiveTexture(GL_TEXTURE0);
\r
612 glBindTexture(GL_TEXTURE_2D,frame->textures[0]);
\r
613 glUniform1i(frame_sampler_locY,0);
\r
614 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
\r
615 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/
\r
617 switch (frame->type) {
\r
619 yuv400_shader.PrepareRendering(frame->textures[0],frame->textures[1],frame->textures[2]);break;
\r
621 yuv444_shader.PrepareRendering(frame->textures[0]);break;
\r
627 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);
\r
628 glEnableVertexAttribArray(0);
\r
629 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));
\r
630 glEnableVertexAttribArray(1);
\r
633 //Log::getInstance()->log("OSD", Log::WARN, "mark8 glerror %x %x",glGetError(),osd_sampler_loc);
\r
637 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
\r
643 /*glUseProgram(osd_program);
\r
644 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);
\r
645 glEnableVertexAttribArray(0);
\r
646 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));
\r
647 glEnableVertexAttribArray(1);
\r
650 glActiveTexture(GL_TEXTURE0);
\r
651 glBindTexture(GL_TEXTURE_2D,((SurfaceOpenGL*)screen)->getTexture());
\r
653 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
\r
654 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
\r
656 glUniform1i(osd_sampler_loc,0);*/
\r
658 osd_shader.PrepareRendering(((SurfaceOpenGL*)screen)->getTexture());
\r
660 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices);
\r
661 glEnableVertexAttribArray(0);
\r
662 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u));
\r
663 glEnableVertexAttribArray(1);
\r
666 if (frame!=NULL) { //This is ok for ffmpeg rendering not OMX
\r
667 glEnable(GL_BLEND);
\r
668 glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_ONE);
\r
671 glDisable(GL_BLEND);
\r
675 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
\r
679 //Show it to the user!
\r
680 eglSwapBuffers(egl_display, egl_surface);
\r
683 #ifdef BENCHMARK_FPS
\r
684 num_benchmark_frames++;
\r
685 if (getTimeMS()-last_benchmark_time>4000) {
\r
686 float fps=1000./(float)(getTimeMS()-last_benchmark_time);
\r
687 fps*=((float)num_benchmark_frames);
\r
688 num_benchmark_frames=0;
\r
689 Log::getInstance()->log("OSD", Log::NOTICE, "Current FPS %g", fps);
\r
690 last_benchmark_time=getTimeMS();
\r
697 // if (!external_driving) {
\r
698 // Sleep(4);//The User can wait for 4 milliseconds to see his changes
\r
702 bool OsdOpenGL::DoLost(){
\r
704 Log::getInstance()->log("OSD", Log::WARN, "Direct3D Device Lost! Reobtaining...");
\r
706 if (external_driving && dsallocator!=NULL) {
\r
707 dsallocator->LostDevice(d3ddevice,d3d); //Propagate the information through DS
\r
709 //First we free up all resources
\r
710 Video* video = Video::getInstance();
\r
711 ((SurfaceWin*)screen)->ReleaseSurface();
\r
712 if (d3drtsurf) d3drtsurf->Release();
\r
714 D3DPRESENT_PARAMETERS d3dparas;
\r
715 ZeroMemory(&d3dparas,sizeof(d3dparas));
\r
716 d3dparas.BackBufferWidth=BACKBUFFER_WIDTH;
\r
717 d3dparas.BackBufferHeight=BACKBUFFER_HEIGHT;
\r
718 d3dparas.Windowed=TRUE;
\r
719 d3dparas.SwapEffect=D3DSWAPEFFECT_COPY;
\r
721 if (swapsurf) {swapsurf->Release();swapsurf=NULL;};
\r
722 if (swappy) {swappy->Release();swappy=NULL;};
\r
724 if (d3ddevice->Reset(&d3dparas)!=D3D_OK){
\r
727 d3ddevice->GetRenderTarget(0,&d3drtsurf);
\r
728 if (d3ddevman) d3ddevman->ResetDevice(d3ddevice,dxvatoken);
\r
729 //InitVertexBuffer();
\r
730 //Redraw Views, Chris could you add a member function to BoxStack, so that
\r
731 // I can cause it to completely redraw the Views?
\r
732 // Otherwise the OSD would be distorted after Device Lost
\r
738 screen->create(video->getScreenWidth(), video->getScreenHeight());
\r
739 screen->display();*/
\r
746 void OsdOpenGL::BeginPainting() {//We synchronize calls to d3d between different threads
\r
749 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
\r
750 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %d",eglGetError());
\r
756 void OsdOpenGL::EndPainting() {
\r
757 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
761 void OsdOpenGL::setExternalDriving(/*DsAllocator* dsall,*/unsigned int width, unsigned height) {
\r
766 d3ddevice->StretchRect(swapsurf,NULL,d3drtsurf,NULL,filter_type);
\r
767 LPDIRECT3DSWAPCHAIN9 temp=swappy;
\r
768 LPDIRECT3DSURFACE9 tempsurf=swapsurf;
\r
772 tempsurf->Release();
\r
777 external_driving=false;
\r
781 WaitForSingleObject(event,INFINITE);//We will only return if we are initted
\r
784 if (width>BACKBUFFER_WIDTH || height>BACKBUFFER_HEIGHT)
\r
786 D3DPRESENT_PARAMETERS d3dparas;
\r
787 ZeroMemory(&d3dparas,sizeof(d3dparas));
\r
788 d3dparas.BackBufferWidth=width;
\r
789 d3dparas.BackBufferHeight=height;
\r
790 d3dparas.Windowed=TRUE;
\r
791 d3dparas.SwapEffect=D3DSWAPEFFECT_COPY;
\r
792 if (d3ddevice->CreateAdditionalSwapChain(&d3dparas,&swappy)!=D3D_OK){
\r
793 Log::getInstance()->log("OSD", Log::WARN, "Could not create Swap Chain!");
\r
796 swappy->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&swapsurf);
\r
798 Log::getInstance()->log("OSD", Log::INFO, "Create Additional Swap Chain %d %d!",width,height);
\r
802 external_driving=true;
\r
807 void OsdOpenGL::Blank() {
\r
809 glClearColor(0.15f, 0.25f, 0.35f, 1.0f); // change this to black after testing
\r
810 glClear( GL_COLOR_BUFFER_BIT );
\r
811 glClear( GL_DEPTH_BUFFER_BIT );
\r