操作系统如何在屏幕上绘制窗口? [英] How does an operating system draw windows on the screen?

查看:20
本文介绍了操作系统如何在屏幕上绘制窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用和编程计算机多年后,我意识到实际在屏幕上绘制的软件堆栈对我来说大多是个谜.

I realized after many years of using and programming computers that the stack of software that actually draws on the screen is mostly a mystery to me.

我曾研究过一些嵌入式 LCD GUI 应用程序,我认为这为简化堆栈提供了一些线索,但 Windows 操作系统之类的应用程序的整体情况仍然模糊不清.

I have worked on some embedded LCD GUI applications and I think that provides some clues as to a simplified stack but the whole picture for something like the Windows operating system is still murky.

据我所知:

  • 最低级别 0 是电子硬件(集成电路),它提供数字接口以将屏幕上的像素变成特定颜色或灰度阴影.该界面记录在数据表中,因此您知道如何切换数字线以按照您希望的方式转动任何像素.
  • 下一级是硬件驱动程序.这通常将硬件抽象为一个公共接口.像 SetPixel() 之类的东西
  • 下一级是 2D/3D 图形库(其中小部件/单屏体验有限).较低级别似乎提供了表示屏幕上像素的缓冲区或内存范围.图形库对此进行了抽象,因此您可以调用 DrawText("text", 10, 10, "font") 等函数,它会以正确的方式为您设置像素.

  • Lowest level 0 is electronic hardware (integrated circuits) that provide a digital interface to turn a pixel on the screen a certain color or grey scale shade. The interface is documented in data sheets so you know how to toggle the digital lines to turn any pixel the way you want it.
  • Next level 1 is a hardware driver. This usually abstracts the hardware into a common interface. Something like SetPixel() etc.
  • Next level 2 is 2D/3D graphics library (of which I have limited widget/single screen experience). The lower levels seem to provide a buffer or range of memory that represents the pixels on the screen. The graphics library abstracts this so you can call functions like DrawText("text", 10, 10, "font") and it will set the pixels for you in the right way.

下一级将是操作系统的魔力.windows/buttons/forms/WPF/etc 在内存中创建,然后路由到适当的驱动程序,同时还被定向到屏幕的某个部分?

Next level would be the magic of the OS. The windows/buttons/forms/WPF/etc is created in memory and then routed to the appropriate driver while also being directed to a certain part of the screen?

但是像 Windows 这样的东西是如何真正工作的?

But how does something like Windows really work?

  • 我假设 GPU 介于 0 级和 1 级之间.GPU 直接驱动显示器上的像素,现在 1 级驱动程序是 GPU 驱动程序.还有更多功能可用于启用 GPU 提供的附加功能.(这会是什么?操作系统是否会在 3D 空间中传递一组三角形,然后 GPU 将其处理为 3D 透视图,然后将其放在屏幕上?)

对我来说最大的谜团是当你进入窗户的时候.您可以同时运行草图、Visual Studio 和 FPS 游戏,并能够在它们之间切换,或者在某些情况下将它们平铺在屏幕上或然后分布在多个屏幕上.这是如何跟踪和呈现的?每一个都必须在后台运行,操作系统必须说明哪个图形管道应该连接到屏幕的哪个部分.Windows 怎么会说这部分屏幕是 3D 游戏而这部分是 2D WPF 应用程序等?

The biggest mystery to me though is when you get into the windows part of things. You can have sketch up, visual studio and a FPS game all running at the same time and be able to switch between them, or in some cases tile them on the screen or have then spread across multiple screens. How is this tracked and rendered? Each of these would have to be running in the background and the OS would have to say which graphics pipe should be connected to which part of the screen. How would Windows say this part of the screen is a 3D game and this part is a 2D WPF app etc?

最重要的是,您在一个应用程序中使用了 DirectX,在另一个应用程序中使用了 Qt.我记得有多个使用相同技术的游戏或应用程序在运行,那么这将如何运作?从我所见,您将拥有应用程序-> 图形库(DirectX、WPF 等)-> 帧缓冲区-> Windows 控制器(此帧缓冲区应缩放到屏幕的何处和哪个部分)-> 驱动程序?

On top of that all you have DirectX used in one application and Qt in another. I remember having multiple games or apps running that use the same technology so how would that work? From what I can see you would have Application->Graphics library (DirectX, WPF etc)->Frame Buffer->Windows director (where and what part of the screen should this frame buffer be scaled to)->Driver?

最后它只是位切换以指示哪个像素应该是什么颜色,但在到达那里的过程中这是一个非常多的切换位.

In the end it is just bits toggling to indicate which pixel should be what color but it is one hell of a lot of toggling bits along the way to get there.

如果我启动 Visual Studio 并创建一个基本的 WPF 应用程序,当我在屏幕上放置一个按钮并点击开始时,后台会发生什么?我已经看到 VS 设计人员将它放在上面,在 XAML 中创建它,我什至在嵌入式系统中逐个像素地手动绘制东西,但中间会发生什么,所谓的三明治的肉?

