Remove unnecessary Src/ folders

This commit is contained in:
Jasper St. Pierre
2013-12-07 15:14:29 -05:00
parent 43e618682e
commit 34692ab826
1026 changed files with 37648 additions and 37646 deletions

View File

@ -0,0 +1,124 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "VideoConfig.h"
#include "Host.h"
#include "RenderBase.h"
#include "ConfigManager.h"
#include <wx/panel.h>
#include "VertexShaderManager.h"
#include "../GLInterface.h"
#include "AGL.h"
void cInterfaceAGL::Swap()
{
[GLWin.cocoaCtx flushBuffer];
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceAGL::Create(void *&window_handle)
{
int _tx, _ty, _twidth, _theight;
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
GLWin.cocoaWin = (NSView*)(((wxPanel*)window_handle)->GetHandle());
// Enable high-resolution display support.
[GLWin.cocoaWin setWantsBestResolutionOpenGLSurface:YES];
NSWindow *window = [GLWin.cocoaWin window];
float scale = [window backingScaleFactor];
_twidth *= scale;
_theight *= scale;
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
NSOpenGLPixelFormatAttribute attr[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, NSOpenGLPFAAccelerated, 0 };
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
initWithAttributes: attr];
if (fmt == nil) {
ERROR_LOG(VIDEO, "failed to create pixel format");
return false;
}
GLWin.cocoaCtx = [[NSOpenGLContext alloc]
initWithFormat: fmt shareContext: nil];
[fmt release];
if (GLWin.cocoaCtx == nil) {
ERROR_LOG(VIDEO, "failed to create context");
return false;
}
if (GLWin.cocoaWin == nil) {
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
[window makeFirstResponder:GLWin.cocoaWin];
[GLWin.cocoaCtx setView: GLWin.cocoaWin];
[window makeKeyAndOrderFront: nil];
return true;
}
bool cInterfaceAGL::MakeCurrent()
{
[GLWin.cocoaCtx makeCurrentContext];
return true;
}
bool cInterfaceAGL::ClearCurrent()
{
// not tested at all
//clearCurrentContext();
return true;
}
// Close backend
void cInterfaceAGL::Shutdown()
{
[GLWin.cocoaCtx clearDrawable];
[GLWin.cocoaCtx release];
GLWin.cocoaCtx = nil;
}
void cInterfaceAGL::Update()
{
NSWindow *window = [GLWin.cocoaWin window];
NSSize size = [GLWin.cocoaWin frame].size;
float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;
if( s_backbuffer_width == size.width
&& s_backbuffer_height == size.height)
return;
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
[GLWin.cocoaCtx update];
}

View File

@ -0,0 +1,39 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _INTERFACEAGL_H_
#define _INTERFACEAGL_H_
#ifdef __APPLE__
#include <GL/glew.h>
#import <AppKit/AppKit.h>
#endif
#include "InterfaceBase.h"
class cInterfaceAGL : public cInterfaceBase
{
public:
void Swap();
bool Create(void *&window_handle);
bool MakeCurrent();
bool ClearCurrent();
void Shutdown();
void Update();
};
#endif

View File

@ -0,0 +1,164 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Host.h"
#include "RenderBase.h"
#include "../GLInterface.h"
#include "EGL.h"
// Show the current FPS
void cInterfaceEGL::UpdateFPSDisplay(const char *text)
{
Platform.UpdateFPSDisplay(text);
}
void cInterfaceEGL::Swap()
{
eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}
void cInterfaceEGL::SwapInterval(int Interval)
{
eglSwapInterval(GLWin.egl_dpy, Interval);
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceEGL::Create(void *&window_handle)
{
const char *s;
EGLint egl_major, egl_minor;
EGLConfig config;
EGLint num_configs;
// attributes for a visual in RGBA format with at least
// 8 bits per color
int attribs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_NONE };
EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
switch(s_opengl_mode)
{
case MODE_OPENGL:
attribs[1] = EGL_OPENGL_BIT;
ctx_attribs[0] = EGL_NONE;
break;
case MODE_OPENGLES2:
attribs[1] = EGL_OPENGL_ES2_BIT;
ctx_attribs[1] = 2;
break;
case MODE_OPENGLES3:
attribs[1] = (1 << 6); /* EGL_OPENGL_ES3_BIT_KHR */
ctx_attribs[1] = 3;
break;
default:
ERROR_LOG(VIDEO, "Unknown opengl mode set\n");
return false;
break;
}
if(!Platform.SelectDisplay())
return false;
GLWin.egl_dpy = Platform.EGLGetDisplay();
if (!GLWin.egl_dpy) {
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n");
return false;
}
GLWin.platform = Platform.platform;
if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) {
INFO_LOG(VIDEO, "Error: eglInitialize() failed\n");
return false;
}
if (s_opengl_mode == MODE_OPENGL)
eglBindAPI(EGL_OPENGL_API);
else
eglBindAPI(EGL_OPENGL_ES_API);
if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) {
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
exit(1);
}
if (!Platform.Init(config))
return false;
s = eglQueryString(GLWin.egl_dpy, EGL_VERSION);
INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s);
s = eglQueryString(GLWin.egl_dpy, EGL_VENDOR);
INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", s);
s = eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS);
INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", s);
s = eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS);
INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", s);
GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
if (!GLWin.egl_ctx) {
INFO_LOG(VIDEO, "Error: eglCreateContext failed\n");
exit(1);
}
GLWin.native_window = Platform.CreateWindow();
GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config,
GLWin.native_window, NULL);
if (!GLWin.egl_surf) {
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n");
exit(1);
}
Platform.ToggleFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen);
window_handle = (void *)GLWin.native_window;
return true;
}
bool cInterfaceEGL::MakeCurrent()
{
return eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx);
}
// Close backend
void cInterfaceEGL::Shutdown()
{
Platform.DestroyWindow();
if (GLWin.egl_ctx && !eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx))
NOTICE_LOG(VIDEO, "Could not release drawing context.");
if (GLWin.egl_ctx)
{
eglMakeCurrent(GLWin.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if(!eglDestroyContext(GLWin.egl_dpy, GLWin.egl_ctx))
NOTICE_LOG(VIDEO, "Could not destroy drawing context.");
if(!eglDestroySurface(GLWin.egl_dpy, GLWin.egl_surf))
NOTICE_LOG(VIDEO, "Could not destroy window surface.");
if(!eglTerminate(GLWin.egl_dpy))
NOTICE_LOG(VIDEO, "Could not destroy display connection.");
GLWin.egl_ctx = NULL;
}
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _INTERFACEEGL_H_
#define _INTERFACEEGL_H_
#if USE_GLES
#ifdef USE_GLES3
#include <GLES3/gl3.h>
#else
#include <GLES2/gl2.h>
#endif
#else
#include <GL/glxew.h>
#include <GL/gl.h>
#endif
#include "InterfaceBase.h"
class cPlatform;
class cInterfaceEGL : public cInterfaceBase
{
private:
cPlatform Platform;
public:
friend class cPlatform;
void SwapInterval(int Interval);
void Swap();
void UpdateFPSDisplay(const char *Text);
bool Create(void *&window_handle);
bool MakeCurrent();
void Shutdown();
};
#endif

View File

@ -0,0 +1,160 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Host.h"
#include "RenderBase.h"
#include "VideoConfig.h"
#include "../GLInterface.h"
#include "GLX.h"
// Show the current FPS
void cInterfaceGLX::UpdateFPSDisplay(const char *text)
{
XStoreName(GLWin.evdpy, GLWin.win, text);
}
void cInterfaceGLX::SwapInterval(int Interval)
{
if (glXSwapIntervalSGI)
glXSwapIntervalSGI(Interval);
else
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
}
void cInterfaceGLX::Swap()
{
glXSwapBuffers(GLWin.dpy, GLWin.win);
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceGLX::Create(void *&window_handle)
{
int _tx, _ty, _twidth, _theight;
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
int glxMajorVersion, glxMinorVersion;
// attributes for a single buffered visual in RGBA format with at least
// 8 bits per color
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None};
// attributes for a double buffered visual in RGBA format with at least
// 8 bits per color
int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None };
int attrListDefault[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None };
GLWin.dpy = XOpenDisplay(0);
GLWin.evdpy = XOpenDisplay(0);
GLWin.parent = (Window)window_handle;
GLWin.screen = DefaultScreen(GLWin.dpy);
if (GLWin.parent == 0)
GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen);
glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion);
NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion);
// Get an appropriate visual
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl);
if (GLWin.vi == NULL)
{
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListSgl);
if (GLWin.vi != NULL)
{
ERROR_LOG(VIDEO, "Only single buffered visual!");
}
else
{
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDefault);
if (GLWin.vi == NULL)
{
ERROR_LOG(VIDEO, "Could not choose visual (glXChooseVisual)");
return false;
}
}
}
else
NOTICE_LOG(VIDEO, "Got double buffered visual!");
// Create a GLX context.
GLWin.ctx = glXCreateContext(GLWin.dpy, GLWin.vi, 0, GL_TRUE);
if (!GLWin.ctx)
{
PanicAlert("Unable to create GLX context.");
return false;
}
GLWin.x = _tx;
GLWin.y = _ty;
GLWin.width = _twidth;
GLWin.height = _theight;
XWindow.CreateXWindow();
window_handle = (void *)GLWin.win;
return true;
}
bool cInterfaceGLX::MakeCurrent()
{
// connect the glx-context to the window
#if defined(HAVE_WX) && (HAVE_WX)
Host_GetRenderWindowSize(GLWin.x, GLWin.y,
(int&)GLWin.width, (int&)GLWin.height);
XMoveResizeWindow(GLWin.evdpy, GLWin.win, GLWin.x, GLWin.y,
GLWin.width, GLWin.height);
#endif
return glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
}
bool cInterfaceGLX::ClearCurrent()
{
return glXMakeCurrent(GLWin.dpy, None, NULL);
}
// Close backend
void cInterfaceGLX::Shutdown()
{
XWindow.DestroyXWindow();
if (GLWin.ctx)
{
glXDestroyContext(GLWin.dpy, GLWin.ctx);
XCloseDisplay(GLWin.dpy);
XCloseDisplay(GLWin.evdpy);
GLWin.ctx = NULL;
}
}

