Selaa lähdekoodia

AndroidRenderWindow implemented, needs test

mikymod 13 vuotta sitten
vanhempi
sitoutus
4e51c85ca6

+ 1 - 2
android/AndroidManifest.xml

@@ -4,8 +4,7 @@
       android:versionCode="1"
       android:versionCode="1"
       android:versionName="1.0">
       android:versionName="1.0">
     <uses-sdk
     <uses-sdk
-        android:minSdkVersion="10"
-        android:targetSdkVersion="15" />
+        android:minSdkVersion="9"/>
 
 
     <application android:label="@string/app_name" >
     <application android:label="@string/app_name" >
         <activity android:name="CrownActivity"
         <activity android:name="CrownActivity"

+ 1 - 3
android/jni/Android.mk

@@ -45,7 +45,6 @@ LOCAL_SRC_FILES :=\
 	os/OS.cpp\
 	os/OS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidRenderWindow.cpp\
 	os/android/AndroidRenderWindow.cpp\
-	os/android/AndroidTimer.cpp\
 \
 \
 	Filesystem.cpp\
 	Filesystem.cpp\
 \
 \
@@ -107,7 +106,6 @@ LOCAL_CPPFLAGS	:= -g -fexceptions
 LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM
 LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM
 LOCAL_STATIC_LIBRARIES := android_native_app_glue
 LOCAL_STATIC_LIBRARIES := android_native_app_glue
 include $(BUILD_STATIC_LIBRARY)
 include $(BUILD_STATIC_LIBRARY)
-
 include $(CLEAR_VARS)
 include $(CLEAR_VARS)
 
 
 #LOCAL_MODULE    := simple
 #LOCAL_MODULE    := simple
@@ -153,5 +151,5 @@ include $(CLEAR_VARS)
 #LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM -lz
 #LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM -lz
 #LOCAL_STATIC_LIBRARIES := android_native_app_glue
 #LOCAL_STATIC_LIBRARIES := android_native_app_glue
 #include $(BUILD_SHARED_LIBRARY)
 #include $(BUILD_SHARED_LIBRARY)
-#$(call import-module,android/native_app_glue)
+$(call import-module,android/native_app_glue)
 
 

+ 24 - 21
src/os/android/AndroidOS.cpp

@@ -28,82 +28,84 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
-#define LOGI(...) ((void)__android_log_print32_t(ANDROID_LOG_INFO, "crown", __VA_ARGS__))
-#define LOGW(...) ((void)__android_log_print32_t(ANDROID_LOG_WARN, "crown", __VA_ARGS__))
-#define LOGD(...) ((void)__android_log_print32_t(ANDROID_LOG_DEBUG, "crown", __VA_ARGS__))
-#define LOGE(...) ((void)__android_log_print32_t(ANDROID_LOG_ERROR, "crown", __VA_ARGS__))
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "crown", __VA_ARGS__))
+#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "crown", __VA_ARGS__))
+#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "crown", __VA_ARGS__))
+#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "crown", __VA_ARGS__))
 
 
 namespace crown
 namespace crown
 {
 {
+namespace os
+{
 
 
-void OS::Print32_tf(const char* string, ...)
+void printf(const char* string, ...)
 {
 {
 	LOGI(string);
 	LOGI(string);
 }
 }
 
 
-void OS::LogDebug(const char* string, ...)
+void log_debug(const char* string, ...)
 {
 {
 	LOGD(string);
 	LOGD(string);
 }
 }
 
 
-void OS::LogError(const char* string, ...)
+void log_error(const char* string, ...)
 {
 {
 	LOGE(string);
 	LOGE(string);
 }
 }
 
 
-void OS::LogWarning(const char* string, ...)
+void log_warning(const char* string, ...)
 {
 {
 	LOGW(string);
 	LOGW(string);
 }
 }
 
 
-void OS::LogInfo(const char* string, ...)
+void log_info(const char* string, ...)
 {
 {
 	LOGI(string);
 	LOGI(string);
 }
 }
 
 
-bool OS::Exists(const Str& path)
+bool exists(const Str& path)
 {
 {
 	struct stat dummy;
 	struct stat dummy;
 	return (stat(path.c_str(), &dummy) == 0);
 	return (stat(path.c_str(), &dummy) == 0);
 }
 }
 
 
-bool OS::IsDir(const Str& path)
+bool is_dir(const Str& path)
 {
 {
 	struct stat info;
 	struct stat info;
 	stat(path.c_str(), &info);
 	stat(path.c_str(), &info);
 	return (S_ISDIR(info.st_mode)) != 0;
 	return (S_ISDIR(info.st_mode)) != 0;
 }
 }
 
 
-bool OS::IsReg(const Str& path)
+bool is_reg(const Str& path)
 {
 {
 	struct stat info;
 	struct stat info;
 	stat(path.c_str(), &info);
 	stat(path.c_str(), &info);
 	return (S_ISREG(info.st_mode)) != 0;
 	return (S_ISREG(info.st_mode)) != 0;
 }
 }
 
 
-bool OS::Mknod(const Str& path)
+bool mknod(const Str& path)
 {
 {
 	// Permission mask: rw-r--r--
 	// Permission mask: rw-r--r--
-	return mknod(path.c_str(), S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 0) == 0;
+	return ::mknod(path.c_str(), S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 0) == 0;
 }
 }
 
 
-bool OS::Unlink(const Str& path)
+bool unlink(const Str& path)
 {
 {
-	return (unlink(path.c_str()) == 0);
+	return (::unlink(path.c_str()) == 0);
 }
 }
 
 
-bool OS::Mkdir(const Str& path)
+bool mkdir(const Str& path)
 {
 {
 	// rwxr-xr-x permission mask
 	// rwxr-xr-x permission mask
-	return (mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0);
+	return (::mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0);
 }
 }
 
 
-bool OS::Rmdir(const Str& path)
+bool rmdir(const Str& path)
 {
 {
-	return (rmdir(path.c_str()) == 0);
+	return (::rmdir(path.c_str()) == 0);
 }
 }
 
 
-bool OS::GetCWD(Str& ret)
+bool get_cwd(Str& ret)
 {
 {
 	static char cwdBuf[1024];
 	static char cwdBuf[1024];
 	if (getcwd(cwdBuf, 1024) == NULL)
 	if (getcwd(cwdBuf, 1024) == NULL)
@@ -115,5 +117,6 @@ bool OS::GetCWD(Str& ret)
 	return true;
 	return true;
 }
 }
 
 
+} // namespace os
 } // namespace crown
 } // namespace crown
 
 

