static void _boxblur (guchar *buffer, int width, int height, int radius, GskBlurFlags flags) { guchar *flipped_buffer; int d = get_box_filter_size (radius); flipped_buffer = g_malloc (width * height); if (flags & GSK_BLUR_Y) { /* Step 1: swap rows and columns */ flip_buffer (flipped_buffer, buffer, width, height); /* Step 2: blur rows (really columns) */ blur_rows (flipped_buffer, buffer, height, width, d); /* Step 3: swap rows and columns */ flip_buffer (buffer, flipped_buffer, height, width); } if (flags & GSK_BLUR_X) { /* Step 4: blur rows */ blur_rows (buffer, flipped_buffer, width, height, d); } g_free (flipped_buffer); }
handler_t recv_data(void * e, void * s) { char buff[1024]; int32_t len = 0; int32_t offset = 0; socket_t * st = (socket_t *)s; connection * ct = st->ct; if (st->status == ISWRITE) { while (1) { memset(buff, 0, sizeof(buff)); len = recv(st->fd, buff, sizeof(buff) - 1, 0); if (len == 0) { break; //木有数据了 }else if (len == -1) { //出错了 }else { while (len > 0) { // printf("len = %d\n",len); // printf("get_buffer_remaining(ct->packet) = %d\n",get_buffer_remaining(ct->packet)); if (buffer_has_remaining(ct->packet)) { int32_t remaining = get_buffer_remaining(ct->packet); if (remaining >= len) { put_buffers_len(ct->packet, buff, offset, len); if (buffer_has_remaining(ct->packet) == false) { flip_buffer(ct->packet); read_all_packet(ct); clear_buffer(ct->packet); } offset = 0; len = 0; } else { put_buffers_len(ct->packet, buff, offset, remaining); flip_buffer(ct->packet); read_all_packet(ct); clear_buffer(ct->packet); offset += remaining; len -= remaining; } } } } } } return HANDLER_GO_ON; }
int mmpfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { struct mmpfb_info *fbi = info->par; dev_dbg(info->dev, "cmd 0x%x, arg 0x%lx\n", cmd, arg); if (!mmp_path_ctrl_safe(fbi->path)) return -EINVAL; switch (cmd) { case FB_IOCTL_QUERY_GLOBAL_INFO: get_global_info(info, arg); break; case FB_IOCTL_FLIP_COMMIT: enable_commit(info, arg); break; case FB_IOCTL_WAIT_VSYNC: mmp_wait_vsync(&fbi->path->vsync); break; case FB_IOCTL_FLIP_USR_BUF: #ifdef CONFIG_MMP_FENCE return flip_buffer(info, arg); #else return flip_buffer_vsync(info, arg); #endif case FB_IOCTL_FLIP_VSYNC: return flip_buffer_vsync(info, arg); case FB_IOCTL_GAMMA_SET: return set_gamma(info, arg); case FB_IOCTL_SET_COLORKEYnALPHA: return set_colorkey_alpha(info, arg); case FB_IOCTL_GET_COLORKEYnALPHA: return get_colorkey_alpha(info, arg); case FB_IOCTL_ENABLE_DMA: return enable_dma(info, arg); case FB_IOCTL_VSMOOTH_EN: return vsmooth_en(info, arg); /* FB_IOCTL_ENABLE_COMMIT_DMA is only for overlay commit temporarily */ case FB_IOCTL_ENABLE_COMMIT_DMA: return enable_commit_dma(info, arg); case FB_IOCTL_SET_PATHALPHA: return set_path_alpha(info, arg); case FB_IOCTL_SET_DFC_RATE: return set_dfc_rate(info, arg); case FB_IOCTL_GET_DFC_RATE: return get_dfc_rate(info, arg); default: dev_info(info->dev, "unknown ioctl 0x%x\n", cmd); return -EINVAL; } return 0; }
static void _boxblur (guchar *buffer, int width, int height, int radius) { guchar *flipped_buffer; flipped_buffer = g_malloc (width * height); /* Step 1: swap rows and columns */ flip_buffer (flipped_buffer, buffer, width, height); /* Step 2: blur rows (really columns) */ blur_rows (flipped_buffer, buffer, height, width, radius); /* Step 3: swap rows and columns */ flip_buffer (buffer, flipped_buffer, height, width); /* Step 4: blur rows */ blur_rows (buffer, flipped_buffer, width, height, radius); g_free (flipped_buffer); }
static void make_shadow (MetaShadow *shadow, cairo_region_t *region) { int d = get_box_filter_size (shadow->key.radius); int spread = get_shadow_spread (shadow->key.radius); cairo_rectangle_int_t extents; cairo_region_t *row_convolve_region; cairo_region_t *column_convolve_region; guchar *buffer; int buffer_width; int buffer_height; int x_offset; int y_offset; int n_rectangles, j, k; cairo_region_get_extents (region, &extents); /* In the case where top_fade >= 0 and the portion above the top * edge of the shape will be cropped, it seems like we could create * a smaller buffer and omit the top portion, but actually, in our * multi-pass blur algorithm, the blur into the area above the window * in the first pass will contribute back to the final pixel values * for the top pixels, so we create a buffer as if we weren't cropping * and only crop when creating the CoglTexture. */ buffer_width = extents.width + 2 * spread; buffer_height = extents.height + 2 * spread; /* Round up so we have aligned rows/columns */ buffer_width = (buffer_width + 3) & ~3; buffer_height = (buffer_height + 3) & ~3; /* Square buffer allows in-place swaps, which are roughly 70% faster, but we * don't want to over-allocate too much memory. */ if (buffer_height < buffer_width && buffer_height > (3 * buffer_width) / 4) buffer_height = buffer_width; if (buffer_width < buffer_height && buffer_width > (3 * buffer_height) / 4) buffer_width = buffer_height; buffer = g_malloc0 (buffer_width * buffer_height); /* Blurring with multiple box-blur passes is fast, but (especially for * large shadow sizes) we can improve efficiency by restricting the blur * to the region that actually needs to be blurred. */ row_convolve_region = meta_make_border_region (region, spread, spread, FALSE); column_convolve_region = meta_make_border_region (region, 0, spread, TRUE); /* Offsets between coordinates of the regions and coordinates in the buffer */ x_offset = spread; y_offset = spread; /* Step 1: unblurred image */ n_rectangles = cairo_region_num_rectangles (region); for (k = 0; k < n_rectangles; k++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (region, k, &rect); for (j = y_offset + rect.y; j < y_offset + rect.y + rect.height; j++) memset (buffer + buffer_width * j + x_offset + rect.x, 255, rect.width); } /* Step 2: swap rows and columns */ buffer = flip_buffer (buffer, buffer_width, buffer_height); /* Step 3: blur rows (really columns) */ blur_rows (column_convolve_region, y_offset, x_offset, buffer, buffer_height, buffer_width, d); /* Step 4: swap rows and columns */ buffer = flip_buffer (buffer, buffer_height, buffer_width); /* Step 5: blur rows */ blur_rows (row_convolve_region, x_offset, y_offset, buffer, buffer_width, buffer_height, d); /* Step 6: fade out the top, if applicable */ if (shadow->key.top_fade >= 0) { for (j = y_offset; j < y_offset + MIN (shadow->key.top_fade, extents.height + shadow->outer_border_bottom); j++) fade_bytes(buffer + j * buffer_width, buffer_width, j - y_offset, shadow->key.top_fade); } /* We offset the passed in pixels to crop off the extra area we allocated at the top * in the case of top_fade >= 0. We also account for padding at the left for symmetry * though that doesn't currently occur. */ shadow->texture = cogl_texture_new_from_data (shadow->outer_border_left + extents.width + shadow->outer_border_right, shadow->outer_border_top + extents.height + shadow->outer_border_bottom, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_A_8, COGL_PIXEL_FORMAT_ANY, buffer_width, (buffer + (y_offset - shadow->outer_border_top) * buffer_width + (x_offset - shadow->outer_border_left))); cairo_region_destroy (row_convolve_region); cairo_region_destroy (column_convolve_region); g_free (buffer); shadow->material = meta_create_texture_material (shadow->texture); }
static int pxa168fb_ovly_ioctl(struct fb_info *fi, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; struct pxa168fb_info *fbi = (struct pxa168fb_info *)fi->par; struct pxa168fb_mach_info *mi = fbi->dev->platform_data; int vid_on = 1; int val = 0, mask = 0; unsigned char param; int blendval = 0; int res, tmp; int ret = 0; unsigned long flags; #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG debug_identify_called_ioctl(fi, cmd, arg); #endif switch (cmd) { case FB_IOCTL_CLEAR_FRAMEBUFFER: if (!mi->mmap) return -EINVAL; pxa168fb_clear_framebuffer(fi); return 0; break; case FB_IOCTL_WAIT_VSYNC: param = (arg & 0x3); wait_for_vsync(fbi, param); break; case FB_IOCTL_GET_VIEWPORT_INFO:/*if rotate 90/270, w/h swap*/ mutex_lock(&fbi->access_ok); if (fbi->surface.viewPortInfo.rotation == 90 || fbi->surface.viewPortInfo.rotation == 270) { tmp = fbi->surface.viewPortInfo.srcWidth; fbi->surface.viewPortInfo.srcWidth = fbi->surface.viewPortInfo.srcHeight; fbi->surface.viewPortInfo.srcHeight = tmp; fbi->surface.viewPortInfo.rotation = 360 - fbi->surface.viewPortInfo.rotation; } res = copy_to_user(argp, &fbi->surface.viewPortInfo, sizeof(struct _sViewPortInfo)) ? -EFAULT : 0; if (fbi->surface.viewPortInfo.rotation == 90 || fbi->surface.viewPortInfo.rotation == 270) { tmp = fbi->surface.viewPortInfo.srcWidth; fbi->surface.viewPortInfo.srcWidth = fbi->surface.viewPortInfo.srcHeight; fbi->surface.viewPortInfo.srcHeight = tmp; fbi->surface.viewPortInfo.rotation = 360 - fbi->surface.viewPortInfo.rotation; } mutex_unlock(&fbi->access_ok); return res; case FB_IOCTL_SET_VIEWPORT_INFO:/*if rotate 90/270, w/h swap*/ mutex_lock(&fbi->access_ok); memset(&gOvlySurface, 0, sizeof(gOvlySurface)); gOvlySurface.videoMode = -1; if (copy_from_user(&gOvlySurface.viewPortInfo, argp, sizeof(gOvlySurface.viewPortInfo))) { mutex_unlock(&fbi->access_ok); return -EFAULT; } if (unsupport_format(fbi, gOvlySurface.viewPortInfo, -1)) { mutex_unlock(&fbi->access_ok); return -EFAULT; } gOvlySurface.viewPortInfo.rotation = (360 - gOvlySurface.viewPortInfo.rotation) % 360; if (gOvlySurface.viewPortInfo.rotation == 90 || gOvlySurface.viewPortInfo.rotation == 270) { tmp = gOvlySurface.viewPortInfo.srcWidth; gOvlySurface.viewPortInfo.srcWidth = gOvlySurface.viewPortInfo.srcHeight; gOvlySurface.viewPortInfo.srcHeight = tmp; } ret = check_surface(fi, &gOvlySurface); if (ret > 0) { pxa168fb_set_par(fi); ret = 0; } else if (ret < 0) { pr_err("fbi %d (line %d): vid %d, check surface" "return error\n", fbi->id, __LINE__, fbi->vid); ret = -EFAULT; } mutex_unlock(&fbi->access_ok); return ret; break; case FB_IOCTL_SET_VIDEO_MODE: /* * Get data from user space. */ memset(&gOvlySurface, 0, sizeof(gOvlySurface)); if (copy_from_user(&gOvlySurface.videoMode, argp, sizeof(gOvlySurface.videoMode))) return -EFAULT; if (unsupport_format(fbi, gOvlySurface.viewPortInfo, gOvlySurface.videoMode)) return -EFAULT; ret = check_surface(fi, &gOvlySurface); if (ret > 0) { pxa168fb_set_par(fi); ret = 0; } else if (ret < 0) { pr_err("fbi %d (line %d): vid %d, check surface" "return error\n", fbi->id, __LINE__, fbi->vid); ret = -EFAULT; } return ret; break; case FB_IOCTL_GET_VIDEO_MODE: return copy_to_user(argp, &fbi->surface.videoMode, sizeof(u32)) ? -EFAULT : 0; case FB_IOCTL_FLIP_VID_BUFFER: return flip_buffer(fi, arg); case FB_IOCTL_GET_FREELIST: return get_freelist(fi, arg); case FB_IOCTL_FLIP_VSYNC: return flip_buffer_vsync(fi, arg); case FB_IOCTL_GET_BUFF_ADDR: { return copy_to_user(argp, &fbi->surface.videoBufferAddr, sizeof(struct _sVideoBufferAddr)) ? -EFAULT : 0; } case FB_IOCTL_SET_VID_OFFSET: mutex_lock(&fbi->access_ok); memset(&gOvlySurface, 0, sizeof(gOvlySurface)); gOvlySurface.videoMode = -1; if (copy_from_user(&gOvlySurface.viewPortOffset, argp, sizeof(gOvlySurface.viewPortOffset))) { mutex_unlock(&fbi->access_ok); return -EFAULT; } ret = check_surface(fi, &gOvlySurface); if (ret > 0) { pxa168fb_set_par(fi); ret = 0; } else if (ret < 0) { pr_err("fbi %d (line %d): vid %d, check surface" "return error\n", fbi->id, __LINE__, fbi->vid); ret = -EFAULT; } mutex_unlock(&fbi->access_ok); return ret; break; case FB_IOCTL_GET_VID_OFFSET: return copy_to_user(argp, &fbi->surface.viewPortOffset, sizeof(struct _sViewPortOffset)) ? -EFAULT : 0; case FB_IOCTL_SET_SURFACE: { mutex_lock(&fbi->access_ok); /* Get user-mode data. */ if (copy_from_user(&fbi->surface_bak, argp, sizeof(struct _sOvlySurface))) { mutex_unlock(&fbi->access_ok); return -EFAULT; } fbi->surface_set = 1; mutex_unlock(&fbi->access_ok); return 0; } case FB_IOCTL_GET_SURFACE: { mutex_lock(&fbi->access_ok); if (fbi->surface_set) { ret = copy_to_user(argp, &fbi->surface_bak, sizeof(struct _sOvlySurface)); } else { ret = copy_to_user(argp, &fbi->surface, sizeof(struct _sOvlySurface)); } ret = (ret ? -EFAULT : 0); mutex_unlock(&fbi->access_ok); return ret; } case FB_IOCTL_SET_COLORKEYnALPHA: if (copy_from_user(&fbi->ckey_alpha, argp, sizeof(struct _sColorKeyNAlpha))) return -EFAULT; pxa168fb_ovly_set_colorkeyalpha(fbi); break; case FB_IOCTL_GET_COLORKEYnALPHA: if (copy_to_user(argp, &fbi->ckey_alpha, sizeof(struct _sColorKeyNAlpha))) return -EFAULT; break; case FB_IOCTL_SWITCH_VID_OVLY: if (copy_from_user(&vid_on, argp, sizeof(int))) return -EFAULT; spin_lock_irqsave(&fbi->var_lock, flags); mask = CFG_DMA_ENA_MASK; fbi->dma_on = vid_on ? 1 : 0; val = CFG_DMA_ENA(check_modex_active(fbi)); if (!val && gfx_info.fbi[0]->active) { pxa688_vdma_release(fbi->id, fbi->vid); /* switch off, disable DMA */ dma_ctrl_set(fbi->id, 0, mask, val); } else if (list_empty(&fbi->buf_waitlist.dma_queue) && !fbi->buf_current) /* switch on, but no buf flipped, return error */ ; /* ret = -EAGAIN; */ printk(KERN_DEBUG "SWITCH_VID_OVLY fbi %d dma_on %d," " val %d, waitlist empty %d buf_current %p, ret %d\n", fbi->id, fbi->dma_on, val, list_empty(&fbi->buf_waitlist.dma_queue), fbi->buf_current, ret); pxa688fb_vsmooth_set(fbi->id, 1, vid_vsmooth & vid_on); spin_unlock_irqrestore(&fbi->var_lock, flags); return ret; break; case FB_IOCTL_SWAP_VIDEO_RED_BLUE: param = (arg & 0x1); dma_ctrl_set(fbi->id, 0, CFG_DMA_SWAPRB_MASK, CFG_DMA_SWAPRB(param)); return 0; break; case FB_IOCTL_SWAP_VIDEO_U_V: param = (arg & 0x1); dma_ctrl_set(fbi->id, 0, CFG_DMA_SWAPUV_MASK, CFG_DMA_SWAPUV(param)); return 0; break; case FB_IOCTL_SWAP_VIDEO_Y_UV: param = (arg & 0x1); dma_ctrl_set(fbi->id, 0, CFG_DMA_SWAPYU_MASK, CFG_DMA_SWAPYU(param)); return 0; break; case FB_IOCTL_PUT_VIDEO_ALPHABLEND: /* * This puts the blending control to the Video layer. */ mask = CFG_ALPHA_MODE_MASK | CFG_ALPHA_MASK; val = CFG_ALPHA_MODE(0) | CFG_ALPHA(0xff); dma_ctrl_set(fbi->id, 1, mask, val); return 0; break; case FB_IOCTL_PUT_GLOBAL_ALPHABLEND: /* * The userspace application can specify a byte value for the * amount of global blend between the video layer and thei * graphic layer. * * The alpha blending is per the formula below: * P = (V[P] * blendval/255) + (G[P] * (1 - blendval/255)) * where: P = Pixel value, V = Video Layer, * and G = Graphic Layer */ blendval = (arg & 0xff); mask = CFG_ALPHA_MODE_MASK | CFG_ALPHA_MASK; val = CFG_ALPHA_MODE(2) | CFG_ALPHA(blendval); dma_ctrl_set(fbi->id, 1, mask, val); return 0; break; case FB_IOCTL_PUT_GRAPHIC_ALPHABLEND: /* * This puts the blending back to the default mode of allowing * the graphic layer to do pixel level blending. */ mask = CFG_ALPHA_MODE_MASK | CFG_ALPHA_MASK; val = CFG_ALPHA_MODE(1) | CFG_ALPHA(0x0); dma_ctrl_set(fbi->id, 1, mask, val); return 0; break; default: break; } return 0; }
void draw_rectangles(cairo_t *fbcr, struct tsdev *ts, cairo_linuxfb_device_t *device) { int bufid = 1; /* start drawing into second buffer */ float r, g, b; int fbsizex = device->fb_vinfo.xres; int fbsizey = device->fb_vinfo.yres; int startx, starty, sizex, sizey; struct ts_sample sample; cairo_surface_t *surface; cairo_t *cr; float scale = 1.0f; surface = cairo_image_surface_create(CAIRO_FORMAT_RGB16_565, fbsizex, fbsizey); cr = cairo_create(surface); /* * We clear the cairo surface here before drawing * This is required in case something was drawn on this surface * previously, the previous contents would not be cleared without this. */ cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); srand(time(NULL)); while (!cancel) { r = (rand() % 100) / 100.0; g = (rand() % 100) / 100.0; b = (rand() % 100) / 100.0; startx = rand() % fbsizex; starty = rand() % fbsizey; sizex = rand() % (fbsizex - startx); sizey = rand() % (fbsizey - starty); cairo_identity_matrix(cr); if (ts) { int pressed = 0; /* Pressure is our identication whether we act on axis... */ while (ts_read(ts, &sample, 1)) { if (sample.pressure > 0) pressed = 1; } if (pressed) { scale *= 1.05f; cairo_translate(cr, sample.x, sample.y); cairo_scale(cr, scale, scale); //r = g = b = 0; startx = -5; starty = -5; sizex = 10; sizey = 10; } else { scale = 1.0f; } } cairo_set_source_rgb(cr, r, g, b); cairo_rectangle(cr, startx, starty, sizex, sizey); cairo_stroke_preserve(cr); cairo_fill(cr); /* Draw to framebuffer at y offset according to current buffer.. */ cairo_set_source_surface(fbcr, surface, 0, bufid * fbsizey); cairo_paint(fbcr); flip_buffer(device, 1, bufid); /* Switch buffer ID for next draw */ bufid = !bufid; usleep(20000); } /* Make sure we leave with buffer 0 enabled */ flip_buffer(device, 1, 0); /* Destroy and release all cairo related contexts */ cairo_destroy(cr); cairo_surface_destroy(surface); }