2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "src/server/graphics/android/internal_client_window.h"
20
#include "mir_test_doubles/mock_buffer.h"
21
#include "mir_test_doubles/mock_swapper.h"
22
#include "mir_test_doubles/mock_interpreter_resource_cache.h"
23
#include "mir/frontend/surface.h"
25
#include <gtest/gtest.h>
28
namespace mc=mir::compositor;
29
namespace mtd=mir::test::doubles;
30
namespace mga=mir::graphics::android;
31
namespace geom=mir::geometry;
32
namespace mf=mir::frontend;
36
struct MockSurface : public mf::Surface
38
MOCK_METHOD0(destroy, void());
39
MOCK_METHOD0(force_requests_to_complete, void());
40
MOCK_CONST_METHOD0(size, geom::Size());
41
MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat());
43
MOCK_METHOD0(advance_client_buffer, void());
44
MOCK_CONST_METHOD0(client_buffer, std::shared_ptr<mc::Buffer>());
46
MOCK_CONST_METHOD0(supports_input, bool());
47
MOCK_CONST_METHOD0(client_input_fd, int());
48
MOCK_METHOD2(configure, int(MirSurfaceAttrib, int));
51
struct InternalClientWindow : public ::testing::Test
55
using namespace testing;
56
sz = geom::Size{geom::Width{4}, geom::Height{23}};
57
pf = geom::PixelFormat::abgr_8888;
58
mock_cache = std::make_shared<mtd::MockInterpreterResourceCache>();
59
mock_surface = std::make_shared<MockSurface>();
60
mock_buffer = std::make_shared<mtd::MockBuffer>();
61
stub_anw = std::make_shared<ANativeWindowBuffer>();
63
ON_CALL(*mock_surface, client_buffer())
64
.WillByDefault(Return(mock_buffer));
65
ON_CALL(*mock_surface, pixel_format())
66
.WillByDefault(Return(geom::PixelFormat::abgr_8888));
67
ON_CALL(*mock_buffer, native_buffer_handle())
68
.WillByDefault(Return(stub_anw));
71
std::shared_ptr<ANativeWindowBuffer> stub_anw;
72
std::shared_ptr<mtd::MockInterpreterResourceCache> mock_cache;
73
std::shared_ptr<MockSurface> mock_surface;
74
std::shared_ptr<mtd::MockBuffer> mock_buffer;
80
TEST_F(InternalClientWindow, driver_requests_buffer)
82
using namespace testing;
83
EXPECT_CALL(*mock_surface, client_buffer())
85
EXPECT_CALL(*mock_buffer, native_buffer_handle())
87
std::shared_ptr<mc::Buffer> tmp = mock_buffer;
88
EXPECT_CALL(*mock_cache, store_buffer(tmp, stub_anw.get()))
91
mga::InternalClientWindow interpreter(mock_surface, mock_cache);
92
auto test_buffer = interpreter.driver_requests_buffer();
93
EXPECT_EQ(stub_anw.get(), test_buffer);
96
TEST_F(InternalClientWindow, driver_returns_buffer)
98
using namespace testing;
99
std::shared_ptr<mga::SyncObject> fake_sync;
101
EXPECT_CALL(*mock_cache, retrieve_buffer(stub_anw.get()))
103
.WillOnce(Return(mock_buffer));
105
mga::InternalClientWindow interpreter(mock_surface, mock_cache);
106
auto test_bufferptr = interpreter.driver_requests_buffer();
107
interpreter.driver_returns_buffer(test_bufferptr, fake_sync);
110
TEST_F(InternalClientWindow, size_test)
112
using namespace testing;
113
EXPECT_CALL(*mock_surface, size())
115
.WillOnce(Return(sz))
116
.WillOnce(Return(sz));
117
mga::InternalClientWindow interpreter(mock_surface, mock_cache);
119
unsigned int rc_width = interpreter.driver_requests_info(NATIVE_WINDOW_WIDTH);
120
unsigned int rc_height = interpreter.driver_requests_info(NATIVE_WINDOW_HEIGHT);
122
EXPECT_EQ(sz.width.as_uint32_t(), rc_width);
123
EXPECT_EQ(sz.height.as_uint32_t(), rc_height);
126
TEST_F(InternalClientWindow, driver_default_format)
128
using namespace testing;
129
EXPECT_CALL(*mock_surface, pixel_format())
132
mga::InternalClientWindow interpreter(mock_surface, mock_cache);
134
auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT);
135
EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format);
138
TEST_F(InternalClientWindow, driver_sets_format)
140
using namespace testing;
141
EXPECT_CALL(*mock_surface, pixel_format())
143
.WillRepeatedly(Return(geom::PixelFormat::abgr_8888));
144
mga::InternalClientWindow interpreter(mock_surface, mock_cache);
146
interpreter.dispatch_driver_request_format(HAL_PIXEL_FORMAT_RGBA_8888);
147
auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT);
148
EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format);