如果一个窗口属于另外一个窗口的一个组件,那么可以将此窗口创建为子窗口,子窗口会继承父窗口的大部分属性,同时也可以单独设置其属性。父窗口隐藏或退出,子窗口也会跟随父窗口,这个可以保证应用的各个组件可以同步操作。
- 以字符串形式检索窗口ID,以便子窗口可以使用它来加入此窗口的组。SCREEN_PROPERTY_ID属性能保证获取的窗口ID在该系统中是唯一的
char window_group_name[64];
screen_get_window_property_cv(screen_window, SCREEN_PROPERTY_ID, sizeof(window_group_name), window_group_name );
- 创建一个子窗口
screen_window_t screen_child_window;
int wintype = SCREEN_CHILD_WINDOW;
screen_create_window_type(&screen_child_window, screen_ctx, wintype );
- 加入父窗口组
screen_join_window_group(screen_child_window,window_group_name);
- 创建一个内部缓冲区, 需要指定创建buffers的数量
int num_bufs = 1;
screen_create_window_buffers(screen_window, num_bufs);
- 设置buffers数据格式
int format = SCREEN_FORMAT_RGBA8888;
screen_set_buffer_property_iv(created_buf, SCREEN_PROPERTY_FORMAT, &format);
- 设置buffers大小
int bsize = {1920,1080};
screen_set_buffer_property_iv(created_buf, SCREEN_PROPERTY_BUFFER_SIZE, bsize);
- 设置stride
int stride = bsize[0] * bpp / 8;
screen_set_buffer_property_iv(created_buf, SCREEN_PROPERTY_STRIDE, &stride);
- 设置offset, 如果是YUV planar格式,例如NV12,需要设置此属性
int offset[3]; offset[0] = 0; offset[1] = bsize[1] * stride; offect[2] = -1;
screen_set_buffer_property_iv(created_buf, SCREEN_PROPERTY_STRIDE, &stride);
使用外部缓冲区,context必须使用SCREEN_BUFFER_PROVIDER_CONTEXT标志
- 设置需要创建的buffers的数量,用于缓存
#define MAX_BUFS_CNT 6
int buf_idx = 0;
int bufs_cnt = MAX_BUFS_CNT;
for(buf_idx =0; buf_idx < bufs_cnt; buf_idx++)
{
… …
}
- 创建一个缓冲区句柄,可以将其附加到窗口或像素图上
screen_buffer_t screen_bufs;
screen_create_buffer(screen_bufs[buf_idx]);
- 设置buffers数据格式
int format = SCREEN_FORMAT_RGBA8888;
screen_set_buffer_property_iv(screen_bufs[buf_idx], SCREEN_PROPERTY_FORMAT, &format);
- 设置buffers size
int bsize = {1920,1080};
screen_set_buffer_property_iv(screen_bufs[buf_idx], SCREEN_PROPERTY_BUFFER_SIZE, bsize);
- 设置stride
int stride = bsize[0] * bpp / 8;
screen_set_buffer_property_iv(screen_bufs, SCREEN_PROPERTY_STRIDE, &stride);
- 设置buffer 大小
int buf_capacity = stride * bsize[1];
screen_set_buffer_property_iv(screen_bufs[buf_idx], SCREEN_PROPERTY_SIZE, &buf_capacity);
- 设置offset, 如果是YUV planar格式,例如NV12,需要设置此属性
int offset[3]; offset[0] = 0; offset[1] = bsize[1] * stride; offect[2] = -1;
screen_set_buffer_property_iv(screen_bufs[buf_idx], SCREEN_PROPERTY_STRIDE, &offset);
- 根据外部传入的物理地址获取虚拟地址
unsigned *vaddr[MAX_BUFS_CNT];
vaddr[buf_idx] = mmap_device_memory(0, attr->buf_capacity, PROT_READ | PROT_WRITE, 0, phyaddr[buf_idx]);
- 将screen的buf指针指向外部缓冲区
screen_set_buffer_property_pv(screen_bufs[buf_idx], SCREEN_PROPERTY_POINTER, (void **)&vaddr[buf_idx]);
- 将缓冲区与窗口关联
screen_attach_window_buffers(screen_window, MAX_BUFS_CNT, screen_bufs);
- 在显示屏上刷新窗口内容
int rects[4] = {0, 0, 1920, 1080};
int count = 1;
screen_post_window(screen_window, screen_bufs[idx], count, rects, SCREEN_WAIT_IDLE);
rects中包含一个窗口矩形的x,y 坐标,宽度和高度。注意x,y坐标是相对坐标,相对与窗口的偏移位置
例如已经调用了screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_POSITION, pos);设置了窗口位置,那么此时x,y坐标应该是相对与这个pos的位置。