int OpenGLView::calculateDPI() {
    int returnCode;
    int screen_phys_size[2];

	qDebug()  << "OpenGLView::calculateDPI: physical: "<< m_egl_disp;

    returnCode = screen_get_display_property_iv(m_screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size);
    if (returnCode) {
        perror("screen_get_display_property_iv");
        return EXIT_FAILURE;
    }

    //Simulator will return 0,0 for physical size of the screen, so use 170 as default dpi
    if ((screen_phys_size[0] == 0) && (screen_phys_size[1] == 0)) {
        return 170;
    } else {
        int screen_resolution[2];

        qDebug()  << "OpenGLView::calculateDPI: screen: "<< m_egl_disp;

        returnCode = screen_get_display_property_iv(m_screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
        if (returnCode) {
            perror("screen_get_display_property_iv");
            return EXIT_FAILURE;
        }

        int diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]);
        int diagontal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]);
        return (int)(diagonal_pixels / diagontal_inches);
    }
}
Ejemplo n.º 2
0
int bbutil_calculate_dpi(screen_context_t ctx) {
    int rc;
    int screen_phys_size[2];

    rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size);
    if (rc) {
        perror("screen_get_display_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    //Simulator will return 0,0 for physical size of the screen, so use 170 as default dpi
    if ((screen_phys_size[0] == 0) && (screen_phys_size[1] == 0)) {
        return 170;
    } else {
        int screen_resolution[2];
        rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
        if (rc) {
            perror("screen_get_display_property_iv");
            bbutil_terminate();
            return EXIT_FAILURE;
        }

        int diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]);
        int diagontal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]);
        return (int)(diagonal_pixels / diagontal_inches);
    }
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, int screenIndex)
    : mContext(context),
      mDisplay(display),
      mPosted(false),
      mUsingOpenGL(false),
      mPrimaryDisplay(screenIndex == 0),
      mKeyboardHeight(0),
      mScreenIndex(screenIndex),
      mCursor(new QBBCursor(this))
{
#if defined(QBBSCREEN_DEBUG)
    qDebug() << "QBBScreen::QBBScreen";
#endif

    // cache initial orientation of this display
    // TODO: use ORIENTATION environment variable?
    errno = 0;
    int result = screen_get_display_property_iv(mDisplay, SCREEN_PROPERTY_ROTATION, &mStartRotation);
    if (result != 0) {
        qFatal("QBBScreen: failed to query display rotation, errno=%d", errno);
    }

    mCurrentRotation = mStartRotation;

    // cache size of this display in pixels
    // TODO: use WIDTH and HEIGHT environment variables?
    errno = 0;
    int val[2];
    result = screen_get_display_property_iv(mDisplay, SCREEN_PROPERTY_SIZE, val);
    if (result != 0) {
        qFatal("QBBScreen: failed to query display size, errno=%d", errno);
    }

    mCurrentGeometry = mStartGeometry = QRect(0, 0, val[0], val[1]);

    // Cache size of this display in millimeters
    mStartPhysicalSize = determineScreenSize(mDisplay, mPrimaryDisplay);

    // swap physical dimensions when rotated orthogonally
    if (mStartRotation == 90 || mStartRotation == 270)
        mStartPhysicalSize.transpose();

    mCurrentPhysicalSize = mStartPhysicalSize;

    // We only create the root window if we are not the primary display.
    if (mPrimaryDisplay)
        mRootWindow = QSharedPointer<QBBRootWindow>(new QBBRootWindow(this));
}
Ejemplo n.º 5
0
ButtonMap::ButtonMap(screen_context_t screen_ctx, QString groupId, int coid)
{
   this->screen_cxt = screen_ctx;
   this->groupId = groupId;
   this->coid = coid;

   const int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_WRITE | SCREEN_USAGE_READ;
   int rc;

   if(screen_create_window_type(&screen_win, screen_cxt, SCREEN_CHILD_WINDOW))
   {
      RARCH_ERR("ButtonMap: screen_create_window_type failed.\n");
   }

   screen_join_window_group(screen_win, (const char *)groupId.toAscii().constData());
   int format = SCREEN_FORMAT_RGBA8888;
   screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);

   screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);

   screen_display_t screen_disp;
   if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp))
   {
      RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
   }

   if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
   }

   rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, screen_resolution);
   if (rc) {
      perror("screen_set_window_property_iv");
   }

   int z = -10;
   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0) {
      return;
   }

   rc = screen_create_window_buffers(screen_win, 1);
   if (rc) {
      perror("screen_create_window_buffers");
   }

   screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);

   int bg[] = { SCREEN_BLIT_COLOR, 0x00000000,
                SCREEN_BLIT_GLOBAL_ALPHA, 0x80,
                SCREEN_BLIT_END };
   screen_fill(screen_cxt, screen_buf, bg);

   screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);

   buttonDataModel = new ArrayDataModel();

   refreshButtonMap(0);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
QT_BEGIN_NAMESPACE

#if defined(QBB_PHYSICAL_SCREEN_WIDTH) && QBB_PHYSICAL_SCREEN_WIDTH > 0 \
    && defined(QBB_PHYSICAL_SCREEN_HEIGHT) && QBB_PHYSICAL_SCREEN_HEIGHT > 0
