/* * 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. */ /* Mono expansion bit blt operation from command stream. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "write_bmp.h" /* Text data to expand, packed per 8x4 bits in 32 bit words */ static const uint32_t text_width = 128; static const uint32_t text_height = 8; static const uint32_t text_data[] = { 0xa9aada89, 0x00898a88, 0xc20528c8, 0x00c82825, 0x00008080, 0x00808000, 0x724a49f0, 0x00f24a4b, 0x27284887, 0x002728e0, 0x0808881c, 0x001c8888, 0x80804830, 0x00304880, 0x08080000, 0x00020508, 0xa29c0000, 0x001c20be, 0xcab10000, 0x00838083, 0x02e60002, 0x00c722c2, 0x221c0000, 0x001c2222, 0xc8b00000, 0x00888888, 0x03000807, 0x00070800, 0x00808000, 0x00189880, 0xa8988870, 0x007088c8 }; static const uint32_t text_size = sizeof(text_data)/4; int main(int argc, char **argv) { int rv; int width = 256; int height = 192; 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. */ memset(etna_bo_map(src), 255, src_size); 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(text_size); (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(x2) | VIV_FE_DRAW_2D_BOTTOM_RIGHT_Y(y2); } /* data in-stream */ ETNA_ALIGN(ctx); for(int ptr=0; ptrbuf[(ctx)->offset++] = text_data[ptr]; ETNA_ALIGN(ctx); 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; }