View File

@ -0,0 +1,43 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _INTERFACEGLX_H_
#define _INTERFACEGLX_H_
#include <GL/glxew.h>
#include <GL/gl.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "X11_Util.h"
#include "InterfaceBase.h"
class cInterfaceGLX : public cInterfaceBase
{
private:
cX11Window XWindow;
public:
friend class cX11Window;
void SwapInterval(int Interval);
void Swap();
void UpdateFPSDisplay(const char *Text);
bool Create(void *&window_handle);
bool MakeCurrent();
bool ClearCurrent();
void Shutdown();
};
#endif

View File

@ -0,0 +1,32 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#ifndef _GLINTERFACEBASE_H_
#define _GLINTERFACEBASE_H_
class cInterfaceBase
{
protected:
// Window dimensions.
u32 s_backbuffer_width;
u32 s_backbuffer_height;
u32 s_opengl_mode;
public:
virtual void Swap() {}
virtual void UpdateFPSDisplay(const char *Text) {}
virtual void SetMode(u32 mode) { s_opengl_mode = mode; }
virtual u32 GetMode() { return s_opengl_mode; }
virtual bool Create(void *&window_handle) { return true; }
virtual bool MakeCurrent() { return true; }
virtual bool ClearCurrent() { return true; }
virtual void Shutdown() {}
virtual void SwapInterval(int Interval) { }
virtual u32 GetBackBufferWidth() { return s_backbuffer_width; }
virtual u32 GetBackBufferHeight() { return s_backbuffer_height; }
virtual void SetBackBufferDimensions(u32 W, u32 H) {s_backbuffer_width = W; s_backbuffer_height = H; }
virtual void Update() { }
virtual bool PeekMessages() { return false; }
};
#endif

