~mir-team/mir/development-branch

« back to all changes in this revision

Viewing changes to tests/integration-tests/client/test_client_render.cpp

  • Committer: Daniel van Vugt
  • Author(s): Kevin DuBois
  • Date: 2013-11-13 02:55:46 UTC
  • mfrom: (1062.1.23 mali-client-render-support)
  • Revision ID: daniel.van.vugt@canonical.com-20131113025546-2u059ffogt5yj2yz
android: support driver hooks for the Mali T604 (present in nexus 10)

The exynos driver needed some function hooks implemented. This change
implements those hooks and gets the TestClientIPCRender test to pass. This
test sends buffers over IPC to a client, and the client then establishes an
egl context, renders to the buffer, and checks the buffer content back on the
server side.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
{
51
51
static int test_width  = 300;
52
52
static int test_height = 200;
53
 
 
54
53
static uint32_t pattern0 [2][2] = {{0x12345678, 0x23456789},
55
54
                                   {0x34567890, 0x45678901}};
56
55
static uint32_t pattern1 [2][2] = {{0xFFFFFFFF, 0xFFFF0000},
61
60
 
62
61
struct TestClient
63
62
{
 
63
    static MirPixelFormat select_format_for_visual_id(int visual_id)
 
64
    {
 
65
        if (visual_id == 5)
 
66
            return mir_pixel_format_argb_8888;
 
67
        if (visual_id == 1)
 
68
            return mir_pixel_format_abgr_8888;
 
69
 
 
70
        return mir_pixel_format_invalid;
 
71
    }
 
72
 
 
73
    static MirSurface* create_mir_surface(MirConnection * connection, EGLDisplay display, EGLConfig config)
 
74
    {
 
75
        int visual_id;
 
76
        eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visual_id);
 
77
 
 
78
        /* make surface */
 
79
        MirSurfaceParameters surface_parameters;
 
80
        surface_parameters.name = "testsurface";
 
81
        surface_parameters.width = test_width;
 
82
        surface_parameters.height = test_height;
 
83
        surface_parameters.pixel_format = select_format_for_visual_id(visual_id);
 
84
        return mir_connection_create_surface_sync(connection, &surface_parameters);
 
85
    }
 
86
 
64
87
    static int render_cpu_pattern(mtf::CrossProcessSync& process_sync, int num_frames)
65
88
    {
66
89
        process_sync.wait_for_signal_ready_for();
107
130
 
108
131
        /* set up egl context */
109
132
        int major, minor, n;
110
 
        EGLDisplay disp;
111
133
        EGLContext context;
112
134
        EGLSurface egl_surface;
113
135
        EGLConfig egl_config;
114
136
        EGLint attribs[] = {
115
137
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
116
 
            EGL_GREEN_SIZE, 8,
 
138
            EGL_BUFFER_SIZE, 32,
117
139
            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
118
140
            EGL_NONE };
119
141
        EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
120
142
 
121
 
        EGLNativeDisplayType native_display = (EGLNativeDisplayType)mir_connection_get_egl_native_display(connection);
122
 
        EGLNativeWindowType native_window = (EGLNativeWindowType) mir_surface_get_egl_native_window(surface);
123
 
 
124
 
        disp = eglGetDisplay(native_display);
125
 
        eglInitialize(disp, &major, &minor);
126
 
 
127
 
        eglChooseConfig(disp, attribs, &egl_config, 1, &n);
128
 
        egl_surface = eglCreateWindowSurface(disp, egl_config, native_window, NULL);
129
 
        context = eglCreateContext(disp, egl_config, EGL_NO_CONTEXT, context_attribs);
130
 
        eglMakeCurrent(disp, egl_surface, egl_surface, context);
 
143
        auto native_display = mir_connection_get_egl_native_display(connection);
 
144
        auto egl_display = eglGetDisplay(native_display);
 
145
        eglInitialize(egl_display, &major, &minor);
 
146
        eglChooseConfig(egl_display, attribs, &egl_config, 1, &n); 
 
147
 
 
148
        auto mir_surface = create_mir_surface(connection, egl_display, egl_config); 
 
149
        auto native_window = static_cast<EGLNativeWindowType>(
 
150
            mir_surface_get_egl_native_window(mir_surface)); 
 
151
    
 
152
        egl_surface = eglCreateWindowSurface(egl_display, egl_config, native_window, NULL);
 
153
        context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attribs);
 
154
        eglMakeCurrent(egl_display, egl_surface, egl_surface, context);
131
155
 
132
156
        for (auto i=0; i < num_frames; i++)
133
157
        {
146
170
            }
147
171
            glClear(GL_COLOR_BUFFER_BIT);
148
172
 
149
 
            eglSwapBuffers(disp, egl_surface);
 
173
            eglSwapBuffers(egl_display, egl_surface);
150
174
        }
151
175
 
152
176
        mir_surface_release_sync(surface);
153
177
        mir_connection_release(connection);
154
178
        return 0;
155
 
 
156
179
    }
