Skip to content

Commit

Permalink
Merge branch 'master' into fixes/3323-resourcedictionary-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys authored Dec 19, 2019
2 parents 01c1669 + e48bbe6 commit e41c586
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 36 deletions.
24 changes: 16 additions & 8 deletions native/Avalonia.Native/src/OSX/gl.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common.h"
#include <OpenGL/gl.h>
#include <dlfcn.h>
#include "window.h"

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

class AvnGlRenderingSession : public ComSingleObject<IAvnGlSurfaceRenderingSession, &IID_IAvnGlSurfaceRenderingSession>
{
NSView* _view;
NSWindow* _window;
AvnView* _view;
AvnWindow* _window;
NSOpenGLContext* _context;
public:
FORWARD_IUNKNOWN()
AvnGlRenderingSession(NSWindow*window, NSView* view, NSOpenGLContext* context)
AvnGlRenderingSession(AvnWindow*window, AvnView* view, NSOpenGLContext* context)
{
_context = context;
_window = window;
Expand All @@ -195,14 +196,12 @@ virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override

virtual HRESULT GetPixelSize(AvnPixelSize* ret) override
{
auto fsize = [_view convertSizeToBacking: [_view frame].size];
ret->Width = (int)fsize.width;
ret->Height = (int)fsize.height;
*ret = [_view getPixelSize];
return S_OK;
}
virtual HRESULT GetScaling(double* ret) override
{
*ret = [_window backingScaleFactor];
*ret = [_window getScaling];
return S_OK;
}

Expand Down Expand Up @@ -234,8 +233,17 @@ virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) override
auto f = GetFeature();
if(f == NULL)
return E_FAIL;
if(![_view lockFocusIfCanDraw])

@try
{
if(![_view lockFocusIfCanDraw])
return E_ABORT;
}
@catch(NSException* exception)
{
return E_ABORT;
}


auto gl = _context;
CGLLockContext([_context CGLContextObj]);
Expand Down
2 changes: 2 additions & 0 deletions native/Avalonia.Native/src/OSX/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class WindowBaseImpl;
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose;
-(void) onClosed;
-(AvnPixelSize) getPixelSize;
@end

@interface AvnWindow : NSWindow <NSWindowDelegate>
Expand All @@ -22,6 +23,7 @@ class WindowBaseImpl;
-(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents;
-(void) applyMenu:(NSMenu *)menu;
-(double) getScaling;
@end

struct INSWindowHolder
Expand Down
89 changes: 65 additions & 24 deletions native/Avalonia.Native/src/OSX/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ virtual HRESULT Close() override
{
@autoreleasepool
{
[Window close];
if (Window != nullptr)
{
[Window close];
}

return S_OK;
}
}
Expand Down Expand Up @@ -291,7 +295,14 @@ virtual bool TryLock() override
{
@autoreleasepool
{
return [View lockFocusIfCanDraw] == YES;
@try
{
return [View lockFocusIfCanDraw] == YES;
}
@catch (NSException*)
{
return NO;
}
}
}

Expand Down Expand Up @@ -719,15 +730,33 @@ @implementation AvnView
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed, _isMouseOver;
NSEvent* _lastMouseDownEvent;
bool _lastKeyHandled;
AvnPixelSize _lastPixelSize;
}

- (void)dealloc
- (void)onClosed
{
@synchronized (self)
{
_parent = nullptr;
}
}

- (void)onClosed
- (BOOL)lockFocusIfCanDraw
{
@synchronized (self)
{
if(_parent == nullptr)
{
return NO;
}
}

return [super lockFocusIfCanDraw];
}

-(AvnPixelSize) getPixelSize
{
_parent = NULL;
return _lastPixelSize;
}

- (NSEvent*) lastMouseDownEvent
Expand All @@ -742,6 +771,8 @@ -(AvnView*) initWithParent: (WindowBaseImpl*) parent
[self setWantsLayer:YES];
_parent = parent;
_area = nullptr;
_lastPixelSize.Height = 100;
_lastPixelSize.Width = 100;
return self;
}

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

_parent->UpdateCursor();

auto fsize = [self convertSizeToBacking: [self frame].size];
_lastPixelSize.Width = (int)fsize.width;
_lastPixelSize.Height = (int)fsize.height;

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

- (void)drawRect:(NSRect)dirtyRect
{
if (_parent == nullptr)
{
return;
}

_parent->BaseEvents->RunRenderPriorityJobs();

@synchronized (self) {
if(_swRenderedFrame != NULL)
{
Expand Down Expand Up @@ -879,7 +920,12 @@ - (AvnPoint)toAvnPoint:(CGPoint)p

- (void) viewDidChangeBackingProperties
{
auto fsize = [self convertSizeToBacking: [self frame].size];
_lastPixelSize.Width = (int)fsize.width;
_lastPixelSize.Height = (int)fsize.height;

_parent->BaseEvents->ScalingChanged([_parent->Window backingScaleFactor]);

[super viewDidChangeBackingProperties];
}

Expand Down Expand Up @@ -1161,6 +1207,12 @@ @implementation AvnWindow
bool _closed;
NSMenu* _menu;
bool _isAppMenuApplied;
double _lastScaling;
}

-(double) getScaling
{
return _lastScaling;
}

+(void)closeAll
Expand All @@ -1174,10 +1226,6 @@ +(void)closeAll
}
}