View File

@ -0,0 +1,221 @@
// Copyright (C) 2013 Scott Moreau <oreaus@gmail.com>
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Host.h"
#include "Platform.h"
bool cPlatform::SelectDisplay(void)
{
enum egl_platform selected_platform = EGL_PLATFORM_NONE;
enum egl_platform desired_platform = EGL_PLATFORM_NONE;
char *platform_env = getenv("DOLPHIN_EGL_PLATFORM");
if (platform_env)
platform_env = strdup(platform_env);
if (!platform_env)
printf("Running automatic platform detection\n");
// Try to select the platform set in the environment variable first
#if HAVE_WAYLAND
bool wayland_possible = WaylandInterface.ServerConnect();
if (platform_env && !strcmp(platform_env, "wayland"))
{
desired_platform = EGL_PLATFORM_WAYLAND;
if (wayland_possible)
selected_platform = EGL_PLATFORM_WAYLAND;
else
printf("Wayland display server connection failed\n");
}
#endif
#if HAVE_X11
bool x11_possible = XInterface.ServerConnect();
if (platform_env && !strcmp(platform_env, "x11"))
{
desired_platform = EGL_PLATFORM_X11;
if ((selected_platform != EGL_PLATFORM_WAYLAND) && x11_possible)
selected_platform = EGL_PLATFORM_X11;
else
printf("X11 display server connection failed\n");
}
#endif
// Fall back to automatic detection
if (selected_platform == EGL_PLATFORM_NONE)
{
if (platform_env && (desired_platform == EGL_PLATFORM_NONE)) {
printf("DOLPHIN_EGL_PLATFORM set to unrecognized platform \"%s\".\n"
#if HAVE_WAYLAND && !HAVE_X11
"Note: Valid value is \"wayland\" (built without x11 support)\n",
#endif
#if HAVE_X11 && !HAVE_WAYLAND
"Note: Valid values is \"x11\" (built without wayland support)\n",
#endif
#if HAVE_WAYLAND && HAVE_X11
"Note: Valid values are \"wayland\" and \"x11\"\n",
#endif
#if !HAVE_WAYLAND && !HAVE_X11
"Note: No Valid platform. Must be Android\n",
#endif
platform_env);
free(platform_env);
platform_env = NULL;
}
#if HAVE_WAYLAND
if (wayland_possible)
{
selected_platform = EGL_PLATFORM_WAYLAND;
platform_env = strdup("wayland");
}
#endif
#if HAVE_X11
if ((selected_platform != EGL_PLATFORM_WAYLAND) && x11_possible)
{
selected_platform = EGL_PLATFORM_X11;
platform_env = strdup("x11");
}
#endif
#ifdef ANDROID
selected_platform = EGL_PLATFORM_ANDROID;
#endif
if (selected_platform == EGL_PLATFORM_NONE)
{
printf("FATAL: Failed to find suitable platform for display connection\n");
goto out;
}
}
printf("Using EGL Native Display Platform: %s\n", platform_env);
out:
cPlatform::platform = selected_platform;
free(platform_env);
#if HAVE_WAYLAND
if (selected_platform != EGL_PLATFORM_WAYLAND) {
if (GLWin.wl_display)
wl_display_disconnect(GLWin.wl_display);
}
#endif
#if HAVE_X11
if (selected_platform != EGL_PLATFORM_X11) {
if (GLWin.dpy)
{
XCloseDisplay(GLWin.dpy);
XCloseDisplay(GLWin.evdpy);
}
}
#endif
if (selected_platform == EGL_PLATFORM_NONE)
return false;
return true;
}
bool cPlatform::Init(EGLConfig config)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
if (!WaylandInterface.Initialize(config))
return false;
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
if (!XInterface.Initialize(config))
return false;
#endif
#ifdef ANDROID
EGLint format;
eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry((EGLNativeWindowType)Host_GetRenderHandle(), 0, 0, format);
int none, width, height;
Host_GetRenderWindowSize(none, none, width, height);
GLWin.width = width;
GLWin.height = height;
GLInterface->SetBackBufferDimensions(width, height);
#endif
return true;
}
EGLDisplay cPlatform::EGLGetDisplay(void)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
return (EGLDisplay) WaylandInterface.EGLGetDisplay();
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
return (EGLDisplay) XInterface.EGLGetDisplay();
#endif
#ifdef ANDROID
return eglGetDisplay(EGL_DEFAULT_DISPLAY);
#endif
return NULL;
}
EGLNativeWindowType cPlatform::CreateWindow(void)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
return (EGLNativeWindowType) WaylandInterface.CreateWindow();
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
return (EGLNativeWindowType) XInterface.CreateWindow();
#endif
#ifdef ANDROID
return (EGLNativeWindowType)Host_GetRenderHandle();
#endif
return 0;
}
void cPlatform::DestroyWindow(void)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
WaylandInterface.DestroyWindow();
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
XInterface.DestroyWindow();
#endif
}
void cPlatform::UpdateFPSDisplay(const char *text)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
WaylandInterface.UpdateFPSDisplay(text);
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
XInterface.UpdateFPSDisplay(text);
#endif
}
void
cPlatform::ToggleFullscreen(bool fullscreen)
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
WaylandInterface.ToggleFullscreen(fullscreen);
#endif
#if HAVE_X11
// Only wayland uses this function
#endif
}

