From 8a0c7141084e7c782ca89bcb3e3cd4bc25f6a284 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 3 Oct 2018 16:58:39 -0700 Subject: [PATCH] Rename ExternalContext to Platform Rename everything related. Also Platform::create() returns a raw Driver* instead of a unique_ptr. This is to remove a dependency on in public headers. --- filament/CMakeLists.txt | 24 +++---- filament/include/filament/Engine.h | 20 +++--- filament/include/filament/SwapChain.h | 4 +- .../driver/{ExternalContext.h => Platform.h} | 27 ++++---- filament/src/Engine.cpp | 38 +++++------ filament/src/details/Engine.h | 8 +-- filament/src/driver/Driver.h | 2 +- filament/src/driver/DriverBase.h | 8 +-- .../{ExternalContext.cpp => Platform.cpp} | 56 ++++++++-------- filament/src/driver/opengl/OpenGLDriver.cpp | 22 +++---- filament/src/driver/opengl/OpenGLDriver.h | 9 ++- ...ontextManagerCocoa.h => PlatformCocoaGL.h} | 22 +++---- ...textManagerCocoa.mm => PlatformCocoaGL.mm} | 28 ++++---- ...xtManagerDummy.cpp => PlatformDummyGL.cpp} | 4 +- ...ontextManagerDummy.h => PlatformDummyGL.h} | 14 ++-- ...{ContextManagerEGL.cpp => PlatformEGL.cpp} | 64 +++++++++---------- .../{ContextManagerEGL.h => PlatformEGL.h} | 16 ++--- ...{ContextManagerGLX.cpp => PlatformGLX.cpp} | 22 +++---- .../{ContextManagerGLX.h => PlatformGLX.h} | 14 ++-- ...{ContextManagerWGL.cpp => PlatformWGL.cpp} | 20 +++--- .../{ContextManagerWGL.h => PlatformWGL.h} | 14 ++-- ...textManagerWebGL.cpp => PlatformWebGL.cpp} | 20 +++--- ...{ContextManagerWebGL.h => PlatformWebGL.h} | 14 ++-- ...gerVkAndroid.cpp => PlatformVkAndroid.cpp} | 6 +- ...xtManagerVkCocoa.h => PlatformVkAndroid.h} | 13 ++-- ...xtManagerVkAndroid.h => PlatformVkCocoa.h} | 15 ++--- ...xtManagerVkCocoa.mm => PlatformVkCocoa.mm} | 6 +- ...ManagerVkLinux.cpp => PlatformVkLinux.cpp} | 6 +- ...textManagerVkLinux.h => PlatformVkLinux.h} | 10 +-- ...gerVkWindows.cpp => PlatformVkWindows.cpp} | 6 +- ...ManagerVkWindows.h => PlatformVkWindows.h} | 10 +-- filament/src/driver/vulkan/VulkanDriver.cpp | 12 ++-- filament/src/driver/vulkan/VulkanDriver.h | 6 +- 33 files changed, 273 insertions(+), 287 deletions(-) rename filament/include/filament/driver/{ExternalContext.h => Platform.h} (83%) rename filament/src/driver/{ExternalContext.cpp => Platform.cpp} (60%) rename filament/src/driver/opengl/{ContextManagerCocoa.h => PlatformCocoaGL.h} (78%) rename filament/src/driver/opengl/{ContextManagerCocoa.mm => PlatformCocoaGL.mm} (76%) rename filament/src/driver/opengl/{ContextManagerDummy.cpp => PlatformDummyGL.cpp} (85%) rename filament/src/driver/opengl/{ContextManagerDummy.h => PlatformDummyGL.h} (83%) rename filament/src/driver/opengl/{ContextManagerEGL.cpp => PlatformEGL.cpp} (94%) rename filament/src/driver/opengl/{ContextManagerEGL.h => PlatformEGL.h} (85%) rename filament/src/driver/opengl/{ContextManagerGLX.cpp => PlatformGLX.cpp} (88%) rename filament/src/driver/opengl/{ContextManagerGLX.h => PlatformGLX.h} (84%) rename filament/src/driver/opengl/{ContextManagerWGL.cpp => PlatformWGL.cpp} (84%) rename filament/src/driver/opengl/{ContextManagerWGL.h => PlatformWGL.h} (81%) rename filament/src/driver/opengl/{ContextManagerWebGL.cpp => PlatformWebGL.cpp} (57%) rename filament/src/driver/opengl/{ContextManagerWebGL.h => PlatformWebGL.h} (83%) rename filament/src/driver/vulkan/{ContextManagerVkAndroid.cpp => PlatformVkAndroid.cpp} (89%) rename filament/src/driver/vulkan/{ContextManagerVkCocoa.h => PlatformVkAndroid.h} (77%) rename filament/src/driver/vulkan/{ContextManagerVkAndroid.h => PlatformVkCocoa.h} (70%) rename filament/src/driver/vulkan/{ContextManagerVkCocoa.mm => PlatformVkCocoa.mm} (92%) rename filament/src/driver/vulkan/{ContextManagerVkLinux.cpp => PlatformVkLinux.cpp} (92%) rename filament/src/driver/vulkan/{ContextManagerVkLinux.h => PlatformVkLinux.h} (78%) rename filament/src/driver/vulkan/{ContextManagerVkWindows.cpp => PlatformVkWindows.cpp} (89%) rename filament/src/driver/vulkan/{ContextManagerVkWindows.h => PlatformVkWindows.h} (77%) diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index 848cf2d1df..b0a2fb55c6 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -9,7 +9,7 @@ set(PUBLIC_HDR_DIR include) # ================================================================================================== set(PUBLIC_HDRS include/filament/driver/BufferDescriptor.h - include/filament/driver/ExternalContext.h + include/filament/driver/Platform.h include/filament/driver/PixelBufferDescriptor.h include/filament/Box.h include/filament/Camera.h @@ -53,7 +53,7 @@ set(SRCS src/driver/CircularBuffer.cpp src/driver/Driver.cpp src/driver/DriverAPI.inc - src/driver/ExternalContext.cpp + src/driver/Platform.cpp src/driver/GPUBuffer.cpp src/driver/Handle.cpp src/driver/Program.cpp @@ -165,17 +165,17 @@ endif() if (USE_EXTERNAL_GLES3) # Experimental feature; clients provide their own Context Manager. elseif (ANDROID) - list(APPEND SRCS src/driver/opengl/ContextManagerEGL.cpp) + list(APPEND SRCS src/driver/opengl/PlatformEGL.cpp) elseif (APPLE) - list(APPEND SRCS src/driver/opengl/ContextManagerCocoa.mm) + list(APPEND SRCS src/driver/opengl/PlatformCocoaGL.mm) elseif (WEBGL) - list(APPEND SRCS src/driver/opengl/ContextManagerWebGL.cpp) + list(APPEND SRCS src/driver/opengl/PlatformWebGL.cpp) elseif (LINUX) - list(APPEND SRCS src/driver/opengl/ContextManagerGLX.cpp) + list(APPEND SRCS src/driver/opengl/PlatformGLX.cpp) elseif (WIN32) - list(APPEND SRCS src/driver/opengl/ContextManagerWGL.cpp) + list(APPEND SRCS src/driver/opengl/PlatformWGL.cpp) else() - list(APPEND SRCS src/driver/opengl/ContextManagerDummy.cpp) + list(APPEND SRCS src/driver/opengl/PlatformDummyGL.cpp) endif() # ================================================================================================== @@ -203,13 +203,13 @@ if (FILAMENT_SUPPORTS_VULKAN) src/driver/vulkan/VulkanStagePool.cpp ) if (LINUX) - list(APPEND SRCS src/driver/vulkan/ContextManagerVkLinux.cpp) + list(APPEND SRCS src/driver/vulkan/PlatformVkLinux.cpp) elseif (APPLE) - list(APPEND SRCS src/driver/vulkan/ContextManagerVkCocoa.mm) + list(APPEND SRCS src/driver/vulkan/PlatformVkCocoa.mm) elseif (ANDROID) - list(APPEND SRCS src/driver/vulkan/ContextManagerVkAndroid.cpp) + list(APPEND SRCS src/driver/vulkan/PlatformVkAndroid.cpp) elseif (WIN32) - list(APPEND SRCS src/driver/vulkan/ContextManagerVkWindows.cpp) + list(APPEND SRCS src/driver/vulkan/PlatformVkWindows.cpp) endif() endif() diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h index 6054f53825..b0e73b9fc5 100644 --- a/filament/include/filament/Engine.h +++ b/filament/include/filament/Engine.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -142,29 +142,29 @@ class TransformManager; */ class UTILS_PUBLIC Engine { public: - using ExternalContext = driver::ExternalContext; + using Platform = driver::Platform; using Backend = driver::Backend; /** * Creates an instance of Engine * - * @param externalContext A pointer to an object that implements ExternalContext. If this is - * provided, then this object is used to manage the hardware context - * (e.g. OpenGL) lifecycle for filament. + * @param platform A pointer to an object that implements Platform. If this is + * provided, then this object is used to create the hardware context + * and expose platform features to it. * - * If not provided (or nullptr is used), an appropriate hardware - * context is created automatically. + * If not provided (or nullptr is used), an appropriate Platform + * is created automatically. * * All methods of this interface are called from filament's * render thread, which is different from the main thread. * - * The lifetime of \p externalContext must exceed the life time of + * The lifetime of \p platform must exceed the lifetime of * the Engine object. * * @param sharedGLContext A platform-dependant OpenGL context used as a shared context * when creating filament's internal context. * Setting this parameter will force filament to use the OpenGL - * implementation (instead of Vulkaan for instance). + * implementation (instead of Vulkan for instance). * * * @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be created. @@ -180,7 +180,7 @@ public: * This method is thread-safe. */ static Engine* create(Backend backend = Backend::DEFAULT, - ExternalContext* externalContext = nullptr, void* sharedGLContext = nullptr); + Platform* platform = nullptr, void* sharedGLContext = nullptr); /** * Destroy the Engine instance and all associated resources. diff --git a/filament/include/filament/SwapChain.h b/filament/include/filament/SwapChain.h index 556a80dfba..ad3e242288 100644 --- a/filament/include/filament/SwapChain.h +++ b/filament/include/filament/SwapChain.h @@ -35,7 +35,7 @@ namespace filament { * SwapChain* swapChain = engine->createSwapChain(nativeWindow); * \endcode * - * When Engine::create() is used without specifying an ExternalContext, the `nativeWindow` + * When Engine::create() is used without specifying a Platform, the `nativeWindow` * parameter above must be of type: * * Platform | nativeWindow type @@ -46,7 +46,7 @@ namespace filament { * X11 | Window * Windows | HWND * - * Otherwise, the `nativeWindow` is defined by the concrete implementation of ExternalContext. + * Otherwise, the `nativeWindow` is defined by the concrete implementation of Platform. * * * Examples: diff --git a/filament/include/filament/driver/ExternalContext.h b/filament/include/filament/driver/Platform.h similarity index 83% rename from filament/include/filament/driver/ExternalContext.h rename to filament/include/filament/driver/Platform.h index 9f3b73b48a..c9d4e240a6 100644 --- a/filament/include/filament/driver/ExternalContext.h +++ b/filament/include/filament/driver/Platform.h @@ -14,10 +14,8 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H -#define TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H - -#include +#ifndef TNT_FILAMENT_DRIVER_PLATFORM_H +#define TNT_FILAMENT_DRIVER_PLATFORM_H #include @@ -32,7 +30,7 @@ class Driver; namespace driver { -class UTILS_PUBLIC ExternalContext { +class UTILS_PUBLIC Platform { public: struct SwapChain {}; struct Fence {}; @@ -43,22 +41,23 @@ public: virtual int getOSVersion() const noexcept = 0; - virtual ~ExternalContext() noexcept; + virtual ~Platform() noexcept; protected: // Creates and and initializes the low-level API (e.g. an OpenGL context or Vulkan instance), // then creates the concrete Driver. Returns null on failure. - virtual std::unique_ptr createDriver(void* sharedGLContext) noexcept = 0; + // The caller takes ownership of the returned Driver* and must destroy it with delete. + virtual Driver* createDriver(void* sharedContext) noexcept = 0; private: friend class details::FEngine; - static ExternalContext* create(driver::Backend* backendHint) noexcept; - static void destroy(ExternalContext** context) noexcept; + static Platform* create(driver::Backend* backendHint) noexcept; + static void destroy(Platform** context) noexcept; }; -class UTILS_PUBLIC ContextManagerGL : public ExternalContext { +class UTILS_PUBLIC OpenGLPlatform : public Platform { public: - ~ContextManagerGL() noexcept override; + ~OpenGLPlatform() noexcept override; // Called to destroy the OpenGL context. This should clean up any windows // or buffers from initialization. @@ -103,9 +102,9 @@ public: virtual void destroyExternalTextureStorage(ExternalTexture* ets) noexcept = 0; }; -class UTILS_PUBLIC ContextManagerVk : public ExternalContext { +class UTILS_PUBLIC VulkanPlatform : public Platform { public: - ~ContextManagerVk() noexcept override; + ~VulkanPlatform() noexcept override; // Given a Vulkan instance and native window handle, creates the platform-specific surface. virtual void* createVkSurfaceKHR(void* nativeWindow, void* instance, @@ -115,4 +114,4 @@ public: } // namespace driver } // namespace filament -#endif // TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H +#endif // TNT_FILAMENT_DRIVER_PLATFORM_H diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index bca25ac41f..35fdeacb7b 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -71,8 +71,8 @@ namespace details { static std::unordered_map> sEngines; static std::mutex sEnginesLock; -FEngine* FEngine::create(Backend backend, ExternalContext* externalContext, void* sharedGLContext) { - FEngine* instance = new FEngine(backend, externalContext, sharedGLContext); +FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLContext) { + FEngine* instance = new FEngine(backend, platform, sharedGLContext); slog.i << "FEngine (" << sizeof(void*) * 8 << " bits) created at " << instance << " " << "(threading is " << (UTILS_HAS_THREADING ? "enabled)" : "disabled)") << io::endl; @@ -84,12 +84,12 @@ FEngine* FEngine::create(Backend backend, ExternalContext* externalContext, void // In the single-threaded case, we do so in the here and now. if (!UTILS_HAS_THREADING) { // we don't own the external context at that point, set it to null - instance->mExternalContext = nullptr; - if (externalContext == nullptr) { - externalContext = ExternalContext::create(&instance->mBackend); - instance->mExternalContext = externalContext; + instance->mPlatform = nullptr; + if (platform == nullptr) { + platform = Platform::create(&instance->mBackend); + instance->mPlatform = platform; } - instance->mDriver = externalContext->createDriver(sharedGLContext); + instance->mDriver = platform->createDriver(sharedGLContext); instance->init(); instance->execute(); return instance; @@ -143,9 +143,9 @@ static const half4 sFullScreenTriangleVertices[3] = { // these must be static because only a pointer is copied to the render stream static const uint16_t sFullScreenTriangleIndices[3] = { 0, 1, 2 }; -FEngine::FEngine(Backend backend, ExternalContext* externalContext, void* sharedGLContext) : +FEngine::FEngine(Backend backend, Platform* platform, void* sharedGLContext) : mBackend(backend), - mExternalContext(externalContext), + mPlatform(platform), mSharedGLContext(sharedGLContext), mEntityManager(EntityManager::get()), mRenderableManager(*this), @@ -245,6 +245,8 @@ void FEngine::init() { FEngine::~FEngine() noexcept { ASSERT_DESTRUCTOR(mTerminated, "Engine destroyed but not terminated!"); + delete mDriver; + Platform::destroy(&mPlatform); } void FEngine::shutdown() { @@ -324,8 +326,6 @@ void FEngine::shutdown() { // detach this thread from the jobsystem mJobSystem.emancipate(); - ExternalContext::destroy(&mExternalContext); - mTerminated = true; } @@ -369,18 +369,18 @@ void FEngine::flush() { int FEngine::loop() { // we don't own the external context at that point, set it to null - ExternalContext* externalContext = mExternalContext; - mExternalContext = nullptr; + Platform* platform = mPlatform; + mPlatform = nullptr; - if (externalContext == nullptr) { - externalContext = ExternalContext::create(&mBackend); - mExternalContext = externalContext; + if (platform == nullptr) { + platform = Platform::create(&mBackend); + mPlatform = platform; #if !defined(NDEBUG) slog.d << "FEngine resolved backend: " << (mBackend == driver::Backend::VULKAN ? "Vulkan" : "OpenGL") << io::endl; #endif } - mDriver = externalContext->createDriver(mSharedGLContext); + mDriver = platform->createDriver(mSharedGLContext); mDriverBarrier.latch(); if (UTILS_UNLIKELY(!mDriver)) { // if we get here, it's because the driver couldn't be initialized and the problem has @@ -771,8 +771,8 @@ EnginePerformanceTest::PFN EnginePerformanceTest::getDestroyUniverseApi() { using namespace details; -Engine* Engine::create(Backend backend, ExternalContext* externalContext, void* sharedGLContext) { - std::unique_ptr engine(FEngine::create(backend, externalContext, sharedGLContext)); +Engine* Engine::create(Backend backend, Platform* platform, void* sharedGLContext) { + std::unique_ptr engine(FEngine::create(backend, platform, sharedGLContext)); if (UTILS_UNLIKELY(!engine)) { // something went wrong during the driver or engine initialization return nullptr; diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h index 14e6a64db5..cc17510ff3 100644 --- a/filament/src/details/Engine.h +++ b/filament/src/details/Engine.h @@ -180,7 +180,7 @@ public: public: static FEngine* create(Backend backend = Backend::DEFAULT, - ExternalContext* externalContext = nullptr, void* sharedGLContext = nullptr); + Platform* platform = nullptr, void* sharedGLContext = nullptr); ~FEngine() noexcept; @@ -346,7 +346,7 @@ public: bool execute(); private: - FEngine(Backend backend, ExternalContext* externalContext, void* sharedGLContext); + FEngine(Backend backend, Platform* platform, void* sharedGLContext); void init(); int loop(); @@ -361,10 +361,10 @@ private: Handle createPostProcessProgram(filaflat::MaterialParser& parser, driver::ShaderModel model, PostProcessStage stage) const noexcept; - std::unique_ptr mDriver; + Driver* mDriver = nullptr; Backend mBackend; - ExternalContext* mExternalContext = nullptr; + Platform* mPlatform = nullptr; void* mSharedGLContext = nullptr; bool mTerminated = false; Handle mFullScreenTriangleRph; diff --git a/filament/src/driver/Driver.h b/filament/src/driver/Driver.h index 1e42cfdee4..0dc7aacc41 100644 --- a/filament/src/driver/Driver.h +++ b/filament/src/driver/Driver.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include "driver/Handle.h" diff --git a/filament/src/driver/DriverBase.h b/filament/src/driver/DriverBase.h index b8277a9fe7..fdaa615cd7 100644 --- a/filament/src/driver/DriverBase.h +++ b/filament/src/driver/DriverBase.h @@ -126,17 +126,17 @@ struct HwRenderTarget : public HwBase { }; struct HwFence : public HwBase { - driver::ExternalContext::Fence* fence; + driver::Platform::Fence* fence; }; struct HwSwapChain : public HwBase { - driver::ExternalContext::SwapChain* swapChain; + driver::Platform::SwapChain* swapChain; }; struct HwStream : public HwBase { HwStream() = default; - explicit HwStream(driver::ExternalContext::Stream* stream) : stream(stream) { } - driver::ExternalContext::Stream* stream = nullptr; + explicit HwStream(driver::Platform::Stream* stream) : stream(stream) { } + driver::Platform::Stream* stream = nullptr; uint32_t width = 0; uint32_t height = 0; }; diff --git a/filament/src/driver/ExternalContext.cpp b/filament/src/driver/Platform.cpp similarity index 60% rename from filament/src/driver/ExternalContext.cpp rename to filament/src/driver/Platform.cpp index 1afe5670dc..fff6e0a396 100644 --- a/filament/src/driver/ExternalContext.cpp +++ b/filament/src/driver/Platform.cpp @@ -14,41 +14,41 @@ * limitations under the License. */ -#include +#include #if defined(ANDROID) #ifndef USE_EXTERNAL_GLES3 - #include "driver/opengl/ContextManagerEGL.h" + #include "driver/opengl/PlatformEGL.h" #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) - #include "driver/vulkan/ContextManagerVkAndroid.h" + #include "driver/vulkan/PlatformVkAndroid.h" #endif #elif defined(__APPLE__) #ifndef USE_EXTERNAL_GLES3 - #include "driver/opengl/ContextManagerCocoa.h" + #include "driver/opengl/PlatformCocoaGL.h" #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) - #include "driver/vulkan/ContextManagerVkCocoa.h" + #include "driver/vulkan/PlatformVkCocoa.h" #endif #elif defined(__linux__) #ifndef USE_EXTERNAL_GLES3 - #include "driver/opengl/ContextManagerGLX.h" + #include "driver/opengl/PlatformGLX.h" #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) - #include "driver/vulkan/ContextManagerVkLinux.h" + #include "driver/vulkan/PlatformVkLinux.h" #endif #elif defined(WIN32) #ifndef USE_EXTERNAL_GLES3 - #include "driver/opengl/ContextManagerWGL.h" + #include "driver/opengl/PlatformWGL.h" #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) - #include "driver/vulkan/ContextManagerVkWindows.h" + #include "driver/vulkan/PlatformVkWindows.h" #endif #elif defined(__EMSCRIPTEN__) - #include "driver/opengl/ContextManagerWebGL.h" + #include "driver/opengl/PlatformWebGL.h" #else #ifndef USE_EXTERNAL_GLES3 - #include "driver/opengl/ContextManagerDummy.h" + #include "driver/opengl/PlatformDummyGL.h" #endif #endif @@ -56,16 +56,16 @@ namespace filament { namespace driver { // this generates the vtable in this translation unit -ExternalContext::~ExternalContext() noexcept = default; +Platform::~Platform() noexcept = default; -ContextManagerGL::~ContextManagerGL() noexcept = default; +OpenGLPlatform::~OpenGLPlatform() noexcept = default; -ContextManagerVk::~ContextManagerVk() noexcept = default; +VulkanPlatform::~VulkanPlatform() noexcept = default; -// Creates the platform-specific ExternalContext object. The caller takes ownership and is +// Creates the platform-specific Platform object. The caller takes ownership and is // responsible for destroying it. Initialization of the backend API is deferred until // createDriver(). The passed-in backend hint is replaced with the resolved backend. -ExternalContext* ExternalContext::create(Backend* backend) noexcept { +Platform* Platform::create(Backend* backend) noexcept { assert(backend); if (*backend == Backend::DEFAULT) { *backend = Backend::OPENGL; @@ -73,13 +73,13 @@ ExternalContext* ExternalContext::create(Backend* backend) noexcept { if (*backend == Backend::VULKAN) { #if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN) #if defined(ANDROID) - return new ContextManagerVkAndroid(); + return new PlatformVkAndroid(); #elif defined(__linux__) - return new ContextManagerVkLinux(); + return new PlatformVkLinux(); #elif defined(__APPLE__) - return new ContextManagerVkCocoa(); + return new PlatformVkCocoa(); #elif defined(WIN32) - return new ContextManagerVkWindows(); + return new PlatformVkWindows(); #else return nullptr; #endif @@ -90,23 +90,23 @@ ExternalContext* ExternalContext::create(Backend* backend) noexcept { #if defined(USE_EXTERNAL_GLES3) return nullptr; #elif defined(ANDROID) - return new ContextManagerEGL(); + return new PlatformEGL(); #elif defined(__APPLE__) - return new ContextManagerCocoa(); + return new PlatformCocoaGL(); #elif defined(__linux__) - return new ContextManagerGLX(); + return new PlatformGLX(); #elif defined(WIN32) - return new ContextManagerWGL(); + return new PlatformWGL(); #elif defined(__EMSCRIPTEN__) - return new ContextManagerWebGL(); + return new PlatformWebGL(); #else - return new ContextManagerDummy(); + return new PlatformDummyGL(); #endif return nullptr; } -// destroys an ExternalContext create by create() -void ExternalContext::destroy(ExternalContext** context) noexcept { +// destroys an Platform create by create() +void Platform::destroy(Platform** context) noexcept { delete *context; *context = nullptr; } diff --git a/filament/src/driver/opengl/OpenGLDriver.cpp b/filament/src/driver/opengl/OpenGLDriver.cpp index 8c896b384a..a12a66c4ea 100644 --- a/filament/src/driver/opengl/OpenGLDriver.cpp +++ b/filament/src/driver/opengl/OpenGLDriver.cpp @@ -28,7 +28,7 @@ #include "driver/opengl/OpenGLProgram.h" #include "driver/opengl/OpenGLBlitter.h" -#include +#include // change to true to display all GL extensions in the console on start-up #define DEBUG_PRINT_EXTENSIONS false @@ -59,10 +59,10 @@ namespace filament { using namespace driver; using namespace GLUtils; -std::unique_ptr OpenGLDriver::create( - ContextManagerGL* const externalContext, void* const sharedGLContext) noexcept { - assert(externalContext); - ContextManagerGL* const ec = externalContext; +Driver* OpenGLDriver::create( + OpenGLPlatform* const platform, void* const sharedGLContext) noexcept { + assert(platform); + OpenGLPlatform* const ec = platform; { // here we check we're on a supported version of GL before initializing the driver GLint major = 0, minor = 0; @@ -93,14 +93,14 @@ std::unique_ptr OpenGLDriver::create( } OpenGLDriver* const driver = new OpenGLDriver(ec); - return std::unique_ptr(driver); + return driver; } -OpenGLDriver::OpenGLDriver(ContextManagerGL* externalContext) noexcept +OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform) noexcept : DriverBase(new ConcreteDispatcher(this)), mHandleArena("Handles", 2U * 1024U * 1024U), // TODO: set the amount in configuration mSamplerMap(32), - mContextManager(*externalContext) { + mContextManager(*platform) { state.enables.caps.set(getIndexForCap(GL_DITHER)); state.vao.p = &mDefaultVAO; @@ -1376,7 +1376,7 @@ void OpenGLDriver::destroyStream(Driver::StreamHandle sh) { Handle OpenGLDriver::createStream(void* nativeStream) { Handle sh( allocateHandle(sizeof(GLStream)) ); - ExternalContext::Stream* stream = mContextManager.createStream(nativeStream); + Platform::Stream* stream = mContextManager.createStream(nativeStream); construct(sh, stream); return sh; } @@ -2237,7 +2237,7 @@ void OpenGLDriver::updateStream(GLTexture* t, driver::DriverApi* driver) noexcep info.width = s->width; info.height = s->height; - ExternalContext::ExternalTexture* ets = s->user_thread.infos[s->user_thread.cur].ets; + Platform::ExternalTexture* ets = s->user_thread.infos[s->user_thread.cur].ets; mContextManager.reallocateExternalStorage(ets, info.width, info.height, TextureFormat::RGB8); @@ -2521,7 +2521,7 @@ void OpenGLDriver::readPixels(Driver::RenderTargetHandle src, void OpenGLDriver::beginFrame(uint64_t monotonic_clock_ns, uint32_t frameId) { insertEventMarker("beginFrame"); if (UTILS_UNLIKELY(!mExternalStreams.empty())) { - driver::ContextManagerGL& contextManager = mContextManager; + driver::OpenGLPlatform& contextManager = mContextManager; const size_t index = getIndexForTextureTarget(GL_TEXTURE_EXTERNAL_OES); for (GLTexture const* t : mExternalStreams) { assert(t && t->hwStream); diff --git a/filament/src/driver/opengl/OpenGLDriver.h b/filament/src/driver/opengl/OpenGLDriver.h index fd18b34f5a..424a71fe0d 100644 --- a/filament/src/driver/opengl/OpenGLDriver.h +++ b/filament/src/driver/opengl/OpenGLDriver.h @@ -43,12 +43,11 @@ class OpenGLProgram; class OpenGLBlitter; class OpenGLDriver final : public DriverBase { - inline explicit OpenGLDriver(driver::ContextManagerGL* external_context) noexcept; + inline explicit OpenGLDriver(driver::OpenGLPlatform* platform) noexcept; ~OpenGLDriver() noexcept final; public: - static std::unique_ptr create( - driver::ContextManagerGL* externalContext, void* sharedGLContext) noexcept; + static Driver* create(driver::OpenGLPlatform* platform, void* sharedGLContext) noexcept; // OpenGLDriver specific fields struct GLVertexBuffer : public HwVertexBuffer { @@ -110,7 +109,7 @@ public: bool isNativeStream() const { return gl.externalTextureId == 0; } struct Info { // storage for the read/write textures below - driver::ExternalContext::ExternalTexture* ets = nullptr; + driver::Platform::ExternalTexture* ets = nullptr; GLuint width = 0; GLuint height = 0; }; @@ -532,7 +531,7 @@ private: void detachStream(GLTexture* t) noexcept; void replaceStream(GLTexture* t, GLStream* stream) noexcept; - driver::ContextManagerGL& mContextManager; + driver::OpenGLPlatform& mContextManager; OpenGLBlitter* mOpenGLBlitter = nullptr; void updateStream(GLTexture* t, driver::DriverApi* driver) noexcept; diff --git a/filament/src/driver/opengl/ContextManagerCocoa.h b/filament/src/driver/opengl/PlatformCocoaGL.h similarity index 78% rename from filament/src/driver/opengl/ContextManagerCocoa.h rename to filament/src/driver/opengl/PlatformCocoaGL.h index 5703de2884..4f12cb0a90 100644 --- a/filament/src/driver/opengl/ContextManagerCocoa.h +++ b/filament/src/driver/opengl/PlatformCocoaGL.h @@ -14,24 +14,24 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H #include #include -#include +#include namespace filament { -struct ContextManagerCocoaImpl; +struct PlatformCocoaGLImpl; -class ContextManagerCocoa final : public driver::ContextManagerGL { +class PlatformCocoaGL final : public driver::OpenGLPlatform { public: - ContextManagerCocoa(); - ~ContextManagerCocoa() noexcept final; + PlatformCocoaGL(); + ~PlatformCocoaGL() noexcept final; - std::unique_ptr createDriver(void* sharedGLContext) noexcept override; + Driver* createDriver(void* sharedContext) noexcept override; void terminate() noexcept final; SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final; @@ -61,11 +61,9 @@ public: int getOSVersion() const noexcept final { return 0; } private: - ContextManagerCocoaImpl* pImpl = nullptr; + PlatformCocoaGLImpl* pImpl = nullptr; }; -using ContextManager = filament::ContextManagerCocoa; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H diff --git a/filament/src/driver/opengl/ContextManagerCocoa.mm b/filament/src/driver/opengl/PlatformCocoaGL.mm similarity index 76% rename from filament/src/driver/opengl/ContextManagerCocoa.mm rename to filament/src/driver/opengl/PlatformCocoaGL.mm index 4a52c12c92..557e583147 100644 --- a/filament/src/driver/opengl/ContextManagerCocoa.mm +++ b/filament/src/driver/opengl/PlatformCocoaGL.mm @@ -14,14 +14,14 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerCocoa.h" +#include "driver/opengl/PlatformCocoaGL.h" #include #include #include "driver/DriverBase.h" -#include +#include #include @@ -31,20 +31,20 @@ namespace filament { using namespace driver; -struct ContextManagerCocoaImpl { +struct PlatformCocoaGLImpl { NSOpenGLContext* mGLContext = nullptr; NSView* mCurrentView = nullptr; }; -ContextManagerCocoa::ContextManagerCocoa() - : pImpl(new ContextManagerCocoaImpl) { +PlatformCocoaGL::PlatformCocoaGL() + : pImpl(new PlatformCocoaGLImpl) { } -ContextManagerCocoa::~ContextManagerCocoa() noexcept { +PlatformCocoaGL::~PlatformCocoaGL() noexcept { delete pImpl; } -std::unique_ptr ContextManagerCocoa::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformCocoaGL::createDriver(void* sharedContext) noexcept { // NSOpenGLPFAColorSize: when unspecified, a format that matches the screen is preferred NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, @@ -54,7 +54,7 @@ std::unique_ptr ContextManagerCocoa::createDriver(void* const sharedGLCo 0, 0, }; - NSOpenGLContext* shareContext = (NSOpenGLContext*)sharedGLContext; + NSOpenGLContext* shareContext = (NSOpenGLContext*)sharedContext; NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; NSOpenGLContext* nsOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:shareContext]; [pixelFormat release]; @@ -67,24 +67,24 @@ std::unique_ptr ContextManagerCocoa::createDriver(void* const sharedGLCo int result = bluegl::bind(); ASSERT_POSTCONDITION(!result, "Unable to load OpenGL entry points."); - return OpenGLDriver::create(this, sharedGLContext); + return OpenGLDriver::create(this, sharedContext); } -void ContextManagerCocoa::terminate() noexcept { +void PlatformCocoaGL::terminate() noexcept { [pImpl->mGLContext release]; bluegl::unbind(); } -ExternalContext::SwapChain* ContextManagerCocoa::createSwapChain(void* nativewindow, uint64_t& flags) noexcept { +Platform::SwapChain* PlatformCocoaGL::createSwapChain(void* nativewindow, uint64_t& flags) noexcept { // Transparent swap chain is not supported flags &= ~driver::SWAP_CHAIN_CONFIG_TRANSPARENT; return (SwapChain*) nativewindow; } -void ContextManagerCocoa::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformCocoaGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept { } -void ContextManagerCocoa::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformCocoaGL::makeCurrent(Platform::SwapChain* swapChain) noexcept { NSView *nsView = (NSView*) swapChain; if (pImpl->mCurrentView != nsView) { pImpl->mCurrentView = nsView; @@ -105,7 +105,7 @@ void ContextManagerCocoa::makeCurrent(ExternalContext::SwapChain* swapChain) noe [pImpl->mGLContext update]; } -void ContextManagerCocoa::commit(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformCocoaGL::commit(Platform::SwapChain* swapChain) noexcept { [pImpl->mGLContext flushBuffer]; } diff --git a/filament/src/driver/opengl/ContextManagerDummy.cpp b/filament/src/driver/opengl/PlatformDummyGL.cpp similarity index 85% rename from filament/src/driver/opengl/ContextManagerDummy.cpp rename to filament/src/driver/opengl/PlatformDummyGL.cpp index 9bfb6d3cc9..2b9f18fe2b 100644 --- a/filament/src/driver/opengl/ContextManagerDummy.cpp +++ b/filament/src/driver/opengl/PlatformDummyGL.cpp @@ -14,13 +14,13 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerDummy.h" +#include "driver/opengl/PlatformDummyGL.h" #include "driver/opengl/OpenGLDriver.h" namespace filament { -std::unique_ptr ContextManagerDummy::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformDummyGL::createDriver(void* const sharedGLContext) noexcept { return nullptr; } diff --git a/filament/src/driver/opengl/ContextManagerDummy.h b/filament/src/driver/opengl/PlatformDummyGL.h similarity index 83% rename from filament/src/driver/opengl/ContextManagerDummy.h rename to filament/src/driver/opengl/PlatformDummyGL.h index 36fb1ab2da..79fdb9409d 100644 --- a/filament/src/driver/opengl/ContextManagerDummy.h +++ b/filament/src/driver/opengl/PlatformDummyGL.h @@ -14,20 +14,20 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H #include #include -#include +#include namespace filament { -class ContextManagerDummy final : public driver::ContextManagerGL { +class PlatformDummyGL final : public driver::OpenGLPlatform { public: - std::unique_ptr createDriver(void* const sharedGLContext) noexcept override; + Driver* createDriver(void* const sharedGLContext) noexcept override; void terminate() noexcept override { } SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final override { @@ -58,8 +58,6 @@ public: int getOSVersion() const noexcept final override { return 0; } }; -using ContextManager = filament::ContextManagerDummy; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H diff --git a/filament/src/driver/opengl/ContextManagerEGL.cpp b/filament/src/driver/opengl/PlatformEGL.cpp similarity index 94% rename from filament/src/driver/opengl/ContextManagerEGL.cpp rename to filament/src/driver/opengl/PlatformEGL.cpp index 7c6abc5579..11c8d48379 100644 --- a/filament/src/driver/opengl/ContextManagerEGL.cpp +++ b/filament/src/driver/opengl/PlatformEGL.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerEGL.h" +#include "driver/opengl/PlatformEGL.h" #include @@ -75,7 +75,7 @@ UTILS_PRIVATE PFNEGLPRESENTATIONTIMEANDROIDPROC eglPresentationTimeANDROID; } using namespace glext; -using EGLStream = ExternalContext::Stream; +using EGLStream = Platform::Stream; // --------------------------------------------------------------------------------------------- // Utilities @@ -294,7 +294,7 @@ struct GraphicBufferWrapper { GraphicBuffer* graphicBuffer; }; } // namespace ndk using namespace ndk; -struct EGLExternalTexture : public ExternalContext::ExternalTexture { +struct EGLExternalTexture : public Platform::ExternalTexture { AHardwareBuffer* hardwareBuffer = nullptr; GraphicBufferWrapper* graphicBufferWrapper = nullptr; }; @@ -491,12 +491,12 @@ private: // --------------------------------------------------------------------------------------------- -ContextManagerEGL::ContextManagerEGL() noexcept +PlatformEGL::PlatformEGL() noexcept : mExternalStreamManager(ExternalStreamManagerAndroid::get()), mExternalTextureManager(ExternalTextureManagerAndroid::get()) { } -std::unique_ptr ContextManagerEGL::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformEGL::createDriver(void* sharedContext) noexcept { char scratch[PROP_VALUE_MAX + 1]; int length = __system_property_get("ro.build.version.release", scratch); int androidVersion = length >= 0 ? atoi(scratch) : 1; @@ -553,7 +553,7 @@ std::unique_ptr ContextManagerEGL::createDriver(void* const sharedGLCont #ifdef NDEBUG // When we don't have a shared context and we're in release mode, we always activate the // EGL_KHR_create_context_no_error extension. - if (!sharedGLContext && extensions.has("EGL_KHR_create_context_no_error")) { + if (!sharedContext && extensions.has("EGL_KHR_create_context_no_error")) { contextAttribs[2] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; contextAttribs[3] = EGL_TRUE; } @@ -617,14 +617,14 @@ std::unique_ptr ContextManagerEGL::createDriver(void* const sharedGLCont goto error; } - mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedGLContext, contextAttribs); - if (mEGLContext == EGL_NO_CONTEXT && sharedGLContext && + mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedContext, contextAttribs); + if (mEGLContext == EGL_NO_CONTEXT && sharedContext && extensions.has("EGL_KHR_create_context_no_error")) { // context creation could fail because of EGL_CONTEXT_OPENGL_NO_ERROR_KHR // not matching the sharedContext. Try with it. contextAttribs[2] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; contextAttribs[3] = EGL_TRUE; - mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedGLContext, contextAttribs); + mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedContext, contextAttribs); } if (UTILS_UNLIKELY(mEGLContext == EGL_NO_CONTEXT)) { // eglCreateContext failed @@ -639,7 +639,7 @@ std::unique_ptr ContextManagerEGL::createDriver(void* const sharedGLCont } // success!! - return OpenGLDriver::create(this, sharedGLContext); + return OpenGLDriver::create(this, sharedContext); error: // if we're here, we've failed @@ -659,7 +659,7 @@ error: return nullptr; } -EGLBoolean ContextManagerEGL::makeCurrent(EGLSurface surface) noexcept { +EGLBoolean PlatformEGL::makeCurrent(EGLSurface surface) noexcept { if (UTILS_UNLIKELY((surface != mCurrentSurface))) { mCurrentSurface = surface; return eglMakeCurrent(mEGLDisplay, surface, surface, mEGLContext); @@ -667,7 +667,7 @@ EGLBoolean ContextManagerEGL::makeCurrent(EGLSurface surface) noexcept { return EGL_TRUE; } -void ContextManagerEGL::terminate() noexcept { +void PlatformEGL::terminate() noexcept { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(mEGLDisplay, mEGLDummySurface); eglDestroyContext(mEGLDisplay, mEGLContext); @@ -675,7 +675,7 @@ void ContextManagerEGL::terminate() noexcept { eglReleaseThread(); } -ExternalContext::SwapChain* ContextManagerEGL::createSwapChain( +Platform::SwapChain* PlatformEGL::createSwapChain( void* nativeWindow, uint64_t& flags) noexcept { EGLSurface sur = eglCreateWindowSurface(mEGLDisplay, (flags & driver::SWAP_CHAIN_CONFIG_TRANSPARENT) ? mEGLTransparentConfig : mEGLConfig, @@ -691,7 +691,7 @@ ExternalContext::SwapChain* ContextManagerEGL::createSwapChain( return (SwapChain*)sur; } -void ContextManagerEGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformEGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept { EGLSurface sur = (EGLSurface) swapChain; if (sur != EGL_NO_SURFACE) { makeCurrent(mEGLDummySurface); @@ -699,14 +699,14 @@ void ContextManagerEGL::destroySwapChain(ExternalContext::SwapChain* swapChain) } } -void ContextManagerEGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformEGL::makeCurrent(Platform::SwapChain* swapChain) noexcept { EGLSurface sur = (EGLSurface) swapChain; if (sur != EGL_NO_SURFACE) { makeCurrent(sur); } } -void ContextManagerEGL::setPresentationTime(long time) noexcept { +void PlatformEGL::setPresentationTime(long time) noexcept { if (mCurrentSurface != EGL_NO_SURFACE) { eglPresentationTimeANDROID( mEGLDisplay, @@ -715,14 +715,14 @@ void ContextManagerEGL::setPresentationTime(long time) noexcept { } } -void ContextManagerEGL::commit(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformEGL::commit(Platform::SwapChain* swapChain) noexcept { EGLSurface sur = (EGLSurface) swapChain; if (sur != EGL_NO_SURFACE) { eglSwapBuffers(mEGLDisplay, sur); } } -ExternalContext::Fence* ContextManagerEGL::createFence() noexcept { +Platform::Fence* PlatformEGL::createFence() noexcept { Fence* f = nullptr; #ifdef EGL_KHR_reusable_sync f = (Fence*) eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_FENCE_KHR, nullptr); @@ -730,7 +730,7 @@ ExternalContext::Fence* ContextManagerEGL::createFence() noexcept { return f; } -void ContextManagerEGL::destroyFence(ExternalContext::Fence* fence) noexcept { +void PlatformEGL::destroyFence(Platform::Fence* fence) noexcept { #ifdef EGL_KHR_reusable_sync EGLSyncKHR sync = (EGLSyncKHR) fence; if (sync != EGL_NO_SYNC_KHR) { @@ -739,8 +739,8 @@ void ContextManagerEGL::destroyFence(ExternalContext::Fence* fence) noexcept { #endif } -driver::FenceStatus ContextManagerEGL::waitFence( - ExternalContext::Fence* fence, uint64_t timeout) noexcept { +driver::FenceStatus PlatformEGL::waitFence( + Platform::Fence* fence, uint64_t timeout) noexcept { #ifdef EGL_KHR_reusable_sync EGLSyncKHR sync = (EGLSyncKHR) fence; if (sync != EGL_NO_SYNC_KHR) { @@ -756,32 +756,32 @@ driver::FenceStatus ContextManagerEGL::waitFence( return FenceStatus::ERROR; } -ExternalContext::Stream* ContextManagerEGL::createStream(void* nativeStream) noexcept { +Platform::Stream* PlatformEGL::createStream(void* nativeStream) noexcept { return mExternalStreamManager.acquire(static_cast(nativeStream)); } -void ContextManagerEGL::destroyStream(ExternalContext::Stream* stream) noexcept { +void PlatformEGL::destroyStream(Platform::Stream* stream) noexcept { mExternalStreamManager.release(static_cast(stream)); } -void ContextManagerEGL::attach(Stream* stream, intptr_t tname) noexcept { +void PlatformEGL::attach(Stream* stream, intptr_t tname) noexcept { mExternalStreamManager.attach(static_cast(stream), tname); } -void ContextManagerEGL::detach(Stream* stream) noexcept { +void PlatformEGL::detach(Stream* stream) noexcept { mExternalStreamManager.detach(static_cast(stream)); } -void ContextManagerEGL::updateTexImage(Stream* stream) noexcept { +void PlatformEGL::updateTexImage(Stream* stream) noexcept { mExternalStreamManager.updateTexImage(static_cast(stream)); } -ExternalContext::ExternalTexture* ContextManagerEGL::createExternalTextureStorage() noexcept { +Platform::ExternalTexture* PlatformEGL::createExternalTextureStorage() noexcept { return mExternalTextureManager.create(); } -void ContextManagerEGL::reallocateExternalStorage( - ExternalContext::ExternalTexture* externalTexture, +void PlatformEGL::reallocateExternalStorage( + Platform::ExternalTexture* externalTexture, uint32_t w, uint32_t h, driver::TextureFormat format) noexcept { if (externalTexture) { EGLExternalTexture* ets = static_cast(externalTexture); @@ -790,15 +790,15 @@ void ContextManagerEGL::reallocateExternalStorage( } } -void ContextManagerEGL::destroyExternalTextureStorage( - ExternalContext::ExternalTexture* externalTexture) noexcept { +void PlatformEGL::destroyExternalTextureStorage( + Platform::ExternalTexture* externalTexture) noexcept { if (externalTexture) { EGLExternalTexture* ets = static_cast(externalTexture); mExternalTextureManager.destroy(ets, mEGLDisplay); } } -int ContextManagerEGL::getOSVersion() const noexcept { +int PlatformEGL::getOSVersion() const noexcept { return mOSVersion; } diff --git a/filament/src/driver/opengl/ContextManagerEGL.h b/filament/src/driver/opengl/PlatformEGL.h similarity index 85% rename from filament/src/driver/opengl/ContextManagerEGL.h rename to filament/src/driver/opengl/PlatformEGL.h index a5a8d90488..91e632706d 100644 --- a/filament/src/driver/opengl/ContextManagerEGL.h +++ b/filament/src/driver/opengl/PlatformEGL.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H #include @@ -23,7 +23,7 @@ #include #include -#include +#include struct AHardwareBuffer; @@ -33,12 +33,12 @@ class VirtualMachineEnv; class ExternalStreamManagerAndroid; class ExternalTextureManagerAndroid; -class ContextManagerEGL final : public driver::ContextManagerGL { +class PlatformEGL final : public driver::OpenGLPlatform { public: - ContextManagerEGL() noexcept; + PlatformEGL() noexcept; - std::unique_ptr createDriver(void* sharedGLContext) noexcept override; + Driver* createDriver(void* sharedContext) noexcept override; void terminate() noexcept override; SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final; @@ -81,8 +81,6 @@ private: ExternalTextureManagerAndroid& mExternalTextureManager; }; -using ContextManager = filament::ContextManagerEGL; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H diff --git a/filament/src/driver/opengl/ContextManagerGLX.cpp b/filament/src/driver/opengl/PlatformGLX.cpp similarity index 88% rename from filament/src/driver/opengl/ContextManagerGLX.cpp rename to filament/src/driver/opengl/PlatformGLX.cpp index df91078485..59c369d3ce 100644 --- a/filament/src/driver/opengl/ContextManagerGLX.cpp +++ b/filament/src/driver/opengl/PlatformGLX.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerGLX.h" +#include "driver/opengl/PlatformGLX.h" #include #include @@ -101,7 +101,7 @@ namespace filament { using namespace driver; -std::unique_ptr ContextManagerGLX::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept { loadLibraries(); // Get the display device mGLXDisplay = g_x11.openDisplay(NULL); @@ -151,7 +151,7 @@ std::unique_ptr ContextManagerGLX::createDriver(void* const sharedGLCont return OpenGLDriver::create(this, sharedGLContext); } -void ContextManagerGLX::terminate() noexcept { +void PlatformGLX::terminate() noexcept { g_glx.setCurrentContext(mGLXDisplay, None, None, nullptr); g_glx.destroyPbuffer(mGLXDisplay, mDummySurface); g_glx.destroyContext(mGLXDisplay, mGLXContext); @@ -159,7 +159,7 @@ void ContextManagerGLX::terminate() noexcept { bluegl::unbind(); } -ExternalContext::SwapChain* ContextManagerGLX::createSwapChain( +Platform::SwapChain* PlatformGLX::createSwapChain( void* nativeWindow, uint64_t& flags) noexcept { // Transparent swap chain is not supported @@ -167,29 +167,29 @@ ExternalContext::SwapChain* ContextManagerGLX::createSwapChain( return (SwapChain*) nativeWindow; } -void ContextManagerGLX::destroySwapChain(ExternalContext::SwapChain* /*swapChain*/) noexcept { +void PlatformGLX::destroySwapChain(Platform::SwapChain* /*swapChain*/) noexcept { } -void ContextManagerGLX::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformGLX::makeCurrent(Platform::SwapChain* swapChain) noexcept { g_glx.setCurrentContext(mGLXDisplay, (GLXDrawable) swapChain, (GLXDrawable) swapChain, mGLXContext); } -void ContextManagerGLX::commit(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformGLX::commit(Platform::SwapChain* swapChain) noexcept { g_glx.swapBuffers(mGLXDisplay, (GLXDrawable)swapChain); } -//TODO Implement GLX fences -ExternalContext::Fence* ContextManagerGLX::createFence() noexcept { +// TODO Implement GLX fences +Platform::Fence* PlatformGLX::createFence() noexcept { Fence* f = new Fence(); return f; } -void ContextManagerGLX::destroyFence(Fence* fence) noexcept { +void PlatformGLX::destroyFence(Fence* fence) noexcept { delete fence; } -driver::FenceStatus ContextManagerGLX::waitFence(Fence* fence, uint64_t timeout) noexcept { +driver::FenceStatus PlatformGLX::waitFence(Fence* fence, uint64_t timeout) noexcept { return driver::FenceStatus::CONDITION_SATISFIED; } diff --git a/filament/src/driver/opengl/ContextManagerGLX.h b/filament/src/driver/opengl/PlatformGLX.h similarity index 84% rename from filament/src/driver/opengl/ContextManagerGLX.h rename to filament/src/driver/opengl/PlatformGLX.h index efa97b7ade..e712b0a09e 100644 --- a/filament/src/driver/opengl/ContextManagerGLX.h +++ b/filament/src/driver/opengl/PlatformGLX.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H #include @@ -23,14 +23,14 @@ #include #include -#include +#include namespace filament { -class ContextManagerGLX final : public driver::ContextManagerGL { +class PlatformGLX final : public driver::OpenGLPlatform { public: - std::unique_ptr createDriver(void* const sharedGLContext) noexcept override; + Driver* createDriver(void* const sharedGLContext) noexcept override; void terminate() noexcept override; @@ -65,8 +65,6 @@ private: GLXPbuffer mDummySurface; }; -using ContextManager = filament::ContextManagerGLX; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H diff --git a/filament/src/driver/opengl/ContextManagerWGL.cpp b/filament/src/driver/opengl/PlatformWGL.cpp similarity index 84% rename from filament/src/driver/opengl/ContextManagerWGL.cpp rename to filament/src/driver/opengl/PlatformWGL.cpp index 9ff5a3e819..5388e5095e 100644 --- a/filament/src/driver/opengl/ContextManagerWGL.cpp +++ b/filament/src/driver/opengl/PlatformWGL.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerWGL.h" +#include "driver/opengl/PlatformWGL.h" #include @@ -61,7 +61,7 @@ namespace filament { using namespace driver; -std::unique_ptr ContextManagerWGL::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformWGL::createDriver(void* const sharedGLContext) noexcept { mPfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, @@ -135,7 +135,7 @@ error: return NULL; } -void ContextManagerWGL::terminate() noexcept { +void PlatformWGL::terminate() noexcept { wglMakeCurrent(NULL, NULL); if (mContext) { wglDeleteContext(mContext); @@ -153,7 +153,7 @@ void ContextManagerWGL::terminate() noexcept { bluegl::unbind(); } -ExternalContext::SwapChain* ContextManagerWGL::createSwapChain(void* nativeWindow, uint64_t& flags) noexcept { +Platform::SwapChain* PlatformWGL::createSwapChain(void* nativeWindow, uint64_t& flags) noexcept { // on Windows, the nativeWindow maps directly to a HDC HDC hdc = (HDC) nativeWindow; if (!ASSERT_POSTCONDITION_NON_FATAL(hdc, @@ -169,12 +169,12 @@ ExternalContext::SwapChain* ContextManagerWGL::createSwapChain(void* nativeWindo return swapChain; } -void ContextManagerWGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept { // make this swapChain not current (by making a dummy one current) wglMakeCurrent(mWhdc, mContext); } -void ContextManagerWGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWGL::makeCurrent(Platform::SwapChain* swapChain) noexcept { HDC hdc = (HDC)(swapChain); if (hdc != NULL) { BOOL success = wglMakeCurrent(hdc, mContext); @@ -185,7 +185,7 @@ void ContextManagerWGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexc } } -void ContextManagerWGL::commit(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWGL::commit(Platform::SwapChain* swapChain) noexcept { HDC hdc = (HDC)(swapChain); if (hdc != NULL) { SwapBuffers(hdc); @@ -193,14 +193,14 @@ void ContextManagerWGL::commit(ExternalContext::SwapChain* swapChain) noexcept { } //TODO Implement WGL fences -ExternalContext::Fence* ContextManagerWGL::createFence() noexcept { +Platform::Fence* PlatformWGL::createFence() noexcept { return nullptr; } -void ContextManagerWGL::destroyFence(Fence* fence) noexcept { +void PlatformWGL::destroyFence(Fence* fence) noexcept { } -driver::FenceStatus ContextManagerWGL::waitFence(Fence* fence, uint64_t timeout) noexcept { +driver::FenceStatus PlatformWGL::waitFence(Fence* fence, uint64_t timeout) noexcept { return driver::FenceStatus::ERROR; } diff --git a/filament/src/driver/opengl/ContextManagerWGL.h b/filament/src/driver/opengl/PlatformWGL.h similarity index 81% rename from filament/src/driver/opengl/ContextManagerWGL.h rename to filament/src/driver/opengl/PlatformWGL.h index cb3079f01a..e0c10bf793 100644 --- a/filament/src/driver/opengl/ContextManagerWGL.h +++ b/filament/src/driver/opengl/PlatformWGL.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WGL_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WGL_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WGL_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WGL_H #include @@ -23,13 +23,13 @@ #include #include -#include +#include namespace filament { -class ContextManagerWGL final : public driver::ContextManagerGL { +class PlatformWGL final : public driver::OpenGLPlatform { public: - std::unique_ptr createDriver(void* const sharedGLContext) noexcept override; + Driver* createDriver(void* const sharedGLContext) noexcept override; void terminate() noexcept override; SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept override; @@ -63,8 +63,6 @@ private: PIXELFORMATDESCRIPTOR mPfd = {}; }; -using ContextManager = filament::ContextManagerWGL; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H diff --git a/filament/src/driver/opengl/ContextManagerWebGL.cpp b/filament/src/driver/opengl/PlatformWebGL.cpp similarity index 57% rename from filament/src/driver/opengl/ContextManagerWebGL.cpp rename to filament/src/driver/opengl/PlatformWebGL.cpp index e0626d6313..fb9b3a3478 100644 --- a/filament/src/driver/opengl/ContextManagerWebGL.cpp +++ b/filament/src/driver/opengl/PlatformWebGL.cpp @@ -14,44 +14,44 @@ * limitations under the License. */ -#include "driver/opengl/ContextManagerWebGL.h" +#include "driver/opengl/PlatformWebGL.h" #include "driver/opengl/OpenGLDriver.h" namespace filament { using namespace driver; -std::unique_ptr ContextManagerWebGL::createDriver(void* const sharedGLContext) noexcept { +Driver* PlatformWebGL::createDriver(void* const sharedGLContext) noexcept { return OpenGLDriver::create(this, sharedGLContext); } -void ContextManagerWebGL::terminate() noexcept { +void PlatformWebGL::terminate() noexcept { } -ExternalContext::SwapChain* ContextManagerWebGL::createSwapChain( +Platform::SwapChain* PlatformWebGL::createSwapChain( void* nativeWindow, uint64_t& flags) noexcept { return (SwapChain*) nativeWindow; } -void ContextManagerWebGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWebGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept { } -void ContextManagerWebGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWebGL::makeCurrent(Platform::SwapChain* swapChain) noexcept { } -void ContextManagerWebGL::commit(ExternalContext::SwapChain* swapChain) noexcept { +void PlatformWebGL::commit(Platform::SwapChain* swapChain) noexcept { } -ExternalContext::Fence* ContextManagerWebGL::createFence() noexcept { +Platform::Fence* PlatformWebGL::createFence() noexcept { Fence* f = new Fence(); return f; } -void ContextManagerWebGL::destroyFence(Fence* fence) noexcept { +void PlatformWebGL::destroyFence(Fence* fence) noexcept { delete fence; } -driver::FenceStatus ContextManagerWebGL::waitFence(Fence* fence, uint64_t timeout) noexcept { +driver::FenceStatus PlatformWebGL::waitFence(Fence* fence, uint64_t timeout) noexcept { return driver::FenceStatus::CONDITION_SATISFIED; } diff --git a/filament/src/driver/opengl/ContextManagerWebGL.h b/filament/src/driver/opengl/PlatformWebGL.h similarity index 83% rename from filament/src/driver/opengl/ContextManagerWebGL.h rename to filament/src/driver/opengl/PlatformWebGL.h index da69a60cbf..aa782fbf72 100644 --- a/filament/src/driver/opengl/ContextManagerWebGL.h +++ b/filament/src/driver/opengl/PlatformWebGL.h @@ -14,23 +14,23 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H -#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H +#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H +#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H #include #include -#include +#include #include #include namespace filament { -class ContextManagerWebGL final : public driver::ContextManagerGL { +class PlatformWebGL final : public driver::OpenGLPlatform { public: - std::unique_ptr createDriver(void* const sharedGLContext) noexcept override; + Driver* createDriver(void* const sharedGLContext) noexcept override; void terminate() noexcept override; SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final override; @@ -58,8 +58,6 @@ public: int getOSVersion() const noexcept final override { return 0; } }; -using ContextManager = filament::ContextManagerWebGL; - } // namespace filament -#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H +#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H diff --git a/filament/src/driver/vulkan/ContextManagerVkAndroid.cpp b/filament/src/driver/vulkan/PlatformVkAndroid.cpp similarity index 89% rename from filament/src/driver/vulkan/ContextManagerVkAndroid.cpp rename to filament/src/driver/vulkan/PlatformVkAndroid.cpp index ac8ad8d0e3..97a9155197 100644 --- a/filament/src/driver/vulkan/ContextManagerVkAndroid.cpp +++ b/filament/src/driver/vulkan/PlatformVkAndroid.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/vulkan/ContextManagerVkAndroid.h" +#include "driver/vulkan/PlatformVkAndroid.h" #include "VulkanDriver.h" @@ -29,7 +29,7 @@ namespace filament { using namespace driver; -std::unique_ptr ContextManagerVkAndroid::createDriver(void* const sharedContext) noexcept { +std::unique_ptr PlatformVkAndroid::createDriver(void* const sharedContext) noexcept { ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts."); static const char* requestedExtensions[] = { "VK_KHR_surface", @@ -42,7 +42,7 @@ std::unique_ptr ContextManagerVkAndroid::createDriver(void* const shared sizeof(requestedExtensions) / sizeof(requestedExtensions[0])); } -void* ContextManagerVkAndroid::createVkSurfaceKHR(void* nativeWindow, void* vkinstance, +void* PlatformVkAndroid::createVkSurfaceKHR(void* nativeWindow, void* vkinstance, uint32_t* width, uint32_t* height) noexcept { const VkInstance instance = (VkInstance) vkinstance; ANativeWindow* aNativeWindow = (ANativeWindow*) nativeWindow; diff --git a/filament/src/driver/vulkan/ContextManagerVkCocoa.h b/filament/src/driver/vulkan/PlatformVkAndroid.h similarity index 77% rename from filament/src/driver/vulkan/ContextManagerVkCocoa.h rename to filament/src/driver/vulkan/PlatformVkAndroid.h index c093817d27..d6fa77708e 100644 --- a/filament/src/driver/vulkan/ContextManagerVkCocoa.h +++ b/filament/src/driver/vulkan/PlatformVkAndroid.h @@ -14,24 +14,27 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H -#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H +#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H +#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H #include #include -#include +#include namespace filament { -class ContextManagerVkCocoa final : public driver::ContextManagerVk { +class PlatformVkAndroid final : public driver::VulkanPlatform { public: + std::unique_ptr createDriver(void* const sharedContext) noexcept override; + void* createVkSurfaceKHR(void* nativeWindow, void* instance, uint32_t* width, uint32_t* height) noexcept override; + int getOSVersion() const noexcept override { return 0; } }; } // namespace filament -#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H +#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H diff --git a/filament/src/driver/vulkan/ContextManagerVkAndroid.h b/filament/src/driver/vulkan/PlatformVkCocoa.h similarity index 70% rename from filament/src/driver/vulkan/ContextManagerVkAndroid.h rename to filament/src/driver/vulkan/PlatformVkCocoa.h index 761c0cbb26..57e78eb6b0 100644 --- a/filament/src/driver/vulkan/ContextManagerVkAndroid.h +++ b/filament/src/driver/vulkan/PlatformVkCocoa.h @@ -14,27 +14,24 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H -#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H +#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H +#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H #include #include -#include +#include namespace filament { -class ContextManagerVkAndroid final : public driver::ContextManagerVk { +class PlatformVkCocoa final : public driver::VulkanPlatform { public: - - std::unique_ptr createDriver(void* const sharedContext) noexcept override; - + Driver* createDriver(void* sharedContext) noexcept override; void* createVkSurfaceKHR(void* nativeWindow, void* instance, uint32_t* width, uint32_t* height) noexcept override; - int getOSVersion() const noexcept override { return 0; } }; } // namespace filament -#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H +#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H diff --git a/filament/src/driver/vulkan/ContextManagerVkCocoa.mm b/filament/src/driver/vulkan/PlatformVkCocoa.mm similarity index 92% rename from filament/src/driver/vulkan/ContextManagerVkCocoa.mm rename to filament/src/driver/vulkan/PlatformVkCocoa.mm index 39a0b0bce1..0353dcb2cd 100644 --- a/filament/src/driver/vulkan/ContextManagerVkCocoa.mm +++ b/filament/src/driver/vulkan/PlatformVkCocoa.mm @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/vulkan/ContextManagerVkCocoa.h" +#include "driver/vulkan/PlatformVkCocoa.h" #include "VulkanDriver.h" @@ -36,14 +36,14 @@ namespace filament { using namespace driver; -std::unique_ptr ContextManagerVkCocoa::createDriver(void* const sharedContext) noexcept { +Driver* PlatformVkCocoa::createDriver(void* sharedContext) noexcept { ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts."); static const char* requestedExtensions[] = {"VK_KHR_surface", "VK_MVK_macos_surface"}; return VulkanDriver::create(this, requestedExtensions, sizeof(requestedExtensions) / sizeof(requestedExtensions[0])); } -void* ContextManagerVkCocoa::createVkSurfaceKHR(void* nativeWindow, void* instance, +void* PlatformVkCocoa::createVkSurfaceKHR(void* nativeWindow, void* instance, uint32_t* width, uint32_t* height) noexcept { // Obtain the CAMetalLayer-backed view. NSView* nsview = (NSView*) nativeWindow; diff --git a/filament/src/driver/vulkan/ContextManagerVkLinux.cpp b/filament/src/driver/vulkan/PlatformVkLinux.cpp similarity index 92% rename from filament/src/driver/vulkan/ContextManagerVkLinux.cpp rename to filament/src/driver/vulkan/PlatformVkLinux.cpp index 8ee3b8d3e6..ed82b8c835 100644 --- a/filament/src/driver/vulkan/ContextManagerVkLinux.cpp +++ b/filament/src/driver/vulkan/PlatformVkLinux.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/vulkan/ContextManagerVkLinux.h" +#include "driver/vulkan/PlatformVkLinux.h" #include "VulkanDriver.h" @@ -43,7 +43,7 @@ struct X11Functions { void* library; } g_x11; -std::unique_ptr ContextManagerVkLinux::createDriver(void* const sharedContext) noexcept { +std::unique_ptr PlatformVkLinux::createDriver(void* const sharedContext) noexcept { ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts."); static const char* requestedExtensions[] = { "VK_KHR_surface", @@ -63,7 +63,7 @@ std::unique_ptr ContextManagerVkLinux::createDriver(void* const sharedCo sizeof(requestedExtensions) / sizeof(requestedExtensions[0])); } -void* ContextManagerVkLinux::createVkSurfaceKHR(void* nativeWindow, void* instance, +void* PlatformVkLinux::createVkSurfaceKHR(void* nativeWindow, void* instance, uint32_t* width, uint32_t* height) noexcept { ASSERT_POSTCONDITION(vkCreateXlibSurfaceKHR, "Unable to load vkCreateXlibSurfaceKHR function."); VkSurfaceKHR surface = nullptr; diff --git a/filament/src/driver/vulkan/ContextManagerVkLinux.h b/filament/src/driver/vulkan/PlatformVkLinux.h similarity index 78% rename from filament/src/driver/vulkan/ContextManagerVkLinux.h rename to filament/src/driver/vulkan/PlatformVkLinux.h index 5a9c7779b1..680a5e062b 100644 --- a/filament/src/driver/vulkan/ContextManagerVkLinux.h +++ b/filament/src/driver/vulkan/PlatformVkLinux.h @@ -14,19 +14,19 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H -#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H +#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H +#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H #include #include -#include +#include #include namespace filament { -class ContextManagerVkLinux final : public driver::ContextManagerVk { +class PlatformVkLinux final : public driver::VulkanPlatform { public: std::unique_ptr createDriver(void* const sharedContext) noexcept override; @@ -42,4 +42,4 @@ private: } // namespace filament -#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H +#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H diff --git a/filament/src/driver/vulkan/ContextManagerVkWindows.cpp b/filament/src/driver/vulkan/PlatformVkWindows.cpp similarity index 89% rename from filament/src/driver/vulkan/ContextManagerVkWindows.cpp rename to filament/src/driver/vulkan/PlatformVkWindows.cpp index 3768c48343..8635428bfc 100644 --- a/filament/src/driver/vulkan/ContextManagerVkWindows.cpp +++ b/filament/src/driver/vulkan/PlatformVkWindows.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "driver/vulkan/ContextManagerVkWindows.h" +#include "driver/vulkan/PlatformVkWindows.h" #include "VulkanDriver.h" @@ -27,7 +27,7 @@ namespace filament { using namespace driver; -std::unique_ptr ContextManagerVkWindows::createDriver(void* const sharedContext) noexcept { +std::unique_ptr PlatformVkWindows::createDriver(void* const sharedContext) noexcept { ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts."); static const char* requestedExtensions[] = { "VK_KHR_surface", @@ -40,7 +40,7 @@ std::unique_ptr ContextManagerVkWindows::createDriver(void* const shared sizeof(requestedExtensions) / sizeof(requestedExtensions[0])); } -void* ContextManagerVkWindows::createVkSurfaceKHR(void* nativeWindow, void* instance, +void* PlatformVkWindows::createVkSurfaceKHR(void* nativeWindow, void* instance, uint32_t* width, uint32_t* height) noexcept { VkSurfaceKHR surface = nullptr; diff --git a/filament/src/driver/vulkan/ContextManagerVkWindows.h b/filament/src/driver/vulkan/PlatformVkWindows.h similarity index 77% rename from filament/src/driver/vulkan/ContextManagerVkWindows.h rename to filament/src/driver/vulkan/PlatformVkWindows.h index 589ae8001d..9c49df68bb 100644 --- a/filament/src/driver/vulkan/ContextManagerVkWindows.h +++ b/filament/src/driver/vulkan/PlatformVkWindows.h @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H -#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H +#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H +#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H #include #include -#include +#include namespace filament { -class ContextManagerVkWindows final : public driver::ContextManagerVk { +class PlatformVkWindows final : public driver::VulkanPlatform { public: std::unique_ptr createDriver(void* const sharedContext) noexcept override; @@ -40,4 +40,4 @@ private: } // namespace filament -#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H +#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H diff --git a/filament/src/driver/vulkan/VulkanDriver.cpp b/filament/src/driver/vulkan/VulkanDriver.cpp index bc1561dcd9..f627fd5286 100644 --- a/filament/src/driver/vulkan/VulkanDriver.cpp +++ b/filament/src/driver/vulkan/VulkanDriver.cpp @@ -39,10 +39,10 @@ static constexpr bool SWAPCHAIN_HAS_DEPTH = true; namespace filament { namespace driver { -VulkanDriver::VulkanDriver(ContextManagerVk* externalContext, +VulkanDriver::VulkanDriver(VulkanPlatform* platform, const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept : DriverBase(new ConcreteDispatcher(this)), - mContextManager(*externalContext), mStagePool(mContext), mFramebufferCache(mContext), + mContextManager(*platform), mStagePool(mContext), mFramebufferCache(mContext), mSamplerCache(mContext) { mContext.rasterState = mBinder.getDefaultRasterState(); @@ -158,12 +158,12 @@ VulkanDriver::VulkanDriver(ContextManagerVk* externalContext, VulkanDriver::~VulkanDriver() noexcept = default; -std::unique_ptr VulkanDriver::create(ContextManagerVk* const externalContext, +Driver* VulkanDriver::create(VulkanPlatform* const platform, const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept { - assert(externalContext); - auto* const driver = new VulkanDriver(externalContext, ppEnabledExtensions, + assert(platform); + auto* const driver = new VulkanDriver(platform, ppEnabledExtensions, enabledExtensionCount); - return std::unique_ptr(driver); + return driver; } ShaderModel VulkanDriver::getShaderModel() const noexcept { diff --git a/filament/src/driver/vulkan/VulkanDriver.h b/filament/src/driver/vulkan/VulkanDriver.h index c0b604d7f9..dac01778bf 100644 --- a/filament/src/driver/vulkan/VulkanDriver.h +++ b/filament/src/driver/vulkan/VulkanDriver.h @@ -40,7 +40,7 @@ struct VulkanSamplerBuffer; class VulkanDriver final : public DriverBase { public: - static std::unique_ptr create(driver::ContextManagerVk* externalContext, + static Driver* create(driver::VulkanPlatform* platform, const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept; private: @@ -49,7 +49,7 @@ private: void debugCommand(const char* methodName) override; #endif - inline VulkanDriver(driver::ContextManagerVk* const externalContext, + inline VulkanDriver(driver::VulkanPlatform* const platform, const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept; virtual ~VulkanDriver() noexcept; @@ -75,7 +75,7 @@ private: VulkanDriver(VulkanDriver const&) = delete; VulkanDriver& operator = (VulkanDriver const&) = delete; - driver::ContextManagerVk& mContextManager; + driver::VulkanPlatform& mContextManager; // For now we're not bothering to store handles in pools, just simple on-demand allocation. // We have a little map from integer handles to "blobs" which get replaced with the Hw objects.