~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/draw/android_graphics.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
Import upstream version 0.1.6+14.04.20140310

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
5
 
 * it under the terms of the GNU General Public License version 3 as
6
 
 * 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 General Public License for more details.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17
 
 */
18
 
 
19
 
 
20
 
#include "mir_test/draw/android_graphics.h"
21
 
#include "mir_toolkit/common.h"
22
 
 
23
 
#include <fstream>
24
 
#include <stdexcept>
25
 
#include <dirent.h>
26
 
#include <fnmatch.h>
27
 
 
28
 
namespace mtd=mir::test::draw;
29
 
namespace mc=mir::compositor;
30
 
namespace geom=mir::geometry;
31
 
 
32
 
namespace
33
 
{
34
 
struct RegionDeleter
35
 
{
36
 
    RegionDeleter(gralloc_module_t* grmod, native_handle_t const* handle)
37
 
     : grmod(grmod),
38
 
       handle(handle)
39
 
    {
40
 
    }
41
 
 
42
 
    void operator()(MirGraphicsRegion* region)
43
 
    {
44
 
        grmod->unlock(grmod, handle);
45
 
        delete region;
46
 
    }
47
 
 
48
 
    gralloc_module_t *grmod;
49
 
    native_handle_t const* handle;
50
 
};
51
 
}
52
 
 
53
 
mtd::TestGrallocMapper::TestGrallocMapper()
54
 
 : gralloc_ownership(true)
55
 
{
56
 
    const hw_module_t *hw_module;
57
 
    if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hw_module) != 0)
58
 
        throw std::runtime_error("error, hw module not available!\n");
59
 
    gralloc_open(hw_module, &alloc_dev);
60
 
    module = (gralloc_module_t*) hw_module;
61
 
}
62
 
 
63
 
mtd::TestGrallocMapper::TestGrallocMapper(const hw_module_t *hw_module,
64
 
                                     alloc_device_t* alloc_dev)
65
 
 : gralloc_ownership(false),
66
 
   module((gralloc_module_t*)hw_module),
67
 
   alloc_dev(alloc_dev)
68
 
{
69
 
}
70
 
 
71
 
mtd::TestGrallocMapper::~TestGrallocMapper()
72
 
{
73
 
    if (gralloc_ownership)
74
 
        gralloc_close(alloc_dev);
75
 
}
76
 
 
77
 
std::shared_ptr<MirGraphicsRegion> mtd::TestGrallocMapper::graphic_region_from_handle(
78
 
    ANativeWindowBuffer* package)
79
 
{
80
 
    int *vaddr;
81
 
    int usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
82
 
    module->lock(module, package->handle, usage, 0, 0, package->width, package->height, (void**) &vaddr);
83
 
 
84
 
    MirGraphicsRegion* region = new MirGraphicsRegion;
85
 
    RegionDeleter del(module, package->handle);
86
 
 
87
 
    region->vaddr = (char*) vaddr;
88
 
   region->stride = package->stride * MIR_BYTES_PER_PIXEL(mir_pixel_format_abgr_8888);
89
 
    region->width = package->width;
90
 
    region->height = package->height;
91
 
    region->pixel_format = mir_pixel_format_abgr_8888;
92
 
 
93
 
    return std::shared_ptr<MirGraphicsRegion>(region, del);
94
 
}