Browse Source

Some NativeWindow refactoring

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
1afdcd6523

+ 4 - 4
AnKi/Core/App.cpp

@@ -295,7 +295,7 @@ void App::cleanup()
 	m_gr = nullptr;
 	m_gr = nullptr;
 	Input::deleteInstance(m_input);
 	Input::deleteInstance(m_input);
 	m_input = nullptr;
 	m_input = nullptr;
-	m_heapAlloc.deleteInstance(m_window);
+	NativeWindow::deleteInstance(m_window);
 	m_window = nullptr;
 	m_window = nullptr;
 
 
 #if ANKI_ENABLE_TRACE
 #if ANKI_ENABLE_TRACE
@@ -389,14 +389,14 @@ Error App::initInternal(const ConfigSet& config_, AllocAlignedCallback allocCb,
 	// Window
 	// Window
 	//
 	//
 	NativeWindowInitInfo nwinit;
 	NativeWindowInitInfo nwinit;
+	nwinit.m_allocCallback = m_allocCb;
+	nwinit.m_allocCallbackUserData = m_allocCbData;
 	nwinit.m_width = config.getNumberU32("width");
 	nwinit.m_width = config.getNumberU32("width");
 	nwinit.m_height = config.getNumberU32("height");
 	nwinit.m_height = config.getNumberU32("height");
 	nwinit.m_depthBits = 0;
 	nwinit.m_depthBits = 0;
 	nwinit.m_stencilBits = 0;
 	nwinit.m_stencilBits = 0;
 	nwinit.m_fullscreenDesktopRez = config.getBool("window_fullscreen");
 	nwinit.m_fullscreenDesktopRez = config.getBool("window_fullscreen");
-	m_window = m_heapAlloc.newInstance<NativeWindow>();
-
-	ANKI_CHECK(m_window->init(nwinit, m_heapAlloc));
+	ANKI_CHECK(NativeWindow::newInstance(nwinit, m_window));
 
 
 	//
 	//
 	// Input
 	// Input

+ 11 - 28
AnKi/Core/NativeWindow.h

@@ -14,13 +14,13 @@
 namespace anki
 namespace anki
 {
 {
 
 
-class NativeWindowImpl;
-using Context = void*;
-
 /// Window initializer
 /// Window initializer
 class NativeWindowInitInfo
 class NativeWindowInitInfo
 {
 {
 public:
 public:
+	AllocAlignedCallback m_allocCallback = nullptr;
+	void* m_allocCallbackUserData = nullptr;
+
 	U32 m_width = 1920;
 	U32 m_width = 1920;
 	U32 m_height = 1080;
 	U32 m_height = 1080;
 	Array<U32, 4> m_rgbaBits = {8, 8, 8, 0};
 	Array<U32, 4> m_rgbaBits = {8, 8, 8, 0};
@@ -38,21 +38,15 @@ public:
 class NativeWindow
 class NativeWindow
 {
 {
 public:
 public:
-	NativeWindow()
-	{
-	}
+	static ANKI_USE_RESULT Error newInstance(const NativeWindowInitInfo& initInfo, NativeWindow*& nativeWindow);
 
 
-	~NativeWindow()
-	{
-		destroy();
-	}
-
-	ANKI_USE_RESULT Error init(NativeWindowInitInfo& initializer, HeapAllocator<U8>& alloc);
+	static void deleteInstance(NativeWindow* nativeWindow);
 
 
 	U32 getWidth() const
 	U32 getWidth() const
 	{
 	{
 		return m_width;
 		return m_width;
 	}
 	}
+
 	U32 getHeight() const
 	U32 getHeight() const
 	{
 	{
 		return m_height;
 		return m_height;
@@ -65,30 +59,19 @@ public:
 
 
 	void setWindowTitle(CString title);
 	void setWindowTitle(CString title);
 
 
-	ANKI_INTERNAL HeapAllocator<U8> getAllocator() const
-	{
-		return m_alloc;
-	}
-
-	ANKI_INTERNAL NativeWindowImpl& getNative()
-	{
-		ANKI_ASSERT(isCreated());
-		return *m_impl;
-	}
-
-private:
+protected:
 	U32 m_width = 0;
 	U32 m_width = 0;
 	U32 m_height = 0;
 	U32 m_height = 0;
 
 
-	NativeWindowImpl* m_impl = nullptr;
 	HeapAllocator<U8> m_alloc;
 	HeapAllocator<U8> m_alloc;
 
 
-	Bool isCreated() const
+	NativeWindow()
 	{
 	{
-		return m_impl != nullptr;
 	}
 	}
 
 
-	void destroy();
+	~NativeWindow()
+	{
+	}
 };
 };
 
 
 } // end namespace anki
 } // end namespace anki

+ 51 - 22
AnKi/Core/NativeWindowAndroid.cpp

@@ -8,22 +8,51 @@
 namespace anki
 namespace anki
 {
 {
 
 
-Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
+Error NativeWindow::newInstance(const NativeWindowInitInfo& initInfo, NativeWindow*& nativeWindow)
 {
 {
-	ANKI_CORE_LOGI("Initializing Android window");
+	HeapAllocator<U8> alloc(initInfo.m_allocCallback, initInfo.m_allocCallbackUserData);
+	NativeWindowAndroid* sdlwin = alloc.newInstance<NativeWindowAndroid>();
 
 
-	m_alloc = alloc;
-	m_impl = m_alloc.newInstance<NativeWindowImpl>();
+	sdlwin->m_alloc = alloc;
 
 
-	// Loop until the window is ready
-	while(g_androidApp->window == nullptr)
+	const Error err = sdlwin->init(initInfo);
+	if(err)
+	{
+		alloc.deleteInstance(sdlwin);
+		nativeWindow = nullptr;
+		return err;
+	}
+	else
+	{
+		nativeWindow = sdlwin;
+		return Error::NONE;
+	}
+}
+
+void NativeWindow::deleteInstance(NativeWindow* window)
+{
+	if(window)
+	{
+		NativeWindowAndroid* self = static_cast<NativeWindowAndroid*>(window);
+		HeapAllocator<U8> alloc = self->m_alloc;
+		self->~NativeWindowAndroid();
+		alloc.getMemoryPool().free(self);
+	}
+}
+
+NativeWindowAndroid::~NativeWindowAndroid()
+{
+	ANKI_CORE_LOGI("Destroying Android window");
+	ANativeActivity_finish(g_androidApp->activity);
+
+	// Loop until destroyRequested is set
+	while(!g_androidApp->destroyRequested)
 	{
 	{
 		int ident;
 		int ident;
 		int events;
 		int events;
 		android_poll_source* source;
 		android_poll_source* source;
 
 
-		const int timeoutMs = 5;
-		while((ident = ALooper_pollAll(timeoutMs, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
+		while((ident = ALooper_pollAll(0, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
 		{
 		{
 			if(source != nullptr)
 			if(source != nullptr)
 			{
 			{
@@ -32,28 +61,22 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 		}
 		}
 	}
 	}
 
 
-	m_impl->m_nativeWindow = g_androidApp->window;
-
-	// Set some stuff
-	m_width = ANativeWindow_getWidth(g_androidApp->window);
-	m_height = ANativeWindow_getHeight(g_androidApp->window);
-
-	return Error::NONE;
+	m_nativeWindow = nullptr;
 }
 }
 
 
-void NativeWindow::destroy()
+Error NativeWindowAndroid::init(const NativeWindowInitInfo& init)
 {
 {
-	ANKI_CORE_LOGI("Destroying Android window");
-	ANativeActivity_finish(g_androidApp->activity);
+	ANKI_CORE_LOGI("Initializing Android window");
 
 
-	// Loop until destroyRequested is set
-	while(!g_androidApp->destroyRequested)
+	// Loop until the window is ready
+	while(g_androidApp->window == nullptr)
 	{
 	{
 		int ident;
 		int ident;
 		int events;
 		int events;
 		android_poll_source* source;
 		android_poll_source* source;
 
 
-		while((ident = ALooper_pollAll(0, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
+		const int timeoutMs = 5;
+		while((ident = ALooper_pollAll(timeoutMs, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
 		{
 		{
 			if(source != nullptr)
 			if(source != nullptr)
 			{
 			{
@@ -62,7 +85,13 @@ void NativeWindow::destroy()
 		}
 		}
 	}
 	}
 
 
-	m_alloc.deleteInstance(m_impl);
+	m_nativeWindow = g_androidApp->window;
+
+	// Set some stuff
+	m_width = ANativeWindow_getWidth(g_androidApp->window);
+	m_height = ANativeWindow_getHeight(g_androidApp->window);
+
+	return Error::NONE;
 }
 }
 
 
 void NativeWindow::setWindowTitle(CString title)
 void NativeWindow::setWindowTitle(CString title)

+ 5 - 3
AnKi/Core/NativeWindowAndroid.h

@@ -6,18 +6,20 @@
 #pragma once
 #pragma once
 
 
 #include <AnKi/Core/NativeWindow.h>
 #include <AnKi/Core/NativeWindow.h>
-#include <EGL/egl.h>
-#include <GLES3/gl3.h>
 #include <android_native_app_glue.h>
 #include <android_native_app_glue.h>
 
 
 namespace anki
 namespace anki
 {
 {
 
 
 /// Native window implementation for Android
 /// Native window implementation for Android
-class NativeWindowImpl
+class NativeWindowAndroid : public NativeWindow
 {
 {
 public:
 public:
 	ANativeWindow* m_nativeWindow = nullptr;
 	ANativeWindow* m_nativeWindow = nullptr;
+
+	~NativeWindowAndroid();
+
+	ANKI_USE_RESULT Error init(const NativeWindowInitInfo& init);
 };
 };
 
 
 } // end namespace anki
 } // end namespace anki

+ 0 - 27
AnKi/Core/NativeWindowDummy.cpp

@@ -1,27 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <AnKi/Core/NativeWindow.h>
-
-namespace anki
-{
-
-NativeWindow::~NativeWindow
-{
-}
-
-void NativeWindow::create(NativeWindowInitInfo&)
-{
-}
-
-void NativeWindow::destroy()
-{
-}
-
-void NativeWindow::swapBuffers()
-{
-}
-
-} // end namespace anki

+ 0 - 212
AnKi/Core/NativeWindowEglFbdev.cpp

@@ -1,212 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <AnKi/Core/NativeWindowEglFbdev.h>
-#include <AnKi/Util/Vector.h>
-#include <AnKi/Util/Array.h>
-#include <AnKi/Util/StdTypes.h>
-
-namespace anki
-{
-
-void NativeWindowImpl::create(NativeWindowInitInfo& init)
-{
-	// Create window
-	//
-	fbwin = (fbdev_window*)malloc(sizeof(fbdev_window));
-	if(fbwin == NULL)
-	{
-		throw ANKI_EXCEPTION("malloc() failed");
-	}
-
-	fbwin->width = init.width;
-	fbwin->height = init.height;
-
-	// EGL init
-	//
-	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-	if(display == EGL_NO_DISPLAY)
-	{
-		throw ANKI_EXCEPTION("Failed to create display");
-	}
-
-	int major, minor;
-	if(eglInitialize(display, &major, &minor) == EGL_FALSE)
-	{
-		throw ANKI_EXCEPTION("Failed to initialize EGL");
-	}
-
-	int maxConfigs;
-	if(eglGetConfigs(display, NULL, 0, &maxConfigs) == EGL_FALSE)
-	{
-		throw ANKI_EXCEPTION("Failed to query EGL configs");
-	}
-
-	if(maxConfigs < 1)
-	{
-		throw ANKI_EXCEPTION("Error in number of configs");
-	}
-
-	Vector<EGLConfig> configs(maxConfigs);
-
-	Array<EGLint, 256> attribs;
-	U attr = 0;
-	attribs[attr++] = EGL_RENDERABLE_TYPE;
-	attribs[attr++] = EGL_OPENGL_ES2_BIT;
-
-	if(init.samplesCount > 1)
-	{
-		attribs[attr++] = EGL_SAMPLES;
-		attribs[attr++] = init.samplesCount;
-	}
-
-	attribs[attr++] = EGL_RED_SIZE;
-	attribs[attr++] = init.rgbaBits[0];
-	attribs[attr++] = EGL_GREEN_SIZE;
-	attribs[attr++] = init.rgbaBits[1];
-	attribs[attr++] = EGL_BLUE_SIZE;
-	attribs[attr++] = init.rgbaBits[2];
-	attribs[attr++] = EGL_ALPHA_SIZE;
-	attribs[attr++] = init.rgbaBits[3];
-
-	attribs[attr++] = EGL_DEPTH_SIZE;
-	attribs[attr++] = init.depthBits;
-	attribs[attr++] = EGL_STENCIL_SIZE;
-	attribs[attr++] = init.stencilBits;
-
-	attribs[attr++] = EGL_NONE;
-
-	EGLint configsCount;
-	if(eglChooseConfig(display, &attribs[0], &configs[0], maxConfigs, &configsCount) == EGL_FALSE)
-	{
-		throw ANKI_EXCEPTION("Failed to query required EGL configs");
-	}
-
-	if(configsCount == 0)
-	{
-		throw ANKI_EXCEPTION("No matching EGL configs found");
-	}
-
-	EGLConfig config_ = nullptr;
-	for(EGLint i = 0; i < configsCount; i++)
-	{
-		EGLint value;
-		EGLConfig config = configs[i];
-
-		// Use this to explicitly check that the EGL config has the
-		// expected color depths
-		eglGetConfigAttrib(display, config, EGL_RED_SIZE, &value);
-		if(value != (EGLint)init.rgbaBits[0])
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &value);
-		if(value != (EGLint)init.rgbaBits[1])
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &value);
-		if(value != (EGLint)init.rgbaBits[2])
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &value);
-		if(value != (EGLint)init.rgbaBits[3])
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_SAMPLES, &value);
-		if(value != (EGLint)init.samplesCount)
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &value);
-		if(value != (EGLint)init.depthBits)
-		{
-			continue;
-		}
-
-		eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &value);
-		if(value != (EGLint)init.stencilBits)
-		{
-			continue;
-		}
-
-		// We found what we wanted
-		config_ = config;
-		break;
-	}
-
-	if(config_ == nullptr)
-	{
-		throw ANKI_EXCEPTION("Unable to find suitable EGL config");
-	}
-
-	// Surface
-	//
-	surface = eglCreateWindowSurface(display, config_, static_cast<EGLNativeWindowType>(fbwin), NULL);
-
-	if(surface == EGL_NO_SURFACE)
-	{
-		throw ANKI_EXCEPTION("Cannot create surface");
-	}
-
-	// Context
-	//
-	EGLint ctxAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
-
-	context = eglCreateContext(display, config_, EGL_NO_CONTEXT, ctxAttribs);
-
-	if(context == EGL_NO_CONTEXT)
-	{
-		throw ANKI_EXCEPTION("Cannot create context");
-	}
-
-	if(eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
-	{
-		throw ANKI_EXCEPTION("Cannot make the context current");
-	}
-}
-
-void NativeWindowImpl::destroy()
-{
-	// XXX
-}
-
-NativeWindow::~NativeWindow()
-{
-}
-
-void NativeWindow::init(NativeWindowInitInfo& initializer)
-{
-	impl.reset(new NativeWindowImpl);
-	impl->create(initializer);
-
-	// Set the size after because the create may have changed it to something
-	// more nice
-	width = initializer.width;
-	height = initializer.height;
-}
-
-void NativeWindow::destroy()
-{
-	impl.reset();
-}
-
-void NativeWindow::swapBuffers()
-{
-	ANKI_ASSERT(isCreated());
-	if(eglSwapBuffers(impl->display, impl->surface) == EGL_FALSE)
-	{
-		throw ANKI_EXCEPTION("eglSwapBuffers() failed");
-	}
-}
-
-} // end namespace anki

+ 0 - 33
AnKi/Core/NativeWindowEglFbdev.h

@@ -1,33 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <AnKi/Core/NativeWindow.h>
-#define EGL_FBDEV 1
-#include <EGL/egl.h>
-#include <GLES3/gl3.h>
-
-namespace anki
-{
-
-/// Native window implementation for EGL & FBDEV
-struct NativeWindowImpl
-{
-	EGLDisplay display = EGL_NO_DISPLAY;
-	EGLSurface surface = EGL_NO_SURFACE;
-	EGLContext context = EGL_NO_CONTEXT;
-	EGLNativeWindowType fbwin = 0;
-
-	~NativeWindowImpl()
-	{
-		destroy();
-	}
-
-	void create(NativeWindowInitInfo& init);
-	void destroy();
-};
-
-} // end namespace anki

+ 54 - 31
AnKi/Core/NativeWindowSdl.cpp

@@ -12,13 +12,57 @@
 namespace anki
 namespace anki
 {
 {
 
 
-const U32 INIT_SUBSYSTEMS = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
+Error NativeWindow::newInstance(const NativeWindowInitInfo& initInfo, NativeWindow*& nativeWindow)
+{
+	HeapAllocator<U8> alloc(initInfo.m_allocCallback, initInfo.m_allocCallbackUserData);
+	NativeWindowSdl* sdlwin = alloc.newInstance<NativeWindowSdl>();
+
+	sdlwin->m_alloc = alloc;
+
+	const Error err = sdlwin->init(initInfo);
+	if(err)
+	{
+		alloc.deleteInstance(sdlwin);
+		nativeWindow = nullptr;
+		return err;
+	}
+	else
+	{
+		nativeWindow = sdlwin;
+		return Error::NONE;
+	}
+}
+
+void NativeWindow::deleteInstance(NativeWindow* window)
+{
+	if(window)
+	{
+		NativeWindowSdl* self = static_cast<NativeWindowSdl*>(window);
+		HeapAllocator<U8> alloc = self->m_alloc;
+		self->~NativeWindowSdl();
+		alloc.getMemoryPool().free(self);
+	}
+}
+
+void NativeWindow::setWindowTitle(CString title)
+{
+	NativeWindowSdl* self = static_cast<NativeWindowSdl*>(this);
+	SDL_SetWindowTitle(self->m_window, title.cstr());
+}
 
 
-Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
+NativeWindowSdl::~NativeWindowSdl()
 {
 {
-	m_alloc = alloc;
-	m_impl = m_alloc.newInstance<NativeWindowImpl>();
+	if(m_window)
+	{
+		SDL_DestroyWindow(m_window);
+	}
 
 
+	SDL_QuitSubSystem(INIT_SUBSYSTEMS);
+	SDL_Quit();
+}
+
+Error NativeWindowSdl::init(const NativeWindowInitInfo& init)
+{
 	if(SDL_Init(INIT_SUBSYSTEMS) != 0)
 	if(SDL_Init(INIT_SUBSYSTEMS) != 0)
 	{
 	{
 		ANKI_CORE_LOGE("SDL_Init() failed: %s", SDL_GetError());
 		ANKI_CORE_LOGE("SDL_Init() failed: %s", SDL_GetError());
@@ -74,14 +118,14 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 			return Error::FUNCTION_FAILED;
 			return Error::FUNCTION_FAILED;
 		}
 		}
 
 
-		init.m_width = mode.w;
-		init.m_height = mode.h;
+		m_width = mode.w;
+		m_height = mode.h;
 	}
 	}
 
 
-	m_impl->m_window = SDL_CreateWindow(&init.m_title[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
-										init.m_width, init.m_height, flags);
+	m_window =
+		SDL_CreateWindow(&init.m_title[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, m_width, m_height, flags);
 
 
-	if(m_impl->m_window == nullptr)
+	if(m_window == nullptr)
 	{
 	{
 		ANKI_CORE_LOGE("SDL_CreateWindow() failed");
 		ANKI_CORE_LOGE("SDL_CreateWindow() failed");
 		return Error::FUNCTION_FAILED;
 		return Error::FUNCTION_FAILED;
@@ -91,7 +135,7 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 	if(init.m_fullscreenDesktopRez)
 	if(init.m_fullscreenDesktopRez)
 	{
 	{
 		int w, h;
 		int w, h;
-		SDL_GetWindowSize(m_impl->m_window, &w, &h);
+		SDL_GetWindowSize(m_window, &w, &h);
 
 
 		m_width = w;
 		m_width = w;
 		m_height = h;
 		m_height = h;
@@ -106,25 +150,4 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 
-void NativeWindow::destroy()
-{
-	if(m_impl != nullptr)
-	{
-		if(m_impl->m_window)
-		{
-			SDL_DestroyWindow(m_impl->m_window);
-		}
-
-		SDL_QuitSubSystem(INIT_SUBSYSTEMS);
-		SDL_Quit();
-	}
-
-	m_alloc.deleteInstance(m_impl);
-}
-
-void NativeWindow::setWindowTitle(CString title)
-{
-	SDL_SetWindowTitle(m_impl->m_window, title.cstr());
-}
-
 } // end namespace anki
 } // end namespace anki

+ 9 - 1
AnKi/Core/NativeWindowSdl.h

@@ -12,10 +12,18 @@ namespace anki
 {
 {
 
 
 /// Native window implementation for SDL
 /// Native window implementation for SDL
-class NativeWindowImpl
+class NativeWindowSdl : public NativeWindow
 {
 {
 public:
 public:
 	SDL_Window* m_window = nullptr;
 	SDL_Window* m_window = nullptr;
+
+	~NativeWindowSdl();
+
+	ANKI_USE_RESULT Error init(const NativeWindowInitInfo& init);
+
+private:
+	static constexpr U32 INIT_SUBSYSTEMS =
+		SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
 };
 };
 
 
 } // end namespace anki
 } // end namespace anki

+ 1 - 2
AnKi/Gr/Vulkan/GrManagerImplAndroid.cpp

@@ -5,7 +5,6 @@
 
 
 #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
 #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
 #include <AnKi/Gr/GrManager.h>
 #include <AnKi/Gr/GrManager.h>
-#include <AnKi/Core/NativeWindow.h>
 #include <AnKi/Core/NativeWindowAndroid.h>
 #include <AnKi/Core/NativeWindowAndroid.h>
 
 
 namespace anki
 namespace anki
@@ -15,7 +14,7 @@ Error GrManagerImpl::initSurface(const GrManagerInitInfo& init)
 {
 {
 	VkAndroidSurfaceCreateInfoKHR createInfo = {};
 	VkAndroidSurfaceCreateInfoKHR createInfo = {};
 	createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
 	createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
-	createInfo.window = init.m_window->getNative().m_nativeWindow;
+	createInfo.window = static_cast<NativeWindowAndroid*>(init.m_window)->m_nativeWindow;
 
 
 	ANKI_VK_CHECK(vkCreateAndroidSurfaceKHR(m_instance, &createInfo, nullptr, &m_surface));
 	ANKI_VK_CHECK(vkCreateAndroidSurfaceKHR(m_instance, &createInfo, nullptr, &m_surface));
 
 

+ 1 - 1
AnKi/Gr/Vulkan/GrManagerImplSdl.cpp

@@ -20,7 +20,7 @@ namespace anki
 
 
 Error GrManagerImpl::initSurface(const GrManagerInitInfo& init)
 Error GrManagerImpl::initSurface(const GrManagerInitInfo& init)
 {
 {
-	if(!SDL_Vulkan_CreateSurface(init.m_window->getNative().m_window, m_instance, &m_surface))
+	if(!SDL_Vulkan_CreateSurface(static_cast<NativeWindowSdl*>(init.m_window)->m_window, m_instance, &m_surface))
 	{
 	{
 		ANKI_VK_LOGE("SDL_Vulkan_CreateSurface() failed: %s", SDL_GetError());
 		ANKI_VK_LOGE("SDL_Vulkan_CreateSurface() failed: %s", SDL_GetError());
 		return Error::FUNCTION_FAILED;
 		return Error::FUNCTION_FAILED;

+ 1 - 1
AnKi/Input/InputSdl.cpp

@@ -83,7 +83,7 @@ void Input::moveCursor(const Vec2& pos)
 		const I32 x = I32(F32(m_nativeWindow->getWidth()) * (pos.x() * 0.5f + 0.5f));
 		const I32 x = I32(F32(m_nativeWindow->getWidth()) * (pos.x() * 0.5f + 0.5f));
 		const I32 y = I32(F32(m_nativeWindow->getHeight()) * (-pos.y() * 0.5f + 0.5f));
 		const I32 y = I32(F32(m_nativeWindow->getHeight()) * (-pos.y() * 0.5f + 0.5f));
 
 
-		SDL_WarpMouseInWindow(m_nativeWindow->getNative().m_window, x, y);
+		SDL_WarpMouseInWindow(static_cast<NativeWindowSdl*>(m_nativeWindow)->m_window, x, y);
 
 
 		// SDL doesn't generate a SDL_MOUSEMOTION event if the cursor is outside the window. Push that event
 		// SDL doesn't generate a SDL_MOUSEMOTION event if the cursor is outside the window. Push that event
 		SDL_Event event;
 		SDL_Event event;

+ 7 - 5
Tests/Framework/Framework.cpp

@@ -236,15 +236,17 @@ void initConfig(ConfigSet& cfg)
 
 
 NativeWindow* createWindow(ConfigSet& cfg)
 NativeWindow* createWindow(ConfigSet& cfg)
 {
 {
-	HeapAllocator<U8> alloc(allocAligned, nullptr);
-
 	NativeWindowInitInfo inf;
 	NativeWindowInitInfo inf;
+	inf.m_allocCallback = allocAligned;
 	inf.m_width = cfg.getNumberU32("width");
 	inf.m_width = cfg.getNumberU32("width");
 	inf.m_height = cfg.getNumberU32("height");
 	inf.m_height = cfg.getNumberU32("height");
 	inf.m_title = "AnKi unit tests";
 	inf.m_title = "AnKi unit tests";
-	NativeWindow* win = new NativeWindow();
-
-	ANKI_TEST_EXPECT_NO_ERR(win->init(inf, alloc));
+	NativeWindow* win;
+	const Error err = NativeWindow::newInstance(inf, win);
+	if(err)
+	{
+		return nullptr;
+	}
 
 
 	cfg.set("width", win->getWidth());
 	cfg.set("width", win->getWidth());
 	cfg.set("height", win->getHeight());
 	cfg.set("height", win->getHeight());

+ 1 - 1
Tests/Gr/Gr.cpp

@@ -281,7 +281,7 @@ static Input* input = nullptr;
 	delete stagingMem; \
 	delete stagingMem; \
 	GrManager::deleteInstance(gr); \
 	GrManager::deleteInstance(gr); \
 	Input::deleteInstance(input); \
 	Input::deleteInstance(input); \
-	delete win; \
+	NativeWindow::deleteInstance(win); \
 	win = nullptr; \
 	win = nullptr; \
 	gr = nullptr; \
 	gr = nullptr; \
 	stagingMem = nullptr;
 	stagingMem = nullptr;

+ 1 - 1
Tests/Ui/Ui.cpp

@@ -153,7 +153,7 @@ ANKI_TEST(Ui, Ui)
 	delete fs;
 	delete fs;
 	GrManager::deleteInstance(gr);
 	GrManager::deleteInstance(gr);
 	Input::deleteInstance(in);
 	Input::deleteInstance(in);
-	delete win;
+	NativeWindow::deleteInstance(win);
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki