Skip to content

Commit

Permalink
Misc tweaks and fixes
Browse files Browse the repository at this point in the history
* Imagine: Add support for NDK r27, which is now required
* Imagine: Replace deprecated ALooper_pollAll() with ALooper_pollOnce()
* Imagine: Replace ItemDelegate & ItemsDelegate menu item types with new ItemSourceDelegate
* Imagine: Refactor Bluetooth classes
* Imagine: Make PixelFormat::id public to allow passing as a non-type template parameter
* Imagine: Remove unneeded ErrorCode type
* Imagine: Use std::generic_category instead of system_category for POSIX file errors
* Imagine: Check and catch exceptions in Android BluetoothAdapter startDiscovery()
* Imagine: Improve RingBuffer's blocking API
* EmuFramework: Refactor key event code into InputManager
* EmuFramework: Move some video-related options into EmuVideoLayer
* EmuFramework: Fix Bluetooth menu items incorrectly shown by default on Android 4.2+
* NES.emu: Fix incorrect paths for some internal palettes
* Saturn.emu: Simplify VDP2 work queue code and flush commands when partially filled
  • Loading branch information
Robert Broglia committed Apr 20, 2024
1 parent 12f8a0c commit 42bf495
Show file tree
Hide file tree
Showing 100 changed files with 1,472 additions and 1,797 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
run: |
mkdir imagine-sdk
mkdir EX-Emulators
wget "https://dl.google.com/android/repository/android-ndk-r26c-linux.zip"
unzip android-ndk-r26c-linux.zip
echo "ANDROID_NDK_PATH=${{ github.workspace }}/android-ndk-r26c" >> $GITHUB_ENV
wget "https://dl.google.com/android/repository/android-ndk-r27-beta1-linux.zip"
unzip android-ndk-r27-beta1-linux.zip
echo "ANDROID_NDK_PATH=${{ github.workspace }}/android-ndk-r27-beta1" >> $GITHUB_ENV
echo "EMUFRAMEWORK_PATH=${{ github.workspace }}/EmuFramework" >> $GITHUB_ENV
echo "IMAGINE_PATH=${{ github.workspace }}/imagine" >> $GITHUB_ENV
echo "IMAGINE_SDK_PATH=${{ github.workspace }}/imagine-sdk" >> $GITHUB_ENV
Expand Down
7 changes: 3 additions & 4 deletions EmuFramework/include/emuframework/Cheats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected:
class BaseEditCheatListView : public TableView, public EmuAppHelper<BaseEditCheatListView>
{
public:
BaseEditCheatListView(ViewAttachParams attach, TableView::ItemsDelegate items, TableView::ItemDelegate item);
BaseEditCheatListView(ViewAttachParams attach, TableView::ItemSourceDelegate);
void setOnCheatListChanged(RefreshCheatsDelegate del);

protected:
Expand All @@ -60,14 +60,13 @@ public:
using EmuAppHelper<BaseEditCheatView<CheatViewImpl>>::app;

BaseEditCheatView(UTF16Convertible auto &&viewName, ViewAttachParams attach, UTF16Convertible auto &&cheatName,
TableView::ItemsDelegate items, TableView::ItemDelegate item, TextMenuItem::SelectDelegate removed,
TableView::ItemSourceDelegate itemSrc, TextMenuItem::SelectDelegate removed,
RefreshCheatsDelegate onCheatListChanged_):
TableView
{
IG_forward(viewName),
attach,
items,
item
itemSrc
},
name
{
Expand Down
36 changes: 8 additions & 28 deletions EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <imagine/gfx/Renderer.hh>
#include <imagine/data-type/image/PixmapReader.hh>
#include <imagine/data-type/image/PixmapWriter.hh>
#include <imagine/bluetooth/BluetoothAdapter.hh>
#include <imagine/font/Font.hh>
#include <imagine/util/used.hh>
#include <imagine/util/enum.hh>
Expand All @@ -49,7 +50,6 @@

namespace IG
{
class BluetoothAdapter;
class FileIO;
class BasicNavView;
class YesNoAlertView;
Expand Down Expand Up @@ -105,12 +105,6 @@ struct AssetDesc
constexpr auto filename() const { return assetFilename[fileIdx()]; }
};

WISE_ENUM_CLASS((ImageChannel, uint8_t),
All,
Red,
Green,
Blue);

enum class AltSpeedMode
{
fast, slow
Expand All @@ -124,11 +118,6 @@ WISE_ENUM_CLASS((CPUAffinityMode, uint8_t),
Auto, Any, Manual
);

struct SystemKeyInputFlags
{
bool allowTurboModifier{true};
};

constexpr float menuVideoBrightnessScale = .25f;

class EmuApp : public IG::Application
Expand Down Expand Up @@ -208,10 +197,9 @@ public:
static void updateLegacySavePath(IG::ApplicationContext, CStringView path);
auto screenshotDirectory() const { return system().userPath(userScreenshotPath); }
std::unique_ptr<View> makeCustomView(ViewAttachParams attach, ViewID id);
bool handleKeyInput(KeyInfo, const Input::Event &srcEvent);
bool handleAppActionKeyInput(InputAction, const Input::Event &srcEvent);
void handleSystemKeyInput(KeyInfo, Input::Action, uint32_t metaState = 0, SystemKeyInputFlags flags = {});
void runTurboInputEvents();
bool handleKeyInput(KeyInfo i, const Input::Event &srcEvent) { return inputManager.handleKeyInput(*this, i, srcEvent); }
bool handleAppActionKeyInput(InputAction a, const Input::Event &srcEvent) { return inputManager.handleAppActionKeyInput(*this, a, srcEvent); }
void handleSystemKeyInput(KeyInfo i, Input::Action a, uint32_t metaState = 0, SystemKeyInputFlags flags = {}) { inputManager.handleSystemKeyInput(*this, i, a, metaState, flags); }
void resetInput();
void setRunSpeed(double speed);
void saveSessionOptions();
Expand Down Expand Up @@ -247,7 +235,6 @@ public:
FS::PathString makeNextScreenshotFilename();
bool mogaManagerIsActive() const { return bool(mogaManagerPtr); }
void setMogaManagerActive(bool on, bool notify);
BluetoothAdapter *bluetoothAdapter();
void closeBluetoothConnections();
ViewAttachParams attachParams();
auto &customKeyConfigList() { return inputManager.customKeyConfigs; };
Expand All @@ -272,8 +259,7 @@ public:
bool setWindowDrawableConfig(Gfx::DrawableConfig);
Gfx::DrawableConfig windowDrawableConfig() const { return windowDrawableConf; }
IG::PixelFormat windowPixelFormat() const;
void setRenderPixelFormat(std::optional<IG::PixelFormat>);
IG::PixelFormat renderPixelFormat() const { return renderPixelFmt; }
void setRenderPixelFormat(IG::PixelFormat);
bool setVideoAspectRatio(float val);
float videoAspectRatio() const;
float defaultVideoAspectRatio() const;
Expand All @@ -284,10 +270,6 @@ public:
void setContentRotation(IG::Rotation);
void updateVideoContentRotation();
void updateContentRotation();
float videoBrightness(ImageChannel) const;
const Gfx::Vec3 &videoBrightnessAsRGB() const { return videoBrightnessRGB; }
int videoBrightnessAsInt(ImageChannel ch) const { return videoBrightness(ch) * 100.f; }
void setVideoBrightness(float brightness, ImageChannel);
Gfx::PresentMode effectivePresentMode() const
{
if(frameTimeSource == FrameTimeSource::Renderer)
Expand Down Expand Up @@ -367,21 +349,21 @@ protected:
EmuSystemTask emuSystemTask{*this};
mutable Gfx::Texture assetBuffImg[wise_enum::size<AssetFileID>];
int savedAdvancedFrames{};
Gfx::Vec3 videoBrightnessRGB{1.f, 1.f, 1.f};
FS::PathString contentSearchPath_;
[[no_unique_address]] IG::Data::PixmapReader pixmapReader;
[[no_unique_address]] IG::Data::PixmapWriter pixmapWriter;
[[no_unique_address]] PerformanceHintManager perfHintManager;
[[no_unique_address]] PerformanceHintSession perfHintSession;
BluetoothAdapter *bta{};
ConditionalMember<MOGA_INPUT, std::unique_ptr<Input::MogaManager>> mogaManagerPtr;
Gfx::DrawableConfig windowDrawableConf;
IG::PixelFormat renderPixelFmt;
ConditionalMember<Config::TRANSLUCENT_SYSTEM_UI, bool> layoutBehindSystemUI{};
bool enableBlankFrameInsertion{};
public:
BluetoothAdapter bluetoothAdapter;
RecentContent recentContent;
std::string userScreenshotPath;
Property<IG::PixelFormat, CFGKEY_RENDER_PIXEL_FORMAT,
PropertyDesc<IG::PixelFormat>{.isValid = renderPixelFormatIsValid}> renderPixelFormat;
ConditionalProperty<Config::cpuAffinity, CPUMask, CFGKEY_CPU_AFFINITY_MASK> cpuAffinityMask;
Property<int16_t, CFGKEY_FAST_MODE_SPEED,
PropertyDesc<int16_t>{.defaultValue = 800, .isValid = isValidFastSpeed}> fastModeSpeed;
Expand Down Expand Up @@ -410,7 +392,6 @@ public:
Property<PixelFormatID, CFGKEY_IMAGE_EFFECT_PIXEL_FORMAT,
PropertyDesc<PixelFormatID>{.defaultValue = PIXEL_NONE, .isValid = imageEffectPixelFormatIsValid}> imageEffectPixelFormat;
Property<int8_t, CFGKEY_MENU_SCALE, PropertyDesc<int8_t>{.defaultValue = 100, .isValid = optionMenuScaleIsValid}> menuScale;
Property<uint8_t, CFGKEY_CONTENT_SCALE, PropertyDesc<uint8_t>{.defaultValue = 100, .isValid = optionContentScaleIsValid}> contentScale;
ConditionalProperty<Config::BASE_MULTI_WINDOW && Config::BASE_MULTI_SCREEN, bool, CFGKEY_SHOW_ON_2ND_SCREEN> showOnSecondScreen;
Property<Gfx::TextureBufferMode, CFGKEY_TEXTURE_BUFFER_MODE> textureBufferMode;
Property<Rotation, CFGKEY_CONTENT_ROTATION,
Expand Down Expand Up @@ -448,7 +429,6 @@ public:
void saveConfigFile(IG::ApplicationContext);
void saveConfigFile(FileIO &);
void initOptions(IG::ApplicationContext);
std::optional<IG::PixelFormat> renderPixelFormatOption() const;
void applyRenderPixelFormat();
std::optional<IG::PixelFormat> windowDrawablePixelFormatOption() const;
std::optional<Gfx::ColorSpace> windowDrawableColorSpaceOption() const;
Expand Down
9 changes: 9 additions & 0 deletions EmuFramework/include/emuframework/EmuInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace EmuEx

using namespace IG;
class InputDeviceConfig;
struct InputAction;

struct KeyCategory
{
Expand Down Expand Up @@ -153,6 +154,11 @@ struct InputDeviceSavedConfig
bool matchesDevice(const Input::Device &dev) const;
};

struct SystemKeyInputFlags
{
bool allowTurboModifier{true};
};

class InputManager
{
public:
Expand All @@ -166,6 +172,9 @@ public:

InputManager(ApplicationContext ctx):
vController{ctx} {}
bool handleKeyInput(EmuApp&, KeyInfo, const Input::Event &srcEvent);
bool handleAppActionKeyInput(EmuApp&, InputAction, const Input::Event &srcEvent);
void handleSystemKeyInput(EmuApp&, KeyInfo, Input::Action, uint32_t metaState = 0, SystemKeyInputFlags flags = {});
void updateInputDevices(ApplicationContext);
KeyConfig *customKeyConfig(std::string_view name, const Input::Device &) const;
KeyConfigDesc keyConfig(std::string_view name, const Input::Device &) const;
Expand Down
17 changes: 17 additions & 0 deletions EmuFramework/include/emuframework/EmuOptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ constexpr bool isValidWithMinMax(const auto &v)
return v >= min && v <= max;
}

constexpr bool windowPixelFormatIsValid(const IG::PixelFormat &v)
{
switch(v)
{
case IG::PIXEL_NONE:
case IG::PIXEL_RGB565:
case IG::PIXEL_RGBA8888:
return true;
default: return false;
}
}

constexpr bool renderPixelFormatIsValid(const auto &v)
{
return windowPixelFormatIsValid(v);
}

}

namespace IG
Expand Down
1 change: 0 additions & 1 deletion EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <emuframework/EmuTiming.hh>
#include <emuframework/VController.hh>
#include <emuframework/EmuInput.hh>
#include <optional>
#include <string>
#include <string_view>

Expand Down
1 change: 0 additions & 1 deletion EmuFramework/include/emuframework/EmuVideo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <emuframework/EmuSystemTaskContext.hh>
#include <imagine/gfx/PixmapBufferTexture.hh>
#include <imagine/gfx/SyncFence.hh>
#include <optional>

namespace EmuEx
{
Expand Down
23 changes: 21 additions & 2 deletions EmuFramework/include/emuframework/EmuVideoLayer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <emuframework/VideoImageOverlay.hh>
#include <emuframework/VideoImageEffect.hh>
#include <emuframework/EmuOptions.hh>
#include <imagine/gfx/Quads.hh>
#include <imagine/gfx/Vec3.hh>
#include <imagine/pixmap/PixelFormat.hh>
Expand All @@ -30,6 +31,12 @@ class EmuVideo;
class EmuSystem;
class VController;

WISE_ENUM_CLASS((ImageChannel, uint8_t),
All,
Red,
Green,
Blue);

class EmuVideoLayer
{
public:
Expand All @@ -48,15 +55,24 @@ public:
void setEffectFormat(IG::PixelFormat);
void setLinearFilter(bool on);
bool usingLinearFilter() const { return useLinearFilter; }
void setBrightness(Gfx::Vec3);
void onVideoFormatChanged(IG::PixelFormat effectFmt);
Gfx::ColorSpace colorSpace() const { return colSpace; }
bool srgbColorSpace() const { return colSpace == Gfx::ColorSpace::SRGB; }
void setRotation(IG::Rotation);
float evalAspectRatio(float aR);
float channelBrightness(ImageChannel) const;
int channelBrightnessAsInt(ImageChannel ch) const { return channelBrightness(ch) * 100.f; }
const Gfx::Vec3 &brightnessAsRGB() const { return brightnessUnscaled; }
void setBrightness(float brightness, ImageChannel);
bool readConfig(MapIO &, unsigned key);
void writeConfig(FileIO &) const;

void setBrightnessScale(float s)
{
brightnessScale = s;
updateBrightness();
}

const IG::WindowRect &contentRect() const
{
return contentRect_;
Expand All @@ -72,6 +88,8 @@ private:
IG::WindowRect contentRect_;
Gfx::Vec3 brightness{1.f, 1.f, 1.f};
Gfx::Vec3 brightnessSrgb{1.f, 1.f, 1.f};
Gfx::Vec3 brightnessUnscaled{1.f, 1.f, 1.f};
float brightnessScale;
public:
float landscapeAspectRatio;
float portraitAspectRatio;
Expand All @@ -82,7 +100,7 @@ private:
ImageOverlayId userOverlayEffectId{};
Gfx::ColorSpace colSpace{};
public:
uint8_t scale{100};
Property<uint8_t, CFGKEY_CONTENT_SCALE, PropertyDesc<uint8_t>{.defaultValue = 100, .isValid = optionContentScaleIsValid}> scale;
private:
IG::Rotation rotation{};
bool useLinearFilter{true};
Expand All @@ -92,6 +110,7 @@ private:
void buildEffectChain();
bool updateConvertColorSpaceEffect();
void updateSprite();
void updateBrightness();
void logOutputFormat();
Gfx::Renderer &renderer();
Gfx::ColorSpace videoColorSpace(IG::PixelFormat videoFmt) const;
Expand Down
10 changes: 3 additions & 7 deletions EmuFramework/include/emuframework/InputManagerView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ private:
ConditionalMember<Config::Input::DEVICE_HOTSWAP, BoolMenuItem> notifyDeviceChange;
ConditionalMember<Config::Input::BLUETOOTH, TextHeadingMenuItem> bluetoothHeading;
ConditionalMember<Config::Input::BLUETOOTH && Config::BASE_CAN_BACKGROUND_APP, BoolMenuItem> keepBtActive;
#ifdef CONFIG_BLUETOOTH_SCAN_SECS
TextMenuItem btScanSecsItem[5];
MultiChoiceMenuItem btScanSecs;
#endif
#ifdef CONFIG_BLUETOOTH_SCAN_CACHE_USAGE
BoolMenuItem btScanCache;
#endif
ConditionalMember<Config::Bluetooth::scanTime, TextMenuItem> btScanSecsItem[5];
ConditionalMember<Config::Bluetooth::scanTime, MultiChoiceMenuItem> btScanSecs;
ConditionalMember<Config::Bluetooth::scanCache, BoolMenuItem> btScanCache;
BoolMenuItem altGamepadConfirm;
StaticArrayList<MenuItem*, 10> item;
EmuInputView *emuInputView{};
Expand Down
6 changes: 2 additions & 4 deletions EmuFramework/include/emuframework/MainMenuView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <imagine/gui/TableView.hh>
#include <imagine/gui/MenuItem.hh>
#include <imagine/util/container/ArrayList.hh>
#include <imagine/bluetooth/sys.hh>
#include <imagine/bluetooth/defs.hh>
#include <array>

namespace EmuEx
Expand Down Expand Up @@ -52,9 +52,7 @@ protected:
TextMenuItem benchmark;
ConditionalMember<Config::Input::BLUETOOTH, TextMenuItem> scanWiimotes;
ConditionalMember<Config::Input::BLUETOOTH, TextMenuItem> bluetoothDisconnect;
#ifdef CONFIG_BLUETOOTH_SERVER
TextMenuItem acceptPS3ControllerConnection;
#endif
ConditionalMember<Config::Bluetooth::server, TextMenuItem> acceptPS3ControllerConnection;
TextMenuItem about;
TextMenuItem exitApp;
StaticArrayList<MenuItem*, STANDARD_ITEMS + MAX_SYSTEM_ITEMS> item;
Expand Down
1 change: 1 addition & 0 deletions EmuFramework/include/emuframework/OutSizeTracker.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <imagine/io/IO.hh>
#include <imagine/io/IOUtils-impl.hh>
#include <optional>

namespace EmuEx
{
Expand Down
1 change: 0 additions & 1 deletion EmuFramework/include/emuframework/VideoImageEffect.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <imagine/gfx/Program.hh>
#include <imagine/gfx/Quads.hh>
#include <imagine/util/enum.hh>
#include <optional>

namespace EmuEx
{
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#include <imagine/config/defs.hh>
#include <imagine/bluetooth/config.hh>
#include <imagine/bluetooth/defs.hh>

#ifdef ENV_NOTE
#define PLATFORM_INFO_STR ENV_NOTE " (" CONFIG_ARCH_STR ")"
Expand Down
Loading

0 comments on commit 42bf495

Please sign in to comment.