Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
d83cfcd4
U
Uno
项目概览
lindexi_gd
/
Uno
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Uno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d83cfcd4
编写于
8月 02, 2023
作者:
M
mergify[bot]
提交者:
GitHub
8月 02, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13070 from Youssef1313/render-target-bitmap
fix: Fix rendering of RenderTargetBitmap
上级
9aec0fd3
6c73bcd1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
62 addition
and
41 deletion
+62
-41
src/Uno.UI.Composition/Composition/SkiaCompositionSurface.skia.cs
...UI.Composition/Composition/SkiaCompositionSurface.skia.cs
+1
-3
src/Uno.UI.Composition/Composition/SkiaExtensions.skia.cs
src/Uno.UI.Composition/Composition/SkiaExtensions.skia.cs
+25
-0
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Media_Imaging/Given_RenderTargetBitmap.cs
...Windows_UI_Xaml_Media_Imaging/Given_RenderTargetBitmap.cs
+0
-4
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.Android.cs
...no.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.Android.cs
+35
-1
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.cs
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.cs
+0
-17
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.skia.cs
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.skia.cs
+1
-16
未找到文件。
src/Uno.UI.Composition/Composition/SkiaCompositionSurface.skia.cs
浏览文件 @
d83cfcd4
...
...
@@ -32,9 +32,7 @@ namespace Windows.UI.Composition
{
using
var
codec
=
SKCodec
.
Create
(
stream
);
var
info
=
codec
.
Info
;
var
bitmap
=
new
SKBitmap
(
actualTargetWidth
,
actualTargetHeight
,
info
.
ColorType
,
info
.
IsOpaque
?
SKAlphaType
.
Opaque
:
SKAlphaType
.
Premul
);
var
bitmap
=
new
SKBitmap
(
actualTargetWidth
,
actualTargetHeight
,
SKColorType
.
Bgra8888
,
SKAlphaType
.
Premul
);
var
result
=
codec
.
GetPixels
(
bitmap
.
Info
,
bitmap
.
GetPixels
());
...
...
src/Uno.UI.Composition/Composition/SkiaExtensions.skia.cs
浏览文件 @
d83cfcd4
...
...
@@ -97,5 +97,30 @@ namespace Windows.UI.Composition
return
ret
;
}
/// <summary>
/// This is an alternative to the built-in SKBitmap.FromImage.
/// The problem with SKBitmap.FromImage is that it ignores the color type of the input image, and
/// uses SKImageInfo.PlatformColorType.
/// The code is the same as SKBitmap.FromImage except for respecting color type.
/// See https://github.com/mono/SkiaSharp/blob/7d7766532a4666f56944e65bee1c2158c320f09c/binding/Binding/SKBitmap.cs#L830-L843
/// </summary>
public
static
SKBitmap
ToSKBitmap
(
this
SKImage
image
)
{
if
(
image
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
image
));
}
var
info
=
new
SKImageInfo
(
image
.
Width
,
image
.
Height
,
image
.
ColorType
,
image
.
AlphaType
);
var
bmp
=
new
SKBitmap
(
info
);
if
(!
image
.
ReadPixels
(
info
,
bmp
.
GetPixels
(),
info
.
RowBytes
,
0
,
0
))
{
bmp
.
Dispose
();
bmp
=
null
;
}
return
bmp
!;
}
}
}
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Media_Imaging/Given_RenderTargetBitmap.cs
浏览文件 @
d83cfcd4
...
...
@@ -88,10 +88,6 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Imaging
[
Ignore
(
"Not implemented yet."
)]
#elif __MACOS__
[
Ignore
(
"Currently fails on macOS, part of #9282 epic"
)]
#elif __SKIA__
[
Ignore
(
"Currently fails on CI for skia GTK (works locally)"
)]
#elif __ANDROID__
[
Ignore
(
"Currently fails on CI for Android https://github.com/unoplatform/uno/issues/9080"
)]
#endif
public
async
Task
When_Render_Then_CanRenderOnCanvas
()
{
...
...
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.Android.cs
浏览文件 @
d83cfcd4
...
...
@@ -9,6 +9,7 @@ using Windows.Foundation;
using
Java.Nio
;
using
Android.Views
;
using
Uno.UI.Xaml.Media
;
using
System.Runtime.InteropServices
;
namespace
Windows.UI.Xaml.Media.Imaging
{
...
...
@@ -39,9 +40,27 @@ namespace Windows.UI.Xaml.Media.Imaging
/// <inheritdoc />
private
protected
override
bool
IsSourceReady
=>
_buffer
!=
null
;
[
StructLayout
(
LayoutKind
.
Explicit
)]
private
struct
ByteArrayToIntArrayBridge
{
[
FieldOffset
(
0
)]
public
byte
[]
ByteArray
;
[
FieldOffset
(
0
)]
public
int
[]
IntArray
;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public
ByteArrayToIntArrayBridge
(
byte
[]
bytes
)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
ByteArray
=
bytes
;
}
}
private
static
ImageData
Open
(
byte
[]
buffer
,
int
bufferLength
,
int
width
,
int
height
)
{
return
ImageData
.
FromBitmap
(
BitmapFactory
.
DecodeByteArray
(
buffer
,
0
,
bufferLength
));
var
bitmap
=
Bitmap
.
CreateBitmap
(
new
ByteArrayToIntArrayBridge
(
buffer
).
IntArray
,
width
,
height
,
Bitmap
.
Config
.
Argb8888
!);
return
ImageData
.
FromBitmap
(
bitmap
);
}
private
(
int
ByteCount
,
int
Width
,
int
Height
)
RenderAsBgra8_Premul
(
UIElement
element
,
ref
byte
[]?
buffer
,
Size
?
scaledSize
=
null
)
...
...
@@ -105,5 +124,20 @@ namespace Windows.UI.Xaml.Media.Imaging
SetSoftwareRendering
(
element
,
false
);
}
}
[
global
::
System
.
Runtime
.
CompilerServices
.
MethodImpl
(
global
::
System
.
Runtime
.
CompilerServices
.
MethodImplOptions
.
AggressiveInlining
)]
private
static
void
SwapRB
(
ref
byte
[]
buffer
,
int
byteCount
)
{
for
(
var
i
=
0
;
i
<
byteCount
;
i
+=
4
)
{
//Swap R and B chanal
Swap
(
ref
buffer
![
i
],
ref
buffer
![
i
+
2
]);
}
}
private
static
void
Swap
(
ref
byte
a
,
ref
byte
b
)
{
(
a
,
b
)
=
(
b
,
a
);
}
}
}
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.cs
浏览文件 @
d83cfcd4
...
...
@@ -172,23 +172,6 @@ namespace Windows.UI.Xaml.Media.Imaging
buffer
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
length
);
}
}
#if !__IOS__ && !__MACOS__
[
global
::
System
.
Runtime
.
CompilerServices
.
MethodImpl
(
global
::
System
.
Runtime
.
CompilerServices
.
MethodImplOptions
.
AggressiveInlining
)]
private
static
void
SwapRB
(
ref
byte
[]
buffer
,
int
byteCount
)
{
for
(
var
i
=
0
;
i
<
byteCount
;
i
+=
4
)
{
//Swap R and B chanal
Swap
(
ref
buffer
![
i
],
ref
buffer
![
i
+
2
]);
}
}
private
static
void
Swap
(
ref
byte
a
,
ref
byte
b
)
{
(
a
,
b
)
=
(
b
,
a
);
}
#endif
#endif
#
endregion
}
...
...
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.skia.cs
浏览文件 @
d83cfcd4
...
...
@@ -14,21 +14,8 @@ namespace Windows.UI.Xaml.Media.Imaging
private
const
int
_bitsPerComponent
=
8
;
private
const
int
_bytesPerPixel
=
_bitsPerPixel
/
_bitsPerComponent
;
delegate
void
SwapColor
(
ref
byte
[]
buffer
,
int
byteCount
);
private
static
readonly
SwapColor
?
_platformSwap
=
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
OSX
)
?
SwapRB
:
default
;
private
static
ImageData
Open
(
byte
[]
buffer
,
int
bufferLength
,
int
width
,
int
height
)
{
if
(
_platformSwap
is
not
null
)
{
var
swappedBuffer
=
default
(
byte
[]);
EnsureBuffer
(
ref
swappedBuffer
,
bufferLength
);
Array
.
Copy
(
buffer
,
swappedBuffer
!,
bufferLength
);
_platformSwap
(
ref
swappedBuffer
!,
bufferLength
);
buffer
=
swappedBuffer
;
}
var
bufferHandle
=
GCHandle
.
Alloc
(
buffer
,
GCHandleType
.
Pinned
);
try
{
...
...
@@ -70,7 +57,7 @@ namespace Windows.UI.Xaml.Media.Imaging
var
img
=
surface
.
Snapshot
();
var
bitmap
=
SKBitmap
.
FromImage
(
img
);
var
bitmap
=
img
.
ToSKBitmap
(
);
if
(
scaledSize
.
HasValue
)
{
var
scaledBitmap
=
bitmap
.
Resize
(
...
...
@@ -84,8 +71,6 @@ namespace Windows.UI.Xaml.Media.Imaging
var
byteCount
=
bitmap
.
ByteCount
;
EnsureBuffer
(
ref
buffer
,
byteCount
);
bitmap
.
GetPixelSpan
().
CopyTo
(
buffer
);
//On macOS color as stored as rgba
_platformSwap
?.
Invoke
(
ref
buffer
!,
byteCount
);
bitmap
?.
Dispose
();
return
(
byteCount
,
width
,
height
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录