If I fire up Visual Studio and create a basic WPF app what is all going on in the background when I drop a button on the screen and hit start? I have seen the VS designer to drop it on, created it in XAML and I have even manually drawn things pixel by pixel in an embedded system but what happens in between, the so-called meat of this sandwich?

我使用过 Android、iOS、Windows 和 Linux,它似乎是一个常见的功能,但我从未见过或听过关于我上面概述的背后的原因的解释,我只是有一点受过教育的猜测.

I have used Android, iOS, Windows and Linux and it seem to be a common functionality but I have never seen or heard an explanation of the how behind what I outline above, I only have a slightly educated guess.

有人能解释一下这是如何工作的吗?

Is anyone able to shed some light on how this works?

推荐答案

VGA

假设 x86,VGA 内存映射到最低 1 MiB 的标准视频缓冲区地址(文本模式为 0x000B8000,图形模式为 0x000A0000).还有许多 VGA 寄存器控制卡的行为.有两种广泛使用的视频模式,模式 0x12(16 色 640x480)和模式 0x13(256 色 320x200).模式 0x12 涉及带有 VGA 寄存器的切换平面(蓝、绿、红、白),而模式 0x13 涉及具有 256 色的调色板,可以使用 VGA 寄存器进行修改.

VGA

Assuming x86, VGA memory is mapped at a standard video buffer address in the lowest 1 MiB (0x000B8000 for text mode and 0x000A0000 for graphics mode). There are also many VGA registers that control the behaviour of the card. There were two widely used video modes, mode 0x12 (16-color 640x480) and mode 0x13 (256-color 320x200). Mode 0x12 involved switching planes (blue, green, red, white) with VGA registers, while mode 0x13 involved having a 256-color palette which can be modified using VGA registers.

通常,依赖 VGA 的操作系统会在启动时使用 BIOS 设置模式,或者在运行时写入适当的 VGA 寄存器(如果它知道自己在做什么).要绘制到屏幕上,视频驱动程序要么简单地写入视频内存(模式 0x13),要么将其与写入 VGA 寄存器的内容相结合(模式 0x12).

Normally, an OS relying on VGA would set the mode using BIOS while booting, or write to the appropriate VGA registers at runtime (if it knows what it is doing). To draw to the screen, the video driver would either simply write to the video memory (mode 0x13) or combine that with writing to VGA registers too (mode 0x12).

今天使用的大多数显卡仍然(部分)兼容 VGA.

Most cards in use today are still (partly) VGA compatible.

几年后,VESA 发明了VESA BIOS 扩展",这是视频卡的标准接口,允许更高的分辨率和更大的色深.视频内存通过两种不同的方式暴露:存储模式和线性帧缓冲区.分组模式会将一小部分视频内存暴露给低地址 (0x000A0000),并且视频驱动程序几乎在每次更新屏幕时都需要切换组.线性帧缓冲区是一种更方便的解决方案,它将整个视频内存映射到一个非标准的高地址.

Some years later, VESA invented "VESA BIOS Extensions", which was a standard interface for video cards and allowed higher resolutions and greater color depths. The video memory was exposed through two different ways: banked mode and linear framebuffer. The banked mode would expose some small portion of the video memory to a low address (0x000A0000) and the video driver would need to switch banks almost each time the screen is to be updated. The linear framebuffer is a much more convenient solution, which would map the entire video memory to a non-standard high address.

在启动过程中,操作系统会调用 VBE 接口来查询支持的模式并设置最方便的模式,或者它会绕过 VBE 接口并直接写入所需的视频硬件寄存器(如果它知道自己在做什么)).在存储模式和线性帧缓冲区之间,视频驱动程序将写入视频内存映射到的指定内存地址.

During boot, an OS would call the VBE interface to query for supported modes and to set the most convenient one, or it would bypass the VBE interface and write directly to the needed video hardware registers (if it knows what it is doing). In either between the banked mode and the linear framebuffer, the video driver would write to the specified memory address to which the video memory is mapped.

今天使用的大多数卡仍然(部分)兼容 VBE.

Most cards in use today are still (partly) VBE compatible.

最现代的视频接口通常不像 VGA 和/或 VBE 那样被广泛记录.然而,视频内存仍然映射到一个地址,而硬件寄存器和/或缓冲区包含有关图形卡行为的可修改信息.不同之处在于接口不再标准化,现在高级操作系统需要为每个显卡提供不同的驱动程序.

The most modern video interfaces usually aren't documented as widely as VGA and/or VBE. However, the video memory is still mapped at an address, while hardware registers and/or a buffer contain modifiable information about the behaviour of the graphics card. The difference is that the interfaces aren't standardised anymore and nowadays an advanced OS requires different drivers for each graphics card.

这篇关于操作系统如何在屏幕上绘制窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