1 // Copyright 2015 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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/gl/gl_surface_egl.h"
10 TEST(EGLInitializationDisplaysTest
, DisableD3D11
) {
11 scoped_ptr
<base::CommandLine
> command_line(
12 new base::CommandLine(base::CommandLine::NO_PROGRAM
));
14 std::vector
<gfx::DisplayType
> displays
;
16 // using --disable-d3d11 with the default --use-angle should never return
18 command_line
->AppendSwitch(switches::kDisableD3D11
);
19 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
20 EXPECT_EQ(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_D3D11
),
23 // Specifically requesting D3D11 should always return it if the extension is
25 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
26 gfx::kANGLEImplementationD3D11Name
);
28 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
29 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_D3D11
),
31 EXPECT_EQ(displays
.size(), 1u);
33 // Specifically requesting D3D11 should not return D3D11 if the extension is
36 GetEGLInitDisplays(false, true, command_line
.get(), &displays
);
37 EXPECT_EQ(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_D3D11
),
41 TEST(EGLInitializationDisplaysTest
, SwiftShader
) {
42 scoped_ptr
<base::CommandLine
> command_line(
43 new base::CommandLine(base::CommandLine::NO_PROGRAM
));
45 std::vector
<gfx::DisplayType
> displays
;
47 // If swiftshader is requested, only SWIFT_SHADER should be returned
48 command_line
->AppendSwitchASCII(switches::kUseGL
,
49 gfx::kGLImplementationSwiftShaderName
);
51 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
52 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::SWIFT_SHADER
),
54 EXPECT_EQ(displays
.size(), 1u);
56 // Even if there are other flags, swiftshader should take prescedence
57 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
58 gfx::kANGLEImplementationD3D11Name
);
60 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
61 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::SWIFT_SHADER
),
63 EXPECT_EQ(displays
.size(), 1u);
66 TEST(EGLInitializationDisplaysTest
, DefaultRenderers
) {
67 scoped_ptr
<base::CommandLine
> command_line(
68 new base::CommandLine(base::CommandLine::NO_PROGRAM
));
70 // Default without --use-angle flag
71 std::vector
<gfx::DisplayType
> default_no_flag_displays
;
72 GetEGLInitDisplays(true, true, command_line
.get(), &default_no_flag_displays
);
73 EXPECT_FALSE(default_no_flag_displays
.empty());
75 // Default with --use-angle flag
76 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
77 gfx::kANGLEImplementationDefaultName
);
78 std::vector
<gfx::DisplayType
> default_with_flag_displays
;
79 GetEGLInitDisplays(true, true, command_line
.get(),
80 &default_with_flag_displays
);
81 EXPECT_FALSE(default_with_flag_displays
.empty());
83 // Make sure the same results are returned
84 EXPECT_EQ(default_no_flag_displays
, default_with_flag_displays
);
87 TEST(EGLInitializationDisplaysTest
, NonDefaultRenderers
) {
88 scoped_ptr
<base::CommandLine
> command_line(
89 new base::CommandLine(base::CommandLine::NO_PROGRAM
));
91 std::vector
<gfx::DisplayType
> displays
;
94 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
95 gfx::kANGLEImplementationWARPName
);
97 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
98 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_WARP
),
100 EXPECT_EQ(displays
.size(), 1u);
103 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
104 gfx::kANGLEImplementationOpenGLName
);
106 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
107 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_OPENGL
),
109 EXPECT_EQ(displays
.size(), 1u);
112 command_line
->AppendSwitchASCII(switches::kUseANGLE
,
113 gfx::kANGLEImplementationOpenGLESName
);
115 GetEGLInitDisplays(true, true, command_line
.get(), &displays
);
116 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::ANGLE_OPENGLES
),
118 EXPECT_EQ(displays
.size(), 1u);
121 TEST(EGLInitializationDisplaysTest
, NoExtensions
) {
122 scoped_ptr
<base::CommandLine
> command_line(
123 new base::CommandLine(base::CommandLine::NO_PROGRAM
));
125 // With no angle platform extensions, only DEFAULT should be available
126 std::vector
<gfx::DisplayType
> displays
;
127 GetEGLInitDisplays(false, false, command_line
.get(), &displays
);
128 EXPECT_NE(std::find(displays
.begin(), displays
.end(), gfx::DEFAULT
),
130 EXPECT_EQ(displays
.size(), 1u);