John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 "gralloc_priv.h" |
| 20 | #include "gralloc_vsync.h" |
| 21 | #include "gralloc_vsync_report.h" |
| 22 | #include <sys/ioctl.h> |
| 23 | #include <errno.h> |
| 24 | |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 25 | #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) |
| 26 | #define S3CFB_SET_VSYNC_INT _IOW('F', 206, unsigned int) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 27 | |
| 28 | int gralloc_vsync_enable(framebuffer_device_t *dev) |
| 29 | { |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 30 | private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 31 | int interrupt = 1; |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 32 | |
| 33 | if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0) |
| 34 | { |
| 35 | return -errno; |
| 36 | } |
| 37 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int gralloc_vsync_disable(framebuffer_device_t *dev) |
| 42 | { |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 43 | private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 44 | int interrupt = 0; |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 45 | |
| 46 | if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0) |
| 47 | { |
| 48 | return -errno; |
| 49 | } |
| 50 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int gralloc_wait_for_vsync(framebuffer_device_t *dev) |
| 55 | { |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 56 | private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); |
| 57 | |
| 58 | if (m->swapInterval) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 59 | { |
| 60 | int crtc = 0; |
| 61 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT); |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 62 | |
| 63 | if (ioctl(m->framebuffer->fd, FBIO_WAITFORVSYNC, &crtc) < 0) |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 64 | { |
| 65 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); |
| 66 | return -errno; |
| 67 | } |
John Stultz | 18814f6 | 2018-02-22 16:02:49 -0800 | [diff] [blame] | 68 | |
John Stultz | 16100f6 | 2017-05-03 11:12:18 -0700 | [diff] [blame] | 69 | gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); |
| 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 | return 0; |
| 73 | } |