Пример #1
0
void *thread_1_func(void *p)
{
    (void)p;    // unused
    VdpPresentationQueueTarget pq_target;
    VdpPresentationQueue pq;
    VdpOutputSurface out_surface;
    VdpOutputSurface out_surface_2;
    VdpBitmapSurface bmp_surface;

    ASSERT_OK(vdpPresentationQueueTargetCreateX11(device, window, &pq_target));
    ASSERT_OK(vdpPresentationQueueCreate(device, pq_target, &pq));
    ASSERT_OK(vdpOutputSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 300, 150, &out_surface));
    ASSERT_OK(vdpOutputSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 300, 150, &out_surface_2));
    ASSERT_OK(vdpBitmapSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 300, 150, 1, &bmp_surface));

    uint32_t buf[300*150];
    for (uint32_t k = 0; k < 300*150; k ++)
        buf[k] = 0xff000000u + (k & 0xffffffu);

    const void * const source_data[] = { buf };
    uint32_t source_pitches[] = { 4 * 300 };

    ASSERT_OK(vdpBitmapSurfacePutBitsNative(bmp_surface, source_data, source_pitches, NULL));
    VdpTime vdpTime = 0;
    ASSERT_OK(vdpPresentationQueueBlockUntilSurfaceIdle(pq, out_surface, &vdpTime));
    ASSERT_OK(vdpPresentationQueueGetTime(pq, &vdpTime));

    VdpOutputSurfaceRenderBlendState blend_state = {
       .blend_factor_source_color=VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
       .blend_factor_destination_color=VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
       .blend_factor_source_alpha=VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
       .blend_factor_destination_alpha=VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
       .blend_equation_color=VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
       .blend_equation_alpha=VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
       .blend_constant = { 0, 0, 0, 0}
    };
    VdpRect source_rect = {0, 0, 300, 150};
    VdpRect destination_rect = {0, 0, 300, 150};
    ASSERT_OK(vdpOutputSurfaceRenderBitmapSurface(out_surface, &destination_rect, bmp_surface,
                &source_rect, NULL, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0));

    ASSERT_OK(vdpPresentationQueueDisplay(pq, out_surface, 0, 0, 0));

    ASSERT_OK(vdpOutputSurfaceDestroy(out_surface));
    ASSERT_OK(vdpOutputSurfaceDestroy(out_surface_2));
    ASSERT_OK(vdpPresentationQueueDestroy(pq));
    ASSERT_OK(vdpPresentationQueueTargetDestroy(pq_target));
    ASSERT_OK(vdpBitmapSurfaceDestroy(bmp_surface));

    return NULL;
}
Пример #2
0
void
test_bitmaps_of_format(VdpDevice device, int fmt, const char *fmt_name,
                       uint32_t max_width, uint32_t max_height)
{
    VdpBitmapSurface bmp_surf1;
    const uint32_t max_square_size = MIN(max_width, max_height);
    const uint32_t step = 128;

    // trying square surface
    for (uint32_t k = 0; k < max_square_size + step; (k < step) ? (k++) : (k+=step)) {
        for (uint32_t freq = 0; freq <= 1; freq ++) {
            const uint32_t size = MAX(1, MIN(k, max_square_size));
            printf("trying square %s bitmap %d x %d (%d)\n", fmt_name, size, size, freq);
            ASSERT_OK(vdpBitmapSurfaceCreate(device, fmt, size, size, freq, &bmp_surf1));
            ASSERT_OK(vdpBitmapSurfaceDestroy(bmp_surf1));
        }
    }

    // width stretched
    for (uint32_t k = 0; k < max_width + step; (k < step) ? (k++) : (k+=step)) {
        for (uint32_t freq = 0; freq <= 1; freq ++) {
            const uint32_t size = MAX(1, MIN(k, max_width));
            printf("trying width stretched %s bitmap %d x %d (%d)\n", fmt_name, size, 128, freq);
            ASSERT_OK(vdpBitmapSurfaceCreate(device, fmt, size, 128, freq, &bmp_surf1));
            ASSERT_OK(vdpBitmapSurfaceDestroy(bmp_surf1));
        }
    }

    // height stretched
    for (uint32_t k = 0; k < max_height + step; (k < step) ? (k++) : (k+=step)) {
        for (uint32_t freq = 0; freq <= 1; freq ++) {
            const uint32_t size = MAX(1, MIN(k, max_height));
            printf("trying height stretched %s bitmap %d x %d (%d)\n", fmt_name, 128, size, freq);
            ASSERT_OK(vdpBitmapSurfaceCreate(device, fmt, 128, size, freq, &bmp_surf1));
            ASSERT_OK(vdpBitmapSurfaceDestroy(bmp_surf1));
        }
    }
}
Пример #3
0
int main(void)
{
    VdpDevice device;
    Display *dpy = get_dpy();

    ASSERT_OK(vdpDeviceCreateX11(dpy, 0, &device, NULL));

    VdpOutputSurface out_surface_1;
    VdpOutputSurface out_surface_2;

    ASSERT_OK(vdpOutputSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 4, 4, &out_surface_1));
    ASSERT_OK(vdpOutputSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 4, 4, &out_surface_2));

    uint32_t black_box[] = {
        0xff000000, 0xff000000, 0xff000000, 0xff000000,
        0xff000000, 0xff000000, 0xff000000, 0xff000000,
        0xff000000, 0xff000000, 0xff000000, 0xff000000,
        0xff000000, 0xff000000, 0xff000000, 0xff000000
    };

    uint32_t two_red_dots[] = {
        0xff000000, 0xff000000, 0xff000000, 0xff000000,
        0xff000000, 0xffff0000, 0xff000000, 0xff000000,
        0xff000000, 0xff000000, 0xff000000, 0xff000000,
        0xff000000, 0xff000000, 0xff000000, 0xffff0000
    };

    const void * const source_data_1[] = {black_box};
    const void * const source_data_2[] = {two_red_dots};
    uint32_t source_pitches[] = { 4 * 4 };

    // upload data
    ASSERT_OK(vdpOutputSurfacePutBitsNative(out_surface_1, source_data_1, source_pitches, NULL));
    ASSERT_OK(vdpOutputSurfacePutBitsNative(out_surface_2, source_data_2, source_pitches, NULL));

    // render
    VdpOutputSurfaceRenderBlendState blend_state = {
        .struct_version =                   VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION,
        .blend_factor_source_color =        VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
        .blend_factor_source_alpha =        VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
        .blend_factor_destination_color =   VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
        .blend_factor_destination_alpha =   VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
        .blend_equation_color =             VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
        .blend_equation_alpha =             VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
        .blend_constant =                   {0, 0, 0, 0}
    };

    ASSERT_OK(vdpOutputSurfaceRenderOutputSurface(out_surface_1, NULL, out_surface_2, NULL,
                NULL, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0));

    // get data back
    uint32_t receive_buf[16];
    void * const dest_data[] = {receive_buf};
    ASSERT_OK(vdpOutputSurfaceGetBitsNative(out_surface_1, NULL, dest_data, source_pitches));

    printf("output surface\n");
    for (int k = 0; k < 16; k ++) {
        printf("%x ", receive_buf[k]);
        if (3 == k % 4) printf("\n");
    }
    printf("----------\n");
    for (int k = 0; k < 16; k ++) {
        printf("%x ", two_red_dots[k]);
        if (3 == k % 4) printf("\n");
    }

    // compare recieve_buf with two_red_dots
    if (memcmp(receive_buf, two_red_dots, 4*4*4)) {
        printf("fail\n");
        return 1;
    }

    // Check bitmap surface rendering smoothing issue
    VdpBitmapSurface bmp_surface;
    ASSERT_OK(vdpBitmapSurfaceCreate(device, VDP_RGBA_FORMAT_B8G8R8A8, 4, 4, 1, &bmp_surface));
    ASSERT_OK(vdpBitmapSurfacePutBitsNative(bmp_surface, source_data_2, source_pitches, NULL));
    VdpOutputSurfaceRenderBlendState blend_state_opaque_copy = {
        .struct_version =                   VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION,
        .blend_factor_source_color =        VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
        .blend_factor_source_alpha =        VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
        .blend_factor_destination_color =   VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
        .blend_factor_destination_alpha =   VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
        .blend_equation_color =             VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
        .blend_equation_alpha =             VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
        .blend_constant =                   {0, 0, 0, 0}
    };
    ASSERT_OK(vdpOutputSurfaceRenderBitmapSurface(out_surface_1, NULL, bmp_surface, NULL,
                NULL, &blend_state_opaque_copy, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0));
    ASSERT_OK(vdpOutputSurfaceGetBitsNative(out_surface_1, NULL, dest_data, source_pitches));

    printf("bitmap surface\n");
    for (int k = 0; k < 16; k ++) {
        printf("%x ", receive_buf[k]);
        if (3 == k % 4) printf("\n");
    }
    printf("----------\n");
    for (int k = 0; k < 16; k ++) {
        printf("%x ", two_red_dots[k]);
        if (3 == k % 4) printf("\n");
    }

    if (memcmp(receive_buf, two_red_dots, 4*4*4)) {
        printf("fail\n");
        return 2;
    }

    printf("pass\n");
    return 0;
}