View File

@ -0,0 +1,167 @@
// Copyright (C) 2013 Scott Moreau <oreaus@gmail.com>
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _EGLPLATFORM_H_
#define _EGLPLATFORM_H_
#include "Thread.h"
#include "ConfigManager.h"
#if USE_EGL
// We must include wayland-egl.h before egl.h so our
// native types are defined as wayland native types
#if HAVE_WAYLAND && !HAVE_X11
#include <wayland-egl.h>
#endif
#include <EGL/egl.h>
#endif
#if HAVE_X11
#include "X11_Util.h"
#endif
#if HAVE_WAYLAND
#include "Wayland_Util.h"
#endif
#if USE_EGL
// There may be multiple EGL platforms
enum egl_platform {
EGL_PLATFORM_NONE,
EGL_PLATFORM_WAYLAND,
EGL_PLATFORM_X11,
EGL_PLATFORM_ANDROID
};
class cPlatform
{
private:
#if HAVE_X11
cXInterface XInterface;
#endif
#if HAVE_WAYLAND
cWaylandInterface WaylandInterface;
#endif
public:
enum egl_platform platform;
bool SelectDisplay(void);
bool Init(EGLConfig config);
EGLDisplay EGLGetDisplay(void);
EGLNativeWindowType CreateWindow(void);
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
void ToggleFullscreen(bool fullscreen);
};
#include "GLInterface/EGL.h"
#if HAVE_WAYLAND
#include <wayland-egl.h>
#endif
#elif defined(__APPLE__)
#include "GLInterface/AGL.h"
#elif defined(_WIN32)
#include "GLInterface/WGL.h"
#elif HAVE_X11
#include "GLInterface/GLX.h"
#endif
#if HAVE_WAYLAND
struct geometry {
int width;
int height;
};
struct xkb {
struct xkb_context *context;
struct xkb_keymap *keymap;
struct xkb_state *state;
xkb_mod_mask_t control_mask;
xkb_mod_mask_t alt_mask;
xkb_mod_mask_t shift_mask;
};
#endif
typedef struct {
// Currently Wayland/EGL and X11/EGL platforms are supported.
// The platform may be spelected at run time by setting the
// environment variable DOLPHIN_EGL_PLATFORM to "wayland" or "x11".
#if USE_EGL
EGLSurface egl_surf;
EGLContext egl_ctx;
EGLDisplay egl_dpy;
enum egl_platform platform;
#endif
EGLNativeWindowType native_window;
#if HAVE_WAYLAND
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor;
struct wl_shell *wl_shell;
struct wl_seat *wl_seat;
struct {
struct wl_pointer *wl_pointer;
uint32_t serial;
} pointer;
struct {
struct wl_keyboard *wl_keyboard;
struct xkb xkb;
uint32_t modifiers;
} keyboard;
struct wl_shm *wl_shm;
struct wl_cursor_theme *wl_cursor_theme;
struct wl_cursor *wl_cursor;
struct wl_surface *wl_cursor_surface;
struct geometry geometry, window_size;
struct wl_egl_window *wl_egl_native;
struct wl_surface *wl_surface;
struct wl_shell_surface *wl_shell_surface;
struct wl_callback *wl_callback;
bool fullscreen, configured, frame_drawn, swap_complete, running;
#endif
#if HAVE_X11
int screen;
// dpy used for egl/glx stuff, evdpy for window events etc.
// evdpy is to be used by XEventThread only
Display *dpy;
Display *evdpy;
#if !USE_EGL
GLXContext ctx;
#endif
Window win;
Window parent;
XVisualInfo *vi;
XSetWindowAttributes attr;
std::thread xEventThread;
int x, y;
unsigned int width, height;
#elif defined(ANDROID)
unsigned int width, height;
#elif defined(__APPLE__)
NSWindow *cocoaWin;
NSOpenGLContext *cocoaCtx;
#endif
} GLWindow;
enum GLInterfaceMode {
MODE_OPENGL = 0,
MODE_OPENGLES2,
MODE_OPENGLES3,
};
extern cInterfaceBase *GLInterface;
extern GLWindow GLWin;
#endif

