~alan-griffiths/mir/fix-1654023

« back to all changes in this revision

Viewing changes to src/client/mir_render_surface_api.cpp

  • Committer: Daniel van Vugt
  • Date: 2016-12-13 06:00:32 UTC
  • mfrom: (3880 development-branch)
  • mto: This revision was merged to the branch mainline in revision 3882.
  • Revision ID: daniel.van.vugt@canonical.com-20161213060032-9x9y9j18av0ayj3z
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
class RenderSurfaceToConnectionMap
57
57
{
58
58
public:
59
 
    void insert(void* const render_surface_key, MirConnection* const connection)
 
59
    void insert(MirRenderSurface* render_surface_key, MirConnection* connection)
60
60
    {
61
61
        std::lock_guard<decltype(guard)> lk(guard);
62
62
        connections[render_surface_key] = connection;
63
63
    }
64
64
 
65
 
    void erase(void* const render_surface_key)
 
65
    void erase(MirRenderSurface* render_surface_key)
66
66
    {
67
67
        std::lock_guard<decltype(guard)> lk(guard);
68
68
        auto conn_it = connections.find(render_surface_key);
70
70
            connections.erase(conn_it);
71
71
    }
72
72
 
73
 
    MirConnection* connection(void* const render_surface_key) const
 
73
    MirConnection* connection(MirRenderSurface* render_surface_key) const
74
74
    {
75
75
        std::shared_lock<decltype(guard)> lk(guard);
76
76
        auto const it = connections.find(render_surface_key);
81
81
    }
82
82
private:
83
83
    std::shared_timed_mutex mutable guard;
84
 
    std::unordered_map<void*, MirConnection*> connections;
 
84
    std::unordered_map<MirRenderSurface*, MirConnection*> connections;
85
85
};
86
86
 
87
87
RenderSurfaceToConnectionMap connection_map;
95
95
try
96
96
{
97
97
    mir::require(connection);
98
 
    void* rs = nullptr;
99
 
    connection->create_render_surface_with_content(
100
 
        mir::geometry::Size{width, height}, callback, context, &rs);
101
 
    if (!rs)
 
98
    if (auto rs = connection->create_render_surface_with_content({width, height}, callback, context))
 
99
    {
 
100
        connection_map.insert(rs, connection);
 
101
    }
 
102
    else
 
103
    {
102
104
        BOOST_THROW_EXCEPTION(std::runtime_error("Error creating native window"));
103
 
    connection_map.insert(rs, connection);
 
105
    }
104
106
}
105
107
catch (std::exception const& ex)
106
108
{
131
133
try
132
134
{
133
135
    mir::require(render_surface);
134
 
    auto conn = connection_map.connection(static_cast<void*>(render_surface));
 
136
    auto conn = connection_map.connection(render_surface);
135
137
    auto rs = conn->connection_surface_map()->render_surface(render_surface);
136
138
    mir::require(rs != nullptr);
137
139
    return rs->valid();
147
149
try
148
150
{
149
151
    mir::require(render_surface);
150
 
    auto conn = connection_map.connection(static_cast<void*>(render_surface));
 
152
    auto conn = connection_map.connection(render_surface);
151
153
    auto rs = conn->connection_surface_map()->render_surface(render_surface);
152
154
    return rs->get_error_message();
153
155
}
162
164
try
163
165
{
164
166
    mir::require(render_surface);
165
 
    auto connection = connection_map.connection(static_cast<void*>(render_surface));
166
 
    connection_map.erase(static_cast<void*>(render_surface));
 
167
    auto connection = connection_map.connection(render_surface);
 
168
    connection_map.erase(render_surface);
167
169
    connection->release_render_surface_with_content(render_surface);
168
170
}
169
171
catch (std::exception const& ex)
179
181
try
180
182
{
181
183
    mir::require(render_surface);
182
 
    auto connection = connection_map.connection(static_cast<void*>(render_surface));
 
184
    auto connection = connection_map.connection(render_surface);
183
185
    auto rs = connection->connection_surface_map()->render_surface(render_surface);
184
186
    return rs->get_buffer_stream(width, height, format, usage);
185
187
}
194
196
try
195
197
{
196
198
    mir::require(render_surface);
197
 
    auto connection = connection_map.connection(static_cast<void*>(render_surface));
 
199
    auto connection = connection_map.connection(render_surface);
198
200
    auto rs = connection->connection_surface_map()->render_surface(render_surface);
199
201
    return rs->get_presentation_chain();
200
202
}
207
209
void mir_render_surface_get_size(MirRenderSurface* render_surface, int* width, int* height)
208
210
{
209
211
    mir::require(render_surface && width && height);
210
 
    auto connection = connection_map.connection(static_cast<void*>(render_surface));
 
212
    auto connection = connection_map.connection(render_surface);
211
213
    auto rs = connection->connection_surface_map()->render_surface(render_surface);
212
214
    auto size = rs->size();
213
215
    *width = size.width.as_int();
217
219
void mir_render_surface_set_size(MirRenderSurface* render_surface, int width, int height)
218
220
{
219
221
    mir::require(render_surface);
220
 
    auto connection = connection_map.connection(static_cast<void*>(render_surface));
 
222
    auto connection = connection_map.connection(render_surface);
221
223
    auto rs = connection->connection_surface_map()->render_surface(render_surface);
222
224
    rs->set_size({width, height});
223
225
}
227
229
    MirRenderSurface* surface,
228
230
    int hotspot_x, int hotspot_y)
229
231
{
230
 
    auto connection = connection_map.connection(static_cast<void*>(surface));
 
232
    auto connection = connection_map.connection(surface);
231
233
    auto rs = connection->connection_surface_map()->render_surface(surface);
232
234
    spec->rendersurface_cursor = MirSurfaceSpec::RenderSurfaceCursor{rs->stream_id(), {hotspot_x, hotspot_y}};
233
235
}