Skip to content

Commit 3fe6604

Browse files
authored
Merge branch 'master' into pt/minor-xml-doc-fix
2 parents 6229975 + f782bab commit 3fe6604

File tree

60 files changed

+1343
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1343
-255
lines changed

Avalonia.Desktop.slnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"src\\Avalonia.Dialogs\\Avalonia.Dialogs.csproj",
2525
"src\\Avalonia.Fonts.Inter\\Avalonia.Fonts.Inter.csproj",
2626
"src\\Avalonia.FreeDesktop\\Avalonia.FreeDesktop.csproj",
27+
"src\\Avalonia.Metal\\Avalonia.Metal.csproj",
2728
"src\\Avalonia.MicroCom\\Avalonia.MicroCom.csproj",
2829
"src\\Avalonia.Native\\Avalonia.Native.csproj",
2930
"src\\Avalonia.OpenGL\\Avalonia.OpenGL.csproj",

Avalonia.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Headless.XUnit.Uni
274274
EndProject
275275
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MobileSandbox.Browser", "samples\MobileSandbox.Browser\MobileSandbox.Browser.csproj", "{43FCC14E-EEBE-44B3-BCBC-F1C537EECBF8}"
276276
EndProject
277+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Metal", "src\Avalonia.Metal\Avalonia.Metal.csproj", "{60B4ED1F-ECFA-453B-8A70-1788261C8355}"
278+
EndProject
277279
Global
278280
GlobalSection(SolutionConfigurationPlatforms) = preSolution
279281
Debug|Any CPU = Debug|Any CPU
@@ -661,6 +663,10 @@ Global
661663
{43FCC14E-EEBE-44B3-BCBC-F1C537EECBF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
662664
{43FCC14E-EEBE-44B3-BCBC-F1C537EECBF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
663665
{43FCC14E-EEBE-44B3-BCBC-F1C537EECBF8}.Release|Any CPU.Build.0 = Release|Any CPU
666+
{60B4ED1F-ECFA-453B-8A70-1788261C8355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
667+
{60B4ED1F-ECFA-453B-8A70-1788261C8355}.Debug|Any CPU.Build.0 = Debug|Any CPU
668+
{60B4ED1F-ECFA-453B-8A70-1788261C8355}.Release|Any CPU.ActiveCfg = Release|Any CPU
669+
{60B4ED1F-ECFA-453B-8A70-1788261C8355}.Release|Any CPU.Build.0 = Release|Any CPU
664670
EndGlobalSection
665671
GlobalSection(SolutionProperties) = preSolution
666672
HideSolutionNode = FALSE

build/CoreLibraries.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Controls/Avalonia.Controls.csproj" />
55
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj" />
66
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.OpenGL/Avalonia.OpenGL.csproj" />
7+
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Metal/Avalonia.Metal.csproj" />
78
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.Dialogs/Avalonia.Dialogs.csproj" />
89
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup/Avalonia.Markup.csproj" />
910
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj" />

native/Avalonia.Native/inc/com.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef DWORD ULONG;
2828
#define E_UNEXPECTED 0x8000FFFFL
2929
#define E_HANDLE 0x80070006L
3030
#define E_INVALIDARG 0x80070057L
31+
#define COR_E_INVALIDOPERATION 0x80131509L
3132

3233
struct IUnknown
3334
{

native/Avalonia.Native/inc/comimpl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ class ComPtr
4343
_obj->AddRef();
4444
}
4545
}
46+
47+
ComPtr(TInterface* pObj, bool ownsHandle)
48+
{
49+
_obj = 0;
50+
51+
if (pObj)
52+
{
53+
_obj = pObj;
54+
if(!ownsHandle)
55+
_obj->AddRef();
56+
}
57+
}
4658

4759
ComPtr(const ComPtr& ptr)
4860
{
@@ -92,6 +104,13 @@ class ComPtr
92104
{
93105
return &_obj;
94106
}
107+
108+
void setNoAddRef(TInterface* value)
109+
{
110+
if(_obj != nullptr)
111+
_obj->Release();
112+
_obj = value;
113+
}
95114

96115
operator TInterface*() const
97116
{

native/Avalonia.Native/inc/noarc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <AppKit/AppKit.h>
2+
3+
class CppAutoreleasePool
4+
{
5+
void* _pool;
6+
public:
7+
CppAutoreleasePool();
8+
~CppAutoreleasePool();
9+
};
10+
11+
#define START_ARP_CALL CppAutoreleasePool __autoreleasePool

native/Avalonia.Native/inc/rendertarget.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
#include "avalonia-native.h"
66

77
@protocol IRenderTarget
8-
-(void) setNewLayer: (CALayer*) layer;
9-
-(HRESULT) setSwFrame: (AvnFramebuffer*) fb;
8+
109
-(void) resize: (AvnPixelSize) size withScale: (float) scale;
11-
-(AvnPixelSize) pixelSize;
12-
-(IAvnGlSurfaceRenderTarget*) createSurfaceRenderTarget;
10+
-(CALayer*) layer;
11+
1312
@end
1413

1514
@interface IOSurfaceRenderTarget : NSObject<IRenderTarget>
1615
-(IOSurfaceRenderTarget*) initWithOpenGlContext: (IAvnGlContext*) context;
16+
-(IAvnGlSurfaceRenderTarget*) createSurfaceRenderTarget;
17+
-(IAvnSoftwareRenderTarget*) createSoftwareRenderTarget;
18+
-(HRESULT) setSwFrame: (AvnFramebuffer*) fb;
19+
-(void)consumeSurfaces;
1720
@end
21+
22+
@interface MetalRenderTarget : NSObject<IRenderTarget>
23+
-(MetalRenderTarget*) initWithDevice: (IAvnMetalDevice*) device;
24+
-(void) getRenderTarget: (IAvnMetalRenderTarget**) ppv;
25+
@end

native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
523484CA26EA688F00EA0C2C /* trayicon.mm in Sources */ = {isa = PBXBuildFile; fileRef = 523484C926EA688F00EA0C2C /* trayicon.mm */; };
4444
5B21A982216530F500CEE36E /* cursor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B21A981216530F500CEE36E /* cursor.mm */; };
4545
5B8BD94F215BFEA6005ED2A7 /* clipboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */; };
46+
64B1EA48E308E574685AFB07 /* metal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 64B1EBEECBE13D8616D7C934 /* metal.mm */; };
47+
64B1ECA861163C0EFF0E502B /* noarc.h in Headers */ = {isa = PBXBuildFile; fileRef = 64B1E26F2B1B9C577BF52F06 /* noarc.h */; };
48+
64B1ED7C5433AC3B815FFCC5 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64B1E23CAFE5FEC7AD981B1B /* Metal.framework */; };
49+
64B1EE5DD4D882D587CE76CE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64B1E677F7791226F783ACE4 /* CoreGraphics.framework */; };
50+
64B1EF3C757B71526FFAF436 /* noarc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 64B1E4FA7D9D6E5F47AA8606 /* noarc.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
4651
855EDC9F28C6546F00807998 /* PlatformBehaviorInhibition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 855EDC9E28C6546F00807998 /* PlatformBehaviorInhibition.mm */; };
4752
8D2F3512292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D2F3511292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h */; };
4853
8D300D65292D0A6800320C49 /* AvnTextInputMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D300D64292D0A6800320C49 /* AvnTextInputMethod.h */; };
@@ -99,6 +104,11 @@
99104
5B21A981216530F500CEE36E /* cursor.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = cursor.mm; sourceTree = "<group>"; };
100105
5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; sourceTree = "<group>"; };
101106
5BF943652167AD1D009CAE35 /* cursor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cursor.h; sourceTree = "<group>"; };
107+
64B1E23CAFE5FEC7AD981B1B /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
108+
64B1E26F2B1B9C577BF52F06 /* noarc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = noarc.h; path = ../../inc/noarc.h; sourceTree = "<group>"; };
109+
64B1E4FA7D9D6E5F47AA8606 /* noarc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = noarc.mm; sourceTree = "<group>"; };
110+
64B1E677F7791226F783ACE4 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
111+
64B1EBEECBE13D8616D7C934 /* metal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = metal.mm; sourceTree = "<group>"; };
102112
855EDC9E28C6546F00807998 /* PlatformBehaviorInhibition.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformBehaviorInhibition.mm; sourceTree = "<group>"; };
103113
8D2F3511292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AvnTextInputMethodDelegate.h; sourceTree = "<group>"; };
104114
8D300D64292D0A6800320C49 /* AvnTextInputMethod.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AvnTextInputMethod.h; sourceTree = "<group>"; };
@@ -126,6 +136,8 @@
126136
AB1E522C217613570091CD71 /* OpenGL.framework in Frameworks */,
127137
522D5959258159C1006F7F7A /* Carbon.framework in Frameworks */,
128138
AB661C1E2148230F00291242 /* AppKit.framework in Frameworks */,
139+
64B1ED7C5433AC3B815FFCC5 /* Metal.framework in Frameworks */,
140+
64B1EE5DD4D882D587CE76CE /* CoreGraphics.framework in Frameworks */,
129141
);
130142
runOnlyForDeploymentPostprocessing = 0;
131143
};
@@ -141,6 +153,8 @@
141153
1A3E5EA923E9F26C00EDE661 /* IOSurface.framework */,
142154
AB1E522B217613570091CD71 /* OpenGL.framework */,
143155
AB661C1D2148230F00291242 /* AppKit.framework */,
156+
64B1E23CAFE5FEC7AD981B1B /* Metal.framework */,
157+
64B1E677F7791226F783ACE4 /* CoreGraphics.framework */,
144158
);
145159
name = Frameworks;
146160
sourceTree = "<group>";
@@ -198,6 +212,9 @@
198212
18391DB45C7D892E61BF388C /* WindowInterfaces.h */,
199213
18391BB698579F40F1783F31 /* PopupImpl.mm */,
200214
183910513F396141938832B5 /* PopupImpl.h */,
215+
64B1EBEECBE13D8616D7C934 /* metal.mm */,
216+
64B1E4FA7D9D6E5F47AA8606 /* noarc.mm */,
217+
64B1E26F2B1B9C577BF52F06 /* noarc.h */,
201218
);
202219
sourceTree = "<group>";
203220
};
@@ -230,6 +247,7 @@
230247
18391F1E2411C79405A9943A /* WindowProtocol.h in Headers */,
231248
183914E50CF6D2EFC1667F7C /* WindowInterfaces.h in Headers */,
232249
18391AC65ADD7DDD33FBE737 /* PopupImpl.h in Headers */,
250+
64B1ECA861163C0EFF0E502B /* noarc.h in Headers */,
233251
);
234252
runOnlyForDeploymentPostprocessing = 0;
235253
};
@@ -319,6 +337,8 @@
319337
18391AC16726CBC45856233B /* AvnWindow.mm in Sources */,
320338
18391D8CD1756DC858DC1A09 /* PopupImpl.mm in Sources */,
321339
EDF8CDCD2964CB01001EE34F /* PlatformSettings.mm in Sources */,
340+
64B1EA48E308E574685AFB07 /* metal.mm in Sources */,
341+
64B1EF3C757B71526FFAF436 /* noarc.mm in Sources */,
322342
);
323343
runOnlyForDeploymentPostprocessing = 0;
324344
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
#include "KeyTransform.h"
1212

