OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "stdafx.h" | 5 #include "stdafx.h" |
6 #include "win8/metro_driver/direct3d_helper.h" | 6 #include "win8/metro_driver/direct3d_helper.h" |
7 #include "win8/metro_driver/winrt_utils.h" | 7 #include "win8/metro_driver/winrt_utils.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/win/windows_version.h" |
10 | 11 |
| 12 #include <corewindow.h> |
| 13 #include <windows.applicationmodel.core.h> |
11 #include <windows.graphics.display.h> | 14 #include <windows.graphics.display.h> |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 void CheckIfFailed(HRESULT hr) { | 18 void CheckIfFailed(HRESULT hr) { |
16 DCHECK(!FAILED(hr)); | 19 DCHECK(!FAILED(hr)); |
17 if (FAILED(hr)) | 20 if (FAILED(hr)) |
18 DVLOG(0) << "Direct3D call failed, hr = " << hr; | 21 DVLOG(0) << "Direct3D call failed, hr = " << hr; |
19 } | 22 } |
20 | 23 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ARRAYSIZE(feature_levels), | 79 ARRAYSIZE(feature_levels), |
77 D3D11_SDK_VERSION, | 80 D3D11_SDK_VERSION, |
78 &device, | 81 &device, |
79 &feature_level_, | 82 &feature_level_, |
80 &context)); | 83 &context)); |
81 CheckIfFailed(device.As(&d3d_device_)); | 84 CheckIfFailed(device.As(&d3d_device_)); |
82 CheckIfFailed(context.As(&d3d_context_)); | 85 CheckIfFailed(context.As(&d3d_context_)); |
83 } | 86 } |
84 | 87 |
85 void Direct3DHelper::CreateWindowSizeDependentResources() { | 88 void Direct3DHelper::CreateWindowSizeDependentResources() { |
86 CheckIfFailed(window_->get_Bounds(&window_bounds_)); | 89 float window_width = 0; |
87 float window_width = ConvertDipsToPixels(window_bounds_.Width); | 90 float window_height = 0; |
88 float window_height = ConvertDipsToPixels(window_bounds_.Height); | 91 |
| 92 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 93 // Windows 8 returns in DIPs. |
| 94 CheckIfFailed(window_->get_Bounds(&window_bounds_)); |
| 95 window_width = ConvertDipsToPixels(window_width); |
| 96 window_height = ConvertDipsToPixels(window_height); |
| 97 } |
89 | 98 |
90 // TODO(scottmg): Orientation. | 99 // TODO(scottmg): Orientation. |
91 | 100 |
92 if (swap_chain_ != nullptr) { | 101 if (swap_chain_ != nullptr) { |
93 // TODO(scottmg): Resize if it already exists. | 102 // TODO(scottmg): Resize if it already exists. |
94 NOTIMPLEMENTED(); | 103 NOTIMPLEMENTED(); |
95 } else { | 104 } else { |
96 DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = { 0 }; | 105 DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = { 0 }; |
97 swap_chain_desc.Width = window_width; | 106 swap_chain_desc.Width = window_width; |
98 swap_chain_desc.Height = window_height; | 107 swap_chain_desc.Height = window_height; |
(...skipping 10 matching lines...) Expand all Loading... |
109 mswr::ComPtr<IDXGIDevice1> dxgi_device; | 118 mswr::ComPtr<IDXGIDevice1> dxgi_device; |
110 CheckIfFailed(d3d_device_.As(&dxgi_device)); | 119 CheckIfFailed(d3d_device_.As(&dxgi_device)); |
111 | 120 |
112 mswr::ComPtr<IDXGIAdapter> dxgi_adapter; | 121 mswr::ComPtr<IDXGIAdapter> dxgi_adapter; |
113 CheckIfFailed(dxgi_device->GetAdapter(&dxgi_adapter)); | 122 CheckIfFailed(dxgi_device->GetAdapter(&dxgi_adapter)); |
114 | 123 |
115 mswr::ComPtr<IDXGIFactory2> dxgi_factory; | 124 mswr::ComPtr<IDXGIFactory2> dxgi_factory; |
116 CheckIfFailed(dxgi_adapter->GetParent( | 125 CheckIfFailed(dxgi_adapter->GetParent( |
117 __uuidof(IDXGIFactory2), &dxgi_factory)); | 126 __uuidof(IDXGIFactory2), &dxgi_factory)); |
118 | 127 |
119 CheckIfFailed(dxgi_factory->CreateSwapChainForCoreWindow( | 128 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
120 d3d_device_.Get(), | 129 // On Win8 we need the CoreWindow interface to create the Swapchain. |
121 reinterpret_cast<IUnknown*>(window_), | 130 CheckIfFailed(dxgi_factory->CreateSwapChainForCoreWindow( |
122 &swap_chain_desc, | 131 d3d_device_.Get(), |
123 nullptr, | 132 reinterpret_cast<IUnknown*>(window_), |
124 &swap_chain_)); | 133 &swap_chain_desc, |
| 134 nullptr, |
| 135 &swap_chain_)); |
| 136 } else { |
| 137 // On Win7 we need the raw HWND to create the Swapchain. |
| 138 mswr::ComPtr<ICoreWindowInterop> interop; |
| 139 CheckIfFailed(window_->QueryInterface(interop.GetAddressOf())); |
| 140 HWND window = NULL; |
| 141 interop->get_WindowHandle(&window); |
| 142 |
| 143 swap_chain_desc.Scaling = DXGI_SCALING_STRETCH; |
| 144 swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; |
| 145 |
| 146 CheckIfFailed(dxgi_factory->CreateSwapChainForHwnd( |
| 147 d3d_device_.Get(), |
| 148 window, |
| 149 &swap_chain_desc, |
| 150 nullptr, |
| 151 nullptr, |
| 152 &swap_chain_)); |
| 153 } |
125 } | 154 } |
126 } | 155 } |
127 | 156 |
128 } // namespace metro_driver | 157 } // namespace metro_driver |
OLD | NEW |