void XCompositeEglClientBufferIntegration::initializeHardware(QtWayland::Display *) { QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); if (nativeInterface) { mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForIntegration("Display")); if (!mDisplay) qFatal("could not retrieve Display from platform integration"); mEglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForIntegration("EGLDisplay")); if (!mEglDisplay) qFatal("could not retrieve EGLDisplay from platform integration"); } else { qFatal("Platform integration doesn't have native interface"); } mScreen = XDefaultScreen(mDisplay); new XCompositeHandler(m_compositor->handle(), mDisplay); }
VibroWorker::VibroWorker () : last_is_alarm (false), last_vibration_looped (false), mCancel (NULL), mVibrate (NULL), mVibratePattern (NULL), objVibrator (NULL) { QPlatformNativeInterface *interface = QApplication::platformNativeInterface (); jobject objActivity = (jobject) interface->nativeResourceForIntegration ("QtActivity"); jclass classActivity = jni_env->FindClass ("android/app/Activity"); if (objActivity && classActivity) { jmethodID mSystemService = jni_env->GetMethodID (classActivity, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); jstring strMethod = jni_env->NewStringUTF ("vibrator"); if (mSystemService && strMethod) objVibrator = jni_env->CallObjectMethod (objActivity, mSystemService, strMethod); if (objVibrator) { jclass classVibrator = jni_env->GetObjectClass (objVibrator); if (classVibrator) { mCancel = jni_env->GetMethodID (classVibrator, "cancel", "()V"); mVibrate = jni_env->GetMethodID (classVibrator, "vibrate", "(J)V"); mVibratePattern = jni_env->GetMethodID (classVibrator, "vibrate", "([JI)V"); } } } cancel_vibration_timer.setSingleShot (true); connect (&cancel_vibration_timer, SIGNAL (timeout ()), this, SLOT (cancelLoopedVibration ())); }
void GVRInterface::enterVRMode() { #if defined(ANDROID) && defined(HAVE_LIBOVR) // Default vrModeParms ovrModeParms vrModeParms; vrModeParms.AsynchronousTimeWarp = true; vrModeParms.AllowPowerSave = true; vrModeParms.DistortionFileName = NULL; vrModeParms.EnableImageServer = false; vrModeParms.CpuLevel = 2; vrModeParms.GpuLevel = 2; vrModeParms.GameThreadTid = 0; QAndroidJniEnvironment jniEnv; QPlatformNativeInterface* interface = QApplication::platformNativeInterface(); jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity"); vrModeParms.ActivityObject = activity; ovrHmdInfo hmdInfo; _ovr = ovr_EnterVrMode(vrModeParms, &hmdInfo); _inVRMode = true; #endif }
static JavaVM *getJavaVM() { if (!g_javaVM){ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); g_javaVM = static_cast<JavaVM*>(nativeInterface->nativeResourceForIntegration("JavaVM")); } return g_javaVM; }
/*------------------------------------------------------------------------------ | get_egl_display +-----------------------------------------------------------------------------*/ EGLDisplay get_egl_display() { QPlatformNativeInterface* nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); Q_ASSERT(nativeInterface); EGLDisplay d = nativeInterface->nativeResourceForIntegration("egldisplay"); if (!d) log_warn("Couldn't get EGL display handle."); return d; }
void GLWidget::makeObject() { static const int coords[6][4][3] = { { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } }; QElapsedTimer timer; timer.start(); #ifndef DISABLED_OPENMAX //loadWithOmx(); QPlatformNativeInterface* nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); Q_ASSERT(nativeInterface); EGLDisplay eglDisplay = nativeInterface->nativeResourceForIntegration("egldisplay"); EGLContext eglContext = nativeInterface->nativeResourceForContext("eglcontext", QOpenGLContext::currentContext()); #if 0 eglImageVideo = getEGLImage(1920, 1080, eglDisplay, eglContext, textures[0]); #endif for (int i = 0; i < 5; i++) textures[i] = 0; //QtConcurrent::run(video_decode_test, videoPath, eglImageVideo, eglDisplay); m_videoProc = new OMX_VideoProcessor(eglDisplay, eglContext, m_provider); connect(m_videoProc, SIGNAL(textureReady(uint)), this, SLOT(onTextureChanged(uint))); m_videoProc->setVideoPath("/home/pi/out.h264"); m_videoProc->play(); #else for (int i = 0; i < 6; i++) { QPixmap pixmap(QString("%1%2.jpg").arg(prefix).arg(i)); if (pixmap.isNull()) LOG_ERROR(LOG_TAG, "Failed to load image!"); textures[i] = bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA); } #endif LOG_INFORMATION(LOG_TAG, "Elapsed: %lld.", timer.elapsed()); for (int i = 0; i < 6; ++i) { for (int j = 0; j < 4; ++j) { texCoords.append (QVector2D(j == 0 || j == 3, j == 0 || j == 1)); vertices.append (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2])); } } }
OMX_TextureData* OMX_TextureProviderQGLWidget::instantiateTexture(QSize size) { // TODO: Reimplement. #if 0 m_parent->makeCurrent(); QPlatformNativeInterface* nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); Q_ASSERT(nativeInterface); EGLDisplay eglDisplay = nativeInterface->nativeResourceForIntegration("egldisplay"); EGLContext eglContext = nativeInterface->nativeResourceForContext("eglcontext", QOpenGLContext::currentContext()); GLuint texture; eglImageVideo = getEGLImage(size.width(), size.height(), eglDisplay, eglContext, texture); return texture; #endif return 0; }
Compositor *Compositor::fromApplication(QObject *parent) { if (!QGuiApplication::platformName().contains(QStringLiteral("wayland"), Qt::CaseInsensitive)) { return nullptr; } QPlatformNativeInterface *native = qApp->platformNativeInterface(); if (!native) { return nullptr; } wl_compositor *compositor = reinterpret_cast<wl_compositor*>(native->nativeResourceForIntegration(QByteArrayLiteral("compositor"))); if (!compositor) { return nullptr; } Compositor *c = new Compositor(parent); c->d->compositor.setup(compositor, true); return c; }
void GLWidget::loadWithOmx() { LOG_VERBOSE(LOG_TAG, "Loading with OMX."); QPlatformNativeInterface* nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); Q_ASSERT(nativeInterface); EGLDisplay eglDisplay = nativeInterface->nativeResourceForIntegration("egldisplay"); EGLContext eglContext = nativeInterface->nativeResourceForContext("eglcontext", QOpenGLContext::currentContext()); for (int i = 5; i < 6; i++) { QString fileAbsPath = QString("%1%2.jpg").arg(prefix).arg(i); OpenMAXILTextureLoader* omTextureLoader = OpenMAXILTextureLoader::intance(); if (!omTextureLoader->loadTextureFromImage(fileAbsPath, eglDisplay, eglContext, textures[i])) { LOG_ERROR(LOG_TAG, "Failed to load image."); } else { LOG_INFORMATION(LOG_TAG, "Image %s successfully decoded and loaded.", qPrintable(fileAbsPath)); } } }
void MouseTouchAdaptor::fetchXInput2Info() { QPlatformNativeInterface *nativeInterface = qGuiApp->platformNativeInterface(); Display *xDisplay = static_cast<Display*>(nativeInterface->nativeResourceForIntegration("Display")); if (xDisplay && XQueryExtension(xDisplay, "XInputExtension", &m_xiOpCode, &m_xiEventBase, &m_xiErrorBase)) { int xiMajor = 2; m_xi2Minor = 2; // try 2.2 first, needed for TouchBegin/Update/End if (XIQueryVersion(xDisplay, &xiMajor, &m_xi2Minor) == BadRequest) { m_xi2Minor = 1; // for smooth scrolling 2.1 is enough if (XIQueryVersion(xDisplay, &xiMajor, &m_xi2Minor) == BadRequest) { m_xi2Minor = 0; // for tablet support 2.0 is enough m_xi2Enabled = XIQueryVersion(xDisplay, &xiMajor, &m_xi2Minor) != BadRequest; } else m_xi2Enabled = true; } else { m_xi2Enabled = true; } } }
GVRInterface::GVRInterface(int argc, char* argv[]) : QApplication(argc, argv), _mainWindow(NULL), _inVRMode(false) { setApplicationName("gvr-interface"); setOrganizationName("highfidelity"); setOrganizationDomain("io"); if (!launchURLString.isEmpty()) { // did we get launched with a lookup URL? If so it is time to give that to the AddressManager qDebug() << "We were opened via a hifi URL -" << launchURLString; } _client = new RenderingClient(this, launchURLString); launchURLString = QString(); connect(this, &QGuiApplication::applicationStateChanged, this, &GVRInterface::handleApplicationStateChange); #if defined(ANDROID) && defined(HAVE_LIBOVR) QAndroidJniEnvironment jniEnv; QPlatformNativeInterface* interface = QApplication::platformNativeInterface(); jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity"); ovr_RegisterHmtReceivers(&*jniEnv, activity); // PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being // stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES // but that increases the size of the plugin by ~1MiB OVR::linkerPlatformActivity++; #endif // call our idle function whenever we can QTimer* idleTimer = new QTimer(this); connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle); idleTimer->start(0); // call our quit handler before we go down connect(this, &QCoreApplication::aboutToQuit, this, &GVRInterface::handleApplicationQuit); }
QSGNode* OMX_MediaProcessorElement::updatePaintNode(QSGNode*, UpdatePaintNodeData*) { if (!m_texProvider) { m_texProvider = new OMX_TextureProviderQQuickItem(this); m_mediaProc = new OMX_MediaProcessor(m_texProvider); connect(m_mediaProc, SIGNAL(playbackCompleted()), this, SIGNAL(playbackCompleted())); connect(m_mediaProc, SIGNAL(playbackStarted()), this, SIGNAL(playbackStarted())); // Open if filepath is set. // TODO: Handle errors. if (!m_source.isNull()) { //if (QFile(m_source).exists()) { if (openMedia(m_source)) m_mediaProc->play(); //} //else { LOG_WARNING(LOG_TAG, "File does not exist."); //} } } return NULL; #if 0 QSGGeometryNode* node = 0; QSGGeometry* geometry = 0; if (!oldNode) { // Create the node. node = new QSGGeometryNode; geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4); geometry->setDrawingMode(GL_TRIANGLE_STRIP); node->setGeometry(geometry); node->setFlag(QSGNode::OwnsGeometry); // TODO: Who is freeing this? // TODO: I cannot know the texture size here. QSGOpaqueTextureMaterial* material = new QSGOpaqueTextureMaterial; m_sgtexture = new OMX_SGTexture(m_texture, QSize(1920, 1080)); material->setTexture(m_sgtexture); node->setMaterial(material); node->setFlag(QSGNode::OwnsMaterial); #ifdef ENABLE_VIDEO_PROCESSOR QPlatformNativeInterface* nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); Q_ASSERT(nativeInterface); EGLDisplay eglDisplay = nativeInterface->nativeResourceForIntegration("egldisplay"); EGLContext eglContext = nativeInterface->nativeResourceForContext( "eglcontext", QOpenGLContext::currentContext() ); #endif // Provider MUST be built in this thread. m_provider = new OMX_TextureProviderQQuickItem(this); #ifdef ENABLE_VIDEO_PROCESSOR m_videoProc = new OMX_VideoProcessor(eglDisplay, eglContext, m_provider); connect(m_videoProc, SIGNAL(textureReady(uint)), this, SLOT(onTextureChanged(uint))); if (!m_source.isNull()) m_videoProc->setVideoPath(m_source); if (m_playScheduled) { m_timer->start(30); m_videoProc->play(); } #elif ENABLE_MEDIA_PROCESSOR LOG_VERBOSE(LOG_TAG, "Starting video using media processor..."); m_mediaProc = new OMX_MediaProcessor(m_provider); m_mediaProc->setFilename("/home/pi/usb/Cars2.mkv", m_texture); //if (m_playScheduled) { m_timer->start(40); m_mediaProc->play(); //} #else LOG_VERBOSE(LOG_TAG, "Starting video..."); QtConcurrent::run(&startVideo, m_provider, this); m_timer->start(30); #endif } else { node = static_cast<QSGGeometryNode*>(oldNode); geometry = node->geometry(); geometry->allocate(4); // Update texture in the node if needed. QSGOpaqueTextureMaterial* material = (QSGOpaqueTextureMaterial*)node->material(); if (m_texture != (GLuint)material->texture()->textureId()) { // TODO: Does setTextureId frees the prev texture? // TODO: I should the given the texture size. LOG_ERROR(LOG_TAG, "Updating texture to %u!", m_texture); material = new QSGOpaqueTextureMaterial; m_sgtexture->setTexture(m_texture, QSize(1920, 1080)); } } // Create the vertices and map to texture. QRectF bounds = boundingRect(); QSGGeometry::TexturedPoint2D* vertices = geometry->vertexDataAsTexturedPoint2D(); vertices[0].set(bounds.x(), bounds.y() + bounds.height(), 0.0f, 0.0f); vertices[1].set(bounds.x() + bounds.width(), bounds.y() + bounds.height(), 1.0f, 0.0f); vertices[2].set(bounds.x(), bounds.y(), 0.0f, 1.0f); vertices[3].set(bounds.x() + bounds.width(), bounds.y(), 1.0f, 1.0f); return node; #endif }
/** * Request the video to avoid the conflicts **/ bool VideoWidget::request( struct vout_window_t *p_wnd ) { if( stable ) { msg_Dbg( p_intf, "embedded video already in use" ); return false; } assert( !p_window ); /* The owner of the video window needs a stable handle (WinId). Reparenting * in Qt4-X11 changes the WinId of the widget, so we need to create another * dummy widget that stays within the reparentable widget. */ stable = new QWidget(); QPalette plt = palette(); plt.setColor( QPalette::Window, Qt::black ); stable->setPalette( plt ); stable->setAutoFillBackground(true); /* Force the widget to be native so that it gets a winId() */ stable->setAttribute( Qt::WA_NativeWindow, true ); /* Indicates that the widget wants to draw directly onto the screen. Widgets with this attribute set do not participate in composition management */ /* This is currently disabled on X11 as it does not seem to improve * performance, but causes the video widget to be transparent... */ #if !defined (QT5_HAS_X11) stable->setAttribute( Qt::WA_PaintOnScreen, true ); #else stable->setMouseTracking( true ); setMouseTracking( true ); #endif layout->addWidget( stable ); sync(); p_window = p_wnd; p_wnd->type = p_intf->p_sys->voutWindowType; switch( p_wnd->type ) { case VOUT_WINDOW_TYPE_XID: p_wnd->handle.xid = stable->winId(); p_wnd->display.x11 = NULL; break; case VOUT_WINDOW_TYPE_HWND: p_wnd->handle.hwnd = (void *)stable->winId(); break; case VOUT_WINDOW_TYPE_NSOBJECT: p_wnd->handle.nsobject = (void *)stable->winId(); break; #ifdef QT5_HAS_WAYLAND case VOUT_WINDOW_TYPE_WAYLAND: { QWindow *window = stable->windowHandle(); assert(window != NULL); window->create(); QPlatformNativeInterface *qni = qApp->platformNativeInterface(); assert(qni != NULL); p_wnd->handle.wl = static_cast<wl_surface*>( qni->nativeResourceForWindow(QByteArrayLiteral("surface"), window)); p_wnd->display.wl = static_cast<wl_display*>( qni->nativeResourceForIntegration(QByteArrayLiteral("wl_display"))); break; } #endif default: vlc_assert_unreachable(); } return true; }