コード例 #1
1
ファイル: drm_egl.c プロジェクト: yoimbert/mpv
static int drm_egl_init(struct MPGLContext *ctx, int flags)
{
    struct priv *p = ctx->priv;
    p->kms = NULL;
    p->old_crtc = NULL;
    p->gbm.surface = NULL;
    p->gbm.device = NULL;
    p->active = false;
    p->waiting_for_flip = false;
    p->ev.version = DRM_EVENT_CONTEXT_VERSION;
    p->ev.page_flip_handler = page_flipped;

    p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, ctx->vo->log);
    if (p->vt_switcher_active) {
        vt_switcher_acquire(&p->vt_switcher, acquire_vt, ctx);
        vt_switcher_release(&p->vt_switcher, release_vt, ctx);
    } else {
        MP_WARN(ctx->vo, "Failed to set up VT switcher. Terminal switching will be unavailable.\n");
    }

    MP_VERBOSE(ctx->vo, "Initializing KMS\n");
    p->kms = kms_create(ctx->vo->log);
    if (!p->kms) {
        MP_ERR(ctx->vo, "Failed to create KMS.\n");
        return -1;
    }

    // TODO: arguments should be configurable
    if (!kms_setup(p->kms, "/dev/dri/card0", -1, 0)) {
        MP_ERR(ctx->vo, "Failed to configure KMS.\n");
        return -1;
    }

    if (!init_gbm(ctx)) {
        MP_ERR(ctx->vo, "Failed to setup GBM.\n");
        return -1;
    }

    if (!init_egl(ctx, flags & VOFLAG_GLES)) {
        MP_ERR(ctx->vo, "Failed to setup EGL.\n");
        return -1;
    }

    if (!eglMakeCurrent(p->egl.display, p->egl.surface, p->egl.surface, p->egl.context)) {
        MP_ERR(ctx->vo, "Failed to make context current.\n");
        return -1;
    }

    const char *egl_exts = eglQueryString(p->egl.display, EGL_EXTENSIONS);
    void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress;
    mpgl_load_functions(ctx->gl, gpa, egl_exts, ctx->vo->log);

    // required by gbm_surface_lock_front_buffer
    eglSwapBuffers(p->egl.display, p->egl.surface);

    MP_VERBOSE(ctx->vo, "Preparing framebuffer\n");
    p->gbm.bo = gbm_surface_lock_front_buffer(p->gbm.surface);
    if (!p->gbm.bo) {
        MP_ERR(ctx->vo, "Failed to lock GBM surface.\n");
        return -1;
    }
    update_framebuffer_from_bo(ctx, p->gbm.bo);
    if (!p->fb.id) {
        MP_ERR(ctx->vo, "Failed to create framebuffer.\n");
        return -1;
    }

    if (!crtc_setup(ctx)) {
        MP_ERR(
               ctx->vo,
               "Failed to set CRTC for connector %u: %s\n",
               p->kms->connector->connector_id,
               mp_strerror(errno));
        return -1;
    }

    return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: astrofimov/LBE_DOCS