+ 49 - 133
src/os/android/AndroidRenderWindow.cpp

@@ -24,97 +24,59 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #include "Device.h"
 #include "Device.h"
-#include "GLESSupport.h"
-#include "AndroidRenderWindow.h"
 #include "Log.h"
 #include "Log.h"
 #include "Types.h"
 #include "Types.h"
 #include "Config.h"
 #include "Config.h"
+#include <EGL/egl.h>
 #include <android_native_app_glue.h>
 #include <android_native_app_glue.h>
 
 
 namespace crown
 namespace crown
 {
 {
-
-AndroidRenderWindow::AndroidRenderWindow() :
-	mEGLDisplay(EGL_NO_DISPLAY),
-	mEGLContext(EGL_NO_CONTEXT),
-	mEGLWindow(EGL_NO_SURFACE)
+namespace os
 {
 {
-	mANativeWindow = GetDevice()->_GetAndroidApp()->window;
-	mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 
 
-	eglInitialize(mEGLDisplay, NULL, NULL);
-}
+EGLDisplay display;
+EGLSurface surface;
+EGLContext context;
+android_app* application;
 
 
-AndroidRenderWindow::~AndroidRenderWindow()
+bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t depth, bool /*fullscreen*/)
 {
 {
-	if (mEGLDisplay != EGL_NO_DISPLAY)
-	{
-		Log::D("AndroidRenderWindow::Destroy: Releasing context...");
-		if (mEGLContext != EGL_NO_CONTEXT)
-		{
-			eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-			eglDestroyContext(mEGLDisplay, mEGLContext);
-		}
-		Log::D("AndroidRenderWindow::Destroy: Context released.");
-
-		if (mEGLWindow != EGL_NO_SURFACE)
-		{
-			eglDestroySurface(mEGLDisplay, mEGLWindow);
-		}
-
-		mEGLWindow = EGL_NO_SURFACE;
-		Log::D("AndroidRenderWindow::Destroy: Window Destroyed.");
-
-		eglTerminate(mEGLDisplay);
-	}
-}
-
-bool AndroidRenderWindow::Create(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t depth, bool /*fullscreen*/)
-{
-	Log::D("AndroidRenderWindow::Create: Creating window...");
-	if (!width || !height)
-	{
-		Log::E("Width and height must differ from 0.");
-		return false;
-	}
+	assert(width != 0 && height != 0);
 
 
-	if (!mEGLDisplay)
-	{
-		Log::E("Unable to open a display");
-		return false;
-	}
+	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 
 
-	uint32_t bpp			= depth / 4;
+	assert(display != EGL_NO_DISPLAY);
 
 
 	const EGLint attribs[] =
 	const EGLint attribs[] =
 	{
 	{
 		EGL_BUFFER_SIZE, 24,
 		EGL_BUFFER_SIZE, 24,
 		EGL_DEPTH_SIZE, 24,
 		EGL_DEPTH_SIZE, 24,
-		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
-		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
+		EGL_SURFACE_TYPE, 
+		EGL_WINDOW_BIT,
+		EGL_RENDERABLE_TYPE, 
+		EGL_OPENGL_ES_BIT,
 		EGL_NONE
 		EGL_NONE
 	};
 	};
+	
+	EGLint major;
+	EGLint minor;
+
+	assert(eglInitialize(display, &major, &minor));
 
 
-	EGLConfig  ecfg;
+	EGLConfig  config;
 	EGLint     num_config;
 	EGLint     num_config;
-	if (!eglChooseConfig(mEGLDisplay, attribs, &ecfg, 1, &num_config))
-	{
-		Log::E("Unable to choose config.");
-		return false;
-	}
+	assert(eglChooseConfig(display, attribs, &config, 1, &num_config));
 
 
 	EGLint format;
 	EGLint format;
-    eglGetConfigAttrib(mEGLDisplay, ecfg, EGL_NATIVE_VISUAL_ID, &format);
+    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
 
 
 	// Reconfigure ANativeWindow buffer
 	// Reconfigure ANativeWindow buffer
-    ANativeWindow_setBuffersGeometry(mANativeWindow, 0, 0, format);
+    ANativeWindow_setBuffersGeometry(application->window, 0, 0, format);
+
+	surface = eglCreateWindowSurface(display, config, application->window, NULL);
+	assert(surface != EGL_NO_SURFACE);
 
 
-	mEGLWindow = eglCreateWindowSurface(mEGLDisplay, ecfg, mANativeWindow, NULL);
-	if (mEGLWindow == EGL_NO_SURFACE)
-	{
-		Log::E("Unable to create window surface.");
-		return false;
-	}
 
 
 	EGLint ctxattr[] =
 	EGLint ctxattr[] =
 	{
 	{
@@ -122,95 +84,49 @@ bool AndroidRenderWindow::Create(uint32_t x, uint32_t y, uint32_t width, uint32_
 		EGL_NONE
 		EGL_NONE
 	};
 	};
 
 
-	mEGLContext = eglCreateContext(mEGLDisplay, ecfg, EGL_NO_CONTEXT, ctxattr);
-	if (mEGLContext == EGL_NO_CONTEXT)
-	{
-		Log::E("Unable to create context: " + Str(eglGetError()));
-		return false;
-	}
-
-	eglMakeCurrent(mEGLDisplay, mEGLWindow, mEGLWindow, mEGLContext);
-
-	EGLint w, h;
-	eglQuerySurface(mEGLDisplay, mEGLWindow, EGL_WIDTH, &w);
-	eglQuerySurface(mEGLDisplay, mEGLWindow, EGL_HEIGHT, &h);
-
-	mX = x;
-	mY = y;
-	mWidth = w;
-	mHeight = h;
-
-	mCreated = true;
+	context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctxattr);
+	assert(context != EGL_NO_CONTEXT);
 
 
-	Log::D("AndroidRenderWindow::Create: Window created.");
+	assert(eglMakeCurrent(display, surface, surface, context) != EGL_NO_CONTEXT);
 
 
 	return true;
 	return true;
 }
 }
 
 
-void AndroidRenderWindow::Destroy()
+void destroy_render_window()
 {
 {
-	if (!mCreated)
+	if (display != EGL_NO_DISPLAY)
 	{
 	{
-		return;
-	}
+		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
 
-	// Main window can not be destroyed
-	if (mMain)
-	{
-		return;
-	}
+		if (context != EGL_NO_CONTEXT)
+		{
+            eglDestroyContext(display, context);
+		}
+		
+		if (surface != EGL_NO_SURFACE)
+		{
+            eglDestroySurface(display, surface);
+		}
 
 
-	if (mFull)
-	{
-		SetFullscreen(false);
+		eglTerminate(display);
 	}
 	}
-
-	mCreated = false;
-}
-
-void AndroidRenderWindow::SetVisible(bool visible)
-{
-	mVisible = visible;
-}
-
-void AndroidRenderWindow::Move(uint32_t x, uint32_t y)
-{
-}
-
-void AndroidRenderWindow::Resize(uint32_t width, uint32_t height)
-{
-}
-
-void AndroidRenderWindow::SetFullscreen(bool full)
-{
-}
-
-void AndroidRenderWindow::Bind()
-{
-	eglMakeCurrent(mEGLDisplay, mEGLWindow, mEGLWindow, mEGLContext);
-}
-
-void AndroidRenderWindow::Unbind()
-{
-	eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-}
-
-void AndroidRenderWindow::Update()
-{
-	eglSwapBuffers(mEGLDisplay, mEGLWindow);
 }
 }
 
 
-void AndroidRenderWindow::EventLoop()
+void bind()
 {
 {
+	eglMakeCurrent(display, surface, surface, context);
 }
 }
 
 
-void AndroidRenderWindow::_NotifyMetricsChange(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
+void unbind()
 {
 {
+	eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 }
 }
 
 
-void AndroidRenderWindow::_SetTitleAndAdditionalTextToWindow()
+void swap_buffers()
 {
 {
+	eglSwapBuffers(display, surface);
 }
 }
 
 
+} // namespace os
 } // namespace crown
 } // namespace crown