- (void)dealloc
{
}

- (void)pollModalSession:(nonnull NSModalSession)session
{
auto response = [NSApp runModalSession:session];
Expand Down Expand Up @@ -1232,6 +1280,9 @@ -(AvnWindow*) initWithParent: (WindowBaseImpl*) parent
[self setReleasedWhenClosed:false];
_parent = parent;
[self setDelegate:self];
_closed = false;

_lastScaling = [self backingScaleFactor];
return self;
}

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

- (void)windowDidChangeBackingProperties:(NSNotification *)notification
{
_lastScaling = [self backingScaleFactor];
}

- (void)windowWillClose:(NSNotification *)notification
{
_closed = true;
Expand All @@ -1257,9 +1313,6 @@ - (void)windowWillClose:(NSNotification *)notification
[self restoreParentWindow];
parent->BaseEvents->Closed();
[parent->View onClosed];
dispatch_async(dispatch_get_main_queue(), ^{
[self setContentView: nil];
});
}
}

Expand Down Expand Up @@ -1406,18 +1459,6 @@ - (void)windowDidMove:(NSNotification *)notification
_parent->GetPosition(&position);
_parent->BaseEvents->PositionChanged(position);
}

// TODO this breaks resizing.
/*- (void)windowDidResize:(NSNotification *)notification
{
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
if(parent != nullptr)
{
parent->WindowStateChanged();
}
}*/
@end

class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static void ConfigurePosition(ref this PopupPositionerParameters position
if (placement == PlacementMode.Pointer)
{
positionerParameters.AnchorRectangle = new Rect(pointer, new Size(1, 1));
positionerParameters.Anchor = PopupPositioningEdge.BottomRight;
positionerParameters.Anchor = PopupPositioningEdge.TopLeft;
positionerParameters.Gravity = PopupPositioningEdge.BottomRight;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/Avalonia.Controls/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,10 @@ private async void Paste()
{
return;
}

_undoRedoHelper.Snapshot();
HandleTextInput(text);
_undoRedoHelper.Snapshot();
}

protected override void OnKeyDown(KeyEventArgs e)
Expand Down
3 changes: 2 additions & 1 deletion src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private void Poll(long _)

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

var labelDirEnum = Directory.Exists(DevByLabelDir) ?
new DirectoryInfo(DevByLabelDir).GetFiles() : Enumerable.Empty<FileInfo>();
Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Native/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ public void SetTopmost(bool value)

public void SetCursor(IPlatformHandle cursor)
{
if (_native == null)
{
return;
}

var newCursor = cursor as AvaloniaNativeCursor;
newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor);
_native.Cursor = newCursor.Cursor;
Expand Down
18 changes: 17 additions & 1 deletion src/Avalonia.X11/Glx/Glx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,24 @@ public delegate IntPtr GlxCreateContextAttribsARB(IntPtr dpy, IntPtr fbconfig, I
[GlEntryPoint("glGetError")]
public GlGetError GetError { get; }

public GlxInterface() : base(GlxGetProcAddress)
public GlxInterface() : base(SafeGetProcAddress)
{
}

// Ignores egl functions.
// On some Linux systems, glXGetProcAddress will return valid pointers for even EGL functions.
// This makes Skia try to load some data from EGL,
// which can then cause segmentation faults because they return garbage.
public static IntPtr SafeGetProcAddress(string proc, bool optional)
{
if (proc.StartsWith("egl", StringComparison.InvariantCulture))
{
return IntPtr.Zero;
}

return GlxConverted(proc, optional);
}

private static readonly Func<string, bool, IntPtr> GlxConverted = ConvertNative(GlxGetProcAddress);
}
}
2 changes: 1 addition & 1 deletion src/Avalonia.X11/Glx/GlxDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public GlxDisplay(X11Info x11)
ImmediateContext.MakeCurrent();
var err = Glx.GetError();

GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
if (GlInterface.Version == null)
throw new OpenGlException("GL version string is null, aborting");
if (GlInterface.Renderer == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public Binding ProvideValue(IServiceProvider serviceProvider)
StringFormat = StringFormat,
RelativeSource = RelativeSource,
DefaultAnchor = new WeakReference(GetDefaultAnchor(descriptorContext)),
TargetNullValue = TargetNullValue,
NameScope = new WeakReference<INameScope>(serviceProvider.GetService<INameScope>())
};
}
Expand Down Expand Up @@ -86,5 +87,7 @@ private static object GetDefaultAnchor(IServiceProvider context)
public string StringFormat { get; set; }

public RelativeSource RelativeSource { get; set; }

public object TargetNullValue { get; set; } = AvaloniaProperty.UnsetValue;
}
}
Loading

0 comments on commit e41c586

Please sign in to comment.