mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-24 04:06:49 +00:00
[Mac] Fixed cursor byte order
This commit is contained in:
parent
2632661d8a
commit
e63970e2be
|
@ -796,6 +796,7 @@
|
|||
</Compile>
|
||||
<Compile Include="Platform\MacOS\Carbon\Cgl.cs" />
|
||||
<Compile Include="WindowIcon.cs" />
|
||||
<Compile Include="Platform\MacOS\Cocoa\NSBitmapFormat.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace OpenTK.Platform.MacOS
|
|||
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, RectangleF rectangle1, int int1, IntPtr intPtr1, IntPtr intPtr2);
|
||||
|
||||
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
|
||||
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr p1, int p2, int p3, int p4, int p5, int p6, int p7, IntPtr p8, int p9, int p10);
|
||||
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr p1, int p2, int p3, int p4, int p5, int p6, int p7, IntPtr p8, NSBitmapFormat p9, int p10, int p11);
|
||||
|
||||
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
|
||||
public extern static bool SendBool(IntPtr receiver, IntPtr selector);
|
||||
|
|
42
Source/OpenTK/Platform/MacOS/Cocoa/NSBitmapFormat.cs
Normal file
42
Source/OpenTK/Platform/MacOS/Cocoa/NSBitmapFormat.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
#region License
|
||||
//
|
||||
// NSBitmapFormat.cs
|
||||
//
|
||||
// Author:
|
||||
// Stefanos A. <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenTK.Platform.MacOS
|
||||
{
|
||||
[Flags]
|
||||
enum NSBitmapFormat
|
||||
{
|
||||
AlphaFirst = 1 << 0,
|
||||
AlphaNonpremultiplied = 1 << 1,
|
||||
FloatingPointSamples = 1 << 2
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ namespace OpenTK.Platform.MacOS
|
|||
static readonly IntPtr selAddCursorRect = Selector.Get("addCursorRect:cursor:");
|
||||
static readonly IntPtr selInvalidateCursorRectsForView = Selector.Get("invalidateCursorRectsForView:");
|
||||
static readonly IntPtr selInitWithBitmapDataPlanes =
|
||||
Selector.Get("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:");
|
||||
Selector.Get("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:");
|
||||
static readonly IntPtr selBitmapData = Selector.Get("bitmapData");
|
||||
static readonly IntPtr selAddRepresentation = Selector.Get("addRepresentation:");
|
||||
static readonly IntPtr selInitWithImageHotSpot = Selector.Get("initWithImage:hotSpot:");
|
||||
|
@ -969,6 +969,7 @@ namespace OpenTK.Platform.MacOS
|
|||
1,
|
||||
0,
|
||||
NSDeviceRGBColorSpace,
|
||||
NSBitmapFormat.AlphaFirst,
|
||||
4 * cursor.Width,
|
||||
32),
|
||||
Selector.Autorelease);
|
||||
|
@ -979,21 +980,24 @@ namespace OpenTK.Platform.MacOS
|
|||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
// Premultiply and copy the cursor data
|
||||
// Copy the cursor data
|
||||
int i = 0;
|
||||
IntPtr data = Cocoa.SendIntPtr(imgdata, selBitmapData);
|
||||
for (int y = 0; y < cursor.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < cursor.Width; x++)
|
||||
{
|
||||
byte a = cursor.Argb[i];
|
||||
byte r = (byte)((cursor.Argb[i + 1] * a) / 255);
|
||||
byte g = (byte)((cursor.Argb[i + 2] * a) / 255);
|
||||
byte b = (byte)((cursor.Argb[i + 3] * a) / 255);
|
||||
Marshal.WriteByte(data, i++, a);
|
||||
Marshal.WriteByte(data, i++, r);
|
||||
Marshal.WriteByte(data, i++, g);
|
||||
Marshal.WriteByte(data, i++, b);
|
||||
uint argb = unchecked((uint)BitConverter.ToInt32(cursor.Argb, i));
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
argb =
|
||||
(argb & 0x000000FFu) << 24 |
|
||||
(argb & 0x0000FF00u) << 8 |
|
||||
(argb & 0x00FF0000u) >> 8 |
|
||||
(argb & 0xFF000000u) >> 24;
|
||||
}
|
||||
Marshal.WriteInt32(data, i, unchecked((int)argb));
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue