Skip to content

Commit

Permalink
Merge remote-tracking branch 'cockos/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
olilarkin committed Apr 13, 2024
2 parents b842366 + 892c8c3 commit 5847cff
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 33 deletions.
12 changes: 10 additions & 2 deletions WDL/audiobuffercontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
#include "queue.h"
#include <assert.h>

void ChannelPinMapper::Reset()
{
for (int i=0; i < CHANNELPINMAPPER_MAXPINS; ++i)
m_mapping[i].set_excl(i);
}

void ChannelPinMapper::SetNPins(int nPins)
{
if (nPins<0) nPins=0;
else if (nPins>CHANNELPINMAPPER_MAXPINS) nPins=CHANNELPINMAPPER_MAXPINS;
int i;
for (i = m_nPins; i < nPins; ++i) {
for (i = m_nPins; i < nPins; ++i)
{
ClearPin(i);
if (i < m_nCh) {
if (i < m_nCh)
{
SetPin(i, i, true);
}
}
Expand Down
4 changes: 3 additions & 1 deletion WDL/audiobuffercontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ class ChannelPinMapper
{
public:

ChannelPinMapper() : m_nCh(0), m_nPins(0) {}
ChannelPinMapper() : m_nCh(0), m_nPins(0) { Reset(); }
~ChannelPinMapper() {}

void SetNPins(int nPins);
void SetNChannels(int nCh, bool auto_passthru=true);
// or ...
void Init(const PinMapPin * pMapping, int nPins);
// or ...
void Reset(); // set to full passthrough

int GetNPins() const { return m_nPins; }
int GetNChannels() const { return m_nCh; }
Expand Down
6 changes: 3 additions & 3 deletions WDL/eel2/eel_lice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2132,8 +2132,8 @@ static EEL_F NSEEL_CGEN_CALL _gfx_getchar(void *opaque, INT_PTR np, EEL_F **plis
rv|=4;
if (*p != 65537.0)
{
POINT p;
GetCursorPos(&p);
POINT pt;
GetCursorPos(&pt);
RECT r;
GetWindowRect(ctx->hwnd_standalone,&r);
if (r.top > r.bottom)
Expand All @@ -2142,7 +2142,7 @@ static EEL_F NSEEL_CGEN_CALL _gfx_getchar(void *opaque, INT_PTR np, EEL_F **plis
r.top = r.bottom;
r.bottom = a;
}
if (PtInRect(&r,p) && WindowFromPoint(p) == ctx->hwnd_standalone) rv|=8;
if (PtInRect(&r,pt) && WindowFromPoint(pt) == ctx->hwnd_standalone) rv|=8;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion WDL/lice/lice_arc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ void LICE_FillCircle(LICE_IBitmap* dest, float cx, float cy, float r, LICE_pixel
void LICE_RoundRect(LICE_IBitmap *drawbm, float xpos, float ypos, float w, float h, int cornerradius,
LICE_pixel col, float alpha, int mode, bool aa)
{
xpos = floor(xpos+0.5);
ypos = floor(ypos+0.5);
w = floor(w+0.5);
h = floor(h+0.5);
if (cornerradius>0)
{
float cr=cornerradius;
Expand Down Expand Up @@ -722,6 +726,6 @@ void LICE_RoundRect(LICE_IBitmap *drawbm, float xpos, float ypos, float w, float
}
}

LICE_DrawRect(drawbm, xpos, ypos, w, h, col, alpha, mode);
LICE_DrawRect(drawbm, (int)xpos, (int)ypos, (int)w, (int)h, col, alpha, mode);
}

11 changes: 5 additions & 6 deletions WDL/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ int PackApeChunk(WDL_HeapBuf *hb, WDL_StringKeyedArray<char*> *metadata)
const char *val=metadata->Enumerate(i, &key);
if (strlen(key) < 5 || strncmp(key, "APE:", 4) || !val || !val[0]) continue;
key += 4;
if (!apelen) apelen += 64;
if (!apelen) apelen=64; // includes header and footer
if (!strncmp(key, "User Defined", 12))
{
const char *k, *v;
Expand All @@ -912,7 +912,7 @@ int PackApeChunk(WDL_HeapBuf *hb, WDL_StringKeyedArray<char*> *metadata)
memcpy(p, "APETAGEX", 8);
p += 8;
_AddInt32LE(2000); // version
_AddInt32LE(apelen-32);
_AddInt32LE(apelen-32); // includes footer but not header
_AddInt32LE(cnt);
_AddInt32LE((1<<31)|(1<<30)|(1<<29)); // tag contains header and footer, this is the header
_AddInt32LE(0);
Expand Down Expand Up @@ -951,7 +951,7 @@ int PackApeChunk(WDL_HeapBuf *hb, WDL_StringKeyedArray<char*> *metadata)
memcpy(p, "APETAGEX", 8);
p += 8;
_AddInt32LE(2000); // version
_AddInt32LE(apelen-32);
_AddInt32LE(apelen-32); // includes footer but not header
_AddInt32LE(cnt);
_AddInt32LE((1<<31)|(1<<30)|(1<<28)); // tag contains header and footer, this is the footer
_AddInt32LE(0);
Expand Down Expand Up @@ -1328,8 +1328,7 @@ void DumpMetadata(WDL_FastString *str, WDL_StringKeyedArray<char*> *metadata)
}
}

int i;
for (i=0; i < metadata->GetSize(); ++i)
for (int i=0; i < metadata->GetSize(); ++i)
{
const char *key;
const char *val=metadata->Enumerate(i, &key);
Expand All @@ -1351,7 +1350,7 @@ void DumpMetadata(WDL_FastString *str, WDL_StringKeyedArray<char*> *metadata)
}

int unk_cnt=0;
for (i=0; i < metadata->GetSize(); ++i)
for (int i=0; i < metadata->GetSize(); ++i)
{
const char *key;
const char *val=metadata->Enumerate(i, &key);
Expand Down
3 changes: 3 additions & 0 deletions WDL/swell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ ifndef NOGDK
endif
endif
LINKEXTRA += -lGL
ifdef PRELOAD_GDK
CFLAGS += -Wl,-z,lazy
endif
endif

CXXFLAGS = $(CFLAGS)
Expand Down
67 changes: 54 additions & 13 deletions WDL/swell/swell-dlg.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
if ((sz).width > 16384.0) (sz).width = 16384.0; \
if ((sz).height > 16384.0) (sz).height = 16384.0;

static id __class_CAMetalLayer, __class_MTLRenderPassDescriptor, __class_MTLTextureDescriptor, __class_MTLRenderPipelineDescriptor, __class_MTLCompileOptions;
static id __class_CAMetalLayer, __class_MTLTextureDescriptor;
static id<MTLDevice> (*__MTLCreateSystemDefaultDevice)(void);
static id<MTLDevice> (*__CGDirectDisplayCopyCurrentMetalDevice)(CGDirectDisplayID);

Expand Down Expand Up @@ -560,13 +560,14 @@ static void SendTreeViewExpandNotification(SWELL_hwndChild *par, NSNotification
}

id<MTLCommandQueue> m_commandQueue;
id<MTLCommandBuffer> m_commandBuffer;
id<MTLCommandBuffer> m_commandBuffer; // only used for presentation

void present()
{
if (m_commandBuffer)
{
[m_commandBuffer commit];
[m_commandBuffer waitUntilCompleted];
[m_commandBuffer release];
m_commandBuffer = NULL;
}
Expand Down Expand Up @@ -651,8 +652,13 @@ - (LRESULT)onSwellMessage:(UINT)msg p1:(WPARAM)wParam p2:(LPARAM)lParam
if ([[self window] contentView] == self && [[self window] respondsToSelector:@selector(swellDestroyAllOwnedWindows)])
[(SWELL_ModelessWindow*)[self window] swellDestroyAllOwnedWindows];

if (m_wndproc) m_wndproc((HWND)self,WM_NCDESTROY,0,0);
if (GetCapture()==(HWND)self) ReleaseCapture();
SWELL_MessageQueue_Clear((HWND)self);

#ifndef SWELL_NO_METAL
if (m_use_metal>0) swell_removeMetalDirty(self);
#endif

if (m_menu)
{
Expand Down Expand Up @@ -1500,9 +1506,6 @@ -(void) swellDrawMetal:(const RECT *)forRect
if (m_use_metal != 1 && m_use_metal != 2) return;
const bool direct_mode = m_use_metal == 1;

CAMetalLayer *layer = (CAMetalLayer *)[self layer];
layer.framebufferOnly = NO;

id<MTLDevice> device = m_metal_device;

static bool reg;
Expand Down Expand Up @@ -1537,15 +1540,19 @@ -(void) swellDrawMetal:(const RECT *)forRect
device = def;
}

CAMetalLayer *layer = (CAMetalLayer *)[self layer];

// this might happen if a caller calls SWELL_SetMetal too late after drawing has already occurred (and the backing layer was already created)
if (WDL_NOT_NORMALLY(![layer respondsToSelector:@selector(setFramebufferOnly:)])) return;

if (device != m_metal_device)
{
id<MTLDevice> olddev = (id<MTLDevice>)m_metal_device;
if (olddev) NSLog(@"swell-cocoa: switching metal devices from %p %@ to %p %@\n",olddev,olddev.name,device,device.name);
m_metal_device = device;
[layer setDevice:device];
swell_metal_set_layer_gravity(layer,m_metal_gravity ^ ([self isFlipped] ? 2 : 0));
if (m_use_metal==1)
layer.framebufferOnly = NO;
layer.framebufferOnly = NO;
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];

if (!direct_mode) [m_metal_texture release];
Expand Down Expand Up @@ -1675,7 +1682,15 @@ -(void) swellDrawMetal:(const RECT *)forRect
[ctx->m_commandBuffer retain];
}

id<MTLBlitCommandEncoder> encoder = [ctx->m_commandBuffer blitCommandEncoder];
id<MTLCommandBuffer> cb = [ctx->m_commandQueue commandBuffer];
if (WDL_NOT_NORMALLY(cb == NULL))
cb = ctx->m_commandBuffer; // backup, run commands in the presentation buffer

id<MTLBlitCommandEncoder> encoder = [cb blitCommandEncoder];
if (WDL_NOT_NORMALLY(encoder == NULL))
{
NSLog(@"swell-cocoa: metal blitCommandEncoder failure\n");
}

[encoder copyFromTexture:m_metal_texture
sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(0,0,0)
Expand All @@ -1685,6 +1700,9 @@ -(void) swellDrawMetal:(const RECT *)forRect

[encoder endEncoding];

if (cb != ctx->m_commandBuffer)
[cb commit];

[ctx->m_commandBuffer presentDrawable:drawable];

if (!s_mtl_in_update)
Expand Down Expand Up @@ -2470,10 +2488,27 @@ @implementation SWELL_ModelessWindow : NSWindow

SWELLDIALOGCOMMONIMPLEMENTS_WND(0)

-(id)_setFrame:(NSRect)r fromAdjustmentToScreen:(NSScreen *)scr anchorIfNeeded:(void *)anch animate:(int)anim
{
if (m_disableMonitorAutosize)
return nil;

SEL sel = @selector(_setFrame:fromAdjustmentToScreen:anchorIfNeeded:animate:);
if (WDL_NOT_NORMALLY(![super respondsToSelector:sel])) return nil;

id (*send_msg)(struct objc_super *, SEL, NSRect, NSScreen*, void*, int) = (id (*)(struct objc_super *, SEL, NSRect, NSScreen*, void*, int)) &objc_msgSendSuper;
struct objc_super sup = {
self,
[self superclass]
};
return send_msg(&sup, sel, r, scr, anch, anim);
}


- (id)initModelessForChild:(HWND)child owner:(HWND)owner styleMask:(unsigned int)smask
{
INIT_COMMON_VARS
m_disableMonitorAutosize = false;
m_wantInitialKeyWindowOnShow=0;
m_wantraiseamt=0;
lastFrameSize.width=lastFrameSize.height=0.0f;
Expand Down Expand Up @@ -2515,6 +2550,7 @@ - (id)initModelessForChild:(HWND)child owner:(HWND)owner styleMask:(unsigned int
- (id)initModeless:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par outputHwnd:(HWND *)hwndOut forceStyles:(unsigned int)smask
{
INIT_COMMON_VARS
m_disableMonitorAutosize = false;
m_wantInitialKeyWindowOnShow=0;
m_wantraiseamt=0;

Expand Down Expand Up @@ -3882,10 +3918,7 @@ static bool mtl_init()
if (__MTLCreateSystemDefaultDevice &&
__MTLCopyAllDevices &&
(__class_CAMetalLayer = objc_getClass("CAMetalLayer")) &&
(__class_MTLRenderPassDescriptor = objc_getClass("MTLRenderPassDescriptor")) &&
(__class_MTLRenderPipelineDescriptor = objc_getClass("MTLRenderPipelineDescriptor")) &&
(__class_MTLTextureDescriptor = objc_getClass("MTLTextureDescriptor")) &&
(__class_MTLCompileOptions = objc_getClass("MTLCompileOptions"))
(__class_MTLTextureDescriptor = objc_getClass("MTLTextureDescriptor"))
)
{
NSArray *ar = __MTLCopyAllDevices();
Expand Down Expand Up @@ -4109,6 +4142,10 @@ static void SWELL_Metal_WriteTex(SWELL_hwndChild *wnd, const unsigned int *srcbu
else if (layer.contentsScale != (retina_hint ? 2.0 : 1.0))
layer.contentsScale = retina_hint ? 2.0 : 1.0;
tex = [(wnd->m_metal_drawable = [layer nextDrawable]) texture];
if (WDL_NOT_NORMALLY(!tex))
{
NSLog(@"swell-cocoa: error creating metal texture for direct mode\n");
}
wnd->m_metal_texture = tex;
}
}
Expand All @@ -4125,6 +4162,10 @@ static void SWELL_Metal_WriteTex(SWELL_hwndChild *wnd, const unsigned int *srcbu
textureDescriptor.height = want_h;
tex = [wnd->m_metal_device newTextureWithDescriptor:textureDescriptor];
wnd->m_metal_texture = tex;
if (WDL_NOT_NORMALLY(!tex))
{
NSLog(@"swell-cocoa: error creating metal texture for full mode\n");
}

[textureDescriptor release];
}
Expand Down Expand Up @@ -4237,7 +4278,7 @@ void SWELL_Metal_Blit(void *_tex, const unsigned int *srcbuf, int x, int y, int
}
}

if (use_alpha && WDL_NORMALLY(wnd->m_metal_texture))
if (use_alpha && wnd->m_metal_texture)
{
id<MTLTexture> tex = (id<MTLTexture>) wnd->m_metal_texture;
const int texw = (int)tex.width, texh = (int)tex.height;
Expand Down
1 change: 1 addition & 0 deletions WDL/swell/swell-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ SWELL_API_DEFINE(void, SetAllowNoMiddleManRendering, (HWND h, bool allow)) // de
#ifdef SWELL_TARGET_OSX
SWELL_API_DEFINE(int, SWELL_IsRetinaDC, (HDC hdc)) // returns 1 if DC is a retina DC (2x res possible)
SWELL_API_DEFINE(int, SWELL_IsRetinaHWND, (HWND h)) // returns 1 if HWND is a retina HWND
SWELL_API_DEFINE(void, SWELL_SetNoMultiMonitorAutoSize, (HWND h, bool noauto))
#endif

SWELL_API_DEFINE(void, SWELL_SetViewGL, (HWND h, char wantGL)) // wantGL=2 to enable wantsBestResolutionOpenGLSurface
Expand Down
5 changes: 4 additions & 1 deletion WDL/swell/swell-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ typedef struct WindowPropRec
int m_wantraiseamt;
bool m_wantInitialKeyWindowOnShow;
bool m_lastZoom;
bool m_disableMonitorAutosize;
}
- (id)initModeless:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par outputHwnd:(HWND *)hwndOut forceStyles:(unsigned int)smask;
- (id)initModelessForChild:(HWND)child owner:(HWND)owner styleMask:(unsigned int)smask;
Expand Down Expand Up @@ -774,7 +775,9 @@ SWELL_IMPLEMENT_GETOSXVERSION int SWELL_GetOSXVersion()
{
if (NSAppKitVersionNumber >= 1266.0)
{
if (NSAppKitVersionNumber >= 2299.0)
if (NSAppKitVersionNumber >= 2487.0)
v = 0x1400;
else if (NSAppKitVersionNumber >= 2299.0)
v = 0x1300;
else if (NSAppKitVersionNumber >= 2100.0)
v = 0x1200;
Expand Down
13 changes: 13 additions & 0 deletions WDL/swell/swell-wnd.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,8 @@ LRESULT SendMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}

static NSView *NavigateUpScrollClipViews(NSView *ch);

void DestroyWindow(HWND hwnd)
{
if (WDL_NOT_NORMALLY(!hwnd)) return;
Expand All @@ -1950,6 +1952,7 @@ void DestroyWindow(HWND hwnd)
KillTimer(hwnd,~(UINT_PTR)0);
sendSwellMessage((id)pid,WM_DESTROY,0,0);

pid = NavigateUpScrollClipViews(pid);
NSWindow *pw = [(NSView *)pid window];
if (pw && [pw contentView] == pid) // destroying contentview should destroy top level window
{
Expand Down Expand Up @@ -7120,6 +7123,16 @@ void SetTransparent(HWND h)
}
}

void SWELL_SetNoMultiMonitorAutoSize(HWND h, bool noauto)
{
if (WDL_NOT_NORMALLY(!h)) return;
NSWindow* wnd=0;
if ([(id)h isKindOfClass:[NSWindow class]]) wnd=(NSWindow*)h;
else if ([(id)h isKindOfClass:[NSView class]]) wnd=[(NSView*)h window];
if (WDL_NORMALLY(wnd && [wnd isKindOfClass:[SWELL_ModelessWindow class]]))
((SWELL_ModelessWindow *)wnd)->m_disableMonitorAutosize = noauto;
}

int SWELL_GetDefaultButtonID(HWND hwndDlg, bool onlyIfEnabled)
{
if (WDL_NOT_NORMALLY(![(id)hwndDlg isKindOfClass:[NSView class]])) return 0;
Expand Down
Loading

0 comments on commit 5847cff

Please sign in to comment.