1831 changed files with 91083 additions and 19122 deletions
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,130 @@ |
|||
|
|||
# Contributor Covenant Code of Conduct |
|||
|
|||
## Our Pledge |
|||
|
|||
We as members, contributors, and leaders pledge to make participation in our |
|||
community a harassment-free experience for everyone, regardless of age, body |
|||
size, visible or invisible disability, ethnicity, sex characteristics, gender |
|||
identity and expression, level of experience, education, socio-economic status, |
|||
nationality, personal appearance, race, religion, or sexual identity |
|||
and orientation. |
|||
|
|||
We pledge to act and interact in ways that contribute to an open, welcoming, |
|||
diverse, inclusive, and healthy community. |
|||
|
|||
## Our Standards |
|||
|
|||
Examples of behavior that contributes to a positive environment for our |
|||
community include: |
|||
|
|||
* Demonstrating empathy and kindness toward other people |
|||
* Being respectful of differing opinions, viewpoints, and experiences |
|||
* Giving and gracefully accepting constructive feedback |
|||
* Accepting responsibility and apologizing to those affected by our mistakes, |
|||
and learning from the experience |
|||
* Focusing on what is best not just for us as individuals, but for the |
|||
overall community |
|||
|
|||
Examples of unacceptable behavior include: |
|||
|
|||
* The use of sexualized language or imagery, and sexual attention or |
|||
advances of any kind |
|||
* Trolling, insulting or derogatory comments, and personal or political attacks |
|||
* Public or private harassment |
|||
* Publishing others' private information, such as a physical or email |
|||
address, without their explicit permission |
|||
* Other conduct which could reasonably be considered inappropriate in a |
|||
professional setting |
|||
|
|||
## Enforcement Responsibilities |
|||
|
|||
Community leaders are responsible for clarifying and enforcing our standards of |
|||
acceptable behavior and will take appropriate and fair corrective action in |
|||
response to any behavior that they deem inappropriate, threatening, offensive, |
|||
or harmful. |
|||
|
|||
Community leaders have the right and responsibility to remove, edit, or reject |
|||
comments, commits, code, wiki edits, issues, and other contributions that are |
|||
not aligned to this Code of Conduct, and will communicate reasons for moderation |
|||
decisions when appropriate. |
|||
|
|||
## Scope |
|||
|
|||
This Code of Conduct applies within all community spaces, and also applies when |
|||
an individual is officially representing the community in public spaces. |
|||
Examples of representing our community include using an official e-mail address, |
|||
posting via an official social media account, or acting as an appointed |
|||
representative at an online or offline event. |
|||
|
|||
## Enforcement |
|||
|
|||
Instances of abusive, harassing, or otherwise unacceptable behavior may be |
|||
reported to the community leaders responsible for enforcement at |
|||
steven@avaloniaui.net. |
|||
All complaints will be reviewed and investigated promptly and fairly. |
|||
|
|||
All community leaders are obligated to respect the privacy and security of the |
|||
reporter of any incident. |
|||
|
|||
## Enforcement Guidelines |
|||
|
|||
Community leaders will follow these Community Impact Guidelines in determining |
|||
the consequences for any action they deem in violation of this Code of Conduct: |
|||
|
|||
### 1. Correction |
|||
|
|||
**Community Impact**: Use of inappropriate language or other behavior deemed |
|||
unprofessional or unwelcome in the community. |
|||
|
|||
**Consequence**: A private, written warning from community leaders, providing |
|||
clarity around the nature of the violation and an explanation of why the |
|||
behavior was inappropriate. A public apology may be requested. |
|||
|
|||
### 2. Warning |
|||
|
|||
**Community Impact**: A violation through a single incident or series |
|||
of actions. |
|||
|
|||
**Consequence**: A warning with consequences for continued behavior. No |
|||
interaction with the people involved, including unsolicited interaction with |
|||
those enforcing the Code of Conduct, for a specified period of time. This |
|||
includes avoiding interactions in community spaces as well as external channels |
|||
like social media. Violating these terms may lead to a temporary or |
|||
permanent ban. |
|||
|
|||
### 3. Temporary Ban |
|||
|
|||
**Community Impact**: A serious violation of community standards, including |
|||
sustained inappropriate behavior. |
|||
|
|||
**Consequence**: A temporary ban from any sort of interaction or public |
|||
communication with the community for a specified period of time. No public or |
|||
private interaction with the people involved, including unsolicited interaction |
|||
with those enforcing the Code of Conduct, is allowed during this period. |
|||
Violating these terms may lead to a permanent ban. |
|||
|
|||
### 4. Permanent Ban |
|||
|
|||
**Community Impact**: Demonstrating a pattern of violation of community |
|||
standards, including sustained inappropriate behavior, harassment of an |
|||
individual, or aggression toward or disparagement of classes of individuals. |
|||
|
|||
**Consequence**: A permanent ban from any sort of public interaction within |
|||
the community. |
|||
|
|||
## Attribution |
|||
|
|||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], |
|||
version 2.0, available at |
|||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. |
|||
|
|||
Community Impact Guidelines were inspired by [Mozilla's code of conduct |
|||
enforcement ladder](https://github.com/mozilla/diversity). |
|||
|
|||
[homepage]: https://www.contributor-covenant.org |
|||
|
|||
For answers to common questions about this code of conduct, see the FAQ at |
|||
https://www.contributor-covenant.org/faq. Translations are available at |
|||
https://www.contributor-covenant.org/translations. |
|||
|
|||
@ -0,0 +1,69 @@ |
|||
# Contributing to Avalonia |
|||
|
|||
## Before You Start |
|||
|
|||
Drop into our [gitter chat room](https://gitter.im/AvaloniaUI/Avalonia) and let us know what you're thinking of doing. We might be able to give you guidance or let you know if someone else is already working on the feature. |
|||
|
|||
## Style |
|||
|
|||
The codebase uses [.net core](https://github.com/dotnet/runtime/blob/master/docs/coding-guidelines/coding-style.md) coding style. |
|||
|
|||
Try to keep lines of code around 100 characters in length or less, though this is not a hard limit. |
|||
If you're a few characters over then don't worry too much. |
|||
|
|||
**DO NOT USE #REGIONS** full stop. |
|||
|
|||
## Pull requests |
|||
|
|||
A single pull request should be submitted for each change. If you're making more than one change, |
|||
please submit separate pull requests for each change for easy review. Rebase your changes to make |
|||
sense, so a history that looks like: |
|||
|
|||
* Add class A |
|||
* Feature A didn't set Foo when Bar was set |
|||
* Fix spacing |
|||
* Add class B |
|||
* Sort using statements |
|||
|
|||
Should be rebased to read: |
|||
|
|||
* Add class A |
|||
* Add class B |
|||
|
|||
Again, this makes review much easier. |
|||
|
|||
Please try not to submit pull requests that don't add new features (e.g. moving stuff around) |
|||
unless you see something that is obviously wrong or that could be written in a more terse or |
|||
idiomatic style. It takes time to review each pull request - time that I'd prefer to spend writing |
|||
new features! |
|||
|
|||
Prefer terseness to verbosity but don't try to be too clever. |
|||
|
|||
## Tests |
|||
|
|||
There are two types of tests currently in the codebase; unit tests and render tests. |
|||
|
|||
Unit tests should be contained in a class name that mirrors the class being tested with the suffix |
|||
-Tests, e.g. |
|||
|
|||
Avalonia.Controls.UnitTests.Presenters.TextPresenterTests |
|||
|
|||
Where Avalonia.Controls.UnitTests is the name of the project. |
|||
|
|||
Unit test methods should be named in a sentence style, separated by underscores, that describes in |
|||
English what the test is testing, e.g. |
|||
|
|||
```csharp |
|||
void Calling_Foo_Should_Increment_Bar() |
|||
``` |
|||
|
|||
Render tests should describe what the produced image is: |
|||
|
|||
```csharp |
|||
void Rectangle_2px_Stroke_Filled() |
|||
``` |
|||
|
|||
## Code of Conduct |
|||
|
|||
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. |
|||
For more information see the [Contributor Covenant Code of Conduct](https://dotnetfoundation.org/code-of-conduct) |
|||
@ -0,0 +1,79 @@ |
|||
# Windows |
|||
|
|||
Avalonia requires at least Visual Studio 2019 and .NET Core SDK 3.1 to build on Windows. |
|||
|
|||
### Clone the Avalonia repository |
|||
|
|||
``` |
|||
git clone https://github.com/AvaloniaUI/Avalonia.git |
|||
git submodule update --init |
|||
``` |
|||
|
|||
### Open in Visual Studio |
|||
|
|||
Open the `Avalonia.sln` solution in Visual Studio 2019 or newer. The free Visual Studio Community |
|||
edition works fine. Run the `Samples\ControlCatalog.Desktop` project to see the sample application. |
|||
|
|||
# Linux/macOS |
|||
|
|||
It's *not* possible to build the *whole* project on Linux/macOS. You can only build the subset targeting .NET Standard and .NET Core (which is, however, sufficient to get UI working on Linux/macOS). If you want to something that involves changing platform-specific APIs you'll need a Windows machine. |
|||
|
|||
MonoDevelop, Xamarin Studio and Visual Studio for Mac aren't capable of properly opening our solution. You can use Rider (at least 2017.2 EAP) or VSCode instead. They will fail to load most of platform specific projects, but you don't need them to run on .NET Core. |
|||
|
|||
### Install the latest version of .NET Core |
|||
|
|||
Go to https://www.microsoft.com/net/core and follow instructions for your OS. You need SDK (not just "runtime") package. |
|||
|
|||
### Additional requirements for macOS |
|||
|
|||
The build process needs [Xcode](https://developer.apple.com/xcode/) to build the native library. Following the install instructions at the [Xcode](https://developer.apple.com/xcode/) website to properly install. |
|||
|
|||
Linux operating systems ship with their own respective package managers however we will use [Homebrew](https://brew.sh/) to manage packages on macOS. To install follow the instructions [here](https://docs.brew.sh/Installation). |
|||
|
|||
### Install CastXML |
|||
|
|||
Avalonia requires [CastXML](https://github.com/CastXML/CastXML) for XML processing during the build process. The easiest way to install this is via the operating system's package managers, such as below. |
|||
|
|||
On macOS: |
|||
``` |
|||
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8a004a91a7fcd3f6620d5b01b6541ff0a640ffba/Formula/castxml.rb |
|||
``` |
|||
|
|||
On Debian based Linux (Debian, Ubuntu, Mint, etc): |
|||
``` |
|||
sudo apt install castxml |
|||
``` |
|||
|
|||
On Red Hat based Linux (Fedora, CentOS, RHEL, etc) using `yum` (`dnf` takes same arguments though): |
|||
``` |
|||
sudo yum install castxml |
|||
``` |
|||
|
|||
|
|||
### Clone the Avalonia repository |
|||
|
|||
``` |
|||
git clone https://github.com/AvaloniaUI/Avalonia.git |
|||
cd Avalonia |
|||
git submodule update --init --recursive |
|||
``` |
|||
|
|||
### Build native libraries (macOS only) |
|||
|
|||
On macOS it is necessary to build and manually install the respective native libraries using [Xcode](https://developer.apple.com/xcode/). The steps to get this working correctly are: |
|||
- Navigate to the Avalonia/native/Avalonia.Native/src/OSX folder and open the `Avalonia.Native.OSX.xcodeproj` project |
|||
- Build the library via the Product->Build menu. This will generate binaries in your local path under ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-*guid* where "guid" is uniquely generated every time you build. |
|||
- Manually install the native library by copying it from the build artifacts folder into the shared dynamic library path: |
|||
|
|||
``` |
|||
cd ~/Library/Developer/Xcode/DerivedData/Avalonia.Native.OSX-[guid]/Build/Products/Debug |
|||
cp libAvalonia.Native.OSX.dylib /usr/local/lib/libAvaloniaNative.dylib |
|||
``` |
|||
|
|||
### Build and Run Avalonia |
|||
|
|||
``` |
|||
cd samples/ControlCatalog.NetCore |
|||
dotnet restore |
|||
dotnet run |
|||
``` |
|||
@ -0,0 +1,305 @@ |
|||
# WPF |
|||
|
|||
https://github.com/dotnet/wpf |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) .NET Foundation and Contributors |
|||
|
|||
All rights reserved. |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
|
|||
# SharpDX |
|||
|
|||
https://github.com/sharpdx/SharpDX |
|||
|
|||
Copyright (c) 2010-2014 SharpDX - Alexandre Mutel |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in |
|||
all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
THE SOFTWARE. |
|||
|
|||
# Silverlight Toolkit |
|||
|
|||
https://github.com/microsoftarchive/SilverlightToolkit |
|||
|
|||
Microsoft Public License (MS-PL) |
|||
|
|||
This license governs use of the accompanying software. If you use the software, you |
|||
accept this license. If you do not accept the license, do not use the software. |
|||
|
|||
1. Definitions |
|||
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the |
|||
same meaning here as under U.S. copyright law. |
|||
A "contribution" is the original software, or any additions or changes to the software. |
|||
A "contributor" is any person that distributes its contribution under this license. |
|||
"Licensed patents" are a contributor's patent claims that read directly on its contribution. |
|||
|
|||
2. Grant of Rights |
|||
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. |
|||
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. |
|||
|
|||
3. Conditions and Limitations |
|||
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. |
|||
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. |
|||
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. |
|||
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. |
|||
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. |
|||
|
|||
# wayland-protocols |
|||
|
|||
https://github.com/wayland-project/wayland-protocols |
|||
|
|||
Copyright © 2008-2013 Kristian Høgsberg |
|||
Copyright © 2010-2013 Intel Corporation |
|||
Copyright © 2013 Rafael Antognolli |
|||
Copyright © 2013 Jasper St. Pierre |
|||
Copyright © 2014 Jonas Ådahl |
|||
Copyright © 2014 Jason Ekstrand |
|||
Copyright © 2014-2015 Collabora, Ltd. |
|||
Copyright © 2015 Red Hat Inc. |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a |
|||
copy of this software and associated documentation files (the "Software"), |
|||
to deal in the Software without restriction, including without limitation |
|||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|||
and/or sell copies of the Software, and to permit persons to whom the |
|||
Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice (including the next |
|||
paragraph) shall be included in all copies or substantial portions of the |
|||
Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|||
DEALINGS IN THE SOFTWARE. |
|||
|
|||
# Metsys.Bson |
|||
|
|||
Copyright (c) 2010, Karl Seguin - http://www.openmymind.net/ |
|||
All rights reserved. |
|||
|
|||
Redistribution and use in source and binary forms, with or without |
|||
modification, are permitted provided that the following conditions are met: |
|||
* Redistributions of source code must retain the above copyright |
|||
notice, this list of conditions and the following disclaimer. |
|||
* Redistributions in binary form must reproduce the above copyright |
|||
notice, this list of conditions and the following disclaimer in the |
|||
documentation and/or other materials provided with the distribution. |
|||
* Neither the name of the <organization> nor the |
|||
names of its contributors may be used to endorse or promote products |
|||
derived from this software without specific prior written permission. |
|||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
|||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
|
|||
# RichTextKit |
|||
|
|||
https://github.com/toptensoftware/RichTextKit |
|||
|
|||
Copyright © 2019 Topten Software. All Rights Reserved. |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); you may |
|||
not use this product except in compliance with the License. You may obtain |
|||
a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
License for the specific language governing permissions and limitations |
|||
under the License. |
|||
|
|||
# Mono |
|||
|
|||
https://github.com/mono/mono |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining |
|||
a copy of this software and associated documentation files (the |
|||
"Software"), to deal in the Software without restriction, including |
|||
without limitation the rights to use, copy, modify, merge, publish, |
|||
distribute, sublicense, and/or sell copies of the Software, and to |
|||
permit persons to whom the Software is furnished to do so, subject to |
|||
the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be |
|||
included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
# Collections.Pooled |
|||
|
|||
https://github.com/jtmueller/Collections.Pooled |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Joel Mueller |
|||
|
|||
All rights reserved. |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
|
|||
# EllipticalArc.java |
|||
|
|||
http://www.spaceroots.org/documents/ellipse/EllipticalArc.java |
|||
http://www.spaceroots.org/documents/ellipse/elliptical-arc.pdf |
|||
|
|||
Copyright (c) 2003-2004, Luc Maisonobe |
|||
All rights reserved. |
|||
|
|||
Redistribution and use in source and binary forms, with |
|||
or without modification, are permitted provided that |
|||
the following conditions are met: |
|||
|
|||
Redistributions of source code must retain the |
|||
above copyright notice, this list of conditions and |
|||
the following disclaimer. |
|||
Redistributions in binary form must reproduce the |
|||
above copyright notice, this list of conditions and |
|||
the following disclaimer in the documentation |
|||
and/or other materials provided with the |
|||
distribution. |
|||
Neither the names of spaceroots.org, spaceroots.com |
|||
nor the names of their contributors may be used to |
|||
endorse or promote products derived from this |
|||
software without specific prior written permission. |
|||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
|||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
|||
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY |
|||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
|||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|||
POSSIBILITY OF SUCH DAMAGE. |
|||
|
|||
# WinUI |
|||
|
|||
https://github.com/microsoft/microsoft-ui-xaml |
|||
|
|||
MIT License |
|||
|
|||
Copyright (c) Microsoft Corporation. All rights reserved. |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE |
|||
|
|||
# Chromium |
|||
|
|||
https://github.com/chromium/chromium |
|||
|
|||
// Copyright 2015 The Chromium Authors. All rights reserved. |
|||
// |
|||
// Redistribution and use in source and binary forms, with or without |
|||
// modification, are permitted provided that the following conditions are |
|||
// met: |
|||
// |
|||
// * Redistributions of source code must retain the above copyright |
|||
// notice, this list of conditions and the following disclaimer. |
|||
// * Redistributions in binary form must reproduce the above |
|||
// copyright notice, this list of conditions and the following disclaimer |
|||
// in the documentation and/or other materials provided with the |
|||
// distribution. |
|||
// * Neither the name of Google Inc. nor the names of its |
|||
// contributors may be used to endorse or promote products derived from |
|||
// this software without specific prior written permission. |
|||
// |
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
@ -1,5 +1,6 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> |
|||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,6 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="HarfBuzzSharp" Version="2.6.1" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.6.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,5 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="Moq" Version="4.7.99" /> |
|||
<PackageReference Include="Moq" Version="4.14.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,5 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="System.Reactive" Version="4.1.6" /> |
|||
<PackageReference Include="System.Reactive" Version="4.4.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,7 +0,0 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="Serilog" Version="2.5.0" /> |
|||
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" /> |
|||
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.0" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,6 +1,6 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="SkiaSharp" Version="1.68.0" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="Avalonia.Skia.Linux.Natives" Version="1.68.0.2" /> |
|||
<PackageReference Include="SkiaSharp" Version="1.68.2.1" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="1.68.2.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,5 +1,2 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
#define COM_GUIDS_MATERIALIZE |
|||
#include "avalonia-native.h" |
|||
|
|||
@ -0,0 +1,12 @@ |
|||
|
|||
@protocol IRenderTarget |
|||
-(void) setNewLayer: (CALayer*) layer; |
|||
-(HRESULT) setSwFrame: (AvnFramebuffer*) fb; |
|||
-(void) resize: (AvnPixelSize) size withScale: (float) scale; |
|||
-(AvnPixelSize) pixelSize; |
|||
-(IAvnGlSurfaceRenderTarget*) createSurfaceRenderTarget; |
|||
@end |
|||
|
|||
@interface IOSurfaceRenderTarget : NSObject<IRenderTarget> |
|||
-(IOSurfaceRenderTarget*) initWithOpenGlContext: (IAvnGlContext*) context; |
|||
@end |
|||
@ -1,24 +1,71 @@ |
|||
#include "common.h" |
|||
@interface AvnAppDelegate : NSObject<NSApplicationDelegate> |
|||
@end |
|||
extern NSApplicationActivationPolicy AvnDesiredActivationPolicy = NSApplicationActivationPolicyRegular; |
|||
|
|||
NSApplicationActivationPolicy AvnDesiredActivationPolicy = NSApplicationActivationPolicyRegular; |
|||
|
|||
@implementation AvnAppDelegate |
|||
- (void)applicationWillFinishLaunching:(NSNotification *)notification |
|||
{ |
|||
[[NSApplication sharedApplication] setActivationPolicy: AvnDesiredActivationPolicy]; |
|||
if([[NSApplication sharedApplication] activationPolicy] != AvnDesiredActivationPolicy) |
|||
{ |
|||
for (NSRunningApplication * app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) { |
|||
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; |
|||
break; |
|||
} |
|||
|
|||
[[NSApplication sharedApplication] setActivationPolicy: AvnDesiredActivationPolicy]; |
|||
|
|||
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"]; |
|||
|
|||
[[NSApplication sharedApplication] setHelpMenu: [[NSMenu new] initWithTitle:@""]]; |
|||
} |
|||
} |
|||
|
|||
- (void)applicationDidFinishLaunching:(NSNotification *)notification |
|||
{ |
|||
[NSApp activateIgnoringOtherApps:true]; |
|||
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps]; |
|||
} |
|||
|
|||
@end |
|||
|
|||
@interface AvnApplication : NSApplication |
|||
|
|||
|
|||
@end |
|||
|
|||
@implementation AvnApplication |
|||
{ |
|||
BOOL _isHandlingSendEvent; |
|||
} |
|||
|
|||
- (void)sendEvent:(NSEvent *)event |
|||
{ |
|||
bool oldHandling = _isHandlingSendEvent; |
|||
_isHandlingSendEvent = true; |
|||
@try { |
|||
[super sendEvent: event]; |
|||
} @finally { |
|||
_isHandlingSendEvent = oldHandling; |
|||
} |
|||
} |
|||
|
|||
// This is needed for certain embedded controls |
|||
- (BOOL) isHandlingSendEvent |
|||
{ |
|||
return _isHandlingSendEvent; |
|||
} |
|||
|
|||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent |
|||
{ |
|||
_isHandlingSendEvent = handlingSendEvent; |
|||
} |
|||
|
|||
@end |
|||
|
|||
extern void InitializeAvnApp() |
|||
{ |
|||
NSApplication* app = [NSApplication sharedApplication]; |
|||
NSApplication* app = [AvnApplication sharedApplication]; |
|||
id delegate = [AvnAppDelegate new]; |
|||
[app setDelegate:delegate]; |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,166 @@ |
|||
#include "common.h" |
|||
#include <dlfcn.h> |
|||
|
|||
static CGLContextObj CreateCglContext(CGLContextObj share) |
|||
{ |
|||
int attributes[] = { |
|||
kCGLPFAAccelerated, |
|||
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, |
|||
kCGLPFADepthSize, 8, |
|||
kCGLPFAStencilSize, 8, |
|||
kCGLPFAColorSize, 32, |
|||
0 |
|||
}; |
|||
|
|||
CGLPixelFormatObj pix; |
|||
CGLError errorCode; |
|||
GLint num; // stores the number of possible pixel formats |
|||
errorCode = CGLChoosePixelFormat( (CGLPixelFormatAttribute*)attributes, &pix, &num ); |
|||
if(errorCode != 0) |
|||
return nil; |
|||
CGLContextObj ctx = nil; |
|||
errorCode = CGLCreateContext(pix, share, &ctx ); |
|||
CGLDestroyPixelFormat( pix ); |
|||
if(errorCode != 0) |
|||
return nil; |
|||
return ctx; |
|||
}; |
|||
|
|||
|
|||
|
|||
class AvnGlContext : public virtual ComSingleObject<IAvnGlContext, &IID_IAvnGlContext> |
|||
{ |
|||
// Debug |
|||
int _usageCount = 0; |
|||
public: |
|||
CGLContextObj Context; |
|||
int SampleCount = 0, StencilBits = 0; |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
class SavedGlContext : public virtual ComUnknownObject |
|||
{ |
|||
CGLContextObj _savedContext; |
|||
ComPtr<AvnGlContext> _parent; |
|||
public: |
|||
SavedGlContext(CGLContextObj saved, AvnGlContext* parent) |
|||
{ |
|||
_savedContext = saved; |
|||
_parent = parent; |
|||
_parent->_usageCount++; |
|||
} |
|||
|
|||
~SavedGlContext() |
|||
{ |
|||
if(_parent->Context == CGLGetCurrentContext()) |
|||
CGLSetCurrentContext(_savedContext); |
|||
_parent->_usageCount--; |
|||
CGLUnlockContext(_parent->Context); |
|||
} |
|||
}; |
|||
|
|||
AvnGlContext(CGLContextObj context) |
|||
{ |
|||
Context = context; |
|||
CGLPixelFormatObj fmt = CGLGetPixelFormat(context); |
|||
CGLDescribePixelFormat(fmt, 0, kCGLPFASamples, &SampleCount); |
|||
CGLDescribePixelFormat(fmt, 0, kCGLPFAStencilSize, &StencilBits); |
|||
|
|||
} |
|||
|
|||
virtual HRESULT LegacyMakeCurrent() override |
|||
{ |
|||
if(CGLSetCurrentContext(Context) != 0) |
|||
return E_FAIL; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual HRESULT MakeCurrent(IUnknown** ppv) override |
|||
{ |
|||
CGLContextObj saved = CGLGetCurrentContext(); |
|||
CGLLockContext(Context); |
|||
if(CGLSetCurrentContext(Context) != 0) |
|||
{ |
|||
CGLUnlockContext(Context); |
|||
return E_FAIL; |
|||
} |
|||
*ppv = new SavedGlContext(saved, this); |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
virtual int GetSampleCount() override |
|||
{ |
|||
return SampleCount; |
|||
} |
|||
|
|||
virtual int GetStencilSize() override |
|||
{ |
|||
return StencilBits; |
|||
} |
|||
|
|||
virtual void* GetNativeHandle() override |
|||
{ |
|||
return Context; |
|||
} |
|||
|
|||
~AvnGlContext() |
|||
{ |
|||
CGLReleaseContext(Context); |
|||
} |
|||
}; |
|||
|
|||
class AvnGlDisplay : public virtual ComSingleObject<IAvnGlDisplay, &IID_IAvnGlDisplay> |
|||
{ |
|||
void* _libgl; |
|||
|
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
AvnGlDisplay() |
|||
{ |
|||
_libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", RTLD_LAZY); |
|||
} |
|||
|
|||
virtual void* GetProcAddress(char* proc) override |
|||
{ |
|||
return dlsym(_libgl, proc); |
|||
} |
|||
|
|||
virtual HRESULT CreateContext(IAvnGlContext* share, IAvnGlContext**ppv) override |
|||
{ |
|||
CGLContextObj shareContext = nil; |
|||
if(share != nil) |
|||
{ |
|||
AvnGlContext* shareCtx = dynamic_cast<AvnGlContext*>(share); |
|||
if(shareCtx != nil) |
|||
shareContext = shareCtx->Context; |
|||
} |
|||
CGLContextObj ctx = ::CreateCglContext(shareContext); |
|||
if(ctx == nil) |
|||
return E_FAIL; |
|||
*ppv = new AvnGlContext(ctx); |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual HRESULT WrapContext(void* native, IAvnGlContext**ppv) override |
|||
{ |
|||
if(native == nil) |
|||
return E_INVALIDARG; |
|||
*ppv = new AvnGlContext((CGLContextObj) native); |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual void LegacyClearCurrentContext() override |
|||
{ |
|||
CGLSetCurrentContext(nil); |
|||
} |
|||
}; |
|||
|
|||
static IAvnGlDisplay* GlDisplay = new AvnGlDisplay(); |
|||
|
|||
|
|||
extern IAvnGlDisplay* GetGlDisplay() |
|||
{ |
|||
return GlDisplay; |
|||
}; |
|||
|
|||
@ -0,0 +1,145 @@ |
|||
#include "common.h" |
|||
|
|||
|
|||
IAvnNativeControlHostTopLevelAttachment* CreateAttachment(); |
|||
|
|||
class AvnNativeControlHost : |
|||
public ComSingleObject<IAvnNativeControlHost, &IID_IAvnNativeControlHost> |
|||
{ |
|||
public: |
|||
FORWARD_IUNKNOWN(); |
|||
NSView* View; |
|||
AvnNativeControlHost(NSView* view) |
|||
{ |
|||
View = view; |
|||
} |
|||
|
|||
virtual HRESULT CreateDefaultChild(void* parent, void** retOut) override |
|||
{ |
|||
NSView* view = [NSView new]; |
|||
[view setWantsLayer: true]; |
|||
|
|||
*retOut = (__bridge_retained void*)view; |
|||
return S_OK; |
|||
}; |
|||
|
|||
virtual IAvnNativeControlHostTopLevelAttachment* CreateAttachment() override |
|||
{ |
|||
return ::CreateAttachment(); |
|||
}; |
|||
|
|||
virtual void DestroyDefaultChild(void* child) override |
|||
{ |
|||
// ARC will release the object for us |
|||
(__bridge_transfer NSView*) child; |
|||
} |
|||
}; |
|||
|
|||
class AvnNativeControlHostTopLevelAttachment : |
|||
public ComSingleObject<IAvnNativeControlHostTopLevelAttachment, &IID_IAvnNativeControlHostTopLevelAttachment> |
|||
{ |
|||
NSView* _holder; |
|||
NSView* _child; |
|||
public: |
|||
FORWARD_IUNKNOWN(); |
|||
|
|||
AvnNativeControlHostTopLevelAttachment() |
|||
{ |
|||
_holder = [NSView new]; |
|||
[_holder setWantsLayer:true]; |
|||
} |
|||
|
|||
virtual ~AvnNativeControlHostTopLevelAttachment() |
|||
{ |
|||
if(_child != nil && [_child superview] == _holder) |
|||
{ |
|||
[_child removeFromSuperview]; |
|||
} |
|||
|
|||
if([_holder superview] != nil) |
|||
{ |
|||
[_holder removeFromSuperview]; |
|||
} |
|||
} |
|||
|
|||
virtual void* GetParentHandle() override |
|||
{ |
|||
return (__bridge void*)_holder; |
|||
}; |
|||
|
|||
virtual HRESULT InitializeWithChildHandle(void* child) override |
|||
{ |
|||
if(_child != nil) |
|||
return E_FAIL; |
|||
_child = (__bridge NSView*)child; |
|||
if(_child == nil) |
|||
return E_FAIL; |
|||
[_holder addSubview:_child]; |
|||
[_child setHidden: false]; |
|||
return S_OK; |
|||
}; |
|||
|
|||
virtual HRESULT AttachTo(IAvnNativeControlHost* host) override |
|||
{ |
|||
if(host == nil) |
|||
{ |
|||
[_holder removeFromSuperview]; |
|||
[_holder setHidden: true]; |
|||
} |
|||
else |
|||
{ |
|||
AvnNativeControlHost* chost = dynamic_cast<AvnNativeControlHost*>(host); |
|||
if(chost == nil || chost->View == nil) |
|||
return E_FAIL; |
|||
[_holder setHidden:true]; |
|||
[chost->View addSubview:_holder]; |
|||
} |
|||
return S_OK; |
|||
}; |
|||
|
|||
virtual void MoveTo(float x, float y, float width, float height) override |
|||
{ |
|||
if(_child == nil) |
|||
return; |
|||
if(AvnInsidePotentialDeadlock::IsInside()) |
|||
{ |
|||
IAvnNativeControlHostTopLevelAttachment* slf = this; |
|||
slf->AddRef(); |
|||
dispatch_async(dispatch_get_main_queue(), ^{ |
|||
slf->MoveTo(x, y, width, height); |
|||
slf->Release(); |
|||
}); |
|||
return; |
|||
} |
|||
|
|||
NSRect childFrame = {0, 0, width, height}; |
|||
NSRect holderFrame = {x, y, width, height}; |
|||
|
|||
[_child setFrame: childFrame]; |
|||
[_holder setFrame: holderFrame]; |
|||
[_holder setHidden: false]; |
|||
if([_holder superview] != nil) |
|||
[[_holder superview] setNeedsDisplay:true]; |
|||
} |
|||
|
|||
virtual void Hide() override |
|||
{ |
|||
[_holder setHidden: true]; |
|||
} |
|||
|
|||
virtual void ReleaseChild() override |
|||
{ |
|||
[_child removeFromSuperview]; |
|||
_child = nil; |
|||
} |
|||
}; |
|||
|
|||
IAvnNativeControlHostTopLevelAttachment* CreateAttachment() |
|||
{ |
|||
return new AvnNativeControlHostTopLevelAttachment(); |
|||
} |
|||
|
|||
extern IAvnNativeControlHost* CreateNativeControlHost(NSView* parent) |
|||
{ |
|||
return new AvnNativeControlHost(parent); |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
#include "common.h" |
|||
|
|||
static int Counter = 0; |
|||
AvnInsidePotentialDeadlock::AvnInsidePotentialDeadlock() |
|||
{ |
|||
Counter++; |
|||
} |
|||
|
|||
AvnInsidePotentialDeadlock::~AvnInsidePotentialDeadlock() |
|||
{ |
|||
Counter--; |
|||
} |
|||
|
|||
bool AvnInsidePotentialDeadlock::IsInside() |
|||
{ |
|||
return Counter!=0; |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
#include "common.h" |
|||
|
|||
extern AvnDragDropEffects ConvertDragDropEffects(NSDragOperation nsop) |
|||
{ |
|||
int effects = 0; |
|||
if((nsop & NSDragOperationCopy) != 0) |
|||
effects |= (int)AvnDragDropEffects::Copy; |
|||
if((nsop & NSDragOperationMove) != 0) |
|||
effects |= (int)AvnDragDropEffects::Move; |
|||
if((nsop & NSDragOperationLink) != 0) |
|||
effects |= (int)AvnDragDropEffects::Link; |
|||
return (AvnDragDropEffects)effects; |
|||
}; |
|||
|
|||
extern NSString* GetAvnCustomDataType() |
|||
{ |
|||
char buffer[256]; |
|||
sprintf(buffer, "net.avaloniaui.inproc.uti.n%in", getpid()); |
|||
return [NSString stringWithUTF8String:buffer]; |
|||
} |
|||
|
|||
@interface AvnDndSource : NSObject<NSDraggingSource> |
|||
|
|||
@end |
|||
|
|||
@implementation AvnDndSource |
|||
{ |
|||
NSDragOperation _operation; |
|||
ComPtr<IAvnDndResultCallback> _cb; |
|||
void* _sourceHandle; |
|||
}; |
|||
|
|||
- (NSDragOperation)draggingSession:(nonnull NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context |
|||
{ |
|||
return NSDragOperationCopy; |
|||
} |
|||
|
|||
- (AvnDndSource*) initWithOperation: (NSDragOperation)operation |
|||
andCallback: (IAvnDndResultCallback*) cb |
|||
andSourceHandle: (void*) handle |
|||
{ |
|||
self = [super init]; |
|||
_operation = operation; |
|||
_cb = cb; |
|||
_sourceHandle = handle; |
|||
return self; |
|||
} |
|||
|
|||
- (void)draggingSession:(NSDraggingSession *)session |
|||
endedAtPoint:(NSPoint)screenPoint |
|||
operation:(NSDragOperation)operation |
|||
{ |
|||
if(_cb != nil) |
|||
{ |
|||
auto cb = _cb; |
|||
_cb = nil; |
|||
cb->OnDragAndDropComplete(ConvertDragDropEffects(operation)); |
|||
} |
|||
if(_sourceHandle != nil) |
|||
{ |
|||
FreeAvnGCHandle(_sourceHandle); |
|||
_sourceHandle = nil; |
|||
} |
|||
} |
|||
|
|||
- (void*) gcHandle |
|||
{ |
|||
return _sourceHandle; |
|||
} |
|||
|
|||
@end |
|||
|
|||
extern NSObject<NSDraggingSource>* CreateDraggingSource(NSDragOperation op, IAvnDndResultCallback* cb, void* handle) |
|||
{ |
|||
return [[AvnDndSource alloc] initWithOperation:op andCallback:cb andSourceHandle:handle]; |
|||
}; |
|||
|
|||
extern void* GetAvnDataObjectHandleFromDraggingInfo(NSObject<NSDraggingInfo>* info) |
|||
{ |
|||
id obj = [info draggingSource]; |
|||
if(obj == nil) |
|||
return nil; |
|||
if([obj isKindOfClass: [AvnDndSource class]]) |
|||
{ |
|||
auto src = (AvnDndSource*)obj; |
|||
return [src gcHandle]; |
|||
} |
|||
return nil; |
|||
} |
|||
@ -1,253 +0,0 @@ |
|||
#include "common.h" |
|||
#include <OpenGL/gl.h> |
|||
#include <dlfcn.h> |
|||
|
|||
template <typename T, size_t N> char (&ArrayCounter(T (&a)[N]))[N]; |
|||
#define ARRAY_COUNT(a) (sizeof(ArrayCounter(a))) |
|||
|
|||
NSOpenGLPixelFormat* CreateFormat() |
|||
{ |
|||
NSOpenGLPixelFormatAttribute attribs[] = |
|||
{ |
|||
NSOpenGLPFADoubleBuffer, |
|||
NSOpenGLPFAColorSize, 32, |
|||
NSOpenGLPFAStencilSize, 8, |
|||
NSOpenGLPFADepthSize, 8, |
|||
0 |
|||
}; |
|||
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; |
|||
} |
|||
|
|||
class AvnGlContext : public virtual ComSingleObject<IAvnGlContext, &IID_IAvnGlContext> |
|||
{ |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
NSOpenGLContext* GlContext; |
|||
GLuint Framebuffer, RenderBuffer, StencilBuffer; |
|||
AvnGlContext(NSOpenGLContext* gl, bool offscreen) |
|||
{ |
|||
Framebuffer = 0; |
|||
RenderBuffer = 0; |
|||
StencilBuffer = 0; |
|||
GlContext = gl; |
|||
if(offscreen) |
|||
{ |
|||
[GlContext makeCurrentContext]; |
|||
|
|||
glGenFramebuffersEXT(1, &Framebuffer); |
|||
glBindFramebufferEXT(GL_FRAMEBUFFER, Framebuffer); |
|||
glGenRenderbuffersEXT(1, &RenderBuffer); |
|||
glGenRenderbuffersEXT(1, &StencilBuffer); |
|||
|
|||
glBindRenderbufferEXT(GL_RENDERBUFFER, StencilBuffer); |
|||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, StencilBuffer); |
|||
glBindRenderbufferEXT(GL_RENDERBUFFER, RenderBuffer); |
|||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, RenderBuffer); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
virtual HRESULT MakeCurrent() override |
|||
{ |
|||
[GlContext makeCurrentContext];/* |
|||
glBindFramebufferEXT(GL_FRAMEBUFFER, Framebuffer); |
|||
glBindRenderbufferEXT(GL_RENDERBUFFER, RenderBuffer); |
|||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, RenderBuffer); |
|||
glBindRenderbufferEXT(GL_RENDERBUFFER, StencilBuffer); |
|||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, StencilBuffer);*/ |
|||
return S_OK; |
|||
} |
|||
}; |
|||
|
|||
class AvnGlDisplay : public virtual ComSingleObject<IAvnGlDisplay, &IID_IAvnGlDisplay> |
|||
{ |
|||
int _sampleCount, _stencilSize; |
|||
void* _libgl; |
|||
|
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
AvnGlDisplay(int sampleCount, int stencilSize) |
|||
{ |
|||
_sampleCount = sampleCount; |
|||
_stencilSize = stencilSize; |
|||
_libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", RTLD_LAZY); |
|||
} |
|||
|
|||
virtual HRESULT GetSampleCount(int* ret) override |
|||
{ |
|||
*ret = _sampleCount; |
|||
return S_OK; |
|||
} |
|||
virtual HRESULT GetStencilSize(int* ret) override |
|||
{ |
|||
*ret = _stencilSize; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual HRESULT ClearContext() override |
|||
{ |
|||
[NSOpenGLContext clearCurrentContext]; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual void* GetProcAddress(char* proc) override |
|||
{ |
|||
return dlsym(_libgl, proc); |
|||
} |
|||
}; |
|||
|
|||
|
|||
class GlFeature : public virtual ComSingleObject<IAvnGlFeature, &IID_IAvnGlFeature> |
|||
{ |
|||
IAvnGlDisplay* _display; |
|||
AvnGlContext *_immediate; |
|||
NSOpenGLContext* _shared; |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
NSOpenGLPixelFormat* _format; |
|||
GlFeature(IAvnGlDisplay* display, AvnGlContext* immediate, NSOpenGLPixelFormat* format) |
|||
{ |
|||
_display = display; |
|||
_immediate = immediate; |
|||
_format = format; |
|||
_shared = [[NSOpenGLContext alloc] initWithFormat:_format shareContext:_immediate->GlContext]; |
|||
} |
|||
|
|||
NSOpenGLContext* CreateContext() |
|||
{ |
|||
return _shared; |
|||
//return [[NSOpenGLContext alloc] initWithFormat:_format shareContext:nil]; |
|||
} |
|||
|
|||
virtual HRESULT ObtainDisplay(IAvnGlDisplay**retOut) override |
|||
{ |
|||
*retOut = _display; |
|||
_display->AddRef(); |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override |
|||
{ |
|||
*retOut = _immediate; |
|||
_immediate->AddRef(); |
|||
return S_OK; |
|||
} |
|||
}; |
|||
|
|||
static GlFeature* Feature; |
|||
|
|||
GlFeature* CreateGlFeature() |
|||
{ |
|||
auto format = CreateFormat(); |
|||
if(format == nil) |
|||
{ |
|||
NSLog(@"Unable to choose pixel format"); |
|||
return NULL; |
|||
} |
|||
|
|||
auto immediateContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil]; |
|||
if(immediateContext == nil) |
|||
{ |
|||
NSLog(@"Unable to create NSOpenGLContext"); |
|||
return NULL; |
|||
} |
|||
|
|||
int stencilBits = 0, sampleCount = 0; |
|||
|
|||
auto fmt = CGLGetPixelFormat([immediateContext CGLContextObj]); |
|||
CGLDescribePixelFormat(fmt, 0, kCGLPFASamples, &sampleCount); |
|||
CGLDescribePixelFormat(fmt, 0, kCGLPFAStencilSize, &stencilBits); |
|||
|
|||
auto offscreen = new AvnGlContext(immediateContext, true); |
|||
auto display = new AvnGlDisplay(sampleCount, stencilBits); |
|||
|
|||
return new GlFeature(display, offscreen, format); |
|||
} |
|||
|
|||
|
|||
static GlFeature* GetFeature() |
|||
{ |
|||
if(Feature == nil) |
|||
Feature = CreateGlFeature(); |
|||
return Feature; |
|||
} |
|||
|
|||
extern IAvnGlFeature* GetGlFeature() |
|||
{ |
|||
return GetFeature(); |
|||
} |
|||
|
|||
class AvnGlRenderingSession : public ComSingleObject<IAvnGlSurfaceRenderingSession, &IID_IAvnGlSurfaceRenderingSession> |
|||
{ |
|||
NSView* _view; |
|||
NSWindow* _window; |
|||
NSOpenGLContext* _context; |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
AvnGlRenderingSession(NSWindow*window, NSView* view, NSOpenGLContext* context) |
|||
{ |
|||
_context = context; |
|||
_window = window; |
|||
_view = view; |
|||
} |
|||
|
|||
virtual HRESULT GetPixelSize(AvnPixelSize* ret) override |
|||
{ |
|||
auto fsize = [_view convertSizeToBacking: [_view frame].size]; |
|||
ret->Width = (int)fsize.width; |
|||
ret->Height = (int)fsize.height; |
|||
return S_OK; |
|||
} |
|||
virtual HRESULT GetScaling(double* ret) override |
|||
{ |
|||
*ret = [_window backingScaleFactor]; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual ~AvnGlRenderingSession() |
|||
{ |
|||
[_context flushBuffer]; |
|||
[NSOpenGLContext clearCurrentContext]; |
|||
CGLUnlockContext([_context CGLContextObj]); |
|||
[_view unlockFocus]; |
|||
} |
|||
}; |
|||
|
|||
class AvnGlRenderTarget : public ComSingleObject<IAvnGlSurfaceRenderTarget, &IID_IAvnGlSurfaceRenderTarget> |
|||
{ |
|||
NSView* _view; |
|||
NSWindow* _window; |
|||
NSOpenGLContext* _context; |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
AvnGlRenderTarget(NSWindow* window, NSView*view) |
|||
{ |
|||
_window = window; |
|||
_view = view; |
|||
_context = GetFeature()->CreateContext(); |
|||
} |
|||
|
|||
virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) override |
|||
{ |
|||
auto f = GetFeature(); |
|||
if(f == NULL) |
|||
return E_FAIL; |
|||
if(![_view lockFocusIfCanDraw]) |
|||
return E_ABORT; |
|||
|
|||
auto gl = _context; |
|||
CGLLockContext([_context CGLContextObj]); |
|||
[gl setView: _view]; |
|||
[gl update]; |
|||
[gl makeCurrentContext]; |
|||
*ret = new AvnGlRenderingSession(_window, _view, gl); |
|||
return S_OK; |
|||
} |
|||
}; |
|||
|
|||
extern IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(NSWindow* window, NSView* view) |
|||
{ |
|||
return new AvnGlRenderTarget(window, view); |
|||
} |
|||
@ -0,0 +1,284 @@ |
|||
#include "common.h" |
|||
#include "rendertarget.h" |
|||
#import <IOSurface/IOSurface.h> |
|||
#import <IOSurface/IOSurfaceObjC.h> |
|||
|
|||
#include <OpenGL/CGLIOSurface.h> |
|||
#include <OpenGL/OpenGL.h> |
|||
#include <OpenGL/glext.h> |
|||
#include <OpenGL/gl3.h> |
|||
#include <OpenGL/gl3ext.h> |
|||
|
|||
@interface IOSurfaceHolder : NSObject |
|||
@end |
|||
|
|||
@implementation IOSurfaceHolder |
|||
{ |
|||
@public IOSurfaceRef surface; |
|||
@public AvnPixelSize size; |
|||
@public float scale; |
|||
ComPtr<IAvnGlContext> _context; |
|||
GLuint _framebuffer, _texture, _renderbuffer; |
|||
} |
|||
|
|||
- (IOSurfaceHolder*) initWithSize: (AvnPixelSize) size |
|||
withScale: (float)scale |
|||
withOpenGlContext: (IAvnGlContext*) context |
|||
{ |
|||
long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.Width * 4); |
|||
long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.Height * bytesPerRow); |
|||
NSDictionary* options = @{ |
|||
(id)kIOSurfaceWidth: @(size.Width), |
|||
(id)kIOSurfaceHeight: @(size.Height), |
|||
(id)kIOSurfacePixelFormat: @((uint)'BGRA'), |
|||
(id)kIOSurfaceBytesPerElement: @(4), |
|||
(id)kIOSurfaceBytesPerRow: @(bytesPerRow), |
|||
(id)kIOSurfaceAllocSize: @(allocSize), |
|||
|
|||
//(id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache), |
|||
(id)kIOSurfaceElementWidth: @(1), |
|||
(id)kIOSurfaceElementHeight: @(1) |
|||
}; |
|||
|
|||
surface = IOSurfaceCreate((CFDictionaryRef)options); |
|||
self->scale = scale; |
|||
self->size = size; |
|||
self->_context = context; |
|||
return self; |
|||
} |
|||
|
|||
-(HRESULT) prepareForGlRender |
|||
{ |
|||
if(_context == nil) |
|||
return E_FAIL; |
|||
if(CGLGetCurrentContext() != _context->GetNativeHandle()) |
|||
return E_FAIL; |
|||
if(_framebuffer == 0) |
|||
glGenFramebuffersEXT(1, &_framebuffer); |
|||
|
|||
|
|||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _framebuffer); |
|||
if(_texture == 0) |
|||
{ |
|||
glGenTextures(1, &_texture); |
|||
|
|||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, _texture); |
|||
CGLError res = CGLTexImageIOSurface2D((CGLContextObj)_context->GetNativeHandle(), |
|||
GL_TEXTURE_RECTANGLE_EXT, GL_RGBA8, |
|||
size.Width, size.Height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, surface, 0); |
|||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0); |
|||
|
|||
if(res != 0) |
|||
{ |
|||
glDeleteTextures(1, &_texture); |
|||
_texture = 0; |
|||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
|||
return E_FAIL; |
|||
} |
|||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_EXT, _texture, 0); |
|||
} |
|||
|
|||
if(_renderbuffer == 0) |
|||
{ |
|||
glGenRenderbuffers(1, &_renderbuffer); |
|||
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer); |
|||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.Width, size.Height); |
|||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderbuffer); |
|||
} |
|||
|
|||
return S_OK; |
|||
} |
|||
|
|||
-(void) finishDraw |
|||
{ |
|||
ComPtr<IUnknown> release; |
|||
_context->MakeCurrent(release.getPPV()); |
|||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
|||
glFlush(); |
|||
} |
|||
|
|||
-(void) dealloc |
|||
{ |
|||
|
|||
if(_framebuffer != 0) |
|||
{ |
|||
ComPtr<IUnknown> release; |
|||
_context->MakeCurrent(release.getPPV()); |
|||
glDeleteFramebuffers(1, &_framebuffer); |
|||
if(_texture != 0) |
|||
glDeleteTextures(1, &_texture); |
|||
if(_renderbuffer != 0) |
|||
glDeleteRenderbuffers(1, &_renderbuffer); |
|||
} |
|||
IOSurfaceDecrementUseCount(surface); |
|||
} |
|||
@end |
|||
|
|||
static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* target); |
|||
|
|||
@implementation IOSurfaceRenderTarget |
|||
{ |
|||
CALayer* _layer; |
|||
@public IOSurfaceHolder* surface; |
|||
@public NSObject* lock; |
|||
ComPtr<IAvnGlContext> _glContext; |
|||
} |
|||
|
|||
- (IOSurfaceRenderTarget*) initWithOpenGlContext: (IAvnGlContext*) context; |
|||
{ |
|||
self = [super init]; |
|||
_glContext = context; |
|||
lock = [NSObject new]; |
|||
surface = nil; |
|||
[self resize:{1,1} withScale: 1]; |
|||
|
|||
return self; |
|||
} |
|||
|
|||
- (AvnPixelSize) pixelSize { |
|||
return {1, 1}; |
|||
} |
|||
|
|||
- (CALayer *)layer { |
|||
return _layer; |
|||
} |
|||
|
|||
- (void)resize:(AvnPixelSize)size withScale: (float) scale;{ |
|||
@synchronized (lock) { |
|||
if(surface == nil |
|||
|| surface->size.Width != size.Width |
|||
|| surface->size.Height != size.Height |
|||
|| surface->scale != scale) |
|||
surface = [[IOSurfaceHolder alloc] initWithSize:size withScale:scale withOpenGlContext:_glContext.getRaw()]; |
|||
} |
|||
} |
|||
|
|||
- (void)updateLayer { |
|||
if ([NSThread isMainThread]) |
|||
{ |
|||
@synchronized (lock) { |
|||
if(_layer == nil) |
|||
return; |
|||
[_layer setContents: nil]; |
|||
if(surface != nil) |
|||
{ |
|||
[_layer setContentsScale: surface->scale]; |
|||
[_layer setContents: (__bridge IOSurface*) surface->surface]; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
dispatch_async(dispatch_get_main_queue(), ^{ |
|||
[self updateLayer]; |
|||
}); |
|||
} |
|||
|
|||
- (void) setNewLayer:(CALayer *)layer { |
|||
_layer = layer; |
|||
[self updateLayer]; |
|||
} |
|||
|
|||
- (HRESULT)setSwFrame:(AvnFramebuffer *)fb { |
|||
@synchronized (lock) { |
|||
if(fb->PixelFormat == AvnPixelFormat::kAvnRgb565) |
|||
return E_INVALIDARG; |
|||
if(surface == nil) |
|||
return E_FAIL; |
|||
IOSurfaceRef surf = surface->surface; |
|||
if(IOSurfaceLock(surf, 0, nil)) |
|||
return E_FAIL; |
|||
size_t w = MIN(fb->Width, IOSurfaceGetWidth(surf)); |
|||
size_t h = MIN(fb->Height, IOSurfaceGetHeight(surf)); |
|||
size_t wbytes = w*4; |
|||
size_t sstride = IOSurfaceGetBytesPerRow(surf); |
|||
size_t fstride = fb->Stride; |
|||
char*pSurface = (char*)IOSurfaceGetBaseAddress(surf); |
|||
char*pFb = (char*)fb->Data; |
|||
for(size_t y = 0; y < h; y++) |
|||
{ |
|||
memcpy(pSurface + y*sstride, pFb + y*fstride, wbytes); |
|||
} |
|||
IOSurfaceUnlock(surf, 0, nil); |
|||
[self updateLayer]; |
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
-(IAvnGlSurfaceRenderTarget*) createSurfaceRenderTarget |
|||
{ |
|||
return CreateGlRenderTarget(self); |
|||
} |
|||
|
|||
@end |
|||
|
|||
class AvnGlRenderingSession : public ComSingleObject<IAvnGlSurfaceRenderingSession, &IID_IAvnGlSurfaceRenderingSession> |
|||
{ |
|||
ComPtr<IUnknown> _releaseContext; |
|||
IOSurfaceRenderTarget* _target; |
|||
IOSurfaceHolder* _surface; |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
AvnGlRenderingSession(IOSurfaceRenderTarget* target, ComPtr<IUnknown> releaseContext) |
|||
{ |
|||
_target = target; |
|||
// This happens in a synchronized block set up by AvnRenderTarget, so we take the current surface for this |
|||
// particular render session |
|||
_surface = _target->surface; |
|||
_releaseContext = releaseContext; |
|||
} |
|||
|
|||
virtual HRESULT GetPixelSize(AvnPixelSize* ret) override |
|||
{ |
|||
if(!_surface) |
|||
return E_FAIL; |
|||
*ret = _surface->size; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual HRESULT GetScaling(double* ret) override |
|||
{ |
|||
if(!_surface) |
|||
return E_FAIL; |
|||
*ret = _surface->scale; |
|||
return S_OK; |
|||
} |
|||
|
|||
virtual ~AvnGlRenderingSession() |
|||
{ |
|||
[_surface finishDraw]; |
|||
[_target updateLayer]; |
|||
_releaseContext = nil; |
|||
} |
|||
}; |
|||
|
|||
class AvnGlRenderTarget : public ComSingleObject<IAvnGlSurfaceRenderTarget, &IID_IAvnGlSurfaceRenderTarget> |
|||
{ |
|||
IOSurfaceRenderTarget* _target; |
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
AvnGlRenderTarget(IOSurfaceRenderTarget* target) |
|||
{ |
|||
_target = target; |
|||
} |
|||
|
|||
virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) override |
|||
{ |
|||
ComPtr<IUnknown> releaseContext; |
|||
@synchronized (_target->lock) { |
|||
if(_target->surface == nil) |
|||
return E_FAIL; |
|||
_target->_glContext->MakeCurrent(releaseContext.getPPV()); |
|||
HRESULT res = [_target->surface prepareForGlRender]; |
|||
if(res) |
|||
return res; |
|||
*ret = new AvnGlRenderingSession(_target, releaseContext); |
|||
return S_OK; |
|||
} |
|||
} |
|||
}; |
|||
|
|||
|
|||
static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* target) |
|||
{ |
|||
return new AvnGlRenderTarget(target); |
|||
} |
|||
File diff suppressed because it is too large
@ -1 +1 @@ |
|||
Subproject commit 4464343aef5c8ab7a42fcb20a483a6058199f8b8 |
|||
Subproject commit aef10ae67dc55c95f49b52a505a0be33bfa297a5 |
|||
@ -1,3 +1,11 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
|
|||
<ItemGroup> |
|||
<AvailableItemName Include="AvaloniaXaml" /> |
|||
<AvailableItemName Include="AvaloniaResource" /> |
|||
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)AvaloniaItemSchema.xaml" /> |
|||
</ItemGroup> |
|||
<ItemGroup Condition="'$(EnableDefaultItems)'=='True'"> |
|||
<AvaloniaXaml Include="**\*.axaml" SubType="Designer" /> |
|||
<AvaloniaXaml Include="**\*.paml" SubType="Designer" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
<ProjectSchemaDefinitions xmlns="http://schemas.microsoft.com/build/2009/properties"> |
|||
<ContentType |
|||
Name="AvaloniaXaml" |
|||
DisplayName="Avalonia XAML" |
|||
ItemType="AvaloniaXaml"> |
|||
<NameValuePair Name="DependentFileExtensions" Value=".cs" /> |
|||
<NameValuePair Name="DefaultMetadata_SubType" Value="Designer" /> |
|||
</ContentType> |
|||
|
|||
<ItemType Name="AvaloniaXaml" DisplayName="Avalonia XAML" /> |
|||
<FileExtension Name=".axaml" ContentType="AvaloniaXaml" /> |
|||
<FileExtension Name=".paml" ContentType="AvaloniaXaml" /> |
|||
<ContentType |
|||
Name="AvaloniaResource" |
|||
DisplayName="Avalonia Resource" |
|||
ItemType="AvaloniaResource" |
|||
/> |
|||
</ProjectSchemaDefinitions> |
|||
@ -1,45 +1,69 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Class="ControlCatalog.Pages.ImagePage"> |
|||
<StackPanel Orientation="Vertical" Spacing="4"> |
|||
<TextBlock Classes="h1">Image</TextBlock> |
|||
<TextBlock Classes="h2">Displays an image</TextBlock> |
|||
|
|||
<StackPanel Orientation="Horizontal" |
|||
Margin="0,16,0,0" |
|||
HorizontalAlignment="Center" |
|||
Spacing="16"> |
|||
<StackPanel Orientation="Vertical"> |
|||
<TextBlock>No Stretch</TextBlock> |
|||
<Image Source="/Assets/delicate-arch-896885_640.jpg" |
|||
Width="100" Height="200" |
|||
Stretch="None"/> |
|||
</StackPanel> |
|||
<DockPanel> |
|||
<StackPanel DockPanel.Dock="Top" Orientation="Vertical" Spacing="4"> |
|||
<TextBlock Classes="h1">Image</TextBlock> |
|||
<TextBlock Classes="h2">Displays an image</TextBlock> |
|||
</StackPanel> |
|||
|
|||
<StackPanel Orientation="Vertical"> |
|||
<TextBlock>Fill</TextBlock> |
|||
<Image Source="/Assets/delicate-arch-896885_640.jpg" |
|||
Width="100" Height="200" |
|||
Stretch="Fill"/> |
|||
</StackPanel> |
|||
<Grid ColumnDefinitions="*,*,*" RowDefinitions="Auto,*" Margin="64"> |
|||
|
|||
<DockPanel Grid.Column="0" Grid.Row="1" Margin="16"> |
|||
<TextBlock DockPanel.Dock="Top" Classes="h3" Margin="0 8">Bitmap</TextBlock> |
|||
<ComboBox Name="bitmapStretch" DockPanel.Dock="Top" SelectedIndex="2" SelectionChanged="BitmapStretchChanged"> |
|||
<ComboBoxItem>None</ComboBoxItem> |
|||
<ComboBoxItem>Fill</ComboBoxItem> |
|||
<ComboBoxItem>Uniform</ComboBoxItem> |
|||
<ComboBoxItem>UniformToFill</ComboBoxItem> |
|||
</ComboBox> |
|||
<Image Name="bitmapImage" |
|||
Source="/Assets/delicate-arch-896885_640.jpg"/> |
|||
</DockPanel> |
|||
|
|||
<StackPanel Orientation="Vertical"> |
|||
<TextBlock>Uniform</TextBlock> |
|||
<Image Source="/Assets/delicate-arch-896885_640.jpg" |
|||
Width="100" Height="200" |
|||
Stretch="Uniform"/> |
|||
</StackPanel> |
|||
<DockPanel Grid.Column="1" Grid.Row="1" Margin="16"> |
|||
<TextBlock DockPanel.Dock="Top" Classes="h3" Margin="0 8">Crop</TextBlock> |
|||
<ComboBox Name="bitmapCrop" DockPanel.Dock="Top" SelectedIndex="2" SelectionChanged="BitmapCropChanged"> |
|||
<ComboBoxItem>None</ComboBoxItem> |
|||
<ComboBoxItem>Center</ComboBoxItem> |
|||
<ComboBoxItem>TopLeft</ComboBoxItem> |
|||
<ComboBoxItem>TopRight</ComboBoxItem> |
|||
<ComboBoxItem>BottomLeft</ComboBoxItem> |
|||
<ComboBoxItem>BottomRight</ComboBoxItem> |
|||
</ComboBox> |
|||
<Image Name="croppedImage"> |
|||
<Image.Source> |
|||
<CroppedBitmap Source="/Assets/delicate-arch-896885_640.jpg" SourceRect="0 0 320 240"/> |
|||
</Image.Source> |
|||
</Image> |
|||
</DockPanel> |
|||
|
|||
<StackPanel Orientation="Vertical"> |
|||
<TextBlock>UniformToFill</TextBlock> |
|||
<Image Source="/Assets/delicate-arch-896885_640.jpg" |
|||
Width="100" Height="200" |
|||
Stretch="UniformToFill"/> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
<StackPanel Orientation="Vertical"> |
|||
<TextBlock>Window Icon as an Image</TextBlock> |
|||
<Image Name="Icon" Width="100" Height="200" Stretch="None" /> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
<DockPanel Grid.Column="2" Grid.Row="1" Margin="16"> |
|||
<TextBlock DockPanel.Dock="Top" Classes="h3" Margin="0 8">Drawing</TextBlock> |
|||
<ComboBox Name="drawingStretch" DockPanel.Dock="Top" SelectedIndex="2" SelectionChanged="DrawingStretchChanged"> |
|||
<ComboBoxItem>None</ComboBoxItem> |
|||
<ComboBoxItem>Fill</ComboBoxItem> |
|||
<ComboBoxItem>Uniform</ComboBoxItem> |
|||
<ComboBoxItem>UniformToFill</ComboBoxItem> |
|||
</ComboBox> |
|||
<Image Name="drawingImage"> |
|||
<Image.Source> |
|||
<DrawingImage> |
|||
<GeometryDrawing Brush="Red"> |
|||
<PathGeometry> |
|||
<PathFigure StartPoint="0,0" IsClosed="True"> |
|||
<QuadraticBezierSegment Point1="50,0" Point2="50,-50" /> |
|||
<QuadraticBezierSegment Point1="100,-50" Point2="100,0" /> |
|||
<LineSegment Point="50,0" /> |
|||
<LineSegment Point="50,50" /> |
|||
</PathFigure> |
|||
</PathGeometry> |
|||
</GeometryDrawing> |
|||
</DrawingImage> |
|||
</Image.Source> |
|||
</Image> |
|||
</DockPanel> |
|||
</Grid> |
|||
|
|||
</DockPanel> |
|||
</UserControl> |
|||
|
|||
@ -1,41 +1,75 @@ |
|||
using System.IO; |
|||
using System; |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Imaging; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class ImagePage : UserControl |
|||
{ |
|||
private Image iconImage; |
|||
private readonly Image _bitmapImage; |
|||
private readonly Image _drawingImage; |
|||
private readonly Image _croppedImage; |
|||
|
|||
public ImagePage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
InitializeComponent(); |
|||
_bitmapImage = this.FindControl<Image>("bitmapImage"); |
|||
_drawingImage = this.FindControl<Image>("drawingImage"); |
|||
_croppedImage = this.FindControl<Image>("croppedImage"); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
iconImage = this.Get<Image>("Icon"); |
|||
} |
|||
|
|||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) |
|||
public void BitmapStretchChanged(object sender, SelectionChangedEventArgs e) |
|||
{ |
|||
if (_bitmapImage != null) |
|||
{ |
|||
var comboxBox = (ComboBox)sender; |
|||
_bitmapImage.Stretch = (Stretch)comboxBox.SelectedIndex; |
|||
} |
|||
} |
|||
|
|||
public void DrawingStretchChanged(object sender, SelectionChangedEventArgs e) |
|||
{ |
|||
base.OnAttachedToVisualTree(e); |
|||
if (iconImage.Source == null) |
|||
if (_drawingImage != null) |
|||
{ |
|||
var windowRoot = e.Root as Window; |
|||
if (windowRoot != null) |
|||
{ |
|||
using (var stream = new MemoryStream()) |
|||
{ |
|||
windowRoot.Icon.Save(stream); |
|||
stream.Seek(0, SeekOrigin.Begin); |
|||
iconImage.Source = new Bitmap(stream); |
|||
} |
|||
} |
|||
var comboxBox = (ComboBox)sender; |
|||
_drawingImage.Stretch = (Stretch)comboxBox.SelectedIndex; |
|||
} |
|||
} |
|||
|
|||
public void BitmapCropChanged(object sender, SelectionChangedEventArgs e) |
|||
{ |
|||
if (_croppedImage != null) |
|||
{ |
|||
var comboxBox = (ComboBox)sender; |
|||
var croppedBitmap = _croppedImage.Source as CroppedBitmap; |
|||
croppedBitmap.SourceRect = GetCropRect(comboxBox.SelectedIndex); |
|||
} |
|||
} |
|||
|
|||
private PixelRect GetCropRect(int index) |
|||
{ |
|||
var bitmapWidth = 640; |
|||
var bitmapHeight = 426; |
|||
var cropSize = new PixelSize(320, 240); |
|||
return index switch |
|||
{ |
|||
1 => new PixelRect(new PixelPoint((bitmapWidth - cropSize.Width) / 2, (bitmapHeight - cropSize.Width) / 2), cropSize), |
|||
2 => new PixelRect(new PixelPoint(0, 0), cropSize), |
|||
3 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, 0), cropSize), |
|||
4 => new PixelRect(new PixelPoint(0, bitmapHeight - cropSize.Height), cropSize), |
|||
5 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, bitmapHeight - cropSize.Height), cropSize), |
|||
_ => PixelRect.Empty |
|||
}; |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue