~kgunn72/mir/dont-crash-when-shooting-invalid-surface

« back to all changes in this revision

Viewing changes to src/platform/graphics/android/internal_client_window.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths, Alexandros Frantzis, Daniel van Vugt, Kevin DuBois, Christopher James Halse Rogers, chris.gagnon, Mathieu Trudel-Lapierre, Robert Carr, Automatic PS uploader, Kevin Gunn, Daniel d'Andrada, Christopher James Halse Rogers, Michael Terry, Brandon Schaefer, Timo Jyrinki, Mir Team, Andreas Pokorny
  • Date: 2013-12-20 11:11:22 UTC
  • mfrom: (1169.1.1 version-0.1.3)
  • Revision ID: tarmac-20131220111122-h503fd1fnq7pn9za
Latest upstream release: Mir 0.1.3 (r1298).

Approved by Alan Griffiths, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright © 2013 Canonical Ltd.
3
3
 *
4
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
 
5
 * it under the terms of the GNU Lesser General Public License version 3 as
6
6
 * published by the Free Software Foundation.
7
7
 *
8
8
 * This program is distributed in the hope that it will be useful,
9
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
 
11
 * GNU Lesser General Public License for more details.
12
12
 *
13
 
 * You should have received a copy of the GNU General Public License
 
13
 * You should have received a copy of the GNU Lesser General Public License
14
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 *
16
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
30
30
namespace mga=mg::android;
31
31
namespace geom=mir::geometry;
32
32
 
33
 
mga::InternalClientWindow::InternalClientWindow(std::shared_ptr<InternalSurface> const& surface,
34
 
                                                std::shared_ptr<InterpreterResourceCache> const& cache)
 
33
mga::InternalClientWindow::InternalClientWindow(std::shared_ptr<InternalSurface> const& surface)
35
34
    : surface(surface),
36
 
      resource_cache(cache)
 
35
      buffer(nullptr)
37
36
{
38
 
    format = mga::to_android_format(geometry::PixelFormat(surface->pixel_format()));
 
37
    format = mga::to_android_format(MirPixelFormat(surface->pixel_format()));
39
38
}
40
39
 
41
40
mg::NativeBuffer* mga::InternalClientWindow::driver_requests_buffer()
42
41
{
43
 
    auto buffer = surface->advance_client_buffer();
 
42
    if (!buffer)
 
43
    {
 
44
        surface->swap_buffers(buffer);
 
45
    }
 
46
 
44
47
    auto handle = buffer->native_buffer_handle();
45
 
    resource_cache->store_buffer(buffer, handle);
 
48
    lookup[handle->anwb()] = {buffer, handle};
 
49
 
 
50
    buffer = nullptr;
 
51
 
46
52
    return handle.get();
47
53
}
48
54
 
49
 
void mga::InternalClientWindow::driver_returns_buffer(ANativeWindowBuffer* buffer, int fence_fd)
 
55
void mga::InternalClientWindow::driver_returns_buffer(ANativeWindowBuffer* key, int fence_fd)
50
56
{
51
 
    resource_cache->update_native_fence(buffer, fence_fd);
52
 
    resource_cache->retrieve_buffer(buffer);
53
 
    /* here, the mc::TemporaryBuffer will destruct, triggering buffer advance */
 
57
    auto it = lookup.find(key);
 
58
    if (it == lookup.end())
 
59
    {
 
60
        BOOST_THROW_EXCEPTION(std::runtime_error("driver is returning buffers it never was given!"));
 
61
    }
 
62
 
 
63
    auto handle = it->second.handle;
 
64
    buffer = it->second.buffer;
 
65
    lookup.erase(it);
 
66
 
 
67
    handle->update_fence(fence_fd);
 
68
    surface->swap_buffers(buffer);
54
69
}
55
70
 
56
71
void mga::InternalClientWindow::dispatch_driver_request_format(int request_format)
74
89
        case NATIVE_WINDOW_FORMAT:
75
90
            return format;
76
91
        case NATIVE_WINDOW_TRANSFORM_HINT:
77
 
            return 0; 
 
92
            return 0;
78
93
        case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
79
94
            return 1;
80
95
        default: