Compare commits

..

15 Commits

Author SHA1 Message Date
elasota
032e44d981 Fix some missing dependencies of ReleasePackageInstaller necessary to import resources. 2020-11-30 23:32:50 -05:00
elasota
7961ca3af7 Fixed some more cases where the screen resolution could become desynced during startup. 2020-11-30 19:02:42 -05:00
elasota
6851025147 Preload entire font file if the font file isn't efficiently seekable, which should fix very slow startup times on Android. 2020-11-30 18:43:17 -05:00
elasota
f0b1d6fff9 Add memory buffer stream 2020-11-30 18:42:35 -05:00
elasota
70e0948847 Log initial resolution 2020-11-30 18:42:22 -05:00
elasota
a698286087 Adjust disclaimer 2020-11-30 10:27:01 -05:00
elasota
b75313fd7b Commit resolution changes 2020-11-30 03:50:57 -05:00
elasota
cab862ed8b Fix exit to shell not working 2020-11-30 03:18:09 -05:00
elasota
553e343abe Fix display resolution desynchronizing with auto-position 2020-11-30 02:59:02 -05:00
elasota
0aa36b27a9 Remove Bluetooth and vibrate permissions 2020-11-30 00:24:58 -05:00
elasota
f6185b1c78 Bump version to 1.0.11 2020-11-30 00:24:23 -05:00
elasota
ff29d5b92c Updated disclaimer 2020-11-30 00:11:21 -05:00
elasota
964c9b8858 Reduce load ring images to grayscale 2020-11-28 11:46:07 -05:00
elasota
8a48726b2e Compress cached fonts 2020-11-28 11:45:51 -05:00
elasota
de06669239 Fix read overrun 2020-11-28 11:45:29 -05:00
38 changed files with 388 additions and 122 deletions

View File

@@ -46,6 +46,8 @@ EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "ReleasePackageInstaller", "ReleasePackageInstaller\ReleasePackageInstaller.wixproj", "{D26BD501-28A7-4849-8130-FB5EA0A2B82F}"
ProjectSection(ProjectDependencies) = postProject
{7EFF1E21-C375-45EA-A069-4E2232C8A72B} = {7EFF1E21-C375-45EA-A069-4E2232C8A72B}
{B852D549-4020-4477-8BFB-E199FF78B047} = {B852D549-4020-4477-8BFB-E199FF78B047}
{2FF15659-5C72-48B8-B55B-3C658E4125B5} = {2FF15659-5C72-48B8-B55B-3C658E4125B5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsUnicodeToolShim", "WindowsUnicodeToolShim\WindowsUnicodeToolShim.vcxproj", "{15009625-1120-405E-8BBA-69A16CD6713D}"

View File

@@ -166,6 +166,12 @@ bool GpSystemServices_Win32::IsTextInputEnabled() const
return true;
}
bool GpSystemServices_Win32::AreFontResourcesSeekable() const
{
return true;
}
void GpSystemServices_Win32::SetTouchscreenSimulation(bool isTouchscreenSimulation)
{
m_isTouchscreenSimulation = isTouchscreenSimulation;

View File

@@ -35,6 +35,7 @@ public:
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;
bool AreFontResourcesSeekable() const override;
void SetTouchscreenSimulation(bool isTouchscreenSimulation);

View File

@@ -15,8 +15,8 @@ android {
}
minSdkVersion 16
targetSdkVersion 29
versionCode 6
versionName "1.0.10"
versionCode 7
versionName "1.0.11"
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-16"

View File

@@ -285,6 +285,11 @@ bool GpSystemServices_Android::IsTextInputEnabled() const
return m_textInputEnabled;
}
bool GpSystemServices_Android::AreFontResourcesSeekable() const
{
return false;
}
GpSystemServices_Android *GpSystemServices_Android::GetInstance()
{
return &ms_instance;

View File

@@ -23,6 +23,7 @@ public:
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;
bool AreFontResourcesSeekable() const override;
void FlushTextInputEnabled();

View File

@@ -41,9 +41,13 @@
<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Allow access to Bluetooth devices -->
<!--
<uses-permission android:name="android.permission.BLUETOOTH" />
-->
<!-- Allow access to the vibrator -->
<!--
<uses-permission android:name="android.permission.VIBRATE" />
-->
<!-- if you want to capture audio, uncomment this. -->
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->

View File

@@ -731,7 +731,7 @@ public:
void Run() override;
void Shutdown() override;
void GetDisplayResolution(unsigned int *width, unsigned int *height) override;
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) override;
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
IGpCursor *CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) override;
@@ -886,6 +886,8 @@ private:
uint32_t m_windowHeightPhysical;
uint32_t m_windowWidthVirtual; // Virtual resolution is the resolution reported to the game
uint32_t m_windowHeightVirtual;
uint32_t m_initialWidthVirtual; // Virtual resolution is the resolution reported to the game
uint32_t m_initialHeightVirtual;
float m_pixelScaleX;
float m_pixelScaleY;
bool m_useUpscaleFilter;
@@ -1178,6 +1180,8 @@ GpDisplayDriver_SDL_GL2::GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties
, m_windowHeightPhysical(480)
, m_windowWidthVirtual(640)
, m_windowHeightVirtual(480)
, m_initialWidthVirtual(640)
, m_initialHeightVirtual(480)
, m_pixelScaleX(1.0f)
, m_pixelScaleY(1.0f)
, m_useUpscaleFilter(false)
@@ -1897,6 +1901,9 @@ void GpDisplayDriver_SDL_GL2::Run()
if (!m_gl.LookUpFunctions())
return;
m_initialWidthVirtual = m_windowWidthVirtual;
m_initialHeightVirtual = m_windowHeightVirtual;
for (;;)
{
SDL_Event msg;
@@ -2052,13 +2059,13 @@ void GpDisplayDriver_SDL_GL2::Shutdown()
free(this);
}
void GpDisplayDriver_SDL_GL2::GetDisplayResolution(unsigned int *width, unsigned int *height)
void GpDisplayDriver_SDL_GL2::GetInitialDisplayResolution(unsigned int *width, unsigned int *height)
{
if (width)
*width = m_windowWidthVirtual;
*width = m_initialWidthVirtual;
if (height)
*height = m_windowHeightVirtual;
*height = m_initialHeightVirtual;
}
IGpDisplayDriverSurface *GpDisplayDriver_SDL_GL2::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -11,6 +11,7 @@
#include "MenuManager.h"
#include "IGpDisplayDriver.h"
#include "IGpSystemServices.h"
#include "Vec2i.h"
#include "WindowManager.h"
#include "PLDrivers.h"
@@ -420,11 +421,9 @@ void HandleDepthSwitching (void)
void GetDeviceRect(Rect *rect)
{
unsigned int width;
unsigned int height;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&width, &height);
PortabilityLayer::Vec2i displayResolution = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution();
SetRect(rect, 0, 0, static_cast<short>(width), static_cast<short>(height));
SetRect(rect, 0, 0, static_cast<short>(displayResolution.m_x), static_cast<short>(displayResolution.m_y));
}
Boolean AreWeColorOrGrayscale()

