Skip to content

Commit e41c586

Browse files
authored
Merge branch 'master' into fixes/3323-resourcedictionary-resource
2 parents 01c1669 + e48bbe6 commit e41c586

File tree

11 files changed

+167
-36
lines changed

11 files changed

+167
-36
lines changed

native/Avalonia.Native/src/OSX/gl.mm

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "common.h"
22
#include <OpenGL/gl.h>
33
#include <dlfcn.h>
4+
#include "window.h"
45

56
template <typename T, size_t N> char (&ArrayCounter(T (&a)[N]))[N];
67
#define ARRAY_COUNT(a) (sizeof(ArrayCounter(a)))
@@ -181,12 +182,12 @@ virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override
181182

182183
class AvnGlRenderingSession : public ComSingleObject<IAvnGlSurfaceRenderingSession, &IID_IAvnGlSurfaceRenderingSession>
183184
{
184-
NSView* _view;
185-
NSWindow* _window;
185+
AvnView* _view;
186+
AvnWindow* _window;
186187
NSOpenGLContext* _context;
187188
public:
188189
FORWARD_IUNKNOWN()
189-
AvnGlRenderingSession(NSWindow*window, NSView* view, NSOpenGLContext* context)
190+
AvnGlRenderingSession(AvnWindow*window, AvnView* view, NSOpenGLContext* context)
190191
{
191192
_context = context;
192193
_window = window;
@@ -195,14 +196,12 @@ virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override
195196

196197
virtual HRESULT GetPixelSize(AvnPixelSize* ret) override
197198
{
198-
auto fsize = [_view convertSizeToBacking: [_view frame].size];
199-
ret->Width = (int)fsize.width;
200-
ret->Height = (int)fsize.height;
199+
*ret = [_view getPixelSize];
201200
return S_OK;
202201
}
203202
virtual HRESULT GetScaling(double* ret) override
204203
{
205-
*ret = [_window backingScaleFactor];
204+
*ret = [_window getScaling];
206205
return S_OK;
207206
}
208207

@@ -234,8 +233,17 @@ virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) override
234233
auto f = GetFeature();
235234
if(f == NULL)
236235
return E_FAIL;
237-
if(![_view lockFocusIfCanDraw])
236+
237+
@try
238+
{
239+
if(![_view lockFocusIfCanDraw])
240+
return E_ABORT;
241+
}
242+
@catch(NSException* exception)
243+
{
238244
return E_ABORT;
245+
}
246+
239247

240248
auto gl = _context;
241249
CGLLockContext([_context CGLContextObj]);

native/Avalonia.Native/src/OSX/window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class WindowBaseImpl;
1212
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
1313
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose;
1414
-(void) onClosed;
15+
-(AvnPixelSize) getPixelSize;
1516
@end
1617

1718
@interface AvnWindow : NSWindow <NSWindowDelegate>
@@ -22,6 +23,7 @@ class WindowBaseImpl;
2223
-(void) restoreParentWindow;
2324
-(bool) shouldTryToHandleEvents;
2425
-(void) applyMenu:(NSMenu *)menu;
26+
-(double) getScaling;
2527
@end
2628

2729
struct INSWindowHolder

native/Avalonia.Native/src/OSX/window.mm

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ virtual HRESULT Close() override
195195
{
196196
@autoreleasepool
197197
{
198-
[Window close];
198+
if (Window != nullptr)
199+
{
200+
[Window close];
201+
}
202+
199203
return S_OK;
200204
}
201205
}
@@ -291,7 +295,14 @@ virtual bool TryLock() override
291295
{
292296
@autoreleasepool
293297
{
294-
return [View lockFocusIfCanDraw] == YES;
298+
@try
299+
{
300+
return [View lockFocusIfCanDraw] == YES;
301+
}
302+
@catch (NSException*)
303+
{
304+
return NO;
305+
}
295306
}
296307
}
297308

@@ -719,15 +730,33 @@ @implementation AvnView
719730
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed, _isMouseOver;
720731
NSEvent* _lastMouseDownEvent;
721732
bool _lastKeyHandled;
733+
AvnPixelSize _lastPixelSize;
722734
}
723735

724-
- (void)dealloc
736+
- (void)onClosed
725737
{
738+
@synchronized (self)
739+
{
740+
_parent = nullptr;
741+
}
726742
}
727743

