Skip to content

Commit

Permalink
IGL: Remove platform specific ImageLoader for Mac, Win and iOS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Eric Griffith authored and facebook-github-bot committed Sep 16, 2023
1 parent 00c8805 commit 7e7d49a
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 154 deletions.
4 changes: 2 additions & 2 deletions shell/ios/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shell/mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 0 additions & 1 deletion shell/mac/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#import <igl/opengl/macos/Device.h>
#import <igl/opengl/macos/HWDevice.h>
#endif
#include <shell/shared/imageLoader/mac/ImageLoaderMac.h>
#include <shell/shared/platform/mac/PlatformMac.h>
#include <shell/shared/renderSession/AppParams.h>
#include <shell/shared/renderSession/DefaultSession.h>
Expand Down
6 changes: 6 additions & 0 deletions shell/shared/imageLoader/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ ImageLoader::ImageLoader(FileLoader& fileLoader) :
fileLoader_(fileLoader),
factory_(std::make_unique<iglu::textureloader::TextureLoaderFactory>(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)) {
Expand Down
7 changes: 4 additions & 3 deletions shell/shared/imageLoader/ImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<iglu::textureloader::TextureLoaderFactory> factory_;
Expand Down
2 changes: 1 addition & 1 deletion shell/shared/imageLoader/android/ImageLoaderAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shell/shared/imageLoader/android/ImageLoaderAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 0 additions & 24 deletions shell/shared/imageLoader/ios/ImageLoaderIos.h

This file was deleted.

21 changes: 0 additions & 21 deletions shell/shared/imageLoader/ios/ImageLoaderIos.mm

This file was deleted.

23 changes: 0 additions & 23 deletions shell/shared/imageLoader/mac/ImageLoaderMac.h

This file was deleted.

21 changes: 0 additions & 21 deletions shell/shared/imageLoader/mac/ImageLoaderMac.mm

This file was deleted.

22 changes: 0 additions & 22 deletions shell/shared/imageLoader/win/ImageLoaderWin.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions shell/shared/imageLoader/win/ImageLoaderWin.h

This file was deleted.

4 changes: 2 additions & 2 deletions shell/shared/platform/ios/PlatformIos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <shell/shared/platform/ios/PlatformIos.h>

#include <shell/shared/fileLoader/apple/FileLoaderApple.h>
#include <shell/shared/imageLoader/ios/ImageLoaderIos.h>
#include <shell/shared/imageLoader/ImageLoader.h>
#include <shell/shared/imageWriter/ios/ImageWriterIos.h>

namespace igl::shell {

PlatformIos::PlatformIos(std::unique_ptr<igl::IDevice> device) : device_(std::move(device)) {
fileLoader_ = std::make_unique<igl::shell::FileLoaderApple>();
imageLoader_ = std::make_unique<igl::shell::ImageLoaderIos>(*fileLoader_);
imageLoader_ = std::make_unique<igl::shell::ImageLoader>(*fileLoader_);
imageWriter_ = std::make_unique<igl::shell::ImageWriterIos>();
}

Expand Down
4 changes: 2 additions & 2 deletions shell/shared/platform/mac/PlatformMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <shell/shared/platform/mac/PlatformMac.h>

#include <shell/shared/fileLoader/apple/FileLoaderApple.h>
#include <shell/shared/imageLoader/mac/ImageLoaderMac.h>
#include <shell/shared/imageLoader/ImageLoader.h>
#include <shell/shared/imageWriter/mac/ImageWriterMac.h>

namespace igl::shell {

PlatformMac::PlatformMac(std::shared_ptr<igl::IDevice> device) : device_(std::move(device)) {
fileLoader_ = std::make_unique<igl::shell::FileLoaderApple>();
imageLoader_ = std::make_unique<igl::shell::ImageLoaderMac>(*fileLoader_);
imageLoader_ = std::make_unique<igl::shell::ImageLoader>(*fileLoader_);
imageWriter_ = std::make_unique<igl::shell::ImageWriterMac>();
}

Expand Down
4 changes: 2 additions & 2 deletions shell/shared/platform/win/PlatformWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <shell/shared/platform/win/PlatformWin.h>

#include <shell/shared/fileLoader/win/FileLoaderWin.h>
#include <shell/shared/imageLoader/win/ImageLoaderWin.h>
#include <shell/shared/imageLoader/ImageLoader.h>
#include <shell/shared/imageWriter/win/ImageWriterWin.h>

namespace igl::shell {

PlatformWin::PlatformWin(std::shared_ptr<igl::IDevice> device) : device_(std::move(device)) {
fileLoader_ = std::make_unique<igl::shell::FileLoaderWin>();
imageLoader_ = std::make_unique<igl::shell::ImageLoaderWin>(*fileLoader_);
imageLoader_ = std::make_unique<igl::shell::ImageLoader>(*fileLoader_);
imageWriter_ = std::make_unique<igl::shell::ImageWriterWin>();
}

Expand Down
4 changes: 2 additions & 2 deletions shell/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 0 additions & 1 deletion shell/windows/opengl/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <igl/opengl/Version.h>
#include <igl/opengl/ViewTextureTarget.h>
#include <memory>
#include <shell/shared/imageLoader/win/ImageLoaderWin.h>
#include <shell/shared/platform/win/PlatformWin.h>
#include <shell/shared/renderSession/AppParams.h>
#include <shell/shared/renderSession/DefaultSession.h>
Expand Down
1 change: 0 additions & 1 deletion shell/windows/opengles/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <igl/opengl/egl/Device.h>
#include <igl/opengl/egl/PlatformDevice.h>
#include <memory>
#include <shell/shared/imageLoader/win/ImageLoaderWin.h>
#include <shell/shared/platform/win/PlatformWin.h>
#include <shell/shared/renderSession/AppParams.h>
#include <shell/shared/renderSession/DefaultSession.h>
Expand Down
1 change: 0 additions & 1 deletion shell/windows/vulkan/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <igl/vulkan/HWDevice.h>
#include <igl/vulkan/VulkanContext.h>
#include <memory>
#include <shell/shared/imageLoader/win/ImageLoaderWin.h>
#include <shell/shared/platform/win/PlatformWin.h>
#include <shell/shared/renderSession/AppParams.h>
#include <shell/shared/renderSession/DefaultSession.h>
Expand Down

0 comments on commit 7e7d49a

Please sign in to comment.