View File

@ -0,0 +1,178 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "VideoConfig.h"
#include "Host.h"
#include "RenderBase.h"
#include "VertexShaderManager.h"
#include "../GLInterface.h"
#include "WGL.h"
#include "EmuWindow.h"
static HDC hDC = NULL; // Private GDI Device Context
static HGLRC hRC = NULL; // Permanent Rendering Context
void cInterfaceWGL::SwapInterval(int Interval)
{
if (WGLEW_EXT_swap_control)
wglSwapIntervalEXT(Interval);
else
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
}
void cInterfaceWGL::Swap()
{
SwapBuffers(hDC);
}
// Draw messages on top of the screen
bool cInterfaceWGL::PeekMessages()
{
// TODO: peekmessage
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return FALSE;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE;
}
// Show the current FPS
void cInterfaceWGL::UpdateFPSDisplay(const char *text)
{
TCHAR temp[512];
swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs"), text);
EmuWindow::SetWindowText(temp);
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceWGL::Create(void *&window_handle)
{
int _tx, _ty, _twidth, _theight;
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Please wait..."));
if (window_handle == NULL)
{
Host_SysMessage("failed to create window");
return false;
}
// Show the window
EmuWindow::Show();
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // 8bit Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
0, // 0Bit Z-Buffer (Depth Buffer)
0, // 0bit Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
GLuint PixelFormat; // Holds The Results After Searching For A Match
if (!(hDC=GetDC(EmuWindow::GetWnd()))) {
PanicAlert("(1) Can't create an OpenGL Device context. Fail.");
return false;
}
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) {
PanicAlert("(2) Can't find a suitable PixelFormat.");
return false;
}
if (!SetPixelFormat(hDC, PixelFormat, &pfd)) {
PanicAlert("(3) Can't set the PixelFormat.");
return false;
}
if (!(hRC = wglCreateContext(hDC))) {
PanicAlert("(4) Can't create an OpenGL rendering context.");
return false;
}
return true;
}
bool cInterfaceWGL::MakeCurrent()
{
return wglMakeCurrent(hDC, hRC) ? true : false;
}
bool cInterfaceWGL::ClearCurrent()
{
return wglMakeCurrent(hDC, NULL) ? true : false;
}
// Update window width, size and etc. Called from Render.cpp
void cInterfaceWGL::Update()
{
RECT rcWindow;
if (!EmuWindow::GetParentWnd())
{
// We are not rendering to a child window - use client size.
GetClientRect(EmuWindow::GetWnd(), &rcWindow);
}
else
{
// We are rendering to a child window - use parent size.
GetWindowRect(EmuWindow::GetParentWnd(), &rcWindow);
}
// Get the new window width and height
// See below for documentation
int width = rcWindow.right - rcWindow.left;
int height = rcWindow.bottom - rcWindow.top;
// If we are rendering to a child window
if (EmuWindow::GetParentWnd() != 0 &&
(s_backbuffer_width != width || s_backbuffer_height != height) &&
width >= 4 && height >= 4)
{
::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE);
s_backbuffer_width = width;
s_backbuffer_height = height;
}
}
// Close backend
void cInterfaceWGL::Shutdown()
{
if (hRC)
{
if (!wglMakeCurrent(NULL, NULL))
NOTICE_LOG(VIDEO, "Could not release drawing context.");
if (!wglDeleteContext(hRC))
ERROR_LOG(VIDEO, "Attempt to release rendering context failed.");
hRC = NULL;
}
if (hDC && !ReleaseDC(EmuWindow::GetWnd(), hDC))
{
ERROR_LOG(VIDEO, "Attempt to release device context failed.");
hDC = NULL;
}
}

View File

@ -0,0 +1,31 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#ifndef _INTERFACEWGL_H_
#define _INTERFACEWGL_H_
#ifdef _WIN32
#define GLEW_STATIC
#include <GL/glew.h>
#include <GL/wglew.h>
#endif
#include "InterfaceBase.h"
class cInterfaceWGL : public cInterfaceBase
{
public:
void SwapInterval(int Interval);
void Swap();
void UpdateFPSDisplay(const char *Text);
bool Create(void *&window_handle);
bool MakeCurrent();
bool ClearCurrent();
void Shutdown();
void Update();
bool PeekMessages();
};
#endif

View File