728-
- (void)onClosed
744+
- (BOOL)lockFocusIfCanDraw
745+
{
746+
@synchronized (self)
747+
{
748+
if(_parent == nullptr)
749+
{
750+
return NO;
751+
}
752+
}
753+
754+
return [super lockFocusIfCanDraw];
755+
}
756+
757+
-(AvnPixelSize) getPixelSize
729758
{
730-
_parent = NULL;
759+
return _lastPixelSize;
731760
}
732761

733762
- (NSEvent*) lastMouseDownEvent
@@ -742,6 +771,8 @@ -(AvnView*) initWithParent: (WindowBaseImpl*) parent
742771
[self setWantsLayer:YES];
743772
_parent = parent;
744773
_area = nullptr;
774+
_lastPixelSize.Height = 100;
775+
_lastPixelSize.Width = 100;
745776
return self;
746777
}
747778

@@ -783,6 +814,10 @@ -(void)setFrameSize:(NSSize)newSize
783814
[self addTrackingArea:_area];
784815

785816
_parent->UpdateCursor();
817+
818+
auto fsize = [self convertSizeToBacking: [self frame].size];
819+
_lastPixelSize.Width = (int)fsize.width;
820+
_lastPixelSize.Height = (int)fsize.height;
786821

787822
_parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height});
788823
}
@@ -812,7 +847,13 @@ - (void) drawFb: (AvnFramebuffer*) fb
812847

813848
- (void)drawRect:(NSRect)dirtyRect
814849
{
850+
if (_parent == nullptr)
851+
{
852+
return;
853+
}
854+
815855
_parent->BaseEvents->RunRenderPriorityJobs();
856+
816857
@synchronized (self) {
817858
if(_swRenderedFrame != NULL)
818859
{
@@ -879,7 +920,12 @@ - (AvnPoint)toAvnPoint:(CGPoint)p
879920

880921
- (void) viewDidChangeBackingProperties
881922
{
923+
auto fsize = [self convertSizeToBacking: [self frame].size];
924+
_lastPixelSize.Width = (int)fsize.width;
925+
_lastPixelSize.Height = (int)fsize.height;
926+
882927
_parent->BaseEvents->ScalingChanged([_parent->Window backingScaleFactor]);
928+
883929
[super viewDidChangeBackingProperties];
884930
}
885931

@@ -1161,6 +1207,12 @@ @implementation AvnWindow
11611207
bool _closed;
11621208
NSMenu* _menu;
11631209
bool _isAppMenuApplied;
1210+
double _lastScaling;
1211+
}
1212+
1213+
-(double) getScaling
1214+
{
1215+
return _lastScaling;
11641216
}
11651217

11661218
+(void)closeAll
@@ -1174,10 +1226,6 @@ +(void)closeAll
11741226
}
11751227
}
11761228

1177-
- (void)dealloc
1178-
{
1179-
}
1180-
11811229
- (void)pollModalSession:(nonnull NSModalSession)session
11821230
{
11831231
auto response = [NSApp runModalSession:session];
@@ -1232,6 +1280,9 @@ -(AvnWindow*) initWithParent: (WindowBaseImpl*) parent
12321280
[self setReleasedWhenClosed:false];
12331281
_parent = parent;
12341282
[self setDelegate:self];
1283+
_closed = false;
1284+
1285+
_lastScaling = [self backingScaleFactor];
12351286
return self;
12361287
}
12371288

@@ -1247,6 +1298,11 @@ - (BOOL)windowShouldClose:(NSWindow *)sender
12471298
return true;
12481299
}
12491300

1301+
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
1302+
{
1303+
_lastScaling = [self backingScaleFactor];
1304+
}
1305+
12501306
- (void)windowWillClose:(NSNotification *)notification
12511307
{
12521308
_closed = true;
@@ -1257,9 +1313,6 @@ - (void)windowWillClose:(NSNotification *)notification
12571313
[self restoreParentWindow];
12581314
parent->BaseEvents->Closed();
12591315
[parent->View onClosed];
1260-
dispatch_async(dispatch_get_main_queue(), ^{
1261-
[self setContentView: nil];
1262-
});
12631316
}
12641317
}
12651318

@@ -1406,18 +1459,6 @@ - (void)windowDidMove:(NSNotification *)notification
14061459
_parent->GetPosition(&position);
14071460
_parent->BaseEvents->PositionChanged(position);
14081461
}
1409-
1410-
// TODO this breaks resizing.
1411-
/*- (void)windowDidResize:(NSNotification *)notification
1412-
{
1413-
1414-
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
1415-
1416-
if(parent != nullptr)
1417-
{
1418-
parent->WindowStateChanged();
1419-
}
1420-
}*/
14211462
@end
14221463

