QNX Screen---Blit

 Screen提供本机渲染 API,这些 API 使用硬件 blitter 从内存到另一个内存,而不涉及 CPU。图形处理需要大量的内存管理和内存区域的移动。为了有效地做到这一点,通常支持位比特硬件元素。位字节转换器能够识别不同的显示格式和内存布局,因此它移动的不是字节,而是像素。blitter还可以提供某些图形功能,如缩放、像素格式转换和透明混合。

blit操作将矩形像素区域从源缓冲区复制到目标缓冲区。应用程序可以通过Scree API提供的以下API访问:

1.screen_blit()
2.screen_fill()

通常在应用程序中执行blit操作需要完成以下步骤:

1.创建渲染目标;

2.访问缓冲区;

3.绘制到缓冲区中;

4.触发blit操作。

接口概要说明:

a) screen_create_pixmap():创建离屏渲染的像素映射;

b) screen_get_context_property_iv():获取context指定整型属性值;

c) screen_set_pixmap_property_iv():设置指定属性值;

d) int screen_fill(screen_context_t ctx, screen_buffer_t dst, const int *attribs):填充指定缓冲区;

e) int screen_blit(screen_context_t ctx, screen_buffer_t dst, screen_buffer_t src, const int *attribs):将像素从src拷贝到dst缓冲区;
int screen_flush_context(screen_context_t ctx, int flags):刷新指定的context,其中flags对应的有效值有以下两种:

1)SCREEN_WAIT_IDLE:函数将阻塞,仅当所有有效的显示得到刷新后才返回;
2)0:函数不阻塞,但blit操作可能为彻底完成。

f) int screen_flush_blits(screen_context_t ctx, int flags):刷新所有的blit,参数解析同上。

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define DISPLAY_WIDTH 1920
#define DISPLAY_HEIGHT 720
#define DISPLAY_ZORDER 50

int Share_Pixmap()
{
    int err;
    printf("Share_Pixmap\n");
    screen_context_t screen_ctx;
    screen_window_t screen_window;
    screen_pixmap_t screen_pixmap;
    screen_buffer_t win_buf[2];
    screen_create_context(&screen_ctx, SCREEN_DISPLAY_MANAGER_CONTEXT);

    int count = 0;
    screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count);

    screen_display_t *screen_displays = (screen_display_t*)calloc(count, sizeof(screen_display_t));

    screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void**)screen_displays);
    for(int i = 0; i < count; ++i)
    {
        int display_id;
        int size[2];
        screen_get_display_property_iv(screen_displays[i], SCREEN_PROPERTY_ID, &display_id);
        screen_get_display_property_iv(screen_displays[i], SCREEN_PROPERTY_SIZE, size);
        printf("screenshot = %d, width = %d, height = %d\n", display_id, size[0], size[1]);
    }
    screen_display_t screen_display = screen_displays[0];

    /*********window**********/
    screen_create_window(&screen_window, screen_ctx);

    int usage = SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE | SCREEN_USAGE_WRITE;
    screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage);

    screen_create_window_buffers(screen_window, 2);
    screen_get_window_property_pv(screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)win_buf);

    int zorder = DISPLAY_ZORDER;
    screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_ZORDER, &zorder);

    /***********pixmap********/
    err = screen_create_pixmap(&screen_pixmap, screen_ctx);
    if(err != 0)
    {
        printf("failed to create pixmap\n");
        return EXIT_FAILURE;
    }

    err = screen_set_pixmap_property_iv(screen_pixmap, SCREEN_PROPERTY_FORMAT, (const int[]){SCREEN_FORMAT_RGBA8888});
    if(err != 0)
    {
        printf("failed to set format\n");
        return EXIT_FAILURE;
    }

    err = screen_set_pixmap_property_iv(screen_pixmap, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_NATIVE | SCREEN_USAGE_OPENGL_ES2});
    if(err != 0)
    {
        printf("failed to set usage\n");
        return EXIT_FAILURE;
    }

    err = screen_set_pixmap_property_iv(screen_pixmap, SCREEN_PROPERTY_BUFFER_SIZE, (const int[]){DISPLAY_WIDTH, DISPLAY_HEIGHT});
    if(err != 0)
    {
        printf("failed to set buffer size\n");
        return EXIT_FAILURE;
    }

    int screen_stride = DISPLAY_WIDTH;
    int rect[4] = { 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT};
    screen_buffer_t pixmap_buf = 0;
    char *screen_ptr = nullptr;

    screen_create_pixmap_buffer(screen_pixmap);
    screen_get_pixmap_property_pv(screen_pixmap, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&pixmap_buf);
    screen_get_buffer_property_pv(pixmap_buf, SCREEN_PROPERTY_POINTER, (void **)&screen_ptr);
    screen_get_buffer_property_iv(pixmap_buf, SCREEN_PROPERTY_STRIDE, &screen_stride);

    int bg[] = { SCREEN_BLIT_COLOR, (int)0xFFFFFF00, SCREEN_BLIT_END };
    screen_fill(screen_ctx, win_buf[0], bg);

    int bar[] = {
           SCREEN_BLIT_COLOR, (int)0xFF0000FF,
           SCREEN_BLIT_DESTINATION_X, pos,
           SCREEN_BLIT_DESTINATION_WIDTH, 32,
           SCREEN_BLIT_END
          };
     screen_fill(screen_ctx, win_buf[0], bar);           

    int rbar[] = {
                SCREEN_BLIT_COLOR, (int)0x0FFF0000,
                SCREEN_BLIT_DESTINATION_X, DISPLAY_WIDTH / 2,
                SCREEN_BLIT_DESTINATION_WIDTH, 32,
                SCREEN_BLIT_END
            };
    screen_fill(screen_ctx, win_buf[0], rbar);

    int args[] = {
        SCREEN_BLIT_SOURCE_X, 0,
        SCREEN_BLIT_SOURCE_Y, 0,
        SCREEN_BLIT_SOURCE_WIDTH, DISPLAY_WIDTH,
        SCREEN_BLIT_SOURCE_HEIGHT, DISPLAY_HEIGHT,
        SCREEN_BLIT_DESTINATION_X, 0,
        SCREEN_BLIT_DESTINATION_Y, DISPLAY_HEIGHT / 2,
        SCREEN_BLIT_DESTINATION_WIDTH, DISPLAY_WIDTH / 2,
        SCREEN_BLIT_DESTINATION_HEIGHT, DISPLAY_HEIGHT / 2,
        SCREEN_BLIT_TRANSPARENCY, SCREEN_TRANSPARENCY_SOURCE_OVER,
        SCREEN_BLIT_END
    };

    screen_read_display(screen_display, pixmap_buf, 0, NULL, 0);
    screen_blit(screen_ctx, win_buf[0], pixmap_buf, args);

    screen_flush_context(screen_ctx, SCREEN_WAIT_IDLE);
    screen_flush_blits(screen_ctx, SCREEN_WAIT_IDLE);  
    screen_post_window(screen_window, win_buf[0], 1, rect, 0);         
    return EXIT_SUCCESS;
}

你可能感兴趣的:(QNX,Screen,C++,c++)