#define QBB_PHYSICAL_SCREEN_SIZE_DEFINED
#elif defined(QBB_PHYSICAL_SCREEN_WIDTH) || defined(QBB_PHYSICAL_SCREEN_HEIGHT)
#error Please define QBB_PHYSICAL_SCREEN_WIDTH and QBB_PHYSICAL_SCREEN_HEIGHT to values greater than zero
#endif

QT_BEGIN_NAMESPACE

static QSize determineScreenSize(screen_display_t display, bool primaryScreen)
{
    int val[2];

    errno = 0;
    const int result = screen_get_display_property_iv(display, SCREEN_PROPERTY_PHYSICAL_SIZE, val);
    if (result != 0) {
        qFatal("QBBScreen: failed to query display physical size, errno=%d", errno);
        return QSize(150, 90);
    }

    if (val[0] > 0 && val[1] > 0)
        return QSize(val[0], val[1]);

    qWarning("QBBScreen: screen_get_display_property_iv() reported an invalid physical screen size (%dx%d). Falling back to QBB_PHYSICAL_SCREEN_SIZE environment variable.", val[0], val[1]);

    const QString envPhySizeStr = qgetenv("QBB_PHYSICAL_SCREEN_SIZE");
    if (!envPhySizeStr.isEmpty()) {
        const QStringList envPhySizeStrList = envPhySizeStr.split(QLatin1Char(','));
        const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1;
        const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1;

        if (envWidth <= 0 || envHeight <= 0) {
            qFatal("QBBScreen: The value of QBB_PHYSICAL_SCREEN_SIZE must be in the format \"width,height\" in mm, with width, height > 0. Example: QBB_PHYSICAL_SCREEN_SIZE=150,90");
            return QSize(150, 90);
        }

        return QSize(envWidth, envHeight);
    }

#if defined(QBB_PHYSICAL_SCREEN_SIZE_DEFINED)
    const QSize defSize(QBB_PHYSICAL_SCREEN_WIDTH, QBB_PHYSICAL_SCREEN_HEIGHT);
    qWarning("QBBScreen: QBB_PHYSICAL_SCREEN_SIZE variable not set. Falling back to defines QBB_PHYSICAL_SCREEN_WIDTH/QBB_PHYSICAL_SCREEN_HEIGHT (%dx%d)", defSize.width(), defSize.height());
    return defSize;
#else
    if (primaryScreen)
        qFatal("QBBScreen: QBB_PHYSICAL_SCREEN_SIZE variable not set. Could not determine physical screen size.");
    return QSize(150, 90);
#endif
}
Ejemplo n.º 9
0
int NativeWindow::calculateDPI() {
    int returnCode;
    int screenPhysicalSize[2];
    int screenResolution[2];
    int diagonalPixels;
    int diagonalInches;

    returnCode = screen_get_display_property_iv(_screenDisplay, SCREEN_PROPERTY_PHYSICAL_SIZE, screenPhysicalSize);
    if (returnCode) {
        perror("screen_get_display_property_iv");
        return EXIT_FAILURE;
    }

	qDebug()  << "NativeWindow::calculateDPI: physical: "<< screenPhysicalSize[0] << " x " << screenPhysicalSize[1];

    //Simulator will return 0,0 for physical size of the screen, so use 170 as default dpi
    if ((screenPhysicalSize[0] == 0) && (screenPhysicalSize[1] == 0)) {
        qDebug()  << "NativeWindow::calculateDPI: DPI: 170 (default)";
        return 170;
    } else {
        returnCode = screen_get_display_property_iv(_screenDisplay, SCREEN_PROPERTY_SIZE, screenResolution);
        if (returnCode) {
            perror("screen_get_display_property_iv");
            return EXIT_FAILURE;
        }

        qDebug()  << "NativeWindow::calculateDPI: screen: "<< screenResolution[0] << " x " << screenResolution[1];

        diagonalPixels = sqrt(screenResolution[0] * screenResolution[0] + screenResolution[1] * screenResolution[1]);
        diagonalInches = 0.0393700787 * sqrt(screenPhysicalSize[0] * screenPhysicalSize[0] + screenPhysicalSize[1] * screenPhysicalSize[1]);
    }

    qDebug()  << "NativeWindow::calculateDPI: DPI: "<< (int)(diagonalPixels / diagonalInches);

    return (int)(diagonalPixels / diagonalInches);
}
Ejemplo n.º 10
0
static int dpi_get_density(qnx_ctx_data_t *qnx)
{
    int screen_dpi[2];

    if(!qnx)
        return -1;

    if (screen_get_display_property_iv(qnx->screen_disp,
             SCREEN_PROPERTY_DPI, screen_dpi))
    {
       RARCH_ERR("screen_get_display_property_iv [SCREEN_PROPERTY_DPI] failed.\n");
       return -1;
    }

    return min(screen_dpi[0], screen_dpi[1]);
}
Ejemplo n.º 11
0
QT_BEGIN_NAMESPACE

