void ScreenWindow::quit() { screen_stop_events(m_context); if (m_window) screen_destroy_window(m_window); if (m_appWindow) screen_destroy_window(m_appWindow); if (m_context) screen_destroy_context(m_context); }
void OpenGLView::cleanup() { if (m_egl_disp != EGL_NO_DISPLAY) { releaseGLContext(); if (m_egl_ctx != EGL_NO_CONTEXT) { eglDestroyContext(m_egl_disp, m_egl_ctx); m_egl_ctx = EGL_NO_CONTEXT; } if (m_egl_surf != EGL_NO_SURFACE) { eglDestroySurface(m_egl_disp, m_egl_surf); m_egl_surf = EGL_NO_SURFACE; } } if (m_screen_win != NULL) { screen_destroy_window(m_screen_win); m_screen_win = NULL; } if (m_screen_dpy != NULL) { free(m_screen_dpy); } if (m_screen_win != NULL) { free(m_screen_modes); } }
NativeWindow::~NativeWindow() { if (_screenWindow) { qDebug() << "NativeWindow::~NativeWindow: _screenWindow: " << ":" << _screenWindow; screen_destroy_window(_screenWindow); _screenWindow = NULL; } }
int main(int argc, char **argv) { const int usage = SCREEN_USAGE_NATIVE; screen_window_t screen_win; screen_buffer_t screen_buf = NULL; int rect[4] = { 0, 0, 0, 0 }; // create an application window which will just act as a background screen_create_context(&screen_ctx, 0); screen_create_window(&screen_win, screen_ctx); screen_create_window_group(screen_win, vf_group); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); // fill the window with black int attribs[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END }; screen_fill(screen_ctx, screen_buf, attribs); screen_post_window(screen_win, screen_buf, 1, rect, 0); // position the window at an arbitrary z-order int i = APP_ZORDER; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &i); // Signal bps library that navigator and screen events will be requested bps_initialize(); screen_request_events(screen_ctx); navigator_request_events(0); // open camera and configure viewfinder if (init_camera() == EOK) { // our main loop just runs a state machine and handles input while (!shutdown) { run_state_machine(); // Handle user input handle_event(); } if (state == STATE_VIEWFINDER) { // clean up camera camera_stop_photo_viewfinder(handle); camera_close(handle); } } // Clean up screen_stop_events(screen_ctx); bps_shutdown(); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return 0; }
gceSTATUS gcoOS_DestroyWindow( IN HALNativeDisplayType Display, IN HALNativeWindowType Window ) { if (Window != gcvNULL) { screen_destroy_window(Window); } return gcvSTATUS_OK; }
void CCEGLView::release() { screen_stop_events(m_screenContext); bps_shutdown(); if (m_eglDisplay != EGL_NO_DISPLAY) { eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } if (m_eglSurface != EGL_NO_SURFACE) { eglDestroySurface(m_eglDisplay, m_eglSurface); m_eglSurface = EGL_NO_SURFACE; } if (m_eglContext != EGL_NO_CONTEXT) { eglDestroyContext(m_eglDisplay, m_eglContext); m_eglContext = EGL_NO_CONTEXT; } if (m_eglDisplay != EGL_NO_DISPLAY) { eglTerminate(m_eglDisplay); m_eglDisplay = EGL_NO_DISPLAY; } if (m_screenWindow) { screen_destroy_window(m_screenWindow); m_screenWindow = NULL; } if (m_screenEvent) { screen_destroy_event(m_screenEvent); m_screenEvent = NULL; } if (m_screenContext) { screen_destroy_context(m_screenContext); m_screenContext = NULL; } eglReleaseThread(); m_isGLInitialized = false; exit(0); }
static void bb10display_destroyWindow(BB10Display *d) { if (!d->window_created) { ms_warning("[bb10_display] screen wasn't created yet, skipping..."); return; } screen_destroy_window_buffers(d->window); screen_destroy_window(d->window); d->window = NULL; d->window_created = FALSE; ms_debug("[bb10_display] bb10display_destroyWindow window destroyed"); }
bool_e qnxscreen_free(struct qnxscreen_api *q) { uint32_t i; if (!q) return false_e; mutex_lock(&q->m_lock); screen_destroy_window(q->win); q->count = 0; bitfield_deinit(&q->used); mutex_unlock(&q->m_lock); return true_e; }
static void gfx_ctx_destroy(void) { RARCH_LOG("gfx_ctx_destroy().\n"); eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(g_egl_dpy, g_egl_ctx); eglDestroySurface(g_egl_dpy, g_egl_surf); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); eglTerminate(g_egl_dpy); eglReleaseThread(); g_egl_dpy = EGL_NO_DISPLAY; g_egl_surf = EGL_NO_SURFACE; g_egl_ctx = EGL_NO_CONTEXT; egl_config = 0; g_resize = false; }
QQnxWindow::~QQnxWindow() { qWindowDebug() << Q_FUNC_INFO << "window =" << window(); // Qt should have already deleted the children before deleting the parent. Q_ASSERT(m_childWindows.size() == 0); // Remove from plugin's window mapper QQnxIntegration::removeWindow(m_window); // Remove from parent's Hierarchy. removeFromParent(); if (m_screen) m_screen->updateHierarchy(); // Cleanup QNX window and its buffers screen_destroy_window(m_window); }
Platform::~Platform() { if (__eglDisplay != EGL_NO_DISPLAY) { eglMakeCurrent(__eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } if (__eglSurface != EGL_NO_SURFACE) { eglDestroySurface(__eglDisplay, __eglSurface); __eglSurface = EGL_NO_SURFACE; } if (__eglContext != EGL_NO_CONTEXT) { eglDestroyContext(__eglDisplay, __eglContext); __eglContext = EGL_NO_CONTEXT; } if (__eglDisplay != EGL_NO_DISPLAY) { eglTerminate(__eglDisplay); __eglDisplay = EGL_NO_DISPLAY; } if (__screenWindow) { screen_destroy_window(__screenWindow); __screenWindow = NULL; } if (__screenEvent) { screen_destroy_event(__screenEvent); __screenEvent = NULL; } if (__screenContext) { screen_destroy_context(__screenContext); __screenContext = NULL; } }
void BlackberryMain::killDisplay(int idx, bool killContext) { if (egl_disp[idx] != EGL_NO_DISPLAY) { if (killContext) eglMakeCurrent(egl_disp[idx], EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl_surf[idx] != EGL_NO_SURFACE) { eglDestroySurface(egl_disp[idx], egl_surf[idx]); egl_surf[idx] = EGL_NO_SURFACE; } if (killContext) { eglTerminate(egl_disp[idx]); egl_disp[idx] = EGL_NO_DISPLAY; } } if (killContext && screen_win[idx] != NULL) { screen_destroy_window(screen_win[idx]); screen_win[idx] = NULL; } screen_destroy_window_buffers(screen_win[idx]); }
void kill_GLES2() { if (egl_disp != EGL_NO_DISPLAY) { eglMakeCurrent(egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl_surf != EGL_NO_SURFACE) { eglDestroySurface(egl_disp, egl_surf); egl_surf = EGL_NO_SURFACE; } if (egl_ctx != EGL_NO_CONTEXT) { eglDestroyContext(egl_disp, egl_ctx); egl_ctx = EGL_NO_CONTEXT; } if (screen_win != NULL) { screen_destroy_window(screen_win); screen_win = NULL; } eglTerminate(egl_disp); egl_disp = EGL_NO_DISPLAY; } eglReleaseThread(); }
void gl_terminate(screen_window_t *screen_win) { // Borrowed from bbutil.c // EGL cleanup if (egl_disp != EGL_NO_DISPLAY) { eglMakeCurrent(egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl_surf != EGL_NO_SURFACE) { eglDestroySurface(egl_disp, egl_surf); egl_surf = EGL_NO_SURFACE; } if (egl_ctx != EGL_NO_CONTEXT) { eglDestroyContext(egl_disp, egl_ctx); egl_ctx = EGL_NO_CONTEXT; } if (screen_win != NULL) { screen_destroy_window(*screen_win); screen_win = NULL; } eglTerminate(egl_disp); egl_disp = EGL_NO_DISPLAY; } eglReleaseThread(); }
/** * Set up a basic screen, so that the navigator will * send window state events when the window state changes. * * @return @c EXIT_SUCCESS or @c EXIT_FAILURE */ int setup_screen() { if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_win, screen_ctx) != 0) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail; if (screen_create_window_buffers(screen_win, 1) != 0) goto fail; if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail; screen_buffer_t buff; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail; int buffer_size[2]; if (screen_get_buffer_property_iv(buff, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail; int attribs[1] = {SCREEN_BLIT_END}; if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail; int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]}; if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail; return EXIT_SUCCESS; fail: screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return EXIT_FAILURE; }
void terminate_egl_window() { // Typical EGL cleanup if (g_egl_disp != EGL_NO_DISPLAY) { eglMakeCurrent(g_egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (g_egl_surf != EGL_NO_SURFACE) { eglDestroySurface(g_egl_disp, g_egl_surf); g_egl_surf = EGL_NO_SURFACE; } if (g_egl_ctx != EGL_NO_CONTEXT) { eglDestroyContext(g_egl_disp, g_egl_ctx); g_egl_ctx = EGL_NO_CONTEXT; } if (g_screen_win != NULL) { screen_destroy_window(g_screen_win); g_screen_win = NULL; } eglTerminate(g_egl_disp); g_egl_disp = EGL_NO_DISPLAY; } eglReleaseThread(); }
void GLimp_Shutdown( void ) { if (!eglContext || !eglDisplay) return; IN_DeactivateMouse(); // bk001206 - replaced with H2/Fakk2 solution // XAutoRepeatOn(dpy); // autorepeaton = qfalse; // bk001130 - from cvs1.17 (mkv) screen_destroy_event(screen_ev); eglMakeCurrent(eglDisplay, NULL, NULL, NULL); eglDestroySurface(eglDisplay, eglSurface); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); eglDestroyContext(eglDisplay, eglContext); eglTerminate(eglDisplay); eglReleaseThread(); eglDisplay = NULL; eglContext = NULL; eglSurface = NULL; memset( &glConfig, 0, sizeof( glConfig ) ); memset( &glState, 0, sizeof( glState ) ); }
void bbutil_terminate() { //Typical EGL cleanup if (egl_disp != EGL_NO_DISPLAY) { eglMakeCurrent(egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl_surf != EGL_NO_SURFACE) { eglDestroySurface(egl_disp, egl_surf); egl_surf = EGL_NO_SURFACE; } if (egl_ctx != EGL_NO_CONTEXT) { eglDestroyContext(egl_disp, egl_ctx); egl_ctx = EGL_NO_CONTEXT; } if (screen_win != NULL) { screen_destroy_window(screen_win); screen_win = NULL; } eglTerminate(egl_disp); egl_disp = EGL_NO_DISPLAY; } eglReleaseThread(); initialized = 0; }
QQnxRootWindow::~QQnxRootWindow() { // Cleanup top-level QNX window screen_destroy_window(m_window); }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; bps_initialize(); // Create and set up the app window. if (EXIT_FAILURE == setup_screen()) return EXIT_FAILURE; bbads_set_log_verbosity(2); // Display Banner on screen load_ad(screen_window, WINDOW_GROUP_NAME); screen_request_events(screen_context); navigator_request_events(0); /** * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = 0; if (BPS_SUCCESS != bps_get_event(&event, -1)) { fprintf(stderr, "ERROR: Could not get BPS event!\n"); return EXIT_FAILURE; } if (event) { if (navigator_get_domain() == bps_event_get_domain(event)) { int code = bps_event_get_code(event); if (NAVIGATOR_EXIT == code) { if (BBADS_EOK != bbads_banner_destroy(ad_banner)) { fprintf(stderr, "cannot destroy banner"); } else { fprintf(stderr, "banner destroy"); } exit_application = 1; } } else if (bbads_get_domain() == bps_event_get_domain(event)) { bbads_banner_t* event_banner; bbads_event_get_banner(event, &event_banner); bbads_banner_event_type_t event_type = (bbads_banner_event_type_t)bps_event_get_code(event); banner_event_handler(event_banner, event_type); } else if (screen_get_domain() == bps_event_get_domain(event)) { int screen_val; char buf[1024]; int pos[2]; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); screen_get_event_property_cv(screen_event, SCREEN_PROPERTY_ID_STRING, sizeof(buf), buf); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos); switch (screen_val) { case SCREEN_EVENT_CREATE: fprintf(stderr, "create\n"); if (BBADS_EOK != bbads_banner_is_visible(ad_banner, &ad_is_visible)) { fprintf(stderr, "cannot get banner visibility"); } if (!ad_is_visible) { if (BBADS_EOK != bbads_banner_set_window_visible(ad_banner)) fprintf(stderr, "bbads_banner_set_window_visible has errors\n"); if (BBADS_EOK != bbads_banner_display(ad_banner, screen_context, event)) fprintf(stderr, "create cannot display banner\n"); } break; } if (exit_application) break; } } } screen_stop_events(screen_context); bps_shutdown(); if (screen_destroy_window(screen_window) != 0) return EXIT_FAILURE; if (screen_destroy_context(screen_context) != 0) return EXIT_FAILURE; screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { char windowGroupId[64] = {0}; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); // Get the application's window group id so that it can be passed the identity library in cases // where a user may need to be interacted with on the application's behalf. screen_create_window(&screen_wnd, screen_cxt); screen_create_window_group( screen_wnd, NULL ); screen_get_window_property_cv( screen_wnd, SCREEN_PROPERTY_GROUP, sizeof( windowGroupId ), windowGroupId ); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if( EXIT_SUCCESS != identity_initialize( windowGroupId ) ) { fprintf(stderr, "Initialization of IDS Library failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } identity_trigger_get_username(); // ENTER APPLICATION EVENT LOOP while (!shutdown) { // Handle bps events, includes input and fd changes handle_events(); } identity_shutdown(); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Use utility code to terminate EGL setup bbutil_terminate(); //Shut down BPS library for this process bps_shutdown(); screen_destroy_window(screen_wnd); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
bool_e qnxscreen_allocate(struct qnxscreen_api *q, uint32_t width, uint32_t height, uint32_t count, fourcc_t color) { bool_e ret = false_e; int size[2] = {(int)width, (int)height}; int bsize[2] = {(int)width, (int)height}; int i; int pformat = 0; int err; int zOrder = 50; int dispCount = 0; int formatCount = 0; int sensitivity = SCREEN_SENSITIVITY_NEVER; int tranparency = SCREEN_TRANSPARENCY_NONE; int idleMode = SCREEN_IDLE_MODE_KEEP_AWAKE; screen_display_t *displays; screen_display_t display; int formats[SCREEN_FORMAT_NFORMATS]; bool_e configured = false_e; const int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_NATIVE | SCREEN_USAGE_CAPTURE; mutex_lock(&q->m_lock); err = screen_create_window_type(&q->win, q->ctx, SCREEN_APPLICATION_WINDOW); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) Failure on screen_create_window_type: (%d)\n", __func__, errno); goto leave; } err = screen_get_context_property_iv(q->ctx, SCREEN_PROPERTY_DISPLAY_COUNT, (void *)&dispCount); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "Failed to query the number of displays! err=%d\n",err); goto leave2; } DVP_PRINT(DVP_ZONE_VIDEO, "There are %u displays\n", dispCount); err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_ZORDER, &zOrder); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) Failure on screen_create_window_type: (%d)\n", __func__, errno); goto leave2; } // this tells the window to not receive input events err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_SENSITIVITY, &sensitivity); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "Failed to set window sensitivity to zero (%d)\n", err); goto leave2; } // this is not the same as global alpha. err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_TRANSPARENCY, &tranparency); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "Failed to set window transparency to none (%d)\n", err); goto leave2; } err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_USAGE, &usage); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) Failure setting USAGE window property: (%d)\n", __func__, errno); goto leave2; } err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_IDLE_MODE, &idleMode); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "Failed to set window idle mode to keep awake (%d)\n", err); goto leave2; } err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_SIZE, size); if (err) goto leave2; err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_SOURCE_SIZE, bsize); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) Failure setting SOURCE_SIZE window property: (%d)\n", __func__, errno); goto leave2; } if (width % OMX_CAMERA_ALIGNMENT) bsize[0] = ( (width / OMX_CAMERA_ALIGNMENT) + 1) * OMX_CAMERA_ALIGNMENT; err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_BUFFER_SIZE, bsize); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) Failure setting BUFFER_SIZE window property: (%d)\n", __func__, errno); goto leave2; } for (i = 0; i < numCodes; i++) { if (color == codes[i].fourcc) pformat = codes[i].qnxscreen_fmt; } if (pformat == 0) { DVP_PRINT(DVP_ZONE_ERROR, "Unknown FOURCC 0x%x\n", color); goto leave2; } else { DVP_PRINT(DVP_ZONE_VIDEO, "Configuring display for fmt:%d\n", pformat); } screen_get_window_property_pv(q->win, SCREEN_PROPERTY_DISPLAY, (void *)&display); screen_get_display_property_iv(display, SCREEN_PROPERTY_FORMAT_COUNT, (void *)&formatCount); screen_get_display_property_iv(display, SCREEN_PROPERTY_FORMATS, (void *)formats); for (i = 0; i < formatCount; i++) { DVP_PRINT(DVP_ZONE_VIDEO, "Display %p supports format %d\n", display, formats[i]); } configured = false_e; for (i = 0; i < formatCount; i++) { if (formats[i] == pformat) { err = screen_set_window_property_iv(q->win, SCREEN_PROPERTY_FORMAT, &pformat); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "screen_set_window_property_iv() returned %d when setting format %d\n", err, pformat); goto leave2; } else configured = true_e; } } if (configured == false_e) { DVP_PRINT(DVP_ZONE_ERROR, "Display %p does not support format %d\n", display, pformat); goto leave2; } err = screen_create_window_buffers(q->win, (int)count); if (err) { DVP_PRINT(DVP_ZONE_ERROR, "screen_create_window_buffers() returned %d when requesting %u buffers\n", err, count); goto leave2; } err = screen_get_window_property_pv(q->win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)q->buf); if (err) { perror("screen_get_window_property(SCREEN_PROPERTY_RENDER_BUFFERS)"); goto leave2; } q->count = count; q->pfmt = pformat; q->metrics.left = 0; q->metrics.top = 0; q->metrics.width = size[0]; q->metrics.height = size[1]; bitfield_init(&q->used, q->count); DVP_PRINT(DVP_ZONE_VIDEO, "QNX Screen Configuring %u images for %ux%u fmt:%d\n", count, size[0], size[1], pformat); for (i = 0; i < q->count; i++) { void *ptr = NULL; screen_get_buffer_property_pv(q->buf[i], SCREEN_PROPERTY_POINTER, &ptr); DVP_PRINT(DVP_ZONE_VIDEO, "\t[%u] ptr=%p\n", i, ptr); } ret = true_e; leave: mutex_unlock(&q->m_lock); return ret; leave2: screen_destroy_window(q->win); mutex_unlock(&q->m_lock); return ret; }
int main(int argc, char **argv) { int pos[2] = {0, 0}; int size[2]; int vis = 1; int type; screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT); int count = 0; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count); screen_display_t *screen_disps = calloc(count, sizeof(screen_display_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_disps); screen_display_t screen_disp = screen_disps[0]; free(screen_disps); int dims[2] = { 0, 0 }; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, dims); char str[16]; snprintf(str, sizeof(str), "%d", getpid()); screen_bg_win = create_bg_window(str, dims); screen_bar_win = create_bar_window(str, bar_id_string, dims); screen_hg_win = create_hg_window(str, hg_id_string, dims); if ( create_gles_window(str, gles_id_string, dims) != EXIT_SUCCESS){ fprintf(stderr, "Could not initialize OpenGL window. Exiting...\n"); screen_destroy_context(screen_ctx); return EXIT_FAILURE; } screen_event_t screen_ev; screen_create_event(&screen_ev); // Now draw our OpenGL stuff, it does not change so we need to do it only once GLfloat vVertices[] = {0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, 3); int rc = eglSwapBuffers(egl_disp, egl_surf); if (rc != EGL_TRUE) { egl_perror("eglSwapBuffers"); } while (1) { do { screen_get_event(screen_ctx, screen_ev, vis ? 0 : ~0); screen_get_event_property_iv(screen_ev, SCREEN_PROPERTY_TYPE, &type); if (type == SCREEN_EVENT_CLOSE) { screen_window_t screen_win; screen_get_event_property_pv(screen_ev, SCREEN_PROPERTY_WINDOW, (void **)&screen_win); if (screen_win == screen_bar_win) { screen_bar_win = NULL; } else if (screen_win == screen_hg_win) { screen_hg_win = NULL; } else if (screen_win == screen_gles_win) { screen_gles_win = NULL; } screen_destroy_window(screen_win); if (!screen_bar_win || !screen_hg_win || !screen_gles_win) { vis = 0; } } if (vis) { if (++pos[0] > dims[0] - barwidth) { pos[0] = 0; } screen_set_window_property_iv(screen_bar_win, SCREEN_PROPERTY_POSITION, pos); screen_flush_context(screen_ctx, SCREEN_WAIT_IDLE); } } while (type != SCREEN_EVENT_NONE); } screen_destroy_event(screen_ev); screen_destroy_context(screen_ctx); return EXIT_SUCCESS; }
void ScreenWindow::setVideoMode(int width, int height) { if (m_window) { screen_destroy_window(m_window); m_window = 0; } if (!m_window) { screen_create_window_type(&m_window, m_context, SCREEN_CHILD_WINDOW); char groupName[256]; snprintf(groupName, 256, "screen-%d", getpid()); screen_join_window_group(m_window, groupName); } else { screen_destroy_window_buffers(m_window); } m_width = width; m_height = height; //#define NOSTRETCH #define STRETCH_PRESERVE_ASPECT #ifdef NOSTRETCH int position[2] = {ceil((1024-width)/2), ceil((600-height)/2)}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, position); int sizeOfWindow[2] = {width, height}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, sizeOfWindow); int sizeOfBuffer[2] = {width, height}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer); #elif defined(STRETCH_PRESERVE_ASPECT) width = ceil(width * 600 / height); height = 600; int position[2] = {ceil((1024-width)/2), ceil((600-height)/2)}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, position); int sizeOfWindow[2] = {width, height}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, sizeOfWindow); int sizeOfBuffer[2] = {m_width, m_height}; // OLD DIMS screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer); #else int sizeOfWindow[2] = {1024, 600}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, sizeOfWindow); int sizeOfBuffer[2] = {width, height}; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer); #endif int zOrder = 1; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, &zOrder); int format = SCREEN_FORMAT_RGBX8888; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, &format); int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, &usage); int angle = 0; char *orientation = getenv("ORIENTATION"); if (orientation) { angle = atoi(orientation); } screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ROTATION, &angle); int visible = 1; screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &visible); screen_create_window_buffers(m_window, 1); }
/** * A sample application demonstrates the BlackBerry Native APIs for accelerometer. * The sample initializes and reads the accelerometer periodically until a * NAVIGATOR_EXIT event is received. * The application also listens for window state changes from the navigator so that * it can stop reading the accelerometer when the application is no longer visible. */ int main(int argc, char *argv[]) { if (setup_screen() != EXIT_SUCCESS) { printf("Unable to set up the screen. Exiting."); return 0; } /* * The accelerometer forces */ double force_x, force_y, force_z; /* * Before we can listen for events from the BlackBerry Tablet OS platform * services, we need to initialize the BPS infrastructure */ bps_initialize(); /* * Once the BPS infrastructure has been initialized we can register for * events from the various BlackBerry Tablet OS platform services. The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so we can track when * the system is terminating the application (NAVIGATOR_EXIT event). This allows * us to clean up application resources. */ navigator_request_events(0); /* * Before initializing the accelerometer service we must ensure the device * supports it */ if (!accelerometer_is_supported()) { /* * If the device does not support accelerometer then notify the user, * clean up and exit */ printf("Accelerometer not supported by device!"); bps_shutdown(); return EXIT_FAILURE; } /* * Initialize the accelerometer by setting the rates at which the * accelerometer values will be updated from hardware */ accelerometer_set_update_frequency(FREQ_40_HZ); /* * Process Navigator events and take accelerometer readings periodically * until we receive a NAVIGATOR_EXIT event. */ int exit_application = 0; int paused = 0; while (!exit_application) { /* * By setting the bps_get_event timeout to ACCELEROMETER_MAX_POLL_INTERVAL, * we assign the maximum time (in millis) that we will wait before * unblocking so we can take an accelerometer reading. */ bps_event_t *event = NULL; bps_get_event(&event, ACCELEROMETER_MAX_POLL_INTERVAL); if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { /* * If it is a NAVIGATOR_EXIT event then set the * exit_application flag so the application will stop * processing events, clean up and exit. * * If it is a NAVIGATOR_WINDOW_STATE event, and the window * state is NAVIGATOR_WINDOW_INVISIBLE, set paused to true so * that we stop collecting accelerometer data. Otherwise, if * we're currently paused, then set paused back to false to * resume collecting accelerometer data. */ unsigned int event_code = bps_event_get_code(event); if (NAVIGATOR_EXIT == event_code) { exit_application = 1; } else if (NAVIGATOR_WINDOW_STATE == event_code) { if (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN) { /* * The application is now full screen. * Resume reading the accelerometer. */ paused = 0; printf("Resuming accelerometer reads.\n"); } else if (!paused){ /* * The application has become thumbnailed or invisible. * If it is not already paused, then pause it. * Otherwise, ignore the window state change. */ paused = 1; printf("Resuming accelerometer reads.\n"); } } } /* * Remember to destroy any delivered events as we need to trigger * the release of any event resources when we are done processing * it. */ bps_event_destroy(event); } else { /* * We've woken up. See if we are in the paused state. If not, * take an accelerometer reading */ if (!paused) { accelerometer_read_forces(&force_x, &force_y, &force_z); display_accelerometer_reading( ACCELEROMETER_CALCULATE_PITCH(force_x, force_y, force_z), ACCELEROMETER_CALCULATE_ROLL(force_x, force_y, force_z)); } } } /* * Clean up screen resources */ screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); /* * Clean up the BPS infrastructure and exit */ bps_shutdown(); return 0; }
void cleanup_screen() { screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); screen_win = 0; screen_ctx = 0; }
int main (int argc, char **argv) { int card = -1; int dev = 0; snd_pcm_t *pcm_handle; FILE *file; wave_hdr wav_header; int samples; int sample_rate; int sample_channels; int sample_bits; char *sample_buffer; int fragsize = -1; int verbose = 0; int rtn; int final_return_code = -1; snd_pcm_channel_info_t pi; snd_mixer_t *mixer_handle; snd_mixer_group_t group; snd_pcm_channel_params_t pp; snd_pcm_channel_setup_t setup; int bsize, bytes_read, total_written = 0; fd_set rfds, wfds; uint32_t voice_mask[] = { 0, 0, 0, 0 }; snd_pcm_voice_conversion_t voice_conversion; int voice_override = 0; int num_frags = -1; char input_file[PATH_MAX]; char cwd[PATH_MAX]; screen_context_t screen_cxt; screen_window_t screen_win; screen_buffer_t screen_buf; int screen_fill_attribs[] = { SCREEN_BLIT_COLOR, COLOR_PURPLE, SCREEN_BLIT_END }; int screen_dirty[4] = { 0, 0, 1024, 600 }; //start with sane default values int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; int usage = SCREEN_USAGE_NATIVE; if (screen_create_context(&screen_cxt, 0) != 0) { return err("failed to create context"); } if (screen_create_window(&screen_win, screen_cxt) != 0) { err("failed to create window"); goto fail1; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) { err("failed to set native usage mode"); goto fail2; } if (screen_create_window_buffers(screen_win, 1) != 0) { err("failed to set native usage mode"); goto fail2; } if(screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf) != 0) { err("failed to get screen buffer"); goto fail2; } if (screen_fill(screen_cxt, screen_buf, screen_fill_attribs) != 0) { err("failed to fill the screen"); goto fail3; } if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, screen_dirty+2) != 0) { err("failed to get window size"); goto fail3; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) { err("failed to set idle mode"); goto fail3; } if (screen_post_window(screen_win, screen_buf, 1, screen_dirty, 0) != 0) { err("failed to post the window"); goto fail3; } if ((rtn = snd_pcm_open_preferred (&pcm_handle, &card, &dev, SND_PCM_OPEN_PLAYBACK)) < 0) { err ("device open"); goto fail3; } getcwd(cwd, PATH_MAX); rtn = snprintf(input_file, PATH_MAX, "%s%s", cwd, WAV_RELATIVE_PATH); if (rtn > PATH_MAX - 1) { err ("File name and path too long"); goto fail4; } if ((file = fopen (input_file, "r")) == 0) { err ("File open failed"); goto fail4; } if (check_hdr (file) == -1) { err ("check_hdr failed"); goto fail5; } samples = find_tag (file, "fmt "); fread (&wav_header, sizeof (wav_header), 1, file); fseek (file, (samples - sizeof (wave_hdr)), SEEK_CUR); sample_rate = ENDIAN_LE32 (wav_header.samples_per_sec); sample_channels = ENDIAN_LE16 (wav_header.channels); sample_bits = ENDIAN_LE16 (wav_header.bits_per_sample); printf ("SampleRate = %d, channels = %d, SampleBits = %d\n", sample_rate, sample_channels, sample_bits); /* disabling mmap is not actually required in this example but it is included to * demonstrate how it is used when it is required. */ if ((rtn = snd_pcm_plugin_set_disable (pcm_handle, PLUGIN_DISABLE_MMAP)) < 0) { fprintf (stderr, "snd_pcm_plugin_set_disable failed: %s\n", snd_strerror (rtn)); goto fail5; } memset (&pi, 0, sizeof (pi)); pi.channel = SND_PCM_CHANNEL_PLAYBACK; if ((rtn = snd_pcm_plugin_info (pcm_handle, &pi)) < 0) { fprintf (stderr, "snd_pcm_plugin_info failed: %s\n", snd_strerror (rtn)); goto fail5; } memset (&pp, 0, sizeof (pp)); pp.mode = SND_PCM_MODE_BLOCK; pp.channel = SND_PCM_CHANNEL_PLAYBACK; pp.start_mode = SND_PCM_START_FULL; pp.stop_mode = SND_PCM_STOP_STOP; pp.buf.block.frag_size = pi.max_fragment_size; if (fragsize != -1) { pp.buf.block.frag_size = fragsize; } pp.buf.block.frags_max = num_frags; pp.buf.block.frags_min = 1; pp.format.interleave = 1; pp.format.rate = sample_rate; pp.format.voices = sample_channels; if (ENDIAN_LE16 (wav_header.format_tag) == 6) pp.format.format = SND_PCM_SFMT_A_LAW; else if (ENDIAN_LE16 (wav_header.format_tag) == 7) pp.format.format = SND_PCM_SFMT_MU_LAW; else if (sample_bits == 8) pp.format.format = SND_PCM_SFMT_U8; else if (sample_bits == 24) pp.format.format = SND_PCM_SFMT_S24; else pp.format.format = SND_PCM_SFMT_S16_LE; strcpy (pp.sw_mixer_subchn_name, "Wave playback channel"); if ((rtn = snd_pcm_plugin_params (pcm_handle, &pp)) < 0) { fprintf (stderr, "snd_pcm_plugin_params failed: %s\n", snd_strerror (rtn)); goto fail5; } if ((rtn = snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) { fprintf (stderr, "snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rtn)); goto fail5; } if (voice_override) { snd_pcm_plugin_get_voice_conversion (pcm_handle, SND_PCM_CHANNEL_PLAYBACK, &voice_conversion); voice_conversion.matrix[0] = voice_mask[0]; voice_conversion.matrix[1] = voice_mask[1]; voice_conversion.matrix[2] = voice_mask[2]; voice_conversion.matrix[3] = voice_mask[3]; snd_pcm_plugin_set_voice_conversion (pcm_handle, SND_PCM_CHANNEL_PLAYBACK, &voice_conversion); } memset (&setup, 0, sizeof (setup)); memset (&group, 0, sizeof (group)); setup.channel = SND_PCM_CHANNEL_PLAYBACK; setup.mixer_gid = &group.gid; if ((rtn = snd_pcm_plugin_setup (pcm_handle, &setup)) < 0) { fprintf (stderr, "snd_pcm_plugin_setup failed: %s\n", snd_strerror (rtn)); goto fail5; } printf ("Format %s \n", snd_pcm_get_format_name (setup.format.format)); printf ("Frag Size %d \n", setup.buf.block.frag_size); printf ("Total Frags %d \n", setup.buf.block.frags); printf ("Rate %d \n", setup.format.rate); printf ("Voices %d \n", setup.format.voices); bsize = setup.buf.block.frag_size; if (group.gid.name[0] == 0) { fprintf (stderr, "Mixer Pcm Group [%s] Not Set \n", group.gid.name); goto fail5; } printf ("Mixer Pcm Group [%s]\n", group.gid.name); if ((rtn = snd_mixer_open (&mixer_handle, card, setup.mixer_device)) < 0) { fprintf (stderr, "snd_mixer_open failed: %s\n", snd_strerror (rtn)); goto fail5; } samples = find_tag (file, "data"); sample_buffer = malloc (bsize); FD_ZERO (&rfds); FD_ZERO (&wfds); bytes_read = 1; while (total_written < samples && bytes_read > 0) { if (tcgetpgrp (0) == getpid ()) FD_SET (STDIN_FILENO, &rfds); FD_SET (snd_mixer_file_descriptor (mixer_handle), &rfds); FD_SET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds); rtn = max (snd_mixer_file_descriptor (mixer_handle), snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)); if (select (rtn + 1, &rfds, &wfds, NULL, NULL) == -1) { err ("select"); goto fail6; } if (FD_ISSET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds)) { snd_pcm_channel_status_t status; int written = 0; if ((bytes_read = fread (sample_buffer, 1, min (samples - total_written, bsize), file)) <= 0) continue; written = snd_pcm_plugin_write (pcm_handle, sample_buffer, bytes_read); if (verbose) printf ("bytes written = %d \n", written); if (written < bytes_read) { memset (&status, 0, sizeof (status)); status.channel = SND_PCM_CHANNEL_PLAYBACK; if (snd_pcm_plugin_status (pcm_handle, &status) < 0) { fprintf (stderr, "underrun: playback channel status error\n"); goto fail6; } if (status.status == SND_PCM_STATUS_READY || status.status == SND_PCM_STATUS_UNDERRUN) { if (snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK) < 0) { fprintf (stderr, "underrun: playback channel prepare error\n"); goto fail6; } } if (written < 0) written = 0; written += snd_pcm_plugin_write (pcm_handle, sample_buffer + written, bytes_read - written); } total_written += written; } } bytes_read = snd_pcm_plugin_flush (pcm_handle, SND_PCM_CHANNEL_PLAYBACK); final_return_code = 0; fail6: rtn = snd_mixer_close (mixer_handle); fail5: fclose (file); fail4: rtn = snd_pcm_close (pcm_handle); fail3: screen_destroy_buffer(screen_buf); fail2: screen_destroy_window(screen_win); fail1: screen_destroy_context(screen_cxt); return final_return_code; }
int main(int argc, char *argv[]) { int rc; // Renderer variables mmr_connection_t* mmr_connection = 0; mmr_context_t* mmr_context = 0; strm_dict_t* dict = NULL; // I/O variables int video_device_output_id = -1; int audio_device_output_id = -1; // Position of the play and stop button. static int ctrl_x = 0; static int ctrl_y = 0; EGLint surface_width; EGLint surface_height; srand(time(0)); app_id = rand(); // I/O devices static char *audio_device_url = "audio:default"; static char video_device_url[PATH_MAX]; rc = snprintf(video_device_url, PATH_MAX, "screen:?winid=videosamplewindowgroup_%d&wingrp=videosamplewindowgroup_%d", app_id, app_id); if (rc >= PATH_MAX) { fprintf(stderr, "URL too long\n"); } // Name of video context...with a random number appended. static char video_context_name[PATH_MAX]; rc = snprintf(video_context_name, PATH_MAX, "samplevideocontextname_%d", app_id); if (rc >= PATH_MAX) { fprintf(stderr, "Video context name too long\n"); } // Window group name...with the same random number appended. static char window_group_name[PATH_MAX]; rc = snprintf(window_group_name, PATH_MAX, "videosamplewindowgroup_%d", app_id); if (rc >= PATH_MAX) { fprintf(stderr, "Video context name too long\n"); } // Video file bundled with our app static const char *video_file_relative_path = "app/native/pb_sample.mp4"; bps_initialize(); // Create the Screen Context. if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { fprintf(stderr, "screen_create_context failed\n"); return EXIT_FAILURE; } // Create the window and initialize EGL for GL_ES_1 rendering rc = initialize_egl_window(g_screen_ctx, window_group_name); if (rc != EXIT_SUCCESS) { fprintf(stderr, "initialize_egl_window failed\n"); return EXIT_FAILURE; } // Query width and height of the window surface created by utility code eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(g_egl_disp, g_egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != EGL_SUCCESS) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } // Initialize GL for 2D rendering glViewport(0, 0, (int)surface_width, (int) surface_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set world coordinates to coincide with screen pixels glScalef(1.0f / (float)surface_width, 1.0f / (float)surface_height, 1.0f); // We can calculate location and verticies of the controls ctrl_x = (float)surface_width / 2 - ctrl_w / 2; ctrl_y = (float)surface_height / 2 - ctrl_h / 2; g_triangle_vertices[0] = ctrl_x; g_triangle_vertices[1] = ctrl_y; g_triangle_vertices[2] = ctrl_x; g_triangle_vertices[3] = ctrl_y + ctrl_h; g_triangle_vertices[4] = ctrl_x + ctrl_w; g_triangle_vertices[5] = ctrl_y + ctrl_h / 2; g_square_vertices[0] = ctrl_x; g_square_vertices[1] = ctrl_y; g_square_vertices[2] = ctrl_x; g_square_vertices[3] = ctrl_y + ctrl_h; g_square_vertices[4] = ctrl_x + ctrl_w; g_square_vertices[5] = ctrl_y + ctrl_h; g_square_vertices[6] = ctrl_x + ctrl_w; g_square_vertices[7] = ctrl_y; g_square_vertices[8] = ctrl_x; g_square_vertices[9] = ctrl_y; // Configure mm-renderer. mmr_connection = mmr_connect(NULL); if (mmr_connection == NULL) { fprintf(stderr, "mmr_connect failed\n"); return EXIT_FAILURE; } mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO); if (mmr_context == NULL) { fprintf(stderr, "mmr_context_create failed\n"); return EXIT_FAILURE; } // Configure video and audio output. video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video"); if (video_device_output_id == -1) { fprintf(stderr, "mmr_output_attach(video) failed\n"); return EXIT_FAILURE; } audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio"); if (audio_device_output_id == -1) { fprintf(stderr, "mmr_output_attach(audio) failed\n"); return EXIT_FAILURE; } // render 'paused' render(true); // Build up the path where our bundled resource is. char cwd[PATH_MAX]; char media_file[PATH_MAX]; getcwd(cwd,PATH_MAX); rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path); if ((rc == -1) || (rc >= PATH_MAX)) { fprintf(stderr, "snprintf(media_file) failed\n"); return EXIT_FAILURE; } // Attach the input media. if (mmr_input_attach(mmr_context, media_file, "track") != 0) { fprintf(stderr, "mmr_input_attach(track) failed\n"); return EXIT_FAILURE; } int video_speed = 0; // Set the speed to 0 to pause the video initially if (mmr_speed_set(mmr_context, video_speed) != 0) { fprintf(stderr, "mmr_set_speed(0) failed\n"); return EXIT_FAILURE; } // Change to the play state, although speed is zero if (mmr_play(mmr_context) != 0) { fprintf(stderr, "mmr_play failed\n"); return EXIT_FAILURE; } /* Do some work to make the aspect ratio correct. */ dict = calculate_rect(surface_width, surface_height); if (NULL == dict) { fprintf(stderr, "calculate_rect failed\n"); return EXIT_FAILURE; } if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) { fprintf(stderr, "mmr_output_parameters failed\n"); return EXIT_FAILURE; } /* Note that we allocated memory for the dictionary, but the call to * mmr_output_parameters() deallocates that memory even on failure. */ dict = NULL; screen_request_events(g_screen_ctx); navigator_request_events(0); screen_window_t video_window = (screen_window_t)0; bool app_window_above = true; int screen_val; int exit_value = EXIT_SUCCESS; // Handle keyboard events and stop playback upon user request. for (;;) { bps_event_t *event = NULL; if (bps_get_event(&event, 0) != BPS_SUCCESS) { return EXIT_FAILURE; } if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_EXIT) { break; } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) { if ((screen_window_t)0 != video_window) { app_window_above = !app_window_above; if (app_window_above) { screen_val = 1; } else { screen_val = -1; } if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) { fprintf(stderr, "screen_set_window_property(ZORDER) failed\n"); exit_value = EXIT_FAILURE; break; } screen_val = 1; if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) { fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n"); exit_value = EXIT_FAILURE; break; } rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE); if (rc != 0) { fprintf (stderr, "Warning: Failed to flush\n"); } } } } else if (bps_event_get_domain(event) == screen_get_domain()) { screen_event_t screen_event = screen_event_get_event(event); int event_type; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type); if (event_type == SCREEN_EVENT_CREATE && (video_window == (screen_window_t)0)) { char id[256]; rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window); if (rc != 0) { fprintf(stderr, "screen_get_event_property(WINDOW) failed\n"); exit_value = EXIT_FAILURE; break; } fprintf(stderr, "video_window%d\n",(int)video_window); rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id); if (rc != 0) { fprintf(stderr, "screen_get_window_property(ID) failed\n"); exit_value = EXIT_FAILURE; break; } fprintf(stderr, "window ID is %s\n", id); if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) { fprintf(stderr, "window ID mismatch\n"); exit_value = EXIT_FAILURE; break; } } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) { if (video_speed == 0) { video_speed = 1000; render(false); } else { video_speed = 0; render(true); } if (mmr_speed_set(mmr_context, video_speed) != 0) { fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed); exit_value = EXIT_FAILURE; break; } } } } } screen_stop_events(g_screen_ctx); if (mmr_stop(mmr_context) != 0) { fprintf(stderr, "mmr_stop failed\n"); exit_value = EXIT_FAILURE; } if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) { fprintf(stderr, "mmr_output_detach(audio) failed\n"); exit_value = EXIT_FAILURE; } if (mmr_output_detach(mmr_context, video_device_output_id) != 0) { fprintf(stderr, "mmr_output_detach(video) failed\n"); exit_value = EXIT_FAILURE; } if (mmr_context_destroy(mmr_context) != 0) { fprintf(stderr, "mmr_context_destroy failed\n"); exit_value = EXIT_FAILURE; } mmr_context = 0; video_device_output_id = -1; audio_device_output_id = -1; mmr_disconnect(mmr_connection); mmr_connection = 0; bps_shutdown(); if (screen_destroy_window(g_screen_win) != 0) { fprintf(stderr, "screen_destroy_window failed\n"); exit_value = EXIT_FAILURE; } if (screen_destroy_context(g_screen_ctx) != 0) { fprintf(stderr, "screen_destroy_context failed\n"); exit_value = EXIT_FAILURE; } g_screen_ctx = 0; g_screen_win = 0; return exit_value; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; // Screen variables screen_context_t screen_context = 0; screen_window_t screen_window = 0; int screen_size[2] = {0,0}; // Renderer variables mmr_connection_t* mmr_connection = 0; mmr_context_t* mmr_context = 0; strm_dict_t* dict = NULL; // I/O variables int video_device_output_id = -1; int audio_device_output_id = -1; bps_initialize(); /* * Create the window used for video output. */ if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_window, screen_context) != 0) { screen_destroy_context(screen_context); return EXIT_FAILURE; } if (screen_create_window_group(screen_window, window_group_name) != 0) { return EXIT_FAILURE; } int format = SCREEN_FORMAT_RGBA8888; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) { return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) { return EXIT_FAILURE; } if (screen_create_window_buffers(screen_window, 1) != 0) { return EXIT_FAILURE; } /* * Configure mm-renderer. */ mmr_connection = mmr_connect(NULL); if (mmr_connection == NULL) { return EXIT_FAILURE; } mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO); if (mmr_context == NULL) { return EXIT_FAILURE; } /* * Configure video and audio output. */ video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video"); if (video_device_output_id == -1) { return EXIT_FAILURE; } audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio"); if (audio_device_output_id == -1) { return EXIT_FAILURE; } // Get the render buffer screen_buffer_t temp_buffer[1]; if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) { return EXIT_FAILURE; } // Fill the buffer with a solid color (black) int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END}; if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) { return EXIT_FAILURE; } // Make the window visible if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) { return EXIT_FAILURE; } int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]}; if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) { return EXIT_FAILURE; } // Prevent the backlight from going off int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) { return EXIT_FAILURE; } // Build up the path where our bundled resource is. char cwd[PATH_MAX]; char media_file[PATH_MAX]; getcwd(cwd,PATH_MAX); rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd); if ((rc == -1) || (rc >= PATH_MAX)) { return EXIT_FAILURE; } /* * Start the playback. */ if (mmr_input_attach(mmr_context, media_file, "track") != 0) { return EXIT_FAILURE; } if (mmr_play(mmr_context) != 0) { return EXIT_FAILURE; } /* Do some work to make the aspect ratio correct. */ dict = calculate_rect(screen_size[0], screen_size[1]); if (NULL == dict) { return EXIT_FAILURE; } if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) { return EXIT_FAILURE; } /* Note that we allocated memory for the dictionary, but the call to * mmr_output_parameters() deallocates that memory even on failure. */ dict = NULL; screen_request_events(screen_context); navigator_request_events(0); /* * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = NULL; if (bps_get_event(&event, -1) != BPS_SUCCESS) { return EXIT_FAILURE; } if (event) { if (bps_event_get_domain(event) == navigator_get_domain() && bps_event_get_code(event) == NAVIGATOR_EXIT) { exit_application = 1; } if (exit_application) { break; } } } screen_stop_events(screen_context); if (mmr_stop(mmr_context) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, video_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_context_destroy(mmr_context) != 0) { return EXIT_FAILURE; } mmr_context = 0; video_device_output_id = -1; audio_device_output_id = -1; mmr_disconnect(mmr_connection); mmr_connection = 0; bps_shutdown(); if (screen_destroy_window(screen_window) != 0) { return EXIT_FAILURE; } if (screen_destroy_context(screen_context) != 0) { return EXIT_FAILURE; } screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
gceSTATUS gcoOS_CreateWindow( IN HALNativeDisplayType Display, IN gctINT X, IN gctINT Y, IN gctINT Width, IN gctINT Height, OUT HALNativeWindowType * Window ) { gctINT pos[2]; gctINT size[2]; gctINT screen_format = SCREEN_FORMAT_RGBX8888; gctINT screen_transparency = SCREEN_TRANSPARENCY_NONE; gctINT screen_usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_OPENVG ; /* Use 0 for no-vsync, and 1 for vsync limited. */ gctINT screen_swap_interval = 0; gctINT rc; gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Display=0x%x X=%d Y=%d Width=%d Height=%d", Display, X, Y, Width, Height); /* Create window strcture. */ rc = screen_create_window((struct _screen_window **)Window, screen_ctx); if (rc) { fprintf(stderr, "screen_create_window failed with error %d (0x%08x)\n", errno, errno); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Set window pximap format. */ rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_FORMAT, &screen_format); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Set window usage. */ rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_USAGE, &screen_usage); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_USAGE) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Get fullscreen window size. */ rc = screen_get_window_property_iv(*Window, SCREEN_PROPERTY_SIZE, size); if (rc) { fprintf(stderr, "screen_get_window_property_iv(SCREEN_PROPERTY_SIZE) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Disable transparency. Due to a bug in Screen, this must be set after format. */ rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_TRANSPARENCY, &screen_transparency); if (rc) { fprintf(stderr, "screen_get_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Set swap interval. */ rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_SWAP_INTERVAL, &screen_swap_interval); if (rc) { fprintf(stderr, "screen_get_window_property_iv(SCREEN_PROPERTY_SWAP_INTERVAL) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Test for zero width. */ if (Width == 0) { Width = size[0]; } /* Test for zero height. */ if (Height == 0) { Height = size[1]; } /* Test for auto-center X coordinate. */ if (X == -1) { X = (size[0] - Width) / 2; } /* Test for auto-center X coordinate. */ if (Y == -1) { Y = (size[1] - Height) / 2; } /* Resize the window. */ size[0] = Width; size[1] = Height; rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_SIZE, size); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_SIZE) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Create window buffer. */ /* Second argument is the number of back buffers to be used. */ rc = screen_create_window_buffers(*Window, gcdDISPLAY_BACK_BUFFERS); if (rc) { fprintf(stderr, "screen_create_window_buffers failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } /* Move window position. */ pos[0] = X; pos[1] = Y; rc = screen_set_window_property_iv(*Window, SCREEN_PROPERTY_POSITION, pos); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_POSITION) failed with error %d (0x%08x)\n", errno, errno); screen_destroy_window(*Window); status = gcvSTATUS_OUT_OF_RESOURCES; gcmFOOTER(); return status; } gcmFOOTER_ARG("*Window=0x%x", *Window); return status; }