/* * Copyright (c) 2012-2013 Etnaviv Project * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sub license, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /* Draw color-patterned lines. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "write_bmp.h" int main(int argc, char **argv) { int rv; int width = 256; int height = 256; int padded_width = etna_align_up(width, 8); int padded_height = etna_align_up(height, 1); printf("padded_width %i padded_height %i\n", padded_width, padded_height); struct viv_conn *conn = 0; rv = viv_open(VIV_HW_2D, &conn); if(rv!=0) { fprintf(stderr, "Error opening device\n"); exit(1); } printf("Succesfully opened device\n"); struct etna_bo *bmp = 0; /* bitmap */ struct etna_bo *src = 0; /* source */ size_t bmp_size = width * height * 4; size_t src_size = width * height * 4; if((bmp=etna_bo_new(conn, bmp_size, DRM_ETNA_GEM_TYPE_BMP))==NULL || (src=etna_bo_new(conn, src_size, DRM_ETNA_GEM_TYPE_BMP))==NULL) { fprintf(stderr, "Error allocating video memory\n"); exit(1); } struct etna_ctx *ctx = 0; if(etna_create(conn, &ctx) != ETNA_OK) { printf("Unable to create context\n"); exit(1); } /* switch to 2D pipe */ etna_set_pipe(ctx, ETNA_PIPE_2D); /* pre-clear surface. Could use the 2D engine for this, * but we're lazy. */ uint32_t *bmp_map = etna_bo_map(bmp); for(int i=0; ibuf[(ctx)->offset++] = VIV_FE_DRAW_2D_HEADER_OP_DRAW_2D | VIV_FE_DRAW_2D_HEADER_COUNT(NUM_RECTS); (ctx)->offset++; /* rectangles start aligned */ (ctx)->buf[(ctx)->offset++] = VIV_FE_DRAW_2D_TOP_LEFT_X(0) | VIV_FE_DRAW_2D_TOP_LEFT_Y(0); (ctx)->buf[(ctx)->offset++] = VIV_FE_DRAW_2D_BOTTOM_RIGHT_X(width) | VIV_FE_DRAW_2D_BOTTOM_RIGHT_Y(height); (ctx)->buf[(ctx)->offset++] = VIV_FE_DRAW_2D_TOP_LEFT_X(width) | VIV_FE_DRAW_2D_TOP_LEFT_Y(0); (ctx)->buf[(ctx)->offset++] = VIV_FE_DRAW_2D_BOTTOM_RIGHT_X(0) | VIV_FE_DRAW_2D_BOTTOM_RIGHT_Y(height); etna_set_state(ctx, 1, 0); etna_set_state(ctx, 1, 0); etna_set_state(ctx, 1, 0); etna_set_state(ctx, VIVS_GL_FLUSH_CACHE, VIVS_GL_FLUSH_CACHE_PE2D); etna_finish(ctx); } bmp_dump32(etna_bo_map(bmp), width, height, false, "/tmp/fb.bmp"); printf("Dump complete\n"); etna_free(ctx); viv_close(conn); return 0; }