Lots of Android fixes and stubs. Increase SDL log level on Android. Add GL context loss handling.

This commit is contained in:
elasota
2020-10-20 23:43:02 -04:00
parent f26f631ae2
commit 23b69cf0ee
32 changed files with 609 additions and 173 deletions

View File

@@ -1,18 +1,18 @@
#pragma once
#ifndef __PL_BINHEX4_H__
#pragma once
#ifndef __PL_BINHEX4_H__
#define __PL_BINHEX4_H__
class GpIOStream;
namespace PortabilityLayer
{
class MacFileMem;
namespace BinHex4
{
MacFileMem *LoadHQX(GpIOStream *stream);
};
}
#endif
class GpIOStream;
namespace PortabilityLayer
{
class MacFileMem;
namespace BinHex4
{
MacFileMem *LoadHQX(GpIOStream *stream);
};
}
#endif

View File

@@ -37,6 +37,7 @@ struct IGpDisplayDriver;
class GpAppInterface
{
public:
virtual void ApplicationInit() = 0;
virtual int ApplicationMain() = 0;
virtual void PL_IncrementTickCounter(uint32_t count) = 0;
virtual void PL_Render(IGpDisplayDriver *displayDriver) = 0;

View File

@@ -6,6 +6,7 @@
#include <stdint.h>
class GpIOStream;
struct IGpThreadRelay;
namespace PortabilityLayer
{
@@ -31,6 +32,8 @@ namespace PortabilityLayer
GpIOStream *OpenFile(VirtualDirectory_t virtualDirectory, const char *path, bool writeAccess, GpFileCreationDisposition_t createDisposition);
virtual void SetMainThreadRelay(IGpThreadRelay *relay) = 0;
private:
static HostFileSystem *ms_instance;
};

View File

@@ -13,6 +13,6 @@ namespace PortabilityLayer
size_t m_size;
void *m_pointer;
const void *m_constPointer;
void (*m_functionPtr)(const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
void (*m_functionPtr)(void *context);
};
}

View File

@@ -1,17 +1,17 @@
#pragma once
#ifndef __PL_HOST_API_CALL_ID_H__
#define __PL_HOST_API_CALL_ID_H__
namespace PortabilityLayer
{
enum HostSuspendCallID
{
HostSuspendCallID_Unknown,
HostSuspendCallID_Delay,
#pragma once
#ifndef __PL_HOST_API_CALL_ID_H__
#define __PL_HOST_API_CALL_ID_H__
namespace PortabilityLayer
{
enum HostSuspendCallID
{
HostSuspendCallID_Unknown,
HostSuspendCallID_Delay,
HostSuspendCallID_CallOnVOSThread,
HostSuspendCallID_ForceSyncFrame
};
}
#endif
HostSuspendCallID_ForceSyncFrame
};
}
#endif

View File

