evas: Add gl_cocoa engine

SVN revision: 64653
This commit is contained in:
Nicolas Aguirre 2011-11-02 18:23:54 +00:00
parent 8d3cd7339d
commit bdfeb1df14
9 changed files with 1802 additions and 4 deletions

View File

@ -96,6 +96,10 @@ if BUILD_ENGINE_GL_SDL
pkgconfig_DATA += evas-opengl-sdl.pc
endif
if BUILD_ENGINE_GL_COCOA
pkgconfig_DATA += evas-opengl-cocoa.pc
endif
if BUILD_ENGINE_SOFTWARE_GDI
pkgconfig_DATA += evas-software-gdi.pc
endif

View File

@ -107,6 +107,7 @@ want_evas_engine_software_16_sdl="no"
want_evas_engine_gl_xlib="no"
want_evas_engine_gl_xcb="no"
want_evas_engine_gl_sdl="no"
want_evas_engine_gl_cocoa="yes"
want_evas_engine_direct3d="no"
want_evas_engine_fb="no"
want_evas_engine_directfb="no"
@ -148,6 +149,7 @@ case "$host_os" in
;;
darwin*)
want_evas_engine_software_xlib="auto"
want_evas_engine_gl_cocoa="auto"
;;
*)
want_evas_engine_software_xlib="auto"
@ -677,6 +679,8 @@ EVAS_CHECK_ENGINE([software-sdl], [${want_evas_engine_software_sdl}], [no], [Sof
EVAS_CHECK_ENGINE([gl-sdl], [${want_evas_engine_gl_sdl}], [no], [OpenGL SDL])
EVAS_CHECK_ENGINE([gl-cocoa], [${want_evas_engine_gl_cocoa}], [no], [OpenGL Cocoa])
EVAS_CHECK_ENGINE([fb], [${want_evas_engine_fb}], [no], [Framebuffer])
EVAS_CHECK_ENGINE([directfb], [${want_evas_engine_directfb}], [no], [DirectFB])
@ -842,12 +846,14 @@ have_evas_engine_gl_common="no"
have_static_evas_engine_gl_common="no"
if test "x$have_evas_engine_gl_xlib" = "xyes" \
|| test "x$have_evas_engine_gl_xcb" = "xyes" \
|| test "x$have_evas_engine_gl_sdl" = "xyes"; then
|| test "x$have_evas_engine_gl_sdl" = "xyes" \
|| test "x$have_evas_engine_gl_cocoa" = "xyes"; then
have_evas_engine_gl_common="yes"
fi
if test "x$have_evas_engine_gl_xlib" = "xstatic" \
|| test "x$have_evas_engine_gl_xcb" = "xstatic" \
|| test "x$have_evas_engine_gl_sdl" = "xstatic"; then
|| test "x$have_evas_engine_gl_sdl" = "xstatic" \
|| test "x$have_evas_engine_gl_cocoa" = "xstatic"; then
have_evas_engine_gl_common="yes"
have_static_evas_engine_gl_common="yes"
fi
@ -1768,6 +1774,7 @@ evas-directfb.pc
evas-fb.pc
evas-opengl-x11.pc
evas-opengl-sdl.pc
evas-opengl-cocoa.pc
evas-software-buffer.pc
evas-software-x11.pc
evas-software-8-x11.pc
@ -1813,6 +1820,7 @@ src/modules/engines/directfb/Makefile
src/modules/engines/gl_common/Makefile
src/modules/engines/gl_x11/Makefile
src/modules/engines/gl_sdl/Makefile
src/modules/engines/gl_cocoa/Makefile
src/modules/engines/software_sdl/Makefile
src/modules/engines/software_8/Makefile
src/modules/engines/software_8_x11/Makefile
@ -1906,6 +1914,7 @@ if test "x$have_evas_engine_gl_sdl" = "xyes"; then
else
echo
fi
echo " OpenGL Cocoa...............: $have_evas_engine_gl_cocoa"
echo " Software Framebuffer.......: $have_evas_engine_fb"
echo " DirectFB...................: $have_evas_engine_directfb"
echo " Software 8bit grayscale....: $have_evas_engine_software_8"

View File

@ -328,8 +328,6 @@ fi
])
dnl use: EVAS_CHECK_ENGINE_DEP_SOFTWARE_GDI(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
AC_DEFUN([EVAS_CHECK_ENGINE_DEP_SOFTWARE_GDI],
@ -411,6 +409,59 @@ fi
])
dnl use: EVAS_CHECK_ENGINE_DEP_GL_COCOA(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
AC_DEFUN([EVAS_CHECK_ENGINE_DEP_GL_COCOA],
[
evas_engine_[]$1[]_cflags=""
evas_engine_[]$1[]_libs=""
AC_LANG_PUSH([Objective C])
LIBS_save="$LIBS"
LIBS="$LIBS -framework Cocoa"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <Cocoa/Cocoa.h>
]],
[[
NSWindow *window;
window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 1, 1)
styleMask:(NSTitledWindowMask)
backing:NSBackingStoreBuffered
defer:NO
screen:nil
];
]])],
[
have_dep="yes"
evas_engine_[]$1[]_libs="-framework Cocoa"
],
[have_dep="no"])
LIBS="$LIBS_save"
AC_LANG_POP([Objective C])
if test "x${have_dep}" = "xyes" ; then
PKG_CHECK_MODULES([GL_EET], [eet >= 1.4.0], [have_dep="yes"], [have_dep="no"])
fi
AC_SUBST([evas_engine_$1_cflags])
AC_SUBST([evas_engine_$1_libs])
if test "x${have_dep}" = "xyes" ; then
m4_default([$4], [:])
else
m4_default([$5], [:])
fi
])
dnl use: EVAS_CHECK_ENGINE_DEP_SOFTWARE_SDL(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
AC_DEFUN([EVAS_CHECK_ENGINE_DEP_SOFTWARE_SDL],

View File

@ -27,6 +27,9 @@ endif
if !EVAS_STATIC_BUILD_GL_SDL
SUBDIRS += gl_sdl
endif
if !EVAS_STATIC_BUILD_GL_COCOA
SUBDIRS += gl_cocoa
endif
if !EVAS_STATIC_BUILD_SOFTWARE_8
SUBDIRS += software_8

View File

@ -0,0 +1,20 @@
#ifndef __EVAS_ENGINE_GL_COCOA_H__
#define __EVAS_ENGINE_GL_COCOA_H__
typedef struct _Evas_Engine_Info_GL_Cocoa Evas_Engine_Info_GL_Cocoa;
struct _Evas_Engine_Info_GL_Cocoa
{
/* PRIVATE - don't mess with this baby or evas will poke its tongue out */
/* at you and make nasty noises */
Evas_Engine_Info magic;
/* engine specific data & parameters it needs to set up */
void *window;
void *view;
int depth;
};
#endif /* __EVAS_ENGINE_GL_COCOA_H__ */

View File

@ -0,0 +1,46 @@
MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/lib/include \
-I$(top_srcdir)/src/modules/engines/gl_common \
@EINA_CFLAGS@ \
@GL_EET_CFLAGS@ \
@FREETYPE_CFLAGS@ \
@evas_engine_gl_cocoa_cflags@
if BUILD_ENGINE_GL_COCOA
GL_COCOA_SOURCES = evas_engine.c\
evas_gl_cocoa_main.m
GL_COCOA_LIBADD = @evas_engine_gl_cocoa_libs@ $(top_builddir)/src/modules/engines/gl_common/libevas_engine_gl_common.la
include_HEADERS = Evas_Engine_GL_Cocoa.h
includesdir = $(includedir)/evas-@VMAJ@
if !EVAS_STATIC_BUILD_GL_COCOA
pkgdir = $(libdir)/evas/modules/engines/gl_cocoa/$(MODULE_ARCH)
pkg_LTLIBRARIES = module.la
module_la_SOURCES = $(GL_COCOA_SOURCES)
module_la_LIBADD = @EINA_LIBS@ @GL_EET_LIBS@ $(GL_COCOA_LIBADD) $(top_builddir)/src/lib/libevas.la @dlopen_libs@
module_la_LDFLAGS = -module -avoid-version
module_la_LIBTOOLFLAGS = --tag=disable-static
else
noinst_LTLIBRARIES = libevas_engine_gl_cocoa.la
libevas_engine_gl_cocoa_la_SOURCES = $(GL_COCOA_SOURCES)
libevas_engine_gl_cocoa_la_LIBADD = $(GL_COCOA_LIBADD)
endif
endif
EXTRA_DIST = evas_engine.h

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
#ifndef __EVAS_ENGINE_H__
#define __EVAS_ENGINE_H__
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <OpenGL/gl.h>
#include "evas_gl_common.h"
#include "Evas_Engine_GL_Cocoa.h"
extern int _evas_engine_gl_cocoa_log_dom;
#ifdef ERR
# undef ERR
#endif
#define ERR(...) EINA_LOG_DOM_ERR(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
#ifdef DBG
# undef DBG
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
#ifdef INF
# undef INF
#endif
#define INF(...) EINA_LOG_DOM_INFO(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
#ifdef WRN
# undef WRN
#endif
#define WRN(...) EINA_LOG_DOM_WARN(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
#ifdef CRIT
# undef CRIT
#endif
#define CRIT(...) EINA_LOG_DOM_CRIT(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
typedef struct _Evas_GL_Cocoa_Window Evas_GL_Cocoa_Window;
struct _Evas_GL_Cocoa_Window
{
void* window;
void* view;
int width;
int height;
int depth;
Evas_Engine_GL_Context *gl_context;
struct {
int x1;
int y1;
int x2;
int y2;
int redraw : 1;
int drew : 1;
} draw;
};
Evas_GL_Cocoa_Window *eng_window_new(void *window,
int width,
int height);
void eng_window_free(Evas_GL_Cocoa_Window *gw);
void eng_window_use(Evas_GL_Cocoa_Window *gw);
void eng_window_swap_buffers(Evas_GL_Cocoa_Window *gw);
void eng_window_vsync_set(int on);
void ng_window_resize(Evas_GL_Cocoa_Window *gw, int width, int height);
#endif /* __EVAS_ENGINE_H__ */

View File

@ -0,0 +1,134 @@
#include <Cocoa/Cocoa.h>
#include "evas_engine.h"
static Evas_GL_Cocoa_Window *_evas_gl_cocoa_window = NULL;
@interface EvasGLView : NSOpenGLView
{
}
+ (NSOpenGLPixelFormat*) basicPixelFormat;
- (id) initWithFrame: (NSRect) frameRect;
@end
@implementation EvasGLView
- (id) init
{
self = [super init];
return self;
}
+ (NSOpenGLPixelFormat*) basicPixelFormat
{
NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
/*NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,*/
0
};
return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
}
// ---------------------------------
-(id) initWithFrame: (NSRect) frameRect
{
NSOpenGLPixelFormat * pf = [EvasGLView basicPixelFormat];
self = [super initWithFrame: frameRect pixelFormat: pf];
return self;
}
@end
Evas_GL_Cocoa_Window *
eng_window_new(void *window,
int w,
int h)
{
Evas_GL_Cocoa_Window *gw;
int context_attrs[3];
int config_attrs[20];
int major_version, minor_version;
int num_config;
gw = calloc(1, sizeof(Evas_GL_Cocoa_Window));
if (!gw) return NULL;
_evas_gl_cocoa_window = gw;
gw->window = window;
gw->view = [[EvasGLView alloc] initWithFrame:NSMakeRect(0,0,w,h)];
NSOpenGLContext *ctx = [(NSOpenGLView*)gw->view openGLContext];
[ctx makeCurrentContext];
gw->gl_context = evas_gl_common_context_new();
if (!gw->gl_context)
{
free(gw);
return NULL;
}
evas_gl_common_context_use(gw->gl_context);
evas_gl_common_context_resize(gw->gl_context, w, h, 0);
return gw;
}
void
eng_window_free(Evas_GL_Cocoa_Window *gw)
{
if (gw == _evas_gl_cocoa_window) _evas_gl_cocoa_window = NULL;
evas_gl_common_context_free(gw->gl_context);
free(gw);
}
void
eng_window_use(Evas_GL_Cocoa_Window *gw)
{
if (_evas_gl_cocoa_window != gw)
{
[[(NSOpenGLView*)gw->view openGLContext] makeCurrentContext];
if (_evas_gl_cocoa_window)
evas_gl_common_context_flush(_evas_gl_cocoa_window->gl_context);
_evas_gl_cocoa_window = gw;
}
evas_gl_common_context_use(gw->gl_context);
}
void
eng_window_swap_buffers(Evas_GL_Cocoa_Window *gw)
{
[[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
}
void
eng_window_vsync_set(int on)
{
}
void
eng_window_resize(Evas_GL_Cocoa_Window *gw, int width, int height)
{
NSRect view_frame;
INF("Resize %d %d\n", width, height);
view_frame = [(EvasGLView*)gw->view frame];
printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
view_frame.size.height = height;
view_frame.size.width = width;
printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
[(EvasGLView*)gw->view setFrame:view_frame];
[[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
}