/** * It creates an OpenGL vout display. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate structure */ vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; /* */ if (CommonInit(vd)) goto error; EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)"); /* process selected GPU affinity */ int nVidiaAffinity = var_InheritInteger(vd, "gpu-affinity"); if (nVidiaAffinity >= 0) CreateGPUAffinityDC(vd, nVidiaAffinity); /* */ sys->hGLDC = GetDC(sys->hvideownd); /* Set the pixel format for the DC */ PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; SetPixelFormat(sys->hGLDC, ChoosePixelFormat(sys->hGLDC, &pfd), &pfd); /* * Create and enable the render context * For GPU affinity, attach the window DC * to the GPU affinity DC */ sys->hGLRC = wglCreateContext((sys->affinityHDC != NULL) ? sys->affinityHDC : sys->hGLDC); wglMakeCurrent(sys->hGLDC, sys->hGLRC); const char *extensions = (const char*)glGetString(GL_EXTENSIONS); #ifdef WGL_EXT_swap_control if (HasExtension(extensions, "WGL_EXT_swap_control")) { PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); if (SwapIntervalEXT) SwapIntervalEXT(1); } #endif /* */ sys->gl = vlc_object_create(object, sizeof(*sys->gl)); if (unlikely(!sys->gl)) goto error; sys->gl->swap = Swap; sys->gl->getProcAddress = OurGetProcAddress; sys->gl->sys = vd; video_format_t fmt = vd->fmt; const vlc_fourcc_t *subpicture_chromas; sys->vgl = vout_display_opengl_New(&fmt, &subpicture_chromas, sys->gl, &vd->cfg->viewpoint); if (!sys->vgl) goto error; vout_display_info_t info = vd->info; info.has_double_click = true; info.has_hide_mouse = false; info.subpicture_chromas = subpicture_chromas; /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = Prepare; vd->display = Display; vd->control = Control; vd->manage = Manage; return VLC_SUCCESS; error: Close(object); return VLC_EGENERIC; }
static int Open(vlc_gl_t *gl, unsigned width, unsigned height) { vout_display_sys_t *sys; /* Allocate structure */ gl->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; /* Process selected GPU affinity */ int nVidiaAffinity = var_InheritInteger(gl, "gpu-affinity"); if (nVidiaAffinity >= 0) CreateGPUAffinityDC(gl, nVidiaAffinity); vout_window_t *wnd = gl->surface; if (wnd->type != VOUT_WINDOW_TYPE_HWND || wnd->handle.hwnd == 0) goto error; sys->hvideownd = wnd->handle.hwnd; sys->hGLDC = GetDC(sys->hvideownd); if (sys->hGLDC == NULL) { msg_Err(gl, "Could not get the device context"); goto error; } /* Set the pixel format for the DC */ PIXELFORMATDESCRIPTOR pfd = VLC_PFD_INITIALIZER; SetPixelFormat(sys->hGLDC, ChoosePixelFormat(sys->hGLDC, &pfd), &pfd); /* Create the context. */ sys->hGLRC = wglCreateContext((sys->affinityHDC != NULL) ? sys->affinityHDC : sys->hGLDC); if (sys->hGLRC == NULL) { msg_Err(gl, "Could not create the OpenGL rendering context"); goto error; } wglMakeCurrent(sys->hGLDC, sys->hGLRC); #if 0 /* TODO pick higher display depth if possible and the source requires it */ int attribsDesired[] = { WGL_DRAW_TO_WINDOW_ARB, 1, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_RED_BITS_ARB, 10, WGL_GREEN_BITS_ARB, 10, WGL_BLUE_BITS_ARB, 10, WGL_ALPHA_BITS_ARB, 2, WGL_DOUBLE_BUFFER_ARB, 1, 0,0 }; UINT nMatchingFormats; int index = 0; PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB__ = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress( "wglChoosePixelFormatARB" ); if (wglChoosePixelFormatARB__!= NULL) wglChoosePixelFormatARB__(sys->hGLDC, attribsDesired, NULL, 1, &index, &nMatchingFormats); #endif #ifdef WGL_EXT_swap_control /* Create an GPU Affinity DC */ const char *extensions = (const char*)glGetString(GL_EXTENSIONS); if (vlc_gl_StrHasToken(extensions, "WGL_EXT_swap_control")) { PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); if (SwapIntervalEXT) SwapIntervalEXT(1); } #endif #define LOAD_EXT(name, type) \ sys->exts.name = (type) wglGetProcAddress("wgl" #name ) LOAD_EXT(GetExtensionsStringEXT, PFNWGLGETEXTENSIONSSTRINGEXTPROC); if (!sys->exts.GetExtensionsStringEXT) LOAD_EXT(GetExtensionsStringARB, PFNWGLGETEXTENSIONSSTRINGARBPROC); wglMakeCurrent(sys->hGLDC, NULL); gl->ext = VLC_GL_EXT_WGL; gl->makeCurrent = MakeCurrent; gl->releaseCurrent = ReleaseCurrent; gl->resize = NULL; gl->swap = Swap; gl->getProcAddress = OurGetProcAddress; if (sys->exts.GetExtensionsStringEXT || sys->exts.GetExtensionsStringARB) gl->wgl.getExtensionsString = GetExtensionsString; (void) width; (void) height; return VLC_SUCCESS; error: Close(gl); return VLC_EGENERIC; }