提交 bf099430 编写于 作者: J jp9000

(API Change) Merge branch 'windowless-context'

API Changed (obs.h):
-----------------------------------------
- Removed member variables from struct obs_video_info:
  - window_width
  - window_height
  - window

- Removed functions:
  - obs_add_draw_callback
  - obs_remove_draw_callback
  - obs_resize
  - obs_preview_set_enabled
  - obs_preview_enabled

API Changed (graphics/graphics.h)
-----------------------------------------
- Changed third parameter of gs_create from
     const struct gs_init_data *data
  to
     uint32_t adapter

Summary
-----------------------------------------
Changing to a windowless context allows the ability to use libobs
without needing to have it depend on an open window/view, and removes
superfluous functionality that's already provided by the obs_display
functions.

Biggest benefits of windowless context:
- Make it so all window/view related code uses obs_display (which is a
  major refactor/prune)
- Allows core functions to not have to be dependent upon an existing
  window/view
- Allow the ability to make a fully CLI front end that doesn't depend on
  a window
- Allows the ability to a hypothetical CLI from a remote

Because of the API changes, multiple modules are affected by this commit
to prevent creating broken commits: libobs, libobs-opengl, libobs-d3d11,
and the UI.

In the libobs back-end, all preview/window API functions that are not
related to obs_display have been removed, and to draw on a window/view
you must now always create an obs_display (rather than having "main"
display functions and then "secondary" display functions that use
obs_display).

For the technicalities of the graphics back-end, the gs_init function
now only takes in an adapter parameter instead of window/format/etc
information.  To draw on a window/view you must now always create a swap
chain for it (note that obs_display wraps this functionality).

