void NativeWindow::setBufferSize(int bufferWidth, int bufferHeight) { _bufferWidth = bufferWidth; _bufferHeight = bufferHeight; int returnCode = setWindowBufferSize(_bufferWidth, _bufferHeight); if (returnCode) { perror("buffer size"); } }
int OpenGLView::regenerate() { int returnCode; EGLBoolean status; EGLint interval = 1; OpenGLView::m_renderMutex.lock(); 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; } /* rc = screen_get_window_property_iv(m_screen_win, SCREEN_PROPERTY_ROTATION, &rotation); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } rc = screen_get_window_property_iv(m_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } switch (angle - rotation) { case -270: case -90: case 90: case 270: temp = size[0]; size[0] = size[1]; size[1] = temp; skip = 0; break; } */ status = eglMakeCurrent(m_egl_disp, NULL, NULL, NULL); if (status != EGL_TRUE) { OpenGLThread::eglPrintError("eglMakeCurrent"); return EXIT_FAILURE; } status = eglDestroySurface(m_egl_disp, m_egl_surf); if (status != EGL_TRUE) { OpenGLThread::eglPrintError("eglMakeCurrent"); 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; } /* setWindowAngle(m_angle); if (returnCode) { perror("window angle"); return EXIT_FAILURE; } */ returnCode = setWindowSourceSize(m_width, m_height); if (returnCode) { perror("unable to set window source size"); return EXIT_FAILURE; } returnCode = setWindowBufferSize(m_width, m_height); if (returnCode) { perror("buffer size"); return EXIT_FAILURE; } 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(); status = eglSwapInterval(m_egl_disp, interval); if (status != EGL_TRUE) { OpenGLThread::eglPrintError("eglSwapInterval"); return EXIT_FAILURE; } OpenGLView::m_renderMutex.unlock(); setAltered(false); setStale(true); return EXIT_SUCCESS; }
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 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; }