1313
@class AvnAccessibilityElement;
14+
@protocol IRenderTarget;
1415

15-
@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination, AvnTextInputMethodDelegate>
16+
@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination, AvnTextInputMethodDelegate, CALayerDelegate>
1617
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
1718
-(NSEvent* _Nonnull) lastMouseDownEvent;
1819
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
19-
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose;
2020
-(void) onClosed;
2121

2222
-(AvnPlatformResizeReason) getResizeReason;
2323
-(void) setResizeReason:(AvnPlatformResizeReason)reason;
24+
-(void) setRenderTarget:(NSObject<IRenderTarget>*)target;
2425
+ (AvnPoint)toAvnPoint:(CGPoint)p;
2526
@end

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ @implementation AvnView
1717
NSEvent* _lastMouseDownEvent;
1818
bool _lastKeyHandled;
1919
AvnPixelSize _lastPixelSize;
20-
NSObject<IRenderTarget>* _renderTarget;
20+
NSObject<IRenderTarget>* _currentRenderTarget;
2121
AvnPlatformResizeReason _resizeReason;
2222
AvnAccessibilityElement* _accessibilityChild;
2323
NSRect _cursorRect;
@@ -41,15 +41,39 @@ - (NSEvent*) lastMouseDownEvent
4141

