├── MODULE_LICENSE_APACHE2 ├── tests ├── Android.mk └── nusensors │ ├── Android.mk │ └── nusensors.cpp ├── modules ├── overlay │ ├── README.android │ ├── Android.mk │ └── overlay.cpp ├── README.android └── gralloc │ ├── Android.mk │ ├── gr.h │ ├── gralloc_priv.h │ ├── mapper.cpp │ ├── gralloc.cpp │ └── framebuffer.cpp ├── Android.mk ├── CleanSpec.mk ├── include └── hardware │ ├── sensors_deprecated.h │ ├── qemud.h │ ├── lights.h │ ├── hardware.h │ ├── copybit.h │ ├── overlay.h │ ├── gralloc.h │ ├── sensors.h │ └── gps.h ├── hardware.c └── NOTICE /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/Android.mk: -------------------------------------------------------------------------------- 1 | include $(call all-subdir-makefiles) 2 | -------------------------------------------------------------------------------- /modules/overlay/README.android: -------------------------------------------------------------------------------- 1 | 2 | Skeleton for the "overlay" HAL module. 3 | 4 | -------------------------------------------------------------------------------- /tests/nusensors/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | nusensors.cpp 6 | 7 | LOCAL_SHARED_LIBRARIES := \ 8 | libcutils libhardware 9 | 10 | LOCAL_MODULE:= test-nusensors 11 | 12 | LOCAL_MODULE_TAGS := optional 13 | 14 | include $(BUILD_EXECUTABLE) 15 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | # Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand. 4 | 5 | LOCAL_PATH:= $(call my-dir) 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_SHARED_LIBRARIES := libcutils 9 | 10 | LOCAL_INCLUDES += $(LOCAL_PATH) 11 | 12 | ifneq ($(TARGET_SIMULATOR),true) 13 | LOCAL_CFLAGS += -DQEMU_HARDWARE 14 | QEMU_HARDWARE := true 15 | endif 16 | 17 | ifneq ($(TARGET_SIMULATOR),true) 18 | LOCAL_SHARED_LIBRARIES += libdl 19 | endif 20 | 21 | LOCAL_SRC_FILES += hardware.c 22 | 23 | # need "-lrt" on Linux simulator to pick up clock_gettime 24 | ifeq ($(TARGET_SIMULATOR),true) 25 | ifeq ($(HOST_OS),linux) 26 | LOCAL_LDLIBS += -lrt -lpthread -ldl 27 | endif 28 | endif 29 | 30 | LOCAL_MODULE:= libhardware 31 | 32 | include $(BUILD_SHARED_LIBRARY) 33 | 34 | include $(addsuffix /Android.mk, $(addprefix $(LOCAL_PATH)/, \ 35 | modules/gralloc \ 36 | tests \ 37 | )) 38 | -------------------------------------------------------------------------------- /modules/README.android: -------------------------------------------------------------------------------- 1 | Default (and possibly architecture dependents) HAL modules go here. 2 | 3 | 4 | libhardware.so eventually should contain *just* the HAL hub 5 | (hardware.c), everything in it should be rewritten as modules. 6 | 7 | Modules are .so in /system/libs/hw/ and have a well defined naming 8 | convention: 9 | 10 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 11 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 12 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 13 | /system/libs/hw/<*_HARDWARE_MODULE_ID>.default.so 14 | 15 | They also have a well defined interface which lives in include/hardware/. 16 | 17 | A module can have several variants: "default", "arch" and "board", and they're 18 | loaded in the "board", "arch" and "default" order. 19 | The source code for the "board" variant, usually lives under partners/... 20 | 21 | The source code for "default" and "arch" would usually 22 | live under hardware/modules/. 23 | 24 | -------------------------------------------------------------------------------- /modules/overlay/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | # HAL module implemenation, not prelinked and stored in 19 | # hw/..so 20 | include $(CLEAR_VARS) 21 | LOCAL_PRELINK_MODULE := false 22 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 23 | LOCAL_SHARED_LIBRARIES := liblog 24 | LOCAL_SRC_FILES := overlay.cpp 25 | LOCAL_MODULE := overlay.default 26 | include $(BUILD_SHARED_LIBRARY) 27 | -------------------------------------------------------------------------------- /modules/gralloc/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | # HAL module implemenation, not prelinked and stored in 19 | # hw/..so 20 | include $(CLEAR_VARS) 21 | LOCAL_PRELINK_MODULE := false 22 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 23 | LOCAL_SHARED_LIBRARIES := liblog libcutils 24 | 25 | LOCAL_SRC_FILES := \ 26 | gralloc.cpp \ 27 | framebuffer.cpp \ 28 | mapper.cpp 29 | 30 | LOCAL_MODULE := gralloc.default 31 | LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" 32 | ifeq ($(BOARD_NO_PAGE_FLIPPING),true) 33 | LOCAL_CFLAGS += -DNO_PAGE_FLIPPING 34 | endif 35 | 36 | include $(BUILD_SHARED_LIBRARY) 37 | -------------------------------------------------------------------------------- /modules/gralloc/gr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef GR_H_ 18 | #define GR_H_ 19 | 20 | #include 21 | #ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define 22 | # include 23 | #else 24 | # include 25 | #endif 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | /*****************************************************************************/ 35 | 36 | struct private_module_t; 37 | struct private_handle_t; 38 | 39 | inline size_t roundUpToPageSize(size_t x) { 40 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); 41 | } 42 | 43 | int mapFrameBufferLocked(struct private_module_t* module); 44 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); 45 | int mapBuffer(gralloc_module_t const* module, private_handle_t* hnd); 46 | 47 | /*****************************************************************************/ 48 | 49 | class Locker { 50 | pthread_mutex_t mutex; 51 | public: 52 | class Autolock { 53 | Locker& locker; 54 | public: 55 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } 56 | inline ~Autolock() { locker.unlock(); } 57 | }; 58 | inline Locker() { pthread_mutex_init(&mutex, 0); } 59 | inline ~Locker() { pthread_mutex_destroy(&mutex); } 60 | inline void lock() { pthread_mutex_lock(&mutex); } 61 | inline void unlock() { pthread_mutex_unlock(&mutex); } 62 | }; 63 | 64 | #endif /* GR_H_ */ 65 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /include/hardware/sensors_deprecated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #define SENSORS_HARDWARE_CONTROL "control" 18 | #define SENSORS_HARDWARE_DATA "data" 19 | 20 | __BEGIN_DECLS 21 | 22 | typedef struct { 23 | int sensor; 24 | union { 25 | sensors_vec_t vector; 26 | sensors_vec_t orientation; 27 | sensors_vec_t acceleration; 28 | sensors_vec_t magnetic; 29 | float temperature; 30 | float distance; 31 | float light; 32 | }; 33 | int64_t time; 34 | uint32_t reserved; 35 | } sensors_data_t; 36 | 37 | struct sensors_control_device_t { 38 | struct hw_device_t common; 39 | native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev); 40 | int (*close_data_source)(struct sensors_control_device_t *dev); 41 | int (*activate)(struct sensors_control_device_t *dev, 42 | int handle, int enabled); 43 | int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms); 44 | int (*wake)(struct sensors_control_device_t *dev); 45 | }; 46 | 47 | struct sensors_data_device_t { 48 | struct hw_device_t common; 49 | int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh); 50 | int (*data_close)(struct sensors_data_device_t *dev); 51 | int (*poll)(struct sensors_data_device_t *dev, 52 | sensors_data_t* data); 53 | }; 54 | 55 | static inline int sensors_control_open(const struct hw_module_t* module, 56 | struct sensors_control_device_t** device) { 57 | return module->methods->open(module, 58 | SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device); 59 | } 60 | 61 | static inline int sensors_control_close(struct sensors_control_device_t* device) { 62 | return device->common.close(&device->common); 63 | } 64 | 65 | static inline int sensors_data_open(const struct hw_module_t* module, 66 | struct sensors_data_device_t** device) { 67 | return module->methods->open(module, 68 | SENSORS_HARDWARE_DATA, (struct hw_device_t**)device); 69 | } 70 | 71 | static inline int sensors_data_close(struct sensors_data_device_t* device) { 72 | return device->common.close(&device->common); 73 | } 74 | 75 | __END_DECLS 76 | -------------------------------------------------------------------------------- /modules/gralloc/gralloc_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef GRALLOC_PRIV_H_ 18 | #define GRALLOC_PRIV_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | /*****************************************************************************/ 33 | 34 | struct private_module_t; 35 | struct private_handle_t; 36 | 37 | struct private_module_t { 38 | gralloc_module_t base; 39 | 40 | private_handle_t* framebuffer; 41 | uint32_t flags; 42 | uint32_t numBuffers; 43 | uint32_t bufferMask; 44 | pthread_mutex_t lock; 45 | buffer_handle_t currentBuffer; 46 | int pmem_master; 47 | void* pmem_master_base; 48 | 49 | struct fb_var_screeninfo info; 50 | struct fb_fix_screeninfo finfo; 51 | float xdpi; 52 | float ydpi; 53 | float fps; 54 | }; 55 | 56 | /*****************************************************************************/ 57 | 58 | #ifdef __cplusplus 59 | struct private_handle_t : public native_handle { 60 | #else 61 | struct private_handle_t { 62 | struct native_handle nativeHandle; 63 | #endif 64 | 65 | enum { 66 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001 67 | }; 68 | 69 | // file-descriptors 70 | int fd; 71 | // ints 72 | int magic; 73 | int flags; 74 | int size; 75 | int offset; 76 | 77 | // FIXME: the attributes below should be out-of-line 78 | int base; 79 | int pid; 80 | 81 | #ifdef __cplusplus 82 | static const int sNumInts = 6; 83 | static const int sNumFds = 1; 84 | static const int sMagic = 0x3141592; 85 | 86 | private_handle_t(int fd, int size, int flags) : 87 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), 88 | base(0), pid(getpid()) 89 | { 90 | version = sizeof(native_handle); 91 | numInts = sNumInts; 92 | numFds = sNumFds; 93 | } 94 | ~private_handle_t() { 95 | magic = 0; 96 | } 97 | 98 | static int validate(const native_handle* h) { 99 | const private_handle_t* hnd = (const private_handle_t*)h; 100 | if (!h || h->version != sizeof(native_handle) || 101 | h->numInts != sNumInts || h->numFds != sNumFds || 102 | hnd->magic != sMagic) 103 | { 104 | LOGE("invalid gralloc handle (at %p)", h); 105 | return -EINVAL; 106 | } 107 | return 0; 108 | } 109 | #endif 110 | }; 111 | 112 | #endif /* GRALLOC_PRIV_H_ */ 113 | -------------------------------------------------------------------------------- /include/hardware/qemud.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_INCLUDE_HARDWARE_QEMUD_H 18 | #define ANDROID_INCLUDE_HARDWARE_QEMUD_H 19 | 20 | #include 21 | 22 | /* the following is helper code that is used by the QEMU-specific 23 | * hardware HAL modules to communicate with the emulator program 24 | * through the 'qemud' multiplexing daemon. 25 | * 26 | * see the documentation comments for details in 27 | * development/emulator/qemud/qemud.c 28 | * 29 | * all definitions here are built into the HAL module to avoid 30 | * having to write a tiny shared library for this. 31 | */ 32 | 33 | /* we expect the D macro to be defined to a function macro 34 | * that sends its formatted string argument(s) to the log. 35 | * If not, ignore the traces. 36 | */ 37 | #ifndef D 38 | # define D(...) ((void)0) 39 | #endif 40 | 41 | static __inline__ int 42 | qemud_fd_write(int fd, const void* buff, int len) 43 | { 44 | int len2; 45 | do { 46 | len2 = write(fd, buff, len); 47 | } while (len2 < 0 && errno == EINTR); 48 | return len2; 49 | } 50 | 51 | static __inline__ int 52 | qemud_fd_read(int fd, void* buff, int len) 53 | { 54 | int len2; 55 | do { 56 | len2 = read(fd, buff, len); 57 | } while (len2 < 0 && errno == EINTR); 58 | return len2; 59 | } 60 | 61 | static __inline__ int 62 | qemud_channel_open(const char* name) 63 | { 64 | int fd; 65 | int namelen = strlen(name); 66 | char answer[2]; 67 | 68 | /* connect to qemud control socket */ 69 | fd = socket_local_client( "qemud", 70 | ANDROID_SOCKET_NAMESPACE_RESERVED, 71 | SOCK_STREAM ); 72 | if (fd < 0) { 73 | D("no qemud control socket: %s", strerror(errno)); 74 | return -1; 75 | } 76 | 77 | /* send service name to connect */ 78 | if (qemud_fd_write(fd, name, namelen) != namelen) { 79 | D("can't send service name to qemud: %s", 80 | strerror(errno)); 81 | close(fd); 82 | return -1; 83 | } 84 | 85 | /* read answer from daemon */ 86 | if (qemud_fd_read(fd, answer, 2) != 2 || 87 | answer[0] != 'O' || answer[1] != 'K') { 88 | D("cant' connect to %s service through qemud", name); 89 | close(fd); 90 | return -1; 91 | } 92 | return fd; 93 | } 94 | 95 | static __inline__ int 96 | qemud_channel_send(int fd, const void* msg, int msglen) 97 | { 98 | char header[5]; 99 | 100 | if (msglen < 0) 101 | msglen = strlen((const char*)msg); 102 | 103 | if (msglen == 0) 104 | return 0; 105 | 106 | snprintf(header, sizeof header, "%04x", msglen); 107 | if (qemud_fd_write(fd, header, 4) != 4) { 108 | D("can't write qemud frame header: %s", strerror(errno)); 109 | return -1; 110 | } 111 | 112 | if (qemud_fd_write(fd, msg, msglen) != msglen) { 113 | D("can4t write qemud frame payload: %s", strerror(errno)); 114 | return -1; 115 | } 116 | return 0; 117 | } 118 | 119 | static __inline__ int 120 | qemud_channel_recv(int fd, void* msg, int msgsize) 121 | { 122 | char header[5]; 123 | int size, avail; 124 | 125 | if (qemud_fd_read(fd, header, 4) != 4) { 126 | D("can't read qemud frame header: %s", strerror(errno)); 127 | return -1; 128 | } 129 | header[4] = 0; 130 | if (sscanf(header, "%04x", &size) != 1) { 131 | D("malformed qemud frame header: '%.*s'", 4, header); 132 | return -1; 133 | } 134 | if (size > msgsize) 135 | return -1; 136 | 137 | if (qemud_fd_read(fd, msg, size) != size) { 138 | D("can't read qemud frame payload: %s", strerror(errno)); 139 | return -1; 140 | } 141 | return size; 142 | } 143 | 144 | #endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_H */ 145 | -------------------------------------------------------------------------------- /include/hardware/lights.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_LIGHTS_INTERFACE_H 18 | #define ANDROID_LIGHTS_INTERFACE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | __BEGIN_DECLS 27 | 28 | /** 29 | * The id of this module 30 | */ 31 | #define LIGHTS_HARDWARE_MODULE_ID "lights" 32 | 33 | /* 34 | * These light IDs correspond to logical lights, not physical. 35 | * So for example, if your INDICATOR light is in line with your 36 | * BUTTONS, it might make sense to also light the INDICATOR 37 | * light to a reasonable color when the BUTTONS are lit. 38 | */ 39 | #define LIGHT_ID_BACKLIGHT "backlight" 40 | #define LIGHT_ID_KEYBOARD "keyboard" 41 | #define LIGHT_ID_BUTTONS "buttons" 42 | #define LIGHT_ID_BATTERY "battery" 43 | #define LIGHT_ID_NOTIFICATIONS "notifications" 44 | #define LIGHT_ID_ATTENTION "attention" 45 | 46 | /* 47 | * These lights aren't currently supported by the higher 48 | * layers, but could be someday, so we have the constants 49 | * here now. 50 | */ 51 | #define LIGHT_ID_BLUETOOTH "bluetooth" 52 | #define LIGHT_ID_WIFI "wifi" 53 | 54 | /* ************************************************************************ 55 | * Flash modes for the flashMode field of light_state_t. 56 | */ 57 | 58 | #define LIGHT_FLASH_NONE 0 59 | 60 | /** 61 | * To flash the light at a given rate, set flashMode to LIGHT_FLASH_TIMED, 62 | * and then flashOnMS should be set to the number of milliseconds to turn 63 | * the light on, followed by the number of milliseconds to turn the light 64 | * off. 65 | */ 66 | #define LIGHT_FLASH_TIMED 1 67 | 68 | /** 69 | * To flash the light using hardware assist, set flashMode to 70 | * the hardware mode. 71 | */ 72 | #define LIGHT_FLASH_HARDWARE 2 73 | 74 | /** 75 | * Light brightness is managed by a user setting. 76 | */ 77 | #define BRIGHTNESS_MODE_USER 0 78 | 79 | /** 80 | * Light brightness is managed by a light sensor. 81 | */ 82 | #define BRIGHTNESS_MODE_SENSOR 1 83 | 84 | /** 85 | * The parameters that can be set for a given light. 86 | * 87 | * Not all lights must support all parameters. If you 88 | * can do something backward-compatible, you should. 89 | */ 90 | struct light_state_t { 91 | /** 92 | * The color of the LED in ARGB. 93 | * 94 | * Do your best here. 95 | * - If your light can only do red or green, if they ask for blue, 96 | * you should do green. 97 | * - If you can only do a brightness ramp, then use this formula: 98 | * unsigned char brightness = ((77*((color>>16)&0x00ff)) 99 | * + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8; 100 | * - If you can only do on or off, 0 is off, anything else is on. 101 | * 102 | * The high byte should be ignored. Callers will set it to 0xff (which 103 | * would correspond to 255 alpha). 104 | */ 105 | unsigned int color; 106 | 107 | /** 108 | * See the LIGHT_FLASH_* constants 109 | */ 110 | int flashMode; 111 | int flashOnMS; 112 | int flashOffMS; 113 | 114 | /** 115 | * Policy used by the framework to manage the light's brightness. 116 | * Currently the values are BRIGHTNESS_MODE_USER and BRIGHTNESS_MODE_SENSOR. 117 | */ 118 | int brightnessMode; 119 | }; 120 | 121 | struct light_device_t { 122 | struct hw_device_t common; 123 | 124 | /** 125 | * Set the provided lights to the provided values. 126 | * 127 | * Returns: 0 on succes, error code on failure. 128 | */ 129 | int (*set_light)(struct light_device_t* dev, 130 | struct light_state_t const* state); 131 | }; 132 | 133 | 134 | __END_DECLS 135 | 136 | #endif // ANDROID_LIGHTS_INTERFACE_H 137 | 138 | -------------------------------------------------------------------------------- /hardware.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define LOG_TAG "HAL" 28 | #include 29 | 30 | /** Base path of the hal modules */ 31 | #define HAL_LIBRARY_PATH1 "/system/lib/hw" 32 | #define HAL_LIBRARY_PATH2 "/vendor/lib/hw" 33 | 34 | /** 35 | * There are a set of variant filename for modules. The form of the filename 36 | * is ".variant.so" so for the led module the Dream variants 37 | * of base "ro.product.board", "ro.board.platform" and "ro.arch" would be: 38 | * 39 | * led.trout.so 40 | * led.msm7k.so 41 | * led.ARMV6.so 42 | * led.default.so 43 | */ 44 | 45 | static const char *variant_keys[] = { 46 | "ro.hardware", /* This goes first so that it can pick up a different 47 | file on the emulator. */ 48 | "ro.product.board", 49 | "ro.board.platform", 50 | "ro.arch" 51 | }; 52 | 53 | static const int HAL_VARIANT_KEYS_COUNT = 54 | (sizeof(variant_keys)/sizeof(variant_keys[0])); 55 | 56 | /** 57 | * Load the file defined by the variant and if successful 58 | * return the dlopen handle and the hmi. 59 | * @return 0 = success, !0 = failure. 60 | */ 61 | static int load(const char *id, 62 | const char *path, 63 | const struct hw_module_t **pHmi) 64 | { 65 | int status; 66 | void *handle; 67 | struct hw_module_t *hmi; 68 | 69 | /* 70 | * load the symbols resolving undefined symbols before 71 | * dlopen returns. Since RTLD_GLOBAL is not or'd in with 72 | * RTLD_NOW the external symbols will not be global 73 | */ 74 | handle = dlopen(path, RTLD_NOW); 75 | if (handle == NULL) { 76 | char const *err_str = dlerror(); 77 | LOGE("load: module=%s\n%s", path, err_str?err_str:"unknown"); 78 | status = -EINVAL; 79 | goto done; 80 | } 81 | 82 | /* Get the address of the struct hal_module_info. */ 83 | const char *sym = HAL_MODULE_INFO_SYM_AS_STR; 84 | hmi = (struct hw_module_t *)dlsym(handle, sym); 85 | if (hmi == NULL) { 86 | LOGE("load: couldn't find symbol %s", sym); 87 | status = -EINVAL; 88 | goto done; 89 | } 90 | 91 | /* Check that the id matches */ 92 | if (strcmp(id, hmi->id) != 0) { 93 | LOGE("load: id=%s != hmi->id=%s", id, hmi->id); 94 | status = -EINVAL; 95 | goto done; 96 | } 97 | 98 | hmi->dso = handle; 99 | 100 | /* success */ 101 | status = 0; 102 | 103 | done: 104 | if (status != 0) { 105 | hmi = NULL; 106 | if (handle != NULL) { 107 | dlclose(handle); 108 | handle = NULL; 109 | } 110 | } else { 111 | LOGV("loaded HAL id=%s path=%s hmi=%p handle=%p", 112 | id, path, *pHmi, handle); 113 | } 114 | 115 | *pHmi = hmi; 116 | 117 | return status; 118 | } 119 | 120 | int hw_get_module(const char *id, const struct hw_module_t **module) 121 | { 122 | int status; 123 | int i; 124 | const struct hw_module_t *hmi = NULL; 125 | char prop[PATH_MAX]; 126 | char path[PATH_MAX]; 127 | 128 | /* 129 | * Here we rely on the fact that calling dlopen multiple times on 130 | * the same .so will simply increment a refcount (and not load 131 | * a new copy of the library). 132 | * We also assume that dlopen() is thread-safe. 133 | */ 134 | 135 | /* Loop through the configuration variants looking for a module */ 136 | for (i=0 ; i 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "gralloc_priv.h" 34 | 35 | 36 | /* desktop Linux needs a little help with gettid() */ 37 | #if defined(ARCH_X86) && !defined(HAVE_ANDROID_OS) 38 | #define __KERNEL__ 39 | # include 40 | pid_t gettid() { return syscall(__NR_gettid);} 41 | #undef __KERNEL__ 42 | #endif 43 | 44 | /*****************************************************************************/ 45 | 46 | static int gralloc_map(gralloc_module_t const* module, 47 | buffer_handle_t handle, 48 | void** vaddr) 49 | { 50 | private_handle_t* hnd = (private_handle_t*)handle; 51 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { 52 | size_t size = hnd->size; 53 | void* mappedAddress = mmap(0, size, 54 | PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0); 55 | if (mappedAddress == MAP_FAILED) { 56 | LOGE("Could not mmap %s", strerror(errno)); 57 | return -errno; 58 | } 59 | hnd->base = intptr_t(mappedAddress) + hnd->offset; 60 | //LOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p", 61 | // hnd->fd, hnd->offset, hnd->size, mappedAddress); 62 | } 63 | *vaddr = (void*)hnd->base; 64 | return 0; 65 | } 66 | 67 | static int gralloc_unmap(gralloc_module_t const* module, 68 | buffer_handle_t handle) 69 | { 70 | private_handle_t* hnd = (private_handle_t*)handle; 71 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { 72 | void* base = (void*)hnd->base; 73 | size_t size = hnd->size; 74 | //LOGD("unmapping from %p, size=%d", base, size); 75 | if (munmap(base, size) < 0) { 76 | LOGE("Could not unmap %s", strerror(errno)); 77 | } 78 | } 79 | hnd->base = 0; 80 | return 0; 81 | } 82 | 83 | /*****************************************************************************/ 84 | 85 | static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER; 86 | 87 | /*****************************************************************************/ 88 | 89 | int gralloc_register_buffer(gralloc_module_t const* module, 90 | buffer_handle_t handle) 91 | { 92 | if (private_handle_t::validate(handle) < 0) 93 | return -EINVAL; 94 | 95 | // if this handle was created in this process, then we keep it as is. 96 | int err = 0; 97 | private_handle_t* hnd = (private_handle_t*)handle; 98 | if (hnd->pid != getpid()) { 99 | void *vaddr; 100 | err = gralloc_map(module, handle, &vaddr); 101 | } 102 | return err; 103 | } 104 | 105 | int gralloc_unregister_buffer(gralloc_module_t const* module, 106 | buffer_handle_t handle) 107 | { 108 | if (private_handle_t::validate(handle) < 0) 109 | return -EINVAL; 110 | 111 | // never unmap buffers that were created in this process 112 | private_handle_t* hnd = (private_handle_t*)handle; 113 | if (hnd->pid != getpid()) { 114 | if (hnd->base) { 115 | gralloc_unmap(module, handle); 116 | } 117 | } 118 | return 0; 119 | } 120 | 121 | int mapBuffer(gralloc_module_t const* module, 122 | private_handle_t* hnd) 123 | { 124 | void* vaddr; 125 | return gralloc_map(module, hnd, &vaddr); 126 | } 127 | 128 | int terminateBuffer(gralloc_module_t const* module, 129 | private_handle_t* hnd) 130 | { 131 | if (hnd->base) { 132 | // this buffer was mapped, unmap it now 133 | gralloc_unmap(module, hnd); 134 | } 135 | 136 | return 0; 137 | } 138 | 139 | int gralloc_lock(gralloc_module_t const* module, 140 | buffer_handle_t handle, int usage, 141 | int l, int t, int w, int h, 142 | void** vaddr) 143 | { 144 | // this is called when a buffer is being locked for software 145 | // access. in thin implementation we have nothing to do since 146 | // not synchronization with the h/w is needed. 147 | // typically this is used to wait for the h/w to finish with 148 | // this buffer if relevant. the data cache may need to be 149 | // flushed or invalidated depending on the usage bits and the 150 | // hardware. 151 | 152 | if (private_handle_t::validate(handle) < 0) 153 | return -EINVAL; 154 | 155 | private_handle_t* hnd = (private_handle_t*)handle; 156 | *vaddr = (void*)hnd->base; 157 | return 0; 158 | } 159 | 160 | int gralloc_unlock(gralloc_module_t const* module, 161 | buffer_handle_t handle) 162 | { 163 | // we're done with a software buffer. nothing to do in this 164 | // implementation. typically this is used to flush the data cache. 165 | 166 | if (private_handle_t::validate(handle) < 0) 167 | return -EINVAL; 168 | return 0; 169 | } 170 | -------------------------------------------------------------------------------- /include/hardware/hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H 18 | #define ANDROID_INCLUDE_HARDWARE_HARDWARE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | __BEGIN_DECLS 26 | 27 | /* 28 | * Value for the hw_module_t.tag field 29 | */ 30 | 31 | #define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D)) 32 | 33 | #define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T') 34 | #define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T') 35 | 36 | struct hw_module_t; 37 | struct hw_module_methods_t; 38 | struct hw_device_t; 39 | 40 | /** 41 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 42 | * and the fields of this data structure must begin with hw_module_t 43 | * followed by module specific information. 44 | */ 45 | typedef struct hw_module_t { 46 | /** tag must be initialized to HARDWARE_MODULE_TAG */ 47 | uint32_t tag; 48 | 49 | /** major version number for the module */ 50 | uint16_t version_major; 51 | 52 | /** minor version number of the module */ 53 | uint16_t version_minor; 54 | 55 | /** Identifier of module */ 56 | const char *id; 57 | 58 | /** Name of this module */ 59 | const char *name; 60 | 61 | /** Author/owner/implementor of the module */ 62 | const char *author; 63 | 64 | /** Modules methods */ 65 | struct hw_module_methods_t* methods; 66 | 67 | /** module's dso */ 68 | void* dso; 69 | 70 | /** padding to 128 bytes, reserved for future use */ 71 | uint32_t reserved[32-7]; 72 | 73 | } hw_module_t; 74 | 75 | typedef struct hw_module_methods_t { 76 | /** Open a specific device */ 77 | int (*open)(const struct hw_module_t* module, const char* id, 78 | struct hw_device_t** device); 79 | 80 | } hw_module_methods_t; 81 | 82 | /** 83 | * Every device data structure must begin with hw_device_t 84 | * followed by module specific public methods and attributes. 85 | */ 86 | typedef struct hw_device_t { 87 | /** tag must be initialized to HARDWARE_DEVICE_TAG */ 88 | uint32_t tag; 89 | 90 | /** version number for hw_device_t */ 91 | uint32_t version; 92 | 93 | /** reference to the module this device belongs to */ 94 | struct hw_module_t* module; 95 | 96 | /** padding reserved for future use */ 97 | uint32_t reserved[12]; 98 | 99 | /** Close this device */ 100 | int (*close)(struct hw_device_t* device); 101 | 102 | } hw_device_t; 103 | 104 | /** 105 | * Name of the hal_module_info 106 | */ 107 | #define HAL_MODULE_INFO_SYM HMI 108 | 109 | /** 110 | * Name of the hal_module_info as a string 111 | */ 112 | #define HAL_MODULE_INFO_SYM_AS_STR "HMI" 113 | 114 | /** 115 | * Get the module info associated with a module by id. 116 | * @return: 0 == success, <0 == error and *pHmi == NULL 117 | */ 118 | int hw_get_module(const char *id, const struct hw_module_t **module); 119 | 120 | 121 | /** 122 | * pixel format definitions 123 | */ 124 | 125 | enum { 126 | HAL_PIXEL_FORMAT_RGBA_8888 = 1, 127 | HAL_PIXEL_FORMAT_RGBX_8888 = 2, 128 | HAL_PIXEL_FORMAT_RGB_888 = 3, 129 | HAL_PIXEL_FORMAT_RGB_565 = 4, 130 | HAL_PIXEL_FORMAT_BGRA_8888 = 5, 131 | HAL_PIXEL_FORMAT_RGBA_5551 = 6, 132 | HAL_PIXEL_FORMAT_RGBA_4444 = 7, 133 | 134 | /* 0x8 - 0xFF range unavailable */ 135 | 136 | /* 137 | * 0x100 - 0x1FF 138 | * 139 | * This range is reserved for pixel formats that are specific to the HAL 140 | * implementation. Implementations can use any value in this range to 141 | * communicate video pixel formats between their HAL modules. These formats 142 | * must not have an alpha channel. Additionally, an EGLimage created from a 143 | * gralloc buffer of one of these formats must be supported for use with the 144 | * GL_OES_EGL_image_external OpenGL ES extension. 145 | */ 146 | 147 | /* 148 | * Android YUV format: 149 | * 150 | * This format is exposed outside of the HAL to software 151 | * decoders and applications. 152 | * EGLImageKHR must support it in conjunction with the 153 | * OES_EGL_image_external extension. 154 | * 155 | * YV12 is 4:2:0 YCrCb planar format comprised of a WxH Y plane followed 156 | * by (W/2) x (H/2) Cr and Cb planes. 157 | * 158 | * This format assumes 159 | * - an even width 160 | * - an even height 161 | * - a horizontal stride multiple of 16 pixels 162 | * - a vertical stride equal to the height 163 | * 164 | * y_size = stride * height 165 | * c_size = ALIGN(stride/2, 16) * height/2 166 | * size = y_size + c_size * 2 167 | * cr_offset = y_size 168 | * cb_offset = y_size + c_size 169 | * 170 | */ 171 | HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar 172 | 173 | 174 | 175 | /* Legacy formats (deprecated), used by ImageFormat.java */ 176 | HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16 177 | HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21 178 | HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2 179 | }; 180 | 181 | 182 | /** 183 | * Transformation definitions 184 | * 185 | * IMPORTANT NOTE: 186 | * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}. 187 | * 188 | */ 189 | 190 | enum { 191 | /* flip source image horizontally (around the vertical axis) */ 192 | HAL_TRANSFORM_FLIP_H = 0x01, 193 | /* flip source image vertically (around the horizontal axis)*/ 194 | HAL_TRANSFORM_FLIP_V = 0x02, 195 | /* rotate source image 90 degrees clockwise */ 196 | HAL_TRANSFORM_ROT_90 = 0x04, 197 | /* rotate source image 180 degrees */ 198 | HAL_TRANSFORM_ROT_180 = 0x03, 199 | /* rotate source image 270 degrees clockwise */ 200 | HAL_TRANSFORM_ROT_270 = 0x07, 201 | }; 202 | 203 | __END_DECLS 204 | 205 | #endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */ 206 | -------------------------------------------------------------------------------- /tests/nusensors/nusensors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | char const* getSensorName(int type) { 28 | switch(type) { 29 | case SENSOR_TYPE_ACCELEROMETER: 30 | return "Acc"; 31 | case SENSOR_TYPE_MAGNETIC_FIELD: 32 | return "Mag"; 33 | case SENSOR_TYPE_ORIENTATION: 34 | return "Ori"; 35 | case SENSOR_TYPE_PROXIMITY: 36 | return "Prx"; 37 | case SENSOR_TYPE_TEMPERATURE: 38 | return "Tmp"; 39 | case SENSOR_TYPE_LIGHT: 40 | return "Lux"; 41 | } 42 | return "ukn"; 43 | } 44 | 45 | int main(int argc, char** argv) 46 | { 47 | int err; 48 | struct sensors_poll_device_t* device; 49 | struct sensors_module_t* module; 50 | 51 | err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&module); 52 | if (err != 0) { 53 | printf("hw_get_module() failed (%s)\n", strerror(-err)); 54 | return 0; 55 | } 56 | 57 | struct sensor_t const* list; 58 | int count = module->get_sensors_list(module, &list); 59 | for (int i=0 ; icommon, &device); 81 | if (err != 0) { 82 | printf("sensors_open() failed (%s)\n", strerror(-err)); 83 | return 0; 84 | } 85 | 86 | for (int i=0 ; iactivate(device, list[i].handle, 0); 88 | if (err != 0) { 89 | printf("deactivate() for '%s'failed (%s)\n", 90 | list[i].name, strerror(-err)); 91 | return 0; 92 | } 93 | } 94 | 95 | for (int i=0 ; iactivate(device, list[i].handle, 1); 97 | if (err != 0) { 98 | printf("activate() for '%s'failed (%s)\n", 99 | list[i].name, strerror(-err)); 100 | return 0; 101 | } 102 | device->setDelay(device, list[i].handle, 10000000); 103 | } 104 | 105 | do { 106 | int n = device->poll(device, buffer, 16); 107 | if (n < 0) { 108 | printf("poll() failed (%s)\n", strerror(-err)); 109 | break; 110 | } 111 | 112 | printf("read %d events:\n", n); 113 | for (int i=0 ; i\n", 125 | getSensorName(data.type), 126 | data.timestamp, 127 | data.acceleration.x, 128 | data.acceleration.y, 129 | data.acceleration.z); 130 | break; 131 | case SENSOR_TYPE_MAGNETIC_FIELD: 132 | printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", 133 | getSensorName(data.type), 134 | data.timestamp, 135 | data.magnetic.x, 136 | data.magnetic.y, 137 | data.magnetic.z); 138 | break; 139 | case SENSOR_TYPE_ORIENTATION: 140 | printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", 141 | getSensorName(data.type), 142 | data.timestamp, 143 | data.orientation.azimuth, 144 | data.orientation.pitch, 145 | data.orientation.roll); 146 | break; 147 | case SENSOR_TYPE_PROXIMITY: 148 | printf("sensor=%s, time=%lld, value=%f\n", 149 | getSensorName(data.type), 150 | data.timestamp, 151 | data.distance); 152 | break; 153 | case SENSOR_TYPE_TEMPERATURE: 154 | printf("sensor=%s, time=%lld, value=%f\n", 155 | getSensorName(data.type), 156 | data.timestamp, 157 | data.temperature); 158 | break; 159 | case SENSOR_TYPE_LIGHT: 160 | printf("sensor=%s, time=%lld, value=%f\n", 161 | getSensorName(data.type), 162 | data.timestamp, 163 | data.light); 164 | break; 165 | default: 166 | printf("sensor=%d, time=%lld, value=<%f,%f,%f>\n", 167 | data.type, 168 | data.timestamp, 169 | data.acceleration.x, 170 | data.acceleration.y, 171 | data.acceleration.z); 172 | break; 173 | } 174 | } 175 | 176 | 177 | } while (1); // fix that 178 | 179 | 180 | for (int i=0 ; iactivate(device, list[i].handle, 0); 182 | if (err != 0) { 183 | printf("deactivate() for '%s'failed (%s)\n", 184 | list[i].name, strerror(-err)); 185 | return 0; 186 | } 187 | } 188 | 189 | err = sensors_close(device); 190 | if (err != 0) { 191 | printf("sensors_close() failed (%s)\n", strerror(-err)); 192 | } 193 | return 0; 194 | } 195 | -------------------------------------------------------------------------------- /include/hardware/copybit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_COPYBIT_INTERFACE_H 18 | #define ANDROID_COPYBIT_INTERFACE_H 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | __BEGIN_DECLS 27 | 28 | /** 29 | * The id of this module 30 | */ 31 | #define COPYBIT_HARDWARE_MODULE_ID "copybit" 32 | 33 | /** 34 | * Name of the graphics device to open 35 | */ 36 | #define COPYBIT_HARDWARE_COPYBIT0 "copybit0" 37 | 38 | /* supported pixel-formats. these must be compatible with 39 | * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h 40 | */ 41 | enum { 42 | COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, 43 | COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, 44 | COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, 45 | COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, 46 | COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, 47 | COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, 48 | COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, 49 | COPYBIT_FORMAT_YCbCr_422_SP = 0x10, 50 | COPYBIT_FORMAT_YCrCb_420_SP = 0x11, 51 | }; 52 | 53 | /* name for copybit_set_parameter */ 54 | enum { 55 | /* rotation of the source image in degrees (0 to 359) */ 56 | COPYBIT_ROTATION_DEG = 1, 57 | /* plane alpha value */ 58 | COPYBIT_PLANE_ALPHA = 2, 59 | /* enable or disable dithering */ 60 | COPYBIT_DITHER = 3, 61 | /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ 62 | COPYBIT_TRANSFORM = 4, 63 | /* blurs the copied bitmap. The amount of blurring cannot be changed 64 | * at this time. */ 65 | COPYBIT_BLUR = 5 66 | }; 67 | 68 | /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ 69 | enum { 70 | /* flip source image horizontally */ 71 | COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, 72 | /* flip source image vertically */ 73 | COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 74 | /* rotate source image 90 degres */ 75 | COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 76 | /* rotate source image 180 degres */ 77 | COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 78 | /* rotate source image 270 degres */ 79 | COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, 80 | }; 81 | 82 | /* enable/disable value copybit_set_parameter */ 83 | enum { 84 | COPYBIT_DISABLE = 0, 85 | COPYBIT_ENABLE = 1 86 | }; 87 | 88 | /* use get_static_info() to query static informations about the hardware */ 89 | enum { 90 | /* Maximum amount of minification supported by the hardware*/ 91 | COPYBIT_MINIFICATION_LIMIT = 1, 92 | /* Maximum amount of magnification supported by the hardware */ 93 | COPYBIT_MAGNIFICATION_LIMIT = 2, 94 | /* Number of fractional bits support by the scaling engine */ 95 | COPYBIT_SCALING_FRAC_BITS = 3, 96 | /* Supported rotation step in degres. */ 97 | COPYBIT_ROTATION_STEP_DEG = 4, 98 | }; 99 | 100 | /* Image structure */ 101 | struct copybit_image_t { 102 | /* width */ 103 | uint32_t w; 104 | /* height */ 105 | uint32_t h; 106 | /* format COPYBIT_FORMAT_xxx */ 107 | int32_t format; 108 | /* base of buffer with image */ 109 | void *base; 110 | /* handle to the image */ 111 | native_handle_t* handle; 112 | }; 113 | 114 | /* Rectangle */ 115 | struct copybit_rect_t { 116 | /* left */ 117 | int l; 118 | /* top */ 119 | int t; 120 | /* right */ 121 | int r; 122 | /* bottom */ 123 | int b; 124 | }; 125 | 126 | /* Region */ 127 | struct copybit_region_t { 128 | int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); 129 | }; 130 | 131 | /** 132 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 133 | * and the fields of this data structure must begin with hw_module_t 134 | * followed by module specific information. 135 | */ 136 | struct copybit_module_t { 137 | struct hw_module_t common; 138 | }; 139 | 140 | /** 141 | * Every device data structure must begin with hw_device_t 142 | * followed by module specific public methods and attributes. 143 | */ 144 | struct copybit_device_t { 145 | struct hw_device_t common; 146 | 147 | /** 148 | * Set a copybit parameter. 149 | * 150 | * @param dev from open 151 | * @param name one for the COPYBIT_NAME_xxx 152 | * @param value one of the COPYBIT_VALUE_xxx 153 | * 154 | * @return 0 if successful 155 | */ 156 | int (*set_parameter)(struct copybit_device_t *dev, int name, int value); 157 | 158 | /** 159 | * Get a static copybit information. 160 | * 161 | * @param dev from open 162 | * @param name one of the COPYBIT_STATIC_xxx 163 | * 164 | * @return value or -EINVAL if error 165 | */ 166 | int (*get)(struct copybit_device_t *dev, int name); 167 | 168 | /** 169 | * Execute the bit blit copy operation 170 | * 171 | * @param dev from open 172 | * @param dst is the destination image 173 | * @param src is the source image 174 | * @param region the clip region 175 | * 176 | * @return 0 if successful 177 | */ 178 | int (*blit)(struct copybit_device_t *dev, 179 | struct copybit_image_t const *dst, 180 | struct copybit_image_t const *src, 181 | struct copybit_region_t const *region); 182 | 183 | /** 184 | * Execute the stretch bit blit copy operation 185 | * 186 | * @param dev from open 187 | * @param dst is the destination image 188 | * @param src is the source image 189 | * @param dst_rect is the destination rectangle 190 | * @param src_rect is the source rectangle 191 | * @param region the clip region 192 | * 193 | * @return 0 if successful 194 | */ 195 | int (*stretch)(struct copybit_device_t *dev, 196 | struct copybit_image_t const *dst, 197 | struct copybit_image_t const *src, 198 | struct copybit_rect_t const *dst_rect, 199 | struct copybit_rect_t const *src_rect, 200 | struct copybit_region_t const *region); 201 | }; 202 | 203 | 204 | /** convenience API for opening and closing a device */ 205 | 206 | static inline int copybit_open(const struct hw_module_t* module, 207 | struct copybit_device_t** device) { 208 | return module->methods->open(module, 209 | COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); 210 | } 211 | 212 | static inline int copybit_close(struct copybit_device_t* device) { 213 | return device->common.close(&device->common); 214 | } 215 | 216 | 217 | __END_DECLS 218 | 219 | #endif // ANDROID_COPYBIT_INTERFACE_H 220 | -------------------------------------------------------------------------------- /include/hardware/overlay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_OVERLAY_INTERFACE_H 18 | #define ANDROID_OVERLAY_INTERFACE_H 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | __BEGIN_DECLS 29 | 30 | /** 31 | * The id of this module 32 | */ 33 | #define OVERLAY_HARDWARE_MODULE_ID "overlay" 34 | 35 | /** 36 | * Name of the overlay device to open 37 | */ 38 | #define OVERLAY_HARDWARE_CONTROL "control" 39 | #define OVERLAY_HARDWARE_DATA "data" 40 | 41 | /*****************************************************************************/ 42 | 43 | /* possible overlay formats */ 44 | enum { 45 | OVERLAY_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, 46 | OVERLAY_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, 47 | OVERLAY_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, 48 | OVERLAY_FORMAT_YCbYCr_422_I = 0x14, 49 | OVERLAY_FORMAT_CbYCrY_422_I = 0x16, 50 | OVERLAY_FORMAT_DEFAULT = 99 // The actual color format is determined 51 | // by the overlay 52 | }; 53 | 54 | /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ 55 | enum { 56 | /* flip source image horizontally */ 57 | OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, 58 | /* flip source image vertically */ 59 | OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 60 | /* rotate source image 90 degrees */ 61 | OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 62 | /* rotate source image 180 degrees */ 63 | OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 64 | /* rotate source image 270 degrees */ 65 | OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270 66 | }; 67 | 68 | /* names for setParameter() */ 69 | enum { 70 | /* rotation of the source image in degrees (0 to 359) */ 71 | OVERLAY_ROTATION_DEG = 1, 72 | /* enable or disable dithering */ 73 | OVERLAY_DITHER = 3, 74 | /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ 75 | OVERLAY_TRANSFORM = 4, 76 | }; 77 | 78 | /* enable/disable value setParameter() */ 79 | enum { 80 | OVERLAY_DISABLE = 0, 81 | OVERLAY_ENABLE = 1 82 | }; 83 | 84 | /* names for get() */ 85 | enum { 86 | /* Maximum amount of minification supported by the hardware*/ 87 | OVERLAY_MINIFICATION_LIMIT = 1, 88 | /* Maximum amount of magnification supported by the hardware */ 89 | OVERLAY_MAGNIFICATION_LIMIT = 2, 90 | /* Number of fractional bits support by the overlay scaling engine */ 91 | OVERLAY_SCALING_FRAC_BITS = 3, 92 | /* Supported rotation step in degrees. */ 93 | OVERLAY_ROTATION_STEP_DEG = 4, 94 | /* horizontal alignment in pixels */ 95 | OVERLAY_HORIZONTAL_ALIGNMENT = 5, 96 | /* vertical alignment in pixels */ 97 | OVERLAY_VERTICAL_ALIGNMENT = 6, 98 | /* width alignment restrictions. negative number for max. power-of-two */ 99 | OVERLAY_WIDTH_ALIGNMENT = 7, 100 | /* height alignment restrictions. negative number for max. power-of-two */ 101 | OVERLAY_HEIGHT_ALIGNMENT = 8, 102 | }; 103 | 104 | /*****************************************************************************/ 105 | 106 | /* opaque reference to an Overlay kernel object */ 107 | typedef const native_handle* overlay_handle_t; 108 | 109 | typedef struct overlay_t { 110 | uint32_t w; 111 | uint32_t h; 112 | int32_t format; 113 | uint32_t w_stride; 114 | uint32_t h_stride; 115 | uint32_t reserved[3]; 116 | /* returns a reference to this overlay's handle (the caller doesn't 117 | * take ownership) */ 118 | overlay_handle_t (*getHandleRef)(struct overlay_t* overlay); 119 | uint32_t reserved_procs[7]; 120 | } overlay_t; 121 | 122 | typedef void* overlay_buffer_t; 123 | 124 | /*****************************************************************************/ 125 | 126 | /** 127 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 128 | * and the fields of this data structure must begin with hw_module_t 129 | * followed by module specific information. 130 | */ 131 | struct overlay_module_t { 132 | struct hw_module_t common; 133 | }; 134 | 135 | /*****************************************************************************/ 136 | 137 | /** 138 | * Every device data structure must begin with hw_device_t 139 | * followed by module specific public methods and attributes. 140 | */ 141 | 142 | struct overlay_control_device_t { 143 | struct hw_device_t common; 144 | 145 | /* get static informations about the capabilities of the overlay engine */ 146 | int (*get)(struct overlay_control_device_t *dev, int name); 147 | 148 | /* creates an overlay matching the given parameters as closely as possible. 149 | * returns an error if no more overlays are available. The actual 150 | * size and format is returned in overlay_t. */ 151 | overlay_t* (*createOverlay)(struct overlay_control_device_t *dev, 152 | uint32_t w, uint32_t h, int32_t format); 153 | 154 | /* destroys an overlay. This call releases all 155 | * resources associated with overlay_t and make it invalid */ 156 | void (*destroyOverlay)(struct overlay_control_device_t *dev, 157 | overlay_t* overlay); 158 | 159 | /* set position and scaling of the given overlay as closely as possible. 160 | * if scaling cannot be performed, overlay must be centered. */ 161 | int (*setPosition)(struct overlay_control_device_t *dev, 162 | overlay_t* overlay, 163 | int x, int y, uint32_t w, uint32_t h); 164 | 165 | /* returns the actual position and size of the overlay */ 166 | int (*getPosition)(struct overlay_control_device_t *dev, 167 | overlay_t* overlay, 168 | int* x, int* y, uint32_t* w, uint32_t* h); 169 | 170 | /* sets configurable parameters for this overlay. returns an error if not 171 | * supported. */ 172 | int (*setParameter)(struct overlay_control_device_t *dev, 173 | overlay_t* overlay, int param, int value); 174 | 175 | int (*stage)(struct overlay_control_device_t *dev, overlay_t* overlay); 176 | int (*commit)(struct overlay_control_device_t *dev, overlay_t* overlay); 177 | }; 178 | 179 | 180 | struct overlay_data_device_t { 181 | struct hw_device_t common; 182 | 183 | /* initialize the overlay from the given handle. this associates this 184 | * overlay data module to its control module */ 185 | int (*initialize)(struct overlay_data_device_t *dev, 186 | overlay_handle_t handle); 187 | 188 | /* can be called to change the width and height of the overlay. */ 189 | int (*resizeInput)(struct overlay_data_device_t *dev, 190 | uint32_t w, uint32_t h); 191 | 192 | int (*setCrop)(struct overlay_data_device_t *dev, 193 | uint32_t x, uint32_t y, uint32_t w, uint32_t h) ; 194 | 195 | int (*getCrop)(struct overlay_data_device_t *dev, 196 | uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) ; 197 | 198 | int (*setParameter)(struct overlay_data_device_t *dev, 199 | int param, int value); 200 | 201 | /* blocks until an overlay buffer is available and return that buffer. */ 202 | int (*dequeueBuffer)(struct overlay_data_device_t *dev, 203 | overlay_buffer_t *buf); 204 | 205 | /* release the overlay buffer and post it */ 206 | int (*queueBuffer)(struct overlay_data_device_t *dev, 207 | overlay_buffer_t buffer); 208 | 209 | /* returns the address of a given buffer if supported, NULL otherwise. */ 210 | void* (*getBufferAddress)(struct overlay_data_device_t *dev, 211 | overlay_buffer_t buffer); 212 | 213 | int (*getBufferCount)(struct overlay_data_device_t *dev); 214 | }; 215 | 216 | 217 | /*****************************************************************************/ 218 | 219 | /** convenience API for opening and closing a device */ 220 | 221 | static inline int overlay_control_open(const struct hw_module_t* module, 222 | struct overlay_control_device_t** device) { 223 | return module->methods->open(module, 224 | OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device); 225 | } 226 | 227 | static inline int overlay_control_close(struct overlay_control_device_t* device) { 228 | return device->common.close(&device->common); 229 | } 230 | 231 | static inline int overlay_data_open(const struct hw_module_t* module, 232 | struct overlay_data_device_t** device) { 233 | return module->methods->open(module, 234 | OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device); 235 | } 236 | 237 | static inline int overlay_data_close(struct overlay_data_device_t* device) { 238 | return device->common.close(&device->common); 239 | } 240 | 241 | __END_DECLS 242 | 243 | #endif // ANDROID_OVERLAY_INTERFACE_H 244 | -------------------------------------------------------------------------------- /modules/gralloc/gralloc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "gralloc_priv.h" 38 | #include "gr.h" 39 | 40 | /*****************************************************************************/ 41 | 42 | struct gralloc_context_t { 43 | alloc_device_t device; 44 | /* our private data here */ 45 | }; 46 | 47 | static int gralloc_alloc_buffer(alloc_device_t* dev, 48 | size_t size, int usage, buffer_handle_t* pHandle); 49 | 50 | /*****************************************************************************/ 51 | 52 | int fb_device_open(const hw_module_t* module, const char* name, 53 | hw_device_t** device); 54 | 55 | static int gralloc_device_open(const hw_module_t* module, const char* name, 56 | hw_device_t** device); 57 | 58 | extern int gralloc_lock(gralloc_module_t const* module, 59 | buffer_handle_t handle, int usage, 60 | int l, int t, int w, int h, 61 | void** vaddr); 62 | 63 | extern int gralloc_unlock(gralloc_module_t const* module, 64 | buffer_handle_t handle); 65 | 66 | extern int gralloc_register_buffer(gralloc_module_t const* module, 67 | buffer_handle_t handle); 68 | 69 | extern int gralloc_unregister_buffer(gralloc_module_t const* module, 70 | buffer_handle_t handle); 71 | 72 | /*****************************************************************************/ 73 | 74 | static struct hw_module_methods_t gralloc_module_methods = { 75 | open: gralloc_device_open 76 | }; 77 | 78 | struct private_module_t HAL_MODULE_INFO_SYM = { 79 | base: { 80 | common: { 81 | tag: HARDWARE_MODULE_TAG, 82 | version_major: 1, 83 | version_minor: 0, 84 | id: GRALLOC_HARDWARE_MODULE_ID, 85 | name: "Graphics Memory Allocator Module", 86 | author: "The Android Open Source Project", 87 | methods: &gralloc_module_methods 88 | }, 89 | registerBuffer: gralloc_register_buffer, 90 | unregisterBuffer: gralloc_unregister_buffer, 91 | lock: gralloc_lock, 92 | unlock: gralloc_unlock, 93 | }, 94 | framebuffer: 0, 95 | flags: 0, 96 | numBuffers: 0, 97 | bufferMask: 0, 98 | lock: PTHREAD_MUTEX_INITIALIZER, 99 | currentBuffer: 0, 100 | }; 101 | 102 | /*****************************************************************************/ 103 | 104 | static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev, 105 | size_t size, int usage, buffer_handle_t* pHandle) 106 | { 107 | private_module_t* m = reinterpret_cast( 108 | dev->common.module); 109 | 110 | // allocate the framebuffer 111 | if (m->framebuffer == NULL) { 112 | // initialize the framebuffer, the framebuffer is mapped once 113 | // and forever. 114 | int err = mapFrameBufferLocked(m); 115 | if (err < 0) { 116 | return err; 117 | } 118 | } 119 | 120 | const uint32_t bufferMask = m->bufferMask; 121 | const uint32_t numBuffers = m->numBuffers; 122 | const size_t bufferSize = m->finfo.line_length * m->info.yres; 123 | if (numBuffers == 1) { 124 | // If we have only one buffer, we never use page-flipping. Instead, 125 | // we return a regular buffer which will be memcpy'ed to the main 126 | // screen when post is called. 127 | int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D; 128 | return gralloc_alloc_buffer(dev, bufferSize, newUsage, pHandle); 129 | } 130 | 131 | if (bufferMask >= ((1LU<framebuffer->base); 138 | private_handle_t* hnd = new private_handle_t(dup(m->framebuffer->fd), size, 139 | private_handle_t::PRIV_FLAGS_FRAMEBUFFER); 140 | 141 | // find a free slot 142 | for (uint32_t i=0 ; ibufferMask |= (1LU<base = vaddr; 151 | hnd->offset = vaddr - intptr_t(m->framebuffer->base); 152 | *pHandle = hnd; 153 | 154 | return 0; 155 | } 156 | 157 | static int gralloc_alloc_framebuffer(alloc_device_t* dev, 158 | size_t size, int usage, buffer_handle_t* pHandle) 159 | { 160 | private_module_t* m = reinterpret_cast( 161 | dev->common.module); 162 | pthread_mutex_lock(&m->lock); 163 | int err = gralloc_alloc_framebuffer_locked(dev, size, usage, pHandle); 164 | pthread_mutex_unlock(&m->lock); 165 | return err; 166 | } 167 | 168 | static int gralloc_alloc_buffer(alloc_device_t* dev, 169 | size_t size, int usage, buffer_handle_t* pHandle) 170 | { 171 | int err = 0; 172 | int fd = -1; 173 | 174 | size = roundUpToPageSize(size); 175 | 176 | fd = ashmem_create_region("gralloc-buffer", size); 177 | if (fd < 0) { 178 | LOGE("couldn't create ashmem (%s)", strerror(-errno)); 179 | err = -errno; 180 | } 181 | 182 | if (err == 0) { 183 | private_handle_t* hnd = new private_handle_t(fd, size, 0); 184 | gralloc_module_t* module = reinterpret_cast( 185 | dev->common.module); 186 | err = mapBuffer(module, hnd); 187 | if (err == 0) { 188 | *pHandle = hnd; 189 | } 190 | } 191 | 192 | LOGE_IF(err, "gralloc failed err=%s", strerror(-err)); 193 | 194 | return err; 195 | } 196 | 197 | /*****************************************************************************/ 198 | 199 | static int gralloc_alloc(alloc_device_t* dev, 200 | int w, int h, int format, int usage, 201 | buffer_handle_t* pHandle, int* pStride) 202 | { 203 | if (!pHandle || !pStride) 204 | return -EINVAL; 205 | 206 | size_t size, stride; 207 | 208 | int align = 4; 209 | int bpp = 0; 210 | switch (format) { 211 | case HAL_PIXEL_FORMAT_RGBA_8888: 212 | case HAL_PIXEL_FORMAT_RGBX_8888: 213 | case HAL_PIXEL_FORMAT_BGRA_8888: 214 | bpp = 4; 215 | break; 216 | case HAL_PIXEL_FORMAT_RGB_888: 217 | bpp = 3; 218 | break; 219 | case HAL_PIXEL_FORMAT_RGB_565: 220 | case HAL_PIXEL_FORMAT_RGBA_5551: 221 | case HAL_PIXEL_FORMAT_RGBA_4444: 222 | bpp = 2; 223 | break; 224 | default: 225 | return -EINVAL; 226 | } 227 | size_t bpr = (w*bpp + (align-1)) & ~(align-1); 228 | size = bpr * h; 229 | stride = bpr / bpp; 230 | 231 | int err; 232 | if (usage & GRALLOC_USAGE_HW_FB) { 233 | err = gralloc_alloc_framebuffer(dev, size, usage, pHandle); 234 | } else { 235 | err = gralloc_alloc_buffer(dev, size, usage, pHandle); 236 | } 237 | 238 | if (err < 0) { 239 | return err; 240 | } 241 | 242 | *pStride = stride; 243 | return 0; 244 | } 245 | 246 | static int gralloc_free(alloc_device_t* dev, 247 | buffer_handle_t handle) 248 | { 249 | if (private_handle_t::validate(handle) < 0) 250 | return -EINVAL; 251 | 252 | private_handle_t const* hnd = reinterpret_cast(handle); 253 | if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) { 254 | // free this buffer 255 | private_module_t* m = reinterpret_cast( 256 | dev->common.module); 257 | const size_t bufferSize = m->finfo.line_length * m->info.yres; 258 | int index = (hnd->base - m->framebuffer->base) / bufferSize; 259 | m->bufferMask &= ~(1<( 262 | dev->common.module); 263 | terminateBuffer(module, const_cast(hnd)); 264 | } 265 | 266 | close(hnd->fd); 267 | delete hnd; 268 | return 0; 269 | } 270 | 271 | /*****************************************************************************/ 272 | 273 | static int gralloc_close(struct hw_device_t *dev) 274 | { 275 | gralloc_context_t* ctx = reinterpret_cast(dev); 276 | if (ctx) { 277 | /* TODO: keep a list of all buffer_handle_t created, and free them 278 | * all here. 279 | */ 280 | free(ctx); 281 | } 282 | return 0; 283 | } 284 | 285 | int gralloc_device_open(const hw_module_t* module, const char* name, 286 | hw_device_t** device) 287 | { 288 | int status = -EINVAL; 289 | if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { 290 | gralloc_context_t *dev; 291 | dev = (gralloc_context_t*)malloc(sizeof(*dev)); 292 | 293 | /* initialize our state here */ 294 | memset(dev, 0, sizeof(*dev)); 295 | 296 | /* initialize the procs */ 297 | dev->device.common.tag = HARDWARE_DEVICE_TAG; 298 | dev->device.common.version = 0; 299 | dev->device.common.module = const_cast(module); 300 | dev->device.common.close = gralloc_close; 301 | 302 | dev->device.alloc = gralloc_alloc; 303 | dev->device.free = gralloc_free; 304 | 305 | *device = &dev->device.common; 306 | status = 0; 307 | } else { 308 | status = fb_device_open(module, name, device); 309 | } 310 | return status; 311 | } 312 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2005-2008, 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 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Apache License 15 | Version 2.0, January 2004 16 | http://www.apache.org/licenses/ 17 | 18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 19 | 20 | 1. Definitions. 21 | 22 | "License" shall mean the terms and conditions for use, reproduction, 23 | and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by 26 | the copyright owner that is granting the License. 27 | 28 | "Legal Entity" shall mean the union of the acting entity and all 29 | other entities that control, are controlled by, or are under common 30 | control with that entity. For the purposes of this definition, 31 | "control" means (i) the power, direct or indirect, to cause the 32 | direction or management of such entity, whether by contract or 33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 34 | outstanding shares, or (iii) beneficial ownership of such entity. 35 | 36 | "You" (or "Your") shall mean an individual or Legal Entity 37 | exercising permissions granted by this License. 38 | 39 | "Source" form shall mean the preferred form for making modifications, 40 | including but not limited to software source code, documentation 41 | source, and configuration files. 42 | 43 | "Object" form shall mean any form resulting from mechanical 44 | transformation or translation of a Source form, including but 45 | not limited to compiled object code, generated documentation, 46 | and conversions to other media types. 47 | 48 | "Work" shall mean the work of authorship, whether in Source or 49 | Object form, made available under the License, as indicated by a 50 | copyright notice that is included in or attached to the work 51 | (an example is provided in the Appendix below). 52 | 53 | "Derivative Works" shall mean any work, whether in Source or Object 54 | form, that is based on (or derived from) the Work and for which the 55 | editorial revisions, annotations, elaborations, or other modifications 56 | represent, as a whole, an original work of authorship. For the purposes 57 | of this License, Derivative Works shall not include works that remain 58 | separable from, or merely link (or bind by name) to the interfaces of, 59 | the Work and Derivative Works thereof. 60 | 61 | "Contribution" shall mean any work of authorship, including 62 | the original version of the Work and any modifications or additions 63 | to that Work or Derivative Works thereof, that is intentionally 64 | submitted to Licensor for inclusion in the Work by the copyright owner 65 | or by an individual or Legal Entity authorized to submit on behalf of 66 | the copyright owner. For the purposes of this definition, "submitted" 67 | means any form of electronic, verbal, or written communication sent 68 | to the Licensor or its representatives, including but not limited to 69 | communication on electronic mailing lists, source code control systems, 70 | and issue tracking systems that are managed by, or on behalf of, the 71 | Licensor for the purpose of discussing and improving the Work, but 72 | excluding communication that is conspicuously marked or otherwise 73 | designated in writing by the copyright owner as "Not a Contribution." 74 | 75 | "Contributor" shall mean Licensor and any individual or Legal Entity 76 | on behalf of whom a Contribution has been received by Licensor and 77 | subsequently incorporated within the Work. 78 | 79 | 2. Grant of Copyright License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | copyright license to reproduce, prepare Derivative Works of, 83 | publicly display, publicly perform, sublicense, and distribute the 84 | Work and such Derivative Works in Source or Object form. 85 | 86 | 3. Grant of Patent License. Subject to the terms and conditions of 87 | this License, each Contributor hereby grants to You a perpetual, 88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 89 | (except as stated in this section) patent license to make, have made, 90 | use, offer to sell, sell, import, and otherwise transfer the Work, 91 | where such license applies only to those patent claims licensable 92 | by such Contributor that are necessarily infringed by their 93 | Contribution(s) alone or by combination of their Contribution(s) 94 | with the Work to which such Contribution(s) was submitted. If You 95 | institute patent litigation against any entity (including a 96 | cross-claim or counterclaim in a lawsuit) alleging that the Work 97 | or a Contribution incorporated within the Work constitutes direct 98 | or contributory patent infringement, then any patent licenses 99 | granted to You under this License for that Work shall terminate 100 | as of the date such litigation is filed. 101 | 102 | 4. Redistribution. You may reproduce and distribute copies of the 103 | Work or Derivative Works thereof in any medium, with or without 104 | modifications, and in Source or Object form, provided that You 105 | meet the following conditions: 106 | 107 | (a) You must give any other recipients of the Work or 108 | Derivative Works a copy of this License; and 109 | 110 | (b) You must cause any modified files to carry prominent notices 111 | stating that You changed the files; and 112 | 113 | (c) You must retain, in the Source form of any Derivative Works 114 | that You distribute, all copyright, patent, trademark, and 115 | attribution notices from the Source form of the Work, 116 | excluding those notices that do not pertain to any part of 117 | the Derivative Works; and 118 | 119 | (d) If the Work includes a "NOTICE" text file as part of its 120 | distribution, then any Derivative Works that You distribute must 121 | include a readable copy of the attribution notices contained 122 | within such NOTICE file, excluding those notices that do not 123 | pertain to any part of the Derivative Works, in at least one 124 | of the following places: within a NOTICE text file distributed 125 | as part of the Derivative Works; within the Source form or 126 | documentation, if provided along with the Derivative Works; or, 127 | within a display generated by the Derivative Works, if and 128 | wherever such third-party notices normally appear. The contents 129 | of the NOTICE file are for informational purposes only and 130 | do not modify the License. You may add Your own attribution 131 | notices within Derivative Works that You distribute, alongside 132 | or as an addendum to the NOTICE text from the Work, provided 133 | that such additional attribution notices cannot be construed 134 | as modifying the License. 135 | 136 | You may add Your own copyright statement to Your modifications and 137 | may provide additional or different license terms and conditions 138 | for use, reproduction, or distribution of Your modifications, or 139 | for any such Derivative Works as a whole, provided Your use, 140 | reproduction, and distribution of the Work otherwise complies with 141 | the conditions stated in this License. 142 | 143 | 5. Submission of Contributions. Unless You explicitly state otherwise, 144 | any Contribution intentionally submitted for inclusion in the Work 145 | by You to the Licensor shall be under the terms and conditions of 146 | this License, without any additional terms or conditions. 147 | Notwithstanding the above, nothing herein shall supersede or modify 148 | the terms of any separate license agreement you may have executed 149 | with Licensor regarding such Contributions. 150 | 151 | 6. Trademarks. This License does not grant permission to use the trade 152 | names, trademarks, service marks, or product names of the Licensor, 153 | except as required for reasonable and customary use in describing the 154 | origin of the Work and reproducing the content of the NOTICE file. 155 | 156 | 7. Disclaimer of Warranty. Unless required by applicable law or 157 | agreed to in writing, Licensor provides the Work (and each 158 | Contributor provides its Contributions) on an "AS IS" BASIS, 159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 160 | implied, including, without limitation, any warranties or conditions 161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 162 | PARTICULAR PURPOSE. You are solely responsible for determining the 163 | appropriateness of using or redistributing the Work and assume any 164 | risks associated with Your exercise of permissions under this License. 165 | 166 | 8. Limitation of Liability. In no event and under no legal theory, 167 | whether in tort (including negligence), contract, or otherwise, 168 | unless required by applicable law (such as deliberate and grossly 169 | negligent acts) or agreed to in writing, shall any Contributor be 170 | liable to You for damages, including any direct, indirect, special, 171 | incidental, or consequential damages of any character arising as a 172 | result of this License or out of the use or inability to use the 173 | Work (including but not limited to damages for loss of goodwill, 174 | work stoppage, computer failure or malfunction, or any and all 175 | other commercial damages or losses), even if such Contributor 176 | has been advised of the possibility of such damages. 177 | 178 | 9. Accepting Warranty or Additional Liability. While redistributing 179 | the Work or Derivative Works thereof, You may choose to offer, 180 | and charge a fee for, acceptance of support, warranty, indemnity, 181 | or other liability obligations and/or rights consistent with this 182 | License. However, in accepting such obligations, You may act only 183 | on Your own behalf and on Your sole responsibility, not on behalf 184 | of any other Contributor, and only if You agree to indemnify, 185 | defend, and hold each Contributor harmless for any liability 186 | incurred by, or claims asserted against, such Contributor by reason 187 | of your accepting any such warranty or additional liability. 188 | 189 | END OF TERMS AND CONDITIONS 190 | 191 | -------------------------------------------------------------------------------- /modules/overlay/overlay.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #define LOG_TAG "Overlay" 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | /*****************************************************************************/ 29 | 30 | struct overlay_control_context_t { 31 | struct overlay_control_device_t device; 32 | /* our private state goes below here */ 33 | }; 34 | 35 | struct overlay_data_context_t { 36 | struct overlay_data_device_t device; 37 | /* our private state goes below here */ 38 | }; 39 | 40 | static int overlay_device_open(const struct hw_module_t* module, const char* name, 41 | struct hw_device_t** device); 42 | 43 | static struct hw_module_methods_t overlay_module_methods = { 44 | open: overlay_device_open 45 | }; 46 | 47 | struct overlay_module_t HAL_MODULE_INFO_SYM = { 48 | common: { 49 | tag: HARDWARE_MODULE_TAG, 50 | version_major: 1, 51 | version_minor: 0, 52 | id: OVERLAY_HARDWARE_MODULE_ID, 53 | name: "Sample Overlay module", 54 | author: "The Android Open Source Project", 55 | methods: &overlay_module_methods, 56 | } 57 | }; 58 | 59 | /*****************************************************************************/ 60 | 61 | /* 62 | * This is the overlay_t object, it is returned to the user and represents 63 | * an overlay. 64 | * This handles will be passed across processes and possibly given to other 65 | * HAL modules (for instance video decode modules). 66 | */ 67 | 68 | class overlay_object : public overlay_t { 69 | 70 | struct handle_t : public native_handle { 71 | /* add the data fields we need here, for instance: */ 72 | int width; 73 | int height; 74 | }; 75 | 76 | handle_t mHandle; 77 | 78 | static overlay_handle_t getHandleRef(struct overlay_t* overlay) { 79 | /* returns a reference to the handle, caller doesn't take ownership */ 80 | return &(static_cast(overlay)->mHandle); 81 | } 82 | 83 | public: 84 | overlay_object() { 85 | this->overlay_t::getHandleRef = getHandleRef; 86 | mHandle.version = sizeof(native_handle); 87 | mHandle.numFds = 0; 88 | mHandle.numInts = 2; // extra ints we have in our handle 89 | } 90 | }; 91 | 92 | // **************************************************************************** 93 | // Control module 94 | // **************************************************************************** 95 | 96 | static int overlay_get(struct overlay_control_device_t *dev, int name) { 97 | int result = -1; 98 | switch (name) { 99 | case OVERLAY_MINIFICATION_LIMIT: 100 | result = 0; // 0 = no limit 101 | break; 102 | case OVERLAY_MAGNIFICATION_LIMIT: 103 | result = 0; // 0 = no limit 104 | break; 105 | case OVERLAY_SCALING_FRAC_BITS: 106 | result = 0; // 0 = infinite 107 | break; 108 | case OVERLAY_ROTATION_STEP_DEG: 109 | result = 90; // 90 rotation steps (for instance) 110 | break; 111 | case OVERLAY_HORIZONTAL_ALIGNMENT: 112 | result = 1; // 1-pixel alignment 113 | break; 114 | case OVERLAY_VERTICAL_ALIGNMENT: 115 | result = 1; // 1-pixel alignment 116 | break; 117 | case OVERLAY_WIDTH_ALIGNMENT: 118 | result = 1; // 1-pixel alignment 119 | break; 120 | case OVERLAY_HEIGHT_ALIGNMENT: 121 | result = 1; // 1-pixel alignment 122 | break; 123 | } 124 | return result; 125 | } 126 | 127 | static overlay_t* overlay_createOverlay(struct overlay_control_device_t *dev, 128 | uint32_t w, uint32_t h, int32_t format) 129 | { 130 | /* check the input params, reject if not supported or invalid */ 131 | switch (format) { 132 | case OVERLAY_FORMAT_RGBA_8888: 133 | case OVERLAY_FORMAT_RGB_565: 134 | case OVERLAY_FORMAT_BGRA_8888: 135 | // add supported format here (especially YUV formats) 136 | break; 137 | default: 138 | return NULL; 139 | } 140 | 141 | /* Create overlay object. Talk to the h/w here and adjust to what it can 142 | * do. the overlay_t returned can be a C++ object, subclassing overlay_t 143 | * if needed. 144 | * 145 | * we probably want to keep a list of the overlay_t created so they can 146 | * all be cleaned up in overlay_close(). 147 | */ 148 | return new overlay_object( /* pass needed params here*/ ); 149 | } 150 | 151 | static void overlay_destroyOverlay(struct overlay_control_device_t *dev, 152 | overlay_t* overlay) 153 | { 154 | /* free resources associated with this overlay_t */ 155 | delete overlay; 156 | } 157 | 158 | static int overlay_setPosition(struct overlay_control_device_t *dev, 159 | overlay_t* overlay, 160 | int x, int y, uint32_t w, uint32_t h) { 161 | /* set this overlay's position (talk to the h/w) */ 162 | return -EINVAL; 163 | } 164 | 165 | static int overlay_getPosition(struct overlay_control_device_t *dev, 166 | overlay_t* overlay, 167 | int* x, int* y, uint32_t* w, uint32_t* h) { 168 | /* get this overlay's position */ 169 | return -EINVAL; 170 | } 171 | 172 | static int overlay_setParameter(struct overlay_control_device_t *dev, 173 | overlay_t* overlay, int param, int value) { 174 | 175 | int result = 0; 176 | /* set this overlay's parameter (talk to the h/w) */ 177 | switch (param) { 178 | case OVERLAY_ROTATION_DEG: 179 | /* if only 90 rotations are supported, the call fails 180 | * for other values */ 181 | break; 182 | case OVERLAY_DITHER: 183 | break; 184 | case OVERLAY_TRANSFORM: 185 | // see OVERLAY_TRANSFORM_* 186 | break; 187 | default: 188 | result = -EINVAL; 189 | break; 190 | } 191 | return result; 192 | } 193 | 194 | static int overlay_control_close(struct hw_device_t *dev) 195 | { 196 | struct overlay_control_context_t* ctx = (struct overlay_control_context_t*)dev; 197 | if (ctx) { 198 | /* free all resources associated with this device here 199 | * in particular the overlay_handle_t, outstanding overlay_t, etc... 200 | */ 201 | free(ctx); 202 | } 203 | return 0; 204 | } 205 | 206 | // **************************************************************************** 207 | // Data module 208 | // **************************************************************************** 209 | 210 | int overlay_initialize(struct overlay_data_device_t *dev, 211 | overlay_handle_t handle) 212 | { 213 | /* 214 | * overlay_handle_t should contain all the information to "inflate" this 215 | * overlay. Typically it'll have a file descriptor, informations about 216 | * how many buffers are there, etc... 217 | * It is also the place to mmap all buffers associated with this overlay 218 | * (see getBufferAddress). 219 | * 220 | * NOTE: this function doesn't take ownership of overlay_handle_t 221 | * 222 | */ 223 | 224 | return -EINVAL; 225 | } 226 | 227 | int overlay_dequeueBuffer(struct overlay_data_device_t *dev, 228 | overlay_buffer_t* buf) 229 | { 230 | /* blocks until a buffer is available and return an opaque structure 231 | * representing this buffer. 232 | */ 233 | return -EINVAL; 234 | } 235 | 236 | int overlay_queueBuffer(struct overlay_data_device_t *dev, 237 | overlay_buffer_t buffer) 238 | { 239 | /* Mark this buffer for posting and recycle or free overlay_buffer_t. */ 240 | return -EINVAL; 241 | } 242 | 243 | void *overlay_getBufferAddress(struct overlay_data_device_t *dev, 244 | overlay_buffer_t buffer) 245 | { 246 | /* this may fail (NULL) if this feature is not supported. In that case, 247 | * presumably, there is some other HAL module that can fill the buffer, 248 | * using a DSP for instance */ 249 | return NULL; 250 | } 251 | 252 | static int overlay_data_close(struct hw_device_t *dev) 253 | { 254 | struct overlay_data_context_t* ctx = (struct overlay_data_context_t*)dev; 255 | if (ctx) { 256 | /* free all resources associated with this device here 257 | * in particular all pending overlay_buffer_t if needed. 258 | * 259 | * NOTE: overlay_handle_t passed in initialize() is NOT freed and 260 | * its file descriptors are not closed (this is the responsibility 261 | * of the caller). 262 | */ 263 | free(ctx); 264 | } 265 | return 0; 266 | } 267 | 268 | /*****************************************************************************/ 269 | 270 | static int overlay_device_open(const struct hw_module_t* module, const char* name, 271 | struct hw_device_t** device) 272 | { 273 | int status = -EINVAL; 274 | if (!strcmp(name, OVERLAY_HARDWARE_CONTROL)) { 275 | struct overlay_control_context_t *dev; 276 | dev = (overlay_control_context_t*)malloc(sizeof(*dev)); 277 | 278 | /* initialize our state here */ 279 | memset(dev, 0, sizeof(*dev)); 280 | 281 | /* initialize the procs */ 282 | dev->device.common.tag = HARDWARE_DEVICE_TAG; 283 | dev->device.common.version = 0; 284 | dev->device.common.module = const_cast(module); 285 | dev->device.common.close = overlay_control_close; 286 | 287 | dev->device.get = overlay_get; 288 | dev->device.createOverlay = overlay_createOverlay; 289 | dev->device.destroyOverlay = overlay_destroyOverlay; 290 | dev->device.setPosition = overlay_setPosition; 291 | dev->device.getPosition = overlay_getPosition; 292 | dev->device.setParameter = overlay_setParameter; 293 | 294 | *device = &dev->device.common; 295 | status = 0; 296 | } else if (!strcmp(name, OVERLAY_HARDWARE_DATA)) { 297 | struct overlay_data_context_t *dev; 298 | dev = (overlay_data_context_t*)malloc(sizeof(*dev)); 299 | 300 | /* initialize our state here */ 301 | memset(dev, 0, sizeof(*dev)); 302 | 303 | /* initialize the procs */ 304 | dev->device.common.tag = HARDWARE_DEVICE_TAG; 305 | dev->device.common.version = 0; 306 | dev->device.common.module = const_cast(module); 307 | dev->device.common.close = overlay_data_close; 308 | 309 | dev->device.initialize = overlay_initialize; 310 | dev->device.dequeueBuffer = overlay_dequeueBuffer; 311 | dev->device.queueBuffer = overlay_queueBuffer; 312 | dev->device.getBufferAddress = overlay_getBufferAddress; 313 | 314 | *device = &dev->device.common; 315 | status = 0; 316 | } 317 | return status; 318 | } 319 | -------------------------------------------------------------------------------- /modules/gralloc/framebuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #if HAVE_ANDROID_OS 37 | #include 38 | #endif 39 | 40 | #include "gralloc_priv.h" 41 | #include "gr.h" 42 | 43 | /*****************************************************************************/ 44 | 45 | // numbers of buffers for page flipping 46 | #if defined(NO_PAGE_FLIPPING) 47 | // page-flipping is buggy on some devices 48 | #define NUM_BUFFERS 1 49 | #else 50 | #define NUM_BUFFERS 2 51 | #endif 52 | 53 | 54 | enum { 55 | PAGE_FLIP = 0x00000001, 56 | LOCKED = 0x00000002 57 | }; 58 | 59 | struct fb_context_t { 60 | framebuffer_device_t device; 61 | }; 62 | 63 | /*****************************************************************************/ 64 | 65 | static int fb_setSwapInterval(struct framebuffer_device_t* dev, 66 | int interval) 67 | { 68 | fb_context_t* ctx = (fb_context_t*)dev; 69 | if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval) 70 | return -EINVAL; 71 | // FIXME: implement fb_setSwapInterval 72 | return 0; 73 | } 74 | 75 | static int fb_setUpdateRect(struct framebuffer_device_t* dev, 76 | int l, int t, int w, int h) 77 | { 78 | if (((w|h) <= 0) || ((l|t)<0)) 79 | return -EINVAL; 80 | 81 | fb_context_t* ctx = (fb_context_t*)dev; 82 | private_module_t* m = reinterpret_cast( 83 | dev->common.module); 84 | m->info.reserved[0] = 0x54445055; // "UPDT"; 85 | m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16); 86 | m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16); 87 | return 0; 88 | } 89 | 90 | static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer) 91 | { 92 | if (private_handle_t::validate(buffer) < 0) 93 | return -EINVAL; 94 | 95 | fb_context_t* ctx = (fb_context_t*)dev; 96 | 97 | private_handle_t const* hnd = reinterpret_cast(buffer); 98 | private_module_t* m = reinterpret_cast( 99 | dev->common.module); 100 | 101 | if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) { 102 | const size_t offset = hnd->base - m->framebuffer->base; 103 | m->info.activate = FB_ACTIVATE_VBL; 104 | m->info.yoffset = offset / m->finfo.line_length; 105 | if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) { 106 | LOGE("FBIOPUT_VSCREENINFO failed"); 107 | m->base.unlock(&m->base, buffer); 108 | return -errno; 109 | } 110 | m->currentBuffer = buffer; 111 | 112 | } else { 113 | // If we can't do the page_flip, just copy the buffer to the front 114 | // FIXME: use copybit HAL instead of memcpy 115 | 116 | void* fb_vaddr; 117 | void* buffer_vaddr; 118 | 119 | m->base.lock(&m->base, m->framebuffer, 120 | GRALLOC_USAGE_SW_WRITE_RARELY, 121 | 0, 0, m->info.xres, m->info.yres, 122 | &fb_vaddr); 123 | 124 | m->base.lock(&m->base, buffer, 125 | GRALLOC_USAGE_SW_READ_RARELY, 126 | 0, 0, m->info.xres, m->info.yres, 127 | &buffer_vaddr); 128 | 129 | memcpy(fb_vaddr, buffer_vaddr, m->finfo.line_length * m->info.yres); 130 | 131 | m->base.unlock(&m->base, buffer); 132 | m->base.unlock(&m->base, m->framebuffer); 133 | } 134 | 135 | return 0; 136 | } 137 | 138 | /*****************************************************************************/ 139 | 140 | int mapFrameBufferLocked(struct private_module_t* module) 141 | { 142 | // already initialized... 143 | if (module->framebuffer) { 144 | return 0; 145 | } 146 | 147 | char const * const device_template[] = { 148 | "/dev/graphics/fb%u", 149 | "/dev/fb%u", 150 | 0 }; 151 | 152 | int fd = -1; 153 | int i=0; 154 | char name[64]; 155 | 156 | while ((fd==-1) && device_template[i]) { 157 | snprintf(name, 64, device_template[i], 0); 158 | fd = open(name, O_RDWR, 0); 159 | i++; 160 | } 161 | if (fd < 0) 162 | return -errno; 163 | 164 | struct fb_fix_screeninfo finfo; 165 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) 166 | return -errno; 167 | 168 | struct fb_var_screeninfo info; 169 | if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) 170 | return -errno; 171 | 172 | info.reserved[0] = 0; 173 | info.reserved[1] = 0; 174 | info.reserved[2] = 0; 175 | info.xoffset = 0; 176 | info.yoffset = 0; 177 | info.activate = FB_ACTIVATE_NOW; 178 | 179 | /* 180 | * Explicitly request 5/6/5 181 | */ 182 | info.bits_per_pixel = 16; 183 | info.red.offset = 11; 184 | info.red.length = 5; 185 | info.green.offset = 5; 186 | info.green.length = 6; 187 | info.blue.offset = 0; 188 | info.blue.length = 5; 189 | info.transp.offset = 0; 190 | info.transp.length = 0; 191 | 192 | /* 193 | * Request NUM_BUFFERS screens (at lest 2 for page flipping) 194 | */ 195 | info.yres_virtual = info.yres * NUM_BUFFERS; 196 | 197 | 198 | uint32_t flags = PAGE_FLIP; 199 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) { 200 | info.yres_virtual = info.yres; 201 | flags &= ~PAGE_FLIP; 202 | LOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported"); 203 | } 204 | 205 | if (info.yres_virtual < info.yres * 2) { 206 | // we need at least 2 for page-flipping 207 | info.yres_virtual = info.yres; 208 | flags &= ~PAGE_FLIP; 209 | LOGW("page flipping not supported (yres_virtual=%d, requested=%d)", 210 | info.yres_virtual, info.yres*2); 211 | } 212 | 213 | if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) 214 | return -errno; 215 | 216 | int refreshRate = 1000000000000000LLU / 217 | ( 218 | uint64_t( info.upper_margin + info.lower_margin + info.yres ) 219 | * ( info.left_margin + info.right_margin + info.xres ) 220 | * info.pixclock 221 | ); 222 | 223 | if (refreshRate == 0) { 224 | // bleagh, bad info from the driver 225 | refreshRate = 60*1000; // 60 Hz 226 | } 227 | 228 | if (int(info.width) <= 0 || int(info.height) <= 0) { 229 | // the driver doesn't return that information 230 | // default to 160 dpi 231 | info.width = ((info.xres * 25.4f)/160.0f + 0.5f); 232 | info.height = ((info.yres * 25.4f)/160.0f + 0.5f); 233 | } 234 | 235 | float xdpi = (info.xres * 25.4f) / info.width; 236 | float ydpi = (info.yres * 25.4f) / info.height; 237 | float fps = refreshRate / 1000.0f; 238 | 239 | LOGI( "using (fd=%d)\n" 240 | "id = %s\n" 241 | "xres = %d px\n" 242 | "yres = %d px\n" 243 | "xres_virtual = %d px\n" 244 | "yres_virtual = %d px\n" 245 | "bpp = %d\n" 246 | "r = %2u:%u\n" 247 | "g = %2u:%u\n" 248 | "b = %2u:%u\n", 249 | fd, 250 | finfo.id, 251 | info.xres, 252 | info.yres, 253 | info.xres_virtual, 254 | info.yres_virtual, 255 | info.bits_per_pixel, 256 | info.red.offset, info.red.length, 257 | info.green.offset, info.green.length, 258 | info.blue.offset, info.blue.length 259 | ); 260 | 261 | LOGI( "width = %d mm (%f dpi)\n" 262 | "height = %d mm (%f dpi)\n" 263 | "refresh rate = %.2f Hz\n", 264 | info.width, xdpi, 265 | info.height, ydpi, 266 | fps 267 | ); 268 | 269 | 270 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) 271 | return -errno; 272 | 273 | if (finfo.smem_len <= 0) 274 | return -errno; 275 | 276 | 277 | module->flags = flags; 278 | module->info = info; 279 | module->finfo = finfo; 280 | module->xdpi = xdpi; 281 | module->ydpi = ydpi; 282 | module->fps = fps; 283 | 284 | /* 285 | * map the framebuffer 286 | */ 287 | 288 | int err; 289 | size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres_virtual); 290 | module->framebuffer = new private_handle_t(dup(fd), fbSize, 0); 291 | 292 | module->numBuffers = info.yres_virtual / info.yres; 293 | module->bufferMask = 0; 294 | 295 | void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 296 | if (vaddr == MAP_FAILED) { 297 | LOGE("Error mapping the framebuffer (%s)", strerror(errno)); 298 | return -errno; 299 | } 300 | module->framebuffer->base = intptr_t(vaddr); 301 | memset(vaddr, 0, fbSize); 302 | return 0; 303 | } 304 | 305 | static int mapFrameBuffer(struct private_module_t* module) 306 | { 307 | pthread_mutex_lock(&module->lock); 308 | int err = mapFrameBufferLocked(module); 309 | pthread_mutex_unlock(&module->lock); 310 | return err; 311 | } 312 | 313 | /*****************************************************************************/ 314 | 315 | static int fb_close(struct hw_device_t *dev) 316 | { 317 | fb_context_t* ctx = (fb_context_t*)dev; 318 | if (ctx) { 319 | free(ctx); 320 | } 321 | return 0; 322 | } 323 | 324 | int fb_device_open(hw_module_t const* module, const char* name, 325 | hw_device_t** device) 326 | { 327 | int status = -EINVAL; 328 | if (!strcmp(name, GRALLOC_HARDWARE_FB0)) { 329 | alloc_device_t* gralloc_device; 330 | status = gralloc_open(module, &gralloc_device); 331 | if (status < 0) 332 | return status; 333 | 334 | /* initialize our state here */ 335 | fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev)); 336 | memset(dev, 0, sizeof(*dev)); 337 | 338 | /* initialize the procs */ 339 | dev->device.common.tag = HARDWARE_DEVICE_TAG; 340 | dev->device.common.version = 0; 341 | dev->device.common.module = const_cast(module); 342 | dev->device.common.close = fb_close; 343 | dev->device.setSwapInterval = fb_setSwapInterval; 344 | dev->device.post = fb_post; 345 | dev->device.setUpdateRect = 0; 346 | 347 | private_module_t* m = (private_module_t*)module; 348 | status = mapFrameBuffer(m); 349 | if (status >= 0) { 350 | int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3); 351 | const_cast(dev->device.flags) = 0; 352 | const_cast(dev->device.width) = m->info.xres; 353 | const_cast(dev->device.height) = m->info.yres; 354 | const_cast(dev->device.stride) = stride; 355 | const_cast(dev->device.format) = HAL_PIXEL_FORMAT_RGB_565; 356 | const_cast(dev->device.xdpi) = m->xdpi; 357 | const_cast(dev->device.ydpi) = m->ydpi; 358 | const_cast(dev->device.fps) = m->fps; 359 | const_cast(dev->device.minSwapInterval) = 1; 360 | const_cast(dev->device.maxSwapInterval) = 1; 361 | *device = &dev->device.common; 362 | } 363 | } 364 | return status; 365 | } 366 | -------------------------------------------------------------------------------- /include/hardware/gralloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | 18 | #ifndef ANDROID_GRALLOC_INTERFACE_H 19 | #define ANDROID_GRALLOC_INTERFACE_H 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | __BEGIN_DECLS 30 | 31 | /** 32 | * The id of this module 33 | */ 34 | #define GRALLOC_HARDWARE_MODULE_ID "gralloc" 35 | 36 | /** 37 | * Name of the graphics device to open 38 | */ 39 | 40 | #define GRALLOC_HARDWARE_FB0 "fb0" 41 | #define GRALLOC_HARDWARE_GPU0 "gpu0" 42 | 43 | enum { 44 | /* buffer is never read in software */ 45 | GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, 46 | /* buffer is rarely read in software */ 47 | GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, 48 | /* buffer is often read in software */ 49 | GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, 50 | /* mask for the software read values */ 51 | GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, 52 | 53 | /* buffer is never written in software */ 54 | GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, 55 | /* buffer is never written in software */ 56 | GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, 57 | /* buffer is never written in software */ 58 | GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, 59 | /* mask for the software write values */ 60 | GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, 61 | 62 | /* buffer will be used as an OpenGL ES texture */ 63 | GRALLOC_USAGE_HW_TEXTURE = 0x00000100, 64 | /* buffer will be used as an OpenGL ES render target */ 65 | GRALLOC_USAGE_HW_RENDER = 0x00000200, 66 | /* buffer will be used by the 2D hardware blitter */ 67 | GRALLOC_USAGE_HW_2D = 0x00000400, 68 | /* buffer will be used with the framebuffer device */ 69 | GRALLOC_USAGE_HW_FB = 0x00001000, 70 | /* mask for the software usage bit-mask */ 71 | GRALLOC_USAGE_HW_MASK = 0x00001F00, 72 | 73 | /* implementation-specific private usage flags */ 74 | GRALLOC_USAGE_PRIVATE_0 = 0x10000000, 75 | GRALLOC_USAGE_PRIVATE_1 = 0x20000000, 76 | GRALLOC_USAGE_PRIVATE_2 = 0x40000000, 77 | GRALLOC_USAGE_PRIVATE_3 = 0x80000000, 78 | GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000, 79 | }; 80 | 81 | /*****************************************************************************/ 82 | 83 | typedef const native_handle* buffer_handle_t; 84 | 85 | enum { 86 | /* FIXME: this only exists to work-around some issues with 87 | * the video and camera frameworks. don't implement unless 88 | * you know what you're doing. 89 | */ 90 | GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, 91 | }; 92 | 93 | /** 94 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 95 | * and the fields of this data structure must begin with hw_module_t 96 | * followed by module specific information. 97 | */ 98 | typedef struct gralloc_module_t { 99 | struct hw_module_t common; 100 | 101 | /* 102 | * (*registerBuffer)() must be called before a buffer_handle_t that has not 103 | * been created with (*alloc_device_t::alloc)() can be used. 104 | * 105 | * This is intended to be used with buffer_handle_t's that have been 106 | * received in this process through IPC. 107 | * 108 | * This function checks that the handle is indeed a valid one and prepares 109 | * it for use with (*lock)() and (*unlock)(). 110 | * 111 | * It is not necessary to call (*registerBuffer)() on a handle created 112 | * with (*alloc_device_t::alloc)(). 113 | * 114 | * returns an error if this buffer_handle_t is not valid. 115 | */ 116 | int (*registerBuffer)(struct gralloc_module_t const* module, 117 | buffer_handle_t handle); 118 | 119 | /* 120 | * (*unregisterBuffer)() is called once this handle is no longer needed in 121 | * this process. After this call, it is an error to call (*lock)(), 122 | * (*unlock)(), or (*registerBuffer)(). 123 | * 124 | * This function doesn't close or free the handle itself; this is done 125 | * by other means, usually through libcutils's native_handle_close() and 126 | * native_handle_free(). 127 | * 128 | * It is an error to call (*unregisterBuffer)() on a buffer that wasn't 129 | * explicitly registered first. 130 | */ 131 | int (*unregisterBuffer)(struct gralloc_module_t const* module, 132 | buffer_handle_t handle); 133 | 134 | /* 135 | * The (*lock)() method is called before a buffer is accessed for the 136 | * specified usage. This call may block, for instance if the h/w needs 137 | * to finish rendering or if CPU caches need to be synchronized. 138 | * 139 | * The caller promises to modify only pixels in the area specified 140 | * by (l,t,w,h). 141 | * 142 | * The content of the buffer outside of the specified area is NOT modified 143 | * by this call. 144 | * 145 | * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address 146 | * of the buffer in virtual memory. 147 | * 148 | * THREADING CONSIDERATIONS: 149 | * 150 | * It is legal for several different threads to lock a buffer from 151 | * read access, none of the threads are blocked. 152 | * 153 | * However, locking a buffer simultaneously for write or read/write is 154 | * undefined, but: 155 | * - shall not result in termination of the process 156 | * - shall not block the caller 157 | * It is acceptable to return an error or to leave the buffer's content 158 | * into an indeterminate state. 159 | * 160 | * If the buffer was created with a usage mask incompatible with the 161 | * requested usage flags here, -EINVAL is returned. 162 | * 163 | */ 164 | 165 | int (*lock)(struct gralloc_module_t const* module, 166 | buffer_handle_t handle, int usage, 167 | int l, int t, int w, int h, 168 | void** vaddr); 169 | 170 | 171 | /* 172 | * The (*unlock)() method must be called after all changes to the buffer 173 | * are completed. 174 | */ 175 | 176 | int (*unlock)(struct gralloc_module_t const* module, 177 | buffer_handle_t handle); 178 | 179 | 180 | /* reserved for future use */ 181 | int (*perform)(struct gralloc_module_t const* module, 182 | int operation, ... ); 183 | 184 | /* reserved for future use */ 185 | void* reserved_proc[7]; 186 | } gralloc_module_t; 187 | 188 | /*****************************************************************************/ 189 | 190 | /** 191 | * Every device data structure must begin with hw_device_t 192 | * followed by module specific public methods and attributes. 193 | */ 194 | 195 | typedef struct alloc_device_t { 196 | struct hw_device_t common; 197 | 198 | /* 199 | * (*alloc)() Allocates a buffer in graphic memory with the requested 200 | * parameters and returns a buffer_handle_t and the stride in pixels to 201 | * allow the implementation to satisfy hardware constraints on the width 202 | * of a pixmap (eg: it may have to be multiple of 8 pixels). 203 | * The CALLER TAKES OWNERSHIP of the buffer_handle_t. 204 | * 205 | * Returns 0 on success or -errno on error. 206 | */ 207 | 208 | int (*alloc)(struct alloc_device_t* dev, 209 | int w, int h, int format, int usage, 210 | buffer_handle_t* handle, int* stride); 211 | 212 | /* 213 | * (*free)() Frees a previously allocated buffer. 214 | * Behavior is undefined if the buffer is still mapped in any process, 215 | * but shall not result in termination of the program or security breaches 216 | * (allowing a process to get access to another process' buffers). 217 | * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes 218 | * invalid after the call. 219 | * 220 | * Returns 0 on success or -errno on error. 221 | */ 222 | int (*free)(struct alloc_device_t* dev, 223 | buffer_handle_t handle); 224 | 225 | } alloc_device_t; 226 | 227 | 228 | typedef struct framebuffer_device_t { 229 | struct hw_device_t common; 230 | 231 | /* flags describing some attributes of the framebuffer */ 232 | const uint32_t flags; 233 | 234 | /* dimensions of the framebuffer in pixels */ 235 | const uint32_t width; 236 | const uint32_t height; 237 | 238 | /* frambuffer stride in pixels */ 239 | const int stride; 240 | 241 | /* framebuffer pixel format */ 242 | const int format; 243 | 244 | /* resolution of the framebuffer's display panel in pixel per inch*/ 245 | const float xdpi; 246 | const float ydpi; 247 | 248 | /* framebuffer's display panel refresh rate in frames per second */ 249 | const float fps; 250 | 251 | /* min swap interval supported by this framebuffer */ 252 | const int minSwapInterval; 253 | 254 | /* max swap interval supported by this framebuffer */ 255 | const int maxSwapInterval; 256 | 257 | int reserved[8]; 258 | 259 | /* 260 | * requests a specific swap-interval (same definition than EGL) 261 | * 262 | * Returns 0 on success or -errno on error. 263 | */ 264 | int (*setSwapInterval)(struct framebuffer_device_t* window, 265 | int interval); 266 | 267 | /* 268 | * This hook is OPTIONAL. 269 | * 270 | * It is non NULL If the framebuffer driver supports "update-on-demand" 271 | * and the given rectangle is the area of the screen that gets 272 | * updated during (*post)(). 273 | * 274 | * This is useful on devices that are able to DMA only a portion of 275 | * the screen to the display panel, upon demand -- as opposed to 276 | * constantly refreshing the panel 60 times per second, for instance. 277 | * 278 | * Only the area defined by this rectangle is guaranteed to be valid, that 279 | * is, the driver is not allowed to post anything outside of this 280 | * rectangle. 281 | * 282 | * The rectangle evaluated during (*post)() and specifies which area 283 | * of the buffer passed in (*post)() shall to be posted. 284 | * 285 | * return -EINVAL if width or height <=0, or if left or top < 0 286 | */ 287 | int (*setUpdateRect)(struct framebuffer_device_t* window, 288 | int left, int top, int width, int height); 289 | 290 | /* 291 | * Post to the display (display it on the screen) 292 | * The buffer must have been allocated with the 293 | * GRALLOC_USAGE_HW_FB usage flag. 294 | * buffer must be the same width and height as the display and must NOT 295 | * be locked. 296 | * 297 | * The buffer is shown during the next VSYNC. 298 | * 299 | * If the same buffer is posted again (possibly after some other buffer), 300 | * post() will block until the the first post is completed. 301 | * 302 | * Internally, post() is expected to lock the buffer so that a 303 | * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or 304 | * USAGE_*_WRITE will block until it is safe; that is typically once this 305 | * buffer is shown and another buffer has been posted. 306 | * 307 | * Returns 0 on success or -errno on error. 308 | */ 309 | int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); 310 | 311 | 312 | /* 313 | * The (*compositionComplete)() method must be called after the 314 | * compositor has finished issuing GL commands for client buffers. 315 | */ 316 | 317 | int (*compositionComplete)(struct framebuffer_device_t* dev); 318 | 319 | 320 | void* reserved_proc[8]; 321 | 322 | } framebuffer_device_t; 323 | 324 | 325 | /** convenience API for opening and closing a supported device */ 326 | 327 | static inline int gralloc_open(const struct hw_module_t* module, 328 | struct alloc_device_t** device) { 329 | return module->methods->open(module, 330 | GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); 331 | } 332 | 333 | static inline int gralloc_close(struct alloc_device_t* device) { 334 | return device->common.close(&device->common); 335 | } 336 | 337 | 338 | static inline int framebuffer_open(const struct hw_module_t* module, 339 | struct framebuffer_device_t** device) { 340 | return module->methods->open(module, 341 | GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); 342 | } 343 | 344 | static inline int framebuffer_close(struct framebuffer_device_t* device) { 345 | return device->common.close(&device->common); 346 | } 347 | 348 | 349 | __END_DECLS 350 | 351 | #endif // ANDROID_ALLOC_INTERFACE_H 352 | -------------------------------------------------------------------------------- /include/hardware/sensors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_SENSORS_INTERFACE_H 18 | #define ANDROID_SENSORS_INTERFACE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | __BEGIN_DECLS 28 | 29 | /** 30 | * The id of this module 31 | */ 32 | #define SENSORS_HARDWARE_MODULE_ID "sensors" 33 | 34 | /** 35 | * Name of the sensors device to open 36 | */ 37 | #define SENSORS_HARDWARE_POLL "poll" 38 | 39 | /** 40 | * Handles must be higher than SENSORS_HANDLE_BASE and must be unique. 41 | * A Handle identifies a given sensors. The handle is used to activate 42 | * and/or deactivate sensors. 43 | * In this version of the API there can only be 256 handles. 44 | */ 45 | #define SENSORS_HANDLE_BASE 0 46 | #define SENSORS_HANDLE_BITS 8 47 | #define SENSORS_HANDLE_COUNT (1<0 100 | * ^ 101 | * | 102 | * +-----------+--> y>0 103 | * | | 104 | * | | 105 | * | | 106 | * | | / z<0 107 | * | | / 108 | * | | / 109 | * O-----------+/ 110 | * |[] [ ] []/ 111 | * +----------/+ y<0 112 | * / 113 | * / 114 | * |/ z>0 (toward the sky) 115 | * 116 | * O: Origin (x=0,y=0,z=0) 117 | * 118 | * 119 | * Orientation 120 | * ----------- 121 | * 122 | * All values are angles in degrees. 123 | * 124 | * Orientation sensors return sensor events for all 3 axes at a constant 125 | * rate defined by setDelay(). 126 | * 127 | * azimuth: angle between the magnetic north direction and the Y axis, around 128 | * the Z axis (0<=azimuth<360). 129 | * 0=North, 90=East, 180=South, 270=West 130 | * 131 | * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when 132 | * the z-axis moves toward the y-axis. 133 | * 134 | * roll: Rotation around Y axis (-90<=roll<=90), with positive values when 135 | * the x-axis moves towards the z-axis. 136 | * 137 | * Note: For historical reasons the roll angle is positive in the clockwise 138 | * direction (mathematically speaking, it should be positive in the 139 | * counter-clockwise direction): 140 | * 141 | * Z 142 | * ^ 143 | * (+roll) .--> | 144 | * / | 145 | * | | roll: rotation around Y axis 146 | * X <-------(.) 147 | * Y 148 | * note that +Y == -roll 149 | * 150 | * 151 | * 152 | * Note: This definition is different from yaw, pitch and roll used in aviation 153 | * where the X axis is along the long side of the plane (tail to nose). 154 | * 155 | * 156 | * Acceleration 157 | * ------------ 158 | * 159 | * All values are in SI units (m/s^2) and measure the acceleration of the 160 | * device minus the force of gravity. 161 | * 162 | * Acceleration sensors return sensor events for all 3 axes at a constant 163 | * rate defined by setDelay(). 164 | * 165 | * x: Acceleration minus Gx on the x-axis 166 | * y: Acceleration minus Gy on the y-axis 167 | * z: Acceleration minus Gz on the z-axis 168 | * 169 | * Examples: 170 | * When the device lies flat on a table and is pushed on its left side 171 | * toward the right, the x acceleration value is positive. 172 | * 173 | * When the device lies flat on a table, the acceleration value is +9.81, 174 | * which correspond to the acceleration of the device (0 m/s^2) minus the 175 | * force of gravity (-9.81 m/s^2). 176 | * 177 | * When the device lies flat on a table and is pushed toward the sky, the 178 | * acceleration value is greater than +9.81, which correspond to the 179 | * acceleration of the device (+A m/s^2) minus the force of 180 | * gravity (-9.81 m/s^2). 181 | * 182 | * 183 | * Magnetic Field 184 | * -------------- 185 | * 186 | * All values are in micro-Tesla (uT) and measure the ambient magnetic 187 | * field in the X, Y and Z axis. 188 | * 189 | * Magnetic Field sensors return sensor events for all 3 axes at a constant 190 | * rate defined by setDelay(). 191 | * 192 | * Gyroscope 193 | * --------- 194 | * All values are in radians/second and measure the rate of rotation 195 | * around the X, Y and Z axis. The coordinate system is the same as is 196 | * used for the acceleration sensor. Rotation is positive in the 197 | * counter-clockwise direction (right-hand rule). That is, an observer 198 | * looking from some positive location on the x, y or z axis at a device 199 | * positioned on the origin would report positive rotation if the device 200 | * appeared to be rotating counter clockwise. Note that this is the 201 | * standard mathematical definition of positive rotation and does not agree 202 | * with the definition of roll given earlier. 203 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). 204 | * 205 | * Proximity 206 | * --------- 207 | * 208 | * The distance value is measured in centimeters. Note that some proximity 209 | * sensors only support a binary "close" or "far" measurement. In this case, 210 | * the sensor should report its maxRange value in the "far" state and a value 211 | * less than maxRange in the "near" state. 212 | * 213 | * Proximity sensors report a value only when it changes and each time the 214 | * sensor is enabled. setDelay() is ignored. 215 | * 216 | * Light 217 | * ----- 218 | * 219 | * The light sensor value is returned in SI lux units. 220 | * 221 | * Light sensors report a value only when it changes and each time the 222 | * sensor is enabled. setDelay() is ignored. 223 | * 224 | * Pressure 225 | * -------- 226 | * 227 | * The pressure sensor value is returned in hectopascal (hPa) 228 | * 229 | * Pressure sensors report events at a constant rate defined by setDelay(). 230 | * 231 | * Gravity 232 | * ------- 233 | * A gravity output indicates the direction of and magnitude of gravity in the devices's 234 | * coordinates. On Earth, the magnitude is 9.8. Units are m/s^2. The coordinate system 235 | * is the same as is used for the acceleration sensor. 236 | * 237 | * Linear Acceleration 238 | * ------------------- 239 | * Indicates the linear acceleration of the device in device coordinates, not including gravity. 240 | * This output is essentially Acceleration - Gravity. Units are m/s^2. The coordinate system is 241 | * the same as is used for the acceleration sensor. 242 | * 243 | * Rotation Vector 244 | * --------------- 245 | * A rotation vector represents the orientation of the device as a combination 246 | * of an angle and an axis, in which the device has rotated through an angle 247 | * theta around an axis . The three elements of the rotation vector 248 | * are , such that the magnitude 249 | * of the rotation vector is equal to sin(theta/2), and the direction of the 250 | * rotation vector is equal to the direction of the axis of rotation. The three 251 | * elements of the rotation vector are equal to the last three components of a 252 | * unit quaternion . 253 | * Elements of the rotation vector are unitless. The x, y, and z axis are defined 254 | * in the same was as for the acceleration sensor. 255 | */ 256 | 257 | typedef struct { 258 | union { 259 | float v[3]; 260 | struct { 261 | float x; 262 | float y; 263 | float z; 264 | }; 265 | struct { 266 | float azimuth; 267 | float pitch; 268 | float roll; 269 | }; 270 | }; 271 | int8_t status; 272 | uint8_t reserved[3]; 273 | } sensors_vec_t; 274 | 275 | /** 276 | * Union of the various types of sensor data 277 | * that can be returned. 278 | */ 279 | typedef struct sensors_event_t { 280 | /* must be sizeof(struct sensors_event_t) */ 281 | int32_t version; 282 | 283 | /* sensor identifier */ 284 | int32_t sensor; 285 | 286 | /* sensor type */ 287 | int32_t type; 288 | 289 | /* reserved */ 290 | int32_t reserved0; 291 | 292 | /* time is in nanosecond */ 293 | int64_t timestamp; 294 | 295 | union { 296 | float data[16]; 297 | 298 | /* acceleration values are in meter per second per second (m/s^2) */ 299 | sensors_vec_t acceleration; 300 | 301 | /* magnetic vector values are in micro-Tesla (uT) */ 302 | sensors_vec_t magnetic; 303 | 304 | /* orientation values are in degrees */ 305 | sensors_vec_t orientation; 306 | 307 | /* gyroscope values are in rad/s */ 308 | sensors_vec_t gyro; 309 | 310 | /* temperature is in degrees centigrade (Celsius) */ 311 | float temperature; 312 | 313 | /* distance in centimeters */ 314 | float distance; 315 | 316 | /* light in SI lux units */ 317 | float light; 318 | 319 | /* pressure in hectopascal (hPa) */ 320 | float pressure; 321 | }; 322 | uint32_t reserved1[4]; 323 | } sensors_event_t; 324 | 325 | 326 | 327 | struct sensor_t; 328 | 329 | /** 330 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 331 | * and the fields of this data structure must begin with hw_module_t 332 | * followed by module specific information. 333 | */ 334 | struct sensors_module_t { 335 | struct hw_module_t common; 336 | 337 | /** 338 | * Enumerate all available sensors. The list is returned in "list". 339 | * @return number of sensors in the list 340 | */ 341 | int (*get_sensors_list)(struct sensors_module_t* module, 342 | struct sensor_t const** list); 343 | }; 344 | 345 | struct sensor_t { 346 | /* name of this sensors */ 347 | const char* name; 348 | /* vendor of the hardware part */ 349 | const char* vendor; 350 | /* version of the hardware part + driver. The value of this field is 351 | * left to the implementation and doesn't have to be monotonically 352 | * increasing. 353 | */ 354 | int version; 355 | /* handle that identifies this sensors. This handle is used to activate 356 | * and deactivate this sensor. The value of the handle must be 8 bits 357 | * in this version of the API. 358 | */ 359 | int handle; 360 | /* this sensor's type. */ 361 | int type; 362 | /* maximaum range of this sensor's value in SI units */ 363 | float maxRange; 364 | /* smallest difference between two values reported by this sensor */ 365 | float resolution; 366 | /* rough estimate of this sensor's power consumption in mA */ 367 | float power; 368 | /* minimum delay allowed between events in microseconds. A value of zero 369 | * means that this sensor doesn't report events at a constant rate, but 370 | * rather only when a new data is available */ 371 | int32_t minDelay; 372 | /* reserved fields, must be zero */ 373 | void* reserved[8]; 374 | }; 375 | 376 | 377 | /** 378 | * Every device data structure must begin with hw_device_t 379 | * followed by module specific public methods and attributes. 380 | */ 381 | struct sensors_poll_device_t { 382 | struct hw_device_t common; 383 | 384 | /** Activate/deactivate one sensor. 385 | * 386 | * @param handle is the handle of the sensor to change. 387 | * @param enabled set to 1 to enable, or 0 to disable the sensor. 388 | * 389 | * @return 0 on success, negative errno code otherwise 390 | */ 391 | int (*activate)(struct sensors_poll_device_t *dev, 392 | int handle, int enabled); 393 | 394 | /** 395 | * Set the delay between sensor events in nanoseconds for a given sensor. 396 | * It is an error to set a delay inferior to the value defined by 397 | * sensor_t::minDelay. If sensor_t::minDelay is zero, setDelay() is 398 | * ignored and returns 0. 399 | * 400 | * @return 0 if successful, < 0 on error 401 | */ 402 | int (*setDelay)(struct sensors_poll_device_t *dev, 403 | int handle, int64_t ns); 404 | 405 | /** 406 | * Returns an array of sensor data. 407 | * This function must block until events are available. 408 | * 409 | * @return the number of events read on success, or -errno in case of an error. 410 | * This function should never return 0 (no event). 411 | * 412 | */ 413 | int (*poll)(struct sensors_poll_device_t *dev, 414 | sensors_event_t* data, int count); 415 | }; 416 | 417 | /** convenience API for opening and closing a device */ 418 | 419 | static inline int sensors_open(const struct hw_module_t* module, 420 | struct sensors_poll_device_t** device) { 421 | return module->methods->open(module, 422 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); 423 | } 424 | 425 | static inline int sensors_close(struct sensors_poll_device_t* device) { 426 | return device->common.close(&device->common); 427 | } 428 | 429 | __END_DECLS 430 | 431 | #include 432 | 433 | #endif // ANDROID_SENSORS_INTERFACE_H 434 | -------------------------------------------------------------------------------- /include/hardware/gps.h: -------------------------------------------------------------------------------- 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 | #ifndef ANDROID_INCLUDE_HARDWARE_GPS_H 18 | #define ANDROID_INCLUDE_HARDWARE_GPS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | __BEGIN_DECLS 28 | 29 | /** 30 | * The id of this module 31 | */ 32 | #define GPS_HARDWARE_MODULE_ID "gps" 33 | 34 | 35 | /** Milliseconds since January 1, 1970 */ 36 | typedef int64_t GpsUtcTime; 37 | 38 | /** Maximum number of SVs for gps_sv_status_callback(). */ 39 | #define GPS_MAX_SVS 32 40 | 41 | /** Requested operational mode for GPS operation. */ 42 | typedef uint32_t GpsPositionMode; 43 | // IMPORTANT: Note that the following values must match 44 | // constants in GpsLocationProvider.java. 45 | /** Mode for running GPS standalone (no assistance). */ 46 | #define GPS_POSITION_MODE_STANDALONE 0 47 | /** AGPS MS-Based mode. */ 48 | #define GPS_POSITION_MODE_MS_BASED 1 49 | /** AGPS MS-Assisted mode. */ 50 | #define GPS_POSITION_MODE_MS_ASSISTED 2 51 | 52 | /** Requested recurrence mode for GPS operation. */ 53 | typedef uint32_t GpsPositionRecurrence; 54 | // IMPORTANT: Note that the following values must match 55 | // constants in GpsLocationProvider.java. 56 | /** Receive GPS fixes on a recurring basis at a specified period. */ 57 | #define GPS_POSITION_RECURRENCE_PERIODIC 0 58 | /** Request a single shot GPS fix. */ 59 | #define GPS_POSITION_RECURRENCE_SINGLE 1 60 | 61 | /** GPS status event values. */ 62 | typedef uint16_t GpsStatusValue; 63 | // IMPORTANT: Note that the following values must match 64 | // constants in GpsLocationProvider.java. 65 | /** GPS status unknown. */ 66 | #define GPS_STATUS_NONE 0 67 | /** GPS has begun navigating. */ 68 | #define GPS_STATUS_SESSION_BEGIN 1 69 | /** GPS has stopped navigating. */ 70 | #define GPS_STATUS_SESSION_END 2 71 | /** GPS has powered on but is not navigating. */ 72 | #define GPS_STATUS_ENGINE_ON 3 73 | /** GPS is powered off. */ 74 | #define GPS_STATUS_ENGINE_OFF 4 75 | 76 | /** Flags to indicate which values are valid in a GpsLocation. */ 77 | typedef uint16_t GpsLocationFlags; 78 | // IMPORTANT: Note that the following values must match 79 | // constants in GpsLocationProvider.java. 80 | /** GpsLocation has valid latitude and longitude. */ 81 | #define GPS_LOCATION_HAS_LAT_LONG 0x0001 82 | /** GpsLocation has valid altitude. */ 83 | #define GPS_LOCATION_HAS_ALTITUDE 0x0002 84 | /** GpsLocation has valid speed. */ 85 | #define GPS_LOCATION_HAS_SPEED 0x0004 86 | /** GpsLocation has valid bearing. */ 87 | #define GPS_LOCATION_HAS_BEARING 0x0008 88 | /** GpsLocation has valid accuracy. */ 89 | #define GPS_LOCATION_HAS_ACCURACY 0x0010 90 | 91 | /** Flags for the gps_set_capabilities callback. */ 92 | 93 | /** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode. 94 | If this is not set, then the framework will use 1000ms for min_interval 95 | and will start and call start() and stop() to schedule the GPS. 96 | */ 97 | #define GPS_CAPABILITY_SCHEDULING 0x0000001 98 | /** GPS supports MS-Based AGPS mode */ 99 | #define GPS_CAPABILITY_MSB 0x0000002 100 | /** GPS supports MS-Assisted AGPS mode */ 101 | #define GPS_CAPABILITY_MSA 0x0000004 102 | /** GPS supports single-shot fixes */ 103 | #define GPS_CAPABILITY_SINGLE_SHOT 0x0000008 104 | 105 | /** Flags used to specify which aiding data to delete 106 | when calling delete_aiding_data(). */ 107 | typedef uint16_t GpsAidingData; 108 | // IMPORTANT: Note that the following values must match 109 | // constants in GpsLocationProvider.java. 110 | #define GPS_DELETE_EPHEMERIS 0x0001 111 | #define GPS_DELETE_ALMANAC 0x0002 112 | #define GPS_DELETE_POSITION 0x0004 113 | #define GPS_DELETE_TIME 0x0008 114 | #define GPS_DELETE_IONO 0x0010 115 | #define GPS_DELETE_UTC 0x0020 116 | #define GPS_DELETE_HEALTH 0x0040 117 | #define GPS_DELETE_SVDIR 0x0080 118 | #define GPS_DELETE_SVSTEER 0x0100 119 | #define GPS_DELETE_SADATA 0x0200 120 | #define GPS_DELETE_RTI 0x0400 121 | #define GPS_DELETE_CELLDB_INFO 0x8000 122 | #define GPS_DELETE_ALL 0xFFFF 123 | 124 | /** AGPS type */ 125 | typedef uint16_t AGpsType; 126 | #define AGPS_TYPE_SUPL 1 127 | #define AGPS_TYPE_C2K 2 128 | 129 | typedef uint16_t AGpsSetIDType; 130 | #define AGPS_SETID_TYPE_NONE 0 131 | #define AGPS_SETID_TYPE_IMSI 1 132 | #define AGPS_SETID_TYPE_MSISDN 2 133 | 134 | /** 135 | * String length constants 136 | */ 137 | #define GPS_NI_SHORT_STRING_MAXLEN 256 138 | #define GPS_NI_LONG_STRING_MAXLEN 2048 139 | 140 | /** 141 | * GpsNiType constants 142 | */ 143 | typedef uint32_t GpsNiType; 144 | #define GPS_NI_TYPE_VOICE 1 145 | #define GPS_NI_TYPE_UMTS_SUPL 2 146 | #define GPS_NI_TYPE_UMTS_CTRL_PLANE 3 147 | 148 | /** 149 | * GpsNiNotifyFlags constants 150 | */ 151 | typedef uint32_t GpsNiNotifyFlags; 152 | /** NI requires notification */ 153 | #define GPS_NI_NEED_NOTIFY 0x0001 154 | /** NI requires verification */ 155 | #define GPS_NI_NEED_VERIFY 0x0002 156 | /** NI requires privacy override, no notification/minimal trace */ 157 | #define GPS_NI_PRIVACY_OVERRIDE 0x0004 158 | 159 | /** 160 | * GPS NI responses, used to define the response in 161 | * NI structures 162 | */ 163 | typedef int GpsUserResponseType; 164 | #define GPS_NI_RESPONSE_ACCEPT 1 165 | #define GPS_NI_RESPONSE_DENY 2 166 | #define GPS_NI_RESPONSE_NORESP 3 167 | 168 | /** 169 | * NI data encoding scheme 170 | */ 171 | typedef int GpsNiEncodingType; 172 | #define GPS_ENC_NONE 0 173 | #define GPS_ENC_SUPL_GSM_DEFAULT 1 174 | #define GPS_ENC_SUPL_UTF8 2 175 | #define GPS_ENC_SUPL_UCS2 3 176 | #define GPS_ENC_UNKNOWN -1 177 | 178 | /** AGPS status event values. */ 179 | typedef uint16_t AGpsStatusValue; 180 | /** GPS requests data connection for AGPS. */ 181 | #define GPS_REQUEST_AGPS_DATA_CONN 1 182 | /** GPS releases the AGPS data connection. */ 183 | #define GPS_RELEASE_AGPS_DATA_CONN 2 184 | /** AGPS data connection initiated */ 185 | #define GPS_AGPS_DATA_CONNECTED 3 186 | /** AGPS data connection completed */ 187 | #define GPS_AGPS_DATA_CONN_DONE 4 188 | /** AGPS data connection failed */ 189 | #define GPS_AGPS_DATA_CONN_FAILED 5 190 | 191 | #define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1 192 | #define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2 193 | #define AGPS_REG_LOCATION_TYPE_MAC 3 194 | 195 | /** Network types for update_network_state "type" parameter */ 196 | #define AGPS_RIL_NETWORK_TYPE_MOBILE 0 197 | #define AGPS_RIL_NETWORK_TYPE_WIFI 1 198 | #define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2 199 | #define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3 200 | #define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4 201 | #define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5 202 | #define AGPS_RIL_NETWORK_TTYPE_WIMAX 6 203 | 204 | /** 205 | * Name for the GPS XTRA interface. 206 | */ 207 | #define GPS_XTRA_INTERFACE "gps-xtra" 208 | 209 | /** 210 | * Name for the GPS DEBUG interface. 211 | */ 212 | #define GPS_DEBUG_INTERFACE "gps-debug" 213 | 214 | /** 215 | * Name for the AGPS interface. 216 | */ 217 | #define AGPS_INTERFACE "agps" 218 | 219 | /** 220 | * Name for NI interface 221 | */ 222 | #define GPS_NI_INTERFACE "gps-ni" 223 | 224 | /** 225 | * Name for the AGPS-RIL interface. 226 | */ 227 | #define AGPS_RIL_INTERFACE "agps_ril" 228 | 229 | /** Represents a location. */ 230 | typedef struct { 231 | /** set to sizeof(GpsLocation) */ 232 | size_t size; 233 | /** Contains GpsLocationFlags bits. */ 234 | uint16_t flags; 235 | /** Represents latitude in degrees. */ 236 | double latitude; 237 | /** Represents longitude in degrees. */ 238 | double longitude; 239 | /** Represents altitude in meters above the WGS 84 reference 240 | * ellipsoid. */ 241 | double altitude; 242 | /** Represents speed in meters per second. */ 243 | float speed; 244 | /** Represents heading in degrees. */ 245 | float bearing; 246 | /** Represents expected accuracy in meters. */ 247 | float accuracy; 248 | /** Timestamp for the location fix. */ 249 | GpsUtcTime timestamp; 250 | } GpsLocation; 251 | 252 | /** Represents the status. */ 253 | typedef struct { 254 | /** set to sizeof(GpsStatus) */ 255 | size_t size; 256 | GpsStatusValue status; 257 | } GpsStatus; 258 | 259 | /** Represents SV information. */ 260 | typedef struct { 261 | /** set to sizeof(GpsSvInfo) */ 262 | size_t size; 263 | /** Pseudo-random number for the SV. */ 264 | int prn; 265 | /** Signal to noise ratio. */ 266 | float snr; 267 | /** Elevation of SV in degrees. */ 268 | float elevation; 269 | /** Azimuth of SV in degrees. */ 270 | float azimuth; 271 | } GpsSvInfo; 272 | 273 | /** Represents SV status. */ 274 | typedef struct { 275 | /** set to sizeof(GpsSvStatus) */ 276 | size_t size; 277 | 278 | /** Number of SVs currently visible. */ 279 | int num_svs; 280 | 281 | /** Contains an array of SV information. */ 282 | GpsSvInfo sv_list[GPS_MAX_SVS]; 283 | 284 | /** Represents a bit mask indicating which SVs 285 | * have ephemeris data. 286 | */ 287 | uint32_t ephemeris_mask; 288 | 289 | /** Represents a bit mask indicating which SVs 290 | * have almanac data. 291 | */ 292 | uint32_t almanac_mask; 293 | 294 | /** 295 | * Represents a bit mask indicating which SVs 296 | * were used for computing the most recent position fix. 297 | */ 298 | uint32_t used_in_fix_mask; 299 | } GpsSvStatus; 300 | 301 | /* 2G and 3G */ 302 | /* In 3G lac is discarded */ 303 | typedef struct { 304 | uint16_t type; 305 | uint16_t mcc; 306 | uint16_t mnc; 307 | uint16_t lac; 308 | uint32_t cid; 309 | } AGpsRefLocationCellID; 310 | 311 | typedef struct { 312 | uint8_t mac[6]; 313 | } AGpsRefLocationMac; 314 | 315 | /** Represents ref locations */ 316 | typedef struct { 317 | uint16_t type; 318 | union { 319 | AGpsRefLocationCellID cellID; 320 | AGpsRefLocationMac mac; 321 | } u; 322 | } AGpsRefLocation; 323 | 324 | /** Callback with location information. 325 | * Can only be called from a thread created by create_thread_cb. 326 | */ 327 | typedef void (* gps_location_callback)(GpsLocation* location); 328 | 329 | /** Callback with status information. 330 | * Can only be called from a thread created by create_thread_cb. 331 | */ 332 | typedef void (* gps_status_callback)(GpsStatus* status); 333 | 334 | /** Callback with SV status information. 335 | * Can only be called from a thread created by create_thread_cb. 336 | */ 337 | typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info); 338 | 339 | /** Callback for reporting NMEA sentences. 340 | * Can only be called from a thread created by create_thread_cb. 341 | */ 342 | typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length); 343 | 344 | /** Callback to inform framework of the GPS engine's capabilities. 345 | * Capability parameter is a bit field of GPS_CAPABILITY_* flags. 346 | */ 347 | typedef void (* gps_set_capabilities)(uint32_t capabilities); 348 | 349 | /** Callback utility for acquiring the GPS wakelock. 350 | * This can be used to prevent the CPU from suspending while handling GPS events. 351 | */ 352 | typedef void (* gps_acquire_wakelock)(); 353 | 354 | /** Callback utility for releasing the GPS wakelock. */ 355 | typedef void (* gps_release_wakelock)(); 356 | 357 | /** Callback for creating a thread that can call into the Java framework code. 358 | * This must be used to create any threads that report events up to the framework. 359 | */ 360 | typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg); 361 | 362 | /** GPS callback structure. */ 363 | typedef struct { 364 | /** set to sizeof(GpsCallbacks) */ 365 | size_t size; 366 | gps_location_callback location_cb; 367 | gps_status_callback status_cb; 368 | gps_sv_status_callback sv_status_cb; 369 | gps_nmea_callback nmea_cb; 370 | gps_set_capabilities set_capabilities_cb; 371 | gps_acquire_wakelock acquire_wakelock_cb; 372 | gps_release_wakelock release_wakelock_cb; 373 | gps_create_thread create_thread_cb; 374 | } GpsCallbacks; 375 | 376 | 377 | /** Represents the standard GPS interface. */ 378 | typedef struct { 379 | /** set to sizeof(GpsInterface) */ 380 | size_t size; 381 | /** 382 | * Opens the interface and provides the callback routines 383 | * to the implemenation of this interface. 384 | */ 385 | int (*init)( GpsCallbacks* callbacks ); 386 | 387 | /** Starts navigating. */ 388 | int (*start)( void ); 389 | 390 | /** Stops navigating. */ 391 | int (*stop)( void ); 392 | 393 | /** Closes the interface. */ 394 | void (*cleanup)( void ); 395 | 396 | /** Injects the current time. */ 397 | int (*inject_time)(GpsUtcTime time, int64_t timeReference, 398 | int uncertainty); 399 | 400 | /** Injects current location from another location provider 401 | * (typically cell ID). 402 | * latitude and longitude are measured in degrees 403 | * expected accuracy is measured in meters 404 | */ 405 | int (*inject_location)(double latitude, double longitude, float accuracy); 406 | 407 | /** 408 | * Specifies that the next call to start will not use the 409 | * information defined in the flags. GPS_DELETE_ALL is passed for 410 | * a cold start. 411 | */ 412 | void (*delete_aiding_data)(GpsAidingData flags); 413 | 414 | /** 415 | * min_interval represents the time between fixes in milliseconds. 416 | * preferred_accuracy represents the requested fix accuracy in meters. 417 | * preferred_time represents the requested time to first fix in milliseconds. 418 | */ 419 | int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence, 420 | uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time); 421 | 422 | /** Get a pointer to extension information. */ 423 | const void* (*get_extension)(const char* name); 424 | } GpsInterface; 425 | 426 | /** Callback to request the client to download XTRA data. 427 | * The client should download XTRA data and inject it by calling inject_xtra_data(). 428 | * Can only be called from a thread created by create_thread_cb. 429 | */ 430 | typedef void (* gps_xtra_download_request)(); 431 | 432 | /** Callback structure for the XTRA interface. */ 433 | typedef struct { 434 | gps_xtra_download_request download_request_cb; 435 | gps_create_thread create_thread_cb; 436 | } GpsXtraCallbacks; 437 | 438 | /** Extended interface for XTRA support. */ 439 | typedef struct { 440 | /** set to sizeof(GpsXtraInterface) */ 441 | size_t size; 442 | /** 443 | * Opens the XTRA interface and provides the callback routines 444 | * to the implemenation of this interface. 445 | */ 446 | int (*init)( GpsXtraCallbacks* callbacks ); 447 | /** Injects XTRA data into the GPS. */ 448 | int (*inject_xtra_data)( char* data, int length ); 449 | } GpsXtraInterface; 450 | 451 | /** Extended interface for DEBUG support. */ 452 | typedef struct { 453 | /** set to sizeof(GpsDebugInterface) */ 454 | size_t size; 455 | 456 | /** 457 | * This function should return any information that the native 458 | * implementation wishes to include in a bugreport. 459 | */ 460 | size_t (*get_internal_state)(char* buffer, size_t bufferSize); 461 | } GpsDebugInterface; 462 | 463 | /** Represents the status of AGPS. */ 464 | typedef struct { 465 | /** set to sizeof(AGpsStatus) */ 466 | size_t size; 467 | 468 | AGpsType type; 469 | AGpsStatusValue status; 470 | } AGpsStatus; 471 | 472 | /** Callback with AGPS status information. 473 | * Can only be called from a thread created by create_thread_cb. 474 | */ 475 | typedef void (* agps_status_callback)(AGpsStatus* status); 476 | 477 | /** Callback structure for the AGPS interface. */ 478 | typedef struct { 479 | agps_status_callback status_cb; 480 | gps_create_thread create_thread_cb; 481 | } AGpsCallbacks; 482 | 483 | 484 | /** Extended interface for AGPS support. */ 485 | typedef struct { 486 | /** set to sizeof(AGpsInterface) */ 487 | size_t size; 488 | 489 | /** 490 | * Opens the AGPS interface and provides the callback routines 491 | * to the implemenation of this interface. 492 | */ 493 | void (*init)( AGpsCallbacks* callbacks ); 494 | /** 495 | * Notifies that a data connection is available and sets 496 | * the name of the APN to be used for SUPL. 497 | */ 498 | int (*data_conn_open)( const char* apn ); 499 | /** 500 | * Notifies that the AGPS data connection has been closed. 501 | */ 502 | int (*data_conn_closed)(); 503 | /** 504 | * Notifies that a data connection is not available for AGPS. 505 | */ 506 | int (*data_conn_failed)(); 507 | /** 508 | * Sets the hostname and port for the AGPS server. 509 | */ 510 | int (*set_server)( AGpsType type, const char* hostname, int port ); 511 | } AGpsInterface; 512 | 513 | 514 | /** Represents an NI request */ 515 | typedef struct { 516 | /** set to sizeof(GpsNiNotification) */ 517 | size_t size; 518 | 519 | /** 520 | * An ID generated by HAL to associate NI notifications and UI 521 | * responses 522 | */ 523 | int notification_id; 524 | 525 | /** 526 | * An NI type used to distinguish different categories of NI 527 | * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ... 528 | */ 529 | GpsNiType ni_type; 530 | 531 | /** 532 | * Notification/verification options, combinations of GpsNiNotifyFlags constants 533 | */ 534 | GpsNiNotifyFlags notify_flags; 535 | 536 | /** 537 | * Timeout period to wait for user response. 538 | * Set to 0 for no time out limit. 539 | */ 540 | int timeout; 541 | 542 | /** 543 | * Default response when time out. 544 | */ 545 | GpsUserResponseType default_response; 546 | 547 | /** 548 | * Requestor ID 549 | */ 550 | char requestor_id[GPS_NI_SHORT_STRING_MAXLEN]; 551 | 552 | /** 553 | * Notification message. It can also be used to store client_id in some cases 554 | */ 555 | char text[GPS_NI_LONG_STRING_MAXLEN]; 556 | 557 | /** 558 | * Client name decoding scheme 559 | */ 560 | GpsNiEncodingType requestor_id_encoding; 561 | 562 | /** 563 | * Client name decoding scheme 564 | */ 565 | GpsNiEncodingType text_encoding; 566 | 567 | /** 568 | * A pointer to extra data. Format: 569 | * key_1 = value_1 570 | * key_2 = value_2 571 | */ 572 | char extras[GPS_NI_LONG_STRING_MAXLEN]; 573 | 574 | } GpsNiNotification; 575 | 576 | /** Callback with NI notification. 577 | * Can only be called from a thread created by create_thread_cb. 578 | */ 579 | typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification); 580 | 581 | /** GPS NI callback structure. */ 582 | typedef struct 583 | { 584 | /** 585 | * Sends the notification request from HAL to GPSLocationProvider. 586 | */ 587 | gps_ni_notify_callback notify_cb; 588 | gps_create_thread create_thread_cb; 589 | } GpsNiCallbacks; 590 | 591 | /** 592 | * Extended interface for Network-initiated (NI) support. 593 | */ 594 | typedef struct 595 | { 596 | /** set to sizeof(GpsNiInterface) */ 597 | size_t size; 598 | 599 | /** Registers the callbacks for HAL to use. */ 600 | void (*init) (GpsNiCallbacks *callbacks); 601 | 602 | /** Sends a response to HAL. */ 603 | void (*respond) (int notif_id, GpsUserResponseType user_response); 604 | } GpsNiInterface; 605 | 606 | struct gps_device_t { 607 | struct hw_device_t common; 608 | 609 | /** 610 | * Set the provided lights to the provided values. 611 | * 612 | * Returns: 0 on succes, error code on failure. 613 | */ 614 | const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev); 615 | }; 616 | 617 | #define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L) 618 | #define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L) 619 | 620 | #define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L) 621 | #define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L) 622 | 623 | typedef void (*agps_ril_request_set_id)(uint32_t flags); 624 | typedef void (*agps_ril_request_ref_loc)(uint32_t flags); 625 | 626 | typedef struct { 627 | agps_ril_request_set_id request_setid; 628 | agps_ril_request_ref_loc request_refloc; 629 | gps_create_thread create_thread_cb; 630 | } AGpsRilCallbacks; 631 | 632 | /** Extended interface for AGPS_RIL support. */ 633 | typedef struct { 634 | /** set to sizeof(AGpsRilInterface) */ 635 | size_t size; 636 | /** 637 | * Opens the AGPS interface and provides the callback routines 638 | * to the implemenation of this interface. 639 | */ 640 | void (*init)( AGpsRilCallbacks* callbacks ); 641 | 642 | /** 643 | * Sets the reference location. 644 | */ 645 | void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct); 646 | /** 647 | * Sets the set ID. 648 | */ 649 | void (*set_set_id) (AGpsSetIDType type, const char* setid); 650 | 651 | /** 652 | * Send network initiated message. 653 | */ 654 | void (*ni_message) (uint8_t *msg, size_t len); 655 | 656 | /** 657 | * Notify GPS of network status changes. 658 | * These parameters match values in the android.net.NetworkInfo class. 659 | */ 660 | void (*update_network_state) (int connected, int type, int roaming, const char* extra_info); 661 | } AGpsRilInterface; 662 | 663 | __END_DECLS 664 | 665 | #endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */ 666 | 667 | --------------------------------------------------------------------------------