Beispiel #1
0
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);
}
Beispiel #2
0
int _glfwPlatformCreateWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig,
                              const _GLFWctxconfig* ctxconfig,
                              const _GLFWfbconfig* fbconfig)
{
    int rc;
    int nbuffers = fbconfig->doublebuffer ? 2 : 1;
    int format = SCREEN_FORMAT_RGBX8888; // TODO: check fbconfig
    int usage = SCREEN_USAGE_OPENGL_ES2|SCREEN_USAGE_OVERLAY; // TODO: check context config
    int size[2] = { wndconfig->width, wndconfig->height };
    int pos[2] = { 0, 0 };
    int interval = 1;

    if (!_glfwCreateContext(window, ctxconfig, fbconfig))
        return GL_FALSE;

    rc = screen_create_window(&window->screen.window, _glfw.screen.context);
    if (rc)
    {
    	_glfwInputError(GLFW_PLATFORM_ERROR,
    	                    "screen: Error creating window %s", strerror(errno));
    	return GL_FALSE;
    }

    if (wndconfig->monitor)
    {
    	rc = screen_set_window_property_pv(window->screen.window, SCREEN_PROPERTY_DISPLAY, (void**)&wndconfig->monitor->screen.display);
    	if (rc)
    	{
    		_glfwInputError(GLFW_PLATFORM_ERROR,
    	                    "screen: Error set window property %s", strerror(errno));
    		return GL_FALSE;
    	}
    }

    rc = screen_set_window_property_iv(window->screen.window, SCREEN_PROPERTY_FORMAT, &format);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to set format property: %s", strerror(errno)); return GL_FALSE; }
    rc = screen_set_window_property_iv(window->screen.window, SCREEN_PROPERTY_USAGE, &usage);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to set usage property: %s", strerror(errno)); return GL_FALSE; }
    rc = screen_set_window_property_iv(window->screen.window, SCREEN_PROPERTY_SWAP_INTERVAL, &interval);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to set swap interval property: %s", strerror(errno)); return GL_FALSE; }
    rc = screen_set_window_property_iv(window->screen.window, SCREEN_PROPERTY_SIZE, size);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to set size property: %s", strerror(errno)); return GL_FALSE; }
    rc = screen_set_window_property_iv(window->screen.window, SCREEN_PROPERTY_POSITION, pos);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to set position property: %s", strerror(errno)); return GL_FALSE; }
    rc = screen_create_window_buffers(window->screen.window, nbuffers);
    if (rc) { _glfwInputError(GLFW_PLATFORM_ERROR, "screen: Failed to create window buffers: %s", strerror(errno)); return GL_FALSE; }

    return GL_TRUE;
}
Beispiel #3
0
void QQnxWindow::setScreen(QQnxScreen *platformScreen)
{
    qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "platformScreen =" << platformScreen;

    if (platformScreen == 0) { // The screen has been destroyed
        m_screen = 0;
        return;
    }

    if (m_screen == platformScreen)
        return;

    if (m_screen)
        m_screen->removeWindow(this);
    platformScreen->addWindow(this);
    m_screen = platformScreen;

    // Move window to proper screen/display
    errno = 0;
    screen_display_t display = platformScreen->nativeDisplay();
    int result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display);
    if (result != 0)
        qFatal("QQnxWindow: failed to set window display, errno=%d", errno);

    // Add window to display's window group
    errno = 0;
    result = screen_join_window_group(m_window, platformScreen->windowGroupName());
    if (result != 0)
        qFatal("QQnxWindow: failed to join window group, errno=%d", errno);

    Q_FOREACH (QQnxWindow *childWindow, m_childWindows) {
        // Only subwindows and tooltips need necessarily be moved to another display with the window.
        if ((window()->type() & Qt::WindowType_Mask) == Qt::SubWindow ||
                (window()->type() & Qt::WindowType_Mask) == Qt::ToolTip)
            childWindow->setScreen(platformScreen);
    }

    m_screen->updateHierarchy();
}
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;
}
Beispiel #5
0
QQnxRootWindow::QQnxRootWindow(const QQnxScreen *screen)
    : m_screen(screen),
      m_window(0),
      m_windowGroupName(),
      m_translucent(false)
{
    qRootWindowDebug() << Q_FUNC_INFO;
    // Create one top-level QNX window to act as a container for child windows
    // since navigator only supports one application window
    errno = 0;
    int result = screen_create_window(&m_window, m_screen->nativeContext());
    int val[2];
    if (result != 0)
        qFatal("QQnxRootWindow: failed to create window, errno=%d", errno);

    // Move window to proper display
    errno = 0;
    screen_display_t display = m_screen->nativeDisplay();
    result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window display, errno=%d", errno);

    // Make sure window is above navigator but below keyboard if running as root
    // since navigator won't automatically set our z-order in this case
    if (getuid() == 0) {
        errno = 0;
        val[0] = MAGIC_ZORDER_FOR_NO_NAV;
        result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, val);
        if (result != 0)
            qFatal("QQnxRootWindow: failed to set window z-order, errno=%d", errno);
    }

    // Window won't be visible unless it has some buffers so make one dummy buffer that is 1x1
    errno = 0;
    val[0] = SCREEN_USAGE_NATIVE;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window buffer usage, errno=%d", errno);

    errno = 0;
    val[0] = m_screen->nativeFormat();
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window pixel format, errno=%d", errno);

    errno = 0;
    val[0] = 1;
    val[1] = 1;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window buffer size, errno=%d", errno);

    errno = 0;
    result = screen_create_window_buffers(m_window, 1);
    if (result != 0)
        qFatal("QQNX: failed to create window buffer, errno=%d", errno);

    // Window is always the size of the display
    errno = 0;
    QRect geometry = m_screen->geometry();
    val[0] = geometry.width();
    val[1] = geometry.height();
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window size, errno=%d", errno);

    // Fill the window with solid black. Note that the LSB of the pixel value
    // 0x00000000 just happens to be 0x00, so if and when this root window's
    // alpha blending mode is changed from None to Source-Over, it will then
    // be interpreted as transparent.
    errno = 0;
    val[0] = 0;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_COLOR, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window colour, errno=%d", errno);

    // Make the window opaque
    errno = 0;
    val[0] = SCREEN_TRANSPARENCY_NONE;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window transparency, errno=%d", errno);

    // Set the swap interval to 1
    errno = 0;
    val[0] = 1;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window swap interval, errno=%d", errno);

    // Set viewport size equal to window size but move outside buffer so the fill colour is used exclusively
    errno = 0;
    val[0] = geometry.width();
    val[1] = geometry.height();
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window source size, errno=%d", errno);

    errno = 0;
    val[0] = 0;
    val[1] = 0;
    result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_POSITION, val);
    if (result != 0)
        qFatal("QQnxRootWindow: failed to set window source position, errno=%d", errno);

    // Optionally disable the screen power save
    bool ok = false;
    const int disablePowerSave = qgetenv("QQNX_DISABLE_POWER_SAVE").toInt(&ok);
    if (ok && disablePowerSave) {
        const int mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
        result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_IDLE_MODE, &mode);
        if (result != 0)
            qWarning("QQnxRootWindow: failed to disable power saving mode");
    }

    createWindowGroup();

    // Don't post yet. This will be lazily done from QQnxScreen upon first posting of
    // a child window. Doing it now pre-emptively would create a flicker if one of
    // the QWindow's about to be created sets its Qt::WA_TranslucentBackground flag
    // and immediately triggers the buffer re-creation in makeTranslucent().
}
Beispiel #6
0
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;
}