2
* Copyright © 2012 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
20
#include "mir_test/draw/android_graphics.h"
21
#include "mir_toolkit/common.h"
28
namespace mtd=mir::test::draw;
29
namespace mc=mir::compositor;
30
namespace geom=mir::geometry;
36
RegionDeleter(gralloc_module_t* grmod, native_handle_t const* handle)
42
void operator()(MirGraphicsRegion* region)
44
grmod->unlock(grmod, handle);
48
gralloc_module_t *grmod;
49
native_handle_t const* handle;
53
mtd::TestGrallocMapper::TestGrallocMapper()
54
: gralloc_ownership(true)
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;
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),
71
mtd::TestGrallocMapper::~TestGrallocMapper()
73
if (gralloc_ownership)
74
gralloc_close(alloc_dev);
77
std::shared_ptr<MirGraphicsRegion> mtd::TestGrallocMapper::graphic_region_from_handle(
78
ANativeWindowBuffer* package)
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);
84
MirGraphicsRegion* region = new MirGraphicsRegion;
85
RegionDeleter del(module, package->handle);
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;
93
return std::shared_ptr<MirGraphicsRegion>(region, del);