added osx cocoa support files

This commit is contained in:
Palana
2013-11-14 18:18:25 +01:00
parent 595dad2e70
commit d7a04aea8c
5 changed files with 611 additions and 1 deletions

View File

@@ -19,6 +19,9 @@
#include "../util/bmem.h"
#include "input.h"
#ifdef __APPLE__
#include <objc/objc-runtime.h>
#endif
/*
* This is an API-independent graphics subsystem wrapper.
@@ -410,7 +413,7 @@ struct gs_init_data {
#if defined(_WIN32)
void *hwnd;
#elif defined(__APPLE__)
/* TODO */
__unsafe_unretained id view;
#elif defined(__posix__)
/* TODO */
#endif

61
libobs/obs-cocoa.c Normal file
View File

@@ -0,0 +1,61 @@
/******************************************************************************
Copyright (C) 2013 by Ruwen Hahn <palana@stunned.de>
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "util/platform.h"
#include "util/dstr.h"
#include "obs.h"
#include "obs-data.h"
#include <unistd.h>
// support both foo.so and libfoo.so for now
static const char *plugin_patterns[] = {
"../plugins/%s.so",
"../plugins/lib%s.so"
};
static const int plugin_patterns_size = sizeof(plugin_patterns)/sizeof(plugin_patterns[0]);
char *find_plugin(const char *plugin)
{
struct dstr path;
dstr_init(&path);
for(int i = 0; i < plugin_patterns_size; i++) {
dstr_printf(&path, plugin_patterns[i], plugin);
if(!access(path.array, F_OK))
break;
}
return path.array;
}
/* on windows, points to [base directory]/libobs */
char *find_libobs_data_file(const char *file)
{
struct dstr path;
dstr_init_copy(&path, "../libobs/");
dstr_cat(&path, file);
return path.array;
}
/* on windows, data files should always be in [base directory]/data */
char *obs_find_plugin_file(const char *file)
{
struct dstr path;
dstr_init_copy(&path, "../data/");
dstr_cat(&path, file);
return path.array;
}

View File

@@ -0,0 +1,100 @@
/******************************************************************************
Copyright (c) 2013 by Ruwen Hahn <palana@stunned.de>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
******************************************************************************/
#include "base.h"
#include "platform.h"
#include "dstr.h"
#include <dlfcn.h>
#include <time.h>
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
void *os_dlopen(const char *path)
{
struct dstr dylib_name;
dstr_init_copy(&dylib_name, path);
if(!dstr_find(&dylib_name, ".so"))
dstr_cat(&dylib_name, ".so");
void *res = dlopen(dylib_name.array, RTLD_LAZY);
if(!res)
blog(LOG_ERROR, "os_dlopen(%s->%s): %s\n",
path, dylib_name.array, dlerror());
dstr_free(&dylib_name);
return res;
}
void *os_dlsym(void *module, const char *func)
{
return dlsym(module, func);
}
void os_dlclose(void *module)
{
dlclose(module);
}
void os_sleepto_ns(uint64_t time_target)
{
uint64_t current = os_gettime_ns();
if(time_target < current)
return;
time_target -= current;
struct timespec req,
remain;
memset(&req, 0, sizeof(req));
memset(&remain, 0, sizeof(remain));
req.tv_sec = time_target/1000000000;
req.tv_nsec = time_target%1000000000;
while(nanosleep(&req, &remain))
{
req = remain;
memset(&remain, 0, sizeof(remain));
}
}
void os_sleep_ms(uint32_t duration)
{
usleep(duration*1000);
}
uint64_t os_gettime_ns(void)
{
uint64_t t = mach_absolute_time();
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Nanoseconds nano = AbsoluteToNanoseconds(*(AbsoluteTime*) &t);
#pragma clang diagnostic pop
return *(uint64_t*) &nano;
}
uint64_t os_gettime_ms(void)
{
return os_gettime_ns()/1000000;
}