RealVNC源码学习笔记 二
1、服务器桌面图像的获取
在介绍怎么获取桌面之前,需要先了解几个用来保存桌面图像的类,这里称这些类为
framebuffer类族。framebuffer类族类族的继承关系如下(箭头指向的为父类):
就获取桌面图像来说,比较关键的是DeviceFrameBuffer、DIBSectionBuffer这两个类。在FullFramePixelBuffer类中,定义了一个U8类型的指针变量data,得到的桌面图像数据就保存在该变量中。data变量的内存空间分配在DIBSectionBuffer类的recreateBuffer函数中完成。
void DIBSectionBuffer::recreateBuffer() {
HBITMAP new_bitmap = 0;
rdr::U8* new_data = 0;
if (width_ && height_&& (format.depth != 0)) {
BitmapInfo bi;
memset(&bi, 0, sizeof(bi));
// *** wrong?
UINT iUsage = format.trueColour? DIB_RGB_COLORS : DIB_PAL_COLORS;
// 初始化位图信息
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biBitCount =format.bpp;//像素格式 format为一个像素格式类//PixelFormat的实例对象
bi.bmiHeader.biSizeImage =(format.bpp / 8) * width_ * height_;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biWidth = width_;
bi.bmiHeader.biHeight =-height_;//biHeight 的正负决定了获取的位图原点的位置,正//时,左下角为原点,负时左上角为原点
bi.bmiHeader.biCompression =(format.bpp > 8) ? BI_BITFIELDS : BI_RGB;
bi.mask.red = format.redMax<< format.redShift;
bi.mask.green = format.greenMax<< format.greenShift;
bi.mask.blue = format.blueMax<< format.blueShift;
// Create a DIBSection to drawinto
//创建一个位图,分配存储位图数据的地址空间,并将位图和数据地址相关联
if (device)
new_bitmap =::CreateDIBSection(device, (BITMAPINFO*)&bi.bmiHeader, iUsage,
(void**)&new_data, NULL, 0);
else
new_bitmap =::CreateDIBSection(WindowDC(window), (BITMAPINFO*)&bi.bmiHeader, iUsage,
(void**)&new_data, NULL, 0);
……//省略部分代码
if (bitmap) {