static QSize determineScreenSize(screen_display_t display, bool primaryScreen) {
    int val[2];

    const int result = screen_get_display_property_iv(display, SCREEN_PROPERTY_PHYSICAL_SIZE, val);
    Q_SCREEN_CHECKERROR(result, "Failed to query display physical size");
    if (result != 0) {
        return QSize(150, 90);
    }

    if (val[0] > 0 && val[1] > 0)
        return QSize(val[0], val[1]);

    qScreenDebug("QQnxScreen: screen_get_display_property_iv() reported an invalid "
                 "physical screen size (%dx%d). Falling back to QQNX_PHYSICAL_SCREEN_SIZE "
                 "environment variable.", val[0], val[1]);

    const QString envPhySizeStr = qgetenv("QQNX_PHYSICAL_SCREEN_SIZE");
    if (!envPhySizeStr.isEmpty()) {
        const QStringList envPhySizeStrList = envPhySizeStr.split(QLatin1Char(','));
        const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1;
        const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1;

        if (envWidth <= 0 || envHeight <= 0) {
            qFatal("QQnxScreen: The value of QQNX_PHYSICAL_SCREEN_SIZE must be in the format "
                   "\"width,height\" in mm, with width, height > 0. "
                   "Example: QQNX_PHYSICAL_SCREEN_SIZE=150,90");
            return QSize(150, 90);
        }

        return QSize(envWidth, envHeight);
    }

#if defined(QQNX_PHYSICAL_SCREEN_SIZE_DEFINED)
    const QSize defSize(QQNX_PHYSICAL_SCREEN_WIDTH, QQNX_PHYSICAL_SCREEN_HEIGHT);
    qWarning("QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. Falling back to defines "
             "QQNX_PHYSICAL_SCREEN_WIDTH/QQNX_PHYSICAL_SCREEN_HEIGHT (%dx%d)",
             defSize.width(), defSize.height());
    return defSize;
#else
    if (primaryScreen)
        qFatal("QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. "
               "Could not determine physical screen size.");
    return QSize(150, 90);
#endif
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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
}
Ejemplo n.º 14
0
void QQnxBpsEventFilter::registerForScreenEvents(QQnxScreen *screen)
{
    if (!m_screenEventHandler) {
        qWarning("QQNX: trying to register for screen events, but no handler provided.");
        return;
    }

    int attached;
    if (screen_get_display_property_iv(screen->nativeDisplay(), SCREEN_PROPERTY_ATTACHED, &attached) != BPS_SUCCESS) {
        qWarning() << "QQNX: unable to query display attachment";
        return;
    }

    if (!attached) {
        qBpsEventFilterDebug() << "skipping event registration for non-attached screen";
        return;
    }

    if (screen_request_events(screen->nativeContext()) != BPS_SUCCESS)
        qWarning("QQNX: failed to register for screen events on screen %p", screen->nativeContext());
}
Ejemplo n.º 15
0
void BlackberryMain::realiseDisplay(int idx) {
	const EGLint egl_surfaceAttr[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };
	int size[2] = { atoi(getenv("WIDTH")), atoi(getenv("HEIGHT")) };
	if (idx != 0)
		screen_get_display_property_iv(screen_dpy[idx], SCREEN_PROPERTY_SIZE, size);

	displays[idx].width = size[0];
	displays[idx].height = size[1];
	screen_set_window_property_iv(screen_win[idx], SCREEN_PROPERTY_BUFFER_SIZE, size);
	screen_create_window_buffers(screen_win[idx], 2); // Double buffered
	fprintf(stderr, "Display %i realised with %ix%i\n", idx, size[0], size[1]);

	egl_surf[idx] = eglCreateWindowSurface(egl_disp[idx], egl_conf, screen_win[idx], egl_surfaceAttr);

	// Only enable for devices with hardware QWERTY, 1:1 aspect ratio
	if ((pixel_xres == pixel_yres) && displays[idx].type != SCREEN_DISPLAY_TYPE_INTERNAL)
	{
		screen_emu = idx;
		if (emulating)
			switchDisplay(idx);
	}

	displays[idx].realised = true;
}
Ejemplo n.º 16
0
static void *gfx_ctx_qnx_init(video_frame_info_t *video_info, void *video_driver)
{
   EGLint n;
   EGLint major, minor;
   EGLint context_attributes[] = {
#ifdef HAVE_OPENGLES2
           EGL_CONTEXT_CLIENT_VERSION, 2,
#elif HAVE_OPENGLES3
           EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
      EGL_NONE
   };

   const EGLint attribs[] = {
#ifdef HAVE_OPENGLES2
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#elif HAVE_OPENGLES3
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
#endif
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_RED_SIZE, 8,
      EGL_NONE
   };

   qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)calloc(1, sizeof(*qnx));

   if (!qnx)
       goto screen_error;

   /* Create a screen context that will be used to
    * create an EGL surface to receive libscreen events */

   RARCH_LOG("Initializing screen context...\n");
   if (!screen_ctx)
   {
      screen_create_context(&screen_ctx, 0);

      if (screen_request_events(screen_ctx) != BPS_SUCCESS)
      {
         RARCH_ERR("screen_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_request_events(0) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_rotation_lock(false) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_location_lock failed.\n");
         goto screen_error;
      }
   }


#ifdef HAVE_EGL
   if (!egl_init_context(&qnx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor,
            &n, attribs))
   {
      egl_report_error();
      goto error;
   }

   if (!egl_create_context(&qnx->egl, context_attributes))
   {
      egl_report_error();
      goto error;
   }
#endif

   if(!screen_win)
   {
      if (screen_create_window(&screen_win, screen_ctx))
      {
             RARCH_ERR("screen_create_window failed:.\n");
	     goto error;
      }
   }

   int format = SCREEN_FORMAT_RGBX8888;
   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_FORMAT, &format))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
      goto error;
   }

   int usage;
#ifdef HAVE_OPENGLES2
   usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
#elif HAVE_OPENGLES3
   usage = SCREEN_USAGE_OPENGL_ES3 | SCREEN_USAGE_ROTATION;
#endif
   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_USAGE, &usage))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_pv(screen_win,
            SCREEN_PROPERTY_DISPLAY, (void **)&qnx->screen_disp))
   {
      RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
      goto error;
   }

   int screen_resolution[2];

   if (screen_get_display_property_iv(qnx->screen_disp,
            SCREEN_PROPERTY_SIZE, screen_resolution))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
      goto error;
   }

#ifndef HAVE_BB10
   int angle, size[2];

   angle = atoi(getenv("ORIENTATION"));

   screen_display_mode_t screen_mode;
   if (screen_get_display_property_pv(qnx->screen_disp,
            SCREEN_PROPERTY_MODE, (void**)&screen_mode))
   {
      RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_iv(screen_win,
            SCREEN_PROPERTY_BUFFER_SIZE, size))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180))
   {
      if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
      {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   }
   else if ((angle == 90) || (angle == 270))
   {
      if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height && size[0] < size[1])))
      {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   }
   else
   {
      RARCH_ERR("Navigator returned an unexpected orientation angle.\n");
      goto error;
   }


   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_ROTATION, &angle))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
      goto error;
   }
#endif

   if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS))
   {
      RARCH_ERR("screen_create_window_buffers failed.\n");
      goto error;
   }

   if (!egl_create_surface(&qnx->egl, screen_win))
      goto error;

   return qnx;

error:
   RARCH_ERR("EGL error: %d.\n", eglGetError());
   gfx_ctx_qnx_destroy(video_driver);
screen_error:
   screen_stop_events(screen_ctx);
   return NULL;
}
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;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
void BlackberryMain::handleInput(screen_event_t screen_event)
{
	TouchInput input;
	KeyInput key;
	int val, buttons, pointerId;
	int pair[2];
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &val);
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pair);

	input_state.mouse_valid = true;
	switch(val)
	{
	// Touchscreen
	case SCREEN_EVENT_MTOUCH_TOUCH:
	case SCREEN_EVENT_MTOUCH_RELEASE: 	// Up, down
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId);
		input_state.pointer_down[pointerId] = (val == SCREEN_EVENT_MTOUCH_TOUCH);
		input_state.pointer_x[pointerId] = pair[0] * g_dpi_scale;
		input_state.pointer_y[pointerId] = pair[1] * g_dpi_scale;

		input.x = pair[0] * g_dpi_scale;
		input.y = pair[1] * g_dpi_scale;
		input.flags = (val == SCREEN_EVENT_MTOUCH_TOUCH) ? TOUCH_DOWN : TOUCH_UP;
		input.id = pointerId;
		NativeTouch(input);
		break;
	case SCREEN_EVENT_MTOUCH_MOVE:
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId);
		input_state.pointer_x[pointerId] = pair[0] * g_dpi_scale;
		input_state.pointer_y[pointerId] = pair[1] * g_dpi_scale;

		input.x = pair[0] * g_dpi_scale;
		input.y = pair[1] * g_dpi_scale;
		input.flags = TOUCH_MOVE;
		input.id = pointerId;
		NativeTouch(input);
		break;
	// Mouse, Simulator
	case SCREEN_EVENT_POINTER:
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &buttons);
		if (buttons == SCREEN_LEFT_MOUSE_BUTTON) { // Down
			input_state.pointer_x[0] = pair[0] * g_dpi_scale;
			input_state.pointer_y[0] = pair[1] * g_dpi_scale;
			input_state.pointer_down[0] = true;

			input.x = pair[0] * g_dpi_scale;
			input.y = pair[1] * g_dpi_scale;
			input.flags = TOUCH_DOWN;
			input.id = 0;
			NativeTouch(input);
		} else if (input_state.pointer_down[0]) {	// Up
			input_state.pointer_x[0] = pair[0] * g_dpi_scale;
			input_state.pointer_y[0] = pair[1] * g_dpi_scale;
			input_state.pointer_down[0] = false;

			input.x = pair[0] * g_dpi_scale;
			input.y = pair[1] * g_dpi_scale;
			input.flags = TOUCH_UP;
			input.id = 0;
			NativeTouch(input);
		}
		break;
	// Keyboard
	case SCREEN_EVENT_KEYBOARD:
		int flags, value;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &value);
		NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawBlackberrytoNative.find(value)->second, (flags & KEY_DOWN) ? KEY_DOWN : KEY_UP));
		break;
	// Gamepad
	case SCREEN_EVENT_GAMEPAD:
	case SCREEN_EVENT_JOYSTICK:
		int analog0[3];
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &buttons);
		for (int i = 0; i < 32; i++) {
			int mask = 1 << i;
			if ((old_buttons & mask) != (buttons & mask))
				NativeKey(KeyInput(DEVICE_ID_PAD_0, KeyMapPadBlackberrytoNative.find(mask)->second, (buttons & mask) ? KEY_DOWN : KEY_UP));
		}
		if (!screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG0, analog0)) {
			for (int i = 0; i < 2; i++) {
				AxisInput axis;
				axis.axisId = JOYSTICK_AXIS_X + i;
				// 1.2 to try to approximate the PSP's clamped rectangular range.
				axis.value = 1.2 * analog0[i] / 128.0f;
				if (axis.value > 1.0f) axis.value = 1.0f;
				if (axis.value < -1.0f) axis.value = -1.0f;
				axis.deviceId = DEVICE_ID_PAD_0;
				axis.flags = 0;
				NativeAxis(axis);
			}
		}
		old_buttons = buttons;
		break;
	case SCREEN_EVENT_DISPLAY:
		screen_display_t new_dpy = NULL;
		screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DISPLAY, (void **)&new_dpy);
		for (int i = 0; i < ndisplays; i++) {
			if (new_dpy != screen_dpy[i])
				continue;
			int active = 0;
			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &active);
			if (active) {
				int size[2];
				screen_get_display_property_iv(screen_dpy[i], SCREEN_PROPERTY_SIZE, size);
				if (size[0] == 0 || size[1] == 0)
					active = 0;
			}
			if (active && !displays[i].attached)
				realiseDisplay(i);
			else if (!active && displays[i].attached && displays[i].realised)
				unrealiseDisplay(i);
			displays[i].attached = active;
		}
		break;
	}
}
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
// Entry Point
int main(int argc, char *argv[]) {
	static screen_context_t screen_cxt;
	// Receive events from window manager
	screen_create_context(&screen_cxt, 0);
	//Initialise Blackberry Platform Services
	bps_initialize();

	net::Init();
	init_GLES2(screen_cxt);
#ifdef BLACKBERRY10
	// Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale
	int dpi;
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi);
#else
	// Playbook: 1024x600, 7", 170DPI, 1.25f scale
	int screen_phys_size[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size);
	int screen_resolution[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
	double diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]);
    double diagonal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]);
	int dpi = (int)(diagonal_pixels / diagonal_inches + 0.5);