int main () {
	
	int i, j, k, m;
	int total_pitch = 320 * 2; /*2 bpp*/
	
	uint16_t *pixels = malloc (320 * 200 * sizeof(uint16_t));
	init_egl();

	gles2_init(320, 200, 16, false);

	clear_screen (320, 200,  pixels);
	
	for (m = 0; m < 2; m++) {
		for (j = 0; j < 320 - 50; j++) {
			
			clear_screen (320, 200,  pixels);
			
			for (i = 0; i < 200; i++) {
				
				for (k = 0; k < 50; k++) 
					pixels[i * 320 + j + k] = 0x0FF0;
				
			}
			
			gles2_draw(pixels);
			eglSwapBuffers(eglInfo.display, eglInfo.surface);
		}
	}
	free (pixels);
	
	return 0;
}
コード例 #3
0
ファイル: main_round.c プロジェクト: techhhuang/bookmark
int main(int argc, char **argv)
{
    get_server_references();

    surface = wl_compositor_create_surface(compositor);

    if (surface == NULL) {
        fprintf(stderr, "Can't create surface\n");
        exit(1);
    } else {
        fprintf(stderr, "Created surface\n");
    }

    shell_surface = wl_shell_get_shell_surface(shell, surface);
    wl_shell_surface_set_toplevel(shell_surface);

//    create_opaque_region();
    init_egl();
    create_window();
    init_gl();

    while (1) {
        draw();
        if (eglSwapBuffers(egl_display, egl_surface)) {
            fprintf(stderr, "Swapped buffers\n");
       } else {
        fprintf(stderr, "Swapped buffers failed\n");
    }
    }

    wl_display_disconnect(display);
    printf("disconnected from display\n");

    exit(0);
}
コード例 #4
0
ファイル: RPIGears.c プロジェクト: mew-cx/RPIGears
int main (int argc, char *argv[])
{
   bcm_host_init();

   // Clear application state
   memset( state, 0, sizeof( *state ) );

   setup_user_options(argc, argv);

   // Start OGLES
   init_egl();
   init_textures();
   build_gears();
   
   // setup the scene based on rendering mode
   if (state->useGLES2) {
	 init_scene_GLES2();
     // Setup the model projection/world
     init_model_projGLES2();
   }
   else { // using gles1
     init_scene_GLES1();
     // Setup the model projection/world
     init_model_projGLES1();
   }

   // animate the gears
   run_gears();

   exit_func();

   return 0;
}
コード例 #5
0
ファイル: egl_epoxy_api.c プロジェクト: ebassi/libepoxy
int
main(int argc, char **argv)
{
    bool pass = true;

    EGLContext egl_ctx;
    EGLDisplay *dpy = get_egl_display_or_skip();
    const char *extensions = eglQueryString(dpy, EGL_EXTENSIONS);
    char *first_space;
    char *an_extension;

    /* We don't have any extensions guaranteed by the ABI, so for the
     * touch test we just check if the first one is reported to be there.
     */
    first_space = strstr(extensions, " ");
    if (first_space) {
        an_extension = strndup(extensions, first_space - extensions);
    } else {
        an_extension = strdup(extensions);
    }

    if (!epoxy_extension_in_string(extensions, an_extension))
        errx(1, "Implementation reported absence of %s", an_extension);

    free(an_extension);

    init_egl(dpy, &egl_ctx);
    pass = make_egl_current_and_test(dpy, egl_ctx);

    return pass != true;
}
コード例 #6
0
ファイル: main.c プロジェクト: astrofimov/LBE_DOCS
int main(int argc, char *argv[])
{
	init_egl();

	init_shaders();
	
	init_gl();

	main_loop();

	return 0;
}
コード例 #7
0
ファイル: simple-egl.c プロジェクト: N8Fear/adwc
int
main(int argc, char **argv)
{
	struct sigaction sigint;
	struct display display = { 0 };
	struct window  window  = { 0 };

	window.display = &display;
	window.geometry.width  = 250;
	window.geometry.height = 250;

	display.display = wl_display_connect(NULL);
	assert(display.display);

	wl_display_add_global_listener(display.display,
				       display_handle_global, &display);

	wl_display_get_fd(display.display, event_mask_update, &display);
	wl_display_iterate(display.display, WL_DISPLAY_READABLE);

	init_egl(&display);
	create_surface(&window);
	init_gl(&window);

	sigint.sa_handler = signal_int;
	sigemptyset(&sigint.sa_mask);
	sigint.sa_flags = SA_RESETHAND;
	sigaction(SIGINT, &sigint, NULL);

	redraw(&window, NULL, 0);

	while (running)
		wl_display_iterate(display.display, display.mask);

	fprintf(stderr, "simple-egl exiting\n");

	destroy_surface(&window);
	fini_egl(&display);

	if (display.shell)
		wl_shell_destroy(display.shell);

	if (display.compositor)
		wl_compositor_destroy(display.compositor);

	wl_display_flush(display.display);
	wl_display_disconnect(display.display);

	return 0;
}
コード例 #8
0
ファイル: egl_gl.c プロジェクト: anholt/libepoxy
int
main(int argc, char **argv)
{
    bool pass = true;
    EGLDisplay *egl_dpy;
    EGLContext egl_ctx;

    /* Force epoxy to have loaded both EGL and GLX libs already -- we
     * can't assume anything about symbol resolution based on having
     * EGL or GLX loaded.
     */
    (void)glXGetCurrentContext();
    (void)eglGetCurrentContext();

    init_egl(&egl_dpy, &egl_ctx);
    pass = make_egl_current_and_test(egl_dpy, egl_ctx) && pass;

    return pass != true;
}
コード例 #9
0
ファイル: OpenGLShowImageCase.c プロジェクト: sfsy1989/OpenGL
static int
setup_graphics(struct engine *engine)
{
	if (!engine->app->window) {
		return 0;
	}

	engine->in_capacity = IN_WIDTH*IN_HEIGHT*IN_BPP;
	engine->in_buf = malloc(engine->in_capacity);
	if (!engine->in_buf) {
		return -1;
	}
	FILE *fp = fopen("/data/iptv/xxx.rgba", "rb");
	if (!fp) {
		return -1;
	}
	fread(engine->in_buf, 1, IN_WIDTH*IN_HEIGHT*4, fp);
	fclose(fp);

	if (init_egl(engine) < 0) {
		return -1;
	}

	engine->program = create_program(g_vert_src, g_frag_src);
	if (!engine->program) {
		LOGE("Could not create program\n");
		return -1;
	}
	engine->loc_pos = glGetAttribLocation(engine->program, "vPosition");
	if (engine->loc_pos < 0) {
		LOGI("vPosition get: %d\n", glGetError());
		return -1;
	}
	
	engine->loc_tex_coord = glGetAttribLocation(engine->program, 
	                                            "a_texCoord");
	if (engine->loc_tex_coord < 0) {
		LOGI("a_texCoord get: %d\n", glGetError());
		return -1;
	}

	engine->loc_tex = glGetUniformLocation(engine->program, "u_texture");
	if (engine->loc_tex < 0) {
		LOGI("u_texture get: %d\n", glGetError());
		return -1;
	}
	glViewport(0, 0, engine->width, engine->height);

	glGenTextures(1, &engine->tex);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, engine->tex);
	/**GL_NEAREST or GL_LINEAR*/
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IN_WIDTH, 
	             IN_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

	return 0;
}
コード例 #10
0
ファイル: simple-egl.c プロジェクト: rzr/weston
int
main(int argc, char **argv)
{
	struct sigaction sigint;
	struct display display = { 0 };
	struct window  window  = { 0 };
	int i, ret = 0;

	window.display = &display;
	display.window = &window;
	window.window_size.width  = 250;
	window.window_size.height = 250;
	window.buffer_size = 32;
	window.frame_sync = 1;

	for (i = 1; i < argc; i++) {
		if (strcmp("-f", argv[i]) == 0)
			window.fullscreen = 1;
		else if (strcmp("-o", argv[i]) == 0)
			window.opaque = 1;
		else if (strcmp("-s", argv[i]) == 0)
			window.buffer_size = 16;
		else if (strcmp("-b", argv[i]) == 0)
			window.frame_sync = 0;
		else if (strcmp("-h", argv[i]) == 0)
			usage(EXIT_SUCCESS);
		else
			usage(EXIT_FAILURE);
	}

	display.display = wl_display_connect(NULL);
	assert(display.display);

	display.registry = wl_display_get_registry(display.display);
	wl_registry_add_listener(display.registry,
				 &registry_listener, &display);

	wl_display_dispatch(display.display);

	init_egl(&display, &window);
	create_surface(&window);
	init_gl(&window);

	display.cursor_surface =
		wl_compositor_create_surface(display.compositor);

	sigint.sa_handler = signal_int;
	sigemptyset(&sigint.sa_mask);
	sigint.sa_flags = SA_RESETHAND;
	sigaction(SIGINT, &sigint, NULL);

	/* The mainloop here is a little subtle.  Redrawing will cause
	 * EGL to read events so we can just call
	 * wl_display_dispatch_pending() to handle any events that got
	 * queued up as a side effect. */
	while (running && ret != -1) {
		wl_display_dispatch_pending(display.display);
		redraw(&window, NULL, 0);
	}

	fprintf(stderr, "simple-egl exiting\n");

	destroy_surface(&window);
	fini_egl(&display);

	wl_surface_destroy(display.cursor_surface);
	if (display.cursor_theme)
		wl_cursor_theme_destroy(display.cursor_theme);

	if (display.shell)
		xdg_shell_destroy(display.shell);

	if (display.compositor)
		wl_compositor_destroy(display.compositor);

	wl_registry_destroy(display.registry);
	wl_display_flush(display.display);
	wl_display_disconnect(display.display);

	return 0;
}
コード例 #11
0
ファイル: context_drm_egl.c プロジェクト: qyot27/mpv
static int drm_egl_init(struct MPGLContext *ctx, int flags)
{
    if (ctx->vo->probing) {
        MP_VERBOSE(ctx->vo, "DRM EGL backend can be activated only manually.\n");
        return -1;
    }
    struct priv *p = ctx->priv;
    p->kms = NULL;
    p->old_crtc = NULL;
    p->gbm.surface = NULL;
    p->gbm.device = NULL;
    p->active = false;
    p->waiting_for_flip = false;
    p->ev.version = DRM_EVENT_CONTEXT_VERSION;
    p->ev.page_flip_handler = page_flipped;

    p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, ctx->vo->log);
    if (p->vt_switcher_active) {
        vt_switcher_acquire(&p->vt_switcher, acquire_vt, ctx);
        vt_switcher_release(&p->vt_switcher, release_vt, ctx);
    } else {
        MP_WARN(ctx->vo, "Failed to set up VT switcher. Terminal switching will be unavailable.\n");
    }

    MP_VERBOSE(ctx->vo, "Initializing KMS\n");
    p->kms = kms_create(ctx->vo->log, ctx->vo->opts->drm_connector_spec,
                        ctx->vo->opts->drm_mode_id);
    if (!p->kms) {
        MP_ERR(ctx->vo, "Failed to create KMS.\n");
        return -1;
    }

    if (!init_gbm(ctx)) {
        MP_ERR(ctx->vo, "Failed to setup GBM.\n");
        return -1;
    }

    if (!init_egl(ctx, flags)) {
        MP_ERR(ctx->vo, "Failed to setup EGL.\n");
        return -1;
    }

    if (!eglMakeCurrent(p->egl.display, p->egl.surface, p->egl.surface,
                        p->egl.context)) {
        MP_ERR(ctx->vo, "Failed to make context current.\n");
        return -1;
    }

    const char *egl_exts = eglQueryString(p->egl.display, EGL_EXTENSIONS);
    void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress;
    mpgl_load_functions(ctx->gl, gpa, egl_exts, ctx->vo->log);

    ctx->native_display_type = "drm";
    ctx->native_display = (void *)(intptr_t)p->kms->fd;

    // required by gbm_surface_lock_front_buffer
    eglSwapBuffers(p->egl.display, p->egl.surface);

    MP_VERBOSE(ctx->vo, "Preparing framebuffer\n");
    p->gbm.bo = gbm_surface_lock_front_buffer(p->gbm.surface);
    if (!p->gbm.bo) {
        MP_ERR(ctx->vo, "Failed to lock GBM surface.\n");
        return -1;
    }
    update_framebuffer_from_bo(ctx, p->gbm.bo);
    if (!p->fb.id) {
        MP_ERR(ctx->vo, "Failed to create framebuffer.\n");
        return -1;
    }

    if (!crtc_setup(ctx)) {
        MP_ERR(ctx->vo, "Failed to set CRTC for connector %u: %s\n",
               p->kms->connector->connector_id, mp_strerror(errno));
        return -1;
    }

    return 0;
}
コード例 #12
0
ファイル: glserver.c プロジェクト: afirago/gl-streaming
void * glserver_thread(void * arg)
{
  int quit = FALSE;
  server_thread_args_t * a = (server_thread_args_t *)arg;
  static graphics_context_t gc;
  memset(&glsec_global, 0, sizeof(glsec_global));
  memset(&gc, 0, sizeof(gc));
  init_egl(&gc);

  glsec_global.sta = a;
  glsec_global.gc = &gc;
  glsec_global.tmp_buf.buf = (char *)malloc(GLSE_TMP_BUFFER_SIZE);
  glsec_global.tmp_buf.size = GLSE_TMP_BUFFER_SIZE;
  glsec_global.out_buf.buf = (char *)malloc(GLSE_OUT_BUFFER_SIZE);
  glsec_global.out_buf.size = GLSE_OUT_BUFFER_SIZE;
  

  while (quit == FALSE)
  {
    void *popptr = (void *)fifo_pop_ptr_get(a->fifo);
    if (popptr == NULL)
    {
      usleep(a->sleep_usec);
    }
    else
    {
      gls_command_t *c = (gls_command_t *)popptr;
      glsec_global.cmd_data = c;
      switch (c->cmd)
      {
        case GLSC_FLIP:
          glse_cmd_flip();
          break;
        case GLSC_SEND_DATA:
          glse_cmd_recv_data();
          break;
        case GLSC_FLUSH:
          glse_cmd_flush();
          break;
        case GLSC_get_context:
          glse_cmd_get_context();
          break;
        case GLSC_glBufferData:
          glse_glBufferData();
          break;
        case GLSC_glBufferSubData:
          glse_glBufferSubData();
          break;
        case GLSC_glCreateProgram:
          glse_glCreateProgram();
          break;
        case GLSC_glCreateShader:
          glse_glCreateShader();
          break;
        case GLSC_glDeleteBuffers:
          glse_glDeleteBuffers();
          break;
        case GLSC_glFinish:
          glse_glFinish();
          break;
        case GLSC_glGenBuffers:
          glse_glGenBuffers();
          break;
        case GLSC_glGenTextures:
          glse_glGenTextures();
          break;
        case GLSC_glGetAttribLocation:
          glse_glGetAttribLocation();
          break;
        case GLSC_glGetProgramInfoLog:
          glse_glGetProgramInfoLog();
          break;
        case GLSC_glGetShaderInfoLog:
          glse_glGetShaderInfoLog();
          break;
        case GLSC_glGetUniformLocation:
          glse_glGetUniformLocation();
          break;
        case GLSC_glShaderSource:
          glse_glShaderSource();
          break;
        default:
          printf("Error: Command\n");
          break;
      }
      fifo_pop_ptr_next(a->fifo);
    }
  }

  release_egl(&gc);

  free(glsec_global.tmp_buf.buf);
  free(glsec_global.out_buf.buf);

  pthread_exit(NULL);
}
コード例 #13
0
ファイル: kmsfps.c プロジェクト: Spudd86/julia-vis
int main(int argc, char *argv[])
{
	struct opt_data opts; optproc(argc, argv, &opts);
	if(audio_init(&opts) < 0) exit(1);
	if(opts.w < 0 && opts.h < 0) opts.w = opts.h = 512;
	else if(opts.w < 0) opts.w = opts.h;
	else if(opts.h < 0) opts.h = opts.w;
	
	int ret;

	ret = init_drm(&opts, 512);
	if (ret) {
		printf("failed to initialize DRM\n");
		return ret;
	}

	ret = init_gbm();
	if (ret) {
		printf("failed to initialize GBM\n");
		return ret;
	}

	ret = init_egl();
	if (ret) {
		printf("failed to initialize EGL\n");
		return ret;
	}
	
	// call init_gl
	//init_gl(&opts, drm.mode->hdisplay, drm.mode->vdisplay);
	init_gl(&opts, opts.w, opts.h); //TODO: better dealing with our great big screen
	
	eglSwapBuffers(gl.display, gl.surface);
	struct gbm_bo *bo = gbm_surface_lock_front_buffer(gbm.surface);
	fb = drm_fb_get_from_bo(bo);

	/* set mode: */
	ret = drmModeSetCrtc(drm.fd, drm.crtc_id, fb->fb_id, 0, 0,
			&drm.connector_id, 1, drm.mode);
	if (ret) {
		printf("failed to set mode: %s\n", strerror(errno));
		return ret;
	}
	
	// turn off line buffering on input and echoing of characters
	struct termios term;
	tcgetattr(STDIN_FILENO, &save_term);
    tcgetattr(STDIN_FILENO, &term);
    term.c_lflag &= ~(ICANON|ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &term);
    
    atexit(shutdown_cleanup);
	
	drmVBlank vbl;
	/* Get current count first hopefully also sync up with blank too*/
	vbl.request.type = DRM_VBLANK_RELATIVE;
	vbl.request.sequence = 1;
	ret = drmWaitVBlank(drm.fd, &vbl);
	if (ret != 0) {
		printf("drmWaitVBlank (relative, event) failed ret: %i\n", ret);
		return -1;
	}
	printf("starting msc: %d\n", vbl.request.sequence);
	
	/* Queue an event for frame + 1 */
	vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
	vbl.request.sequence = 1;
	vbl.request.signal = NULL;
	ret = drmWaitVBlank(drm.fd, &vbl);
	if (ret != 0) {
		printf("drmWaitVBlank (relative, event) failed ret: %i\n", ret);
		return -1;
	}
	
	struct pollfd pfds[] = {
		{drm.fd, POLLIN | POLLPRI, 0 },
		{STDIN_FILENO, POLLIN, 0 },
	};

	int debug_maxsrc = 0, debug_pal = 0, show_mandel = 0, show_fps_hist = 0;
	bool done = false;
	while (!done) {

		render_frame(debug_maxsrc, debug_pal, show_mandel, show_fps_hist);

		while (waiting_for_flip) { // TODO: input handling			
			ret = poll(pfds, 2, -1);
			if (ret < 0) {
				printf("poll err: %s\n", strerror(errno));
				return ret;
			} else if (ret == 0) {
				printf("poll timeout!\n");
				done = true;
				break;
			} 
			
			if (pfds[1].revents) {
				char buf[128];
				int cnt = read(STDIN_FILENO, buf, sizeof(buf));
				if(buf[0] == 27) done = true;
				else if(buf[0] == '1') debug_maxsrc = !debug_maxsrc;
				else if(buf[0] == '2') debug_pal = !debug_pal;
				else if(buf[0] == '3') show_mandel = !show_mandel;
				else if(buf[0] == '4') show_fps_hist = !show_fps_hist;
				//continue;
			}
			
			if(pfds[0].revents)
				drmHandleEvent(drm.fd, &evctx);
		}

		/* release last buffer to render on again: */
		gbm_surface_release_buffer(gbm.surface, bo);
		bo = next_bo;
	}
	
	audio_shutdown();

	return ret;
}
コード例 #14
0
int egl_lock_surface(void)
{
	fprintf(stderr, "TEST_EXTENSIONS : EGL_KHR_lock_surface & EGL_KHR_lock_surface2 \n");
	int ret = 1;
	int i = 0;

	EGLImageKHR image;
	GLuint image_texture;
	int move_x = 0;
	int move_y = 0;
	int direction_x = 1;
	int direction_y = 1;
	

	/* CREATE CONTEXT STRUCTURE */
	X11Context* x11_ctx = (X11Context*)malloc(sizeof(X11Context));
	EglContext* egl_ctx = (EglContext*)malloc(sizeof(EglContext));
	RenderingContext* gles_ctx = (RenderingContext*)malloc(sizeof(RenderingContext));
	PFNEGLCREATEIMAGEKHRPROC p_eglCreateImageKHR;
	PFNEGLDESTROYIMAGEKHRPROC p_eglDestroyImageKHR;
	PFNGLEGLIMAGETARGETTEXTURE2DOESPROC p_glEGLImageTargetTexture2DOES;
	
	/* Initialize native x11 */
	if(!init_x11_native(x11_ctx))
		goto finish;

	/* Initialize egl */
	if(!init_egl(x11_ctx, egl_ctx))
		goto finish;
		
	if(!is_supported(egl_ctx->egl_display,"EGL_KHR_lock_surface"))
	{	
		/* EGL_KHR_lock_surface is not supporect */
		fprintf(stderr, "EGL_KHR_lock_surface is not supported\n");
		goto finish;
	}

	/* Create native pixmap */
	int xDefaultScreen = DefaultScreen(x11_ctx->native_display);
	int xDefaultDepth = XDefaultDepth( x11_ctx->native_display, xDefaultScreen );
	Pixmap pixmap = XCreatePixmap(x11_ctx->native_display,x11_ctx->native_window, TEX_W, TEX_H, xDefaultDepth);
	if(pixmap == None)
	{
		fprintf(stderr, "FAIL to XCreatePixmap \n");
		goto finish;
	}
	
	PFNEGLLOCKSURFACEKHRPROC p_eglLockSurfaceKHR = (PFNEGLLOCKSURFACEKHRPROC)eglGetProcAddress( "eglLockSurfaceKHR" );
	PFNEGLUNLOCKSURFACEKHRPROC p_eglUnlockSurfaceKHR = (PFNEGLUNLOCKSURFACEKHRPROC)eglGetProcAddress( "eglUnlockSurfaceKHR" );
	if(!p_eglLockSurfaceKHR || !p_eglUnlockSurfaceKHR)
	{
		fprintf(stderr, "EGL_KHR_lock_surface is not supported \n");
		goto finish;
	}

	/* Create eglPixmapSurface */
	if(!create_lockable_pixmap_surface(egl_ctx, pixmap))
	{
		fprintf(stderr, "FAIL to Create PixmapSurface \n");
		goto finish;
	}

	/* Create eglImage and texture */
	if(!create_egl_image_texture(pixmap, &image_texture, egl_ctx))
	{
		fprintf(stderr, "FAIL to Create eglImage \n");
		goto finish;
	}

	/* vertices, color, texture coordinate info */
	static GLfloat vertices[] = {  -1.0,  1.0, 0.0,
									1.0,  1.0, 0.0,
								   -1.0, -1.0, 0.0, 
									1.0, -1.0, 0.0};

	static GLfloat colors[] = { 1.0f, 1.0f, 1.0f, 1.0f, 			
								1.0f, 1.0f, 1.0f, 1.0f,
								1.0f, 1.0f, 1.0f, 1.0f, 			
								1.0f, 1.0f, 1.0f, 1.0f};

	static GLfloat texcoord[] = {0.0, 1.0,
								 1.0, 1.0,
								 0.0, 0.0,
								 1.0, 0.0};
								 
	EGLint lock_surface_attrib [] = {EGL_MAP_PRESERVE_PIXELS_KHR, EGL_FALSE, 
									EGL_LOCK_USAGE_HINT_KHR, EGL_READ_SURFACE_BIT_KHR | EGL_WRITE_SURFACE_BIT_KHR,
									EGL_NONE};	
	unsigned char* p_eglimg_data = NULL;

	if(!init_gles(vertices, colors, texcoord, gles_ctx))
	{
		fprintf(stderr, "FAIL TO INIT GLES\n");
		goto finish;
	}

	/* Query Lockable Surface infomation */
	if(!eglMakeCurrent(egl_ctx->egl_display, egl_ctx->pixmap_sur, egl_ctx->pixmap_sur, egl_ctx->pixmap_ctx))
		goto finish;
		
	if(!p_eglLockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur, lock_surface_attrib ))
	{
		p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur );
		if(!eglMakeCurrent(egl_ctx->egl_display, egl_ctx->wnd_sur, egl_ctx->wnd_sur, egl_ctx->wnd_ctx))
			goto finish;

		if(!p_eglLockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur, lock_surface_attrib ))
		{
			fprintf(stderr, "FAIL to p_eglLockSurfaceKHR %x \n", eglGetError());	
			p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur );
		}
	}
	EGLint data[7];
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PITCH_KHR, &data[0]);
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_ORIGIN_KHR, &data[1]);
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PIXEL_RED_OFFSET_KHR, &data[2]);
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR , &data[3]);
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR, &data[4]);
	eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR , &data[5]);
	fprintf(stderr, "eglSurface Infomation \n");
	fprintf(stderr, " EGL_BITMAP_PITCH_KHR %d\n EGL_BITMAP_ORIGIN_KHR 0x%x\n EGL_BITMAP_PIXEL_RED_OFFSET_KHR %d\n EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR %d\n ", data[0], data[1], data[2], data[3]);
	fprintf(stderr, "EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR %d\n EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR %d\n", data[4], data[5]);
	
	if(is_supported(egl_ctx->egl_display, "EGL_KHR_lock_surface2"))
	{
		eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur,  EGL_BITMAP_PIXEL_SIZE_KHR , &data[6]);
		fprintf(stderr, " EGL_BITMAP_PIXEL_SIZE_KHR %d\n", data[6]);
	}
	
	if(!p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur ))
	{
		fprintf(stderr, "FAIL to eglUnlockSurfaceKHR %x \n", eglGetError());
		goto finish;
	}

	for(i=0; i<FRAME; i++)
	{
		/* MakeCurrent eglPixmapSurface */
		if(!eglMakeCurrent(egl_ctx->egl_display, egl_ctx->pixmap_sur, egl_ctx->pixmap_sur, egl_ctx->pixmap_ctx))
			goto finish;
			
		if(!p_eglLockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur, lock_surface_attrib ))
		{
			p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur );
			/* MakeCurrent eglWindowSurface */
			if(!eglMakeCurrent(egl_ctx->egl_display, egl_ctx->wnd_sur, egl_ctx->wnd_sur, egl_ctx->wnd_ctx))
				goto finish;

			if(!p_eglLockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur, lock_surface_attrib ))
			{
				fprintf(stderr, "FAIL to p_eglLockSurfaceKHR %x \n", eglGetError());	
				p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur );
			}
		}
		if(!eglQuerySurface(egl_ctx->egl_display, egl_ctx->pixmap_sur, EGL_BITMAP_POINTER_KHR, (EGLint *) &p_eglimg_data))
		{
				fprintf(stderr, "FAIL to query surface %x \n", eglGetError());
				p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur );
				goto finish;
		}

		if(p_eglimg_data == NULL)
		{
			fprintf(stderr, "eglQuerySurface return NULL for locksurface \n");
			goto finish;
		}

		if(i%30 < 10)
			update_eglimg( p_eglimg_data, 'R', TEX_W, TEX_H, 4 );
		else if(i%30 >= 10 && i%30 <20)
			update_eglimg( p_eglimg_data, 'G', TEX_W, TEX_H, 4 );
		else
			update_eglimg( p_eglimg_data, 'B', TEX_W, TEX_H, 4 );
			
		if(!p_eglUnlockSurfaceKHR( egl_ctx->egl_display, egl_ctx->pixmap_sur ))
		{
			fprintf(stderr, "FAIL to eglUnlockSurfaceKHR %x \n", eglGetError());
			goto finish;
		}
		
		/* MakeCurrent eglWindowSurface */
		if(!eglMakeCurrent(egl_ctx->egl_display, egl_ctx->wnd_sur, egl_ctx->wnd_sur, egl_ctx->wnd_ctx))
			goto finish;
		
		/* Draw on to eglWindowSurface */
		glClearColor(1.0, 1.0, 1.0, 1.0);
		glClear(GL_COLOR_BUFFER_BIT);
		glViewport(move_x,move_y, RECT_W, RECT_H );
		glBindTexture(GL_TEXTURE_2D, image_texture);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		eglSwapBuffers(egl_ctx->egl_display, egl_ctx->wnd_sur);

		if(direction_x == 1)
			move_x += SPEED;
		else 
			move_x -= SPEED;
			
		if(direction_y == 1)
			move_y += SPEED;
		else
			move_y -= SPEED;

		if(move_x+RECT_W > x11_ctx->width || move_x < 0)
			direction_x = - direction_x;
		if(move_y+RECT_H > x11_ctx->height || move_y < 0)
			direction_y = - direction_y;
		if(!eglSwapBuffers(egl_ctx->egl_display, egl_ctx->wnd_sur))
			goto finish;
	}
	destroy_egl_image_texture(&image_texture, egl_ctx);			