@ -0,0 +1,472 @@
// Copyright (C) 2013 Scott Moreau <oreaus@gmail.com>
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Core.h"
#include "State.h"
#include "../GLInterface.h"
#include <linux/input.h>
#include <sys/mman.h>
static void
redraw(void *data, struct wl_callback *callback, uint32_t time);
static const struct wl_callback_listener frame_listener = {
redraw
};
static void
redraw(void *data, struct wl_callback *callback, uint32_t time)
{
if (GLWin.wl_callback != callback) {
printf("Got wrong callback from wayland server\n");
exit(-1);
}
GLWin.wl_callback = NULL;
if (callback)
wl_callback_destroy(callback);
if (!GLWin.configured)
return;
// Reset the frame callback
GLWin.wl_callback = wl_surface_frame(GLWin.wl_surface);
wl_callback_add_listener(GLWin.wl_callback, &frame_listener, 0);
// Present rendered buffer on screen
//eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}
static void
hide_cursor(void)
{
if (!GLWin.pointer.wl_pointer)
return;
wl_pointer_set_cursor(GLWin.pointer.wl_pointer,
GLWin.pointer.serial, NULL, 0, 0);
}
static void
configure_callback(void *data, struct wl_callback *callback, uint32_t time)
{
wl_callback_destroy(callback);
GLWin.configured = true;
if (GLWin.wl_callback == NULL)
redraw(data, NULL, time);
}
static struct wl_callback_listener configure_callback_listener = {
configure_callback,
};
static void
handle_ping(void *data, struct wl_shell_surface *wl_shell_surface,
uint32_t serial)
{
wl_shell_surface_pong(wl_shell_surface, serial);
}
static void
handle_configure(void *data, struct wl_shell_surface *wl_shell_surface,
uint32_t edges, int32_t width, int32_t height)
{
if (GLWin.wl_egl_native)
wl_egl_window_resize(GLWin.wl_egl_native, width, height, 0, 0);
GLWin.geometry.width = width;
GLWin.geometry.height = height;
GLInterface->SetBackBufferDimensions(width, height);
if (!GLWin.fullscreen)
GLWin.window_size = GLWin.geometry;
}
static void
handle_popup_done(void *data, struct wl_shell_surface *wl_shell_surface)
{
}
static const struct wl_shell_surface_listener shell_surface_listener = {
handle_ping,
handle_configure,
handle_popup_done
};
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy)
{
GLWin.pointer.serial = serial;
if (GLWin.fullscreen)
hide_cursor();
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface)
{
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer,
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{
}
static void
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button,
uint32_t state)
{
}
static void
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
}
static const struct wl_pointer_listener pointer_listener = {
pointer_handle_enter,
pointer_handle_leave,
pointer_handle_motion,
pointer_handle_button,
pointer_handle_axis,
};
void setup_callback_listener()
{
struct wl_callback *callback;
callback = wl_display_sync(GLWin.wl_display);
wl_callback_add_listener(callback, &configure_callback_listener, 0);
}
static void
toggle_fullscreen(bool fullscreen)
{
GLWin.fullscreen = fullscreen;
GLWin.configured = false;
if (fullscreen) {
wl_shell_surface_set_fullscreen(GLWin.wl_shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, NULL);
} else {
wl_shell_surface_set_toplevel(GLWin.wl_shell_surface);
handle_configure(NULL, GLWin.wl_shell_surface, 0,
GLWin.window_size.width,
GLWin.window_size.height);
}
setup_callback_listener();
}
static void
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
uint32_t format, int fd, uint32_t size)
{
char *map_str;
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
close(fd);
return;
}
map_str = (char *) mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (map_str == MAP_FAILED) {
close(fd);
return;
}
GLWin.keyboard.xkb.keymap = xkb_map_new_from_string(GLWin.keyboard.xkb.context,
map_str,
XKB_KEYMAP_FORMAT_TEXT_V1,
(xkb_keymap_compile_flags) 0);
munmap(map_str, size);
close(fd);
if (!GLWin.keyboard.xkb.keymap) {
fprintf(stderr, "failed to compile keymap\n");
return;
}
GLWin.keyboard.xkb.state = xkb_state_new(GLWin.keyboard.xkb.keymap);
if (!GLWin.keyboard.xkb.state) {
fprintf(stderr, "failed to create XKB state\n");
xkb_map_unref(GLWin.keyboard.xkb.keymap);
GLWin.keyboard.xkb.keymap = NULL;
return;
}
GLWin.keyboard.xkb.control_mask =
1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Control");
GLWin.keyboard.xkb.alt_mask =
1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Mod1");
GLWin.keyboard.xkb.shift_mask =
1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Shift");
}
static void
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface,
struct wl_array *keys)
{
}
static void
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface)
{
}
static void
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t time, uint32_t key,
uint32_t state)
{
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;
if (key == KEY_ESC)
GLWin.running = false;
else if ((key == KEY_P) ||
((key == KEY_ENTER) && (GLWin.keyboard.modifiers == 0)))
Core::SetState((Core::GetState() == Core::CORE_RUN) ?
Core::CORE_PAUSE : Core::CORE_RUN);
else if (key == KEY_F)
toggle_fullscreen(!GLWin.fullscreen);
else if ((key == KEY_ENTER) && (GLWin.keyboard.modifiers == MOD_ALT_MASK))
toggle_fullscreen(!GLWin.fullscreen);
else if (key >= KEY_F1 && key <= KEY_F8) {
int slot_number = key - KEY_F1 + 1;
if (GLWin.keyboard.modifiers == MOD_SHIFT_MASK)
State::Save(slot_number);
else
State::Load(slot_number);
}
else if (key == KEY_F9)
Core::SaveScreenShot();
else if (key == KEY_F11)
State::LoadLastSaved();
else if (key == KEY_F12) {
if (GLWin.keyboard.modifiers == MOD_SHIFT_MASK)
State::UndoLoadState();
else
State::UndoSaveState();
}
}
static void
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t mods_depressed,
uint32_t mods_latched, uint32_t mods_locked,
uint32_t group)
{
xkb_mod_mask_t mask;
xkb_state_update_mask(GLWin.keyboard.xkb.state, mods_depressed, mods_latched,
mods_locked, 0, 0, group);
mask = xkb_state_serialize_mods(GLWin.keyboard.xkb.state,
(xkb_state_component)
(XKB_STATE_DEPRESSED |
XKB_STATE_LATCHED));
GLWin.keyboard.modifiers = 0;
if (mask & GLWin.keyboard.xkb.control_mask)
GLWin.keyboard.modifiers |= MOD_CONTROL_MASK;
if (mask & GLWin.keyboard.xkb.alt_mask)
GLWin.keyboard.modifiers |= MOD_ALT_MASK;
if (mask & GLWin.keyboard.xkb.shift_mask)
GLWin.keyboard.modifiers |= MOD_SHIFT_MASK;
}
static const struct wl_keyboard_listener keyboard_listener = {
keyboard_handle_keymap,
keyboard_handle_enter,
keyboard_handle_leave,
keyboard_handle_key,
keyboard_handle_modifiers,
};
static void
seat_handle_capabilities(void *data, struct wl_seat *seat,
uint32_t caps)
{
struct wl_pointer *wl_pointer = NULL;
struct wl_keyboard *wl_keyboard = NULL;
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl_pointer) {
wl_pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(wl_pointer, &pointer_listener, 0);
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl_pointer) {
wl_pointer_destroy(wl_pointer);
wl_pointer = NULL;
}
GLWin.pointer.wl_pointer = wl_pointer;
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl_keyboard) {
wl_keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, 0);
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl_keyboard) {
wl_keyboard_destroy(wl_keyboard);
wl_keyboard = NULL;
}
GLWin.keyboard.wl_keyboard = wl_keyboard;
}
static const struct wl_seat_listener seat_listener = {
seat_handle_capabilities,
};
static void
registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
if (strcmp(interface, "wl_compositor") == 0) {
GLWin.wl_compositor = (wl_compositor *)
wl_registry_bind(registry, name,
&wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) {
GLWin.wl_shell = (wl_shell *) wl_registry_bind(registry, name,
&wl_shell_interface, 1);
} else if (strcmp(interface, "wl_seat") == 0) {
GLWin.wl_seat = (wl_seat *) wl_registry_bind(registry, name,
&wl_seat_interface, 1);
wl_seat_add_listener(GLWin.wl_seat, &seat_listener, 0);
} else if (strcmp(interface, "wl_shm") == 0) {
GLWin.wl_shm = (wl_shm *) wl_registry_bind(registry, name,
&wl_shm_interface, 1);
GLWin.wl_cursor_theme = (wl_cursor_theme *) wl_cursor_theme_load(NULL, 32, GLWin.wl_shm);
GLWin.wl_cursor = (wl_cursor *)
wl_cursor_theme_get_cursor(GLWin.wl_cursor_theme, "left_ptr");
}
}
static void
registry_handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name)
{
}
static const struct wl_registry_listener registry_listener = {
registry_handle_global,
registry_handle_global_remove
};
bool cWaylandInterface::ServerConnect(void)
{
GLWin.wl_display = wl_display_connect(NULL);
if (!GLWin.wl_display)
return false;
return true;
}
bool cWaylandInterface::Initialize(void *config)
{
if (!GLWin.wl_display) {
printf("Error: couldn't open wayland display\n");
return false;
}
GLWin.pointer.wl_pointer = NULL;
GLWin.keyboard.wl_keyboard = NULL;
GLWin.keyboard.xkb.context = xkb_context_new((xkb_context_flags) 0);
if (GLWin.keyboard.xkb.context == NULL) {
fprintf(stderr, "Failed to create XKB context\n");
return NULL;
}
GLWin.wl_registry = wl_display_get_registry(GLWin.wl_display);
wl_registry_add_listener(GLWin.wl_registry,
&registry_listener, NULL);
wl_display_dispatch(GLWin.wl_display);
GLWin.wl_cursor_surface =
wl_compositor_create_surface(GLWin.wl_compositor);
return true;
}
void *cWaylandInterface::EGLGetDisplay(void)
{
#if HAVE_X11
return eglGetDisplay((_XDisplay *) GLWin.wl_display);
#else
return eglGetDisplay(GLWin.wl_display);
#endif
}
void *cWaylandInterface::CreateWindow(void)
{
GLWin.window_size.width = 640;
GLWin.window_size.height = 480;
GLWin.fullscreen = true;
GLWin.frame_drawn = false;
GLWin.swap_complete = false;
GLWin.wl_surface = wl_compositor_create_surface(GLWin.wl_compositor);
GLWin.wl_shell_surface = wl_shell_get_shell_surface(GLWin.wl_shell,
GLWin.wl_surface);
wl_shell_surface_add_listener(GLWin.wl_shell_surface,
&shell_surface_listener, 0);
GLWin.wl_egl_native = wl_egl_window_create(GLWin.wl_surface,
GLWin.window_size.width,
GLWin.window_size.height);
#if HAVE_X11
return GLWin.wl_egl_native;
#else
return GLWin.wl_egl_native;
#endif
}
void cWaylandInterface::DestroyWindow(void)
{
wl_egl_window_destroy(GLWin.wl_egl_native);
wl_shell_surface_destroy(GLWin.wl_shell_surface);
wl_surface_destroy(GLWin.wl_surface);
if (GLWin.wl_callback)
wl_callback_destroy(GLWin.wl_callback);
}
void cWaylandInterface::UpdateFPSDisplay(const char *text)
{
wl_shell_surface_set_title(GLWin.wl_shell_surface, text);
}
void cWaylandInterface::ToggleFullscreen(bool fullscreen)
{
toggle_fullscreen(GLWin.fullscreen);
}

