Skip to content

Commit

Permalink
Use Windows provided xinput dll instead of bundling dll from DX redist.
Browse files Browse the repository at this point in the history
Internal Chrome build machines have a copy of DirectX 2010 redist on predefined
path. Built chromium package would then include a copy of xinput1_3.dll from
DirectX redist.
Here, approach is to use whatever xinput dll platform includes. Logic about
what dll is in use for different platforms is copied from Xinput.h.
In order to target all of the Windows versions with the same binary, chosen to
keep dynamic linking approach. Otherwise, there would be a problem with
XInputEnable not available in xinput dll before Windows8 and deprecated on
Windows 10.

BUG=579495

Review URL: https://codereview.chromium.org/1719693002

Cr-Commit-Position: refs/heads/master@{#384809}
  • Loading branch information
astojilj authored and Commit bot committed Apr 2, 2016
1 parent 52ef1ab commit 5568924
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 57 deletions.
1 change: 0 additions & 1 deletion .gn
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ exec_script_whitelist = [
"//content/browser/browser.gni",
"//content/child/child.gni",
"//content/common/common.gni",
"//content/content.gni",
"//content/public/android/BUILD.gn",
"//content/renderer/renderer.gni",
"//content/test/BUILD.gn",
Expand Down
1 change: 0 additions & 1 deletion chrome/installer/mini_installer/chrome.release
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ natives_blob.bin: %(VersionDir)s\
resources.pak: %(VersionDir)s\
snapshot_blob.bin: %(VersionDir)s\
syzyasan_rtl.dll: %(VersionDir)s\
xinput1_3.dll: %(VersionDir)s\
#
# Sub directories living in the version dir
#
Expand Down
5 changes: 0 additions & 5 deletions chrome/tools/build/win/FILES.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ FILES = [
'buildtype': ['dev', 'official'],
'filegroup': ['default', 'symsrc'],
},
# XInput files:
{
'filename': 'xinput1_3.dll',
'buildtype': ['dev', 'official'],
},
# Native Client plugin files:
{
'filename': 'nacl_irt_x86_32.nexe',
Expand Down
26 changes: 21 additions & 5 deletions content/browser/gamepad/gamepad_platform_data_fetcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,25 @@ const WebUChar* GamepadSubTypeName(BYTE sub_type) {
}
}

const WebUChar* XInputDllFileName() {
// Xinput.h defines filename (XINPUT_DLL) on different Windows versions, but
// Xinput.h specifies it in build time. Approach here uses the same values
// and it is resolving dll filename based on Windows version it is running on.
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
// For Windows 8 and 10, XINPUT_DLL is xinput1_4.dll.
return FILE_PATH_LITERAL("xinput1_4.dll");
} else if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
return FILE_PATH_LITERAL("xinput9_1_0.dll");
} else {
NOTREACHED();
return nullptr;
}
}

} // namespace

GamepadPlatformDataFetcherWin::GamepadPlatformDataFetcherWin()
: xinput_dll_(base::FilePath(FILE_PATH_LITERAL("xinput1_3.dll"))),
: xinput_dll_(base::FilePath(XInputDllFileName())),
xinput_available_(GetXInputDllFunctions()) {
for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) {
platform_pad_state_[i].status = DISCONNECTED;
Expand Down Expand Up @@ -317,10 +332,8 @@ void GamepadPlatformDataFetcherWin::GetRawInputPadData(
bool GamepadPlatformDataFetcherWin::GetXInputDllFunctions() {
xinput_get_capabilities_ = NULL;
xinput_get_state_ = NULL;
xinput_enable_ = reinterpret_cast<XInputEnableFunc>(
XInputEnableFunc xinput_enable = reinterpret_cast<XInputEnableFunc>(
xinput_dll_.GetFunctionPointer("XInputEnable"));
if (!xinput_enable_)
return false;
xinput_get_capabilities_ = reinterpret_cast<XInputGetCapabilitiesFunc>(
xinput_dll_.GetFunctionPointer("XInputGetCapabilities"));
if (!xinput_get_capabilities_)
Expand All @@ -329,7 +342,10 @@ bool GamepadPlatformDataFetcherWin::GetXInputDllFunctions() {
xinput_dll_.GetFunctionPointer("XInputGetState"));
if (!xinput_get_state_)
return false;
xinput_enable_(true);
if (xinput_enable) {
// XInputEnable is unavailable before Win8 and deprecated in Win10.
xinput_enable(true);
}
return true;
}

Expand Down
7 changes: 2 additions & 5 deletions content/browser/gamepad/gamepad_platform_data_fetcher_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
typedef DWORD (WINAPI *XInputGetStateFunc)(
DWORD dwUserIndex, XINPUT_STATE* pState);

// Get functions from dynamically loaded xinput1_3.dll. We don't use
// DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which
// isn't redistributable. Returns true if loading was successful. We include
// xinput1_3.dll with Chrome.
// Get functions from dynamically loading the xinput dll.
// Returns true if loading was successful.
bool GetXInputDllFunctions();

// Scan for connected XInput and DirectInput gamepads.
Expand All @@ -71,7 +69,6 @@ class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {

// Function pointers to XInput functionality, retrieved in
// |GetXinputDllFunctions|.
XInputEnableFunc xinput_enable_;
XInputGetCapabilitiesFunc xinput_get_capabilities_;
XInputGetStateFunc xinput_get_state_;

Expand Down
12 changes: 0 additions & 12 deletions content/content.gni

This file was deleted.

1 change: 0 additions & 1 deletion content/content.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'variables': {
'chromium_code': 1, # Use higher warning level.
'chromium_enable_vtune_jit_for_v8%': 0, # enable the vtune support for V8 engine.
'directxsdk_exists': '<!pymod_do_main(dir_exists ../third_party/directxsdk)',
},
'target_defaults': {
'defines': ['CONTENT_IMPLEMENTATION'],
Expand Down
24 changes: 0 additions & 24 deletions content/content_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1023,30 +1023,6 @@
'<(DEPTH)/third_party/khronos',
],
}],
['OS=="win" and directxsdk_exists=="True"', {
'actions': [
{
'action_name': 'extract_xinput',
'variables': {
'input': 'APR2007_xinput_<(winsdk_arch).cab',
'output': 'xinput1_3.dll',
},
'inputs': [
'../third_party/directxsdk/files/Redist/<(input)',
],
'outputs': [
'<(PRODUCT_DIR)/<(output)',
],
'action': [
'python',
'../build/extract_from_cab.py',
'..\\third_party\\directxsdk\\files\\Redist\\<(input)',
'<(output)',
'<(PRODUCT_DIR)',
],
},
]
}],
['use_seccomp_bpf==0', {
'sources!': [
'common/sandbox_linux/android/sandbox_bpf_base_policy_android.cc',
Expand Down
1 change: 0 additions & 1 deletion content/gpu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# found in the LICENSE file.

import("//build/config/ui.gni")
import("//content/content.gni")
import("//media/media_options.gni")

# See //content/BUILD.gn for how this works.
Expand Down
3 changes: 1 addition & 2 deletions tools/checkbins/checkbins.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
# Windows guru for advice.
EXCLUDED_FILES = ['chrome_frame_mini_installer.exe',
'mini_installer.exe',
'wow_helper.exe',
'xinput1_3.dll' # Microsoft DirectX redistributable.
'wow_helper.exe'
]

def IsPEFile(path):
Expand Down

0 comments on commit 5568924

Please sign in to comment.