GTK : Removed the XVideo renderer since it was badly written, and OpenGL

does a better job in all cases now.
This commit is contained in:
bgk 2009-03-19 10:41:38 +00:00
parent 7595ec268f
commit 0354e4aa06
9 changed files with 14 additions and 356 deletions

View File

@ -49,7 +49,6 @@ IF(NOT NO_GTK)
PKG_CHECK_MODULES ( GLIBMM glibmm-2.4 )
PKG_CHECK_MODULES ( GIOMM giomm-2.4 )
PKG_CHECK_MODULES ( GLADEMM libglademm-2.4 )
PKG_CHECK_MODULES ( XV xv )
PKG_CHECK_MODULES ( GTKGLMM gtkglextmm-x11-1.2 )
ENDIF(NOT NO_GTK)
@ -67,9 +66,9 @@ ENDIF( WITH_LIRC )
# Check that the dependencies are met to build the GTK frontend
IF( NOT NO_GTK )
IF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND AND XV_FOUND )
IF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND )
SET( CAN_BUILD_GVBAM 1 )
ENDIF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND AND XV_FOUND )
ENDIF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND )
ENDIF( NOT NO_GTK )
# Set the default install dir
@ -219,7 +218,6 @@ SET(SRC_GTK
src/gtk/soundconfig.cpp
src/gtk/screenarea.cpp
src/gtk/screenarea-cairo.cpp
src/gtk/screenarea-xvideo.cpp
src/gtk/screenarea-opengl.cpp
src/gtk/tools.cpp
src/gtk/window.cpp
@ -326,7 +324,6 @@ IF( CAN_BUILD_GVBAM )
${PNG_LIBRARY}
${GLADEMM_LIBRARIES}
${SDL_LIBRARY}
${XV_LIBRARIES}
${GTKGLMM_LIBRARIES}
)

View File

@ -38,14 +38,12 @@ DisplayConfigDialog::DisplayConfigDialog(GtkDialog* _pstDialog, const Glib::RefP
refBuilder->get_widget("DefaultScaleComboBox", m_poDefaultScaleComboBox);
refBuilder->get_widget("OutputOpenGL", m_poOutputOpenGLRadioButton);
refBuilder->get_widget("OutputCairo", m_poOutputCairoRadioButton);
refBuilder->get_widget("OutputXv", m_poOutputXvRadioButton);
m_poFiltersComboBox->signal_changed().connect(sigc::mem_fun(*this, &DisplayConfigDialog::vOnFilterChanged));
m_poIBFiltersComboBox->signal_changed().connect(sigc::mem_fun(*this, &DisplayConfigDialog::vOnFilterIBChanged));
m_poDefaultScaleComboBox->signal_changed().connect(sigc::mem_fun(*this, &DisplayConfigDialog::vOnScaleChanged));
m_poOutputOpenGLRadioButton->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &DisplayConfigDialog::vOnOutputChanged), VBA::Window::OutputOpenGL));
m_poOutputCairoRadioButton->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &DisplayConfigDialog::vOnOutputChanged), VBA::Window::OutputCairo));
m_poOutputXvRadioButton->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &DisplayConfigDialog::vOnOutputChanged), VBA::Window::OutputXvideo));
// Populate the filters combobox
@ -90,9 +88,6 @@ void DisplayConfigDialog::vSetConfig(Config::Section * _poConfig, VBA::Window *
case VBA::Window::OutputOpenGL:
m_poOutputOpenGLRadioButton->set_active();
break;
case VBA::Window::OutputXvideo:
m_poOutputXvRadioButton->set_active();
break;
default:
m_poOutputCairoRadioButton->set_active();
break;
@ -121,12 +116,17 @@ void DisplayConfigDialog::vOnFilterIBChanged()
void DisplayConfigDialog::vOnOutputChanged(VBA::Window::EVideoOutput _eOutput)
{
VBA::Window::EVideoOutput eOldOutput = (VBA::Window::EVideoOutput)m_poConfig->oGetKey<int>("output");
if (_eOutput == eOldOutput)
return;
if (_eOutput == VBA::Window::OutputOpenGL && m_poOutputOpenGLRadioButton->get_active())
m_poConfig->vSetKey("output", VBA::Window::OutputOpenGL);
else if (_eOutput == VBA::Window::OutputCairo && m_poOutputCairoRadioButton->get_active())
m_poConfig->vSetKey("output", VBA::Window::OutputCairo);
else if (_eOutput == VBA::Window::OutputXvideo && m_poOutputXvRadioButton->get_active())
m_poConfig->vSetKey("output", VBA::Window::OutputXvideo);
g_message("caca");
m_poWindow->vApplyConfigScreenArea();
}

View File

@ -50,7 +50,6 @@ private:
Gtk::ComboBox * m_poDefaultScaleComboBox;
Gtk::RadioButton * m_poOutputOpenGLRadioButton;
Gtk::RadioButton * m_poOutputCairoRadioButton;
Gtk::RadioButton * m_poOutputXvRadioButton;
};
} // namespace VBA

View File

@ -1,253 +0,0 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "screenarea-xvideo.h"
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/Xvlib.h>
#include <cstring>
#define FOURCC_YUY2 0x32595559
namespace VBA
{
template<typename T> T min( T x, T y ) { return x < y ? x : y; }
template<typename T> T max( T x, T y ) { return x > y ? x : y; }
ScreenAreaXv::ScreenAreaXv(int _iWidth, int _iHeight, int _iScale) :
ScreenArea(_iWidth, _iHeight, _iScale),
m_iAreaTop(0),
m_iAreaLeft(0)
{
XvAdaptorInfo *pAdaptors;
unsigned int iNumAdaptors;
GdkWindow *pRoot;
memset(&m_oShm, 0, sizeof(m_oShm));
// Ugly bit of GTK+ to get the X display
Glib::RefPtr<Gdk::Window> poWindow = get_root_window();
GdkWindow *pWindow = poWindow->gobj();
m_pDisplay = gdk_x11_drawable_get_xdisplay(GDK_DRAWABLE(pWindow));
Glib::RefPtr<Gdk::Screen> poScreen = get_screen();
Glib::RefPtr<Gdk::Window> poRoot = poScreen->get_root_window();
pRoot = poRoot->gobj();
m_iXvPortId = -1;
XvQueryAdaptors(m_pDisplay,
GDK_WINDOW_XWINDOW(pRoot),
&iNumAdaptors,
&pAdaptors);
for (unsigned int i = 0; i < iNumAdaptors; i++)
{
if (pAdaptors[i].type & XvInputMask &&
pAdaptors[i].type & XvImageMask)
{
m_iXvPortId = pAdaptors[i].base_id;
}
}
XvFreeAdaptorInfo(pAdaptors);
if (m_iXvPortId < 0)
{
fprintf (stderr, "Could not open Xv output port.\n");
throw std::exception();
}
m_iFormat = FOURCC_YUY2;
/* FIXME: RGB mode is disabled for now. Someone with a graphic card that allows
RGB overlays should try to fix it.
XvImageFormatValues *pFormats;
int iNumFormats;
// Try to find an RGB format
pFormats = XvListImageFormats(m_pDisplay, m_iXvPortId, &iNumFormats);
for (int i = 0; i < iNumFormats; i++)
{
if (pFormats[i].id == 0x3 || pFormats[i].type == XvRGB)
{
// Try to find a 32-bit mode
if (pFormats[i].bits_per_pixel == 32)
{
m_iFormat = pFormats[i].id;
}
}
}
*/
int iNumAttributes;
XvAttribute *pAttr = XvQueryPortAttributes(m_pDisplay, m_iXvPortId, &iNumAttributes);
for (int iAttr = 0; iAttr < iNumAttributes; iAttr++)
{
if (!strcmp(pAttr[iAttr].name, "XV_AUTOPAINT_COLORKEY"))
{
Atom oAtom = XInternAtom(m_pDisplay, "XV_AUTOPAINT_COLORKEY", True);
if (oAtom != None)
XvSetPortAttribute(m_pDisplay, m_iXvPortId, oAtom, 1);
break;
}
}
vUpdateSize();
}
ScreenAreaXv::~ScreenAreaXv()
{
XShmDetach(m_pDisplay, &m_oShm);
}
void ScreenAreaXv::vDrawPixels(u8 * _puiData)
{
GtkWidget *pDrawingArea = GTK_WIDGET(this->gobj());
GdkGC *gc = pDrawingArea->style->bg_gc[GTK_WIDGET_STATE (pDrawingArea)];
const int iScaledPitch = m_iScaledWidth * sizeof(u32) + 4;
const int iDstPitch = (m_iScaledWidth + 4) * sizeof(u16);
ScreenArea::vDrawPixels(_puiData);
vRGB32toYUY2((unsigned char*)m_pXvImage->data, m_iScaledWidth, m_iScaledHeight, iDstPitch,
(u8 *)m_puiPixels + iScaledPitch, m_iScaledWidth + 4, m_iScaledHeight + 4, iScaledPitch);
gdk_display_sync(gtk_widget_get_display(pDrawingArea));
XvShmPutImage(m_pDisplay,
m_iXvPortId,
GDK_WINDOW_XWINDOW (pDrawingArea->window),
GDK_GC_XGC (gc),
m_pXvImage,
0, 0,
m_iScaledWidth, m_iScaledHeight,
m_iAreaLeft, m_iAreaTop,
m_iAreaWidth + 4, m_iAreaHeight + 4,
True);
gdk_display_sync(gtk_widget_get_display(pDrawingArea));
}
void ScreenAreaXv::vDrawBlackScreen()
{
modify_bg(get_state(), Gdk::Color("black"));
}
void ScreenAreaXv::vRGB32toYUY2 (unsigned char* dest_ptr,
int dest_width,
int dest_height,
int dest_pitch,
unsigned char* src_ptr,
int src_width,
int src_height,
int src_pitch)
{
unsigned char* pSrc = NULL;
unsigned char* pDst = NULL;
int iR = 0;
int iG = 0;
int iB = 0;
int iY = 0;
int iU = 0;
int iV = 0;
/* Run through each row */
for (int y = 0; y < src_height; y++)
{
/* Get the src and dst row pointers */
pSrc = src_ptr + y * src_pitch;
pDst = dest_ptr + y * dest_pitch;
/* Loop along each row */
for (int x = 0; x < src_width; x++)
{
/* Convert RGB to YUV, using the following fixed-point formula:
*
* Y = (r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13
* U = (r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13
* V = (r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13
*/
#if defined(_WINDOWS)
iR = pSrc[2];
iG = pSrc[1];
iB = pSrc[0];
#else
iR = pSrc[0];
iG = pSrc[1];
iB = pSrc[2];
#endif
iY = (iR * 2104 + iG * 4130 + iB * 802 + 4096 + 131072) >> 13;
iU = (iR * -1214 - iG * 2384 + iB * 3598 + 4096 + 1048576) >> 13;
iV = (iR * 3598 - iG * 3013 - iB * 585 + 4096 + 1048576) >> 13;
/* Write out the Y */
pDst[0] = (unsigned char) iY;
/* If we are even, write out U. If odd, write V */
pDst[1] = (unsigned char) ((x & 1) ? iV : iU);
/* Advance the src pointer */
pSrc += 4;
/* Advance the dst pointer */
pDst += 2;
}
}
}
void ScreenAreaXv::vOnWidgetResize()
{
double dAspectRatio = m_iWidth / (double)m_iHeight;
if (m_oShm.shmid)
{
XShmDetach(m_pDisplay, &m_oShm);
}
m_iAreaHeight = min<int>(get_height(), get_width() / dAspectRatio);
m_iAreaWidth = min<int>(get_width(), get_height() * dAspectRatio);
m_iAreaTop = (get_height() - m_iAreaHeight) / 2;
m_iAreaLeft = (get_width() - m_iAreaWidth) / 2;
m_pXvImage = XvShmCreateImage(m_pDisplay,
m_iXvPortId,
m_iFormat,
0,
m_iFilterScale * m_iWidth + 4,
m_iFilterScale * m_iHeight + 4,
&m_oShm);
m_oShm.shmid = shmget(IPC_PRIVATE, m_pXvImage->data_size, IPC_CREAT | 0777);
m_oShm.shmaddr = (char *) shmat(m_oShm.shmid, 0, 0);
m_oShm.readOnly = FALSE;
m_pXvImage->data = m_oShm.shmaddr;
XShmAttach(m_pDisplay, &m_oShm);
}
} // namespace VBA