View File

@ -0,0 +1,42 @@
// Copyright (C) 2013 Scott Moreau <oreaus@gmail.com>
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _WAYLAND_UTIL_H_
#define _WAYLAND_UTIL_H_
#include <wayland-client.h>
#include <wayland-egl.h>
#include <wayland-cursor.h>
#include <xkbcommon/xkbcommon.h>
#define MOD_SHIFT_MASK 0x01
#define MOD_ALT_MASK 0x02
#define MOD_CONTROL_MASK 0x04
class cWaylandInterface
{
public:
bool ServerConnect(void);
bool Initialize(void *config);
void *EGLGetDisplay(void);
void *CreateWindow(void);
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
void ToggleFullscreen(bool fullscreen);
};
#endif

View File

@ -0,0 +1,189 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Host.h"
#include "VideoConfig.h"
#include "../GLInterface.h"
#if USE_EGL
bool cXInterface::ServerConnect(void)
{
GLWin.dpy = XOpenDisplay(NULL);
if (!GLWin.dpy)
return false;
return true;
}
bool cXInterface::Initialize(void *config)
{
int _tx, _ty, _twidth, _theight;
XVisualInfo visTemplate;
int num_visuals;
EGLint vid;
if (!GLWin.dpy) {
printf("Error: couldn't open X display\n");
return false;
}
if (!eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
exit(1);
}
/* The X window visual must match the EGL config */
visTemplate.visualid = vid;
GLWin.vi = XGetVisualInfo(GLWin.dpy, VisualIDMask, &visTemplate, &num_visuals);
if (!GLWin.vi) {
printf("Error: couldn't get X visual\n");
exit(1);
}
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
GLWin.x = _tx;
GLWin.y = _ty;
GLWin.width = _twidth;
GLWin.height = _theight;
GLWin.evdpy = XOpenDisplay(NULL);
GLWin.parent = GLWin.win;
GLWin.screen = DefaultScreen(GLWin.dpy);
if (GLWin.parent == 0)
GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen);
/* Set initial projection/viewing transformation.
* We can't be sure we'll get a ConfigureNotify event when the window
* first appears.
*/
glViewport(0, 0, (GLint) GLWin.width, (GLint) GLWin.height);
return true;
}
void *cXInterface::EGLGetDisplay(void)
{
return eglGetDisplay(GLWin.dpy);
}
void *cXInterface::CreateWindow(void)
{
Atom wmProtocols[1];
// Setup window attributes
GLWin.attr.colormap = XCreateColormap(GLWin.evdpy,
GLWin.parent, GLWin.vi->visual, AllocNone);
GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask;
GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen);
GLWin.attr.border_pixel = 0;
// Create the window
GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent,
GLWin.x, GLWin.y, GLWin.width, GLWin.height, 0,
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True);
XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1);
XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, NULL, 0, NULL);
XMapRaised(GLWin.evdpy, GLWin.win);
XSync(GLWin.evdpy, True);
GLWin.xEventThread = std::thread(&cXInterface::XEventThread, this);
// Control window size and picture scaling
GLInterface->SetBackBufferDimensions(GLWin.width, GLWin.height);
return (void *) GLWin.win;
}
void cXInterface::DestroyWindow(void)
{
XDestroyWindow(GLWin.evdpy, GLWin.win);
GLWin.win = 0;
if (GLWin.xEventThread.joinable())
GLWin.xEventThread.join();
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
}
void cXInterface::UpdateFPSDisplay(const char *text)
{
XStoreName(GLWin.evdpy, GLWin.win, text);
}
void cXInterface::XEventThread()
#else
void cX11Window::CreateXWindow(void)
{
Atom wmProtocols[1];
// Setup window attributes
GLWin.attr.colormap = XCreateColormap(GLWin.evdpy,
GLWin.parent, GLWin.vi->visual, AllocNone);
GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask;
GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen);
GLWin.attr.border_pixel = 0;
// Create the window
GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent,
GLWin.x, GLWin.y, GLWin.width, GLWin.height, 0,
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True);
XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1);
XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, NULL, 0, NULL);
XMapRaised(GLWin.evdpy, GLWin.win);
XSync(GLWin.evdpy, True);
GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this);
}
void cX11Window::DestroyXWindow(void)
{
XUnmapWindow(GLWin.evdpy, GLWin.win);
GLWin.win = 0;
if (GLWin.xEventThread.joinable())
GLWin.xEventThread.join();
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
}
void cX11Window::XEventThread()
#endif
{
while (GLWin.win)
{
XEvent event;
for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--)
{
XNextEvent(GLWin.evdpy, &event);
switch(event.type) {
case ConfigureNotify:
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
case ClientMessage:
if ((unsigned long) event.xclient.data.l[0] ==
XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", False))
Host_Message(WM_USER_STOP);
break;
default:
break;
}
}
Common::SleepCurrentThread(20);
}
}

View File

@ -0,0 +1,48 @@
// Copyright (C) 2003 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _X11_UTIL_H_
#define _X11_UTIL_H_
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xutil.h>
#if USE_EGL
class cXInterface
{
private:
void XEventThread();
public:
bool ServerConnect(void);
bool Initialize(void *config);
void *EGLGetDisplay(void);
void *CreateWindow(void);
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
};
#else
class cX11Window
{
private:
void XEventThread();
public:
void CreateXWindow(void);
void DestroyXWindow(void);
};
#endif
#endif