OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_angle_util_win.h" | 5 #include "ui/gl/gl_angle_util_win.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "third_party/angle/include/EGL/egl.h" | 8 #include "third_party/angle/include/EGL/egl.h" |
9 #include "third_party/angle/include/EGL/eglext.h" | 9 #include "third_party/angle/include/EGL/eglext.h" |
10 #include "ui/gl/gl_surface_egl.h" | 10 #include "ui/gl/gl_surface_egl.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 return d3d11_device; | 75 return d3d11_device; |
76 } | 76 } |
77 | 77 |
78 base::win::ScopedComPtr<IDirect3DDevice9> QueryD3D9DeviceObjectFromANGLE() { | 78 base::win::ScopedComPtr<IDirect3DDevice9> QueryD3D9DeviceObjectFromANGLE() { |
79 base::win::ScopedComPtr<IDirect3DDevice9> d3d9_device; | 79 base::win::ScopedComPtr<IDirect3DDevice9> d3d9_device; |
80 d3d9_device = reinterpret_cast<IDirect3DDevice9*>( | 80 d3d9_device = reinterpret_cast<IDirect3DDevice9*>( |
81 QueryDeviceObjectFromANGLE(EGL_D3D9_DEVICE_ANGLE)); | 81 QueryDeviceObjectFromANGLE(EGL_D3D9_DEVICE_ANGLE)); |
82 return d3d9_device; | 82 return d3d9_device; |
83 } | 83 } |
84 | 84 |
85 base::win::ScopedComPtr<IDCompositionDevice2> QueryDirectCompositionDevice( | |
86 base::win::ScopedComPtr<ID3D11Device> d3d11_device) { | |
87 // Each D3D11 device will have a DirectComposition device stored in its | |
88 // private data under this GUID. | |
89 // {CF81D85A-8D30-4769-8509-B9D73898D870} | |
90 static const GUID kDirectCompositionGUID = { | |
91 0xcf81d85a, | |
92 0x8d30, | |
93 0x4769, | |
94 {0x85, 0x9, 0xb9, 0xd7, 0x38, 0x98, 0xd8, 0x70}}; | |
95 | |
96 base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device; | |
97 if (!d3d11_device) | |
98 return dcomp_device; | |
99 | |
100 UINT data_size = sizeof(dcomp_device.get()); | |
101 HRESULT hr = d3d11_device->GetPrivateData(kDirectCompositionGUID, &data_size, | |
102 dcomp_device.ReceiveVoid()); | |
103 if (SUCCEEDED(hr) && dcomp_device) | |
104 return dcomp_device; | |
105 | |
106 // Allocate a new DirectComposition device if none currently exists. | |
107 HMODULE dcomp_module = ::GetModuleHandle(L"dcomp.dll"); | |
108 if (!dcomp_module) | |
109 return dcomp_device; | |
110 | |
111 typedef HRESULT(WINAPI * PFN_DCOMPOSITION_CREATE_DEVICE2)( | |
dcheng
2017/02/15 06:57:05
Nit: prefer using over typedef
| |
112 IUnknown * renderingDevice, REFIID iid, void** dcompositionDevice); | |
113 PFN_DCOMPOSITION_CREATE_DEVICE2 create_device_function = | |
114 reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE2>( | |
115 ::GetProcAddress(dcomp_module, "DCompositionCreateDevice2")); | |
116 if (!create_device_function) | |
117 return dcomp_device; | |
118 | |
119 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; | |
120 d3d11_device.QueryInterface(dxgi_device.Receive()); | |
121 base::win::ScopedComPtr<IDCompositionDesktopDevice> desktop_device; | |
122 hr = create_device_function(dxgi_device.get(), | |
123 IID_PPV_ARGS(desktop_device.Receive())); | |
124 if (FAILED(hr)) | |
125 return dcomp_device; | |
126 | |
127 hr = desktop_device.QueryInterface(dcomp_device.Receive()); | |
128 CHECK(SUCCEEDED(hr)); | |
129 d3d11_device->SetPrivateDataInterface(kDirectCompositionGUID, | |
130 dcomp_device.get()); | |
131 | |
132 return dcomp_device; | |
133 } | |
134 | |
85 } // namespace gl | 135 } // namespace gl |
OLD | NEW |