finish:
	/* Deinit gl */
	deinit_gles(gles_ctx);
	
	/* Deinit egl */
	deinit_egl(egl_ctx);
	
	/* Deinit native x11 */
	deinit_x11_native(x11_ctx);

	if(x11_ctx)
		free(x11_ctx);
	if(egl_ctx)
		free(egl_ctx);
	if(gles_ctx)
		free(gles_ctx);

	return ret;
}
コード例 #15
0
ファイル: simple-egl.c プロジェクト: anarsoul/weston
int
main(int argc, char **argv)
{
	struct sigaction sigint;
	struct display display = { 0 };
	struct window  window  = { 0 };
	int i, ret = 0;

	window.display = &display;
	display.window = &window;
	window.window_size.width  = 250;
	window.window_size.height = 250;

	for (i = 1; i < argc; i++) {
		if (strcmp("-f", argv[i]) == 0)
			window.fullscreen = 1;
		else if (strcmp("-o", argv[i]) == 0)
			window.opaque = 1;
		else if (strcmp("-h", argv[i]) == 0)
			usage(EXIT_SUCCESS);
		else
			usage(EXIT_FAILURE);
	}

	display.display = wl_display_connect(NULL);
	assert(display.display);

	display.registry = wl_display_get_registry(display.display);
	wl_registry_add_listener(display.registry,
				 &registry_listener, &display);

	wl_display_dispatch(display.display);

	init_egl(&display, window.opaque);
	create_surface(&window);
	init_gl(&window);

	display.cursor_surface =
		wl_compositor_create_surface(display.compositor);

	sigint.sa_handler = signal_int;
	sigemptyset(&sigint.sa_mask);
	sigint.sa_flags = SA_RESETHAND;
	sigaction(SIGINT, &sigint, NULL);

	while (running && ret != -1)
		ret = wl_display_dispatch(display.display);

	fprintf(stderr, "simple-egl exiting\n");

	destroy_surface(&window);
	fini_egl(&display);

	wl_surface_destroy(display.cursor_surface);
	if (display.cursor_theme)
		wl_cursor_theme_destroy(display.cursor_theme);

	if (display.shell)
		wl_shell_destroy(display.shell);

	if (display.compositor)
		wl_compositor_destroy(display.compositor);

	wl_registry_destroy(display.registry);
	wl_display_flush(display.display);
	wl_display_disconnect(display.display);

	return 0;
}