#endif
	float dpi_scale = 213.6f / dpi;
	dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale);

	NativeInit(argc, (const char **)argv, "data/", "/accounts/1000/shared", "BADCOFFEE");
	NativeInitGraphics();
	screen_request_events(screen_cxt);
	navigator_request_events(0);
	dialog_request_events(0);
#ifdef BLACKBERRY10
	vibration_request_events(0);
#endif
	BlackberryAudio* audio = new BlackberryAudio();
	InputState input_state;
	bool running = true;
	while (running) {
		input_state.mouse_valid = false;
		input_state.accelerometer_valid = false;
		SimulateGamepad(&input_state);
		while (true) {
			// Handle Blackberry events
			bps_event_t *event = NULL;
			bps_get_event(&event, 0);
			if (event == NULL)
				break; // Ran out of events
			int domain = bps_event_get_domain(event);
			if (domain == screen_get_domain()) {
				int screen_val, buttons, pointerId;
				int pair[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_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pair);
				screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId);

				input_state.mouse_valid = true;
				switch(screen_val)
				{
				// Touchscreen
				case SCREEN_EVENT_MTOUCH_TOUCH:
				case SCREEN_EVENT_MTOUCH_RELEASE: 	// Up, down
					input_state.pointer_down[pointerId] = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
				case SCREEN_EVENT_MTOUCH_MOVE:
					input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
					input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
					break;
				// Mouse, Simulator
    			case SCREEN_EVENT_POINTER:
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
						&buttons);
					if (buttons == SCREEN_LEFT_MOUSE_BUTTON) { 			// Down
						input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
						input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
						input_state.pointer_down[pointerId] = true;
					} else if (input_state.pointer_down[pointerId]) {	// Up
						input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
						input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
						input_state.pointer_down[pointerId] = false;
					}
					break;
				// Keyboard
				case SCREEN_EVENT_KEYBOARD:
					int flags, value;
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &value);
					if (flags & (KEY_DOWN | KEY_SYM_VALID)) {
						for (int b = 0; b < 14; b++) {
							if (value == buttonMappings[b])
								input_state.pad_buttons |= (1<<b);
						}
					}
					break;
				}
			} else if (domain == navigator_get_domain()) {
				switch(bps_event_get_code(event))
				{
				case NAVIGATOR_BACK:
				case NAVIGATOR_SWIPE_DOWN:
					input_state.pad_buttons |= PAD_BUTTON_MENU;
					break;
				case NAVIGATOR_EXIT:
					running = false;
					break;
				}
			}
		}
		UpdateInputState(&input_state);
		NativeUpdate(input_state);
		EndInputState(&input_state);
		NativeRender();
		// On Blackberry, this handles VSync for us
		eglSwapBuffers(egl_disp, egl_surf);
	}

	screen_stop_events(screen_cxt);
	bps_shutdown();

	NativeShutdownGraphics();
	delete audio;
	NativeShutdown();
	kill_GLES2();
	net::Shutdown();
	screen_destroy_context(screen_cxt);
	exit(0);
	return 0;
}
Ejemplo n.º 23
0
// Video
int init_GLES2(screen_context_t ctx) {
	int usage = SCREEN_USAGE_ROTATION | SCREEN_USAGE_OPENGL_ES2;
	int format = SCREEN_FORMAT_RGBX8888;
	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 };
	const EGLint egl_surfaceAttr[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };

	screen_ctx = ctx;
	screen_create_window(&screen_win, screen_ctx);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
	screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);

	// This must be landscape.
	int screen_resolution[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
	int angle = atoi(getenv("ORIENTATION"));
	pixel_xres = screen_resolution[0]; pixel_yres = screen_resolution[1];

	screen_display_mode_t screen_mode;
	screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);

	int size[2];
	screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);

	int buffer_size[2] = {size[0], size[1]};

	if ((angle == 0) || (angle == 180)) {
		if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
		((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
			buffer_size[1] = size[0];
			buffer_size[0] = size[1];
			pixel_yres = screen_resolution[0];
			pixel_xres = screen_resolution[1];
		}
	} else if ((angle == 90) || (angle == 270)){
		if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
		((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
			buffer_size[1] = size[0];
			buffer_size[0] = size[1];
			pixel_yres = screen_resolution[0];
			pixel_xres = screen_resolution[1];
		}
	}
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);

	screen_create_window_buffers(screen_win, 2); // Double buffered
	egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(egl_disp, NULL, NULL);

	eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs);
	egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes);

	egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, egl_surfaceAttr);

	eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx);
	eglSwapInterval(egl_disp, 1);

	return 0;
}
bool CIrrDeviceBB10::createWindow()
{
	if ( Close )
		return false;

	int rc = screen_create_window(&bspScreenWindow, bspScreenCtx);
	if(rc)
	{
		os::Printer::log("Screen create window failed!");
		return false;
	}

	if(video::EDT_OGLES1 != CreationParams.DriverType && video::EDT_OGLES2 !=CreationParams.DriverType)
		return false;

	bspformat = SCREEN_FORMAT_RGBX8888;
	if(CreationParams.Bits==16)
		bspformat = SCREEN_FORMAT_RGBX4444;

	bspUsage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
	if(video::EDT_OGLES2 ==CreationParams.DriverType)
		bspUsage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;

	//window properties
	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_FORMAT, &bspformat);

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_USAGE, &bspUsage);

	screen_display_t screenDisplay;
	rc = screen_get_window_property_pv(bspScreenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screenDisplay);

	int screenResolution[2];
	rc = screen_get_display_property_iv(screenDisplay, SCREEN_PROPERTY_SIZE, screenResolution);

	int angle = atoi(getenv("ORIENTATION"));

	screen_display_mode_t screenDisplayMode;
	rc = screen_get_display_property_pv(screenDisplay, SCREEN_PROPERTY_MODE, (void**)&screenDisplayMode);

	int bufferSize[2];
	rc = screen_get_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_BUFFER_SIZE, bufferSize);

	int newBufferSize[2] = {bufferSize[0], bufferSize[1]};
	if ((angle == 0) || (angle == 180)) 
	{
		if (((screenDisplayMode.width > screenDisplayMode.height) && (bufferSize[0] < bufferSize[1])) 
			|| ((screenDisplayMode.width < screenDisplayMode.height) && (bufferSize[0] > bufferSize[1])))
		{
			newBufferSize[1] = bufferSize[0];
			newBufferSize[0] = bufferSize[1];
		}
	}
	else if ((angle == 90) || (angle == 270))
	{
		if (((screenDisplayMode.width > screenDisplayMode.height) && (bufferSize[0] > bufferSize[1]))
			|| ((screenDisplayMode.width < screenDisplayMode.height && bufferSize[0] < bufferSize[1]))) 
		{
			newBufferSize[1] = bufferSize[0];
			newBufferSize[0] = bufferSize[1];
		}
	} 
	else
	{
		os::Printer::log("Navigator returned an unexpected orientation angle.\n");
		return false;
	}

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_BUFFER_SIZE, newBufferSize);

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_ROTATION, &angle);

	rc = screen_create_window_buffers(bspScreenWindow, 2);
	return true;
}
Ejemplo n.º 25
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;
}
Ejemplo n.º 26
0
int
bbutil_init_egl(screen_context_t ctx) {
    int usage;
    int format = SCREEN_FORMAT_RGBX8888;
    EGLint interval = 1;
    int rc, num_configs;

    EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                            EGL_GREEN_SIZE,      8,
                            EGL_BLUE_SIZE,       8,
                            EGL_ALPHA_SIZE,       8,
                            EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
                            EGL_DEPTH_SIZE, 24,
                            EGL_NONE};