14231464
class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup

src/Avalonia.Controls/Primitives/PopupPositioning/IPopupPositioner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public static void ConfigurePosition(ref this PopupPositionerParameters position
306306
if (placement == PlacementMode.Pointer)
307307
{
308308
positionerParameters.AnchorRectangle = new Rect(pointer, new Size(1, 1));
309-
positionerParameters.Anchor = PopupPositioningEdge.BottomRight;
309+
positionerParameters.Anchor = PopupPositioningEdge.TopLeft;
310310
positionerParameters.Gravity = PopupPositioningEdge.BottomRight;
311311
}
312312
else

src/Avalonia.Controls/TextBox.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ private async void Paste()
390390
{
391391
return;
392392
}
393+
393394
_undoRedoHelper.Snapshot();
394395
HandleTextInput(text);
396+
_undoRedoHelper.Snapshot();
395397
}
396398

397399
protected override void OnKeyDown(KeyEventArgs e)

src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private void Poll(long _)
4747

4848
var fProcMounts = File.ReadAllLines(ProcMountsDir)
4949
.Select(x => x.Split(' '))
50-
.Select(x => (x[0], x[1]));
50+
.Select(x => (x[0], x[1]))
51+
.Where(x => !x.Item2.StartsWith("/snap/", StringComparison.InvariantCultureIgnoreCase));
5152

5253
var labelDirEnum = Directory.Exists(DevByLabelDir) ?
5354
new DirectoryInfo(DevByLabelDir).GetFiles() : Enumerable.Empty<FileInfo>();

src/Avalonia.Native/WindowImplBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ public void SetTopmost(bool value)
353353

354354
public void SetCursor(IPlatformHandle cursor)
355355
{
356+
if (_native == null)
357+
{
358+
return;
359+
}
360+
356361
var newCursor = cursor as AvaloniaNativeCursor;
357362
newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor);
358363
_native.Cursor = newCursor.Cursor;

src/Avalonia.X11/Glx/Glx.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,24 @@ public delegate IntPtr GlxCreateContextAttribsARB(IntPtr dpy, IntPtr fbconfig, I
8484
[GlEntryPoint("glGetError")]
8585
public GlGetError GetError { get; }
8686

87-
public GlxInterface() : base(GlxGetProcAddress)
87+
public GlxInterface() : base(SafeGetProcAddress)
8888
{
8989
}
90+
91+
// Ignores egl functions.
92+
// On some Linux systems, glXGetProcAddress will return valid pointers for even EGL functions.
93+
// This makes Skia try to load some data from EGL,
94+
// which can then cause segmentation faults because they return garbage.
95+
public static IntPtr SafeGetProcAddress(string proc, bool optional)
96+
{
97+
if (proc.StartsWith("egl", StringComparison.InvariantCulture))
98+
{
99+
return IntPtr.Zero;
100+
}
101+
102+
return GlxConverted(proc, optional);
103+
}
104+
105+
private static readonly Func<string, bool, IntPtr> GlxConverted = ConvertNative(GlxGetProcAddress);
90106
}
91107
}

src/Avalonia.X11/Glx/GlxDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public GlxDisplay(X11Info x11)
8787
ImmediateContext.MakeCurrent();
8888
var err = Glx.GetError();
8989

90-
GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
90+
GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
9191
if (GlInterface.Version == null)
9292
throw new OpenGlException("GL version string is null, aborting");
9393
if (GlInterface.Renderer == null)

src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public Binding ProvideValue(IServiceProvider serviceProvider)
4141
StringFormat = StringFormat,
4242
RelativeSource = RelativeSource,
4343
DefaultAnchor = new WeakReference(GetDefaultAnchor(descriptorContext)),
44+
TargetNullValue = TargetNullValue,
4445
NameScope = new WeakReference<INameScope>(serviceProvider.GetService<INameScope>())
4546
};
4647
}
@@ -86,5 +87,7 @@ private static object GetDefaultAnchor(IServiceProvider context)
8687
public string StringFormat { get; set; }
8788

8889
public RelativeSource RelativeSource { get; set; }
90+
91+
public object TargetNullValue { get; set; } = AvaloniaProperty.UnsetValue;
8992
}
9093
}

0 commit comments

Comments
 (0)