1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/****************************************************************************
*
* Copyright 2012 - 2020 Vivante Corporation, Santa Clara, California.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#include "elm_precom.h"
#include "vg_lite.h"
#if !DDRLESS
static vg_lite_buffer_format_t _buffer_format_to_vglite(ELM_BUFFER_FORMAT format)
{
vg_lite_buffer_format_t fmt;
switch (format) {
case ELM_BUFFER_FORMAT_RGBA8888:
fmt = VG_LITE_RGBA8888;
break;
case ELM_BUFFER_FORMAT_RGBX8888:
fmt = VG_LITE_RGBX8888;
break;
case ELM_BUFFER_FORMAT_BGRA8888:
fmt = VG_LITE_BGRA8888;
break;
case ELM_BUFFER_FORMAT_BGRX8888:
fmt = VG_LITE_BGRX8888;
break;
case ELM_BUFFER_FORMAT_RGB565:
fmt = VG_LITE_RGB565;
break;
case ELM_BUFFER_FORMAT_BGR565:
fmt = VG_LITE_BGR565;
break;
case ELM_BUFFER_FORMAT_RGBA4444:
fmt = VG_LITE_RGBA4444;
break;
case ELM_BUFFER_FORMAT_BGRA4444:
fmt = VG_LITE_BGRA4444;
break;
default:
fmt = VG_LITE_RGBA8888;
break;
}
return fmt;
}
#endif
/*!
@abstract Create internal render buffer.
@discussion
This functiois is to create an internal render buffer for Elementary rendering, ussually it's not for direct display.
The buffer which is displayed on pannel is wrapped up by another API, whose address is managed by display controller side.
@param width
The buffer's width.
@param height
The buffer's height.
@param format
The buffer's format, check enumeration of ELM_BUFFER_FORMAT.
@return
The buffer handle.
*/
ElmBuffer ElmCreateBuffer(unsigned int width, unsigned int height, ELM_BUFFER_FORMAT format)
{
#if !DDRLESS
el_Obj_Buffer *buffer_obj;
vg_lite_buffer_t *buffer;
vg_lite_error_t error;
ElmHandle handle = ELM_NULL_HANDLE;
do {
/* Allocate ebo object. */
buffer_obj = (el_Obj_Buffer *)calloc(1,sizeof(el_Obj_Buffer));
if (buffer_obj != NULL) {
buffer_obj->object.type = ELM_OBJECT_TYPE_BUF;
/* Allocate the buffer. */
buffer = &buffer_obj->buffer;
memset(buffer, 0, sizeof(vg_lite_buffer_t));
buffer->width = width;
buffer->height = height;
buffer->format = (vg_lite_buffer_format_t)format;
error = vg_lite_allocate(buffer);
if (error)
goto error_exit;
JUMP_IF_NON_ZERO_VALUE(add_object((el_Object *)buffer_obj), error_exit);
handle = buffer_obj->object.handle;
}
} while(0);
return handle;
error_exit:
vg_lite_free(buffer);
free(buffer_obj);
return ELM_NULL_HANDLE;
#else
return ELM_NULL_HANDLE;
#endif
}
/*!
@abstract Wrap a customized buffer.
@discussion
The application may wrap a user created buffer by giving the information of
the buffer including the size, the memory addresses and format. E.g., the
application can wrap a system framebuffer thus ELM can directly render onto
the screen.
@return
The buffer handle.
*/
ElmBuffer ElmWrapBuffer(int width, int height, int stride,
void *logical, uint32_t physical,
ELM_BUFFER_FORMAT format)
{
#if !DDRLESS
el_Obj_Buffer *buffer_obj;
vg_lite_buffer_t *buffer;
ElmHandle handle = ELM_NULL_HANDLE;
do {
/* open framebuffer. */
buffer_obj = (el_Obj_Buffer *)elm_alloc(1, sizeof(el_Obj_Buffer));
if (buffer_obj != NULL) {
buffer_obj->object.type = ELM_OBJECT_TYPE_BUF;
buffer = &buffer_obj->buffer;
buffer->width = width;
buffer->height = height;
buffer->stride = stride;
buffer->memory = logical;
buffer->handle = NULL;
buffer->address = physical;
buffer->format = _buffer_format_to_vglite(format);
buffer->tiled = VG_LITE_LINEAR;
JUMP_IF_NON_ZERO_VALUE(add_object((el_Object *)buffer_obj), error_exit);
handle = buffer_obj->object.handle;
}
} while(0);
return handle;
error_exit:
free(buffer_obj);
return ELM_NULL_HANDLE;
#else
return ELM_NULL_HANDLE;
#endif
}
/*!
@abstract Get buffer address.
@discussion
The function is to get the address of ElmBuffer.
@return
The buffer address.
*/
uint32_t ElmGetBufferAddress(ElmBuffer buffer)
{
#if !DDRLESS
el_Obj_Buffer *buff_obj;
buff_obj = (el_Obj_Buffer *)get_object(buffer);
if (buff_obj == NULL)
{
return 0;
}
else
{
return buff_obj->buffer.address;
}
#else
return 0;
#endif
}
/*!
@abstract Destroy a render buffer.
@discussion
This function is to release all internal resource inside Elementary libary belonging to this buffer.
Applicatoin need make sure the buffer is not being used by elmentary library any more when calling this function.
@param buffer
The render buffer handle
@return
If destroying is completed successfully.
*/
BOOL ElmDestroyBuffer(ElmBuffer buffer)
{
#if !DDRLESS
/* Find the object. */
el_Obj_Buffer *buff = (el_Obj_Buffer *)get_object(buffer);
/* If found, delete the vg_lite_buffer object. Otherwise, return FALSE. */
if (buff != NULL) {
if (buff->buffer.handle != NULL) {
/* Free the buffer memory. */
vg_lite_free(&buff->buffer);
}
remove_object((el_Object*)buff);
elm_free(buff);
return TRUE;
}
else {
return FALSE;
}
#else
return TRUE;
#endif
}
BOOL ElmSaveBuffer(ElmBuffer buffer, const char *name)
{
#if !DDRLESS
el_Obj_Buffer *buff = (el_Obj_Buffer *)get_object(buffer);
/* If found, delete the vg_lite_buffer object. Otherwise, return FALSE. */
if (buff != NULL) {
#if !RTOS
/*
"vg_lite_save_png" function does not exist (anymore). Probably a left
over from an older driver.
*/
if (buff->buffer.memory != NULL) {
vg_lite_save_png(name, &buff->buffer);
}
#endif
return TRUE;
}
else {
return FALSE;
}
#else
return TRUE;
#endif
}
/*!
@abstract Convert vglite format to elm format.
*/
ELM_BUFFER_FORMAT _buffer_format_to_Elm(vg_lite_buffer_format_t format)
{
switch (format)
{
case VG_LITE_RGB565:
return ELM_BUFFER_FORMAT_RGB565;
break;
case VG_LITE_BGR565:
return ELM_BUFFER_FORMAT_BGR565;
break;
default:
return ELM_BUFFER_FORMAT_RGBA8888;
break;
}
}
/*!
@abstract Get handle of the framebuffer.
*/
ElmBuffer ElmGetBuffer(vg_lite_buffer_t *buffer)
{
elm_tls_t* elm_tls;
elm_tls = (elm_tls_t *) elm_os_get_tls();
if (elm_tls == NULL)
return ELM_NULL_HANDLE;
for (int i = 0; i < APP_BUFFER_COUNT; i++) {
if (elm_tls->gContext.elmFB[i].buffer == NULL) {
elm_tls->gContext.elmFB[i].buffer = buffer;
elm_tls->gContext.elmFB[i].handle = ElmWrapBuffer(buffer->width, buffer->height, buffer->stride, buffer->memory,
buffer->address, _buffer_format_to_Elm(buffer->format));
vg_lite_clear(buffer, NULL, 0x0);
return elm_tls->gContext.elmFB[i].handle;
}
if (elm_tls->gContext.elmFB[i].buffer == buffer)
return elm_tls->gContext.elmFB[i].handle;
}
return 0;
}
|