From 7d462d38175e712b388bc877f0764e46c657c4a8 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 1 Sep 2012 10:31:08 +0200 Subject: [PATCH] Switch to smaller OSD rendering buffer --- osdopengl.cc | 334 ++------------------------------------------------- osdopengl.h | 21 ---- 2 files changed, 7 insertions(+), 348 deletions(-) mode change 100755 => 100644 osdopengl.h diff --git a/osdopengl.cc b/osdopengl.cc index 545b5cb..6717f64 100644 --- a/osdopengl.cc +++ b/osdopengl.cc @@ -29,8 +29,8 @@ #include "command.h" -#define BACKBUFFER_WIDTH 1920 -#define BACKBUFFER_HEIGHT 1080 +#define BACKBUFFER_WIDTH 1280 +#define BACKBUFFER_HEIGHT 720 @@ -151,7 +151,7 @@ int OsdOpenGL::init(void* device) } Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height); VC_RECT_T dst_rect ={0,0,display_width,display_height}; - VC_RECT_T src_rect={0,0,display_width<<16,display_height<<16}; + VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16}; DISPMANX_DISPLAY_HANDLE_T bcm_display; DISPMANX_ELEMENT_HANDLE_T bcm_element; DISPMANX_UPDATE_HANDLE_T bcm_update; @@ -166,8 +166,8 @@ int OsdOpenGL::init(void* device) vc_dispmanx_update_submit_sync(bcm_update); static EGL_DISPMANX_WINDOW_T nativewindow; nativewindow.element=bcm_element; - nativewindow.height=display_height; - nativewindow.width=display_width; + nativewindow.height=BACKBUFFER_HEIGHT; + nativewindow.width=BACKBUFFER_WIDTH; egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL ); if (egl_surface==EGL_NO_SURFACE) { @@ -231,75 +231,6 @@ int OsdOpenGL::init(void* device) return 0; } - /* gen_shader=CreateShader(generic_vertex_shader, GL_VERTEX_SHADER); - osd_shader=CreateShader(osd_frag_shader, GL_FRAGMENT_SHADER); - - // Create the program for osd rendering - osd_program=glCreateProgram(); - if (osd_program==0) { - Log::getInstance()->log("OSD", Log::WARN, "Creating glsl program failed!%d",glGetError()); - return 0; - } - glAttachShader(osd_program,gen_shader); - glAttachShader(osd_program,osd_shader); - glBindAttribLocation(osd_program,0,"vec_pos"); - glBindAttribLocation(osd_program,1,"tex_coord"); - - - - glLinkProgram(osd_program); - - - - GLint link_status; - glGetProgramiv(osd_program,GL_LINK_STATUS, &link_status); - - if (!link_status) { - char buffer[1024]; - glGetProgramInfoLog(osd_program,1024,NULL,buffer); - Log::getInstance()->log("OSD", Log::WARN, "Compiling Programm failed!"); - Log::getInstance()->log("OSD", Log::WARN, "%s",buffer); - glDeleteProgram(osd_program); - return 0; - } - - osd_sampler_loc=glGetUniformLocation(osd_program,"texture"); - // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",osd_sampler_loc,glGetError()); - - // create the program for yuv frame rendering - frame_shader=CreateShader(frame_frag_shader, GL_FRAGMENT_SHADER); - - frame_program=glCreateProgram(); - if (frame_program==0) { - Log::getInstance()->log("OSD", Log::WARN, "Creating glsl program failed!%d",glGetError()); - return 0; - } - glAttachShader(frame_program,gen_shader); - glAttachShader(frame_program,frame_shader); - glBindAttribLocation(frame_program,0,"vec_pos"); - glBindAttribLocation(frame_program,1,"tex_coord"); - - - - glLinkProgram(frame_program); - //GLint link_status; - glGetProgramiv(frame_program,GL_LINK_STATUS, &link_status); - - if (!link_status) { - char buffer[1024]; - glGetProgramInfoLog(frame_program,1024,NULL,buffer); - Log::getInstance()->log("OSD", Log::WARN, "Compiling Programm failed!"); - Log::getInstance()->log("OSD", Log::WARN, "%s",buffer); - glDeleteProgram(frame_program); - return 0; - } - - frame_sampler_locY=glGetUniformLocation(frame_program,"textureY"); - // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locY,glGetError()); - frame_sampler_locU=glGetUniformLocation(frame_program,"textureU"); - //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError()); - frame_sampler_locV=glGetUniformLocation(frame_program,"textureV"); -*/ glClearColor(0.0f,0.0f,0.0f,1.f); @@ -361,18 +292,6 @@ void OsdOpenGL::InitVertexBuffer(float scalex,float scaley) osdindices[4]=2; osdindices[5]=3; - - - - // glBindBuffer(GL_ARRAY_BUFFER, vB); - // glBufferData(GL_ARRAY_BUFFER, sizeof(osdvertices), osdvertices, GL_STATIC_DRAW); - - - // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iB); - //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(osdindices), osdindices, GL_STATIC_DRAW); - - - return; } @@ -467,162 +386,23 @@ void OsdOpenGL::threadPostStopCleanup() //goo; } -/* -// This function is called from the WinMain function in order to get Screen updates -void OsdOpenGL::Render() -{ - if (!initted) return ; - VPEOGLFrame* frame=NULL; - if (external_driving) { - long long time1=getTimeMS(); - if ((time1-lastrendertime)>200) {//5 fps for OSD updates are enough, avoids tearing - InternalRendering(NULL); - lastrendertime=getTimeMS(); - } else { - //Sleep(5); //Sleep for 5 ms, in order to avoid blocking the other threads - } - } else { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - long long time1=ts.tv_sec*1000+ts.tv_nsec/1000000LL; - if ((time1-lastrendertime)>100) {//10 fps for OSD updates are enough, avoids tearing - InternalRendering(NULL); - lastrendertime=getTimeMS(); - } else { - //Sleep(5); - - } - - } -} - -void OsdOpenGL::RenderDS(VPEOGLFrame* frame){ - if (!initted) return; - if (external_driving) { - InternalRendering(frame); - lastrendertime=getTimeMS(); - } -}*/ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ BeginPainting(); - /* HRESULT losty=d3ddevice->TestCooperativeLevel(); - if (losty==D3DERR_DEVICELOST) { - //Sleep(10); - EndPainting(); - return; //Device Lost - } - if (losty==D3DERR_DEVICENOTRESET){ - EndPainting(); - DoLost(); - return; - } - WaitForSingleObject(event,INFINITE); - */ - - -/* - LPDIRECT3DSURFACE9 targetsurf; - if (swappy) - { - targetsurf=swapsurf; - d3ddevice->SetRenderTarget(0,swapsurf);//Stupid VMR manipulates the render target - } - else - { - targetsurf=d3drtsurf; - d3ddevice->SetRenderTarget(0,d3drtsurf);//Stupid VMR manipulates the render target - } - D3DSURFACE_DESC targetdesc; - targetsurf->GetDesc(&targetdesc); - - if (external_driving) { - //Copy video to Backbuffer - if (present!=NULL ) { - VideoWin* video =(VideoWin*) Video::getInstance(); - /*calculating destination rect * - RECT destrect={0,0,/*video->getScreenWidth()* targetdesc.Width, - /*video->getScreenHeight()*targetdesc.Height}; - UCHAR mode=video->getMode(); - switch (mode) { - case Video::EIGHTH: - destrect.right=destrect.right/2; - destrect.bottom=destrect.bottom/2; - case Video::QUARTER: - destrect.right=destrect.right/2+video->getPosx()*2; - destrect.bottom=destrect.bottom/2+video->getPosy()*2; - destrect.left=video->getPosx()*2; - destrect.top=video->getPosy()*2; - d3ddevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); - break; - }; - D3DSURFACE_DESC surf_desc; - present->GetDesc(&surf_desc);//for chop sides - RECT sourcerect= {0,0,surf_desc.Width,surf_desc.Height}; - if (video->getPseudoTVsize()==Video::ASPECT4X3 - && video->getMode()==Video::NORMAL - && video->getAspectRatio()==Video::ASPECT16X9) { - unsigned int correction=((double) (surf_desc.Width))*4.*9./3./16.; - sourcerect.left=(surf_desc.Width-correction)/2; - sourcerect.right=sourcerect.left+correction; - } - d3ddevice->StretchRect(present,&sourcerect,targetsurf ,&destrect,filter_type); - } - } else { - VideoWin* video =(VideoWin*) Video::getInstance(); - //Clear Background - if (!video->isVideoOn()) d3ddevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); - }*/ //InitVertexBuffer(display_width,display_height); InitVertexBuffer(1.f,1.f); - glViewport(0, 0, display_width,display_height); + glViewport(0, 0, BACKBUFFER_WIDTH ,BACKBUFFER_HEIGHT); glClearColor(0.0f,0.0f,0.0f,1.f); glClear(GL_COLOR_BUFFER_BIT); - - - - if (frame) { - //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError()); - /* glUseProgram(frame_program); - //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError()); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); - glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); - glEnableVertexAttribArray(1); - - - //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError()); - - - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D,frame->textures[2]); - glUniform1i(frame_sampler_locV,2); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D,frame->textures[1]); - glUniform1i(frame_sampler_locU,1); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D,frame->textures[0]); - glUniform1i(frame_sampler_locY,0); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/ - switch (frame->type) { case 1: yuv400_shader.PrepareRendering(frame->textures[0],frame->textures[1],frame->textures[2]);break; @@ -649,20 +429,7 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ } - /*glUseProgram(osd_program); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), osdvertices); - glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,sizeof(OSDVERTEX), &(osdvertices[0].u)); - glEnableVertexAttribArray(1); - - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D,((SurfaceOpenGL*)screen)->getTexture()); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glUniform1i(osd_sampler_loc,0);*/ osd_shader.PrepareRendering(((SurfaceOpenGL*)screen)->getTexture()); @@ -703,53 +470,10 @@ void OsdOpenGL::InternalRendering(VPEOGLFrame* frame){ #endif -// if (!external_driving) { -// Sleep(4);//The User can wait for 4 milliseconds to see his changes -// } -} -bool OsdOpenGL::DoLost(){ - /* - Log::getInstance()->log("OSD", Log::WARN, "Direct3D Device Lost! Reobtaining..."); - ResetEvent(event); - if (external_driving && dsallocator!=NULL) { - dsallocator->LostDevice(d3ddevice,d3d); //Propagate the information through DS - } - //First we free up all resources - Video* video = Video::getInstance(); - ((SurfaceWin*)screen)->ReleaseSurface(); - if (d3drtsurf) d3drtsurf->Release(); - d3drtsurf=NULL; - D3DPRESENT_PARAMETERS d3dparas; - ZeroMemory(&d3dparas,sizeof(d3dparas)); - d3dparas.BackBufferWidth=BACKBUFFER_WIDTH; - d3dparas.BackBufferHeight=BACKBUFFER_HEIGHT; - d3dparas.Windowed=TRUE; - d3dparas.SwapEffect=D3DSWAPEFFECT_COPY; - - if (swapsurf) {swapsurf->Release();swapsurf=NULL;}; - if (swappy) {swappy->Release();swappy=NULL;}; - - if (d3ddevice->Reset(&d3dparas)!=D3D_OK){ - return false; - } - d3ddevice->GetRenderTarget(0,&d3drtsurf); - if (d3ddevman) d3ddevman->ResetDevice(d3ddevice,dxvatoken); - //InitVertexBuffer(); - //Redraw Views, Chris could you add a member function to BoxStack, so that - // I can cause it to completely redraw the Views? - // Otherwise the OSD would be distorted after Device Lost - // FIXME - - SetEvent(event); +} - screen->create(video->getScreenWidth(), video->getScreenHeight()); - screen->display();*/ - - return true; - -} void OsdOpenGL::BeginPainting() {//We synchronize calls to d3d between different threads @@ -767,51 +491,7 @@ void OsdOpenGL::EndPainting() { glmutex.Unlock(); } -void OsdOpenGL::setExternalDriving(/*DsAllocator* dsall,*/unsigned int width, unsigned height) { - /* - if (swappy) - { - BeginPainting(); - d3ddevice->StretchRect(swapsurf,NULL,d3drtsurf,NULL,filter_type); - LPDIRECT3DSWAPCHAIN9 temp=swappy; - LPDIRECT3DSURFACE9 tempsurf=swapsurf; - swappy=NULL; - swapsurf=NULL; - EndPainting(); - tempsurf->Release(); - temp->Release(); - } - - if (dsall==NULL) { - external_driving=false; - dsallocator=NULL; - return; - } - WaitForSingleObject(event,INFINITE);//We will only return if we are initted - BeginPainting(); - if (width>BACKBUFFER_WIDTH || height>BACKBUFFER_HEIGHT) - { - D3DPRESENT_PARAMETERS d3dparas; - ZeroMemory(&d3dparas,sizeof(d3dparas)); - d3dparas.BackBufferWidth=width; - d3dparas.BackBufferHeight=height; - d3dparas.Windowed=TRUE; - d3dparas.SwapEffect=D3DSWAPEFFECT_COPY; - if (d3ddevice->CreateAdditionalSwapChain(&d3dparas,&swappy)!=D3D_OK){ - Log::getInstance()->log("OSD", Log::WARN, "Could not create Swap Chain!"); - //return 0; - } else { - swappy->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&swapsurf); - } - Log::getInstance()->log("OSD", Log::INFO, "Create Additional Swap Chain %d %d!",width,height); - } - - dsallocator=dsall; - external_driving=true; - - EndPainting();*/ -} void OsdOpenGL::Blank() { BeginPainting(); diff --git a/osdopengl.h b/osdopengl.h old mode 100755 new mode 100644 index 75288f2..e2446e3 --- a/osdopengl.h +++ b/osdopengl.h @@ -83,15 +83,9 @@ class OsdOpenGL : public Osd, public Thread_TYPE Surface * createNewSurface(); - - - // This function is called from the threadMethod function in order to get Screen updates -/* void Render(); - void RenderDS(VPEOGLFrame* frame);*/ void BeginPainting(); void EndPainting(); - void setExternalDriving(/*DsAllocator* dsall,*/ unsigned int width, unsigned int height); void Blank(); void getEGLObjs(EGLDisplay *i_egl_display,EGLSurface *i_egl_surface,EGLContext *i_egl_context, EGLConfig *i_egl_config){ @@ -121,25 +115,10 @@ private: Mutex glmutex; long long lastrendertime; void InternalRendering(VPEOGLFrame* frame); - bool DoLost(); void InitVertexBuffer(float scalex,float scaley); OSDVERTEX osdvertices[4]; GLubyte osdindices[6]; - -/* GLuint osd_shader; - GLuint gen_shader; - - GLuint osd_program; - - GLuint frame_shader; - GLuint frame_program; - - GLint frame_sampler_locY; - GLint frame_sampler_locU; - GLint frame_sampler_locV; - - GLint osd_sampler_loc;*/ GLOsdShader osd_shader; GLYuv400Shader yuv400_shader; GLYuv444Shader yuv444_shader; -- 2.39.5