View File

@@ -5,6 +5,7 @@
#include "WindowManager.h"
#include "PLDrivers.h"
#include "PLSysCalls.h"
int gpAppMain();
void gpAppInit();
@@ -30,7 +31,7 @@ void GpAppInterfaceImpl::ApplicationInit()
int GpAppInterfaceImpl::ApplicationMain()
{
return gpAppMain();
return PLSysCalls::MainExitWrapper(gpAppMain);
}
void GpAppInterfaceImpl::PL_IncrementTickCounter(uint32_t count)

View File

@@ -508,8 +508,7 @@ void MoveDialogToTopOfScreen(Dialog *dial)
Window *window = dial->GetWindow();
PortabilityLayer::Vec2i pos = window->GetPosition();
unsigned int height = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &height);
unsigned int height = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
pos.m_y = (height - window->GetDrawSurface()->m_port.GetRect().Height()) / 8;

View File

@@ -11,6 +11,7 @@
#include "Externs.h"
#include "Environ.h"
#include "FontFamily.h"
#include "FontManager.h"
#include "GpApplicationName.h"
#include "GpRenderedFontMetrics.h"
#include "IGpMutex.h"
@@ -391,6 +392,8 @@ void StepLoadScreenRing()
void CreateLoadScreenWindow(int phase)
{
FlushResolutionChange();
if (loadScreenRingSurface)
{
DisposeGWorld(loadScreenRingSurface);
@@ -420,7 +423,7 @@ void CreateLoadScreenWindow(int phase)
loadRingRect.right *= 2;
loadRingRect.bottom *= 2;
CreateOffScreenGWorld(&loadRingSurface, &loadRingRect);
loadRingSurface->DrawPicture(loadRingImageH, loadRingRect);
loadRingSurface->DrawPicture(loadRingImageH, loadRingRect, false);
int32_t lsX = (thisMac.fullScreen.Width() - kLoadScreenWidth) / 2;
int32_t lsY = (thisMac.fullScreen.Height() - kLoadScreenHeight) / 2;
@@ -473,7 +476,7 @@ void CreateLoadScreenWindow(int phase)
DrawSurface *loadRingSurface = nullptr;
Rect loadRingRect = loadRingImage->GetRect();
CreateOffScreenGWorld(&loadRingSurface, &loadRingRect);
loadRingSurface->DrawPicture(loadRingImageH, loadRingRect);
loadRingSurface->DrawPicture(loadRingImageH, loadRingRect, false);
int32_t lsX = (thisMac.fullScreen.Width() - kLoadScreenWidth) / 2;
int32_t lsY = (thisMac.fullScreen.Height() - kLoadScreenHeight) / 2;
@@ -539,7 +542,7 @@ void StepLoadScreen(int steps, bool insertDelay)
const Rect loadScreenProgressBarFillRect = loadScreenProgressBarRect.Inset(1, 1);
int loadScreenMax = 42;
int loadScreenMax = 43;
loadScreenProgress = loadScreenProgress + steps;
if (loadScreenProgress > loadScreenMax)
loadScreenProgress = loadScreenMax;
@@ -663,6 +666,7 @@ void PreloadFonts()
{ FontCategory_Application, 9, PortabilityLayer::FontFamilyFlag_None, true },
{ FontCategory_Application, 12, PortabilityLayer::FontFamilyFlag_Bold, true },
{ FontCategory_Application, 14, PortabilityLayer::FontFamilyFlag_Bold, true },
{ FontCategory_Application, 14, PortabilityLayer::FontFamilyFlag_None, true },
{ FontCategory_Application, 40, PortabilityLayer::FontFamilyFlag_None, true },
{ FontCategory_Handwriting, 24, PortabilityLayer::FontFamilyFlag_None, true },
{ FontCategory_Handwriting, 48, PortabilityLayer::FontFamilyFlag_None, true },
@@ -671,7 +675,6 @@ void PreloadFonts()
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
const int numFontSpecs = sizeof(specs) / sizeof(specs[0]);
int queuedSpecs = 0;
@@ -713,6 +716,8 @@ void PreloadFonts()
StepLoadScreenRing();
Delay(1, nullptr);
}
PortabilityLayer::FontManager::GetInstance()->PurgeCache();
}
struct PreloadAATableSpec
@@ -902,32 +907,37 @@ void ShowInitialLaunchDisclaimer()
{
const char *disclaimerLines[] =
{
GP_APPLICATION_NAME " is a port of John Calhoun's Glider PRO, based",
"on the 2016 release of the game's source code and assets.",
GP_APPLICATION_NAME " is a port of John Calhoun\xd5s Glider PRO, based",
"on the 2016 release of the game\xd5s source code and assets.",
"",
"Glider PRO, a sequel to the original Glider, was released",
"in 1994 for the Apple Macintosh, and is widely recognized",
"as one of the most iconic Macintosh-exclusive games.",
"Glider PRO, a sequel to the original Glider, was released in 1994",
"for the Apple Macintosh, and is widely recognized as one of",
"of the most iconic Macintosh-exclusive games of the 1990\xd5s.",
"",
"I hope that by adapting it to be playable on modern systems, more",
"people can appreciate this important piece of video game history.",
"",
"This software is an adaptation and contains some differences",
"from the original. Some fonts, graphics, and sounds have been",
"substituted or removed for copyright reasons. This software",
"is not developed by, maintained by, supported by, endorsed by,",
"or otherwise associated with the authors or publishers of Glider PRO."
"This software is an adaptation that attempts to restore the original work",
"as accurately as possible, but some fonts, graphics, and sounds have been",
"substituted or removed for copyright reasons, and some user interface",
"components have been added or changed to improve compatibility.",
"",
"This software is not developed by, maintained by, supported by, endorsed by,",
"or otherwise associated with the authors or publishers of Glider PRO.",
"Any references to Glider PRO in this software are for historical accuracy",
"and should not be interpreted as implying any form of endorsement."
};
const size_t numLines = sizeof(disclaimerLines) / sizeof(disclaimerLines[0]);
PortabilityLayer::RenderedFont *rfont = GetApplicationFont(18, 0, true);
PortabilityLayer::RenderedFont *rfont = GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_None, true);
PortabilityLayer::RenderedFont *buttonFont = GetApplicationFont(18, PortabilityLayer::FontFamilyFlag_None, true);
const int kButtonSpacing = 16;
const int kButtonHeight = 32;
const PLPasStr buttonText = PLDrivers::GetSystemServices()->IsTouchscreen() ? PLPasStr(PSTR("Tap to Continue...")) : PLPasStr(PSTR("Click to Continue..."));
const int32_t buttonTextWidth = rfont->MeasureString(buttonText.UChars(), buttonText.Length());
const int32_t buttonTextWidth = buttonFont->MeasureString(buttonText.UChars(), buttonText.Length());
const int32_t buttonWidth = buttonTextWidth + 16;
const int32_t linegap = rfont->GetMetrics().m_linegap;
@@ -1021,7 +1031,7 @@ void ShowInitialLaunchDisclaimer()
surface->FillRect(buttonRect, whiteColor);
surface->FillRect(buttonRect.Inset(borderThickness, borderThickness), backgroundColor);
surface->DrawString(textPoint, buttonText, whiteColor, rfont);
surface->DrawString(textPoint, buttonText, whiteColor, buttonFont);
Delay(1, nullptr);
}
@@ -1131,9 +1141,12 @@ int gpAppMain()
{
WriteOutPrefs();
FlushResolutionChange();
ShowInitialLaunchDisclaimer();
}
FlushResolutionChange();
OpenMainWindow();
if (isDoColorFade)

View File

@@ -169,8 +169,7 @@ static void DrawMainMenuControl(DrawSurface *surface, MainMenuUIState::ControlID
void StartScrollForPage()
{
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
DismissMainMenuUI();
@@ -263,8 +262,7 @@ void StartMainMenuUI()
static void DismissMainMenuUIPage()
{
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
@@ -293,8 +291,7 @@ void TickMainMenuUI()
{
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
mainMenu.m_scrollInStep -= MainMenuUIState::kControlScrollInDecay;
mainMenu.m_scrollInOffset -= (mainMenu.m_scrollInStep >> MainMenuUIState::kControlScrollInDecayFalloffBits);
@@ -328,8 +325,7 @@ void HandleMainMenuUIResolutionChange()
{
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
for (int i = 0; i < MainMenuUIState::Control_Count; i++)
{

View File

@@ -1,6 +1,7 @@
#include "CombinedTimestamp.h"
#include "DeflateCodec.h"
#include "Environ.h"
#include "FontFamily.h"
#include "GpBuildVersion.h"
#include "GpIOStream.h"
#include "GpFileCreationDisposition.h"
@@ -12,10 +13,10 @@
#include "GpApplicationName.h"
#include "GpRenderedFontMetrics.h"
#include "ResolveCachingColor.h"
#include "ZipFile.h"
#include "Vec2i.h"
#include "WindowDef.h"
#include "WindowManager.h"
#include "FontFamily.h"
#include "ZipFile.h"
#include "PLCore.h"
#include "PLDrivers.h"
@@ -140,9 +141,9 @@ static void InitSourceExportWindow(SourceExportState *state)
// We have to use this instead of thisMac.fullScreen because the resolution may change during the sleep call, especially on Android displays where
// the status bar dismissal causes a major change in the virtual resolution.
unsigned int displayWidth = 0;
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&displayWidth, &displayHeight);
PortabilityLayer::Vec2i displaySize = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution();
unsigned int displayWidth = displaySize.m_x;
unsigned int displayHeight = displaySize.m_y;
int32_t lsX = (static_cast<int32_t>(displayWidth) - kLoadScreenWidth) / 2;
int32_t lsY = (static_cast<int32_t>(displayHeight) - kLoadScreenHeight) / 2;

View File

@@ -11,6 +11,7 @@
#include "PLPasStr.h"
#include "PLResources.h"
#include "PLSound.h"
#include "PLSysCalls.h"
#include "PLTimeTaggedVOSEvent.h"
#include "QDPixMap.h"
#include "BitmapImage.h"
@@ -114,9 +115,7 @@ void RedAlert (short errorNumber)
// CenterAlert(rDeathAlertID);
dummyInt = PortabilityLayer::DialogManager::GetInstance()->DisplayAlert(rDeathAlertID, &substitutions);
//ExitToShell();
PL_NotYetImplemented_TODO("Exit");
PLSysCalls::Exit(-1);
}
//-------------------------------------------------------------- CreateOffScreenBitMap

View File

@@ -2,8 +2,8 @@
#define GP_BUILD_VERSION_MAJOR 1
#define GP_BUILD_VERSION_MINOR 0
#define GP_BUILD_VERSION_UPDATE 10
#define GP_BUILD_VERSION_UPDATE 11
#define GP_APPLICATION_VERSION_STRING "1.0.10"
#define GP_APPLICATION_VERSION_STRING "1.0.11"
#define GP_APPLICATION_COPYRIGHT_STRING "2019-2020 Eric Lasota"
#define GP_APPLICATION_WEBSITE_STRING "https://github.com/elasota/Aerofoil"

View File

@@ -31,7 +31,8 @@ struct IGpDisplayDriver
virtual void Run() = 0;
virtual void Shutdown() = 0;
virtual void GetDisplayResolution(unsigned int *width, unsigned int *height) = 0;
// Returns the initial resolution before any display resolution events are posted
virtual void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) = 0;
virtual IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) = 0;
virtual void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) = 0;

View File

@@ -33,4 +33,5 @@ public:
virtual unsigned int GetCPUCount() const = 0;
virtual void SetTextInputEnabled(bool isEnabled) = 0;
virtual bool IsTextInputEnabled() const = 0;
virtual bool AreFontResourcesSeekable() const = 0;
};

View File

@@ -1143,6 +1143,9 @@ void GpDisplayDriverD3D11::Run()
LARGE_INTEGER lastTimestamp;
memset(&lastTimestamp, 0, sizeof(lastTimestamp));
m_initialWidth = m_windowWidthVirtual;
m_initialHeight = m_windowHeightVirtual;
MSG msg;
for (;;)
{
@@ -1242,12 +1245,12 @@ void GpDisplayDriverD3D11::Shutdown()
free(this);
}
void GpDisplayDriverD3D11::GetDisplayResolution(unsigned int *width, unsigned int *height)
void GpDisplayDriverD3D11::GetInitialDisplayResolution(unsigned int *width, unsigned int *height)
{
if (width)
*width = m_windowWidthVirtual;
*width = m_initialWidth;
if (height)
*height = m_windowHeightVirtual;
*height = m_initialHeight;
}
IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext)
@@ -1516,6 +1519,8 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
, m_windowHeightPhysical(480)
, m_windowWidthVirtual(640)
, m_windowHeightVirtual(480)
, m_initialWidth(640)
, m_initialHeight(480)
, m_pixelScaleX(1.0f)
, m_pixelScaleY(1.0f)
, m_vosFiber(nullptr)

View File

@@ -39,7 +39,7 @@ public:
void Run() override;
void Shutdown() override;
void GetDisplayResolution(unsigned int *width, unsigned int *height) override;
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) override;
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
@@ -178,6 +178,9 @@ private:
float m_pixelScaleX;
float m_pixelScaleY;
unsigned int m_initialWidth;
unsigned int m_initialHeight;
IGpCursor_Win32 *m_activeCursor;
IGpCursor_Win32 *m_pendingCursor;
EGpStandardCursor_t m_currentStandardCursor;

View File

@@ -64,6 +64,7 @@ bool PortabilityLayer::DeflateCodec::DecompressStream(GpIOStream *stream, size_t
zstream.avail_in = sizeToRead;
zstream.next_in = buffer;
inSize -= sizeToRead;
}
int result = inflate(&zstream, Z_NO_FLUSH);

View File

@@ -1,6 +1,7 @@
#include "DialogManager.h"
#include "IconLoader.h"
#include "IGpDisplayDriver.h"
#include "IGpLogDriver.h"
#include "IGpSystemServices.h"
#include "ResourceManager.h"
#include "QDPixMap.h"
@@ -830,8 +831,11 @@ namespace PortabilityLayer
void DialogManagerImpl::PositionWindow(Window *window, const Rect &rect) const
{
unsigned int displayWidth, displayHeight;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&displayWidth, &displayHeight);
IGpLogDriver *logger = PLDrivers::GetLogDriver();
Vec2i displayResolution = WindowManager::GetInstance()->GetDisplayResolution();
unsigned int displayWidth = displayResolution.m_x;
unsigned int displayHeight = displayResolution.m_y;
const unsigned int halfDisplayHeight = displayHeight / 2;
const unsigned int quarterDisplayWidth = displayHeight / 4;
@@ -840,6 +844,9 @@ namespace PortabilityLayer
const uint16_t dialogWidth = rect.Width();
const uint16_t dialogHeight = rect.Height();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Auto positioning window size %ix%i on display size %ix%i", static_cast<int>(dialogWidth), static_cast<int>(dialogHeight), static_cast<int>(displayWidth), static_cast<int>(displayHeight));
Vec2i newPosition;
newPosition.m_x = (static_cast<int32_t>(displayWidth) - static_cast<int32_t>(dialogWidth)) / 2;
@@ -860,6 +867,9 @@ namespace PortabilityLayer
else
newPosition.m_y = (static_cast<int32_t>(displayHeight) - static_cast<int32_t>(dialogHeight)) / 2;
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Positioned at %i,%i", static_cast<int>(newPosition.m_x), static_cast<int>(newPosition.m_y));
window->SetPosition(newPosition);
}

View File

@@ -3,7 +3,10 @@
#include "IGpFileSystem.h"
#include "IGpFontHandler.h"
#include "IGpFont.h"
#include "IGpSystemServices.h"
#include "MemReaderStream.h"
#include "MemoryManager.h"
#include "PLDrivers.h"
#include <stdlib.h>
@@ -11,11 +14,82 @@
namespace PortabilityLayer
{
FontFamily::FontSpec::FontSpec()
: m_fontPath(nullptr)
, m_font(nullptr)
, m_hacks(FontHacks_None)
, m_isRegistered(false)
{
}
void FontFamily::AddFont(int flags, const char *path, FontHacks fontHacks)
{
GpIOStream *sysFontStream = PLDrivers::GetFileSystem()->OpenFile(PortabilityLayer::VirtualDirectories::kFonts, path, false, GpFileCreationDispositions::kOpenExisting);
m_fontSpecs[flags].m_fontPath = path;
m_fontSpecs[flags].m_hacks = fontHacks;
m_fontSpecs[flags].m_isRegistered = true;
if (!m_fontSpecs[0].m_isRegistered)
m_defaultVariation = flags;
}
void FontFamily::SetDefaultVariation(int defaultVariation)
{
if (m_fontSpecs[defaultVariation].m_isRegistered)
m_defaultVariation = defaultVariation;
}
int FontFamily::GetVariationForFlags(int variation) const
{
if (m_fontSpecs[variation].m_isRegistered)
return variation;
if (m_fontSpecs[0].m_isRegistered)
return 0;
return m_defaultVariation;
}
IGpFont *FontFamily::GetFontForVariation(int variation)
{
FontSpec &spec = m_fontSpecs[variation];
if (spec.m_font)
return spec.m_font;
GpIOStream *sysFontStream = PLDrivers::GetFileSystem()->OpenFile(PortabilityLayer::VirtualDirectories::kFonts, spec.m_fontPath, false, GpFileCreationDispositions::kOpenExisting);
if (!sysFontStream)
return;
return nullptr;
if (!PLDrivers::GetSystemServices()->AreFontResourcesSeekable())
{
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
size_t fontSize = sysFontStream->Size();
void *buffer = mm->Alloc(fontSize);
if (!buffer)
{
sysFontStream->Close();
return nullptr;
}
MemBufferReaderStream *bufferStream = MemBufferReaderStream::Create(buffer, fontSize);
if (!bufferStream)
{
mm->Release(buffer);
sysFontStream->Close();
return nullptr;
}
if (sysFontStream->Read(buffer, fontSize) != fontSize)
{
mm->Release(buffer);
sysFontStream->Close();
return nullptr;
}
sysFontStream->Close();
sysFontStream = bufferStream;
}
IGpFontHandler *fontHandler = PLDrivers::GetFontHandler();
@@ -25,40 +99,16 @@ namespace PortabilityLayer
sysFontStream->Close();
if (!font)
return;
return nullptr;
m_fonts[flags] = font;
m_hacks[flags] = fontHacks;
spec.m_font = font;
if (m_fonts[0] == nullptr)
m_defaultVariation = flags;
}
void FontFamily::SetDefaultVariation(int defaultVariation)
{
if (m_fonts[defaultVariation])
m_defaultVariation = defaultVariation;
}
int FontFamily::GetVariationForFlags(int variation) const
{
if (m_fonts[variation])
return variation;
if (m_fonts[0])
return 0;
return m_defaultVariation;
}
IGpFont *FontFamily::GetFontForVariation(int variation) const
{
return m_fonts[variation];
return font;
}
PortabilityLayer::FontHacks FontFamily::GetHacksForVariation(int variation) const
{
return m_hacks[variation];
return m_fontSpecs[variation].m_hacks;
}
int FontFamily::GetCacheID() const
@@ -66,6 +116,18 @@ namespace PortabilityLayer
return m_cacheID;
}
void FontFamily::PurgeCache()
{
for (unsigned int i = 0; i < kNumVariations; i++)
{
if (IGpFont *font = m_fontSpecs[i].m_font)
{
font->Destroy();
m_fontSpecs[i].m_font = nullptr;
}
}
}
FontFamily *FontFamily::Create(int cacheID)
{
void *storage = malloc(sizeof(FontFamily));
@@ -85,19 +147,10 @@ namespace PortabilityLayer
: m_defaultVariation(0)
, m_cacheID(cacheID)
{
for (unsigned int i = 0; i < kNumVariations; i++)
{
m_fonts[i] = nullptr;
m_hacks[i] = FontHacks_None;
}
}
FontFamily::~FontFamily()
{
for (unsigned int i = 0; i < kNumVariations; i++)
{
if (IGpFont *font = m_fonts[i])
font->Destroy();
}
PurgeCache();
}
}

View File

@@ -26,17 +26,28 @@ namespace PortabilityLayer
void SetDefaultVariation(int defaultVariation);
int GetVariationForFlags(int variation) const;
IGpFont *GetFontForVariation(int variation) const;
IGpFont *GetFontForVariation(int variation);
FontHacks GetHacksForVariation(int variation) const;
int GetCacheID() const;
void PurgeCache();
static FontFamily *Create(int cacheID);
void Destroy();
private:
FontHacks m_hacks[kNumVariations];
IGpFont *m_fonts[kNumVariations];
struct FontSpec
{
FontSpec();
IGpFont *m_font;
FontHacks m_hacks;
const char *m_fontPath;
bool m_isRegistered;
};
FontSpec m_fontSpecs[kNumVariations];
uint8_t m_defaultVariation;
int m_cacheID;

View File

@@ -35,6 +35,8 @@ namespace PortabilityLayer
RenderedFont *LoadCachedRenderedFont(int cacheID, int size, bool aa, int flags) const override;
void SaveCachedRenderedFont(const RenderedFont *rfont, int cacheID, int size, bool aa, int flags) const override;
void PurgeCache() override;
static FontManagerImpl *GetInstance();
private:
@@ -43,7 +45,7 @@ namespace PortabilityLayer
static const int kApplicationFontCacheID = 2;
static const int kHandwritingFontCacheID = 3;
static const int kMonospaceFontCacheID = 4;
static const int kFontCacheVersion = 1;
static const int kFontCacheVersion = 2;
static const int kFontCacheNameSize = 64;
struct CachedRenderedFont
@@ -264,6 +266,14 @@ namespace PortabilityLayer
stream->Close();
}
void FontManagerImpl::PurgeCache()
{
m_systemFont->PurgeCache();
m_applicationFont->PurgeCache();
m_handwritingFont->PurgeCache();
m_monospaceFont->PurgeCache();
}
FontManagerImpl *FontManagerImpl::GetInstance()
{
return &ms_instance;

View File

@@ -26,6 +26,8 @@ namespace PortabilityLayer
virtual RenderedFont *LoadCachedRenderedFont(int cacheID, int size, bool aa, int flags) const = 0;
virtual void SaveCachedRenderedFont(const RenderedFont *rfont, int cacheID, int size, bool aa, int flags) const = 0;
virtual void PurgeCache() = 0;
static FontManager *GetInstance();
};
}

View File

@@ -5,6 +5,7 @@
#include "GpIOStream.h"
#include "IGpFontRenderedGlyph.h"
#include "MacRomanConversion.h"
#include "MemoryManager.h"
#include "RenderedFont.h"
#include "GpRenderedFontMetrics.h"
#include "GpRenderedGlyphMetrics.h"
@@ -12,6 +13,7 @@
#include "PLBigEndian.h"
#include "PLDrivers.h"
#include "PLPasStr.h"
#include "DeflateCodec.h"
#include <assert.h>
#include <string.h>
@@ -42,7 +44,8 @@ namespace PortabilityLayer
struct CacheHeader
{
BEUInt32_t m_cacheVersion;
BEUInt32_t m_glyphDataSize;
BEUInt32_t m_glyphDataUncompressedSize;
BEUInt32_t m_glyphDataCompressedSize;
BEUInt32_t m_sizeSize;
BEUInt32_t m_isAA;
@@ -53,7 +56,7 @@ namespace PortabilityLayer
RenderedFontImpl(void *data, size_t dataSize, bool aa);
~RenderedFontImpl();
bool LoadInternal(GpIOStream *stream);
bool LoadInternal(GpIOStream *stream, size_t compressedDataSize);
size_t m_dataOffsets[256];
GpRenderedGlyphMetrics m_glyphMetrics[256];
@@ -143,11 +146,11 @@ namespace PortabilityLayer
if (header.m_sizeSize != sizeof(size_t))
return nullptr;
RenderedFontImpl *rfont = RenderedFontImpl::Create(header.m_glyphDataSize, header.m_isAA != 0);
RenderedFontImpl *rfont = RenderedFontImpl::Create(header.m_glyphDataUncompressedSize, header.m_isAA != 0);
if (!rfont)
return nullptr;
if (!rfont->LoadInternal(stream))
if (!rfont->LoadInternal(stream, header.m_glyphDataCompressedSize))
{
rfont->Destroy();
return nullptr;
@@ -160,16 +163,32 @@ namespace PortabilityLayer
{
CacheHeader header;
header.m_cacheVersion = kRFontCacheVersion;
header.m_glyphDataSize = static_cast<uint32_t>(this->m_dataSize);
header.m_glyphDataUncompressedSize = static_cast<uint32_t>(this->m_dataSize);
header.m_glyphDataCompressedSize = 0;
header.m_isAA = m_isAntiAliased;
header.m_sizeSize = sizeof(size_t);
GpUFilePos_t headerPos = stream->Tell();
if (stream->Write(&header, sizeof(header)) != sizeof(header))
return false;
if (stream->Write(m_data, m_dataSize) != m_dataSize)
DeflateContext *deflateContext = DeflateContext::Create(stream, 9);
if (!deflateContext)
return false;
GpUFilePos_t dataStartPos = stream->Tell();
if (!deflateContext->Append(m_data, m_dataSize) || !deflateContext->Flush())
{
deflateContext->Destroy();
return false;
}
deflateContext->Destroy();
GpUFilePos_t dataEndPos = stream->Tell();
if (stream->Write(m_dataOffsets, sizeof(m_dataOffsets)) != sizeof(m_dataOffsets))
return false;
@@ -179,6 +198,18 @@ namespace PortabilityLayer
if (stream->Write(&m_fontMetrics, sizeof(m_fontMetrics)) != sizeof(m_fontMetrics))
return false;
GpUFilePos_t endPos = stream->Tell();
if (!stream->SeekStart(headerPos))
return false;
header.m_glyphDataCompressedSize = dataEndPos - dataStartPos;
if (stream->Write(&header, sizeof(header)) != sizeof(header))
return false;
if (!stream->SeekStart(headerPos))
return false;
return true;
}
@@ -215,9 +246,11 @@ namespace PortabilityLayer
{
}
bool RenderedFontImpl::LoadInternal(GpIOStream *stream)
bool RenderedFontImpl::LoadInternal(GpIOStream *stream, size_t compressedDataSize)
{
if (stream->Read(m_data, m_dataSize) != m_dataSize)
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
if (!DeflateCodec::DecompressStream(stream, compressedDataSize, m_data, m_dataSize))
return false;
if (stream->Read(m_dataOffsets, sizeof(m_dataOffsets)) != sizeof(m_dataOffsets))

View File

@@ -10,7 +10,7 @@ namespace PortabilityLayer
HostSuspendCallID_Delay,
HostSuspendCallID_CallOnVOSThread,
HostSuspendCallID_ForceSyncFrame
HostSuspendCallID_ForceSyncFrame,
};
}

View File

@@ -1,4 +1,5 @@
#include "MemReaderStream.h"
#include "MemReaderStream.h"
#include "MemoryManager.h"
#include <string.h>
@@ -9,6 +10,10 @@ namespace PortabilityLayer
, m_size(size)
, m_loc(0)
{
}
MemReaderStream::~MemReaderStream()
{
}
size_t MemReaderStream::Read(void *bytesOut, size_t size)
@@ -110,5 +115,33 @@ namespace PortabilityLayer
void MemReaderStream::Flush()
{
}
}
MemBufferReaderStream::~MemBufferReaderStream()
{
if (m_buffer)
MemoryManager::GetInstance()->Release(m_buffer);
}
MemBufferReaderStream *MemBufferReaderStream::Create(void *buffer, size_t size)
{
void *storage = MemoryManager::GetInstance()->Alloc(sizeof(MemBufferReaderStream));
if (!storage)
return nullptr;
return new (storage) MemBufferReaderStream(buffer, size);
}
void MemBufferReaderStream::Close()
{
this->~MemBufferReaderStream();
MemoryManager::GetInstance()->Release(this);
}
MemBufferReaderStream::MemBufferReaderStream(void *buffer, size_t size)
: MemReaderStream(buffer, size)
, m_buffer(buffer)
{
}
}

View File

@@ -7,10 +7,11 @@
namespace PortabilityLayer
{
class MemReaderStream final : public GpIOStream
class MemReaderStream : public GpIOStream
{
public:
MemReaderStream(const void *memStream, size_t size);
MemReaderStream(const void *memStream, size_t size);
virtual ~MemReaderStream();
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
@@ -32,6 +33,22 @@ namespace PortabilityLayer
const uint8_t *m_bytes;
size_t m_size;
size_t m_loc;
};
class MemBufferReaderStream final : public MemReaderStream
{
public:
~MemBufferReaderStream() override;
static MemBufferReaderStream *Create(void *buffer, size_t size);
void Close() override;
private:
MemBufferReaderStream() GP_DELETED;
MemBufferReaderStream(void *buffer, size_t size);
void *m_buffer;
};
}

View File

@@ -14,6 +14,7 @@
#include "RGBAColor.h"
#include "ResolveCachingColor.h"
#include "Vec2i.h"
#include "WindowManager.h"
#include "PLBigEndian.h"
#include "PLCore.h"
@@ -840,8 +841,7 @@ namespace PortabilityLayer
m_haveIcon = true;
}
unsigned int width;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&width, nullptr);
unsigned int width = WindowManager::GetInstance()->GetDisplayResolution().m_x;
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
@@ -1036,8 +1036,7 @@ namespace PortabilityLayer
if (m_isTouchScreen)
{
unsigned int displayHeight = 0;
displayDriver->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
y = static_cast<int32_t>(displayHeight) - kTouchscreenMenuBarHeight;
}
@@ -1307,8 +1306,7 @@ namespace PortabilityLayer
{
if (m_isTouchScreen)
{
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
return y >= (static_cast<int32_t>(displayHeight - kTouchscreenMenuBarHeight)) && y < static_cast<int32_t>(displayHeight);
}
else
@@ -1388,8 +1386,7 @@ namespace PortabilityLayer
{
int32_t popupBottom = static_cast<int32_t>(m_popupPosition.m_y + menu->layoutFinalHeight);
unsigned int displayHeight = 0;
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
if (popupBottom > static_cast<int32_t>(displayHeight))
m_popupPosition.m_y -= popupBottom - static_cast<int32_t>(displayHeight);
}

View File

@@ -677,6 +677,7 @@ void PL_Init()
PortabilityLayer::DisplayDeviceManager::GetInstance()->Init();
PortabilityLayer::QDManager::GetInstance()->Init();
PortabilityLayer::MenuManager::GetInstance()->Init();
PortabilityLayer::WindowManager::GetInstance()->Init();
PLDrivers::GetFileSystem()->SetMainThreadRelay(PLMainThreadRelay::GetInstance());
PLDrivers::GetFileSystem()->SetDelayCallback(PLSysCalls::Sleep);

View File

@@ -16,6 +16,9 @@
#include "PLDrivers.h"
#include <assert.h>
#include <setjmp.h>
static void TranslateMouseInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpMouseInputEvent &vosEvent = vosEventBase.m_event.m_mouseInputEvent;
@@ -198,4 +201,24 @@ namespace PLSysCalls
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_CallOnVOSThread, args, nullptr);
}
static jmp_buf gs_mainExitWrapper;
static int gs_exitCode = 0;
void Exit(int exitCode)
{
gs_exitCode = exitCode;
longjmp(gs_mainExitWrapper, 1);
}
int MainExitWrapper(int (*mainFunc)())
{
if (!setjmp(gs_mainExitWrapper))
{
int returnCode = mainFunc();
return returnCode;
}
else
return gs_exitCode;
}
}

View File

@@ -9,4 +9,7 @@ namespace PLSysCalls
void Sleep(uint32_t ticks);
void ForceSyncFrame();
void RunOnVOSThread(void(*callback)(void *context), void *context);
void Exit(int exitCode);
int MainExitWrapper(int (*mainFunc)());
}

View File

@@ -171,6 +171,8 @@ namespace PortabilityLayer
WindowManagerImpl();
~WindowManagerImpl();
void Init() override;
Window *CreateWindow(const WindowDef &windowDef) override;
void ResizeWindow(Window *window, int width, int height) override;
void MoveWindow(Window *window, int x, int y) override;
@@ -198,6 +200,8 @@ namespace PortabilityLayer
void HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) override;
Vec2i GetDisplayResolution() const override;
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) override;
Window *GetPutInFrontSentinel() const override;
@@ -229,6 +233,8 @@ namespace PortabilityLayer
DrawSurface m_resizeInProgressVerticalBar;
bool m_isResizeInProgress;
Vec2i m_displayResolution;
static WindowManagerImpl ms_instance;
static uint8_t ms_putInFrontSentinel;
@@ -1011,8 +1017,6 @@ namespace PortabilityLayer
return m_effects;
}
WindowManagerImpl::WindowManagerImpl()
: m_windowStackTop(nullptr)
, m_windowStackBottom(nullptr)
@@ -1025,6 +1029,7 @@ namespace PortabilityLayer
, m_flickerZoneSize(0)
, m_flickerBasisCoordinateDistance(0)
, m_flickerChromeDistanceOffset(0)
, m_displayResolution(0, 0)
{
}
@@ -1032,6 +1037,19 @@ namespace PortabilityLayer
{
}
void WindowManagerImpl::Init()
{
unsigned int displayWidth, displayHeight;
PLDrivers::GetDisplayDriver()->GetInitialDisplayResolution(&displayWidth, &displayHeight);
m_displayResolution = Vec2i(displayWidth, displayHeight);
IGpLogDriver *logger = PLDrivers::GetLogDriver();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "WindowManagerImpl: Initialized at resolution %ix%i", static_cast<int>(displayWidth), static_cast<int>(displayHeight));
}
Window *WindowManagerImpl::CreateWindow(const WindowDef &windowDef)
{
void *windowMem = MemoryManager::GetInstance()->Alloc(sizeof(WindowImpl));
@@ -1526,6 +1544,13 @@ namespace PortabilityLayer
window->SetPosition(Vec2i(newX, newY));
}
m_displayResolution = Vec2i(newWidth, newHeight);
}
Vec2i WindowManagerImpl::GetDisplayResolution() const
{
return m_displayResolution;
}
void WindowManagerImpl::SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b)

View File

@@ -22,6 +22,7 @@ namespace PortabilityLayer
class WindowManager
{
public:
virtual void Init() = 0;
virtual Window *GetPutInFrontSentinel() const = 0;
virtual Window *CreateWindow(const WindowDef &windowDef) = 0;
virtual void ResizeWindow(Window *window, int width, int height) = 0;
@@ -52,6 +53,8 @@ namespace PortabilityLayer
virtual void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) = 0;
virtual Vec2i GetDisplayResolution() const = 0;
static WindowManager *GetInstance();
};
}