157
180
 
158
181
    static int exit_function()
165
188
struct StubServerGenerator : public mt::StubServerTool
166
189
{
167
190
    StubServerGenerator()
168
 
     : next_received(false),
169
 
       next_allowed(false)
170
191
    {
171
192
        auto initializer = std::make_shared<mg::NullBufferInitializer>();
172
193
        allocator = std::make_shared<mga::AndroidGraphicBufferAllocator> (initializer);
173
194
        auto size = geom::Size{test_width, test_height};
174
 
        auto pf = geom::PixelFormat::abgr_8888;
175
 
        last_posted = allocator->alloc_buffer_platform(size, pf, mga::BufferUsage::use_hardware);
176
 
        client_buffer = allocator->alloc_buffer_platform(size, pf, mga::BufferUsage::use_hardware);
 
195
        surface_pf = geom::PixelFormat::abgr_8888;
 
196
        last_posted = allocator->alloc_buffer_platform(size, surface_pf, mga::BufferUsage::use_hardware);
 
197
        client_buffer = allocator->alloc_buffer_platform(size, surface_pf, mga::BufferUsage::use_hardware);
177
198
    }
178
199
 
179
200
    void create_surface(google::protobuf::RpcController* /*controller*/,
184
205
        response->mutable_id()->set_value(13);
185
206
        response->set_width(test_width);
186
207
        response->set_height(test_height);
 
208
        surface_pf = geom::PixelFormat(request->pixel_format());
187
209
        response->set_pixel_format(request->pixel_format());
188
210
        response->mutable_buffer()->set_buffer_id(client_buffer->id().as_uint32_t());
189
211
 
190
212
        auto buf = client_buffer->native_buffer_handle();
191
 
        response->mutable_buffer()->set_stride(buf->anwb()->stride);
 
213
        //note about the stride. Mir protocol sends stride in bytes, android uses stride in pixels
 
214
        response->mutable_buffer()->set_stride(client_buffer->stride().as_uint32_t());
192
215
 
193
216
        response->mutable_buffer()->set_fds_on_side_channel(1);
194
217
        native_handle_t const* native_handle = buf->handle();
195
218
        for(auto i=0; i<native_handle->numFds; i++)
196
219
            response->mutable_buffer()->add_fd(native_handle->data[i]);
197
 
        for(auto i=0; i<native_handle->numInts; i++)
 
220
        for(auto i=0; i < native_handle->numInts; i++)
198
221
            response->mutable_buffer()->add_data(native_handle->data[native_handle->numFds+i]);
199
222
 
200
223
        std::unique_lock<std::mutex> lock(guard);
216
239
        response->set_buffer_id(client_buffer->id().as_uint32_t());
217
240
 
218
241
        auto buf = client_buffer->native_buffer_handle();
219
 
 
220
242
        response->set_fds_on_side_channel(1);
221
243
        native_handle_t const* native_handle = buf->handle();
222
 
        response->set_stride(buf->anwb()->stride);
 
244
        response->set_stride(client_buffer->stride().as_uint32_t());
223
245
        for(auto i=0; i<native_handle->numFds; i++)
224
246
            response->add_fd(native_handle->data[i]);
225
247
        for(auto i=0; i<native_handle->numInts; i++)
226
248
            response->add_data(native_handle->data[native_handle->numFds+i]);
227
 
 
228
 
 
229
249
        done->Run();
230
250
    }
231
251
 
 
252
    uint32_t red_value_for_surface()
 
253
    {
 
254
        if ((surface_pf == geom::PixelFormat::abgr_8888) || (surface_pf == geom::PixelFormat::xbgr_8888))
 
255
            return 0xFF0000FF;
 
256
 
 
257
        if ((surface_pf == geom::PixelFormat::argb_8888) || (surface_pf == geom::PixelFormat::xrgb_8888))
 
258
            return 0xFFFF0000;
 
259
 
 
260
        return 0x0;
 
261
    }
 
262
 
 
263
    uint32_t green_value_for_surface()
 
264
    {
 
265
        return 0xFF00FF00;
 
266
    }
 
267
 
232
268
    std::shared_ptr<mga::Buffer> second_to_last_posted_buffer()
233
269
    {
234
270
        std::unique_lock<std::mutex> lk(buffer_mutex);
245
281
    std::shared_ptr<mga::AndroidGraphicBufferAllocator> allocator;
246
282
    std::shared_ptr<mga::Buffer> client_buffer;
247
283
    std::shared_ptr<mga::Buffer> last_posted;
248
 
 
249
284
    std::mutex buffer_mutex;
250
 
    std::condition_variable next_cv;
251
 
    std::condition_variable allow_cv;
252
 
    bool next_received;
253
 
    bool next_allowed;
254
 
 
255
 
    int handle_id;
 
285
    geom::PixelFormat surface_pf;
256
286
};
257
287
 
258
288
}