mdp_test.c revision 9a8ffbeff88c7b09cc9a86191c7a7fd665ddd980
1/* 2 * Copyright (C) 2007 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <stdlib.h> 18#include <unistd.h> 19 20#include <fcntl.h> 21#include <stdio.h> 22 23#include <sys/ioctl.h> 24#include <sys/mman.h> 25#include <sys/types.h> 26 27#include <linux/fb.h> 28#include <linux/msm_mdp.h> 29 30static struct fb_var_screeninfo vi; 31 32static int get_framebuffer(int *fd, char **fb, int *width, int *height) 33{ 34 struct fb_fix_screeninfo fi; 35 void *bits; 36 37 *fd = open("/dev/graphics/fb0", O_RDWR); 38 if(*fd < 0) { 39 perror("cannot open fb0"); 40 return -1; 41 } 42 43 if(ioctl(*fd, FBIOGET_FSCREENINFO, &fi) < 0) { 44 perror("failed to get fb0 info"); 45 return -1; 46 } 47 48 if(ioctl(*fd, FBIOGET_VSCREENINFO, &vi) < 0) { 49 perror("failed to get fb0 info"); 50 return -1; 51 } 52 53 bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); 54 if(bits == MAP_FAILED) { 55 perror("failed to mmap framebuffer"); 56 return -1; 57 } 58 59 *width = vi.xres; 60 *height = vi.yres; 61 *fb = bits; 62 return 0; 63} 64 65static void set_active_framebuffer(int fd, unsigned n) 66{ 67 68 if(n > 1) return; 69 vi.yres_virtual = vi.yres * 2; 70 vi.yoffset = n * vi.yres; 71 if(ioctl(fd, FBIOPUT_VSCREENINFO, &vi) < 0) { 72 fprintf(stderr,"active fb swap failed!\n"); 73 } 74} 75 76int main(int argc, const char *argv[]) { 77 int fd, width, height; 78 char* fb; 79 struct mdp_blit_req_list *req_list; 80 struct mdp_blit_req *req; 81 int srw, srh, drw, drh; 82 int srcx = 0; int srcy = 0; 83 int dstx = 10; int dsty = 10; 84 85 req_list = malloc(sizeof(struct mdp_blit_req_list) + 86 sizeof(struct mdp_blit_req)); 87 req_list->count = 1; 88 req = req_list->req; 89 90 if (argc < 5) 91 printf("not enough args\n"); 92 srw = atoi(argv[1]); 93 srh = atoi(argv[2]); 94 drw = atoi(argv[3]); 95 drh = atoi(argv[4]); 96 97 if (argc >= 7) { 98 srcx = atoi(argv[5]); 99 srcy = atoi(argv[6]); 100 } 101 102 if (argc == 9) { 103 dstx = atoi(argv[7]); 104 dsty = atoi(argv[8]); 105 } 106 107 108 if (get_framebuffer(&fd, &fb, &width, &height)) { 109 printf("couldnt' get fb\n"); 110 return -1; 111 } 112 /* 113 req->src.width = 448; 114 req->src.height = 320; 115 */ 116 req->src.width = vi.xres; 117 req->src.height = vi.yres; 118 req->src.format = MDP_RGB_565/*MDP_Y_CBCR_H2V2*/; 119 req->src.offset = 0; 120 req->src.memory_id = fd; 121 req->src_rect.x = srcx; 122 req->src_rect.y = srcy; 123 req->src_rect.w = srw; 124 req->src_rect.h = srh; 125 126 req->dst.width = vi.xres; 127 req->dst.height = vi.yres; 128 req->dst.format = MDP_RGB_565; 129 req->dst.offset = 0; 130 req->dst.memory_id = fd; 131 req->dst_rect.x = dstx; 132 req->dst_rect.y = dsty; 133 req->dst_rect.w = drw; 134 req->dst_rect.h = drh; 135 req->alpha = MDP_ALPHA_NOP; 136 req->transp_mask = MDP_TRANSP_NOP; 137// req->flags = MDP_ROT_90; 138 req->flags = MDP_ROT_NOP; 139 140 if(ioctl(fd, MSMFB_BLIT, req_list)) 141 fprintf(stderr, "crap, failed blit\n"); 142 return 0; 143} 144