View File

@ -1,68 +0,0 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __VBA_SCREENAREA_XVIDEO_H__
#define __VBA_SCREENAREA_XVIDEO_H__
#include "screenarea.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xv.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/Xvlib.h>
namespace VBA
{
class ScreenAreaXv : public ScreenArea
{
public:
ScreenAreaXv(int _iWidth, int _iHeight, int _iScale = 1);
virtual ~ScreenAreaXv();
void vDrawPixels(u8 * _puiData);
void vDrawBlackScreen();
protected:
void vOnWidgetResize();
private:
Display *m_pDisplay;
XvImage *m_pXvImage;
int m_iXvPortId;
int m_iFormat;
u16* m_paYUY;
XShmSegmentInfo m_oShm;
int m_iAreaTop;
int m_iAreaLeft;
void vRGB32toYUY2 (unsigned char* dest_ptr,
int dest_width,
int dest_height,
int dest_pitch,
unsigned char* src_ptr,
int src_width,
int src_height,
int src_pitch);
};
} // namespace VBA
#endif // __VBA_SCREENAREA_XVIDEO_H__

View File

@ -86,19 +86,6 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="OutputXv">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">XVideo</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">OutputOpenGL</property>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -37,7 +37,6 @@
#include "tools.h"
#include "intl.h"
#include "screenarea-cairo.h"
#include "screenarea-xvideo.h"
#ifdef USE_OPENGL
#include "screenarea-opengl.h"
@ -102,7 +101,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
m_iJoypadMin (PAD_1),
m_iJoypadMax (PAD_4),
m_iVideoOutputMin (OutputCairo),
m_iVideoOutputMax (OutputXvideo),
m_iVideoOutputMax (OutputOpenGL),
m_bFullscreen (false)
{
m_poXml = _poXml;
@ -454,7 +453,7 @@ void Window::vInitColors(EColorFormat _eColorFormat)
void Window::vApplyConfigScreenArea()
{
EVideoOutput eVideoOutput = (EVideoOutput)m_poDisplayConfig->oGetKey<int>("output");;
EVideoOutput eVideoOutput = (EVideoOutput)m_poDisplayConfig->oGetKey<int>("output");
Gtk::Alignment * poC;
@ -472,10 +471,6 @@ void Window::vApplyConfigScreenArea()
m_poScreenArea = Gtk::manage(new ScreenAreaGl(m_iScreenWidth, m_iScreenHeight));
break;
#endif // USE_OPENGL
case OutputXvideo:
vInitColors(ColorFormatBGR);
m_poScreenArea = Gtk::manage(new ScreenAreaXv(m_iScreenWidth, m_iScreenHeight));
break;
case OutputCairo:
default:
vInitColors(ColorFormatRGB);

View File

@ -57,8 +57,7 @@ public:
enum EVideoOutput
{
OutputCairo,
OutputOpenGL,
OutputXvideo
OutputOpenGL
};
enum EEmulatorType

View File

@ -430,7 +430,9 @@ void Window::vOnDisplayConfigure()
poBuilder->get_widget_derived("DisplayConfigDialog", poDialog);
poDialog->vSetConfig(m_poDisplayConfig, this);
poDialog->set_transient_for(*this);
m_poScreenArea->vSetEnableRender(false);
poDialog->run();
m_poScreenArea->vSetEnableRender(true);
poDialog->hide();
}