#ifdef USING_GL11
    usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
    attrib_list[9] = EGL_OPENGL_ES_BIT;
#elif defined(USING_GL20)
    usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
    //attrib_list[9] = EGL_OPENGL_ES2_BIT;
    EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
#else
    fprintf(stderr, "bbutil should be compiled with either USING_GL11 or USING_GL20 -D flags\n");
    return EXIT_FAILURE;
#endif

    //Simple egl initialization
    screen_cxt = ctx;

    egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (egl_disp == EGL_NO_DISPLAY) {
        bbutil_egl_perror("eglGetDisplay");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglInitialize(egl_disp, NULL, NULL);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglInitialize");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglBindAPI(EGL_OPENGL_ES_API);

    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglBindApi");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    if(!eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs)) {
        bbutil_terminate();
        return EXIT_FAILURE;
    }

#ifdef USING_GL20
        egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes);
#elif defined(USING_GL11)
        egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, NULL);
#endif

    if (egl_ctx == EGL_NO_CONTEXT) {
        bbutil_egl_perror("eglCreateContext");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_create_window(&screen_win, screen_cxt);
    if (rc) {
        perror("screen_create_window");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);
    if (rc) {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
    if (rc) {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);
    if (rc) {
        perror("screen_get_window_property_pv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    int screen_resolution[2];

    rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
    if (rc) {
        perror("screen_get_display_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    int angle = atoi(getenv("ORIENTATION"));

    screen_display_mode_t screen_mode;
    rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
    if (rc) {
        perror("screen_get_display_property_pv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    int size[2];
    rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
    if (rc) {
        perror("screen_get_window_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    int buffer_size[2] = {size[0], size[1]};

    if ((angle == 0) || (angle == 180)) {
        if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
                buffer_size[1] = size[0];
                buffer_size[0] = size[1];
        }
    } else if ((angle == 90) || (angle == 270)){
        if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
                buffer_size[1] = size[0];
                buffer_size[0] = size[1];
        }
    } else {
         fprintf(stderr, "Navigator returned an unexpected orientation angle.\n");
         bbutil_terminate();
         return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
    if (rc) {
        perror("screen_set_window_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
    if (rc) {
        perror("screen_set_window_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_create_window_buffers(screen_win, nbuffers);
    if (rc) {
        perror("screen_create_window_buffers");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, NULL);
    if (egl_surf == EGL_NO_SURFACE) {
        bbutil_egl_perror("eglCreateWindowSurface");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglMakeCurrent");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglSwapInterval(egl_disp, interval);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglSwapInterval");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    initialized = 1;

    return EXIT_SUCCESS;
}
Ejemplo n.º 27
0
static bool gfx_ctx_qnx_init(void *data)
{
   /* Create a screen context that will be used to 
    * create an EGL surface to receive libscreen events */

   RARCH_LOG("Initializing screen context...\n");
   if (!screen_ctx)
   {
      screen_create_context(&screen_ctx, 0);

      if (screen_request_events(screen_ctx) != BPS_SUCCESS)
      {
         RARCH_ERR("screen_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_request_events(0) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_rotation_lock(false) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_location_lock failed.\n");
         goto screen_error;
      }
   }

   const EGLint attribs[] = {
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_RED_SIZE, 8,
      EGL_NONE
   };
   EGLint num_config;
   EGLint egl_version_major, egl_version_minor;
   int format = SCREEN_FORMAT_RGBX8888;

   EGLint context_attributes[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };
   int usage;

   usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;

   RARCH_LOG("Initializing context\n");

   if ((g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY)
   {
      RARCH_ERR("eglGetDisplay failed.\n");
      goto error;
   }

   if (!eglInitialize(g_egl_dpy, &egl_version_major, &egl_version_minor))
   {
      RARCH_ERR("eglInitialize failed.\n");
      goto error;
   }

   if (!eglBindAPI(EGL_OPENGL_ES_API))
   {
      RARCH_ERR("eglBindAPI failed.\n");
      goto error;
   }

   RARCH_LOG("[BLACKBERRY QNX/EGL]: EGL version: %d.%d\n", egl_version_major, egl_version_minor);

   if (!eglChooseConfig(g_egl_dpy, attribs, &egl_config, 1, &num_config))
   {
      RARCH_ERR("eglChooseConfig failed.\n");
      goto error;
   }

   if ((g_egl_ctx = eglCreateContext(g_egl_dpy, egl_config, 0, context_attributes)) == EGL_NO_CONTEXT)
   {
      RARCH_ERR("eglCreateContext failed.\n");
      goto error;
   }

   if(!screen_win)
   {
      if (screen_create_window(&screen_win, screen_ctx))
      {
	     RARCH_ERR("screen_create_window failed:.\n");
	     goto error;
      }
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp))
   {
      RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
      goto error;
   }

   int screen_resolution[2];

   if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
      goto error;
   }

#ifndef HAVE_BB10
   int angle = atoi(getenv("ORIENTATION"));

   screen_display_mode_t screen_mode;
   if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode))
   {
      RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
      goto error;
   }

   int size[2];
   if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180)) {
      if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   } else if ((angle == 90) || (angle == 270)){
      if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   } else {
      RARCH_ERR("Navigator returned an unexpected orientation angle.\n");
      goto error;
   }


   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
      goto error;
   }
#endif

   if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS))
   {
      RARCH_ERR("screen_create_window_buffers failed.\n");
      goto error;
   }

   if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, egl_config, screen_win, 0)))
   {
      RARCH_ERR("eglCreateWindowSurface failed.\n");
      goto error;
   }


   if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx))
   {
      RARCH_ERR("eglMakeCurrent failed.\n");
      goto error;
   }

   return true;