@@ -159,6 +159,9 @@ namespace PortabilityLayer
void RenderFrame(IGpDisplayDriver *displayDriver) override;
void SetMenuTouchScreenStyle(bool isTouchScreen) override;
bool IsMenuTouchScreenStyle() const override;
static MenuManagerImpl *GetInstance();
private:
@@ -199,13 +202,18 @@ namespace PortabilityLayer
void ProcessMouseMoveToMenuBar(const Vec2i &point);
void ProcessMouseMoveToMenu(const Vec2i &point);
bool IsYInMenuBarRange(int32_t y) const;
static bool ItemIsSeparator(const Menu &menu, const MenuItem &item);
static const unsigned int kIconResID = 128;
static const unsigned int kMenuFontSize = 12;
static const unsigned int kTouchScreenMenuFontSize = 24;
static const unsigned int kMenuBarIconYOffset = 2;
static const unsigned int kMenuBarTextYOffset = 14;
static const unsigned int kTouchScreenMenuBarTextYOffset = 26;
static const unsigned int kMenuBarHeight = 20;
static const unsigned int kTouchscreenMenuBarHeight = 38;
static const unsigned int kMenuBarItemPadding = 6;
static const unsigned int kMenuBarInitialPadding = 16;
@@ -223,6 +231,7 @@ namespace PortabilityLayer
static const unsigned int kMenuItemLeftPadding = 16 + 2 + 2; // 2 for left border, 16 for icon, 2 for spacing
static const int kMenuFontFlags = PortabilityLayer::FontFamilyFlag_Bold;
static const int kTouchScreenMenuFontFlags = PortabilityLayer::FontFamilyFlag_None;
DrawSurface *m_menuBarGraf;
@@ -231,6 +240,7 @@ namespace PortabilityLayer
bool m_haveMenuBarLayout;
bool m_haveIcon;
bool m_menuBarVisible;
bool m_isTouchScreen;
uint8_t m_iconColors[16 * 16];
uint8_t m_iconMask[32];
@@ -252,6 +262,7 @@ namespace PortabilityLayer
, m_haveIcon(false)
, m_iconGraphic(nullptr)
, m_menuBarVisible(false)
, m_isTouchScreen(false)
{
}
@@ -634,7 +645,7 @@ namespace PortabilityLayer
bool MenuManagerImpl::IsPointInMenuBar(const Vec2i &point) const
{
return point.m_y >= 0 && static_cast<uint32_t>(point.m_y) < kMenuBarHeight;
return IsYInMenuBarRange(point.m_y);
}
uint16_t MenuManagerImpl::GetMenuBarHeight() const
@@ -829,7 +840,9 @@ namespace PortabilityLayer
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
const Rect menuRect = Rect::Create(0, 0, kMenuBarHeight, width);
const int16_t menuHeight = m_isTouchScreen ? kTouchscreenMenuBarHeight : kMenuBarHeight;
const Rect menuRect = Rect::Create(0, 0, menuHeight, width);
if (m_menuBarGraf == nullptr)
{
@@ -863,7 +876,7 @@ namespace PortabilityLayer
// Left stripe
{
const Rect rect = Rect::Create(0, 0, kMenuBarHeight - 1, 1);
const Rect rect = Rect::Create(0, 0, menuHeight - 1, 1);
m_menuBarGraf->FillRect(rect, barBrightColor);
}
@@ -871,13 +884,13 @@ namespace PortabilityLayer
// Bottom stripe
{
const Rect rect = Rect::Create(kMenuBarHeight - 2, 1, kMenuBarHeight - 1, width);
const Rect rect = Rect::Create(menuHeight - 2, 1, menuHeight - 1, width);
m_menuBarGraf->FillRect(rect, barDarkColor);
}
// Right stripe
{
const Rect rect = Rect::Create(0, width - 1, kMenuBarHeight - 1, width);
const Rect rect = Rect::Create(0, width - 1, menuHeight - 1, width);
m_menuBarGraf->FillRect(rect, barDarkColor);
}
@@ -885,7 +898,7 @@ namespace PortabilityLayer
// Bottom edge
{
const Rect rect = Rect::Create(kMenuBarHeight - 1, 0, kMenuBarHeight, width);
const Rect rect = Rect::Create(menuHeight - 1, 0, menuHeight, width);
m_menuBarGraf->FillRect(rect, barBottomEdgeColor);
}
@@ -917,20 +930,31 @@ namespace PortabilityLayer
// Middle
{
ResolveCachingColor barHighlightMidColor = gs_barHighlightMidColor;
const Rect rect = Rect::Create(1, left, kMenuBarHeight - 2, right);
const Rect rect = Rect::Create(1, left, menuHeight - 2, right);
m_menuBarGraf->FillRect(rect, barHighlightMidColor);
}
{
ResolveCachingColor barHighlightDarkColor = gs_barHighlightDarkColor;
const Rect rect = Rect::Create(kMenuBarHeight - 2, left, kMenuBarHeight - 1, right);
const Rect rect = Rect::Create(menuHeight - 2, left, menuHeight - 1, right);
m_menuBarGraf->FillRect(rect, barHighlightDarkColor);
}
}
// Text items
ResolveCachingColor barNormalTextColor = gs_barNormalTextColor;
PortabilityLayer::RenderedFont *sysFont = GetSystemFont(kMenuFontSize, PortabilityLayer::FontFamilyFlag_Bold, true);
PortabilityLayer::RenderedFont *sysFont = nullptr;
unsigned int textYOffset = 0;
if (m_isTouchScreen)
{
sysFont = GetApplicationFont(kTouchScreenMenuFontSize, kTouchScreenMenuFontFlags, true);
textYOffset = kTouchScreenMenuBarTextYOffset;
}
else
{
sysFont = GetSystemFont(kMenuFontSize, kMenuFontFlags, true);
textYOffset = kMenuBarTextYOffset;
}
{
Menu **menuHdl = m_firstMenu;
@@ -951,7 +975,7 @@ namespace PortabilityLayer
{
if (menuHdl != selectedMenuHdl)
{
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), kMenuBarTextYOffset);
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), textYOffset);
graf->DrawString(itemPos, PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)), barNormalTextColor, sysFont);
}
}
@@ -971,7 +995,7 @@ namespace PortabilityLayer
size_t xCoordinate = menu->cumulativeOffset + (menu->menuIndex * 2) * kMenuBarItemPadding + kMenuBarInitialPadding;
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), kMenuBarTextYOffset);
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), textYOffset);
graf->DrawString(itemPos, PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)), barHighlightTextColor, sysFont);
}
}
@@ -1001,7 +1025,16 @@ namespace PortabilityLayer
const PixMap *pixMap = *m_menuBarGraf->m_port.GetPixMap();
const size_t width = pixMap->m_rect.right - pixMap->m_rect.left;
const size_t height = pixMap->m_rect.bottom - pixMap->m_rect.top;
displayDriver->DrawSurface(m_menuBarGraf->m_ddSurface, 0, 0, width, height, nullptr);
int32_t y = 0;
if (m_isTouchScreen)
{
unsigned int displayHeight = 0;
displayDriver->GetDisplayResolution(nullptr, &displayHeight);
y = static_cast<int32_t>(displayHeight) - kTouchscreenMenuBarHeight;
}
displayDriver->DrawSurface(m_menuBarGraf->m_ddSurface, 0, y, width, height, nullptr);
}
}
@@ -1030,6 +1063,16 @@ namespace PortabilityLayer
}
}
void MenuManagerImpl::SetMenuTouchScreenStyle(bool isTouchScreenStyle)
{
m_isTouchScreen = isTouchScreenStyle;
}
bool MenuManagerImpl::IsMenuTouchScreenStyle() const
{
return m_isTouchScreen;
}
void MenuManagerImpl::RefreshMenuBarLayout()
{
if (m_haveMenuBarLayout)
@@ -1037,11 +1080,29 @@ namespace PortabilityLayer
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
PortabilityLayer::FontFamily *fontFamily = PortabilityLayer::FontManager::GetInstance()->GetSystemFont(kMenuFontSize, kMenuFontFlags);
PortabilityLayer::FontFamily *fontFamily = nullptr;
unsigned int fontSize = 0;
unsigned int fontFlags = 0;
if (m_isTouchScreen)
{
fontSize = kTouchScreenMenuFontSize;
fontFlags = PortabilityLayer::FontFamilyFlag_None;
fontFamily = PortabilityLayer::FontManager::GetInstance()->GetApplicationFont(kTouchScreenMenuFontSize, PortabilityLayer::FontFamilyFlag_None);
}
else
{
fontSize = kMenuFontSize;
fontFlags = kMenuFontFlags;
fontFamily = PortabilityLayer::FontManager::GetInstance()->GetSystemFont(kMenuFontSize, kMenuFontFlags);
}
if (!fontFamily)
return;
PortabilityLayer::RenderedFont *rfont = PortabilityLayer::FontManager::GetInstance()->GetRenderedFontFromFamily(fontFamily, kMenuFontSize, true, kMenuFontFlags);
PortabilityLayer::RenderedFont *rfont = PortabilityLayer::FontManager::GetInstance()->GetRenderedFontFromFamily(fontFamily, fontSize, true, fontFlags);
if (!rfont)
return;
@@ -1137,7 +1198,7 @@ namespace PortabilityLayer
if (point.m_y < 0)
return;
if (!m_menuSelectionState.IsPopup() && point.m_y < static_cast<int>(kMenuBarHeight))
if (!m_menuSelectionState.IsPopup() && IsYInMenuBarRange(point.m_y))
{
m_menuSelectionState.ClearSelection();
ProcessMouseMoveToMenuBar(point);
@@ -1235,6 +1296,18 @@ namespace PortabilityLayer
m_menuSelectionState.ClearSelection();
}
bool MenuManagerImpl::IsYInMenuBarRange(int32_t y) const
{
if (m_isTouchScreen)
{
unsigned int displayHeight = 0;
PortabilityLayer::HostDisplayDriver::GetInstance()->GetDisplayResolution(nullptr, &displayHeight);
return y >= (static_cast<int32_t>(displayHeight - kTouchscreenMenuBarHeight)) && y < static_cast<int32_t>(displayHeight);
}
else
return y >= 0 && y < static_cast<int32_t>(kMenuBarHeight);
}
bool MenuManagerImpl::ItemIsSeparator(const Menu &menu, const MenuItem &item)
{
const uint8_t *strBlob = static_cast<const uint8_t*>(menu.stringBlobHandle->m_contents);

View File

@@ -54,6 +54,9 @@ namespace PortabilityLayer
virtual void RenderFrame(IGpDisplayDriver *displayDriver) = 0;
virtual void SetMenuTouchScreenStyle(bool isTouchScreenStyle) = 0;
virtual bool IsMenuTouchScreenStyle() const = 0;
static MenuManager *GetInstance();
};
}