As for the UI, the UI has been refactored so that all dialogs/windows
that have a preview do not have to manually create OBSDisplay objects;
the OBSQTDisplay class now automatically handles all the code related to
displays.  The main window preview now also relies on that same
functionality/code.
......@@ -184,16 +184,13 @@ const static D3D_FEATURE_LEVEL featureLevels[] =
D3D_FEATURE_LEVEL_9_3,
};
void gs_device::InitDevice(const gs_init_data *data, IDXGIAdapter *adapter)
void gs_device::InitDevice(uint32_t adapterIdx, IDXGIAdapter *adapter)
{
wstring adapterName;
DXGI_SWAP_CHAIN_DESC swapDesc;
DXGI_ADAPTER_DESC desc;
D3D_FEATURE_LEVEL levelUsed = D3D_FEATURE_LEVEL_9_3;
HRESULT hr = 0;
make_swap_desc(swapDesc, data);
uint32_t createFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
//createFlags |= D3D11_CREATE_DEVICE_DEBUG;
......@@ -205,26 +202,19 @@ void gs_device::InitDevice(const gs_init_data *data, IDXGIAdapter *adapter)
char *adapterNameUTF8;
os_wcs_to_utf8_ptr(adapterName.c_str(), 0, &adapterNameUTF8);
blog(LOG_INFO, "Loading up D3D11 on adapter %s (%" PRIu32 ")",
adapterNameUTF8, data->adapter);
adapterNameUTF8, adapterIdx);
bfree(adapterNameUTF8);
hr = D3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN,
hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN,
NULL, createFlags, featureLevels,
sizeof(featureLevels) / sizeof(D3D_FEATURE_LEVEL),
D3D11_SDK_VERSION, &swapDesc,
defaultSwap.swap.Assign(), device.Assign(),
D3D11_SDK_VERSION, device.Assign(),
&levelUsed, context.Assign());
if (FAILED(hr))
throw UnsupportedHWError("Failed to create device and "
"swap chain", hr);
throw UnsupportedHWError("Failed to create device", hr);
blog(LOG_INFO, "D3D11 loaded sucessfully, feature level used: %u",
(unsigned int)levelUsed);
defaultSwap.device = this;
defaultSwap.hwnd = (HWND)data->window.hwnd;
defaultSwap.numBuffers = data->num_backbuffers;
defaultSwap.Init(data);
}
static inline void ConvertStencilSide(D3D11_DEPTH_STENCILOP_DESC &desc,
......@@ -420,9 +410,8 @@ void gs_device::UpdateViewProjMatrix()
&curViewProjMatrix);
}
gs_device::gs_device(const gs_init_data *data)
: curSwapChain (&defaultSwap),
curToplogy (D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
gs_device::gs_device(uint32_t adapterIdx)
: curToplogy (D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
{
ComPtr<IDXGIAdapter1> adapter;
......@@ -438,8 +427,8 @@ gs_device::gs_device(const gs_init_data *data)
}
InitCompiler();
InitFactory(data->adapter, adapter.Assign());
InitDevice(data, adapter);
InitFactory(adapterIdx, adapter.Assign());
InitDevice(adapterIdx, adapter);
device_set_render_target(this, NULL, NULL);
}
......@@ -515,7 +504,7 @@ static bool LogAdapterCallback(void *param, const char *name, uint32_t id)
return true;
}
int device_create(gs_device_t **p_device, const gs_init_data *data)
int device_create(gs_device_t **p_device, uint32_t adapter)
{
gs_device *device = NULL;
int errorcode = GS_SUCCESS;
......@@ -526,7 +515,7 @@ int device_create(gs_device_t **p_device, const gs_init_data *data)
blog(LOG_INFO, "Available Video Adapters: ");
device_enum_adapters(LogAdapterCallback, nullptr);
device = new gs_device(data);
device = new gs_device(adapter);
} catch (UnsupportedHWError error) {
blog(LOG_ERROR, "device_create (D3D11): %s (%08lX)", error.str,
......@@ -1048,25 +1037,26 @@ void device_set_render_target(gs_device_t *device, gs_texture_t *tex,
device->curZStencilBuffer == zstencil)
return;
if (tex->type != GS_TEXTURE_2D) {
if (tex && tex->type != GS_TEXTURE_2D) {
blog(LOG_ERROR, "device_set_render_target (D3D11): "
"texture is not a 2D texture");
return;
}
gs_texture_2d *tex2d = static_cast<gs_texture_2d*>(tex);
if (!tex2d->renderTarget[0]) {
if (tex2d && !tex2d->renderTarget[0]) {
blog(LOG_ERROR, "device_set_render_target (D3D11): "
"texture is not a render target");
return;
}
ID3D11RenderTargetView *rt = tex2d->renderTarget[0];
ID3D11RenderTargetView *rt = tex2d ? tex2d->renderTarget[0] : nullptr;
device->curRenderTarget = tex2d;
device->curRenderSide = 0;
device->curZStencilBuffer = zstencil;
device->context->OMSetRenderTargets(1, &rt, zstencil->view);
device->context->OMSetRenderTargets(1, &rt,
zstencil ? zstencil->view : nullptr);
}
void device_set_cube_render_target(gs_device_t *device, gs_texture_t *tex,
......@@ -1295,15 +1285,15 @@ void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swapchain)
{
gs_texture_t *target = device->curRenderTarget;
gs_zstencil_t *zs = device->curZStencilBuffer;
bool is_cube = device->curRenderTarget->type == GS_TEXTURE_CUBE;
bool is_cube = device->curRenderTarget ?
(device->curRenderTarget->type == GS_TEXTURE_CUBE) : false;
if (target == &device->curSwapChain->target)
target = NULL;
if (zs == &device->curSwapChain->zs)
zs = NULL;
if (swapchain == NULL)
swapchain = &device->defaultSwap;
if (device->curSwapChain) {
if (target == &device->curSwapChain->target)
target = NULL;
if (zs == &device->curSwapChain->zs)
zs = NULL;
}
device->curSwapChain = swapchain;
......@@ -1626,12 +1616,8 @@ void device_projection_pop(gs_device_t *device)
void gs_swapchain_destroy(gs_swapchain_t *swapchain)
{
if (!swapchain)
return;
gs_device *device = swapchain->device;
if (device->curSwapChain == swapchain)
device->curSwapChain = &device->defaultSwap;
if (swapchain->device->curSwapChain == swapchain)
device_load_swapchain(swapchain->device, nullptr);
delete swapchain;
}
......
......@@ -614,7 +614,6 @@ struct gs_device {
ComPtr<IDXGIFactory1> factory;
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
gs_swap_chain defaultSwap;
gs_texture_2d *curRenderTarget = nullptr;
gs_zstencil_buffer *curZStencilBuffer = nullptr;
......@@ -653,7 +652,7 @@ struct gs_device {
void InitCompiler();
void InitFactory(uint32_t adapterIdx, IDXGIAdapter1 **adapter);
void InitDevice(const gs_init_data *data, IDXGIAdapter *adapter);
void InitDevice(uint32_t adapterIdx, IDXGIAdapter *adapter);
ID3D11DepthStencilState *AddZStencilState();
ID3D11RasterizerState *AddRasterState();
......@@ -669,5 +668,5 @@ struct gs_device {
void UpdateViewProjMatrix();
gs_device(const gs_init_data *data);
gs_device(uint32_t adapterIdx);
};
......@@ -31,10 +31,9 @@ struct gl_windowinfo {
struct gl_platform {
NSOpenGLContext *context;
struct gs_swap_chain swap;
};
static NSOpenGLContext *gl_context_create(const struct gs_init_data *info)
static NSOpenGLContext *gl_context_create(void)
{
unsigned attrib_count = 0;
......@@ -44,33 +43,8 @@ static NSOpenGLContext *gl_context_create(const struct gs_init_data *info)
NSOpenGLPixelFormatAttribute attributes[40];
switch(info->num_backbuffers) {
case 0:
break;
case 1:
ADD_ATTR(NSOpenGLPFADoubleBuffer);
break;
case 2:
ADD_ATTR(NSOpenGLPFATripleBuffer);
break;
default:
blog(LOG_ERROR, "Requested backbuffers (%d) not "
"supported", info->num_backbuffers);
}
ADD_ATTR(NSOpenGLPFAClosestPolicy);
ADD_ATTR(NSOpenGLPFADoubleBuffer);
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
int color_bits = 0;//get_color_format_bits(info->format);
if(color_bits == 0) color_bits = 24;
else if(color_bits < 15) color_bits = 15;
ADD_ATTR2(NSOpenGLPFAColorSize, color_bits);
ADD_ATTR2(NSOpenGLPFAAlphaSize, 8);
ADD_ATTR2(NSOpenGLPFADepthSize, 16);
ADD_ATTR(0);
#undef ADD_ATTR2
......@@ -91,30 +65,17 @@ static NSOpenGLContext *gl_context_create(const struct gs_init_data *info)
return NULL;
}
[context setView:info->window.view];
[context clearDrawable];
return context;
}
static bool gl_init_default_swap(struct gl_platform *plat, gs_device_t *dev,
const struct gs_init_data *info)
{
if(!(plat->context = gl_context_create(info)))
return false;
plat->swap.device = dev;
plat->swap.info = *info;
plat->swap.wi = gl_windowinfo_create(info);
return plat->swap.wi != NULL;
}
struct gl_platform *gl_platform_create(gs_device_t *device,
const struct gs_init_data *info)
struct gl_platform *gl_platform_create(gs_device_t *device, uint32_t adapter)
{
struct gl_platform *plat = bzalloc(sizeof(struct gl_platform));
if(!gl_init_default_swap(plat, device, info))
plat->context = gl_context_create();
if (!plat->context)
goto fail;
[plat->context makeCurrentContext];
......@@ -127,13 +88,9 @@ struct gl_platform *gl_platform_create(gs_device_t *device,
fail:
blog(LOG_ERROR, "gl_platform_create failed");
gl_platform_destroy(plat);
return NULL;
}
struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform)
{
if(platform)
return &platform->swap;
UNUSED_PARAMETER(device);
UNUSED_PARAMETER(adapter);
return NULL;
}
......@@ -144,7 +101,6 @@ void gl_platform_destroy(struct gl_platform *platform)
[platform->context release];
platform->context = nil;
gl_windowinfo_destroy(platform->swap.wi);
bfree(platform);
}
......@@ -205,14 +161,15 @@ void device_leave_context(gs_device_t *device)
void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
{
if(!swap)
swap = &device->plat->swap;
if(device->cur_swap == swap)
return;
device->cur_swap = swap;
[device->plat->context setView:swap->wi->view];
if (swap) {
[device->plat->context setView:swap->wi->view];
} else {
[device->plat->context clearDrawable];
}
}
void device_present(gs_device_t *device)
......
......@@ -202,12 +202,12 @@ const char *device_preprocessor_name(void)
return "_OPENGL";
}
int device_create(gs_device_t **p_device, const struct gs_init_data *info)
int device_create(gs_device_t **p_device, uint32_t adapter)
{
struct gs_device *device = bzalloc(sizeof(struct gs_device));
int errorcode = GS_ERROR_FAIL;
device->plat = gl_platform_create(device, info);
device->plat = gl_platform_create(device, adapter);
if (!device->plat)
goto fail;
......@@ -219,7 +219,7 @@ int device_create(gs_device_t **p_device, const struct gs_init_data *info)
gl_enable(GL_CULL_FACE);
device_leave_context(device);
device->cur_swap = gl_platform_getswap(device->plat);
device->cur_swap = NULL;
*p_device = device;
return GS_SUCCESS;
......
......@@ -510,8 +510,7 @@ extern struct fbo_info *get_fbo(struct gs_device *device,
extern void gl_update(gs_device_t *device);
extern struct gl_platform *gl_platform_create(gs_device_t *device,
const struct gs_init_data *info);
extern struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform);
uint32_t adapter);
extern void gl_platform_destroy(struct gl_platform *platform);
extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap);
......
......@@ -33,7 +33,7 @@ struct gl_windowinfo {
* default. */
struct gl_platform {
HGLRC hrc;
struct gs_swap_chain swap;
struct gl_windowinfo window;
};
/* For now, only support basic 32bit formats for graphics output. */
......@@ -350,17 +350,56 @@ static struct gl_windowinfo *gl_windowinfo_bare(const struct gs_init_data *info)
return wi;
}
static bool init_default_swap(struct gl_platform *plat, gs_device_t *device,
int pixel_format, PIXELFORMATDESCRIPTOR *pfd,
const struct gs_init_data *info)
#define DUMMY_WNDCLASS "Dummy GL Window Class"
static bool register_dummy_class(void)
{
static bool created = false;
WNDCLASSA wc = {0};
wc.style = CS_OWNDC;
wc.hInstance = GetModuleHandleW(NULL);
wc.lpfnWndProc = (WNDPROC)DefWindowProcA;
wc.lpszClassName = DUMMY_WNDCLASS;
if (created)
return true;
if (!RegisterClassA(&wc)) {
blog(LOG_ERROR, "Failed to register dummy GL window class, %lu",
GetLastError());
return false;
}
created = true;
return true;
}
static bool create_dummy_window(struct gl_platform *plat)
{
plat->swap.device = device;
plat->swap.info = *info;
plat->swap.wi = gl_windowinfo_bare(info);
if (!plat->swap.wi)
plat->window.hwnd = CreateWindowExA(0, DUMMY_WNDCLASS,
"OpenGL Dummy Window", WS_POPUP, 0, 0, 1, 1,
NULL, NULL, GetModuleHandleW(NULL), NULL);
if (!plat->window.hwnd) {
blog(LOG_ERROR, "Failed to create dummy GL window, %lu",
GetLastError());
return false;
}
if (!gl_setpixelformat(plat->swap.wi->hdc, pixel_format, pfd))
plat->window.hdc = GetDC(plat->window.hwnd);
if (!plat->window.hdc) {
blog(LOG_ERROR, "Failed to get dummy GL window DC (%lu)",
GetLastError());
return false;
}
return true;
}
static bool init_default_swap(struct gl_platform *plat, gs_device_t *device,
int pixel_format, PIXELFORMATDESCRIPTOR *pfd)
{
if (!gl_setpixelformat(plat->window.hdc, pixel_format, pfd))
return false;
return true;
......@@ -372,32 +411,43 @@ void gl_update(gs_device_t *device)
UNUSED_PARAMETER(device);
}
struct gl_platform *gl_platform_create(gs_device_t *device,
const struct gs_init_data *info)
static void init_dummy_swap_info(struct gs_init_data *info)
{
info->format = GS_RGBA;
info->zsformat = GS_ZS_NONE;
}
struct gl_platform *gl_platform_create(gs_device_t *device, uint32_t adapter)
{
struct gl_platform *plat = bzalloc(sizeof(struct gl_platform));
struct dummy_context dummy;
struct gs_init_data info = {0};
int pixel_format;
PIXELFORMATDESCRIPTOR pfd;
memset(&dummy, 0, sizeof(struct dummy_context));
init_dummy_swap_info(&info);
if (!gl_dummy_context_init(&dummy))
goto fail;
if (!gl_init_extensions(dummy.hdc))
goto fail;
if (!register_dummy_class())
return false;
if (!create_dummy_window(plat))
return false;
/* you have to have a dummy context open before you can actually
* use wglChoosePixelFormatARB */
if (!gl_getpixelformat(dummy.hdc, info, &pixel_format, &pfd))
if (!gl_getpixelformat(dummy.hdc, &info, &pixel_format, &pfd))
goto fail;
gl_dummy_context_free(&dummy);
if (!init_default_swap(plat, device, pixel_format, &pfd, info))
if (!init_default_swap(plat, device, pixel_format, &pfd))
goto fail;
plat->hrc = gl_init_context(plat->swap.wi->hdc);
plat->hrc = gl_init_context(plat->window.hdc);
if (!plat->hrc)
goto fail;
......@@ -406,6 +456,7 @@ struct gl_platform *gl_platform_create(gs_device_t *device,
goto fail;
}
UNUSED_PARAMETER(adapter);
return plat;
fail:
......@@ -415,11 +466,6 @@ fail:
return NULL;
}
struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform)
{
return &platform->swap;
}
void gl_platform_destroy(struct gl_platform *plat)
{
if (plat) {
......@@ -428,7 +474,11 @@ void gl_platform_destroy(struct gl_platform *plat)
wglDeleteContext(plat->hrc);
}
gl_windowinfo_destroy(plat->swap.wi);
if (plat->window.hdc)
ReleaseDC(plat->window.hwnd, plat->window.hdc);
if (plat->window.hwnd)
DestroyWindow(plat->window.hwnd);
bfree(plat);
}
}
......@@ -477,7 +527,7 @@ void gl_windowinfo_destroy(struct gl_windowinfo *wi)
void device_enter_context(gs_device_t *device)
{
HDC hdc = device->plat->swap.wi->hdc;
HDC hdc = device->plat->window.hdc;
if (device->cur_swap)
hdc = device->cur_swap->wi->hdc;
......@@ -493,18 +543,16 @@ void device_leave_context(gs_device_t *device)
void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
{
HDC hdc;
if (!swap)
swap = &device->plat->swap;
HDC hdc = device->plat->window.hdc;
if (device->cur_swap == swap)
return;
device->cur_swap = swap;
if (swap) {
if (swap)
hdc = swap->wi->hdc;
if (hdc) {
if (!wgl_make_current(hdc, device->plat->hrc))
blog(LOG_ERROR, "device_load_swapchain (GL) failed");
}
......@@ -523,9 +571,14 @@ extern void gl_getclientsize(const struct gs_swap_chain *swap,
uint32_t *width, uint32_t *height)
{
RECT rc;
GetClientRect(swap->wi->hwnd, &rc);
*width = rc.right;
*height = rc.bottom;
if (swap) {
GetClientRect(swap->wi->hwnd, &rc);
*width = rc.right;
*height = rc.bottom;
} else {
*width = 0;
*height = 0;
}
}
EXPORT bool device_gdi_texture_available(void)
......
......@@ -49,6 +49,20 @@ static const int ctx_attribs[] = {
None,
};
static int ctx_pbuffer_attribs[] = {
GLX_PBUFFER_WIDTH, 2,
GLX_PBUFFER_HEIGHT, 2,
None
};
static int ctx_visual_attribs[] = {
GLX_STENCIL_SIZE, 0,
GLX_DEPTH_SIZE, 0,
GLX_BUFFER_SIZE, 32,
GLX_DOUBLEBUFFER, true,
GLX_X_RENDERABLE, true,
};
struct gl_windowinfo {
/* We store this value since we can fetch a lot
* of information not only concerning the config
......@@ -70,14 +84,9 @@ struct gl_windowinfo {
struct gl_platform {
Display *display;
GLXContext context;
struct gs_swap_chain swap;
GLXPbuffer pbuffer;
};
extern struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform)
{
return &platform->swap;
}
static void print_info_stuff(const struct gs_init_data *info)
{
blog( LOG_INFO,
......@@ -202,51 +211,53 @@ static xcb_get_geometry_reply_t* get_window_geometry(
static bool gl_context_create(struct gl_platform *plat)
{
Display *display = plat->display;
GLXFBConfig config = plat->swap.wi->config;
int major, minor;
int frame_buf_config_count = 0;
GLXFBConfig *config = NULL;
GLXContext context;
bool success = false;
{
int error_base;
int event_base;
if (!glXQueryExtension(display, &error_base, &event_base)) {
blog(LOG_ERROR, "GLX not supported.");
return 0;
}
}
/* We require glX version 1.3 */
glXQueryVersion(display, &major, &minor);
if (major < 1 || (major == 1 && minor < 3)) {
blog(LOG_ERROR, "GLX version found: %i.%i\nRequired: "
"1.3", major, minor);
if (!GLAD_GLX_ARB_create_context) {
blog(LOG_ERROR, "ARB_GLX_create_context not supported!");
return false;
}
if (!GLAD_GLX_ARB_create_context) {
blog(LOG_ERROR, "ARB_GLX_create_context not supported!");
config = glXChooseFBConfig(display, DefaultScreen(display),
ctx_visual_attribs, &frame_buf_config_count);
if (!config) {
blog(LOG_ERROR, "Failed to create OpenGL frame buffer config");
return false;
}
context = glXCreateContextAttribsARB(display, config, NULL,
context = glXCreateContextAttribsARB(display, config[0], NULL,
true, ctx_attribs);
if (!context) {
blog(LOG_ERROR, "Failed to create OpenGL context.");
return false;
goto error;
}
plat->context = context;
plat->display = display;
return true;
plat->pbuffer = glXCreatePbuffer(display, config[0],
ctx_pbuffer_attribs);
if (!plat->pbuffer) {
blog(LOG_ERROR, "Failed to create OpenGL pbuffer");
goto error;
}
success = true;
error:
XFree(config);
XSync(display, false);
return success;
}
static void gl_context_destroy(struct gl_platform *plat)
{
Display *display = plat->display;
glXMakeCurrent(display, None, 0);
glXMakeContextCurrent(display, None, None, NULL);
glXDestroyContext(display, plat->context);
bfree(plat);
}
......@@ -263,6 +274,51 @@ extern void gl_windowinfo_destroy(struct gl_windowinfo *info)
bfree(info);
}
static Display *open_windowless_display(void)
{
Display *display = XOpenDisplay(NULL);
xcb_connection_t *xcb_conn;
xcb_screen_iterator_t screen_iterator;
xcb_screen_t *screen;
int screen_num;
if (!display) {
blog(LOG_ERROR, "Unable to open new X connection!");
return NULL;
}
xcb_conn = XGetXCBConnection(display);
if (!xcb_conn) {
blog(LOG_ERROR, "Unable to get XCB connection to main display");
goto error;
}
screen_iterator = xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
screen = screen_iterator.data;
if (!screen) {
blog(LOG_ERROR, "Unable to get screen root");
goto error;
}
screen_num = get_screen_num_from_root(xcb_conn, screen->root);
if (screen_num == -1) {
blog(LOG_ERROR, "Unable to get screen number from root");
goto error;
}
if (!gladLoadGLX(display, screen_num)) {
blog(LOG_ERROR, "Unable to load GLX entry functions.");
goto error;
}
return display;
error:
if (display)
XCloseDisplay(display);
return NULL;
}
static int x_error_handler(Display *display, XErrorEvent *error)
{
char str[512];
......@@ -273,25 +329,15 @@ static int x_error_handler(Display *display, XErrorEvent *error)
}
extern struct gl_platform *gl_platform_create(gs_device_t *device,
const struct gs_init_data *info)
uint32_t adapter)
{
/* There's some trickery here... we're mixing libX11, xcb, and GLX
For an explanation see here: http://xcb.freedesktop.org/MixingCalls/
Essentially, GLX requires Xlib. Everything else we use xcb. */
struct gl_windowinfo *wi = gl_windowinfo_create(info);
struct gl_platform * plat = bmalloc(sizeof(struct gl_platform));
Display * display;
print_info_stuff(info);
if (!wi) {
blog(LOG_ERROR, "Failed to create window info!");
goto fail_wi_create;
}
Display * display = open_windowless_display();
display = XOpenDisplay(XDisplayString(info->window.display));
if (!display) {
blog(LOG_ERROR, "Unable to open new X connection!");
goto fail_display_open;
}
......@@ -299,25 +345,17 @@ extern struct gl_platform *gl_platform_create(gs_device_t *device,
XSetErrorHandler(x_error_handler);
/* We assume later that cur_swap is already set. */
device->cur_swap = &plat->swap;
device->plat = plat;
plat->display = display;
plat->swap.device = device;
plat->swap.info = *info;
plat->swap.wi = wi;
if (!gl_platform_init_swapchain(&plat->swap)) {
blog(LOG_ERROR, "Failed to initialize swap chain!");
goto fail_init_swapchain;
}
if (!gl_context_create(plat)) {
blog(LOG_ERROR, "Failed to create context!");
goto fail_context_create;
}
if (!glXMakeCurrent(plat->display, wi->window, plat->context)) {
if (!glXMakeContextCurrent(plat->display, plat->pbuffer, plat->pbuffer,
plat->context)) {
blog(LOG_ERROR, "Failed to make context current.");
goto fail_make_current;
}
......@@ -335,14 +373,12 @@ fail_make_current:
gl_context_destroy(plat);
fail_context_create:
fail_load_gl:
fail_init_swapchain:
XCloseDisplay(display);
fail_display_open:
fail_wi_create:
gl_windowinfo_destroy(wi);
free(plat);
plat = NULL;
success:
UNUSED_PARAMETER(adapter);
return plat;
}
......@@ -351,16 +387,12 @@ extern void gl_platform_destroy(struct gl_platform *plat)
if (!plat) /* In what case would platform be invalid here? */
return;
struct gl_windowinfo *wi = plat->swap.wi;
gl_context_destroy(plat);
gl_windowinfo_destroy(wi);
}
extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
{
Display *display = swap->device->plat->display;
struct gs_init_data *info = &swap->info;
xcb_connection_t *xcb_conn = XGetXCBConnection(display);
xcb_window_t wid = xcb_generate_id(xcb_conn);
xcb_window_t parent = swap->info.window.id;
......@@ -379,37 +411,11 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
goto fail_screen;
}
/* NOTE:
* So GLX is odd. You can have different extensions per screen,
* not just per video card or visual.
*
* Because of this, it makes sense to call LoadGLX everytime
* we open a frackin' window. In Windows, entry points can change
* so it makes more sense there. Here, despite it virtually never
* having the possibility of changing unless the user is intentionally
* being an asshole to cause this behavior, we still have to give it
* the correct screen num just out of good practice. *sigh*
*/
if (!gladLoadGLX(display, screen_num)) {
blog(LOG_ERROR, "Unable to load GLX entry functions.");
goto fail_load_glx;
}
/* Define our FBConfig hints for GLX... */
const int fb_attribs[] = {
GLX_STENCIL_SIZE, get_stencil_format_bits(info->zsformat),
GLX_DEPTH_SIZE, get_depth_format_bits(info->zsformat),
GLX_BUFFER_SIZE, get_color_format_bits(info->format),
GLX_DOUBLEBUFFER, true,
GLX_X_RENDERABLE, true,
None
};
/* ...fetch the best match... */
{
int num_configs;
fb_config = glXChooseFBConfig(display, screen_num,
fb_attribs, &num_configs);
ctx_visual_attribs, &num_configs);
if (!fb_config || !num_configs) {
blog(LOG_ERROR, "Failed to find FBConfig!");
......@@ -461,7 +467,6 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
fail_visual_id:
XFree(fb_config);
fail_fb_config:
fail_load_glx:
fail_screen:
fail_geometry_request:
success:
......@@ -478,11 +483,18 @@ extern void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
extern void device_enter_context(gs_device_t *device)
{
GLXContext context = device->plat->context;
XID window = device->cur_swap->wi->window;
Display *display = device->plat->display;
if (!glXMakeCurrent(display, window, context)) {
blog(LOG_ERROR, "Failed to make context current.");
if (device->cur_swap) {
XID window = device->cur_swap->wi->window;
if (!glXMakeContextCurrent(display, window, window, context)) {
blog(LOG_ERROR, "Failed to make context current.");
}
} else {
GLXPbuffer pbuf = device->plat->pbuffer;
if (!glXMakeContextCurrent(display, pbuf, pbuf, context)) {
blog(LOG_ERROR, "Failed to make context current.");
}
}
}
......@@ -490,7 +502,7 @@ extern void device_leave_context(gs_device_t *device)
{
Display *display = device->plat->display;
if (!glXMakeCurrent(display, None, NULL)) {
if (!glXMakeContextCurrent(display, None, None, NULL)) {
blog(LOG_ERROR, "Failed to reset current context.");
}
}
......@@ -527,20 +539,24 @@ extern void gl_update(gs_device_t *device)
extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
{
if (!swap)
swap = &device->plat->swap;
if (device->cur_swap == swap)
return;
Display *dpy = device->plat->display;
XID window = swap->wi->window;
GLXContext ctx = device->plat->context;
device->cur_swap = swap;
if (!glXMakeCurrent(dpy, window, ctx)) {
blog(LOG_ERROR, "Failed to make context current.");
if (swap) {
XID window = swap->wi->window;
if (!glXMakeContextCurrent(dpy, window, window, ctx)) {
blog(LOG_ERROR, "Failed to make context current.");
}
} else {
GLXPbuffer pbuf = device->plat->pbuffer;
if (!glXMakeContextCurrent(dpy, pbuf, pbuf, ctx)) {
blog(LOG_ERROR, "Failed to make context current.");
}
}
}
......
......@@ -29,7 +29,7 @@ EXPORT bool device_enum_adapters(
bool (*callback)(void *param, const char *name, uint32_t id),
void *param);
EXPORT const char *device_preprocessor_name(void);
EXPORT int device_create(gs_device_t **device, const struct gs_init_data *data);
EXPORT int device_create(gs_device_t **device, uint32_t adapter);
EXPORT void device_destroy(gs_device_t *device);
EXPORT void device_enter_context(gs_device_t *device);
EXPORT void device_leave_context(gs_device_t *device);
......
......@@ -30,8 +30,7 @@ struct gs_exports {
bool (*callback)(void*, const char*, uint32_t),
void*);
const char *(*device_preprocessor_name)(void);
int (*device_create)(gs_device_t **device,
const struct gs_init_data *data);
int (*device_create)(gs_device_t **device, uint32_t adapter);
void (*device_destroy)(gs_device_t *device);
void (*device_enter_context)(gs_device_t *device);
void (*device_leave_context)(gs_device_t *device);
......
......@@ -139,19 +139,14 @@ static bool graphics_init(struct graphics_subsystem *graphics)
return true;
}
int gs_create(graphics_t **pgraphics, const char *module,
const struct gs_init_data *data)
int gs_create(graphics_t **pgraphics, const char *module, uint32_t adapter)
{
struct gs_init_data new_data = *data;
int errcode = GS_ERROR_FAIL;
graphics_t *graphics = bzalloc(sizeof(struct graphics_subsystem));
pthread_mutex_init_value(&graphics->mutex);
pthread_mutex_init_value(&graphics->effect_mutex);
if (!new_data.num_backbuffers)
new_data.num_backbuffers = 1;
graphics->module = os_dlopen(module);
if (!graphics->module) {
errcode = GS_ERROR_MODULE_NOT_FOUND;
......@@ -162,7 +157,7 @@ int gs_create(graphics_t **pgraphics, const char *module,
module))
goto error;
errcode = graphics->exports.device_create(&graphics->device, &new_data);
errcode = graphics->exports.device_create(&graphics->device, adapter);
if (errcode != GS_SUCCESS)
goto error;
......
......@@ -452,7 +452,7 @@ EXPORT void gs_enum_adapters(
void *param);
EXPORT int gs_create(graphics_t **graphics, const char *module,
const struct gs_init_data *data);
uint32_t adapter);
EXPORT void gs_destroy(graphics_t *graphics);
EXPORT void gs_enter_context(graphics_t *graphics);
......
......@@ -235,8 +235,6 @@ struct obs_core_video {
uint32_t base_height;
float color_matrix[16];
enum obs_scale_type scale_type;
struct obs_display main_display;
};
struct obs_core_audio {
......
......@@ -113,9 +113,6 @@ static inline void render_displays(void)
pthread_mutex_unlock(&obs->data.displays_mutex);
/* render main display */
render_display(&obs->video.main_display);
gs_leave_context();
}
......
......@@ -28,18 +28,6 @@ struct obs_core *obs = NULL;
extern void add_default_module_paths(void);
extern char *find_libobs_data_file(const char *file);
static inline void make_gs_init_data(struct gs_init_data *gid,
const struct obs_video_info *ovi)
{
memcpy(&gid->window, &ovi->window, sizeof(struct gs_window));
gid->cx = ovi->window_width;
gid->cy = ovi->window_height;
gid->num_backbuffers = 2;
gid->format = GS_RGBA;
gid->zsformat = GS_ZS_NONE;
gid->adapter = ovi->adapter;
}
static inline void make_video_info(struct video_output_info *vi,
struct obs_video_info *ovi)
{
......@@ -230,14 +218,11 @@ static bool obs_init_textures(struct obs_video_info *ovi)
static int obs_init_graphics(struct obs_video_info *ovi)
{
struct obs_core_video *video = &obs->video;
struct gs_init_data graphics_data;
bool success = true;
int errorcode;
make_gs_init_data(&graphics_data, ovi);
errorcode = gs_create(&video->graphics, ovi->graphics_module,
&graphics_data);
ovi->adapter);
if (errorcode != GS_SUCCESS) {
switch (errorcode) {
case GS_ERROR_MODULE_NOT_FOUND:
......@@ -360,12 +345,6 @@ static int obs_init_video(struct obs_video_info *ovi)
return OBS_VIDEO_FAIL;
}
if (!obs_display_init(&video->main_display, NULL))
return OBS_VIDEO_FAIL;
video->main_display.cx = ovi->window_width;
video->main_display.cy = ovi->window_height;
gs_enter_context(video->graphics);
if (ovi->gpu_conversion && !obs_init_gpu_conversion(ovi))
......@@ -404,8 +383,6 @@ static void obs_free_video(void)
struct obs_core_video *video = &obs->video;
if (video->video) {
obs_display_free(&video->main_display);
video_output_close(video->video);
video->video = NULL;
......@@ -1375,30 +1352,6 @@ proc_handler_t *obs_get_proc_handler(void)
return obs->procs;
}
void obs_add_draw_callback(
void (*draw)(void *param, uint32_t cx, uint32_t cy),
void *param)
{
if (!obs) return;
obs_display_add_draw_callback(&obs->video.main_display, draw, param);
}
void obs_remove_draw_callback(
void (*draw)(void *param, uint32_t cx, uint32_t cy),
void *param)
{
if (!obs) return;
obs_display_remove_draw_callback(&obs->video.main_display, draw, param);
}
void obs_resize(uint32_t cx, uint32_t cy)
{
if (!obs || !obs->video.video || !obs->video.graphics) return;
obs_display_resize(&obs->video.main_display, cx, cy);
}
void obs_render_main_view(void)
{
if (!obs) return;
......@@ -1755,14 +1708,3 @@ void obs_context_data_setname(struct obs_context_data *context,
pthread_mutex_unlock(&context->rename_cache_mutex);
}
void obs_preview_set_enabled(bool enable)
{
if (obs)
obs->video.main_display.enabled = enable;
}
bool obs_preview_enabled(void)
{
return obs ? obs->video.main_display.enabled : false;
}
......@@ -154,9 +154,6 @@ struct obs_video_info {
uint32_t fps_num; /**< Output FPS numerator */
uint32_t fps_den; /**< Output FPS denominator */
uint32_t window_width; /**< Window width */
uint32_t window_height; /**< Window height */
uint32_t base_width; /**< Base compositing width */
uint32_t base_height; /**< Base compositing height */
......@@ -167,8 +164,6 @@ struct obs_video_info {
/** Video adapter index to use (NOTE: avoid for optimus laptops) */
uint32_t adapter;
struct gs_window window; /**< Window to render to */
/** Use shaders to convert to different color formats */
bool gpu_conversion;
......@@ -527,19 +522,6 @@ EXPORT signal_handler_t *obs_get_signal_handler(void);
/** Returns the primary obs procedure handler */
EXPORT proc_handler_t *obs_get_proc_handler(void);
/** Adds a draw callback to the main render context */
EXPORT void obs_add_draw_callback(
void (*draw)(void *param, uint32_t cx, uint32_t cy),
void *param);
/** Removes a draw callback to the main render context */
EXPORT void obs_remove_draw_callback(
void (*draw)(void *param, uint32_t cx, uint32_t cy),
void *param);
/** Changes the size of the main view */
EXPORT void obs_resize(uint32_t cx, uint32_t cy);
/** Renders the main view */
EXPORT void obs_render_main_view(void);
......@@ -567,9 +549,6 @@ EXPORT void obs_load_sources(obs_data_array_t *array);
/** Saves sources to a data array */
EXPORT obs_data_array_t *obs_save_sources(void);
EXPORT void obs_preview_set_enabled(bool enable);
EXPORT bool obs_preview_enabled(void);
/* ------------------------------------------------------------------------- */
/* View context */
......
......@@ -126,6 +126,7 @@ set(obs_SOURCES
visibility-item-widget.cpp
slider-absoluteset-style.cpp
source-list-widget.cpp
qt-display.cpp
crash-report.cpp
hotkey-edit.cpp
source-label.cpp
......
......@@ -592,6 +592,7 @@ bool OBSApp::OBSInit()
config_save(globalConfig);
}
obs_startup(locale.c_str());
mainWindow = new OBSBasic();
mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
......
......@@ -20,6 +20,7 @@
#include <QApplication>
#include <QTranslator>
#include <QPointer>
#include <obs.hpp>
#include <util/lexer.h>
#include <util/util.hpp>
#include <string>
......@@ -59,6 +60,7 @@ private:
std::string theme;
ConfigFile globalConfig;
TextLookup textLookup;
OBSContext obsContext;
QPointer<OBSMainWindow> mainWindow;
bool InitGlobalConfig();
......
#include "qt-display.hpp"
#include "qt-wrappers.hpp"
#include "display-helpers.hpp"
#include <QWindow>
#include <QScreen>
#include <QResizeEvent>
#include <QShowEvent>
OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_DontCreateNativeAncestors);
setAttribute(Qt::WA_NativeWindow);
auto windowVisible = [this] (bool visible)
{
if (!visible)
return;
if (!display) {
CreateDisplay();
} else {
QSize size = GetPixelSize(this);
obs_display_resize(display, size.width(), size.height());
}
};
auto sizeChanged = [this] (QScreen*)
{
CreateDisplay();
QSize size = GetPixelSize(this);
obs_display_resize(display, size.width(), size.height());
};
connect(windowHandle(), &QWindow::visibleChanged, windowVisible);
connect(windowHandle(), &QWindow::screenChanged, sizeChanged);
}
void OBSQTDisplay::CreateDisplay()
{
if (display || !windowHandle()->isExposed())
return;
QSize size = GetPixelSize(this);
gs_init_data info = {};
info.cx = size.width();
info.cy = size.height();
info.format = GS_RGBA;
info.zsformat = GS_ZS_NONE;
QTToGSWindow(winId(), info.window);
display = obs_display_create(&info);
emit DisplayCreated(this);
}
void OBSQTDisplay::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
CreateDisplay();
if (isVisible() && display) {
QSize size = GetPixelSize(this);
obs_display_resize(display, size.width(), size.height());
}
emit DisplayResized();
}
void OBSQTDisplay::paintEvent(QPaintEvent *event)
{
CreateDisplay();
QWidget::paintEvent(event);
}
QPaintEngine *OBSQTDisplay::paintEngine() const
{
return nullptr;
}
#pragma once
#include <QWidget>
#include <obs.hpp>
class OBSQTDisplay : public QWidget {
Q_OBJECT
virtual void resizeEvent(QResizeEvent *event) override
{
emit DisplayResized();
QWidget::resizeEvent(event);
}
OBSDisplay display;
void CreateDisplay();
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
signals:
void DisplayCreated(OBSQTDisplay *window);
void DisplayResized();
public:
inline OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags flags = 0)
: QWidget(parent, flags)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_DontCreateNativeAncestors);
setAttribute(Qt::WA_NativeWindow);
}
virtual QPaintEngine *paintEngine() const override {return nullptr;}
OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags flags = 0);
virtual QPaintEngine *paintEngine() const override;
inline obs_display_t *GetDisplay() const {return display;}
};
......@@ -72,9 +72,6 @@ OBSBasicFilters::OBSBasicFilters(QWidget *parent, OBSSource source_)
installEventFilter(CreateShortcutFilter());
connect(ui->preview, SIGNAL(DisplayResized()),
this, SLOT(OnPreviewResized()));
connect(ui->asyncFilters->itemDelegate(),
SIGNAL(closeEditor(QWidget*,
QAbstractItemDelegate::EndEditHint)),
......@@ -105,6 +102,14 @@ OBSBasicFilters::OBSBasicFilters(QWidget *parent, OBSSource source_)
if (audioOnly || (audio && !async))
ui->asyncLabel->setText(QTStr("Basic.Filters.AudioFilters"));
auto addDrawCallback = [this] ()
{
obs_display_add_draw_callback(ui->preview->GetDisplay(),
OBSBasicFilters::DrawPreview, this);
};
connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDrawCallback);
}
OBSBasicFilters::~OBSBasicFilters()
......@@ -115,21 +120,7 @@ OBSBasicFilters::~OBSBasicFilters()
void OBSBasicFilters::Init()
{
gs_init_data init_data = {};
show();
QSize previewSize = GetPixelSize(ui->preview);
init_data.cx = uint32_t(previewSize.width());
init_data.cy = uint32_t(previewSize.height());
init_data.format = GS_RGBA;
QTToGSWindow(ui->preview->winId(), init_data.window);
display = obs_display_create(&init_data);
if (display)
obs_display_add_draw_callback(display,
OBSBasicFilters::DrawPreview, this);
}
inline OBSSource OBSBasicFilters::GetFilter(int row, bool async)
......@@ -393,24 +384,12 @@ void OBSBasicFilters::AddFilterFromAction()
AddNewFilter(QT_TO_UTF8(action->data().toString()));
}
void OBSBasicFilters::OnPreviewResized()
{
QSize size = GetPixelSize(ui->preview);
obs_display_resize(display, size.width(), size.height());
}
void OBSBasicFilters::closeEvent(QCloseEvent *event)
{
QDialog::closeEvent(event);
if (!event->isAccepted())
return;
// remove draw callback and release display in case our drawable
// surfaces go away before the destructor gets called
obs_display_remove_draw_callback(display,
OBSBasicFilters::DrawPreview, this);
display = nullptr;
main->SaveProject();
}
......
......@@ -39,7 +39,6 @@ private:
OBSSource source;
OBSPropertiesView *view = nullptr;
OBSDisplay display;
OBSSignal addSignal;
OBSSignal removeSignal;
OBSSignal reorderSignal;
......@@ -78,8 +77,6 @@ private slots:
void AddFilterFromAction();
void OnPreviewResized();
void on_addAsyncFilter_clicked();
void on_removeAsyncFilter_clicked();
void on_moveAsyncFilterUp_clicked();
......
......@@ -56,13 +56,16 @@ OBSBasicInteraction::OBSBasicInteraction(QWidget *parent, OBSSource source_)
OBSData settings = obs_source_get_settings(source);
obs_data_release(settings);
connect(windowHandle(), &QWindow::screenChanged, [this]() {
QSize size = GetPixelSize(ui->preview);
obs_display_resize(display, size.width(), size.height());
});
const char *name = obs_source_get_name(source);
setWindowTitle(QTStr("Basic.InteractionWindow").arg(QT_UTF8(name)));
auto addDrawCallback = [this] ()
{
obs_display_add_draw_callback(ui->preview->GetDisplay(),
OBSBasicInteraction::DrawPreview, this);
};
connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDrawCallback);
}
OBSBasicInteraction::~OBSBasicInteraction()
......@@ -155,34 +158,12 @@ void OBSBasicInteraction::DrawPreview(void *data, uint32_t cx, uint32_t cy)
gs_viewport_pop();
}
void OBSBasicInteraction::OnInteractionResized()
{
QSize size = GetPixelSize(ui->preview);
obs_display_resize(display, size.width(), size.height());
}
void OBSBasicInteraction::resizeEvent(QResizeEvent *event)
{
if (isVisible()) {
QSize size = GetPixelSize(ui->preview);
obs_display_resize(display, size.width(), size.height());
}
QDialog::resizeEvent(event);
}
void OBSBasicInteraction::closeEvent(QCloseEvent *event)
{
QDialog::closeEvent(event);
if (!event->isAccepted())
return;
// remove draw callback and release display in case our drawable
// surfaces go away before the destructor gets called
obs_display_remove_draw_callback(display,
OBSBasicInteraction::DrawPreview, this);
display = nullptr;
config_set_int(App()->GlobalConfig(), "InteractionWindow", "cx",
width());
config_set_int(App()->GlobalConfig(), "InteractionWindow", "cy",
......@@ -381,19 +362,5 @@ bool OBSBasicInteraction::HandleKeyEvent(QKeyEvent *event)
void OBSBasicInteraction::Init()
{
gs_init_data init_data = {};
show();
QSize previewSize = GetPixelSize(ui->preview);
init_data.cx = uint32_t(previewSize.width());
init_data.cy = uint32_t(previewSize.height());
init_data.format = GS_RGBA;
QTToGSWindow(ui->preview->winId(), init_data.window);
display = obs_display_create(&init_data);
if (display)
obs_display_add_draw_callback(display,
OBSBasicInteraction::DrawPreview, this);
}
......@@ -39,7 +39,6 @@ private:
std::unique_ptr<Ui::OBSBasicInteraction> ui;
OBSSource source;
OBSDisplay display;
OBSSignal removedSignal;
OBSSignal renamedSignal;
std::unique_ptr<OBSEventFilter> eventFilter;
......@@ -58,9 +57,6 @@ private:
OBSEventFilter *BuildEventFilter();
private slots:
void OnInteractionResized();
public:
OBSBasicInteraction(QWidget *parent, OBSSource source_);
~OBSBasicInteraction();
......@@ -68,7 +64,6 @@ public:
void Init();
protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual void closeEvent(QCloseEvent *event) override;
};
......
......@@ -841,12 +841,6 @@ void OBSBasic::OBSInit()
if (ret <= 0)
throw "Failed to get scene collection json file path";
/* make sure it's fully displayed before doing any initialization */
show();
App()->processEvents();
if (!obs_startup(App()->GetLocale()))
throw "Failed to initialize libobs";
if (!InitBasicConfig())
throw "Failed to load basic.ini";
if (!ResetAudio())
......@@ -909,6 +903,20 @@ void OBSBasic::OBSInit()
RefreshSceneCollections();
RefreshProfiles();
disableSaving--;
auto addDisplay = [this] (OBSQTDisplay *window)
{
obs_display_add_draw_callback(window->GetDisplay(),
OBSBasic::RenderMain, this);
struct obs_video_info ovi;
if (obs_get_video_info(&ovi))
ResizePreview(ovi.base_width, ovi.base_height);
};
connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
show();
}
void OBSBasic::InitHotkeys()
......@@ -1055,7 +1063,7 @@ void OBSBasic::ClearHotkeys()
OBSBasic::~OBSBasic()
{
bool previewEnabled = obs_preview_enabled();
bool previewEnabled = obs_display_enabled(ui->preview->GetDisplay());
/* XXX: any obs data must be released before calling obs_shutdown.
* currently, we can't automate this with C++ RAII because of the
......@@ -1087,6 +1095,9 @@ OBSBasic::~OBSBasic()
if (advAudioWindow)
delete advAudioWindow;
obs_display_remove_draw_callback(ui->preview->GetDisplay(),
OBSBasic::RenderMain, this);
obs_enter_graphics();
gs_vertexbuffer_destroy(box);
gs_vertexbuffer_destroy(circle);
......@@ -1101,8 +1112,6 @@ OBSBasic::~OBSBasic()
* expect or want it to. */
QApplication::sendPostedEvents(this);
obs_shutdown();
config_set_int(App()->GlobalConfig(), "General", "LastVersion",
LIBOBS_API_VER);
......@@ -1954,23 +1963,7 @@ bool OBSBasic::StreamingActive()
static inline int AttemptToResetVideo(struct obs_video_info *ovi)
{
int ret = obs_reset_video(ovi);
if (ret == OBS_VIDEO_INVALID_PARAM) {
struct obs_video_info new_params = *ovi;
if (new_params.window_width == 0)
new_params.window_width = 512;
if (new_params.window_height == 0)
new_params.window_height = 512;
new_params.output_width = new_params.window_width;
new_params.output_height = new_params.window_height;
new_params.base_width = new_params.window_width;
new_params.base_height = new_params.window_height;
ret = obs_reset_video(&new_params);
}
return ret;
return obs_reset_video(ovi);
}
static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
......@@ -2038,15 +2031,6 @@ int OBSBasic::ResetVideo()
ovi.gpu_conversion = true;
ovi.scale_type = GetScaleType(basicConfig);
QTToGSWindow(ui->preview->winId(), ovi.window);
//required to make opengl display stuff on osx(?)
ResizePreview(ovi.base_width, ovi.base_height);
QSize size = GetPixelSize(ui->preview);
ovi.window_width = size.width();
ovi.window_height = size.height();
ret = AttemptToResetVideo(&ovi);
if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
/* Try OpenGL if DirectX fails on windows */
......@@ -2061,9 +2045,6 @@ int OBSBasic::ResetVideo()
}
}
if (ret == OBS_VIDEO_SUCCESS)
obs_add_draw_callback(OBSBasic::RenderMain, this);
return ret;
}
......@@ -2132,11 +2113,6 @@ void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
previewX += float(PREVIEW_EDGE_SIZE);
previewY += float(PREVIEW_EDGE_SIZE);
if (isVisible()) {
QSize size = GetPixelSize(ui->preview);
obs_resize(size.width(), size.height());
}
}
void OBSBasic::CloseDialogs()
......@@ -2212,10 +2188,6 @@ void OBSBasic::closeEvent(QCloseEvent *event)
signalHandlers.clear();
// remove draw callback in case our drawable surfaces go away before
// the destructor gets called
obs_remove_draw_callback(OBSBasic::RenderMain, this);
SaveProjectNow();
disableSaving++;
......@@ -2550,7 +2522,8 @@ void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
QTStr("Basic.Main.PreviewConextMenu.Enable"),
this, SLOT(TogglePreview()));
action->setCheckable(true);
action->setChecked(obs_preview_enabled());
action->setChecked(
obs_display_enabled(ui->preview->GetDisplay()));
previewProjector = new QMenu(QTStr("PreviewProjector"));
AddProjectorMenuMonitors(previewProjector, this,
......@@ -3163,7 +3136,7 @@ void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
QTStr("Basic.Main.PreviewConextMenu.Enable"),
this, SLOT(TogglePreview()));
action->setCheckable(true);
action->setChecked(obs_preview_enabled());
action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
previewProjector = new QMenu(QTStr("PreviewProjector"));
AddProjectorMenuMonitors(previewProjector, this,
......@@ -3476,8 +3449,8 @@ void OBSBasic::on_actionCenterToScreen_triggered()
void OBSBasic::TogglePreview()
{
bool enabled = !obs_preview_enabled();
obs_preview_set_enabled(enabled);
bool enabled = !obs_display_enabled(ui->preview->GetDisplay());
obs_display_set_enabled(ui->preview->GetDisplay(), enabled);
ui->preview->setVisible(enabled);
ui->previewDisabledLabel->setVisible(!enabled);
}
......
......@@ -85,14 +85,6 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
installEventFilter(CreateShortcutFilter());
connect(view, SIGNAL(PropertiesResized()),
this, SLOT(OnPropertiesResized()));
connect(windowHandle(), &QWindow::screenChanged, [this]() {
QSize size = GetPixelSize(preview);
obs_display_resize(display, size.width(), size.height());
});
const char *name = obs_source_get_name(source);
setWindowTitle(QTStr("Basic.PropertiesWindow").arg(QT_UTF8(name)));
......@@ -102,6 +94,14 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
"update_properties",
OBSBasicProperties::UpdateProperties,
this);
auto addDrawCallback = [this] ()
{
obs_display_add_draw_callback(preview->GetDisplay(),
OBSBasicProperties::DrawPreview, this);
};
connect(preview, &OBSQTDisplay::DisplayCreated, addDrawCallback);
}
OBSBasicProperties::~OBSBasicProperties()
......@@ -190,30 +190,8 @@ void OBSBasicProperties::DrawPreview(void *data, uint32_t cx, uint32_t cy)
gs_viewport_pop();
}
void OBSBasicProperties::OnPropertiesResized()
{
QSize size = GetPixelSize(preview);
obs_display_resize(display, size.width(), size.height());
}
void OBSBasicProperties::resizeEvent(QResizeEvent *event)
{
if (isVisible()) {
QSize size = GetPixelSize(preview);
obs_display_resize(display, size.width(), size.height());
}
QDialog::resizeEvent(event);
}
void OBSBasicProperties::Cleanup()
{
// remove draw callback and release display in case our drawable
// surfaces go away before the destructor gets called
obs_display_remove_draw_callback(display,
OBSBasicProperties::DrawPreview, this);
display = nullptr;
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cx",
width());
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cy",
......@@ -250,21 +228,7 @@ void OBSBasicProperties::closeEvent(QCloseEvent *event)
void OBSBasicProperties::Init()
{
gs_init_data init_data = {};
show();
QSize previewSize = GetPixelSize(preview);
init_data.cx = uint32_t(previewSize.width());
init_data.cy = uint32_t(previewSize.height());
init_data.format = GS_RGBA;
QTToGSWindow(preview->winId(), init_data.window);
display = obs_display_create(&init_data);
if (display)
obs_display_add_draw_callback(display,
OBSBasicProperties::DrawPreview, this);
}
int OBSBasicProperties::CheckSettings()
......
......@@ -36,7 +36,6 @@ private:
bool acceptClicked;
OBSSource source;
OBSDisplay display;
OBSSignal removedSignal;
OBSSignal renamedSignal;
OBSSignal updatePropertiesSignal;
......@@ -53,7 +52,6 @@ private:
void Cleanup();
private slots:
void OnPropertiesResized();
void on_buttonBox_clicked(QAbstractButton *button);
public:
......@@ -63,7 +61,6 @@ public:
void Init();
protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual void closeEvent(QCloseEvent *event) override;
virtual void reject() override;
};
......@@ -17,6 +17,14 @@ OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_)
setAttribute(Qt::WA_DeleteOnClose, true);
installEventFilter(CreateShortcutFilter());
auto addDrawCallback = [this] ()
{
obs_display_add_draw_callback(GetDisplay(), OBSRender, this);
obs_display_set_background_color(GetDisplay(), 0x000000);
};
connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);
}
OBSProjector::~OBSProjector()
......@@ -38,16 +46,6 @@ void OBSProjector::Init(int monitor)
if (source)
obs_source_inc_showing(source);
struct gs_init_data gid = {};
gid.cx = mi.cx;
gid.cy = mi.cy;
gid.format = GS_RGBA;
QTToGSWindow(winId(), gid.window);
display = obs_display_create(&gid);
obs_display_set_background_color(display, 0x000000);
obs_display_add_draw_callback(display, OBSRender, this);
QAction *action = new QAction(this);
action->setShortcut(Qt::Key_Escape);
addAction(action);
......
......@@ -9,7 +9,6 @@ class OBSProjector : public OBSQTDisplay {
Q_OBJECT
private:
OBSDisplay display;
OBSSource source;
OBSSignal removedSignal;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册