简体   繁体   English

Kivy 如何实现跨平台兼容?

[英]How does Kivy achieve cross-platform compatibility?

What allows Kivy to be cross-platform compatible?是什么让 Kivy 跨平台兼容?

In other words, how can the same Kivy source code generate apps on multiple kinds of hardware platforms, such as desktop, iOS, and Android?换句话说,同一个 Kivy 源代码如何在桌面、iOS 和 Android 等多种硬件平台上生成应用程序?

I suppose there are two key extremes of achieving cross-platform compatibility:我认为实现跨平台兼容性有两个关键的极端:

  1. By implementing things in a different way on each platform so that Kivy is running different code on each one, but hiding that difference from the user by making the output appear the same.通过在每个平台上以不同的方式实现事物,以便 Kivy 在每个平台上运行不同的代码,但通过使输出看起来相同来向用户隐藏这种差异。
  2. By using external APIs that are supported by all the different platforms, so that Kivy's own code is basically the same and the platforms themselves take care of making it work.通过使用所有不同平台支持的外部 API,Kivy 自己的代码基本相同,平台本身负责使其工作。

Kivy has a bit of both of these, but in particular all the drawing uses OpenGL ES 2 which is the second type: all of Kivy's drawing logic is just about identical across all supported platforms. Kivy 有一点两者,但特别是所有绘图都使用 OpenGL ES 2,这是第二种类型:Kivy 的所有绘图逻辑在所有支持的平台上都几乎相同。 Of course there are other types too, eg when working out display metrics such as the pixel density Kivy uses a different method on each platform but doesn't expose any of that detail to the user.当然还有其他类型,例如,在计算像素密度等显示指标时,Kivy 在每个平台上使用不同的方法,但不会向用户公开任何细节。

Of course things are much more nuanced when considering things as a whole.当然,将事情作为一个整体考虑时,事情要微妙得多。 For instance, Kivy uses SDL2 as a library for creating a window, setting its size/pos handling pause/resume etc., so Kivy's code is of the second type here as it calls SDL2 in the same way on every platform.例如,Kivy 使用 SDL2 作为库来创建窗口,设置其大小/位置处理暂停/恢复等,因此 Kivy 的代码在这里属于第二种类型,因为它在每个平台上以相同的方式调用 SDL2。 However, SDL2 is not itself platform-native and is of the first type, implementing its API differently on different platforms but exposing the same API to Kivy on each one.然而,SDL2 本身并不是平台原生的,而是第一种类型,在不同平台上以不同方式实现其 API,但在每个平台上向 Kivy 公开相同的 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM