/* * 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. */ /* Test bit_blt operation (rotated 90 degrees). */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "write_bmp.h" #include "read_png.h" int main(int argc, char **argv) { int rv; int width = 256; int height = 256; size_t dst_stride = etna_align_up(width, 8) * 4; 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"); /* Read test image */ int src_width, src_height, src_stride; uint32_t *src_data = 0; if(!read_png("amethyst256.png", 8*4, &src_stride, &src_width, &src_height, &src_data)) { printf("Unable to read amethyst256.png in current directory\n"); exit(1); } struct etna_bo *bmp = 0; /* bitmap */ struct etna_bo *src = 0; /* source */ size_t bmp_size = dst_stride * height; size_t src_size = src_stride * src_height; 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) | VIV_FE_DRAW_2D_HEADER_DATA_COUNT(0); (ctx)->offset++; /* rectangles start aligned */ for(int rec=0; recbuf[(ctx)->offset++] = VIV_FE_DRAW_2D_TOP_LEFT_X(x1) | VIV_FE_DRAW_2D_TOP_LEFT_Y(y1); (ctx)->buf[(ctx)->offset++] = VIV_FE_DRAW_2D_BOTTOM_RIGHT_X(x1 + tgt_width) | VIV_FE_DRAW_2D_BOTTOM_RIGHT_Y(y1 + tgt_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_noflip(etna_bo_map(bmp), width, height, true, "/tmp/fb.bmp"); printf("Dump complete\n"); etna_free(ctx); viv_close(conn); return 0; }