void discoverControllers() { // Get an array of all available devices. int deviceCount; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); screen_device_t* devices_found = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); // Scan the list for gamepad and joystick devices. int i; for(i=0;i<pads_connected;++i) initController(&devices[i]); pads_connected = 0; for (i = 0; i < deviceCount; i++) { int type; screen_get_device_property_iv(devices_found[i], SCREEN_PROPERTY_TYPE, &type); if (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) { devices[pads_connected].handle = devices_found[i]; loadController(&devices[pads_connected]); pads_connected++; if (pads_connected == MAX_PADS) break; } } free(devices_found); }
static void discoverControllers() { // Get an array of all available devices. int deviceCount; SCREEN_API(screen_get_context_property_iv(_screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount), "SCREEN_PROPERTY_DEVICE_COUNT"); screen_device_t* devices = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); SCREEN_API(screen_get_context_property_pv(_screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices), "SCREEN_PROPERTY_DEVICES"); // Scan the list for gamepad and joystick devices. int i; int controllerIndex = 0; for (i = 0; i < deviceCount; i++) { int type; SCREEN_API(screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &type), "SCREEN_PROPERTY_TYPE"); if (!rc && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK)) { // Assign this device to control Player 1 or Player 2. GameController* controller = &_controllers[controllerIndex]; controller->handle = devices[i]; loadController(controller); // We'll just use the first compatible devices we find. controllerIndex++; if (controllerIndex == MAX_CONTROLLERS) { break; } } } free(devices); }
void BlackberryMain::startDisplays() { int num_configs; EGLint attrib_list[]= { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_STENCIL_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE}; const EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; screen_get_context_property_iv(screen_cxt, SCREEN_PROPERTY_DISPLAY_COUNT, &ndisplays); egl_disp = (EGLDisplay*)calloc(ndisplays, sizeof(EGLDisplay)); egl_surf = (EGLSurface*)calloc(ndisplays, sizeof(EGLSurface)); displays = (dispdata_t*)calloc(ndisplays, sizeof(dispdata_t)); screen_win = (screen_window_t *)calloc(ndisplays, sizeof(screen_window_t )); screen_dpy = (screen_display_t*)calloc(ndisplays, sizeof(screen_display_t)); screen_get_context_property_pv(screen_cxt, SCREEN_PROPERTY_DISPLAYS, (void **)screen_dpy); // Common data int usage = SCREEN_USAGE_ROTATION | SCREEN_USAGE_OPENGL_ES2; int format = SCREEN_FORMAT_RGBX8888; int sensitivity = SCREEN_SENSITIVITY_ALWAYS; // Initialise every display for (int i = 0; i < ndisplays; i++) { screen_get_display_property_iv(screen_dpy[i], SCREEN_PROPERTY_TYPE, &(displays[i].type)); screen_get_display_property_iv(screen_dpy[i], SCREEN_PROPERTY_ATTACHED, &(displays[i].attached)); screen_create_window(&screen_win[i], screen_cxt); screen_set_window_property_iv(screen_win[i], SCREEN_PROPERTY_FORMAT, &format); screen_set_window_property_iv(screen_win[i], SCREEN_PROPERTY_USAGE, &usage); screen_set_window_property_iv(screen_win[i], SCREEN_PROPERTY_SENSITIVITY, &sensitivity); screen_set_window_property_pv(screen_win[i], SCREEN_PROPERTY_DISPLAY, (void **)&screen_dpy[i]); egl_disp[i] = eglGetDisplay((EGLNativeDisplayType)i); eglInitialize(egl_disp[i], NULL, NULL); if (egl_cont == EGL_NO_CONTEXT) { eglChooseConfig(egl_disp[0], attrib_list, &egl_conf, 1, &num_configs); egl_cont = eglCreateContext(egl_disp[0], egl_conf, EGL_NO_CONTEXT, attributes); } fprintf(stderr, "Display %i: %s, %s\n", i, displayTypeString(displays[i].type), displays[i].attached ? "Attached" : "Detached"); if (displays[i].attached) realiseDisplay(i); } #ifdef ARM screen_get_display_property_iv(screen_dpy[0], SCREEN_PROPERTY_DPI, &dpi); // Only internal display has DPI // We only use dpi to calculate the width. Smaller aspect ratios have giant text despite high DPI. dpi = dpi * (((float)displays[0].width/(float)displays[0].height) / (16.0/9.0)); // Adjust to 16:9 #else dpi = 340.0f; #endif g_dpi_scale = 210.0f / dpi; switchDisplay(screen_ui); }
int OpenGLThread::initEGL() { int returnCode, type; int num_configs; m_numberDisplays = 0; EGLint attrib_list[]= { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 16, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_NONE}; screen_get_context_property_iv(m_screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &m_numberDisplays); m_screen_dpy = (screen_display_t *)calloc(m_numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(m_screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)m_screen_dpy); m_egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (m_egl_disp == EGL_NO_DISPLAY) { eglPrintError("eglGetDisplay"); return EXIT_FAILURE; } returnCode = eglInitialize(m_egl_disp, NULL, NULL); if (returnCode != EGL_TRUE) { eglPrintError("eglInitialize"); return EXIT_FAILURE; } if ((m_api == GL_ES_1) || (m_api == GL_ES_2)) { returnCode = eglBindAPI(EGL_OPENGL_ES_API); } else if (m_api == VG) { returnCode = eglBindAPI(EGL_OPENVG_API); } if (returnCode != EGL_TRUE) { eglPrintError("eglBindApi"); return EXIT_FAILURE; } if(!eglChooseConfig(m_egl_disp, attrib_list, &m_egl_conf, 1, &num_configs)) { perror("eglChooseConfig"); return EXIT_FAILURE; } setEGLInitialized(true); return EXIT_SUCCESS; }
int NativeWindow::screenDisplayAttached(bps_event_t *event, int *size) { screen_display_t eventDisplay; int type; int attached = -1; screen_event_t screen_event = screen_event_get_event(event); //Query type of screen event and its location on the screen screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &type); _displaysMutex.lock(); if (_screenDisplays) { free (_screenDisplays); } // try this first as it will fail if an HDMI display is not attached screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays); _screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays); switch (type) { case SCREEN_EVENT_DISPLAY: screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DISPLAY, (void **)&eventDisplay); for (int index = 0; index < _numberDisplays; index++) { if (eventDisplay == _screenDisplays[index]) { screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached); if (attached) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_SIZE, size); if (size[0] == 0 || size[1] == 0) { attached = 0; } } } } break; } _displaysMutex.unlock(); return attached; }
static void discoverControllers(void *data) { /* Get an array of all available devices. */ int deviceCount; unsigned i; screen_event_t *event; qnx_input_t *qnx = (qnx_input_t*)data; (void)event; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); screen_device_t* devices_found = (screen_device_t*) calloc(deviceCount, sizeof(screen_device_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); /* Scan the list for gamepad and joystick devices. */ for(i = 0; i < qnx->pads_connected; ++i) initController(qnx, &qnx->devices[i]); qnx->pads_connected = 0; for (i = 0; i < deviceCount; i++) { int type; screen_get_device_property_iv( devices_found[i], SCREEN_PROPERTY_TYPE, &type); if ( type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) { qnx->devices[qnx->pads_connected].handle = devices_found[i]; qnx->devices[qnx->pads_connected].index = qnx->pads_connected; handle_device(qnx, &qnx->devices[qnx->pads_connected]); if (qnx->pads_connected == MAX_PADS) break; } } free(devices_found); }
void QQnxIntegration::createDisplays() { qIntegrationDebug() << Q_FUNC_INFO; // Query number of displays errno = 0; int displayCount; int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount); if (result != 0) { qFatal("QQnxIntegration: failed to query display count, errno=%d", errno); } if (displayCount < 1) { // Never happens, even if there's no display, libscreen returns 1 qFatal("QQnxIntegration: displayCount=%d", displayCount); } // Get all displays errno = 0; screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)displays); if (result != 0) { qFatal("QQnxIntegration: failed to query displays, errno=%d", errno); } // If it's primary, we create a QScreen for it even if it's not attached // since Qt will dereference QGuiApplication::primaryScreen() createDisplay(displays[0], /*isPrimary=*/true); for (int i=1; i<displayCount; i++) { int isAttached = 0; result = screen_get_display_property_iv(displays[i], SCREEN_PROPERTY_ATTACHED, &isAttached); if (result != 0) { qWarning("QQnxIntegration: failed to query display attachment, errno=%d", errno); isAttached = 1; // assume attached } if (!isAttached) { qIntegrationDebug() << Q_FUNC_INFO << "Skipping non-attached display" << i; continue; } qIntegrationDebug() << Q_FUNC_INFO << "Creating screen for display" << i; createDisplay(displays[i], /*isPrimary=*/false); } // of displays iteration }
int NativeWindow::screenDisplayAttached(int *size) { //qDebug() << "NativeWindow::screenDisplayAttached: "; int type; int attached = 0; _displaysMutex.lock(); if (_screenDisplays) { free (_screenDisplays); } // try this first as it will fail if an HDMI display is not attached screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays); _screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays); for (int index = 0; index < _numberDisplays; index++) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_TYPE, &type); attached = 0; if (type == SCREEN_DISPLAY_TYPE_HDMI) { //qDebug() << "NativeWindow::screenDisplayAttached: HDMI: " << index; screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_ATTACHED, &attached); if (attached) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_SIZE, size); //qDebug() << "NativeWindow::screenDisplayAttached: size: " << size[0] << "x" << size[1]; if (size[0] == 0 || size[1] == 0) { attached = 0; } } } } _displaysMutex.unlock(); //qDebug() << "NativeWindow::screenDisplayAttached: "<< attached; return attached; }
screen_display_t* NativeWindow::getAttachedDisplay() { int type; int attached = 0; screen_display_t* attachedDisplay = NULL; _displaysMutex.lock(); if (_screenDisplays) { free (_screenDisplays); } // try this first as it will fail if an HDMI display is not attached screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays); _screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays); for (int index = 0; index < _numberDisplays; index++) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_TYPE, &type); attached = 0; if (type == SCREEN_DISPLAY_TYPE_HDMI) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_ATTACHED, &attached); if (attached) { int size[2]; screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_SIZE, size); if (size[0] == 0 || size[1] == 0) { attached = 0; } else { attachedDisplay = &_screenDisplays[index]; } } } } _displaysMutex.unlock(); return attachedDisplay; }
int OpenGLView::initGL() { int numberDisplays; int numberModes; int returnCode; EGLBoolean status; int type; EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLint attrib_list[]= { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_NONE}; // try this first as it will fail if an HDMI display is not attached if (m_api == GL_ES_2) { m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, attributes); } else { m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, NULL); } if (m_egl_ctx == EGL_NO_CONTEXT) { perror("eglCreateContext"); return EXIT_FAILURE; } screen_get_context_property_iv(m_screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &numberDisplays); m_screen_dpy = (screen_display_t *)calloc(numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(m_screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)m_screen_dpy); for (int index = 0; index < numberDisplays; index++) { int displayID; returnCode = screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_ID, (int *)&displayID); if (returnCode) { perror("display ID"); return EXIT_FAILURE; } else { if (displayID == m_display) { screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_TYPE, &type); if (type == SCREEN_DISPLAY_TYPE_HDMI) { returnCode = screen_create_window(&m_screen_win, m_screen_ctx); if (returnCode) { perror("screen_create_window"); return EXIT_FAILURE; } } else { returnCode = screen_create_window_type(&m_screen_win, m_screen_ctx, SCREEN_CHILD_WINDOW); if (returnCode) { perror("screen_create_window (child window)"); return EXIT_FAILURE; } } if (type == SCREEN_DISPLAY_TYPE_HDMI) { returnCode = screen_set_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&(m_screen_dpy[index])); if (returnCode) { perror("window display"); return EXIT_FAILURE; } } } } } qDebug() << "OpenGLView::initialize: "<< m_screen_ctx << ":" << m_egl_disp << ":" << m_egl_conf << ":" << m_egl_ctx << ":" << m_screen_win; int format = SCREEN_FORMAT_RGBA8888; returnCode = screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_FORMAT, &format); if (returnCode) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)"); return EXIT_FAILURE; } if (m_transparency > 0) { returnCode = setWindowTransparency(m_transparency); if (returnCode) { perror("transparency"); return EXIT_FAILURE; } } returnCode = screen_get_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_disp); if (returnCode) { perror("screen_get_window_property_pv"); return EXIT_FAILURE; } int angle = atoi(getenv("ORIENTATION")); screen_get_display_property_iv(m_screen_disp, SCREEN_PROPERTY_MODE_COUNT, &numberModes); m_screen_modes = (screen_display_mode_t *)calloc(numberModes, sizeof(screen_display_mode_t)); returnCode = screen_get_display_property_pv(m_screen_disp, SCREEN_PROPERTY_MODE, (void**)m_screen_modes); if (returnCode) { perror("screen modes"); return EXIT_FAILURE; } int dpi = calculateDPI(); if (dpi == EXIT_FAILURE) { fprintf(stderr, "Unable to calculate dpi\n"); return EXIT_FAILURE; } returnCode = setWindowPosition(m_x, m_y); if (returnCode) { perror("window position"); return EXIT_FAILURE; } returnCode = setWindowSize(m_width, m_height); if (returnCode) { perror("window size"); return EXIT_FAILURE; } returnCode = setWindowZ(m_z); if (returnCode) { perror("z order"); return EXIT_FAILURE; } returnCode = setWindowBufferSize(m_width, m_height); if (returnCode) { perror("buffer size"); return EXIT_FAILURE; } returnCode = setWindowAngle(m_angle); if (returnCode) { perror("angle"); return EXIT_FAILURE; } returnCode = screen_create_window_buffers(m_screen_win, m_nbuffers); if (returnCode) { perror("screen_create_window_buffers"); return EXIT_FAILURE; } if (m_api == GL_ES_1) { m_usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION; } else if (m_api == GL_ES_2) { attrib_list[9] = EGL_OPENGL_ES2_BIT; m_usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; } else if (m_api == VG) { attrib_list[9] = EGL_OPENVG_BIT; m_usage = SCREEN_USAGE_OPENVG | SCREEN_USAGE_ROTATION; } else { fprintf(stderr, "invalid api setting\n"); return EXIT_FAILURE; } returnCode = setWindowUsage(m_usage); if (returnCode) { perror("screen_set_window_property_iv(window usage)"); return EXIT_FAILURE; } qDebug() << "OpenGLView::initGL:eglCreateContext "<< m_egl_ctx; m_egl_surf = eglCreateWindowSurface(m_egl_disp, m_egl_conf, m_screen_win, NULL); if (m_egl_surf == EGL_NO_SURFACE) { OpenGLThread::eglPrintError("eglCreateWindowSurface"); return EXIT_FAILURE; } getGLContext(); EGLint interval = 1; status = eglSwapInterval(m_egl_disp, interval); if (status != EGL_TRUE) { OpenGLThread::eglPrintError("eglSwapInterval"); return EXIT_FAILURE; } status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_WIDTH, &m_surface_width); if (status != EGL_TRUE) { perror("query surface width"); return EXIT_FAILURE; } status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_HEIGHT, &m_surface_height); if (status != EGL_TRUE) { perror("query surface height"); return EXIT_FAILURE; } returnCode = joinWindowGroup(m_group); if (returnCode) { perror("window group"); return EXIT_FAILURE; } returnCode = setScreenWindowID(m_id); if (returnCode) { perror("window ID"); return EXIT_FAILURE; } qDebug() << "OpenGLView::initGL: "<< angle << ":" << numberModes << ":" << m_screen_modes[0].width << ":" << m_screen_modes[0].height << ":" << m_egl_disp << ":" << dpi; setInitialized(true); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int exit_application = 0; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_ctx, 0); // Get display configuration (dimensions) int count = 0; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count); screen_display_t *screen_disps = (screen_display_t *)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); nScreenWidth = dims[0]; nScreenHeight = dims[1]; //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 2.0 if (EXIT_SUCCESS != bbutil_init_egl(screen_ctx)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); bps_shutdown(); return 0; } while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) { if (BPS_SUCCESS != bps_get_event(&event, 0)) { fprintf(stderr, "bps_get_event failed\n"); break; } if (event) { int domain = bps_event_get_domain(event); if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } else { break; } } render(); } //Stop requesting events from libscreen screen_stop_events(screen_ctx); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_ctx); return 0; }
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; }
int InitQNX(const char *Title,int Width,int Height) { /* Initialize variables */ AppTitle = Title; XSize = Width; YSize = Height; TimerON = 0; TimerReady = 0; JoyState = 0; LastKey = 0; KeyModes = 0; FrameCount = 0; FrameRate = 0; /* Get initial timestamp */ gettimeofday(&TimeStamp,0); screen_create_context(&ctxt, SCREEN_APPLICATION_CONTEXT); int dispCount; screen_get_context_property_iv(ctxt, SCREEN_PROPERTY_DISPLAY_COUNT, &dispCount); screen_display_t* displays = new screen_display_t[dispCount]; screen_get_context_property_pv(ctxt, SCREEN_PROPERTY_DISPLAYS, (void**)displays); int resolution[2] = { 0, 0 }; screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_SIZE, resolution); delete[] displays; actualSize_x = resolution[0]; actualSize_y = resolution[1]; double scaleY; if (isPhysicalKeyboardDevice) scaleY = ((double)resolution[1]) / 600.0; else scaleY = ((double)resolution[1]) / 1024.0; double scaleX = ((double)resolution[0]) / 600.0; scaleTouchMap(scaleX, scaleY); if (BPS_SUCCESS != screen_request_events(ctxt)) { screen_destroy_context(ctxt); return 0; } #ifdef __BBTEN__ screen_create_window_type(&window, ctxt, SCREEN_CHILD_WINDOW); screen_join_window_group(window, windowGroup); screen_set_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, windowIdLength, "AlmostTIAppID"); int vis = 1; screen_set_window_property_iv(window, SCREEN_PROPERTY_VISIBLE, &vis); int z = -5; screen_set_window_property_iv(window, SCREEN_PROPERTY_ZORDER, &z); if (isPhysicalKeyboardDevice) virtualkeyboard_request_events(0); #else screen_create_window(&window, ctxt); int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_NATIVE; screen_set_window_property_iv(window, SCREEN_PROPERTY_USAGE, &usage); #endif screen_create_window_buffers(window, 1); screen_get_window_property_iv(window, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); /* Done */ return(1); }
int NativeWindow::initialize(bool _createFullWindow) { int returnCode; int numberModes; screen_display_mode_t* screenModes; int type; if (_createFullWindow) { returnCode = screen_create_window(&_screenWindow, _screenContext); qDebug() << "NativeWindow::initialize: _screenWindow (full window): " << ":" << _screenWindow << ":" << _screenContext << ":" << returnCode; if (returnCode) { perror("screen_create_window"); return EXIT_FAILURE; } } else { returnCode = screen_create_window_type(&_screenWindow, _screenContext, SCREEN_CHILD_WINDOW); qDebug() << "NativeWindow::initialize: _screenWindow (child window): " << _screenWindow << ":" << returnCode; if (returnCode) { perror("screen_create_window (child window)"); return EXIT_FAILURE; } } _displaysMutex.lock(); if (_screenDisplays) { free (_screenDisplays); } // try this first as it will fail if an HDMI display is not attached screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays); _screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t)); screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays); for (int index = 0; index < _numberDisplays; index++) { int displayID; returnCode = screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_ID, (int *)&displayID); qDebug() << "NativeWindow::initialize: display: " << ":" << index << ":" << displayID << ":" << _display << ":" << _screenDisplays[index]; if (returnCode) { perror("display ID"); return EXIT_FAILURE; } else { if (displayID == _display) { screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_TYPE, &type); if (type == SCREEN_DISPLAY_TYPE_HDMI) { returnCode = screen_set_window_property_pv(_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&(_screenDisplays[index])); if (returnCode) { perror("window display"); return EXIT_FAILURE; } } } } } _displaysMutex.unlock(); qDebug() << "NativeWindow::initialize: "<< _screenContext << ":" << _screenWindow; returnCode = setWindowFormat(_format); if (returnCode) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)"); return EXIT_FAILURE; } returnCode = setWindowTransparency(_transparency); if (returnCode) { perror("transparency"); return EXIT_FAILURE; } returnCode = screen_get_window_property_pv(_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&_screenDisplay); if (returnCode) { perror("screenDisplay"); return EXIT_FAILURE; } int angle = atoi(getenv("ORIENTATION")); screen_get_display_property_iv(_screenDisplay, SCREEN_PROPERTY_MODE_COUNT, &numberModes); screenModes = (screen_display_mode_t *)calloc(numberModes, sizeof(screen_display_mode_t)); returnCode = screen_get_display_property_pv(_screenDisplay, SCREEN_PROPERTY_MODE, (void**)screenModes); if (returnCode) { perror("screen modes"); return EXIT_FAILURE; } int dpi = calculateDPI(); if (dpi == EXIT_FAILURE) { fprintf(stderr, "Unable to calculate dpi\n"); return EXIT_FAILURE; } returnCode = setWindowPosition(_x, _y); if (returnCode) { perror("window position"); return EXIT_FAILURE; } returnCode = setWindowSize(_width, _height); if (returnCode) { perror("window size"); return EXIT_FAILURE; } returnCode = setWindowZ(_z); if (returnCode) { perror("z order"); return EXIT_FAILURE; } if (_sourceWidth > 0) { returnCode = setWindowSourcePosition(_sourceX, _sourceY); if (returnCode) { perror("source size"); return EXIT_FAILURE; } returnCode = setWindowSourceSize(_sourceWidth, _sourceHeight); if (returnCode) { perror("source size"); return EXIT_FAILURE; } } if (_bufferWidth > 0) { returnCode = setWindowBufferSize(_bufferWidth, _bufferHeight); if (returnCode) { perror("buffer size"); return EXIT_FAILURE; } } returnCode = setWindowAngle(_angle); if (returnCode) { perror("angle"); return EXIT_FAILURE; } returnCode = screen_create_window_buffers(_screenWindow, _nbuffers); if (returnCode) { perror("screen_create_window_buffers"); return EXIT_FAILURE; } _usage = Graphics::getNativeWindowUsage(); // enable this in case we need any native API access to this window _usage |= SCREEN_USAGE_NATIVE; returnCode = setWindowUsage(_usage); if (returnCode) { perror("screen_set_window_property_iv(window usage)"); return EXIT_FAILURE; } returnCode = joinWindowGroup(_group); if (returnCode) { perror("window group"); return EXIT_FAILURE; } returnCode = setScreenWindowID(_id); if (returnCode) { perror("window ID"); return EXIT_FAILURE; } qDebug() << "NativeWindow::initialize: "<< angle << ":" << numberModes << ":" << screenModes[0].width << ":" << screenModes[0].height << ":" << dpi; if (screenModes != NULL) { free(screenModes); } return EXIT_SUCCESS; }