View File

@@ -21,6 +21,7 @@
#include "HostVOSEventQueue.h"
#include "IGpCursor.h"
#include "IGpDisplayDriver.h"
#include "IGpThreadRelay.h"
#include "InputManager.h"
#include "ResourceManager.h"
#include "MacFileInfo.h"
@@ -47,6 +48,29 @@
#include <assert.h>
#include <algorithm>
class PLMainThreadRelay final : public IGpThreadRelay
{
public:
void Invoke(Callback_t callback, void *context) const override;
static PLMainThreadRelay *GetInstance();
private:
static PLMainThreadRelay ms_instance;
};
void PLMainThreadRelay::Invoke(Callback_t callback, void *context) const
{
PLSysCalls::RunOnVOSThread(callback, context);
}
PLMainThreadRelay *PLMainThreadRelay::GetInstance()
{
return &ms_instance;
}
PLMainThreadRelay PLMainThreadRelay::ms_instance;
static bool ConvertFilenameToSafePStr(const char *str, uint8_t *pstr)
{
const char *strBase = str;
@@ -650,6 +674,8 @@ void PL_Init()
PortabilityLayer::DisplayDeviceManager::GetInstance()->Init();
PortabilityLayer::QDManager::GetInstance()->Init();
PortabilityLayer::MenuManager::GetInstance()->Init();
PortabilityLayer::HostFileSystem::GetInstance()->SetMainThreadRelay(PLMainThreadRelay::GetInstance());
}
WindowPtr PL_GetPutInFrontWindowPtr()

