/src/mozilla-central/gfx/vr/VRDisplayLocal.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "VRDisplayLocal.h" |
8 | | #include "gfxPrefs.h" |
9 | | #include "gfxVR.h" |
10 | | #include "ipc/VRLayerParent.h" |
11 | | #include "mozilla/layers/TextureHost.h" |
12 | | #include "mozilla/dom/GamepadBinding.h" // For GamepadMappingType |
13 | | #include "VRThread.h" |
14 | | |
15 | | #if defined(XP_WIN) |
16 | | |
17 | | #include <d3d11.h> |
18 | | #include "gfxWindowsPlatform.h" |
19 | | #include "../layers/d3d11/CompositorD3D11.h" |
20 | | #include "mozilla/gfx/DeviceManagerDx.h" |
21 | | #include "mozilla/layers/TextureD3D11.h" |
22 | | |
23 | | #elif defined(XP_MACOSX) |
24 | | |
25 | | #include "mozilla/gfx/MacIOSurface.h" |
26 | | |
27 | | #endif |
28 | | |
29 | | #if defined(MOZ_WIDGET_ANDROID) |
30 | | #include "mozilla/layers/CompositorThread.h" |
31 | | #endif // defined(MOZ_WIDGET_ANDROID) |
32 | | |
33 | | using namespace mozilla; |
34 | | using namespace mozilla::gfx; |
35 | | using namespace mozilla::layers; |
36 | | |
37 | | VRDisplayLocal::VRDisplayLocal(VRDeviceType aType) |
38 | | : VRDisplayHost(aType) |
39 | 0 | { |
40 | 0 | MOZ_COUNT_CTOR_INHERITED(VRDisplayLocal, VRDisplayHost); |
41 | 0 | } |
42 | | |
43 | | VRDisplayLocal::~VRDisplayLocal() |
44 | 0 | { |
45 | 0 | MOZ_COUNT_DTOR_INHERITED(VRDisplayLocal, VRDisplayHost); |
46 | 0 | } |
47 | | |
48 | | bool |
49 | | VRDisplayLocal::SubmitFrame(const layers::SurfaceDescriptor &aTexture, |
50 | | uint64_t aFrameId, |
51 | | const gfx::Rect& aLeftEyeRect, |
52 | | const gfx::Rect& aRightEyeRect) |
53 | 0 | { |
54 | 0 | #if !defined(MOZ_WIDGET_ANDROID) |
55 | 0 | MOZ_ASSERT(mSubmitThread->GetThread() == NS_GetCurrentThread()); |
56 | 0 | #endif // !defined(MOZ_WIDGET_ANDROID) |
57 | 0 |
|
58 | 0 | switch (aTexture.type()) { |
59 | 0 |
|
60 | | #if defined(XP_WIN) |
61 | | case SurfaceDescriptor::TSurfaceDescriptorD3D10: { |
62 | | if (!CreateD3DObjects()) { |
63 | | return false; |
64 | | } |
65 | | const SurfaceDescriptorD3D10& surf = aTexture.get_SurfaceDescriptorD3D10(); |
66 | | RefPtr<ID3D11Texture2D> dxTexture; |
67 | | HRESULT hr = mDevice->OpenSharedResource((HANDLE)surf.handle(), |
68 | | __uuidof(ID3D11Texture2D), |
69 | | (void**)(ID3D11Texture2D**)getter_AddRefs(dxTexture)); |
70 | | if (FAILED(hr) || !dxTexture) { |
71 | | NS_WARNING("Failed to open shared texture"); |
72 | | return false; |
73 | | } |
74 | | |
75 | | // Similar to LockD3DTexture in TextureD3D11.cpp |
76 | | RefPtr<IDXGIKeyedMutex> mutex; |
77 | | dxTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex)); |
78 | | if (mutex) { |
79 | | HRESULT hr = mutex->AcquireSync(0, 1000); |
80 | | if (hr == WAIT_TIMEOUT) { |
81 | | gfxDevCrash(LogReason::D3DLockTimeout) << "D3D lock mutex timeout"; |
82 | | } |
83 | | else if (hr == WAIT_ABANDONED) { |
84 | | gfxCriticalNote << "GFX: D3D11 lock mutex abandoned"; |
85 | | } |
86 | | if (FAILED(hr)) { |
87 | | NS_WARNING("Failed to lock the texture"); |
88 | | return false; |
89 | | } |
90 | | } |
91 | | bool success = SubmitFrame(dxTexture, surf.size(), |
92 | | aLeftEyeRect, aRightEyeRect); |
93 | | if (mutex) { |
94 | | HRESULT hr = mutex->ReleaseSync(0); |
95 | | if (FAILED(hr)) { |
96 | | NS_WARNING("Failed to unlock the texture"); |
97 | | } |
98 | | } |
99 | | return success; |
100 | | } |
101 | | #elif defined(XP_MACOSX) |
102 | | case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: { |
103 | | const auto& desc = aTexture.get_SurfaceDescriptorMacIOSurface(); |
104 | | RefPtr<MacIOSurface> surf = MacIOSurface::LookupSurface(desc.surfaceId(), |
105 | | desc.scaleFactor(), |
106 | | !desc.isOpaque()); |
107 | | if (!surf) { |
108 | | NS_WARNING("VRDisplayHost::SubmitFrame failed to get a MacIOSurface"); |
109 | | return false; |
110 | | } |
111 | | IntSize texSize = gfx::IntSize(surf->GetDevicePixelWidth(), |
112 | | surf->GetDevicePixelHeight()); |
113 | | if (!SubmitFrame(surf, texSize, aLeftEyeRect, aRightEyeRect)) { |
114 | | return false; |
115 | | } |
116 | | return true; |
117 | | } |
118 | | #elif defined(MOZ_WIDGET_ANDROID) |
119 | | case SurfaceDescriptor::TSurfaceTextureDescriptor: { |
120 | | const SurfaceTextureDescriptor& desc = aTexture.get_SurfaceTextureDescriptor(); |
121 | | if (!SubmitFrame(desc, aLeftEyeRect, aRightEyeRect)) { |
122 | | return false; |
123 | | } |
124 | | return true; |
125 | | } |
126 | | #endif |
127 | 0 | default: { |
128 | 0 | NS_WARNING("Unsupported SurfaceDescriptor type for VR layer texture"); |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | } |
132 | 0 | } |