UPInt String::InsertCharAt(UInt32 c, UPInt posAt) { char buf[8]; SPInt index = 0; UTF8Util::EncodeChar(buf, &index, c); OVR_ASSERT(index >= 0); buf[(UPInt)index] = 0; Insert(buf, posAt, index); return (UPInt)index; }
eMsgStatus OvrAnimComponent::OnEvent_Impl( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { switch ( event.EventType ) { case VRMENU_EVENT_FRAME_UPDATE: return Frame( app, vrFrame, menuMgr, self, event ); default: OVR_ASSERT( !"Event flags mismatch!" ); // the constructor is specifying a flag that's not handled return MSG_STATUS_ALIVE; } }
// Inserts character at posAt UPInt StringBuffer::InsertCharAt(UInt32 c, UPInt posAt) { char buf[8]; SPInt len = 0; UTF8Util::EncodeChar(buf, &len, c); OVR_ASSERT(len >= 0); buf[(UPInt)len] = 0; Insert(buf, posAt, len); return (UPInt)len; }
unsigned char FrameLatencyTracker::GetNextDrawColor() { if (!TrackerEnabled || (WaitMode == SampleWait_Zeroes) || (FrameIndex >= FramesTracked)) { return (unsigned char)Util::FrameTimeRecord::ReadbackIndexToColor(0); } OVR_ASSERT(FrameIndex < FramesTracked); return (unsigned char)Util::FrameTimeRecord::ReadbackIndexToColor(FrameIndex+1); }
//============================== // OvrSurfaceToggleComponent::OnEvent_Impl eMsgStatus OvrSurfaceToggleComponent::OnEvent_Impl( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { switch ( event.EventType ) { case VRMENU_EVENT_FRAME_UPDATE: return Frame( app, vrFrame, menuMgr, self, event ); default: OVR_ASSERT( !"Event flags mismatch!" ); return MSG_STATUS_ALIVE; } }
double PerformanceTimer::GetTimeSecondsDouble() { if (UsingVistaOrLater) { LARGE_INTEGER li; QueryPerformanceCounter(&li); OVR_ASSERT(PerfFrequencyInverse != 0); return (li.QuadPart * PerfFrequencyInverse); } return (GetTimeNanos() * .0000000001); }
//----------------------------------------------------------------------------- void HIDDevice::closeDevice(bool wasUnplugged) { OVR_UNUSED(wasUnplugged); OVR_ASSERT(DeviceHandle >= 0); HIDManager->DevManager->pThread->RemoveSelectFd(this,-1); hid_close(DeviceHandle); DeviceHandle = NULL; LogText("OVR::Linux::HIDDevice - HID Device Closed '%s'\n", DevDesc.Path.ToCStr()); }
uint64_t PerformanceTimer::GetTimeSeconds() { if (UsingVistaOrLater) { LARGE_INTEGER li; QueryPerformanceCounter(&li); OVR_ASSERT(PerfFrequencyInverse != 0); // Initialize should have been called earlier. return (uint64_t)(li.QuadPart * PerfFrequencyInverse); } return (uint64_t)(GetTimeNanos() * .0000000001); }
void RefCountNTSImplCore::checkInvalidDelete(RefCountNTSImplCore *pmem) { #ifdef OVR_BUILD_DEBUG if (pmem->RefCount != 0) { OVR_DEBUG_LOG( ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem) ); OVR_ASSERT(0); } #else OVR_UNUSED( pmem ); #endif }
BOOL CALLBACK VersionCheckInitOnceCallback(PINIT_ONCE, PVOID, PVOID*) { typedef NTSTATUS(WINAPI * pfnRtlGetVersion)(PRTL_OSVERSIONINFOEXW lpVersionInformation); NTSTATUS status = STATUS_DLL_NOT_FOUND; HMODULE hNTDll = LoadLibraryW(L"ntdll.dll"); OVR_ASSERT(hNTDll); if (hNTDll) { status = STATUS_ENTRYPOINT_NOT_FOUND; pfnRtlGetVersion pRtlGetVersion = (pfnRtlGetVersion)GetProcAddress(hNTDll, "RtlGetVersion"); OVR_ASSERT(pRtlGetVersion); if (pRtlGetVersion) { RTL_OSVERSIONINFOEXW OSVersionInfoEx; OSVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVersionInfoEx); status = pRtlGetVersion(&OSVersionInfoEx); OVR_ASSERT(status == 0); if (status == 0) { OSVersion = OSVersionInfoEx.dwMajorVersion * 100 + OSVersionInfoEx.dwMinorVersion; OSBuildNumber = OSVersionInfoEx.dwBuildNumber; } } FreeLibrary(hNTDll); } if (status != 0) { LogError("[VersionCheckInitOnceCallback] Failed to obtain OS version information. 0x%08x\n", status); } return (status == 0); }
void UIDiscreteSlider::AddCells( unsigned int maxValue, unsigned int startValue, float cellSpacing ) { MaxValue = maxValue; StartValue = startValue; DiscreteSliderComponent = new UIDiscreteSliderComponent( *this, StartValue ); OVR_ASSERT( DiscreteSliderComponent ); AddComponent( DiscreteSliderComponent ); float cellOffset = 0.0f; const float pixelCellSpacing = cellSpacing * VRMenuObject::DEFAULT_TEXEL_SCALE; VRMenuFontParms fontParms( HORIZONTAL_CENTER, VERTICAL_CENTER, false, false, false, 1.0f ); Vector3f defaultScale( 1.0f ); for ( unsigned int cellIndex = 0; cellIndex <= MaxValue; ++cellIndex ) { const Posef pose( Quatf( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ), Vector3f( cellOffset, 0.f, 0.0f ) ); cellOffset += pixelCellSpacing; VRMenuObjectParms cellParms( VRMENU_BUTTON, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), "", pose, defaultScale, fontParms, Menu->AllocId(), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); UICell * cellObject = new UICell( GuiSys ); cellObject->AddToDiscreteSlider( Menu, this, cellParms ); cellObject->SetImage( 0, SURFACE_TEXTURE_DIFFUSE, CellOffTexture ); UICellComponent * cellComp = new UICellComponent( *DiscreteSliderComponent, cellIndex ); VRMenuObject * object = cellObject->GetMenuObject(); OVR_ASSERT( object ); object->AddComponent( cellComp ); DiscreteSliderComponent->AddCell( cellObject ); } DiscreteSliderComponent->HighlightCells( StartValue ); }
void Log::DefaultLogOutput(const char* formattedText, LogMessageType messageType, int bufferSize) { bool debug = IsDebugMessage(messageType); OVR_UNUSED(bufferSize); #if defined(OVR_OS_WIN32) // Under Win32, output regular messages to console if it exists; debug window otherwise. static DWORD dummyMode; static bool hasConsole = (GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE) && (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &dummyMode)); if (!hasConsole || debug) { ::OutputDebugStringA(formattedText); } fputs(formattedText, stdout); #elif defined(OVR_OS_MS) // Any other Microsoft OSs ::OutputDebugStringA(formattedText); #elif defined(OVR_OS_ANDROID) // To do: use bufferSize to deal with the case that Android has a limited output length. __android_log_write(ANDROID_LOG_INFO, "OVR", formattedText); #else fputs(formattedText, stdout); #endif if (messageType == Log_Error) { #if defined(OVR_OS_WIN32) if (!ReportEventA(hEventSource, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, &formattedText, NULL)) { OVR_ASSERT(false); } #elif defined(OVR_OS_MS) // Any other Microsoft OSs // TBD #elif defined(OVR_OS_ANDROID) // TBD #elif defined(OVR_OS_MAC) || defined(OVR_OS_LINUX) syslog(LOG_ERR, "%s", formattedText); #else // TBD #endif } // Just in case. OVR_UNUSED2(formattedText, debug); }
void PerformanceTimer::Initialize() { ::InitializeCriticalSection(&TimeCS); MMTimeWrapCounter = 0; getFrequency(); #if defined(OVR_OS_WIN32) // Desktop Windows only // Set Vista flag. On Vista, we can just use QPC() without all the extra work OSVERSIONINFOEXW ver; ZeroMemory(&ver, sizeof(OSVERSIONINFOEXW)); ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); ver.dwMajorVersion = 6; // Vista+ DWORDLONG condMask = 0; VER_SET_CONDITION(condMask, VER_MAJORVERSION, VER_GREATER_EQUAL); // VerifyVersionInfo returns true if the OS meets the conditions set above UsingVistaOrLater = ::VerifyVersionInfoW(&ver, VER_MAJORVERSION, condMask) != 0; #else UsingVistaOrLater = true; #endif if (!UsingVistaOrLater) { #if defined(OVR_OS_WIN32) // Desktop Windows only // The following has the effect of setting the NT timer resolution (NtSetTimerResolution) to 1 millisecond. MMRESULT mmr = timeBeginPeriod(1); OVR_ASSERT(TIMERR_NOERROR == mmr); OVR_UNUSED(mmr); #endif #if defined(OVR_BUILD_DEBUG) && defined(OVR_OS_WIN32) HMODULE hNtDll = ::LoadLibraryW(L"NtDll.dll"); if (hNtDll) { pNtQueryTimerResolution = (NtQueryTimerResolutionType)::GetProcAddress(hNtDll, "NtQueryTimerResolution"); //pNtSetTimerResolution = (NtSetTimerResolutionType)::GetProcAddress(hNtDll, "NtSetTimerResolution"); if (pNtQueryTimerResolution) { ULONG MinimumResolution; // in 100-ns units ULONG MaximumResolution; ULONG ActualResolution; pNtQueryTimerResolution(&MinimumResolution, &MaximumResolution, &ActualResolution); OVR_DEBUG_LOG(("NtQueryTimerResolution = Min %ld us, Max %ld us, Current %ld us", MinimumResolution / 10, MaximumResolution / 10, ActualResolution / 10)); } ::FreeLibrary(hNtDll); } #endif } }
RenderDevice* PlatformCore::SetupGraphics(const SetupGraphicsDeviceSet& setupGraphicsDesc, const char* type, const Render::RendererParams& rp) { const SetupGraphicsDeviceSet* setupDesc = setupGraphicsDesc.PickSetupDevice(type); OVR_ASSERT(setupDesc); pRender = *setupDesc->pCreateDevice(rp, (void*)hWnd); if (pRender) pRender->SetWindowSize(Width, Height); ::ShowWindow(hWnd, SW_RESTORE); return pRender.GetPtr(); }
void RenderDevice::Present(bool useVsync) { BOOL success; int swapInterval = (useVsync) ? 1 : 0; if (wglGetSwapIntervalEXT() != swapInterval) wglSwapIntervalEXT(swapInterval); HDC dc = GetDC(Window); success = SwapBuffers(dc); ReleaseDC(Window, dc); OVR_ASSERT(success); }
void PerformanceTimer::Shutdown() { ::DeleteCriticalSection(&TimeCS); if (!UsingVistaOrLater) { #if defined(OVR_OS_WIN32) // Desktop Windows only MMRESULT mmr = timeEndPeriod(1); OVR_ASSERT(TIMERR_NOERROR == mmr); OVR_UNUSED(mmr); #endif } }
// Append a string void StringBuffer::AppendString(const wchar_t* pstr, intptr_t len) { if (!pstr || !len) return; intptr_t srcSize = UTF8Util::GetEncodeStringSize(pstr, len); size_t origSize = GetSize(); size_t size = srcSize + origSize; Resize(size); OVR_ASSERT(pData != NULL); UTF8Util::EncodeString(pData + origSize, pstr, len); }
//============================== // OvrScrollBarComponent::OnEvent_Impl eMsgStatus OvrScrollBarComponent::OnEvent_Impl( OvrGuiSys & guiSys, VrFrame const & vrFrame, VRMenuObject * self, VRMenuEvent const & event ) { switch ( event.EventType ) { case VRMENU_EVENT_FRAME_UPDATE: return OnFrameUpdate( guiSys, vrFrame, self, event ); default: OVR_ASSERT( false ); break; } return MSG_STATUS_ALIVE; }
//============================== // OvrScrollBarComponent::OnEvent_Impl eMsgStatus OvrScrollBarComponent::OnEvent_Impl( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { switch ( event.EventType ) { case VRMENU_EVENT_FRAME_UPDATE: return OnFrameUpdate( app, vrFrame, menuMgr, self, event ); default: OVR_ASSERT( false ); return MSG_STATUS_ALIVE; } return MSG_STATUS_CONSUMED; }
// Allocates a state block of specified size and advances pointers, // returning 0 if buffer is full. UByte* CircularBuffer::Write(UPInt size) { UByte* p = 0; size = roundUpSize(size); // Since this is circular buffer, always allow at least one item. OVR_ASSERT(size < Size/2); if (Head >= Tail) { OVR_ASSERT(End == 0); if (size <= (Size - Head)) { p = pBuffer + Head; Head += size; } else if (size < Tail) { p = pBuffer; End = Head; Head = size; OVR_ASSERT(Head != Tail); } } else { OVR_ASSERT(End != 0); if ((Tail - Head) > size) { p = pBuffer + Head; Head += size; OVR_ASSERT(Head != Tail); } } return p; }
void ovrJobThread::Init( int const threadNum ) { OVR_ASSERT( JobManager != nullptr ); OVR_ASSERT( MyThread == nullptr ); size_t const stackSize = 128 * 1024; int const processorAffinity = -1; OVR::Thread::ThreadState initialState = OVR::Thread::Running; OVR_ASSERT( Jni == nullptr ); // this will be attached when the thread executes Thread::CreateParams createParams( ovrJobThread::Fn, this, stackSize, processorAffinity, initialState, Thread::IdlePriority ); //MyThread = new OVR::Thread( ovrJobThread::Fn, this, stackSize, processorAffinity, initialState ); MyThread = new OVR::Thread( createParams ); }
bool DeviceManagerThread::AddSelectFd(Notifier* notify, int fd) { struct pollfd pfd; pfd.fd = fd; pfd.events = POLLIN|POLLHUP|POLLERR; pfd.revents = 0; FdNotifiers.PushBack(notify); PollFds.PushBack(pfd); OVR_ASSERT(FdNotifiers.GetSize() == PollFds.GetSize()); return true; }
DeviceManagerImpl::~DeviceManagerImpl() { // Shutdown must've been called. OVR_ASSERT(!pCreateDesc->pDevice); // Remove all factories while(!Factories.IsEmpty()) { DeviceFactory* factory = Factories.GetFirst(); factory->RemovedFromManager(); factory->RemoveNode(); } }
bool HMDDeviceCreateDesc::UpdateMatchedCandidate(const DeviceCreateDesc& other, bool* newDeviceFlag) { // This candidate was the the "best fit" to apply sensor DisplayInfo to. OVR_ASSERT(other.Type == Device_HMD); const HMDDeviceCreateDesc& s2 = (const HMDDeviceCreateDesc&) other; // Force screen size on resolution from SensorDisplayInfo. // We do this because USB detection is more reliable as compared to HDMI EDID, // which may be corrupted by splitter reporting wrong monitor if (s2.DeviceId.IsEmpty()) { ScreenSizeInMeters = s2.ScreenSizeInMeters; Contents |= Contents_Screen; if (s2.Contents & HMDDeviceCreateDesc::Contents_Distortion) { memcpy(DistortionK, s2.DistortionK, sizeof(float)*4); // TODO: DistortionEqn Contents |= Contents_Distortion; } DeviceId = s2.DeviceId; DisplayId = s2.DisplayId; DisplayDeviceName = s2.DisplayDeviceName; Desktop.X = s2.Desktop.X; Desktop.Y = s2.Desktop.Y; if (newDeviceFlag) *newDeviceFlag = true; } else if (DeviceId.IsEmpty()) { // This branch is executed when 'fake' HMD descriptor is being replaced by // the real one. DeviceId = s2.DeviceId; DisplayId = s2.DisplayId; DisplayDeviceName = s2.DisplayDeviceName; Desktop.X = s2.Desktop.X; Desktop.Y = s2.Desktop.Y; // ScreenSize and Resolution are NOT assigned here, since they may have // come from a sensor DisplayInfo (which has precedence over HDMI). if (newDeviceFlag) *newDeviceFlag = true; } else { if (newDeviceFlag) *newDeviceFlag = false; } return true; }
void TestSerialFormatStuff() { for (int ii = 0; ii < 256; ++ii) { OVR_ASSERT(Base32FromChar[ii] == (char)DecodeBase32((char)ii)); } DK2BinarySerialFormat sa; sa.ProductId = DK2ProductId_DK2; sa.PartId = DK2PartId_HMD; sa.MinutesSinceEpoch = 65000; sa.UnitNumber = 2; sa.MacHash[0] = 0xa1; sa.MacHash[1] = 0xb2; sa.MacHash[2] = 0xc3; sa.MacHash[3] = 0xd4; sa.MacHash[4] = 0xe5; uint8_t buffer[12]; sa.ToBuffer(buffer); DK2BinarySerialFormat sb; OVR_ASSERT(sb.FromBuffer(buffer)); OVR_ASSERT(sa == sb); DK2PrintedSerialFormat psn; psn.FromBinary(sb); OVR_ASSERT(psn == sa); String s = psn.ToBase32(); DK2PrintedSerialFormat psn2; psn2.FromBase32(s.ToCStr()); OVR_ASSERT(psn == psn2); }
bool ShaderSet::SetUniform(const char* name, int n, const float* v) { for (unsigned int i = 0; i < UniformInfo.GetSize(); i++) if (!strcmp(UniformInfo[i].Name.ToCStr(), name)) { OVR_ASSERT(UniformInfo[i].Location >= 0); glUseProgram(Prog); switch (UniformInfo[i].Type) { case 1: glUniform1fv(UniformInfo[i].Location, n, v); break; case 2: glUniform2fv(UniformInfo[i].Location, n/2, v); break; case 3: glUniform3fv(UniformInfo[i].Location, n/3, v); break; case 4: glUniform4fv(UniformInfo[i].Location, n/4, v); break; case 12: glUniformMatrix3fv(UniformInfo[i].Location, 1, 1, v); break; case 16: glUniformMatrix4fv(UniformInfo[i].Location, 1, 1, v); break; default: OVR_ASSERT(0); } return 1; } OVR_DEBUG_LOG(("Warning: uniform %s not present in selected shader", name)); return 0; }
int64_t BufferedFile::LTell() { if (BufferMode == ReadBuffer) return FilePos - DataSize + Pos; int64_t pos = pFile->LTell(); if (pos!=-1) { OVR_ASSERT(BufferMode != ReadBuffer); if (BufferMode == WriteBuffer) pos += Pos; } return pos; }
// Reloads data for ReadBuffer void BufferedFile::LoadBuffer() { if (BufferMode == ReadBuffer) { // We should only reload once all of pre-loaded buffer is consumed. OVR_ASSERT(Pos == DataSize); // WARNING: Right now LoadBuffer() assumes the buffer's empty int sz = pFile->Read(pBuffer,FILEBUFFER_SIZE); DataSize = sz<0 ? 0 : (unsigned)sz; Pos = 0; FilePos += DataSize; } }
void DeviceManagerImpl::Shutdown() { // Remove all device descriptors from list while the lock is held. // Some descriptors may survive longer due to handles. while(!Devices.IsEmpty()) { DeviceCreateDesc* devDesc = Devices.GetFirst(); OVR_ASSERT(!devDesc->pDevice); // Manager shouldn't be dying while Device exists. devDesc->Enumerated = false; devDesc->RemoveNode(); devDesc->pNext = devDesc->pPrev = 0; if (devDesc->HandleCount == 0) { delete devDesc; } } Devices.Clear(); // These must've been cleared by caller. OVR_ASSERT(pCreateDesc->pDevice == 0); OVR_ASSERT(pCreateDesc->pLock->pManager == 0); }
virtual eMsgStatus OnEvent_Impl( OvrGuiSys & guiSys, ovrFrameInput const & vrFrame, VRMenuObject * self, VRMenuEvent const & event ) { switch ( event.EventType ) { case VRMENU_EVENT_FRAME_UPDATE: return OnFrame( guiSys, vrFrame, self, event ); case VRMENU_EVENT_OPENING: return OnOpening( guiSys, vrFrame, self, event ); default: OVR_ASSERT( !"Event flags mismatch!" ); // the constructor is specifying a flag that's not handled return MSG_STATUS_ALIVE; } }