Arun Kumar K.R | 00b8479 | 2015-03-27 11:28:36 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | //#include "overlay.h" |
| 31 | #include "overlayCursor.h" |
| 32 | #include "mdpWrapper.h" |
| 33 | |
| 34 | namespace overlay { |
| 35 | |
| 36 | HWCursor* HWCursor::sHwCursor = 0; |
| 37 | |
| 38 | //=========== class HWCursor ================================================= |
| 39 | HWCursor* HWCursor::getInstance() { |
| 40 | if (sHwCursor == NULL) { |
| 41 | sHwCursor = new HWCursor(); |
| 42 | } |
| 43 | return sHwCursor; |
| 44 | } |
| 45 | |
| 46 | bool HWCursor::config(const int fd, void* base, PipeArgs& pargs, |
| 47 | Dim& crop, Dim& dest) { |
| 48 | bool ret = true; |
| 49 | fb_cursor *cursor = &mfbCursor; |
| 50 | fb_image cursorImage; |
| 51 | |
| 52 | cursor->set = FB_CUR_SETIMAGE | FB_CUR_SETPOS; |
| 53 | cursor->enable = (uint16_t)1; |
| 54 | cursor->rop = 0, |
| 55 | cursor->mask = NULL; |
| 56 | cursor->hot.x = (uint16_t)crop.x; |
| 57 | cursor->hot.y = (uint16_t)crop.y; |
| 58 | |
| 59 | cursorImage.dx = dest.x; |
| 60 | cursorImage.dy = dest.y; |
| 61 | cursorImage.width = pargs.whf.w; |
| 62 | cursorImage.height = pargs.whf.h; |
| 63 | cursorImage.fg_color = pargs.planeAlpha; // Hint for PMA |
| 64 | cursorImage.bg_color = 0xffffff00; // RGBA |
| 65 | cursorImage.depth = 32; |
| 66 | cursorImage.data = (char*)base; |
| 67 | |
| 68 | cursor->image = cursorImage; |
| 69 | |
| 70 | if (!setCursor(fd)) { |
| 71 | ALOGE("%s: Failed to setup HW cursor", __FUNCTION__); |
| 72 | ret = false; |
| 73 | memset(cursor, 0, sizeof(fb_cursor)); |
| 74 | } |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | bool HWCursor::setPositionAsync(const int fd, int x, int y) { |
| 79 | bool ret = true; |
| 80 | if (isCursorSet()) { |
| 81 | fb_cursor *cursor = &mfbCursor; |
| 82 | cursor->set = FB_CUR_SETPOS; |
| 83 | cursor->image.dx = x; |
| 84 | cursor->image.dy = y; |
| 85 | if (!setCursor(fd)) { |
| 86 | ALOGE("%s: Failed to set position x = %d y = %d", __FUNCTION__, x, y); |
| 87 | ret = false; |
| 88 | } |
| 89 | } |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | bool HWCursor::free(const int fd) { |
| 94 | fb_cursor *cursor = &mfbCursor; |
| 95 | fb_image cursorImage; |
| 96 | bool ret = true; |
| 97 | |
| 98 | if(!cursor->enable) { |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | cursor->enable = (uint16_t)0; |
| 103 | |
| 104 | if (!setCursor(fd)) { |
| 105 | ALOGE("%s: Failed to free cursor hw", __FUNCTION__); |
| 106 | ret = false; |
| 107 | } |
| 108 | memset(cursor, 0, sizeof(fb_cursor)); |
| 109 | return ret; |
| 110 | } |
| 111 | |
| 112 | bool HWCursor::setCursor(const int fd) { |
| 113 | bool ret = true; |
| 114 | ATRACE_CALL(); |
| 115 | fb_cursor *cursor = &mfbCursor; |
| 116 | |
| 117 | if(fd <= 0) { |
| 118 | ALOGE("%s: Invalid fd", fd); |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | if (ioctl(fd, MSMFB_CURSOR, cursor) < 0) { |
| 123 | ALOGE("%s: Failed to call ioctl MSMFB_CURSOR err=%s\n", __FUNCTION__, |
| 124 | strerror(errno)); |
| 125 | ret = false; |
| 126 | } |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | void HWCursor::getDump(char* buf, size_t len) { |
| 131 | char cursordump[len]; |
| 132 | fb_cursor* cursor = &mfbCursor; |
| 133 | if (cursor->enable) { |
| 134 | snprintf(cursordump, sizeof(cursordump), |
| 135 | "HWCursor on Primary: src w=%d h=%d\n" |
| 136 | "\tsrc_rect x=%d y=%d w=%d h=%d\n" |
| 137 | "\tdst_rect x=%d y=%d w=%d h=%d\n\n", cursor->image.width, |
| 138 | cursor->image.height, cursor->hot.x, cursor->hot.y, |
| 139 | cursor->image.width, cursor->image.height, |
| 140 | cursor->image.dx, cursor->image.dy, cursor->image.width, |
| 141 | cursor->image.height); |
| 142 | strlcat(buf, cursordump, len); |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
| 147 | } //namespace overlay |