Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / compat / ui / ui_compatibility_layer.cpp
CommitLineData
d42e7319
JB
1/*
2 * Copyright (C) 2013 Simon Busch <morphis@gravedo.de>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <fcntl.h>
18#include <sys/stat.h>
19
20#include <ui/GraphicBuffer.h>
21#include <ui/GraphicBufferMapper.h>
22#include <ui/GraphicBufferAllocator.h>
23
24#include <hybris/ui/ui_compatibility_layer.h>
25
26struct graphic_buffer
27{
28 android::GraphicBuffer *self;
29};
30
31struct graphic_buffer* graphic_buffer_new(void)
32{
33 struct graphic_buffer *buffer = NULL;
34
35 buffer = (struct graphic_buffer*) malloc(sizeof(struct graphic_buffer));
36 if (!buffer)
37 return NULL;
38
39 buffer->self = new android::GraphicBuffer();
40
41 return buffer;
42}
43
44struct graphic_buffer* graphic_buffer_new_sized(uint32_t w, uint32_t h,
45 int32_t format, uint32_t usage)
46{
47 struct graphic_buffer *buffer = NULL;
48
49 buffer = (struct graphic_buffer*) malloc(sizeof(struct graphic_buffer));
50 if (!buffer)
51 return NULL;
52
53 buffer->self = new android::GraphicBuffer(w, h, format, usage);
54
55 return buffer;
56}
57
58struct graphic_buffer* graphic_buffer_new_existing(uint32_t w, uint32_t h,
59 int32_t format, uint32_t usage,
60 uint32_t stride, void *handle,
61 bool keepOwnership)
62{
63 struct graphic_buffer *buffer = NULL;
64
65 buffer = (struct graphic_buffer*) malloc(sizeof(struct graphic_buffer));
66 if (!buffer)
67 return NULL;
68
69 buffer->self = new android::GraphicBuffer(w, h, format, usage, stride, (native_handle_t*) handle, keepOwnership);
70
71 return buffer;
72
73}
74
75void graphic_buffer_free(struct graphic_buffer *buffer)
76{
77 if (!buffer)
78 return;
79
80 free(buffer);
81}
82
83uint32_t graphic_buffer_get_width(struct graphic_buffer *buffer)
84{
85 return buffer->self->getWidth();
86}
87
88uint32_t graphic_buffer_get_height(struct graphic_buffer *buffer)
89{
90 return buffer->self->getHeight();
91}
92
93uint32_t graphic_buffer_get_stride(struct graphic_buffer *buffer)
94{
95 return buffer->self->getStride();
96}
97
98uint32_t graphic_buffer_get_usage(struct graphic_buffer *buffer)
99{
100 return buffer->self->getUsage();
101}
102
103int32_t graphic_buffer_get_pixel_format(struct graphic_buffer *buffer)
104{
105 return buffer->self->getPixelFormat();
106}
107
108uint32_t graphic_buffer_reallocate(struct graphic_buffer *buffer, uint32_t w,
109 uint32_t h, int32_t f, uint32_t usage)
110{
111 return buffer->self->reallocate(w, h, f, usage);
112}
113
114uint32_t graphic_buffer_lock(struct graphic_buffer *buffer, uint32_t usage, void **vaddr)
115{
116 return buffer->self->lock(usage, vaddr);
117}
118
119uint32_t graphic_buffer_unlock(struct graphic_buffer *buffer)
120{
121 return buffer->self->unlock();
122}
123
124void* graphic_buffer_get_native_buffer(struct graphic_buffer *buffer)
125{
126 return buffer->self->getNativeBuffer();
127}
128
129void graphic_buffer_set_index(struct graphic_buffer *buffer, int index)
130{
131 return buffer->self->setIndex(index);
132}
133
134int graphic_buffer_get_index(struct graphic_buffer *buffer)
135{
136 return buffer->self->getIndex();
137}
138
139int graphic_buffer_init_check(struct graphic_buffer *buffer)
140{
141 return buffer->self->initCheck();
142}