Path: blob/21.2-virgl/src/gallium/tests/graw/clear.c
4565 views
/* Display a cleared blue window. This demo has no dependencies on1* any utility code, just the graw interface and gallium.2*/34#include <stdio.h>5#include "frontend/graw.h"6#include "pipe/p_screen.h"7#include "pipe/p_context.h"8#include "pipe/p_state.h"9#include "pipe/p_defines.h"1011enum pipe_format formats[] = {12PIPE_FORMAT_RGBA8888_UNORM,13PIPE_FORMAT_BGRA8888_UNORM,14PIPE_FORMAT_NONE15};1617static const int WIDTH = 300;18static const int HEIGHT = 300;1920struct pipe_screen *screen;21struct pipe_context *ctx;22struct pipe_surface *surf;23struct pipe_resource *tex;24static void *window = NULL;2526static void draw( void )27{28union pipe_color_union clear_color = { {1, 0, 1, 1} };2930ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);31ctx->flush(ctx, NULL, 0);3233graw_save_surface_to_file(ctx, surf, NULL);3435screen->flush_frontbuffer(screen, ctx, tex, 0, 0, window, NULL);36}3738static void init( void )39{40struct pipe_framebuffer_state fb;41struct pipe_resource templat;42struct pipe_surface surf_tmpl;43int i;4445/* It's hard to say whether window or screen should be created46* first. Different environments would prefer one or the other.47*48* Also, no easy way of querying supported formats if the screen49* cannot be created first.50*/51for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {52screen = graw_create_window_and_screen(0, 0, 300, 300,53formats[i],54&window);55if (window && screen)56break;57}58if (!screen || !window) {59fprintf(stderr, "Unable to create window\n");60exit(1);61}6263ctx = screen->context_create(screen, NULL, 0);64if (ctx == NULL)65exit(3);6667memset(&templat, 0, sizeof(templat));68templat.target = PIPE_TEXTURE_2D;69templat.format = formats[i];70templat.width0 = WIDTH;71templat.height0 = HEIGHT;72templat.depth0 = 1;73templat.array_size = 1;74templat.last_level = 0;75templat.bind = (PIPE_BIND_RENDER_TARGET |76PIPE_BIND_DISPLAY_TARGET);7778tex = screen->resource_create(screen,79&templat);80if (tex == NULL)81exit(4);8283surf_tmpl.format = templat.format;84surf_tmpl.u.tex.level = 0;85surf_tmpl.u.tex.first_layer = 0;86surf_tmpl.u.tex.last_layer = 0;87surf = ctx->create_surface(ctx, tex, &surf_tmpl);88if (surf == NULL)89exit(5);9091memset(&fb, 0, sizeof fb);92fb.nr_cbufs = 1;93fb.width = WIDTH;94fb.height = HEIGHT;95fb.cbufs[0] = surf;9697ctx->set_framebuffer_state(ctx, &fb);98}99100static void args(int argc, char *argv[])101{102int i;103104for (i = 1; i < argc;) {105if (graw_parse_args(&i, argc, argv)) {106continue;107}108exit(1);109}110}111112int main( int argc, char *argv[] )113{114args(argc, argv);115init();116117graw_set_display_func( draw );118graw_main_loop();119return 0;120}121122123