4242
- (void) updateRenderTarget
4343
{
44-
[_renderTarget resize:_lastPixelSize withScale:static_cast<float>([[self window] backingScaleFactor])];
45-
[self setNeedsDisplayInRect:[self frame]];
44+
if(_currentRenderTarget) {
45+
[_currentRenderTarget resize:_lastPixelSize withScale:static_cast<float>([[self window] backingScaleFactor])];
46+
[self setNeedsDisplayInRect:[self frame]];
47+
}
48+
}
49+
50+
51+
-(void) setRenderTarget:(NSObject<IRenderTarget>*)target
52+
{
53+
if([self layer])
54+
{
55+
[self layer].delegate = nil;
56+
}
57+
_currentRenderTarget = target;
58+
auto layer = [target layer];
59+
[self setLayer: layer];
60+
[layer setDelegate: self];
61+
layer.needsDisplayOnBoundsChange = YES;
62+
[self updateRenderTarget];
63+
}
64+
65+
-(void)displayLayer: (CALayer*)layer
66+
{
67+
[self updateLayer];
4668
}
4769

4870
-(AvnView*) initWithParent: (WindowBaseImpl*) parent
4971
{
5072
self = [super init];
51-
_renderTarget = parent->renderTarget;
5273
[self setWantsLayer:YES];
74+
[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
75+
76+
[self setCanDrawSubviewsIntoLayer: NO];
5377
[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
5478

5579
_parent = parent;
@@ -77,12 +101,6 @@ - (BOOL)wantsUpdateLayer
77101
return YES;
78102
}
79103

80-
- (void)setLayer:(CALayer *)layer
81-
{
82-
[_renderTarget setNewLayer: layer];
83-
[super setLayer: layer];
84-
}
85-
86104
- (BOOL)isOpaque
87105
{
88106
return YES;
@@ -164,14 +182,6 @@ - (void)drawRect:(NSRect)dirtyRect
164182
return;
165183
}
166184

167-
-(void) setSwRenderedFrame: (AvnFramebuffer*) fb dispose: (IUnknown*) dispose
168-
{
169-
@autoreleasepool {
170-
[_renderTarget setSwFrame:fb];
171-
dispose->Release();
172-
}
173-
}
174-
175185
- (AvnPoint) translateLocalPoint:(AvnPoint)pt
176186
{
177187
pt.Y = [self bounds].size.height - pt.Y;

0 commit comments

Comments
 (0)