1 /*
2  * Copyright (C) 2014-2018 ARM Limited. All rights reserved.
3  *
4  * Copyright (C) 2008 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * You may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <sys/ioctl.h>
20 #include <errno.h>
21 #include <system/window.h>
22 
23 #include <hardware/hardware.h>
24 #include <hardware/fb.h>
25 
26 #if GRALLOC_VERSION_MAJOR == 1
27 #include <hardware/gralloc1.h>
28 #elif GRALLOC_VERSION_MAJOR == 0
29 #include <hardware/gralloc.h>
30 #endif
31 
32 #include "mali_gralloc_module.h"
33 #include "mali_gralloc_private_interface_types.h"
34 #include "mali_gralloc_buffer.h"
35 #include "gralloc_vsync.h"
36 #include "gralloc_vsync_report.h"
37 
38 #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
39 
gralloc_vsync_enable(framebuffer_device_t * dev)40 int gralloc_vsync_enable(framebuffer_device_t *dev)
41 {
42 	GRALLOC_UNUSED(dev);
43 	return 0;
44 }
45 
gralloc_vsync_disable(framebuffer_device_t * dev)46 int gralloc_vsync_disable(framebuffer_device_t *dev)
47 {
48 	GRALLOC_UNUSED(dev);
49 	return 0;
50 }
51 
gralloc_wait_for_vsync(framebuffer_device_t * dev)52 int gralloc_wait_for_vsync(framebuffer_device_t *dev)
53 {
54 	private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module);
55 
56 	if (MALI_DPY_TYPE_CLCD == m->dpy_type || MALI_DPY_TYPE_HDLCD == m->dpy_type)
57 	{
58 		/* Silently ignore wait for vsync as neither PL111 nor HDLCD implement this IOCTL. */
59 		return 0;
60 	}
61 
62 	if (m->swapInterval)
63 	{
64 		int crtc = 0;
65 		gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT);
66 
67 		if (ioctl(m->framebuffer->fb_fd, FBIO_WAITFORVSYNC, &crtc) < 0)
68 		{
69 			gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT);
70 			return -errno;
71 		}
72 
73 		gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT);
74 	}
75 
76 	return 0;
77 }
78