Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <hardware/hardware.h> |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 18 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 19 | #include <errno.h> |
Elliott Hughes | 84b9ff8 | 2015-01-28 19:54:13 -0800 | [diff] [blame] | 20 | #include <fcntl.h> |
| 21 | #include <malloc.h> |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 22 | |
| 23 | #include <cutils/log.h> |
| 24 | #include <cutils/atomic.h> |
| 25 | |
| 26 | #include <hardware/hwcomposer.h> |
| 27 | |
| 28 | #include <EGL/egl.h> |
| 29 | |
| 30 | /*****************************************************************************/ |
| 31 | |
| 32 | struct hwc_context_t { |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 33 | hwc_composer_device_1_t device; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 34 | /* our private state goes below here */ |
| 35 | }; |
| 36 | |
| 37 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 38 | struct hw_device_t** device); |
| 39 | |
| 40 | static struct hw_module_methods_t hwc_module_methods = { |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 41 | .open = hwc_device_open |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | hwc_module_t HAL_MODULE_INFO_SYM = { |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 45 | .common = { |
| 46 | .tag = HARDWARE_MODULE_TAG, |
| 47 | .version_major = 1, |
| 48 | .version_minor = 0, |
| 49 | .id = HWC_HARDWARE_MODULE_ID, |
| 50 | .name = "Sample hwcomposer module", |
| 51 | .author = "The Android Open Source Project", |
| 52 | .methods = &hwc_module_methods, |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
| 56 | /*****************************************************************************/ |
| 57 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 58 | static void dump_layer(hwc_layer_1_t const* l) { |
Steve Block | cee8501 | 2011-12-20 16:25:12 +0000 | [diff] [blame] | 59 | ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}", |
Mathias Agopian | e6b5c05 | 2010-08-11 16:15:42 -0700 | [diff] [blame] | 60 | l->compositionType, l->flags, l->handle, l->transform, l->blending, |
| 61 | l->sourceCrop.left, |
| 62 | l->sourceCrop.top, |
| 63 | l->sourceCrop.right, |
| 64 | l->sourceCrop.bottom, |
| 65 | l->displayFrame.left, |
| 66 | l->displayFrame.top, |
| 67 | l->displayFrame.right, |
| 68 | l->displayFrame.bottom); |
| 69 | } |
| 70 | |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 71 | static int hwc_prepare(hwc_composer_device_1_t * /*dev*/, |
| 72 | size_t /*numDisplays*/, hwc_display_contents_1_t** displays) { |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 73 | if (displays && (displays[0]->flags & HWC_GEOMETRY_CHANGED)) { |
| 74 | for (size_t i=0 ; i<displays[0]->numHwLayers ; i++) { |
Mathias Agopian | e6b5c05 | 2010-08-11 16:15:42 -0700 | [diff] [blame] | 75 | //dump_layer(&list->hwLayers[i]); |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 76 | displays[0]->hwLayers[i].compositionType = HWC_FRAMEBUFFER; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | return 0; |
| 80 | } |
| 81 | |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 82 | static int hwc_set(hwc_composer_device_1_t * /*dev*/, |
| 83 | size_t /*numDisplays*/, hwc_display_contents_1_t** displays) |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 84 | { |
Mathias Agopian | e6b5c05 | 2010-08-11 16:15:42 -0700 | [diff] [blame] | 85 | //for (size_t i=0 ; i<list->numHwLayers ; i++) { |
| 86 | // dump_layer(&list->hwLayers[i]); |
| 87 | //} |
| 88 | |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 89 | EGLBoolean success = eglSwapBuffers((EGLDisplay)displays[0]->dpy, |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 90 | (EGLSurface)displays[0]->sur); |
Greg Kaiser | 8f35d92 | 2016-06-30 16:43:40 -0700 | [diff] [blame^] | 91 | if (!success) { |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 92 | return HWC_EGL_ERROR; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int hwc_device_close(struct hw_device_t *dev) |
| 98 | { |
| 99 | struct hwc_context_t* ctx = (struct hwc_context_t*)dev; |
| 100 | if (ctx) { |
| 101 | free(ctx); |
| 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | /*****************************************************************************/ |
| 107 | |
| 108 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 109 | struct hw_device_t** device) |
| 110 | { |
| 111 | int status = -EINVAL; |
| 112 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 113 | struct hwc_context_t *dev; |
| 114 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 115 | |
| 116 | /* initialize our state here */ |
| 117 | memset(dev, 0, sizeof(*dev)); |
| 118 | |
| 119 | /* initialize the procs */ |
| 120 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 121 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_0; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 122 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 123 | dev->device.common.close = hwc_device_close; |
| 124 | |
| 125 | dev->device.prepare = hwc_prepare; |
| 126 | dev->device.set = hwc_set; |
| 127 | |
| 128 | *device = &dev->device.common; |
| 129 | status = 0; |
| 130 | } |
| 131 | return status; |
| 132 | } |