View File

@@ -189,4 +189,13 @@ namespace PLSysCalls
{
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_ForceSyncFrame, nullptr, nullptr);
}
void RunOnVOSThread(void(*callback)(void *context), void *context)
{
PortabilityLayer::HostSuspendCallArgument args[2];
args[0].m_functionPtr = callback;
args[1].m_pointer = context;
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_CallOnVOSThread, args, nullptr);
}
}

View File

@@ -8,4 +8,5 @@ namespace PLSysCalls
{
void Sleep(uint32_t ticks);
void ForceSyncFrame();
void RunOnVOSThread(void(*callback)(void *context), void *context);
}

View File

@@ -28,7 +28,7 @@ void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
}
if (m_ddSurface == nullptr)
m_ddSurface = displayDriver->CreateSurface(pixMap->m_rect.right - pixMap->m_rect.left, pixMap->m_rect.bottom - pixMap->m_rect.top, pixMap->m_pitch, pixMap->m_pixelFormat);
m_ddSurface = displayDriver->CreateSurface(pixMap->m_rect.right - pixMap->m_rect.left, pixMap->m_rect.bottom - pixMap->m_rect.top, pixMap->m_pitch, pixMap->m_pixelFormat, DrawSurface::StaticOnDriverInvalidate, this);
if (m_port.IsDirty(PortabilityLayer::QDPortDirtyFlag_Contents) && m_ddSurface != nullptr)
{
@@ -36,3 +36,13 @@ void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
m_port.ClearDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
}
void DrawSurface::StaticOnDriverInvalidate(void *context)
{
static_cast<DrawSurface*>(context)->OnDriverInvalidate();
}
void DrawSurface::OnDriverInvalidate()
{
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}

View File

@@ -89,4 +89,8 @@ struct DrawSurface
PortabilityLayer::RGBAColor m_cachedAAColor;
PortabilityLayer::QDPort m_port;
private:
static void StaticOnDriverInvalidate(void *context);
void OnDriverInvalidate();
};

View File

@@ -17,6 +17,8 @@ namespace PortabilityLayer
kCursors,
kHighScores,
kLogs,
kSourceExport,
};
}

View File

@@ -1434,6 +1434,7 @@ namespace PortabilityLayer
void WindowManagerImpl::HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight)
{
const uint32_t menuBarHeight = PortabilityLayer::MenuManager::GetInstance()->GetMenuBarHeight();
const bool menuIsTouchScreen = PortabilityLayer::MenuManager::GetInstance()->IsMenuTouchScreenStyle();
for (PortabilityLayer::WindowImpl *window = m_windowStackTop; window != nullptr; window = window->GetWindowBelow())
{
@@ -1457,17 +1458,37 @@ namespace PortabilityLayer
int64_t newY = 0;
int32_t currentY = window->GetPosition().m_y;
if (currentY < static_cast<int32_t>(menuBarHeight))
newY = currentY;
else
if (!menuIsTouchScreen)
{
if (newHeight <= (paddedHeight + menuBarHeight) || prevHeight <= paddedHeight + menuBarHeight)
newY = (static_cast<int64_t>(newHeight) - paddedHeight - menuBarHeight) / 2 + menuBarHeight;
if (currentY < static_cast<int32_t>(menuBarHeight))
newY = currentY;
else
{
uint32_t prevClearanceY = prevHeight - paddedHeight - menuBarHeight;
uint32_t newClearanceY = newHeight - paddedHeight - menuBarHeight;
newY = (static_cast<int64_t>(currentY) - static_cast<int64_t>(menuBarHeight) - chromePadding[WindowChromeSides::kTop]) * static_cast<int64_t>(newClearanceY) / static_cast<int64_t>(prevClearanceY) + menuBarHeight + chromePadding[WindowChromeSides::kTop];
if (newHeight <= (paddedHeight + menuBarHeight) || prevHeight <= paddedHeight + menuBarHeight)
newY = (static_cast<int64_t>(newHeight) - paddedHeight - menuBarHeight) / 2 + menuBarHeight;
else
{
uint32_t prevClearanceY = prevHeight - paddedHeight - menuBarHeight;
uint32_t newClearanceY = newHeight - paddedHeight - menuBarHeight;
newY = (static_cast<int64_t>(currentY) - static_cast<int64_t>(menuBarHeight) - chromePadding[WindowChromeSides::kTop]) * static_cast<int64_t>(newClearanceY) / static_cast<int64_t>(prevClearanceY) + menuBarHeight + chromePadding[WindowChromeSides::kTop];
}
}
}
else
{
uint32_t heightWithoutMenu = surfaceRect.Height() - menuBarHeight;
if (currentY + static_cast<int32_t>(paddedHeight) >= heightWithoutMenu)
newY = currentY;
else
{
if (newHeight <= (paddedHeight + menuBarHeight) || prevHeight <= paddedHeight + menuBarHeight)
newY = (static_cast<int64_t>(newHeight) - paddedHeight - menuBarHeight) / 2 + menuBarHeight;
else
{
uint32_t prevClearanceY = prevHeight - paddedHeight - menuBarHeight;
uint32_t newClearanceY = newHeight - paddedHeight - menuBarHeight;
newY = (static_cast<int64_t>(currentY) - static_cast<int64_t>(menuBarHeight) - chromePadding[WindowChromeSides::kTop]) * static_cast<int64_t>(newClearanceY) / static_cast<int64_t>(prevClearanceY) + chromePadding[WindowChromeSides::kTop];
}
}
}