static gr_surface adf_flip(struct minui_backend *backend)
{
    struct adf_pdata *pdata = (struct adf_pdata *)backend;
    struct adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface]; 
    int fence_fd = adf_interface_simple_post(pdata->intf_fd, pdata->eng_id,
            surf->base.width, surf->base.height, pdata->format, surf->fd,
            surf->offset, surf->pitch, -1);

    //ActionsCode(author:lipeng, type:newcode, comment: save fence_fd)
    surf->fence_fd = fence_fd;
    // end ActionsCode

#if 0    // android original code
    if (fence_fd >= 0)
        close(fence_fd);
#endif

    pdata->current_surface = (pdata->current_surface + 1) % pdata->n_surfaces;

    //ActionsCode(author:lipeng, type:newcode, comment: wait fence)
    if (pdata->surfaces[pdata->current_surface].fence_fd >= 0) {
        sync_wait(pdata->surfaces[pdata->current_surface].fence_fd, 1000);
        close(pdata->surfaces[pdata->current_surface].fence_fd);
        pdata->surfaces[pdata->current_surface].fence_fd = -1;
    }
    // end ActionsCode

    return &pdata->surfaces[pdata->current_surface].base;
}
static int adf_fbdev_post(struct adf_fbdev *fbdev)
{
	struct adf_buffer buf;
	struct sync_fence *complete_fence;
	int ret = 0;

	memset(&buf, 0, sizeof(buf));
	buf.overlay_engine = fbdev->eng;
	buf.w = fbdev->info->var.xres;
	buf.h = fbdev->info->var.yres;
	buf.format = fbdev->format;
	buf.dma_bufs[0] = fbdev->dma_buf;
	buf.offset[0] = fbdev->offset +
			fbdev->info->var.yoffset * fbdev->pitch +
			fbdev->info->var.xoffset *
			(fbdev->info->var.bits_per_pixel / 8);
	buf.pitch[0] = fbdev->pitch;
	buf.n_planes = 1;

	complete_fence = adf_interface_simple_post(fbdev->intf, &buf);
	if (IS_ERR(complete_fence)) {
		ret = PTR_ERR(complete_fence);
		goto done;
	}

	sync_fence_put(complete_fence);
done:
	return ret;
}
TEST_F(AdfTest, simple_buffer) {
    uint32_t w = 0, h = 0;
    ASSERT_NO_FATAL_FAILURE(getCurrentMode(w, h));

    uint32_t format = 0;
    char format_str[ADF_FORMAT_STR_SIZE];
    ASSERT_NO_FATAL_FAILURE(get8888Format(format, format_str));

    uint32_t offset;
    uint32_t pitch;
    int buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, format, &offset,
            &pitch);
    ASSERT_GE(buf_fd, 0) << "allocating " << w << "x" << h << " " <<
            format_str << " buffer failed: " << strerror(-buf_fd);
    EXPECT_GE(pitch, w * 4);

    void *mapped = mmap(NULL, pitch * h, PROT_WRITE, MAP_SHARED, buf_fd,
            offset);
    ASSERT_NE(mapped, MAP_FAILED) << "mapping " << w << "x" << h << " " <<
            format_str << " buffer failed: " << strerror(-errno);
    drawCheckerboard(mapped, w, h, pitch);
    munmap(mapped, pitch * h);

    ASSERT_NO_FATAL_FAILURE(attach());
    ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));

    int release_fence = adf_interface_simple_post(intf, eng_id, w, h, format,
            buf_fd, offset, pitch, -1);
    close(buf_fd);
    ASSERT_GE(release_fence, 0) << "posting " << w << "x" << h << " " <<
            format_str << " buffer failed: " << strerror(-release_fence);
    close(release_fence);
}
GRSurface* MinuiBackendAdf::Flip() {
  GRSurfaceAdf* surf = &surfaces[current_surface];

  int fence_fd = adf_interface_simple_post(intf_fd, eng_id, surf->width, surf->height, format,
                                           surf->fd, surf->offset, surf->pitch, -1);
  if (fence_fd >= 0) surf->fence_fd = fence_fd;

  current_surface = (current_surface + 1) % n_surfaces;
  Sync(&surfaces[current_surface]);
  return &surfaces[current_surface];
}
static GRSurface* adf_flip(minui_backend *backend)
{
    adf_pdata *pdata = (adf_pdata *)backend;
    adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface];

    int fence_fd = adf_interface_simple_post(pdata->intf_fd, pdata->eng_id,
            surf->base.width, surf->base.height, pdata->format, surf->fd,
            surf->offset, surf->pitch, -1);
    if (fence_fd >= 0)
        close(fence_fd);

    pdata->current_surface = (pdata->current_surface + 1) % pdata->n_surfaces;
    return &pdata->surfaces[pdata->current_surface].base;
}