error:
   RARCH_ERR("EGL error: %d.\n", eglGetError());
   gfx_ctx_qnx_destroy(data);
screen_error:
   screen_stop_events(screen_ctx);
   return false;
}
Ejemplo n.º 28
0
bool Game::InitDisplay()
{
   /*
   * Here specify the attributes of the desired configuration.
   * Below, we select an EGLConfig with at least 8 bits per color
   * component compatible with on-screen windows
   */
   const EGLint attribs[] =
   {
      EGL_RED_SIZE,        8,
      EGL_GREEN_SIZE,      8,
      EGL_BLUE_SIZE,       8,
      EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
      EGL_DEPTH_SIZE,      24,
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //Maybe EGL_CONFORMANT for windows and Android?
      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, 0,
                           EGL_NONE};

   EGLint w, h, format;
   EGLint numConfigs;
   EGLConfig config[64];
   EGLSurface surface;
   EGLContext context;

   EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

   int maj;
   int min;
   eglInitialize(display, &maj, &min);
   Log::Debug("EGLInitialise", "EGL Major:%d Minor:%d", maj, min);

   /* Here, the application chooses the configuration it desires. In this
   * sample, we have a very simplified selection process, where we pick
   * the first EGLConfig that matches our criteria */
   eglChooseConfig(display, attribs, &config[0], 64, &numConfigs);

   for(int i = 0; i < numConfigs; i++)
   {
      int val[1];
      eglGetConfigAttrib(display, config[i], EGL_CONFORMANT, &val[0]);
      Log::Debug("EGLInitialise", "EGL_CONFORMANT: %d", val[0]);
      Log::Debug("EGLInitialise", "GL2: %d", val[0] & EGL_OPENGL_ES2_BIT);
      Log::Debug("EGLInitialise", "GL1: %d", val[0] & EGL_OPENGL_ES_BIT);
   }

   if(numConfigs == 0)
   {
      Log::Error("EGLInitialise", "No EGL configs were returned.");
      return true;
   }

   /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
   * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
   * As soon as we picked a EGLConfig, we can safely reconfigure the
   * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
   eglGetConfigAttrib(display, config[0], EGL_NATIVE_VISUAL_ID, &format);

#ifdef ANDROID
   ANativeWindow_setBuffersGeometry(mDisplay.app->window, 0, 0, format); //TODO!
   surface = eglCreateWindowSurface(display, config[0], mDisplay.app->window, NULL);
#endif
#ifdef _WIN32
   mDisplay.WindowHandle = create_window(mDisplay.Width, mDisplay.Height);
   surface = EGL_CHECK(eglCreateWindowSurface(display, config[0], (EGLNativeWindowType)mDisplay.WindowHandle, NULL));
#endif
#ifdef __QNX__
   int screen_format = SCREEN_FORMAT_RGBX8888;
   int usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
   int screen_resolution[2];
   screen_display_mode_t screen_mode;
   int size[2];
   int angle = std::atoi(std::getenv("ORIENTATION"));

   screen_create_window(&mDisplay.qnx_screen_win, mDisplay.qnx_screen_context);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_FORMAT, &screen_format);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_USAGE, &usage);
   screen_get_window_property_pv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&mDisplay.qnx_screen_disp);
   screen_get_display_property_iv(mDisplay.qnx_screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
   screen_get_display_property_pv(mDisplay.qnx_screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
   screen_get_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180)) {
       if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
           ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
               buffer_size[1] = size[0];
               buffer_size[0] = size[1];
       }
   } else if ((angle == 90) || (angle == 270)){
       if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
           ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
               buffer_size[1] = size[0];
               buffer_size[0] = size[1];
       }
   } else {
        return true;
   }

   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_ROTATION, &angle);
   screen_create_window_buffers(mDisplay.qnx_screen_win, 2);

   surface = EGL_CHECK(eglCreateWindowSurface(display, config[0], (EGLNativeWindowType)mDisplay.qnx_screen_win, NULL));
