void QQnxWindow::setVisible(bool visible) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "visible =" << visible; if (m_visible == visible || window()->type() == Qt::Desktop) return; // The first time through we join a window group if appropriate. if (m_parentGroupName.isNull() && !m_isTopLevel) { joinWindowGroup(parent() ? static_cast<QQnxWindow*>(parent())->groupName() : QByteArray(m_screen->windowGroupName())); } m_visible = visible; QQnxWindow *root = this; while (root->m_parentWindow) root = root->m_parentWindow; root->updateVisibility(root->m_visible); QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), window()->geometry().size())); if (visible) { applyWindowState(); } else { // Flush the context, otherwise it won't disappear immediately screen_flush_context(m_screenContext, 0); } }
void QQnxWindow::setGeometryHelper(const QRect &rect) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << ", (" << rect.x() << "," << rect.y() << "," << rect.width() << "," << rect.height() << ")"; // Call base class method QPlatformWindow::setGeometry(rect); // Set window geometry equal to widget geometry int val[2]; val[0] = rect.x(); val[1] = rect.y(); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val), "Failed to set window position"); val[0] = rect.width(); val[1] = rect.height(); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val), "Failed to set window size"); // Set viewport size equal to window size Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val), "Failed to set window source size"); screen_flush_context(m_screenContext, 0); QWindowSystemInterface::handleGeometryChange(window(), rect); }
void QBBScreen::setRotation(int rotation) { #if defined(QBBSCREEN_DEBUG) qDebug() << "QBBScreen::setRotation, o=" << rotation; #endif // check if rotation changed if (mCurrentRotation != rotation) { // update rotation of root window if (mRootWindow) mRootWindow->setRotation(rotation); const QRect previousScreenGeometry = geometry(); // swap dimensions if we've rotated 90 or 270 from initial orientation if (isOrthogonal(mStartRotation, rotation)) { mCurrentGeometry = QRect(0, 0, mStartGeometry.height(), mStartGeometry.width()); mCurrentPhysicalSize = QSize(mStartPhysicalSize.height(), mStartPhysicalSize.width()); } else { mCurrentGeometry = QRect(0, 0, mStartGeometry.width(), mStartGeometry.height()); mCurrentPhysicalSize = mStartPhysicalSize; } // resize app window if we've rotated 90 or 270 from previous orientation if (isOrthogonal(mCurrentRotation, rotation)) { #if defined(QBBSCREEN_DEBUG) qDebug() << "QBBScreen::setRotation - resize, s=" << mCurrentGeometry.size(); #endif if (mRootWindow) mRootWindow->resize(mCurrentGeometry.size()); if (mPrimaryDisplay) resizeWindows(previousScreenGeometry); } else { // TODO: find one global place to flush display updates #if defined(QBBSCREEN_DEBUG) qDebug() << "QBBScreen::setRotation - flush"; #endif // force immediate display update if no geometry changes required if (mRootWindow) mRootWindow->flush(); } // save new rotation mCurrentRotation = rotation; // TODO: check if other screens are supposed to rotate as well and/or whether this depends // on if clone mode is being used. // Rotating only the primary screen is what we had in the navigator event handler before refactoring if (mPrimaryDisplay) QWindowSystemInterface::handleScreenGeometryChange(mScreenIndex); // Flush everything, so that the windows rotations are applied properly. // Needed for non-maximized windows screen_flush_context(mContext, 0); } }
void QQnxRootWindow::flush() const { qRootWindowDebug() << Q_FUNC_INFO; // Force immediate display update errno = 0; int result = screen_flush_context(m_screen->nativeContext(), 0); if (result != 0) qFatal("QQnxRootWindow: failed to flush context, errno=%d", errno); }
void QQnxWindow::setOpacity(qreal level) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "opacity =" << level; // Set window global alpha int val = (int)(level * 255); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val), "Failed to set global alpha"); screen_flush_context(m_screenContext, 0); }
static void handle_screen_event(bps_event_t *event) { int screen_val; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); switch (screen_val) { case SCREEN_EVENT_MTOUCH_TOUCH: fprintf(stderr,"Touch event\n"); touch = true; break; case SCREEN_EVENT_MTOUCH_MOVE: fprintf(stderr,"Move event\n"); break; case SCREEN_EVENT_MTOUCH_RELEASE: fprintf(stderr,"Release event\n"); break; case SCREEN_EVENT_CREATE: // in a more involved application, it may be wise to actually check the window name to ensure // that we are processing the viewfinder window here, and not some other window if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void **)&vf_win) == -1) { perror("screen_get_event_property_pv(SCREEN_PROPERTY_WINDOW)"); } else { fprintf(stderr,"viewfinder window found!\n"); // mirror viewfinder if this is the front-facing camera int i = (shouldmirror?1:0); screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_MIRROR, &i); // place viewfinder in front of the black application background window. // note that a child window's ZORDER is relative to it's parent. // if we wanted to draw a UI on the application window, we could place the // viewfinder behind it and rely on transparency. or alternately, another // child window could be overlaid on top of the viewfinder. i = +1; screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_ZORDER, &i); // make viewfinder window visible i = 1; screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_VISIBLE, &i); screen_flush_context(screen_ctx, 0); // we should now have a visible viewfinder // other things we could do here include rotating the viewfinder window (screen rotation), // or adjusting the size & position of the window. // some properties are immutable for security reasons since the window was actually created // in another process. anything related to presentation should be modifiable. touch = false; state = STATE_VIEWFINDER; } break; default: break; } }
QT_BEGIN_NAMESPACE void qScreenCheckError(int rc, const char *funcInfo, const char *message, bool critical) { if (!rc && (QQnxIntegration::options() & QQnxIntegration::AlwaysFlushScreenContext) && QQnxIntegration::screenContext() != 0) { rc = screen_flush_context(QQnxIntegration::screenContext(), 0); } if (rc) { if (critical) qCritical("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno); else qWarning("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno); } }
void QQnxWindow::setVisible(bool visible) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "visible =" << visible; m_visible = visible; QQnxWindow *root = this; while (root->m_parentWindow) root = root->m_parentWindow; root->updateVisibility(root->m_visible); window()->requestActivate(); if (window()->isTopLevel()) { QWindowSystemInterface::handleExposeEvent(window(), window()->geometry()); if (!visible) { // Flush the context, otherwise it won't disappear immediately screen_flush_context(m_screenContext, 0); } } }
void MinutesPerGameRenderer::initialize() { m_startPos = 1; QByteArray groupArr = m_group.toAscii(); QByteArray idArr = m_id.toAscii(); // Initialize the BBS components. initGL(); // We want to handle openGL Events in the foreign window. So bring the // in front of the cascades window (z > 0). m_screen_win = bbutil_get_window(); int z = 1; screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_ZORDER, &z); screen_join_window_group(m_screen_win, groupArr.constData()); screen_set_window_property_cv(m_screen_win, SCREEN_PROPERTY_ID_STRING, idArr.length(), idArr.constData()); int vis = 1; screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_VISIBLE, &vis); int pos[2] = { 280, 0 }; screen_set_window_property_iv(getWindow(), SCREEN_PROPERTY_POSITION, pos); screen_flush_context(GLThread::instance()->getContext(), SCREEN_WAIT_IDLE); }
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 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 NativeWindow::updateScreen() { int returnCode = screen_flush_context(_screenContext, SCREEN_WAIT_IDLE); return returnCode; }