1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "device/vr/vr_device_base.h" 6 7 #include <utility> 8 9 #include "base/metrics/histogram_functions.h" 10 #include "device/vr/public/cpp/vr_device_provider.h" 11 12 namespace device { 13 VRDeviceBase(mojom::XRDeviceId id)14VRDeviceBase::VRDeviceBase(mojom::XRDeviceId id) : id_(id) { 15 device_data_.is_ar_blend_mode_supported = false; 16 } 17 18 VRDeviceBase::~VRDeviceBase() = default; 19 GetId() const20mojom::XRDeviceId VRDeviceBase::GetId() const { 21 return id_; 22 } 23 GetDeviceData() const24mojom::XRDeviceDataPtr VRDeviceBase::GetDeviceData() const { 25 return device_data_.Clone(); 26 } 27 PauseTracking()28void VRDeviceBase::PauseTracking() {} 29 ResumeTracking()30void VRDeviceBase::ResumeTracking() {} 31 GetVRDisplayInfo()32mojom::VRDisplayInfoPtr VRDeviceBase::GetVRDisplayInfo() { 33 return display_info_.Clone(); 34 } 35 ShutdownSession(base::OnceClosure on_completed)36void VRDeviceBase::ShutdownSession(base::OnceClosure on_completed) { 37 DVLOG(2) << __func__; 38 // TODO(https://crbug.com/1015594): The default implementation of running the 39 // callback immediately is backwards compatible, but runtimes should be 40 // updated to override this, calling the callback at the appropriate time 41 // after any necessary cleanup has been completed. Once that's done, make this 42 // method abstract. 43 std::move(on_completed).Run(); 44 } 45 OnExitPresent()46void VRDeviceBase::OnExitPresent() { 47 DVLOG(2) << __func__ << ": !!listener_=" << !!listener_; 48 if (listener_) 49 listener_->OnExitPresent(); 50 presenting_ = false; 51 } 52 OnStartPresenting()53void VRDeviceBase::OnStartPresenting() { 54 DVLOG(2) << __func__; 55 presenting_ = true; 56 } 57 HasExclusiveSession()58bool VRDeviceBase::HasExclusiveSession() { 59 return presenting_; 60 } 61 ListenToDeviceChanges(mojo::PendingAssociatedRemote<mojom::XRRuntimeEventListener> listener_info,mojom::XRRuntime::ListenToDeviceChangesCallback callback)62void VRDeviceBase::ListenToDeviceChanges( 63 mojo::PendingAssociatedRemote<mojom::XRRuntimeEventListener> listener_info, 64 mojom::XRRuntime::ListenToDeviceChangesCallback callback) { 65 listener_.Bind(std::move(listener_info)); 66 std::move(callback).Run(display_info_.Clone()); 67 } 68 SetVRDisplayInfo(mojom::VRDisplayInfoPtr display_info)69void VRDeviceBase::SetVRDisplayInfo(mojom::VRDisplayInfoPtr display_info) { 70 DCHECK(display_info); 71 display_info_ = std::move(display_info); 72 73 if (listener_) 74 listener_->OnDisplayInfoChanged(display_info_.Clone()); 75 } 76 OnVisibilityStateChanged(mojom::XRVisibilityState visibility_state)77void VRDeviceBase::OnVisibilityStateChanged( 78 mojom::XRVisibilityState visibility_state) { 79 if (listener_) 80 listener_->OnVisibilityStateChanged(visibility_state); 81 } 82 SetArBlendModeSupported(bool is_ar_blend_mode_supported)83void VRDeviceBase::SetArBlendModeSupported(bool is_ar_blend_mode_supported) { 84 device_data_.is_ar_blend_mode_supported = is_ar_blend_mode_supported; 85 } 86 87 #if defined(OS_WIN) SetLuid(const LUID & luid)88void VRDeviceBase::SetLuid(const LUID& luid) { 89 if (luid.HighPart != 0 || luid.LowPart != 0) { 90 // Only set the LUID if it exists and is nonzero. 91 device_data_.luid = base::make_optional<LUID>(luid); 92 } 93 } 94 #endif 95 BindXRRuntime()96mojo::PendingRemote<mojom::XRRuntime> VRDeviceBase::BindXRRuntime() { 97 DVLOG(2) << __func__; 98 return runtime_receiver_.BindNewPipeAndPassRemote(); 99 } 100 LogViewerType(VrViewerType type)101void LogViewerType(VrViewerType type) { 102 base::UmaHistogramSparse("VRViewerType", static_cast<int>(type)); 103 } 104 105 } // namespace device 106