~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to src/client/android/gralloc_registrar.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Daniel van Vugt
  • Date: 2014-07-17 07:58:53 UTC
  • mfrom: (1.1.67)
  • Revision ID: package-import@ubuntu.com-20140717075853-s4i71ob3iq4ns49z
Tags: 0.5.0+14.10.20140717-0ubuntu1
[ Daniel van Vugt ]
* New upstream release 0.5.0 (https://launchpad.net/mir/+milestone/0.5.0)
  - mirclient ABI unchanged at 8. Clients do not need rebuilding.
  - mirserver ABI bumped to 23. Servers need rebuilding, but probably don't
    need modification:
    . DefaultServerConfiguration/Cursor API: Cursor interfaces changed, most
      notably CursorImages moved from ::mir::graphics to ::mir::input.
    . DefaultServerConfiguration: New "prompt" API.
    . DefaultServerConfiguration: "clock" member is now static.
    . SessionAuthorizer: New functions.
    . ServerConfiguration: New function added: the_prompt_connector().
  - Enhancements:
    . Add AddressSanitizer cmake build type.
    . frontend, client API, tests: add support for prompt session
      permissions and for client detecting errors.
    . server: Ensure our emergency cleanup handling infrastructure is
      signal-safe.
    . Implement and enable an xcursor based image loader for cursors.
    . Fix warnings raised by the new g++-4.9.
    . shared, scene: Introduce a generic listener collection.
    . MirMotionEvent: Define a struct typedef to allow for
      pointer_coordinates to be used individually.
  - Bugs fixed:
    . Nexus 10 leaks during overlay operations (LP: #1331769)
    . MultiThreadedCompositor deadlocks (LP: #1335311)
    . Intermittent test failure in ClientSurfaceEvents can client query 
      orientation (LP: #1335741)
    . Intermittent test failure in ClientSurfaceEvents/OrientationEvents
      (LP: #1335752)
    . Intermittent memory error in ClientSurfaceEvents on
      orientation query (LP: #1335819)
    . mir_unit_tests.EventDistributorTest.* SEGFAULT (LP: #1338902)
    . [regression] Device locks randomly on welcome screen (LP: #1339700)
    . Intermittent deadlock when switching to session with custom display
      config & closing other session (LP: #1340669)
    . Mir cursor has no hotspot setting, assumes (0, 0) (LP: #1189775)
    . clang built mir_unit_tests.ProtobufSocketCommunicatorFD crashes
      intermittently (LP: #1300653)
    . g++-4.9 binary incompatibilities with libraries built with g++-4.8
      (LP: #1329089)
    . [test regression] SurfaceLoop fails sporadically on deleting surfaces
      for a disconnecting client (LP: #1335747)
    . Intermittent test failure ServerShutdown when clients are blocked
      (LP: #1335873)
    . [regression] mir_demo_client_multiwin is displayed with obviously
      wrong colours (LP: #1339471)
    . Partially onscreen surfaces not occluded when covered by another
      surface (LP: #1340078)
    . SurfaceConfigurator::attribute_set always say "unfocused" for focus
      property changes (LP: #1336548)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3,
 
6
 * as published by the Free Software Foundation.
 
7
 *
 
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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Kevin DuBois<kevin.dubois@canonical.com>
 
17
 */
 
18
 
 
19
#include "gralloc_registrar.h"
 
20
#include "../client_buffer.h"
 
21
 
 
22
#include <boost/throw_exception.hpp>
 
23
#include <stdexcept>
 
24
 
 
25
namespace mcl=mir::client;
 
26
namespace mcla=mir::client::android;
 
27
namespace geom=mir::geometry;
 
28
 
 
29
namespace
 
30
{
 
31
struct NativeHandleDeleter
 
32
{
 
33
    NativeHandleDeleter(const std::shared_ptr<const gralloc_module_t>& mod)
 
34
        : module(mod)
 
35
    {}
 
36
 
 
37
    void operator()(const native_handle_t* t)
 
38
    {
 
39
        module->unregisterBuffer(module.get(), t);
 
40
        for(auto i = 0; i < t->numFds; i++)
 
41
        {
 
42
            close(t->data[i]);
 
43
        }
 
44
        ::operator delete(const_cast<native_handle_t*>(t));
 
45
    }
 
46
private:
 
47
    const std::shared_ptr<const gralloc_module_t> module;
 
48
};
 
49
 
 
50
struct MemoryRegionDeleter
 
51
{
 
52
    MemoryRegionDeleter(const std::shared_ptr<const gralloc_module_t>& mod,
 
53
                        const std::shared_ptr<const native_handle_t>&  han)
 
54
     : handle(han),
 
55
       module(mod)
 
56
    {}
 
57
 
 
58
    void operator()(char *)
 
59
    {
 
60
        module->unlock(module.get(), handle.get());
 
61
        //we didn't alloc region(just mapped it), so we don't delete
 
62
    }
 
63
private:
 
64
    const std::shared_ptr<const native_handle_t>  handle;
 
65
    const std::shared_ptr<const gralloc_module_t> module;
 
66
};
 
67
}
 
68
 
 
69
mcla::GrallocRegistrar::GrallocRegistrar(const std::shared_ptr<const gralloc_module_t>& gr_module)
 
70
: gralloc_module(gr_module)
 
71
{
 
72
}
 
73
 
 
74
std::shared_ptr<const native_handle_t> mcla::GrallocRegistrar::register_buffer(
 
75
    std::shared_ptr<MirBufferPackage> const& package) const
 
76
{
 
77
    int native_handle_header_size = sizeof(native_handle_t);
 
78
    int total_size = sizeof(int) *
 
79
                     (package->fd_items + package->data_items + native_handle_header_size);
 
80
    native_handle_t* handle = static_cast<native_handle_t*>(::operator new(total_size));
 
81
    handle->version = native_handle_header_size;
 
82
    handle->numFds  = package->fd_items;
 
83
    handle->numInts = package->data_items;
 
84
    for (auto i=0; i< handle->numFds; i++)
 
85
    {
 
86
        handle->data[i] = package->fd[i];
 
87
    }
 
88
 
 
89
    int offset_i = handle->numFds;
 
90
    for (auto i=0; i< handle->numInts; i++)
 
91
    {
 
92
        handle->data[offset_i+i] = package->data[i];
 
93
    }
 
94
 
 
95
    if ( gralloc_module->registerBuffer(gralloc_module.get(), handle) )
 
96
    {
 
97
        ::operator delete(const_cast<native_handle_t*>(handle));
 
98
        BOOST_THROW_EXCEPTION(std::runtime_error("error registering graphics buffer for client use\n"));
 
99
    }
 
100
 
 
101
    NativeHandleDeleter del(gralloc_module);
 
102
    return std::shared_ptr<const native_handle_t>(handle, del);
 
103
}
 
104
 
 
105
std::shared_ptr<char> mcla::GrallocRegistrar::secure_for_cpu(
 
106
    std::shared_ptr<const native_handle_t> handle,
 
107
    const geometry::Rectangle rect)
 
108
{
 
109
    char* vaddr;
 
110
    int usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
 
111
    int width = rect.size.width.as_uint32_t();
 
112
    int height = rect.size.height.as_uint32_t();
 
113
    int top = rect.top_left.x.as_uint32_t();
 
114
    int left = rect.top_left.y.as_uint32_t();
 
115
    if ( gralloc_module->lock(gralloc_module.get(), handle.get(),
 
116
                              usage, top, left, width, height, (void**) &vaddr) )
 
117
        BOOST_THROW_EXCEPTION(std::runtime_error("error securing buffer for client cpu use"));
 
118
 
 
119
    MemoryRegionDeleter del(gralloc_module, handle);
 
120
    return std::shared_ptr<char>(vaddr, del);
 
121
}