diff options
-rw-r--r-- | gralloc/Android.mk | 1 | ||||
-rw-r--r-- | gralloc/framebuffer.cpp | 33 | ||||
-rw-r--r-- | gralloc/gralloc_vsync.cpp | 68 | ||||
-rwxr-xr-x | include/gralloc_priv.h | 1 | ||||
-rw-r--r-- | include/gralloc_vsync.h | 31 | ||||
-rw-r--r-- | include/gralloc_vsync_report.h | 44 |
6 files changed, 173 insertions, 5 deletions
diff --git a/gralloc/Android.mk b/gralloc/Android.mk index 6268513..e1edc61 100644 --- a/gralloc/Android.mk +++ b/gralloc/Android.mk @@ -29,6 +29,7 @@ LOCAL_C_INCLUDES := \ LOCAL_SRC_FILES := \ gralloc.cpp \ + gralloc_vsync.cpp \ framebuffer.cpp \ mapper.cpp diff --git a/gralloc/framebuffer.cpp b/gralloc/framebuffer.cpp index 85457f3..b34a6b6 100644 --- a/gralloc/framebuffer.cpp +++ b/gralloc/framebuffer.cpp @@ -40,6 +40,7 @@ #endif #include "gralloc_priv.h" +#include "gralloc_vsync.h" inline size_t roundUpToPageSize(size_t x) { return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); @@ -65,13 +66,35 @@ struct fb_context_t { /*****************************************************************************/ + +/* + * Keep track of the vsync state to avoid making excessive ioctl calls. + * States: -1 --> unknown; 0 --> disabled; 1 --> enabled. + */ +static int vsync_state = -1; + static int fb_setSwapInterval(struct framebuffer_device_t* dev, int interval) { - fb_context_t* ctx = (fb_context_t*)dev; - if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval) - return -EINVAL; - // FIXME: implement fb_setSwapInterval + if (interval < dev->minSwapInterval) { + interval = dev->minSwapInterval; + } else if (interval > dev->maxSwapInterval) { + interval = dev->maxSwapInterval; + } + + private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module); + m->swapInterval = interval; + + if (interval == 0 && vsync_state != 0) { + gralloc_vsync_disable(dev); + vsync_state = 0; + } else if (vsync_state != 1) { + gralloc_vsync_enable(dev); + vsync_state = 1; + } + + ALOGV("%s: vsync state is: %d", __func__, vsync_state); + return 0; } @@ -295,7 +318,7 @@ int fb_device_open(hw_module_t const* module, const char* name, dev->common.version = 0; dev->common.module = const_cast<hw_module_t*>(module); dev->common.close = fb_close; - dev->setSwapInterval = 0; + dev->setSwapInterval = fb_setSwapInterval; dev->post = fb_post; dev->setUpdateRect = 0; dev->compositionComplete = 0; diff --git a/gralloc/gralloc_vsync.cpp b/gralloc/gralloc_vsync.cpp new file mode 100644 index 0000000..b1c2c9b --- /dev/null +++ b/gralloc/gralloc_vsync.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 ARM Limited. All rights reserved. + * + * 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 <cutils/log.h> + +#include "gralloc_priv.h" +#include "gralloc_vsync.h" +#include "gralloc_vsync_report.h" + +#include <sys/ioctl.h> + +#include <errno.h> + +#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +#define S3CFB_SET_VSYNC_INT _IOW('F', 206, unsigned int) + +int gralloc_vsync_enable(framebuffer_device_t *dev) +{ + private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module); + int interrupt = 1; + if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0) { + return -errno; + } + + return 0; +} + +int gralloc_vsync_disable(framebuffer_device_t *dev) +{ + private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module); + int interrupt = 0; + if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0) { + return -errno; + } + + return 0; +} + +int gralloc_wait_for_vsync(framebuffer_device_t *dev) +{ + private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module); + if (m->swapInterval ) { + int crtc = 0; + gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT); + if (ioctl(m->framebuffer->fd, FBIO_WAITFORVSYNC, &crtc) < 0) { + gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); + return -errno; + } + gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT); + } + + return 0; +} diff --git a/include/gralloc_priv.h b/include/gralloc_priv.h index 59a08ad..197fbbc 100755 --- a/include/gralloc_priv.h +++ b/include/gralloc_priv.h @@ -55,6 +55,7 @@ struct private_module_t { float xdpi; float ydpi; float fps; + int swapInterval; void *queue; pthread_mutex_t queue_lock; diff --git a/include/gralloc_vsync.h b/include/gralloc_vsync.h new file mode 100644 index 0000000..6027eda --- /dev/null +++ b/include/gralloc_vsync.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 ARM Limited. All rights reserved. + * + * 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. + */ + +#ifndef _GRALLOC_VSYNC_H_ +#define _GRALLOC_VSYNC_H_ + +struct framebuffer_device_t; + +/* Enables vsync interrupt. */ +int gralloc_vsync_enable(struct framebuffer_device_t* dev); +/* Disables vsync interrupt. */ +int gralloc_vsync_disable(struct framebuffer_device_t* dev); +/* Waits for the vsync interrupt. */ +int gralloc_wait_for_vsync(struct framebuffer_device_t* dev); + +#endif /* _GRALLOC_VSYNC_H_ */ diff --git a/include/gralloc_vsync_report.h b/include/gralloc_vsync_report.h new file mode 100644 index 0000000..861009a --- /dev/null +++ b/include/gralloc_vsync_report.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2011 ARM Limited. All rights reserved. + * + * 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. + */ + +#ifndef GRALLOC_VSYNC_REPORT_H_ +#define GRALLOC_VSYNC_REPORT_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + + +typedef enum mali_vsync_event +{ + MALI_VSYNC_EVENT_BEGIN_WAIT = 0, + MALI_VSYNC_EVENT_END_WAIT +} mali_vsync_event; + +extern void _mali_base_arch_vsync_event_report(mali_vsync_event); + +inline void gralloc_mali_vsync_report(mali_vsync_event event) +{ + #ifdef MALI_VSYNC_EVENT_REPORT_ENABLE + _mali_base_arch_vsync_event_report(event); + #endif +} + +#ifdef __cplusplus +} +#endif +#endif /* GRALLOC_VSYNC_REPORT_H_ */ |