/src/mozilla-central/gfx/tests/gtest/TestTextureCompatibility.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 "gfxConfig.h" |
8 | | #include "gfxPlatform.h" |
9 | | #include "gtest/gtest.h" |
10 | | #include "MockWidget.h" |
11 | | #include "mozilla/layers/BasicCompositor.h" |
12 | | #include "mozilla/layers/Compositor.h" |
13 | | #include "mozilla/layers/LayersTypes.h" |
14 | | #include "mozilla/layers/TextureClient.h" |
15 | | #include "mozilla/layers/TextureHost.h" |
16 | | #include "mozilla/RefPtr.h" |
17 | | #include "TestLayers.h" |
18 | | #include "TextureHelper.h" |
19 | | |
20 | | using mozilla::gfx::Feature; |
21 | | using mozilla::gfx::gfxConfig; |
22 | | using mozilla::layers::BasicCompositor; |
23 | | using mozilla::layers::Compositor; |
24 | | using mozilla::layers::CompositorOptions; |
25 | | using mozilla::layers::LayersBackend; |
26 | | using mozilla::layers::TestSurfaceAllocator; |
27 | | using mozilla::layers::TextureClient; |
28 | | using mozilla::layers::TextureHost; |
29 | | using mozilla::widget::CompositorWidget; |
30 | | using mozilla::widget::InProcessCompositorWidget; |
31 | | |
32 | | /** |
33 | | * This function will create the possible TextureClient and TextureHost pairs |
34 | | * according to the given backend. |
35 | | */ |
36 | | static void |
37 | | CreateTextureWithBackend(LayersBackend& aLayersBackend, |
38 | | ISurfaceAllocator* aDeallocator, |
39 | | nsTArray<RefPtr<TextureClient>>& aTextureClients, |
40 | | nsTArray<RefPtr<TextureHost>>& aTextureHosts) |
41 | 0 | { |
42 | 0 | aTextureClients.AppendElement(CreateTextureClientWithBackend(aLayersBackend)); |
43 | 0 |
|
44 | 0 | aTextureClients.AppendElement( |
45 | 0 | CreateYCbCrTextureClientWithBackend(aLayersBackend)); |
46 | 0 |
|
47 | 0 | for (uint32_t i = 0; i < aTextureClients.Length(); i++) { |
48 | 0 | aTextureHosts.AppendElement( |
49 | 0 | CreateTextureHostWithBackend(aTextureClients[i], aDeallocator, |
50 | 0 | aLayersBackend)); |
51 | 0 | } |
52 | 0 | } |
53 | | |
54 | | /** |
55 | | * This will return the default list of backends that units test should run |
56 | | * against. |
57 | | */ |
58 | | static void |
59 | | GetPlatformBackends(nsTArray<LayersBackend>& aBackends) |
60 | 0 | { |
61 | 0 | gfxPlatform* platform = gfxPlatform::GetPlatform(); |
62 | 0 | MOZ_ASSERT(platform); |
63 | 0 |
|
64 | 0 | platform->GetCompositorBackends( |
65 | 0 | gfxConfig::IsEnabled(Feature::HW_COMPOSITING), aBackends); |
66 | 0 |
|
67 | 0 | if (aBackends.IsEmpty()) { |
68 | 0 | aBackends.AppendElement(LayersBackend::LAYERS_BASIC); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | /** |
73 | | * This function will return a BasicCompositor to caller. |
74 | | */ |
75 | | already_AddRefed<Compositor> |
76 | | CreateBasicCompositor() |
77 | 0 | { |
78 | 0 | RefPtr<Compositor> compositor; |
79 | 0 | // Init the platform. |
80 | 0 | if (gfxPlatform::GetPlatform()) { |
81 | 0 | RefPtr<MockWidget> widget = new MockWidget(256, 256); |
82 | 0 | CompositorOptions options; |
83 | 0 | RefPtr<CompositorWidget> proxy |
84 | 0 | = new InProcessCompositorWidget(options, widget); |
85 | 0 | compositor = new BasicCompositor(nullptr, proxy); |
86 | 0 | } |
87 | 0 | return compositor.forget(); |
88 | 0 | } |
89 | | |
90 | | /** |
91 | | * This function checks if the textures react correctly when setting them to |
92 | | * BasicCompositor. |
93 | | */ |
94 | | void |
95 | | CheckCompatibilityWithBasicCompositor(LayersBackend aBackends, |
96 | | nsTArray<RefPtr<TextureHost>>& aTextures) |
97 | 0 | { |
98 | 0 | RefPtr<Compositor> compositor = CreateBasicCompositor(); |
99 | 0 | for (uint32_t i = 0; i < aTextures.Length(); i++) { |
100 | 0 | if (!aTextures[i]) { |
101 | 0 | continue; |
102 | 0 | } |
103 | 0 | aTextures[i]->SetTextureSourceProvider(compositor); |
104 | 0 |
|
105 | 0 | // The lock function will fail if the texture is not compatible with |
106 | 0 | // BasicCompositor. |
107 | 0 | bool lockResult = aTextures[i]->Lock(); |
108 | 0 | if (aBackends != LayersBackend::LAYERS_BASIC) { |
109 | 0 | EXPECT_FALSE(lockResult); |
110 | 0 | } else { |
111 | 0 | EXPECT_TRUE(lockResult); |
112 | 0 | } |
113 | 0 | if (lockResult) { |
114 | 0 | aTextures[i]->Unlock(); |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | TEST(Gfx, TestTextureCompatibility) |
120 | 0 | { |
121 | 0 | nsTArray<LayersBackend> backendHints; |
122 | 0 | RefPtr<TestSurfaceAllocator> deallocator = new TestSurfaceAllocator(); |
123 | 0 |
|
124 | 0 | GetPlatformBackends(backendHints); |
125 | 0 | for (uint32_t i = 0; i < backendHints.Length(); i++) { |
126 | 0 | nsTArray<RefPtr<TextureClient>> textureClients; |
127 | 0 | nsTArray<RefPtr<TextureHost>> textureHosts; |
128 | 0 |
|
129 | 0 | CreateTextureWithBackend(backendHints[i], deallocator, |
130 | 0 | textureClients, textureHosts); |
131 | 0 | CheckCompatibilityWithBasicCompositor(backendHints[i], textureHosts); |
132 | 0 | } |
133 | 0 | } |