Browse Source

Fix render issues with main preview widget

 - I seem to have fixed ths issues with the main preview widget.  It
   seems you just need to set the right window attributes to stop it from
   breaking.  Though when opengl is enabled, there appears to be a weird
   background glitch in the Qt stuff -- I'm not entirely sure what's
   going on.  Bug in Qt?

   Also fixed the layout issues, and the widget now properly resizes and
   centers in to its parent widget.

 - Prevent the render loop from accessing data if the data isn't valid.
   Because obs->data is freed before the graphics stuff, it can cause
   the graphics to keep trying to query the obs->data.displays_mutex
   after it had already been destroyed.
jp9000 11 years ago
parent
commit
4cba9d336a
7 changed files with 62 additions and 37 deletions
  1. 2 0
      libobs/obs-data.h
  2. 3 0
      libobs/obs-video.c
  3. 4 2
      libobs/obs.c
  4. 29 19
      obs/forms/OBSBasic.ui
  5. 2 0
      obs/obs-app.cpp
  6. 6 5
      obs/qt-display.hpp
  7. 16 11
      obs/window-basic-main.cpp

+ 2 - 0
libobs/obs-data.h

@@ -88,6 +88,8 @@ struct obs_data {
 	pthread_mutex_t             displays_mutex;
 	pthread_mutex_t             outputs_mutex;
 	pthread_mutex_t             encoders_mutex;
+
+	volatile bool               valid;
 };
 
 struct obs_subsystem {

+ 3 - 0
libobs/obs-video.c

@@ -92,6 +92,9 @@ static inline void render_displays(void)
 {
 	size_t i;
 
+	if (!obs->data.valid)
+		return;
+
 	/* render extra displays/swaps */
 	pthread_mutex_lock(&obs->data.displays_mutex);
 

+ 4 - 2
libobs/obs.c

@@ -243,11 +243,11 @@ static bool obs_init_data(void)
 	if (pthread_mutex_init(&data->encoders_mutex, &attr) != 0)
 		goto fail;
 
-	success = true;
+	data->valid = true;
 
 fail:
 	pthread_mutexattr_destroy(&attr);
-	return success;
+	return data->valid;
 }
 
 static void obs_free_data(void)
@@ -255,6 +255,8 @@ static void obs_free_data(void)
 	struct obs_data *data = &obs->data;
 	uint32_t i;
 
+	data->valid = false;
+
 	for (i = 0; i < MAX_CHANNELS; i++)
 		obs_set_output_source(i, NULL);
 

+ 29 - 19
obs/forms/OBSBasic.ui

@@ -8,7 +8,7 @@
     <x>0</x>
     <y>0</y>
     <width>927</width>
-    <height>703</height>
+    <height>700</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -36,24 +36,34 @@
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
-      <layout class="QHBoxLayout" name="horizontalLayout">
-       <item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
-        <widget class="OBSQTDisplay" name="preview" native="true">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="minimumSize">
-          <size>
-           <width>32</width>
-           <height>32</height>
-          </size>
-         </property>
-        </widget>
-       </item>
-      </layout>
+      <property name="minimumSize">
+       <size>
+        <width>32</width>
+        <height>32</height>
+       </size>
+      </property>
+      <widget class="OBSQTDisplay" name="preview" native="true">
+       <property name="geometry">
+        <rect>
+         <x>50</x>
+         <y>30</y>
+         <width>32</width>
+         <height>32</height>
+        </rect>
+       </property>
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>32</width>
+         <height>32</height>
+        </size>
+       </property>
+      </widget>
      </widget>
     </item>
     <item alignment="Qt::AlignHCenter|Qt::AlignVCenter">

+ 2 - 0
obs/obs-app.cpp

@@ -26,7 +26,9 @@
 #include "window-basic-main.hpp"
 #include "platform.hpp"
 
+#ifdef _WIN32
 #include <windows.h>
+#endif
 
 using namespace std;
 

+ 6 - 5
obs/qt-display.hpp

@@ -6,14 +6,15 @@ class OBSQTDisplay : public QWidget {
 	Q_OBJECT
 
 public:
-	inline OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags f = 0)
-		: QWidget(parent, f)
+	inline OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags flags = 0)
+		: QWidget(parent, flags)
 	{
-		setAutoFillBackground(false);
-		setAttribute(Qt::WA_OpaquePaintEvent);
-		setAttribute(Qt::WA_NativeWindow);
 		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 {return nullptr;}

+ 16 - 11
obs/window-basic-main.cpp

@@ -281,28 +281,33 @@ bool OBSBasic::InitAudio()
 void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
 {
 	double targetAspect, baseAspect;
-	QSize  targetSize, newSize;
+	QSize  targetSize;
+	int x, y;
 
 	/* resize preview panel to fix to the top section of the window */
 	targetSize   = ui->previewContainer->size();
 	targetAspect = double(targetSize.width()) / double(targetSize.height());
 	baseAspect   = double(cx) / double(cy);
 
-	if (targetAspect > baseAspect)
-		newSize = QSize(targetSize.height() * baseAspect,
-				targetSize.height());
-	else
-		newSize = QSize(targetSize.width(),
-				targetSize.width() / baseAspect);
+	if (targetAspect > baseAspect) {
+		cx = targetSize.height() * baseAspect;
+		cy = targetSize.height();
+	} else {
+		cx = targetSize.width();
+		cy = targetSize.width() / baseAspect;
+	}
+
+	x = targetSize.width() /2 - cx/2;
+	y = targetSize.height()/2 - cy/2;
 
-	//ui->preview->resize(newSize);
+	ui->preview->setGeometry(x, y, cx, cy);
 
 	graphics_t graphics = obs_graphics();
-	/*if (graphics) {
+	if (graphics && isVisible()) {
 		gs_entercontext(graphics);
-		gs_resize(newSize.width(), newSize.height());
+		gs_resize(cx, cy);
 		gs_leavecontext();
-	}*/
+	}
 }
 
 void OBSBasic::closeEvent(QCloseEvent *event)