#endif

   if(surface == EGL_NO_SURFACE) {
      Log::Error("EGLInitialise", "EGL Surface creation failed.");
      return true;
   }

   const EGLint attribs2[] =
   {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };
   context = eglCreateContext(display, config[0], NULL, attribs2);

   if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
      Log::Error("EGLInitialise", "Unable to eglMakeCurrent");
      return true;
   }

#ifdef __QNX__
   eglSwapInterval(display, 1);
#endif

   eglQuerySurface(display, surface, EGL_WIDTH, &w);
   eglQuerySurface(display, surface, EGL_HEIGHT, &h);

   mDisplay.Display = display;
   mDisplay.Context = context;
   mDisplay.Surface = surface;
   mDisplay.Width = w;
   mDisplay.Height = h;
   mTP->camera->SetResolution(Vector2f((float)mDisplay.Width, (float)mDisplay.Height));

   // Initialize GL state.
   GL_CHECK(glViewport(0, 0, w, h));
   GL_CHECK(glEnable(GL_DEPTH_TEST));
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   GL_CHECK(glEnable(GL_BLEND));
   GL_CHECK(glEnable(GL_ALPHA));


   Effect::CacheTick(*mTP, EffectClearLevel::Initialise);
   Texture::CacheTick(*mTP, TextureClearLevel::Initialise);
   Font::CacheTick(*mTP, FontClearLevel::Initialise);
   //Initialise graphics
   for(std::vector<GameObject*>::iterator it = mGO.begin(); it != mGO.end(); ++it)
   {
      (*it)->InitialiseGraphics(*mTP);
   }

   return false;
}
Ejemplo n.º 29
0
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);
}