John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 1 | /* |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 2 | * Copyright (C) 2014-2017 ARM Limited. All rights reserved. |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 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 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 19 | #include <sys/ioctl.h> |
| 20 | #include <errno.h> |
| 21 | |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 22 | #include <hardware/hardware.h> |
| 23 | #include <hardware/fb.h> |
| 24 | |
| 25 | #if GRALLOC_USE_GRALLOC1_API == 1 |
| 26 | #include <hardware/gralloc1.h> |
| 27 | #else |
| 28 | #include <hardware/gralloc.h> |
| 29 | #endif |
| 30 | |
| 31 | #include "mali_gralloc_module.h" |
| 32 | #include "mali_gralloc_private_interface_types.h" |
| 33 | #include "mali_gralloc_buffer.h" |
| 34 | #include "gralloc_vsync.h" |
| 35 | #include "gralloc_vsync_report.h" |
| 36 | |
| 37 | #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 38 | |
| 39 | int gralloc_vsync_enable(framebuffer_device_t *dev) |
| 40 | { |
| 41 | GRALLOC_UNUSED(dev); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | int gralloc_vsync_disable(framebuffer_device_t *dev) |
| 46 | { |
| 47 | GRALLOC_UNUSED(dev); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int gralloc_wait_for_vsync(framebuffer_device_t *dev) |
| 52 | { |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 53 | private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); |
| 54 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 55 | if (MALI_DPY_TYPE_CLCD == m->dpy_type || MALI_DPY_TYPE_HDLCD == m->dpy_type) |
| 56 | { |
| 57 | /* Silently ignore wait for vsync as neither PL111 nor HDLCD implement this IOCTL. */ |
| 58 | return 0; |
| 59 | } |
| 60 | |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 61 | if (m->swapInterval) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 62 | { |
| 63 | int crtc = 0; |
| 64 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT); |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 65 | |
| 66 | if (ioctl(m->framebuffer->fd, FBIO_WAITFORVSYNC, &crtc) < 0) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 67 | { |
| 68 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); |
| 69 | return -errno; |
| 70 | } |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 71 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 72 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); |
| 73 | } |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 74 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |