From 7e7d49a8828ed737775d07db89fa4a185e8072cf Mon Sep 17 00:00:00 2001 From: Eric Griffith Date: Sat, 16 Sep 2023 06:31:28 -0700 Subject: [PATCH] IGL: Remove platform specific ImageLoader for Mac, Win and iOS Summary: This diff removes the platform specific ImageLoader implementations for Mac, Win and iOS. These all have the same implementation, so the functionality is just moved into the base class. Only Android still has a platform-specific implementation. Reviewed By: corporateshark Differential Revision: D49136971 fbshipit-source-id: c049121d6c5d363fb3e70d19ec746c9e41faccb3 --- shell/ios/CMakeLists.txt | 4 ++-- shell/mac/CMakeLists.txt | 4 ++-- shell/mac/ViewController.mm | 1 - shell/shared/imageLoader/ImageLoader.cpp | 6 +++++ shell/shared/imageLoader/ImageLoader.h | 7 +++--- .../android/ImageLoaderAndroid.cpp | 2 +- .../imageLoader/android/ImageLoaderAndroid.h | 2 +- shell/shared/imageLoader/ios/ImageLoaderIos.h | 24 ------------------- .../shared/imageLoader/ios/ImageLoaderIos.mm | 21 ---------------- shell/shared/imageLoader/mac/ImageLoaderMac.h | 23 ------------------ .../shared/imageLoader/mac/ImageLoaderMac.mm | 21 ---------------- .../shared/imageLoader/win/ImageLoaderWin.cpp | 22 ----------------- shell/shared/imageLoader/win/ImageLoaderWin.h | 22 ----------------- shell/shared/platform/ios/PlatformIos.mm | 4 ++-- shell/shared/platform/mac/PlatformMac.cpp | 4 ++-- shell/shared/platform/win/PlatformWin.cpp | 4 ++-- shell/windows/CMakeLists.txt | 4 ++-- shell/windows/opengl/App.cpp | 1 - shell/windows/opengles/App.cpp | 1 - shell/windows/vulkan/App.cpp | 1 - 20 files changed, 24 insertions(+), 154 deletions(-) delete mode 100644 shell/shared/imageLoader/ios/ImageLoaderIos.h delete mode 100644 shell/shared/imageLoader/ios/ImageLoaderIos.mm delete mode 100644 shell/shared/imageLoader/mac/ImageLoaderMac.h delete mode 100644 shell/shared/imageLoader/mac/ImageLoaderMac.mm delete mode 100644 shell/shared/imageLoader/win/ImageLoaderWin.cpp delete mode 100644 shell/shared/imageLoader/win/ImageLoaderWin.h diff --git a/shell/ios/CMakeLists.txt b/shell/ios/CMakeLists.txt index c47c7c9c0e..4889a64ae3 100644 --- a/shell/ios/CMakeLists.txt +++ b/shell/ios/CMakeLists.txt @@ -8,9 +8,9 @@ cmake_minimum_required(VERSION 3.16) set(PROJECT_NAME "iOS") file(GLOB PLATFORM_SHARED_SRC_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/apple/*.mm ../shared/imageLoader/ios/*.mm ../shared/imageWriter/ios/*.mm ../shared/platform/ios/*.mm) + ../shared/fileLoader/apple/*.mm ../shared/imageWriter/ios/*.mm ../shared/platform/ios/*.mm) file(GLOB PLATFORM_SHARED_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/apple/*.h ../shared/imageLoader/ios/*.h ../shared/imageWriter/ios/*.h ../shared/platform/ios/*.h) + ../shared/fileLoader/apple/*.h ../shared/imageWriter/ios/*.h ../shared/platform/ios/*.h) add_library(IGLShellPlatform ${PLATFORM_SHARED_SRC_FILES} ${PLATFORM_SHARED_HEADER_FILES}) target_link_libraries(IGLShellPlatform PUBLIC IGLLibrary) diff --git a/shell/mac/CMakeLists.txt b/shell/mac/CMakeLists.txt index 65722dd254..dc8c49e5cc 100644 --- a/shell/mac/CMakeLists.txt +++ b/shell/mac/CMakeLists.txt @@ -10,9 +10,9 @@ set(PROJECT_NAME "Mac") file(GLOB PLATFORM_SHARED_SRC_CPP_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../shared/imageWriter/stb/*.cpp ../shared/platform/mac/*.cpp) file(GLOB PLATFORM_SHARED_SRC_OBJC_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/apple/*.mm ../shared/imageLoader/mac/*.mm ../shared/imageWriter/mac/*.mm) + ../shared/fileLoader/apple/*.mm ../shared/imageWriter/mac/*.mm) file(GLOB PLATFORM_SHARED_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/apple/*.h ../shared/imageLoader/mac/*.h ../shared/imageWriter/mac/*.h ../shared/imageWriter/stb/*.h + ../shared/fileLoader/apple/*.h ../shared/imageWriter/mac/*.h ../shared/imageWriter/stb/*.h ../shared/platform/mac/*.h) add_library(IGLShellPlatform ${PLATFORM_SHARED_SRC_CPP_FILES} ${PLATFORM_SHARED_SRC_OBJC_FILES} ${PLATFORM_SHARED_HEADER_FILES}) diff --git a/shell/mac/ViewController.mm b/shell/mac/ViewController.mm index 27aa213a2a..1cd93c5a5d 100644 --- a/shell/mac/ViewController.mm +++ b/shell/mac/ViewController.mm @@ -24,7 +24,6 @@ #import #import #endif -#include #include #include #include diff --git a/shell/shared/imageLoader/ImageLoader.cpp b/shell/shared/imageLoader/ImageLoader.cpp index 138ca3baeb..ccc67491dd 100644 --- a/shell/shared/imageLoader/ImageLoader.cpp +++ b/shell/shared/imageLoader/ImageLoader.cpp @@ -57,6 +57,12 @@ ImageLoader::ImageLoader(FileLoader& fileLoader) : fileLoader_(fileLoader), factory_(std::make_unique(createLoaderFactories())) {} +ImageData ImageLoader::defaultLoadImageData(const std::string& imageName) noexcept { + std::string fullName = fileLoader().fullPath(imageName); + + return loadImageDataFromFile(fullName); +} + ImageData ImageLoader::loadImageDataFromFile(const std::string& fileName) noexcept { auto [data, length] = fileLoader_.loadBinaryData(fileName); if (IGL_VERIFY(data && length > 0)) { diff --git a/shell/shared/imageLoader/ImageLoader.h b/shell/shared/imageLoader/ImageLoader.h index c206194358..00dd12d8aa 100644 --- a/shell/shared/imageLoader/ImageLoader.h +++ b/shell/shared/imageLoader/ImageLoader.h @@ -27,9 +27,10 @@ class ImageLoader { public: explicit ImageLoader(FileLoader& fileLoader); virtual ~ImageLoader() = default; - virtual ImageData loadImageData(std::string /*imageName*/) noexcept { - return checkerboard(); + virtual ImageData loadImageData(const std::string& imageName) noexcept { + return defaultLoadImageData(imageName); } + static ImageData checkerboard() noexcept; protected: [[nodiscard]] const FileLoader& fileLoader() const noexcept { @@ -45,7 +46,7 @@ class ImageLoader { [[nodiscard]] ImageData loadImageDataFromMemory(const uint8_t* data, uint32_t length) noexcept; private: - static ImageData checkerboard() noexcept; + ImageData defaultLoadImageData(const std::string& imageName) noexcept; FileLoader& fileLoader_; std::unique_ptr factory_; diff --git a/shell/shared/imageLoader/android/ImageLoaderAndroid.cpp b/shell/shared/imageLoader/android/ImageLoaderAndroid.cpp index b3b429913f..0b2ea24ca7 100644 --- a/shell/shared/imageLoader/android/ImageLoaderAndroid.cpp +++ b/shell/shared/imageLoader/android/ImageLoaderAndroid.cpp @@ -14,7 +14,7 @@ namespace igl::shell { ImageLoaderAndroid::ImageLoaderAndroid(FileLoader& fileLoader) : ImageLoader(fileLoader) {} -ImageData ImageLoaderAndroid::loadImageData(std::string imageName) noexcept { +ImageData ImageLoaderAndroid::loadImageData(const std::string& imageName) noexcept { auto ret = ImageData(); // Load file diff --git a/shell/shared/imageLoader/android/ImageLoaderAndroid.h b/shell/shared/imageLoader/android/ImageLoaderAndroid.h index a589e4a48f..eea3f3b3c0 100644 --- a/shell/shared/imageLoader/android/ImageLoaderAndroid.h +++ b/shell/shared/imageLoader/android/ImageLoaderAndroid.h @@ -19,7 +19,7 @@ class ImageLoaderAndroid final : public ImageLoader { public: ImageLoaderAndroid(FileLoader& fileLoader); ~ImageLoaderAndroid() override = default; - ImageData loadImageData(std::string imageName) noexcept override; + ImageData loadImageData(const std::string& imageName) noexcept override; void setAssetManager(AAssetManager* mgr) { assetManager_ = mgr; } diff --git a/shell/shared/imageLoader/ios/ImageLoaderIos.h b/shell/shared/imageLoader/ios/ImageLoaderIos.h deleted file mode 100644 index ec0b25e9f8..0000000000 --- a/shell/shared/imageLoader/ios/ImageLoaderIos.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace igl::shell { - -class ImageLoaderIos final : public ImageLoader { - public: - ImageLoaderIos(FileLoader& fileLoader); - ~ImageLoaderIos() override = default; - ImageData loadImageData(std::string imageName) noexcept override; - - private: -}; - -} // namespace igl::shell diff --git a/shell/shared/imageLoader/ios/ImageLoaderIos.mm b/shell/shared/imageLoader/ios/ImageLoaderIos.mm deleted file mode 100644 index b5bb8cb66e..0000000000 --- a/shell/shared/imageLoader/ios/ImageLoaderIos.mm +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include - -#include - -namespace igl::shell { - -ImageLoaderIos::ImageLoaderIos(FileLoader& fileLoader) : ImageLoader(fileLoader) {} - -ImageData ImageLoaderIos::loadImageData(std::string imageName) noexcept { - auto fullPath = fileLoader().fullPath(imageName); - return loadImageDataFromFile(fullPath); -} - -} // namespace igl::shell diff --git a/shell/shared/imageLoader/mac/ImageLoaderMac.h b/shell/shared/imageLoader/mac/ImageLoaderMac.h deleted file mode 100644 index 634fdb9c35..0000000000 --- a/shell/shared/imageLoader/mac/ImageLoaderMac.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -namespace igl::shell { - -class ImageLoaderMac final : public ImageLoader { - public: - ImageLoaderMac(FileLoader& fileLoader); - ~ImageLoaderMac() override = default; - ImageData loadImageData(std::string imageName) noexcept override; - - private: -}; - -} // namespace igl::shell diff --git a/shell/shared/imageLoader/mac/ImageLoaderMac.mm b/shell/shared/imageLoader/mac/ImageLoaderMac.mm deleted file mode 100644 index 65a2937538..0000000000 --- a/shell/shared/imageLoader/mac/ImageLoaderMac.mm +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include - -#include - -namespace igl::shell { - -ImageLoaderMac::ImageLoaderMac(FileLoader& fileLoader) : ImageLoader(fileLoader) {} - -ImageData ImageLoaderMac::loadImageData(std::string imageName) noexcept { - auto fullPath = fileLoader().fullPath(imageName); - return loadImageDataFromFile(fullPath); -} - -} // namespace igl::shell diff --git a/shell/shared/imageLoader/win/ImageLoaderWin.cpp b/shell/shared/imageLoader/win/ImageLoaderWin.cpp deleted file mode 100644 index f734eba17d..0000000000 --- a/shell/shared/imageLoader/win/ImageLoaderWin.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include - -#include - -namespace igl::shell { - -ImageLoaderWin::ImageLoaderWin(FileLoader& fileLoader) : ImageLoader(fileLoader) {} - -ImageData ImageLoaderWin::loadImageData(std::string imageName) noexcept { - std::string fullName = fileLoader().fullPath(imageName); - - return loadImageDataFromFile(fullName); -} - -} // namespace igl::shell diff --git a/shell/shared/imageLoader/win/ImageLoaderWin.h b/shell/shared/imageLoader/win/ImageLoaderWin.h deleted file mode 100644 index f726339fbb..0000000000 --- a/shell/shared/imageLoader/win/ImageLoaderWin.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace igl::shell { - -class ImageLoaderWin final : public ImageLoader { - public: - ImageLoaderWin(FileLoader& fileLoader); - ~ImageLoaderWin() override = default; - ImageData loadImageData(std::string imageName) noexcept override; -}; - -} // namespace igl::shell diff --git a/shell/shared/platform/ios/PlatformIos.mm b/shell/shared/platform/ios/PlatformIos.mm index d0f2c0ce74..23dd06bf7c 100644 --- a/shell/shared/platform/ios/PlatformIos.mm +++ b/shell/shared/platform/ios/PlatformIos.mm @@ -8,14 +8,14 @@ #include #include -#include +#include #include namespace igl::shell { PlatformIos::PlatformIos(std::unique_ptr device) : device_(std::move(device)) { fileLoader_ = std::make_unique(); - imageLoader_ = std::make_unique(*fileLoader_); + imageLoader_ = std::make_unique(*fileLoader_); imageWriter_ = std::make_unique(); } diff --git a/shell/shared/platform/mac/PlatformMac.cpp b/shell/shared/platform/mac/PlatformMac.cpp index 90f4302cb3..ad29c3fb4b 100644 --- a/shell/shared/platform/mac/PlatformMac.cpp +++ b/shell/shared/platform/mac/PlatformMac.cpp @@ -8,14 +8,14 @@ #include #include -#include +#include #include namespace igl::shell { PlatformMac::PlatformMac(std::shared_ptr device) : device_(std::move(device)) { fileLoader_ = std::make_unique(); - imageLoader_ = std::make_unique(*fileLoader_); + imageLoader_ = std::make_unique(*fileLoader_); imageWriter_ = std::make_unique(); } diff --git a/shell/shared/platform/win/PlatformWin.cpp b/shell/shared/platform/win/PlatformWin.cpp index a90c7c183b..48ed4f774b 100644 --- a/shell/shared/platform/win/PlatformWin.cpp +++ b/shell/shared/platform/win/PlatformWin.cpp @@ -8,14 +8,14 @@ #include #include -#include +#include #include namespace igl::shell { PlatformWin::PlatformWin(std::shared_ptr device) : device_(std::move(device)) { fileLoader_ = std::make_unique(); - imageLoader_ = std::make_unique(*fileLoader_); + imageLoader_ = std::make_unique(*fileLoader_); imageWriter_ = std::make_unique(); } diff --git a/shell/windows/CMakeLists.txt b/shell/windows/CMakeLists.txt index 3d864444e1..3b8c442f50 100644 --- a/shell/windows/CMakeLists.txt +++ b/shell/windows/CMakeLists.txt @@ -11,10 +11,10 @@ add_definitions("-DNOMINMAX") add_definitions("-D_USE_MATH_DEFINES=1") file(GLOB PLATFORM_SHARED_SRC_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/win/*.cpp ../shared/imageLoader/win/*.cpp ../shared/imageWriter/win/*.cpp + ../shared/fileLoader/win/*.cpp ../shared/imageWriter/win/*.cpp ../shared/imageWriter/stb/*.cpp ../shared/platform/win/*.cpp) file(GLOB PLATFORM_SHARED_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ../shared/fileLoader/win/*.h ../shared/imageLoader/win/*.h ../shared/imageWriter/win/*.h ../shared/imageWriter/stb/*.h + ../shared/fileLoader/win/*.h ../shared/imageWriter/win/*.h ../shared/imageWriter/stb/*.h ../shared/platform/win/*.h) add_library(IGLShellPlatform ${PLATFORM_SHARED_SRC_FILES} ${PLATFORM_SHARED_HEADER_FILES}) diff --git a/shell/windows/opengl/App.cpp b/shell/windows/opengl/App.cpp index ae14093b28..818cf26255 100644 --- a/shell/windows/opengl/App.cpp +++ b/shell/windows/opengl/App.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/shell/windows/opengles/App.cpp b/shell/windows/opengles/App.cpp index cc7b63f099..5705c83ab0 100644 --- a/shell/windows/opengles/App.cpp +++ b/shell/windows/opengles/App.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/shell/windows/vulkan/App.cpp b/shell/windows/vulkan/App.cpp index 46b2a54205..1f3df2defb 100644 --- a/shell/windows/vulkan/App.cpp +++ b/shell/windows/vulkan/App.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include