This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gralloc_dispmanx.cpp
138 lines (112 loc) · 4.27 KB
/
gralloc_dispmanx.cpp
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
/*
* Copyright (C) 2013 Andreas Harter - RazDroid project
*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gralloc_dispmanx.h"
#include "bcm_host.h"
#include <cutils/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/mman.h>
#ifndef ALIGN_UP
#define ALIGN_UP(x,y) ((x + (y)-1) & ~((y)-1))
#endif
void alloc_dispmanx_window_size(private_handle_t* handle)
{
DISPMANX_MODEINFO_T info;
EGL_DISPMANX_WINDOW_T window;
vc_dispmanx_display_get_info(handle->brcm_handle->dispman_display, &info);
window.height = info.height;
window.width = info.width;
handle->brcm_handle->window = window;
}
void alloc_dispmanx_default_values(private_handle_t* handle)
{
handle->brcm_handle->gl_format = GRALLOC_MAGICS_HAL_PIXEL_FORMAT_OPAQUE;
handle->brcm_handle->stride = ALIGN_UP(handle->brcm_handle->window.width, 32);
handle->brcm_handle->res_type = GRALLOC_PRIV_TYPE_MM_RESOURCE;
handle->brcm_handle->egl_image = (EGLImageKHR) 0xBADF00D;
}
void open_display(private_handle_t* handle)
{
handle->brcm_handle->dispman_display = vc_dispmanx_display_open(0);
}
void write_buffer_dispmanx(private_handle_t* handle)
{
//TODO: get image type from private_handle_t
VC_IMAGE_TYPE_T type = VC_IMAGE_RGBA565;
VC_RECT_T dst_rect;
void* image = (void*) handle->base;
int width = handle->brcm_handle->window.width;
int height = handle->brcm_handle->window.height;
vc_dispmanx_rect_set(&dst_rect, 0, 0, width, height);
vc_dispmanx_resource_write_data(handle->brcm_handle->dispman_resource, type, handle->brcm_handle->stride, image,
&dst_rect);
}
int dispmanx_alloc(private_handle_t* handle)
{
bcm_host_init();
VC_RECT_T src_rect;
VC_RECT_T dst_rect;
handle->brcm_handle = (struct gralloc_private_handle_t*) malloc(sizeof(struct gralloc_private_handle_t));
open_display(handle);
alloc_dispmanx_window_size(handle);
alloc_dispmanx_default_values(handle);
dst_rect.x = 0;
dst_rect.y = 0;
dst_rect.width = handle->brcm_handle->window.width;
dst_rect.height = handle->brcm_handle->window.height;
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = handle->brcm_handle->window.width << 16;
src_rect.height = handle->brcm_handle->window.height << 16;
uint32_t dummy = 0;
handle->brcm_handle->dispman_resource = vc_dispmanx_resource_create(VC_IMAGE_RGB565, dst_rect.width,
dst_rect.height, &dummy);
DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0);
handle->brcm_handle->window.element = vc_dispmanx_element_add(update, handle->brcm_handle->dispman_display,
-127/*layer*/, &dst_rect, handle->brcm_handle->dispman_resource, &src_rect,
DISPMANX_PROTECTION_NONE, 0, 0, (DISPMANX_TRANSFORM_T) 0);
vc_dispmanx_update_submit(update, 0, 0);
return 0;
}
int dispmanx_lock(private_handle_t* handle, int usage, int l, int t, int w, int h, void** vaddr)
{
// this is called when a buffer is being locked for software
// access. in thin implementation we have nothing to do since
// not synchronization with the h/w is needed.
// typically this is used to wait for the h/w to finish with
// this buffer if relevant. the data cache may need to be
// flushed or invalidated depending on the usage bits and the
// hardware.
if (handle->lock & private_handle_t::WRITE_LOCK) {
return -EBUSY;
} else if (handle->flags & GRALLOC_USAGE_SW_WRITE_MASK) {
handle->lock |= private_handle_t::WRITE_LOCK;
}
return 0;
}
int dispmanx_unlock(private_handle_t* handle)
{
// flush the data cache
write_buffer_dispmanx(handle);
handle->lock = 0;
return 0;
}