Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | #include <math.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
Mathias Agopian | f1352df | 2010-08-11 17:31:33 -0700 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | |
| 27 | #include <utils/Errors.h> |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 28 | #include <utils/misc.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 29 | #include <utils/NativeHandle.h> |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 30 | #include <utils/String8.h> |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 31 | #include <utils/Thread.h> |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 32 | #include <utils/Trace.h> |
Mathias Agopian | 22da60c | 2011-09-09 00:49:11 -0700 | [diff] [blame] | 33 | #include <utils/Vector.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 34 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 35 | #include <ui/GraphicBuffer.h> |
| 36 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 37 | #include <hardware/hardware.h> |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 38 | #include <hardware/hwcomposer.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 39 | |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 40 | #include <android/configuration.h> |
| 41 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 42 | #include <cutils/log.h> |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 43 | #include <cutils/properties.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 44 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 45 | #include "HWComposer.h" |
Mathias Agopian | 33ceeb3 | 2013-04-01 16:54:58 -0700 | [diff] [blame] | 46 | |
| 47 | #include "../Layer.h" // needed only for debugging |
| 48 | #include "../SurfaceFlinger.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 49 | |
| 50 | namespace android { |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 51 | |
Jesse Hall | 7296051 | 2013-01-10 16:19:56 -0800 | [diff] [blame] | 52 | #define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION |
Jesse Hall | 9eb1eb5 | 2012-08-29 10:39:38 -0700 | [diff] [blame] | 53 | |
| 54 | static uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) { |
| 55 | uint32_t hwcVersion = hwc->common.version; |
Jesse Hall | 9eb1eb5 | 2012-08-29 10:39:38 -0700 | [diff] [blame] | 56 | return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK; |
| 57 | } |
| 58 | |
| 59 | static uint32_t hwcHeaderVersion(const hwc_composer_device_1_t* hwc) { |
| 60 | uint32_t hwcVersion = hwc->common.version; |
Jesse Hall | 9eb1eb5 | 2012-08-29 10:39:38 -0700 | [diff] [blame] | 61 | return hwcVersion & HARDWARE_API_VERSION_2_HEADER_MASK; |
| 62 | } |
| 63 | |
| 64 | static bool hwcHasApiVersion(const hwc_composer_device_1_t* hwc, |
| 65 | uint32_t version) { |
| 66 | return hwcApiVersion(hwc) >= (version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK); |
Jesse Hall | bbd164a | 2012-08-21 12:05:09 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 69 | // --------------------------------------------------------------------------- |
| 70 | |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 71 | struct HWComposer::cb_context { |
| 72 | struct callbacks : public hwc_procs_t { |
| 73 | // these are here to facilitate the transition when adding |
| 74 | // new callbacks (an implementation can check for NULL before |
| 75 | // calling a new callback). |
| 76 | void (*zero[4])(void); |
| 77 | }; |
| 78 | callbacks procs; |
| 79 | HWComposer* hwc; |
| 80 | }; |
| 81 | |
| 82 | // --------------------------------------------------------------------------- |
| 83 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 84 | HWComposer::HWComposer( |
| 85 | const sp<SurfaceFlinger>& flinger, |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 86 | EventHandler& handler) |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 87 | : mFlinger(flinger), |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 88 | mFbDev(0), mHwc(0), mNumDisplays(1), |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 89 | mCBContext(new cb_context), |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 90 | mEventHandler(handler), |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 91 | mDebugForceFakeVSync(false) |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 92 | { |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 93 | for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) { |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 94 | mLists[i] = 0; |
| 95 | } |
Jesse Hall | b685c54 | 2012-07-31 14:32:56 -0700 | [diff] [blame] | 96 | |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 97 | for (size_t i=0 ; i<HWC_NUM_PHYSICAL_DISPLAY_TYPES ; i++) { |
| 98 | mLastHwVSync[i] = 0; |
| 99 | mVSyncCounts[i] = 0; |
| 100 | } |
| 101 | |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 102 | char value[PROPERTY_VALUE_MAX]; |
| 103 | property_get("debug.sf.no_hw_vsync", value, "0"); |
| 104 | mDebugForceFakeVSync = atoi(value); |
| 105 | |
Mathias Agopian | 028508c | 2012-07-25 21:12:12 -0700 | [diff] [blame] | 106 | bool needVSyncThread = true; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 107 | |
| 108 | // Note: some devices may insist that the FB HAL be opened before HWC. |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 109 | int fberr = loadFbHalModule(); |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 110 | loadHwcModule(); |
| 111 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 112 | if (mFbDev && mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 113 | // close FB HAL if we don't needed it. |
| 114 | // FIXME: this is temporary until we're not forced to open FB HAL |
| 115 | // before HWC. |
| 116 | framebuffer_close(mFbDev); |
| 117 | mFbDev = NULL; |
| 118 | } |
| 119 | |
Andy McFadden | babba18 | 2012-09-12 13:14:51 -0700 | [diff] [blame] | 120 | // If we have no HWC, or a pre-1.1 HWC, an FB dev is mandatory. |
| 121 | if ((!mHwc || !hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) |
| 122 | && !mFbDev) { |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 123 | ALOGE("ERROR: failed to open framebuffer (%s), aborting", |
| 124 | strerror(-fberr)); |
Andy McFadden | 43601a2 | 2012-09-11 15:15:13 -0700 | [diff] [blame] | 125 | abort(); |
| 126 | } |
| 127 | |
Andy McFadden | 620685c | 2012-10-19 12:53:46 -0700 | [diff] [blame] | 128 | // these display IDs are always reserved |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 129 | for (size_t i=0 ; i<NUM_BUILTIN_DISPLAYS ; i++) { |
Andy McFadden | 620685c | 2012-10-19 12:53:46 -0700 | [diff] [blame] | 130 | mAllocatedDisplayIDs.markBit(i); |
| 131 | } |
| 132 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 133 | if (mHwc) { |
| 134 | ALOGI("Using %s version %u.%u", HWC_HARDWARE_COMPOSER, |
| 135 | (hwcApiVersion(mHwc) >> 24) & 0xff, |
| 136 | (hwcApiVersion(mHwc) >> 16) & 0xff); |
| 137 | if (mHwc->registerProcs) { |
| 138 | mCBContext->hwc = this; |
| 139 | mCBContext->procs.invalidate = &hook_invalidate; |
| 140 | mCBContext->procs.vsync = &hook_vsync; |
| 141 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) |
| 142 | mCBContext->procs.hotplug = &hook_hotplug; |
| 143 | else |
| 144 | mCBContext->procs.hotplug = NULL; |
| 145 | memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); |
| 146 | mHwc->registerProcs(mHwc, &mCBContext->procs); |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 149 | // don't need a vsync thread if we have a hardware composer |
| 150 | needVSyncThread = false; |
| 151 | // always turn vsync off when we start |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 152 | eventControl(HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, 0); |
Jesse Hall | bbd164a | 2012-08-21 12:05:09 -0700 | [diff] [blame] | 153 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 154 | // the number of displays we actually have depends on the |
| 155 | // hw composer version |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 156 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { |
| 157 | // 1.3 adds support for virtual displays |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 158 | mNumDisplays = MAX_HWC_DISPLAYS; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 159 | } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 160 | // 1.1 adds support for multiple displays |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 161 | mNumDisplays = NUM_BUILTIN_DISPLAYS; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 162 | } else { |
| 163 | mNumDisplays = 1; |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 164 | } |
Mathias Agopian | 3a77871 | 2012-04-09 14:16:47 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 167 | if (mFbDev) { |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 168 | ALOG_ASSERT(!(mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)), |
| 169 | "should only have fbdev if no hwc or hwc is 1.0"); |
| 170 | |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 171 | DisplayData& disp(mDisplayData[HWC_DISPLAY_PRIMARY]); |
Mathias Agopian | 38e623b | 2012-09-20 19:27:07 -0700 | [diff] [blame] | 172 | disp.connected = true; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 173 | disp.format = mFbDev->format; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 174 | DisplayConfig config = DisplayConfig(); |
| 175 | config.width = mFbDev->width; |
| 176 | config.height = mFbDev->height; |
| 177 | config.xdpi = mFbDev->xdpi; |
| 178 | config.ydpi = mFbDev->ydpi; |
| 179 | config.refresh = nsecs_t(1e9 / mFbDev->fps); |
| 180 | disp.configs.push_back(config); |
| 181 | disp.currentConfig = 0; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 182 | } else if (mHwc) { |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 183 | // here we're guaranteed to have at least HWC 1.1 |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 184 | for (size_t i =0 ; i<NUM_BUILTIN_DISPLAYS ; i++) { |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 185 | queryDisplayProperties(i); |
| 186 | } |
Mathias Agopian | 888c822 | 2012-08-04 21:10:38 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Mathias Agopian | 3a77871 | 2012-04-09 14:16:47 -0700 | [diff] [blame] | 189 | if (needVSyncThread) { |
| 190 | // we don't have VSYNC support, we need to fake it |
| 191 | mVSyncThread = new VSyncThread(*this); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
| 195 | HWComposer::~HWComposer() { |
Andy McFadden | babba18 | 2012-09-12 13:14:51 -0700 | [diff] [blame] | 196 | if (mHwc) { |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 197 | eventControl(HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, 0); |
Andy McFadden | babba18 | 2012-09-12 13:14:51 -0700 | [diff] [blame] | 198 | } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 199 | if (mVSyncThread != NULL) { |
| 200 | mVSyncThread->requestExitAndWait(); |
| 201 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 202 | if (mHwc) { |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 203 | hwc_close_1(mHwc); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 204 | } |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 205 | if (mFbDev) { |
| 206 | framebuffer_close(mFbDev); |
| 207 | } |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 208 | delete mCBContext; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 211 | // Load and prepare the hardware composer module. Sets mHwc. |
| 212 | void HWComposer::loadHwcModule() |
| 213 | { |
| 214 | hw_module_t const* module; |
| 215 | |
| 216 | if (hw_get_module(HWC_HARDWARE_MODULE_ID, &module) != 0) { |
| 217 | ALOGE("%s module not found", HWC_HARDWARE_MODULE_ID); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | int err = hwc_open_1(module, &mHwc); |
| 222 | if (err) { |
| 223 | ALOGE("%s device failed to initialize (%s)", |
| 224 | HWC_HARDWARE_COMPOSER, strerror(-err)); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_0) || |
| 229 | hwcHeaderVersion(mHwc) < MIN_HWC_HEADER_VERSION || |
| 230 | hwcHeaderVersion(mHwc) > HWC_HEADER_VERSION) { |
| 231 | ALOGE("%s device version %#x unsupported, will not be used", |
| 232 | HWC_HARDWARE_COMPOSER, mHwc->common.version); |
| 233 | hwc_close_1(mHwc); |
| 234 | mHwc = NULL; |
| 235 | return; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // Load and prepare the FB HAL, which uses the gralloc module. Sets mFbDev. |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 240 | int HWComposer::loadFbHalModule() |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 241 | { |
| 242 | hw_module_t const* module; |
| 243 | |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 244 | int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 245 | if (err != 0) { |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 246 | ALOGE("%s module not found", GRALLOC_HARDWARE_MODULE_ID); |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 247 | return err; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Jesse Hall | ef64b75 | 2013-03-18 11:28:50 -0700 | [diff] [blame] | 250 | return framebuffer_open(module, &mFbDev); |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 253 | status_t HWComposer::initCheck() const { |
| 254 | return mHwc ? NO_ERROR : NO_INIT; |
| 255 | } |
| 256 | |
Jesse Hall | bbd164a | 2012-08-21 12:05:09 -0700 | [diff] [blame] | 257 | void HWComposer::hook_invalidate(const struct hwc_procs* procs) { |
| 258 | cb_context* ctx = reinterpret_cast<cb_context*>( |
| 259 | const_cast<hwc_procs_t*>(procs)); |
| 260 | ctx->hwc->invalidate(); |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 263 | void HWComposer::hook_vsync(const struct hwc_procs* procs, int disp, |
Jesse Hall | bbd164a | 2012-08-21 12:05:09 -0700 | [diff] [blame] | 264 | int64_t timestamp) { |
| 265 | cb_context* ctx = reinterpret_cast<cb_context*>( |
| 266 | const_cast<hwc_procs_t*>(procs)); |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 267 | ctx->hwc->vsync(disp, timestamp); |
| 268 | } |
| 269 | |
| 270 | void HWComposer::hook_hotplug(const struct hwc_procs* procs, int disp, |
| 271 | int connected) { |
| 272 | cb_context* ctx = reinterpret_cast<cb_context*>( |
| 273 | const_cast<hwc_procs_t*>(procs)); |
| 274 | ctx->hwc->hotplug(disp, connected); |
Mathias Agopian | 31d2843 | 2012-04-03 16:31:39 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 277 | void HWComposer::invalidate() { |
Mathias Agopian | e2c2f92 | 2011-10-05 15:00:22 -0700 | [diff] [blame] | 278 | mFlinger->repaintEverything(); |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 281 | void HWComposer::vsync(int disp, int64_t timestamp) { |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 282 | if (uint32_t(disp) < HWC_NUM_PHYSICAL_DISPLAY_TYPES) { |
Jesse Hall | 8e26b28 | 2013-10-14 12:36:45 -0700 | [diff] [blame] | 283 | { |
| 284 | Mutex::Autolock _l(mLock); |
| 285 | |
| 286 | // There have been reports of HWCs that signal several vsync events |
| 287 | // with the same timestamp when turning the display off and on. This |
| 288 | // is a bug in the HWC implementation, but filter the extra events |
| 289 | // out here so they don't cause havoc downstream. |
| 290 | if (timestamp == mLastHwVSync[disp]) { |
Michael Lentine | 258ee43 | 2014-07-30 16:24:48 -0700 | [diff] [blame] | 291 | ALOGW("Ignoring duplicate VSYNC event from HWC (t=%" PRId64 ")", |
Jesse Hall | 8e26b28 | 2013-10-14 12:36:45 -0700 | [diff] [blame] | 292 | timestamp); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | mLastHwVSync[disp] = timestamp; |
| 297 | } |
| 298 | |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 299 | char tag[16]; |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 300 | snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp); |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 301 | ATRACE_INT(tag, ++mVSyncCounts[disp] & 1); |
| 302 | |
| 303 | mEventHandler.onVSyncReceived(disp, timestamp); |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 304 | } |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 307 | void HWComposer::hotplug(int disp, int connected) { |
Michael Lentine | 10613dc | 2015-05-12 18:04:26 -0700 | [diff] [blame] | 308 | if (disp >= VIRTUAL_DISPLAY_ID_BASE) { |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 309 | ALOGE("hotplug event received for invalid display: disp=%d connected=%d", |
| 310 | disp, connected); |
| 311 | return; |
| 312 | } |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 313 | queryDisplayProperties(disp); |
Michael Lentine | 10613dc | 2015-05-12 18:04:26 -0700 | [diff] [blame] | 314 | // Do not teardown or recreate the primary display |
| 315 | if (disp != HWC_DISPLAY_PRIMARY) { |
| 316 | mEventHandler.onHotplugReceived(disp, bool(connected)); |
| 317 | } |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Jesse Hall | bacc28e | 2014-09-28 12:14:12 -0700 | [diff] [blame] | 320 | static float getDefaultDensity(uint32_t width, uint32_t height) { |
| 321 | // Default density is based on TVs: 1080p displays get XHIGH density, |
| 322 | // lower-resolution displays get TV density. Maybe eventually we'll need |
| 323 | // to update it for 4K displays, though hopefully those just report |
| 324 | // accurate DPI information to begin with. This is also used for virtual |
| 325 | // displays and even primary displays with older hwcomposers, so be |
| 326 | // careful about orientation. |
| 327 | |
| 328 | uint32_t h = width < height ? width : height; |
| 329 | if (h >= 1080) return ACONFIGURATION_DENSITY_XHIGH; |
| 330 | else return ACONFIGURATION_DENSITY_TV; |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 333 | static const uint32_t DISPLAY_ATTRIBUTES[] = { |
| 334 | HWC_DISPLAY_VSYNC_PERIOD, |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 335 | HWC_DISPLAY_WIDTH, |
| 336 | HWC_DISPLAY_HEIGHT, |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 337 | HWC_DISPLAY_DPI_X, |
| 338 | HWC_DISPLAY_DPI_Y, |
Dan Stoza | f2699fc | 2015-08-31 12:06:48 -0700 | [diff] [blame] | 339 | HWC_DISPLAY_COLOR_TRANSFORM, |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 340 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 341 | }; |
| 342 | #define NUM_DISPLAY_ATTRIBUTES (sizeof(DISPLAY_ATTRIBUTES) / sizeof(DISPLAY_ATTRIBUTES)[0]) |
| 343 | |
Dan Stoza | f2699fc | 2015-08-31 12:06:48 -0700 | [diff] [blame] | 344 | static const uint32_t PRE_HWC15_DISPLAY_ATTRIBUTES[] = { |
| 345 | HWC_DISPLAY_VSYNC_PERIOD, |
| 346 | HWC_DISPLAY_WIDTH, |
| 347 | HWC_DISPLAY_HEIGHT, |
| 348 | HWC_DISPLAY_DPI_X, |
| 349 | HWC_DISPLAY_DPI_Y, |
| 350 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 351 | }; |
| 352 | |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 353 | status_t HWComposer::queryDisplayProperties(int disp) { |
| 354 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 355 | LOG_ALWAYS_FATAL_IF(!mHwc || !hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)); |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 356 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 357 | // use zero as default value for unspecified attributes |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 358 | int32_t values[NUM_DISPLAY_ATTRIBUTES - 1]; |
| 359 | memset(values, 0, sizeof(values)); |
| 360 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 361 | const size_t MAX_NUM_CONFIGS = 128; |
| 362 | uint32_t configs[MAX_NUM_CONFIGS] = {0}; |
| 363 | size_t numConfigs = MAX_NUM_CONFIGS; |
| 364 | status_t err = mHwc->getDisplayConfigs(mHwc, disp, configs, &numConfigs); |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 365 | if (err != NO_ERROR) { |
| 366 | // this can happen if an unpluggable display is not connected |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 367 | mDisplayData[disp].connected = false; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 368 | return err; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 371 | mDisplayData[disp].currentConfig = 0; |
| 372 | for (size_t c = 0; c < numConfigs; ++c) { |
| 373 | err = mHwc->getDisplayAttributes(mHwc, disp, configs[c], |
| 374 | DISPLAY_ATTRIBUTES, values); |
Dan Stoza | f2699fc | 2015-08-31 12:06:48 -0700 | [diff] [blame] | 375 | // If this is a pre-1.5 HWC, it may not know about color transform, so |
| 376 | // try again with a smaller set of attributes |
| 377 | if (err != NO_ERROR) { |
| 378 | err = mHwc->getDisplayAttributes(mHwc, disp, configs[c], |
| 379 | PRE_HWC15_DISPLAY_ATTRIBUTES, values); |
| 380 | } |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 381 | if (err != NO_ERROR) { |
| 382 | // we can't get this display's info. turn it off. |
| 383 | mDisplayData[disp].connected = false; |
| 384 | return err; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 385 | } |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 386 | |
| 387 | DisplayConfig config = DisplayConfig(); |
| 388 | for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { |
| 389 | switch (DISPLAY_ATTRIBUTES[i]) { |
| 390 | case HWC_DISPLAY_VSYNC_PERIOD: |
| 391 | config.refresh = nsecs_t(values[i]); |
| 392 | break; |
| 393 | case HWC_DISPLAY_WIDTH: |
| 394 | config.width = values[i]; |
| 395 | break; |
| 396 | case HWC_DISPLAY_HEIGHT: |
| 397 | config.height = values[i]; |
| 398 | break; |
| 399 | case HWC_DISPLAY_DPI_X: |
| 400 | config.xdpi = values[i] / 1000.0f; |
| 401 | break; |
| 402 | case HWC_DISPLAY_DPI_Y: |
| 403 | config.ydpi = values[i] / 1000.0f; |
| 404 | break; |
Dan Stoza | f2699fc | 2015-08-31 12:06:48 -0700 | [diff] [blame] | 405 | case HWC_DISPLAY_COLOR_TRANSFORM: |
| 406 | config.colorTransform = values[i]; |
| 407 | break; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 408 | default: |
Michael Lentine | b54ee77 | 2014-08-07 14:54:23 -0700 | [diff] [blame] | 409 | ALOG_ASSERT(false, "unknown display attribute[%zu] %#x", |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 410 | i, DISPLAY_ATTRIBUTES[i]); |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (config.xdpi == 0.0f || config.ydpi == 0.0f) { |
Jesse Hall | bacc28e | 2014-09-28 12:14:12 -0700 | [diff] [blame] | 416 | float dpi = getDefaultDensity(config.width, config.height); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 417 | config.xdpi = dpi; |
| 418 | config.ydpi = dpi; |
| 419 | } |
| 420 | |
| 421 | mDisplayData[disp].configs.push_back(config); |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 424 | // FIXME: what should we set the format to? |
| 425 | mDisplayData[disp].format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 426 | mDisplayData[disp].connected = true; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 427 | return NO_ERROR; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 430 | status_t HWComposer::setVirtualDisplayProperties(int32_t id, |
| 431 | uint32_t w, uint32_t h, uint32_t format) { |
| 432 | if (id < VIRTUAL_DISPLAY_ID_BASE || id >= int32_t(mNumDisplays) || |
| 433 | !mAllocatedDisplayIDs.hasBit(id)) { |
| 434 | return BAD_INDEX; |
| 435 | } |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 436 | size_t configId = mDisplayData[id].currentConfig; |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 437 | mDisplayData[id].format = format; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 438 | DisplayConfig& config = mDisplayData[id].configs.editItemAt(configId); |
| 439 | config.width = w; |
| 440 | config.height = h; |
Jesse Hall | bacc28e | 2014-09-28 12:14:12 -0700 | [diff] [blame] | 441 | config.xdpi = config.ydpi = getDefaultDensity(w, h); |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 442 | return NO_ERROR; |
| 443 | } |
| 444 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 445 | int32_t HWComposer::allocateDisplayId() { |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 446 | if (mAllocatedDisplayIDs.count() >= mNumDisplays) { |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 447 | return NO_MEMORY; |
| 448 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 449 | int32_t id = mAllocatedDisplayIDs.firstUnmarkedBit(); |
| 450 | mAllocatedDisplayIDs.markBit(id); |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 451 | mDisplayData[id].connected = true; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 452 | mDisplayData[id].configs.resize(1); |
| 453 | mDisplayData[id].currentConfig = 0; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 454 | return id; |
| 455 | } |
| 456 | |
| 457 | status_t HWComposer::freeDisplayId(int32_t id) { |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 458 | if (id < NUM_BUILTIN_DISPLAYS) { |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 459 | // cannot free the reserved IDs |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 460 | return BAD_VALUE; |
| 461 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 462 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 463 | return BAD_INDEX; |
| 464 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 465 | mAllocatedDisplayIDs.clearBit(id); |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 466 | mDisplayData[id].connected = false; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 467 | return NO_ERROR; |
| 468 | } |
| 469 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 470 | nsecs_t HWComposer::getRefreshTimestamp(int disp) const { |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 471 | // this returns the last refresh timestamp. |
| 472 | // if the last one is not available, we estimate it based on |
| 473 | // the refresh period and whatever closest timestamp we have. |
| 474 | Mutex::Autolock _l(mLock); |
| 475 | nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 476 | size_t configId = mDisplayData[disp].currentConfig; |
| 477 | return now - ((now - mLastHwVSync[disp]) % |
| 478 | mDisplayData[disp].configs[configId].refresh); |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 481 | sp<Fence> HWComposer::getDisplayFence(int disp) const { |
| 482 | return mDisplayData[disp].lastDisplayFence; |
| 483 | } |
| 484 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 485 | uint32_t HWComposer::getFormat(int disp) const { |
Ajay Dudani | 4e3e30c | 2015-05-03 11:44:55 -0700 | [diff] [blame] | 486 | if (static_cast<uint32_t>(disp) >= MAX_HWC_DISPLAYS || !mAllocatedDisplayIDs.hasBit(disp)) { |
Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 487 | return HAL_PIXEL_FORMAT_RGBA_8888; |
| 488 | } else { |
| 489 | return mDisplayData[disp].format; |
| 490 | } |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 493 | bool HWComposer::isConnected(int disp) const { |
| 494 | return mDisplayData[disp].connected; |
| 495 | } |
| 496 | |
| 497 | uint32_t HWComposer::getWidth(int disp) const { |
| 498 | size_t currentConfig = mDisplayData[disp].currentConfig; |
| 499 | return mDisplayData[disp].configs[currentConfig].width; |
| 500 | } |
| 501 | |
| 502 | uint32_t HWComposer::getHeight(int disp) const { |
| 503 | size_t currentConfig = mDisplayData[disp].currentConfig; |
| 504 | return mDisplayData[disp].configs[currentConfig].height; |
| 505 | } |
| 506 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 507 | float HWComposer::getDpiX(int disp) const { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 508 | size_t currentConfig = mDisplayData[disp].currentConfig; |
| 509 | return mDisplayData[disp].configs[currentConfig].xdpi; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | float HWComposer::getDpiY(int disp) const { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 513 | size_t currentConfig = mDisplayData[disp].currentConfig; |
| 514 | return mDisplayData[disp].configs[currentConfig].ydpi; |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 517 | nsecs_t HWComposer::getRefreshPeriod(int disp) const { |
| 518 | size_t currentConfig = mDisplayData[disp].currentConfig; |
| 519 | return mDisplayData[disp].configs[currentConfig].refresh; |
| 520 | } |
| 521 | |
| 522 | const Vector<HWComposer::DisplayConfig>& HWComposer::getConfigs(int disp) const { |
| 523 | return mDisplayData[disp].configs; |
| 524 | } |
| 525 | |
| 526 | size_t HWComposer::getCurrentConfig(int disp) const { |
| 527 | return mDisplayData[disp].currentConfig; |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 530 | void HWComposer::eventControl(int disp, int event, int enabled) { |
| 531 | if (uint32_t(disp)>31 || !mAllocatedDisplayIDs.hasBit(disp)) { |
Andy McFadden | 620685c | 2012-10-19 12:53:46 -0700 | [diff] [blame] | 532 | ALOGD("eventControl ignoring event %d on unallocated disp %d (en=%d)", |
| 533 | event, disp, enabled); |
| 534 | return; |
| 535 | } |
| 536 | if (event != EVENT_VSYNC) { |
| 537 | ALOGW("eventControl got unexpected event %d (disp=%d en=%d)", |
| 538 | event, disp, enabled); |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 539 | return; |
| 540 | } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 541 | status_t err = NO_ERROR; |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 542 | if (mHwc && !mDebugForceFakeVSync) { |
| 543 | // NOTE: we use our own internal lock here because we have to call |
| 544 | // into the HWC with the lock held, and we want to make sure |
| 545 | // that even if HWC blocks (which it shouldn't), it won't |
| 546 | // affect other threads. |
| 547 | Mutex::Autolock _l(mEventControlLock); |
| 548 | const int32_t eventBit = 1UL << event; |
| 549 | const int32_t newValue = enabled ? eventBit : 0; |
| 550 | const int32_t oldValue = mDisplayData[disp].events & eventBit; |
| 551 | if (newValue != oldValue) { |
| 552 | ATRACE_CALL(); |
| 553 | err = mHwc->eventControl(mHwc, disp, event, enabled); |
| 554 | if (!err) { |
| 555 | int32_t& events(mDisplayData[disp].events); |
| 556 | events = (events & ~eventBit) | newValue; |
Jesse Hall | 4d407a0 | 2014-08-25 14:44:16 -0700 | [diff] [blame] | 557 | |
| 558 | char tag[16]; |
| 559 | snprintf(tag, sizeof(tag), "HW_VSYNC_ON_%1u", disp); |
| 560 | ATRACE_INT(tag, enabled); |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 561 | } |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 562 | } |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 563 | // error here should not happen -- not sure what we should |
| 564 | // do if it does. |
| 565 | ALOGE_IF(err, "eventControl(%d, %d) failed %s", |
| 566 | event, enabled, strerror(-err)); |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 567 | } |
Mathias Agopian | 3a77871 | 2012-04-09 14:16:47 -0700 | [diff] [blame] | 568 | |
| 569 | if (err == NO_ERROR && mVSyncThread != NULL) { |
| 570 | mVSyncThread->setEnabled(enabled); |
| 571 | } |
Mathias Agopian | 31d2843 | 2012-04-03 16:31:39 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 574 | status_t HWComposer::createWorkList(int32_t id, size_t numLayers) { |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 575 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 576 | return BAD_INDEX; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 577 | } |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 578 | |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 579 | if (mHwc) { |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 580 | DisplayData& disp(mDisplayData[id]); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 581 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 582 | // we need space for the HWC_FRAMEBUFFER_TARGET |
| 583 | numLayers++; |
| 584 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 585 | if (disp.capacity < numLayers || disp.list == NULL) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 586 | size_t size = sizeof(hwc_display_contents_1_t) |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 587 | + numLayers * sizeof(hwc_layer_1_t); |
| 588 | free(disp.list); |
| 589 | disp.list = (hwc_display_contents_1_t*)malloc(size); |
| 590 | disp.capacity = numLayers; |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 591 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 592 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 593 | disp.framebufferTarget = &disp.list->hwLayers[numLayers - 1]; |
| 594 | memset(disp.framebufferTarget, 0, sizeof(hwc_layer_1_t)); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 595 | const DisplayConfig& currentConfig = |
| 596 | disp.configs[disp.currentConfig]; |
| 597 | const hwc_rect_t r = { 0, 0, |
| 598 | (int) currentConfig.width, (int) currentConfig.height }; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 599 | disp.framebufferTarget->compositionType = HWC_FRAMEBUFFER_TARGET; |
| 600 | disp.framebufferTarget->hints = 0; |
| 601 | disp.framebufferTarget->flags = 0; |
| 602 | disp.framebufferTarget->handle = disp.fbTargetHandle; |
| 603 | disp.framebufferTarget->transform = 0; |
| 604 | disp.framebufferTarget->blending = HWC_BLENDING_PREMULT; |
Mathias Agopian | 8f63c20 | 2013-09-25 20:44:34 -0700 | [diff] [blame] | 605 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { |
| 606 | disp.framebufferTarget->sourceCropf.left = 0; |
| 607 | disp.framebufferTarget->sourceCropf.top = 0; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 608 | disp.framebufferTarget->sourceCropf.right = |
| 609 | currentConfig.width; |
| 610 | disp.framebufferTarget->sourceCropf.bottom = |
| 611 | currentConfig.height; |
Mathias Agopian | 8f63c20 | 2013-09-25 20:44:34 -0700 | [diff] [blame] | 612 | } else { |
| 613 | disp.framebufferTarget->sourceCrop = r; |
| 614 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 615 | disp.framebufferTarget->displayFrame = r; |
| 616 | disp.framebufferTarget->visibleRegionScreen.numRects = 1; |
| 617 | disp.framebufferTarget->visibleRegionScreen.rects = |
| 618 | &disp.framebufferTarget->displayFrame; |
| 619 | disp.framebufferTarget->acquireFenceFd = -1; |
| 620 | disp.framebufferTarget->releaseFenceFd = -1; |
Mathias Agopian | 70a6e88 | 2013-03-21 16:25:12 -0700 | [diff] [blame] | 621 | disp.framebufferTarget->planeAlpha = 0xFF; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 622 | } |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 623 | disp.list->retireFenceFd = -1; |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 624 | disp.list->flags = HWC_GEOMETRY_CHANGED; |
| 625 | disp.list->numHwLayers = numLayers; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 626 | } |
| 627 | return NO_ERROR; |
| 628 | } |
| 629 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 630 | status_t HWComposer::setFramebufferTarget(int32_t id, |
| 631 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf) { |
| 632 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { |
| 633 | return BAD_INDEX; |
| 634 | } |
| 635 | DisplayData& disp(mDisplayData[id]); |
| 636 | if (!disp.framebufferTarget) { |
| 637 | // this should never happen, but apparently eglCreateWindowSurface() |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 638 | // triggers a Surface::queueBuffer() on some |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 639 | // devices (!?) -- log and ignore. |
| 640 | ALOGE("HWComposer: framebufferTarget is null"); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 641 | return NO_ERROR; |
| 642 | } |
| 643 | |
| 644 | int acquireFenceFd = -1; |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 645 | if (acquireFence->isValid()) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 646 | acquireFenceFd = acquireFence->dup(); |
| 647 | } |
| 648 | |
| 649 | // ALOGD("fbPost: handle=%p, fence=%d", buf->handle, acquireFenceFd); |
| 650 | disp.fbTargetHandle = buf->handle; |
| 651 | disp.framebufferTarget->handle = disp.fbTargetHandle; |
| 652 | disp.framebufferTarget->acquireFenceFd = acquireFenceFd; |
| 653 | return NO_ERROR; |
| 654 | } |
| 655 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 656 | status_t HWComposer::prepare() { |
Manoj Kumar AVM | e04e4ed | 2015-06-11 14:18:14 -0700 | [diff] [blame] | 657 | Mutex::Autolock _l(mDisplayLock); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 658 | for (size_t i=0 ; i<mNumDisplays ; i++) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 659 | DisplayData& disp(mDisplayData[i]); |
| 660 | if (disp.framebufferTarget) { |
| 661 | // make sure to reset the type to HWC_FRAMEBUFFER_TARGET |
| 662 | // DO NOT reset the handle field to NULL, because it's possible |
| 663 | // that we have nothing to redraw (eg: eglSwapBuffers() not called) |
| 664 | // in which case, we should continue to use the same buffer. |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 665 | LOG_FATAL_IF(disp.list == NULL); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 666 | disp.framebufferTarget->compositionType = HWC_FRAMEBUFFER_TARGET; |
| 667 | } |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 668 | if (!disp.connected && disp.list != NULL) { |
Michael Lentine | 258ee43 | 2014-07-30 16:24:48 -0700 | [diff] [blame] | 669 | ALOGW("WARNING: disp %zu: connected, non-null list, layers=%zu", |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 670 | i, disp.list->numHwLayers); |
| 671 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 672 | mLists[i] = disp.list; |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 673 | if (mLists[i]) { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 674 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { |
Jesse Hall | f7a6758 | 2013-11-05 16:12:31 -0800 | [diff] [blame] | 675 | mLists[i]->outbuf = disp.outbufHandle; |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 676 | mLists[i]->outbufAcquireFenceFd = -1; |
| 677 | } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 678 | // garbage data to catch improper use |
| 679 | mLists[i]->dpy = (hwc_display_t)0xDEADBEEF; |
| 680 | mLists[i]->sur = (hwc_surface_t)0xDEADBEEF; |
| 681 | } else { |
| 682 | mLists[i]->dpy = EGL_NO_DISPLAY; |
| 683 | mLists[i]->sur = EGL_NO_SURFACE; |
| 684 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 685 | } |
| 686 | } |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 687 | |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 688 | int err = mHwc->prepare(mHwc, mNumDisplays, mLists); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 689 | ALOGE_IF(err, "HWComposer: prepare failed (%s)", strerror(-err)); |
| 690 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 691 | if (err == NO_ERROR) { |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 692 | // here we're just making sure that "skip" layers are set |
| 693 | // to HWC_FRAMEBUFFER and we're also counting how many layers |
| 694 | // we have of each type. |
Jesse Hall | d05a17f | 2013-09-30 16:49:30 -0700 | [diff] [blame] | 695 | // |
| 696 | // If there are no window layers, we treat the display has having FB |
| 697 | // composition, because SurfaceFlinger will use GLES to draw the |
| 698 | // wormhole region. |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 699 | for (size_t i=0 ; i<mNumDisplays ; i++) { |
| 700 | DisplayData& disp(mDisplayData[i]); |
| 701 | disp.hasFbComp = false; |
| 702 | disp.hasOvComp = false; |
| 703 | if (disp.list) { |
| 704 | for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { |
| 705 | hwc_layer_1_t& l = disp.list->hwLayers[i]; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 706 | |
| 707 | //ALOGD("prepare: %d, type=%d, handle=%p", |
| 708 | // i, l.compositionType, l.handle); |
| 709 | |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 710 | if (l.flags & HWC_SKIP_LAYER) { |
| 711 | l.compositionType = HWC_FRAMEBUFFER; |
| 712 | } |
| 713 | if (l.compositionType == HWC_FRAMEBUFFER) { |
| 714 | disp.hasFbComp = true; |
| 715 | } |
| 716 | if (l.compositionType == HWC_OVERLAY) { |
| 717 | disp.hasOvComp = true; |
| 718 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 719 | if (l.compositionType == HWC_CURSOR_OVERLAY) { |
| 720 | disp.hasOvComp = true; |
| 721 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 722 | } |
Jesse Hall | d05a17f | 2013-09-30 16:49:30 -0700 | [diff] [blame] | 723 | if (disp.list->numHwLayers == (disp.framebufferTarget ? 1 : 0)) { |
| 724 | disp.hasFbComp = true; |
| 725 | } |
| 726 | } else { |
| 727 | disp.hasFbComp = true; |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 728 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 729 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 730 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 731 | return (status_t)err; |
| 732 | } |
| 733 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 734 | bool HWComposer::hasHwcComposition(int32_t id) const { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 735 | if (!mHwc || uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 736 | return false; |
| 737 | return mDisplayData[id].hasOvComp; |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 740 | bool HWComposer::hasGlesComposition(int32_t id) const { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 741 | if (!mHwc || uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) |
| 742 | return true; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 743 | return mDisplayData[id].hasFbComp; |
| 744 | } |
| 745 | |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 746 | sp<Fence> HWComposer::getAndResetReleaseFence(int32_t id) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 747 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 748 | return Fence::NO_FENCE; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 749 | |
| 750 | int fd = INVALID_OPERATION; |
| 751 | if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 752 | const DisplayData& disp(mDisplayData[id]); |
| 753 | if (disp.framebufferTarget) { |
| 754 | fd = disp.framebufferTarget->releaseFenceFd; |
Jamie Gennis | d30b36d | 2012-09-30 20:02:03 -0700 | [diff] [blame] | 755 | disp.framebufferTarget->acquireFenceFd = -1; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 756 | disp.framebufferTarget->releaseFenceFd = -1; |
| 757 | } |
| 758 | } |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 759 | return fd >= 0 ? new Fence(fd) : Fence::NO_FENCE; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 762 | status_t HWComposer::commit() { |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 763 | int err = NO_ERROR; |
| 764 | if (mHwc) { |
Jesse Hall | 9eb1eb5 | 2012-08-29 10:39:38 -0700 | [diff] [blame] | 765 | if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 766 | // On version 1.0, the OpenGL ES target surface is communicated |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 767 | // by the (dpy, sur) fields and we are guaranteed to have only |
| 768 | // a single display. |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 769 | mLists[0]->dpy = eglGetCurrentDisplay(); |
| 770 | mLists[0]->sur = eglGetCurrentSurface(EGL_DRAW); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 771 | } |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 772 | |
Jesse Hall | afaf14b | 2013-03-20 13:42:29 -0700 | [diff] [blame] | 773 | for (size_t i=VIRTUAL_DISPLAY_ID_BASE; i<mNumDisplays; i++) { |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 774 | DisplayData& disp(mDisplayData[i]); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 775 | if (disp.outbufHandle) { |
| 776 | mLists[i]->outbuf = disp.outbufHandle; |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 777 | mLists[i]->outbufAcquireFenceFd = |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 778 | disp.outbufAcquireFence->dup(); |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 782 | err = mHwc->set(mHwc, mNumDisplays, mLists); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 783 | |
| 784 | for (size_t i=0 ; i<mNumDisplays ; i++) { |
| 785 | DisplayData& disp(mDisplayData[i]); |
Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 786 | disp.lastDisplayFence = disp.lastRetireFence; |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 787 | disp.lastRetireFence = Fence::NO_FENCE; |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 788 | if (disp.list) { |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 789 | if (disp.list->retireFenceFd != -1) { |
Jamie Gennis | 2ec3e07 | 2012-11-11 16:24:33 -0800 | [diff] [blame] | 790 | disp.lastRetireFence = new Fence(disp.list->retireFenceFd); |
Jesse Hall | db27621 | 2012-09-07 11:20:56 -0700 | [diff] [blame] | 791 | disp.list->retireFenceFd = -1; |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 792 | } |
| 793 | disp.list->flags &= ~HWC_GEOMETRY_CHANGED; |
| 794 | } |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 795 | } |
Mathias Agopian | 5895934 | 2010-10-07 14:57:04 -0700 | [diff] [blame] | 796 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 797 | return (status_t)err; |
| 798 | } |
| 799 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 800 | status_t HWComposer::setPowerMode(int disp, int mode) { |
Jesse Hall | afaf14b | 2013-03-20 13:42:29 -0700 | [diff] [blame] | 801 | LOG_FATAL_IF(disp >= VIRTUAL_DISPLAY_ID_BASE); |
Mathias Agopian | 7ee4cd5 | 2011-09-02 12:22:39 -0700 | [diff] [blame] | 802 | if (mHwc) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 803 | if (mode == HWC_POWER_MODE_OFF) { |
| 804 | eventControl(disp, HWC_EVENT_VSYNC, 0); |
| 805 | } |
| 806 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_4)) { |
| 807 | return (status_t)mHwc->setPowerMode(mHwc, disp, mode); |
| 808 | } else { |
| 809 | return (status_t)mHwc->blank(mHwc, disp, |
| 810 | mode == HWC_POWER_MODE_OFF ? 1 : 0); |
| 811 | } |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 812 | } |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 813 | return NO_ERROR; |
| 814 | } |
| 815 | |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 816 | status_t HWComposer::setActiveConfig(int disp, int mode) { |
| 817 | LOG_FATAL_IF(disp >= VIRTUAL_DISPLAY_ID_BASE); |
Michael Lentine | d3e6914 | 2014-08-21 14:43:13 -0700 | [diff] [blame] | 818 | DisplayData& dd(mDisplayData[disp]); |
| 819 | dd.currentConfig = mode; |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 820 | if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_4)) { |
| 821 | return (status_t)mHwc->setActiveConfig(mHwc, disp, mode); |
| 822 | } else { |
| 823 | LOG_FATAL_IF(mode != 0); |
| 824 | } |
| 825 | return NO_ERROR; |
| 826 | } |
| 827 | |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 828 | void HWComposer::disconnectDisplay(int disp) { |
Andy McFadden | 5a8f901 | 2012-10-04 19:09:45 -0700 | [diff] [blame] | 829 | LOG_ALWAYS_FATAL_IF(disp < 0 || disp == HWC_DISPLAY_PRIMARY); |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 830 | DisplayData& dd(mDisplayData[disp]); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 831 | free(dd.list); |
| 832 | dd.list = NULL; |
| 833 | dd.framebufferTarget = NULL; // points into dd.list |
| 834 | dd.fbTargetHandle = NULL; |
| 835 | dd.outbufHandle = NULL; |
| 836 | dd.lastRetireFence = Fence::NO_FENCE; |
| 837 | dd.lastDisplayFence = Fence::NO_FENCE; |
| 838 | dd.outbufAcquireFence = Fence::NO_FENCE; |
Naseer Ahmed | 949ea08 | 2014-08-20 16:31:58 -0400 | [diff] [blame] | 839 | // clear all the previous configs and repopulate when a new |
| 840 | // device is added |
| 841 | dd.configs.clear(); |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 844 | int HWComposer::getVisualID() const { |
Jesse Hall | d3d35f1 | 2012-09-18 11:39:40 -0700 | [diff] [blame] | 845 | if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 846 | // FIXME: temporary hack until HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED |
| 847 | // is supported by the implementation. we can only be in this case |
| 848 | // if we have HWC 1.1 |
| 849 | return HAL_PIXEL_FORMAT_RGBA_8888; |
| 850 | //return HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 851 | } else { |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 852 | return mFbDev->format; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 856 | bool HWComposer::supportsFramebufferTarget() const { |
| 857 | return (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)); |
| 858 | } |
| 859 | |
| 860 | int HWComposer::fbPost(int32_t id, |
| 861 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) { |
Jesse Hall | d3d35f1 | 2012-09-18 11:39:40 -0700 | [diff] [blame] | 862 | if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 863 | return setFramebufferTarget(id, acquireFence, buffer); |
| 864 | } else { |
Mathias Agopian | ea74d3b | 2013-05-16 18:03:22 -0700 | [diff] [blame] | 865 | acquireFence->waitForever("HWComposer::fbPost"); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 866 | return mFbDev->post(mFbDev, buffer->handle); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 867 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | int HWComposer::fbCompositionComplete() { |
Jesse Hall | d3d35f1 | 2012-09-18 11:39:40 -0700 | [diff] [blame] | 871 | if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 872 | return NO_ERROR; |
| 873 | |
| 874 | if (mFbDev->compositionComplete) { |
| 875 | return mFbDev->compositionComplete(mFbDev); |
| 876 | } else { |
| 877 | return INVALID_OPERATION; |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 878 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 881 | void HWComposer::fbDump(String8& result) { |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 882 | if (mFbDev && mFbDev->common.version >= 1 && mFbDev->dump) { |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 883 | const size_t SIZE = 4096; |
| 884 | char buffer[SIZE]; |
| 885 | mFbDev->dump(mFbDev, buffer, SIZE); |
| 886 | result.append(buffer); |
| 887 | } |
| 888 | } |
| 889 | |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 890 | status_t HWComposer::setOutputBuffer(int32_t id, const sp<Fence>& acquireFence, |
| 891 | const sp<GraphicBuffer>& buf) { |
| 892 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) |
| 893 | return BAD_INDEX; |
| 894 | if (id < VIRTUAL_DISPLAY_ID_BASE) |
| 895 | return INVALID_OPERATION; |
| 896 | |
| 897 | DisplayData& disp(mDisplayData[id]); |
| 898 | disp.outbufHandle = buf->handle; |
| 899 | disp.outbufAcquireFence = acquireFence; |
| 900 | return NO_ERROR; |
| 901 | } |
| 902 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 903 | sp<Fence> HWComposer::getLastRetireFence(int32_t id) const { |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 904 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) |
| 905 | return Fence::NO_FENCE; |
| 906 | return mDisplayData[id].lastRetireFence; |
| 907 | } |
| 908 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 909 | status_t HWComposer::setCursorPositionAsync(int32_t id, const Rect& pos) |
| 910 | { |
| 911 | if (mHwc->setCursorPositionAsync) { |
| 912 | return (status_t)mHwc->setCursorPositionAsync(mHwc, id, pos.left, pos.top); |
| 913 | } |
| 914 | else { |
| 915 | return NO_ERROR; |
| 916 | } |
| 917 | } |
| 918 | |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 919 | /* |
| 920 | * Helper template to implement a concrete HWCLayer |
| 921 | * This holds the pointer to the concrete hwc layer type |
| 922 | * and implements the "iterable" side of HWCLayer. |
| 923 | */ |
| 924 | template<typename CONCRETE, typename HWCTYPE> |
| 925 | class Iterable : public HWComposer::HWCLayer { |
| 926 | protected: |
| 927 | HWCTYPE* const mLayerList; |
| 928 | HWCTYPE* mCurrentLayer; |
| 929 | Iterable(HWCTYPE* layer) : mLayerList(layer), mCurrentLayer(layer) { } |
| 930 | inline HWCTYPE const * getLayer() const { return mCurrentLayer; } |
| 931 | inline HWCTYPE* getLayer() { return mCurrentLayer; } |
| 932 | virtual ~Iterable() { } |
| 933 | private: |
| 934 | // returns a copy of ourselves |
| 935 | virtual HWComposer::HWCLayer* dup() { |
| 936 | return new CONCRETE( static_cast<const CONCRETE&>(*this) ); |
| 937 | } |
| 938 | virtual status_t setLayer(size_t index) { |
| 939 | mCurrentLayer = &mLayerList[index]; |
| 940 | return NO_ERROR; |
| 941 | } |
| 942 | }; |
| 943 | |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 944 | /* |
| 945 | * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_1_0. |
| 946 | * This implements the HWCLayer side of HWCIterableLayer. |
| 947 | */ |
| 948 | class HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> { |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 949 | struct hwc_composer_device_1* mHwc; |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 950 | public: |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 951 | HWCLayerVersion1(struct hwc_composer_device_1* hwc, hwc_layer_1_t* layer) |
| 952 | : Iterable<HWCLayerVersion1, hwc_layer_1_t>(layer), mHwc(hwc) { } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 953 | |
| 954 | virtual int32_t getCompositionType() const { |
| 955 | return getLayer()->compositionType; |
| 956 | } |
| 957 | virtual uint32_t getHints() const { |
| 958 | return getLayer()->hints; |
| 959 | } |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 960 | virtual sp<Fence> getAndResetReleaseFence() { |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 961 | int fd = getLayer()->releaseFenceFd; |
| 962 | getLayer()->releaseFenceFd = -1; |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 963 | return fd >= 0 ? new Fence(fd) : Fence::NO_FENCE; |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 964 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 965 | virtual void setAcquireFenceFd(int fenceFd) { |
| 966 | getLayer()->acquireFenceFd = fenceFd; |
| 967 | } |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 968 | virtual void setPerFrameDefaultState() { |
| 969 | //getLayer()->compositionType = HWC_FRAMEBUFFER; |
| 970 | } |
| 971 | virtual void setPlaneAlpha(uint8_t alpha) { |
| 972 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_2)) { |
| 973 | getLayer()->planeAlpha = alpha; |
| 974 | } else { |
Mathias Agopian | 5fe58b8 | 2013-02-07 16:22:50 -0800 | [diff] [blame] | 975 | if (alpha < 0xFF) { |
| 976 | getLayer()->flags |= HWC_SKIP_LAYER; |
| 977 | } |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 978 | } |
| 979 | } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 980 | virtual void setDefaultState() { |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 981 | hwc_layer_1_t* const l = getLayer(); |
| 982 | l->compositionType = HWC_FRAMEBUFFER; |
| 983 | l->hints = 0; |
| 984 | l->flags = HWC_SKIP_LAYER; |
| 985 | l->handle = 0; |
| 986 | l->transform = 0; |
| 987 | l->blending = HWC_BLENDING_NONE; |
| 988 | l->visibleRegionScreen.numRects = 0; |
| 989 | l->visibleRegionScreen.rects = NULL; |
| 990 | l->acquireFenceFd = -1; |
| 991 | l->releaseFenceFd = -1; |
| 992 | l->planeAlpha = 0xFF; |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 993 | } |
| 994 | virtual void setSkip(bool skip) { |
| 995 | if (skip) { |
| 996 | getLayer()->flags |= HWC_SKIP_LAYER; |
| 997 | } else { |
| 998 | getLayer()->flags &= ~HWC_SKIP_LAYER; |
| 999 | } |
| 1000 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 1001 | virtual void setIsCursorLayerHint(bool isCursor) { |
| 1002 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_4)) { |
| 1003 | if (isCursor) { |
| 1004 | getLayer()->flags |= HWC_IS_CURSOR_LAYER; |
| 1005 | } |
| 1006 | else { |
| 1007 | getLayer()->flags &= ~HWC_IS_CURSOR_LAYER; |
| 1008 | } |
| 1009 | } |
| 1010 | } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1011 | virtual void setBlending(uint32_t blending) { |
| 1012 | getLayer()->blending = blending; |
| 1013 | } |
| 1014 | virtual void setTransform(uint32_t transform) { |
| 1015 | getLayer()->transform = transform; |
| 1016 | } |
| 1017 | virtual void setFrame(const Rect& frame) { |
Mathias Agopian | 6b44267 | 2013-07-09 21:24:52 -0700 | [diff] [blame] | 1018 | getLayer()->displayFrame = reinterpret_cast<hwc_rect_t const&>(frame); |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1019 | } |
Mathias Agopian | 6b44267 | 2013-07-09 21:24:52 -0700 | [diff] [blame] | 1020 | virtual void setCrop(const FloatRect& crop) { |
| 1021 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { |
| 1022 | getLayer()->sourceCropf = reinterpret_cast<hwc_frect_t const&>(crop); |
| 1023 | } else { |
| 1024 | /* |
| 1025 | * Since h/w composer didn't support a flot crop rect before version 1.3, |
| 1026 | * using integer coordinates instead produces a different output from the GL code in |
| 1027 | * Layer::drawWithOpenGL(). The difference can be large if the buffer crop to |
| 1028 | * window size ratio is large and a window crop is defined |
| 1029 | * (i.e.: if we scale the buffer a lot and we also crop it with a window crop). |
| 1030 | */ |
| 1031 | hwc_rect_t& r = getLayer()->sourceCrop; |
| 1032 | r.left = int(ceilf(crop.left)); |
| 1033 | r.top = int(ceilf(crop.top)); |
| 1034 | r.right = int(floorf(crop.right)); |
| 1035 | r.bottom= int(floorf(crop.bottom)); |
| 1036 | } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1037 | } |
| 1038 | virtual void setVisibleRegionScreen(const Region& reg) { |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 1039 | hwc_region_t& visibleRegion = getLayer()->visibleRegionScreen; |
Pablo Ceballos | d814cf2 | 2015-09-11 14:37:39 -0700 | [diff] [blame^] | 1040 | mVisibleRegion = reg; |
| 1041 | visibleRegion.rects = reinterpret_cast<hwc_rect_t const *>( |
| 1042 | mVisibleRegion.getArray(&visibleRegion.numRects)); |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1043 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 1044 | virtual void setSurfaceDamage(const Region& reg) { |
| 1045 | if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_5)) { |
| 1046 | return; |
| 1047 | } |
| 1048 | hwc_region_t& surfaceDamage = getLayer()->surfaceDamage; |
| 1049 | // We encode default full-screen damage as INVALID_RECT upstream, but as |
| 1050 | // 0 rects for HWComposer |
| 1051 | if (reg.isRect() && reg.getBounds() == Rect::INVALID_RECT) { |
| 1052 | surfaceDamage.numRects = 0; |
| 1053 | surfaceDamage.rects = NULL; |
| 1054 | return; |
| 1055 | } |
Pablo Ceballos | d814cf2 | 2015-09-11 14:37:39 -0700 | [diff] [blame^] | 1056 | mSurfaceDamage = reg; |
| 1057 | surfaceDamage.rects = reinterpret_cast<hwc_rect_t const *>( |
| 1058 | mSurfaceDamage.getArray(&surfaceDamage.numRects)); |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 1059 | } |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1060 | virtual void setSidebandStream(const sp<NativeHandle>& stream) { |
| 1061 | ALOG_ASSERT(stream->handle() != NULL); |
| 1062 | getLayer()->compositionType = HWC_SIDEBAND; |
| 1063 | getLayer()->sidebandStream = stream->handle(); |
| 1064 | } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1065 | virtual void setBuffer(const sp<GraphicBuffer>& buffer) { |
| 1066 | if (buffer == 0 || buffer->handle == 0) { |
| 1067 | getLayer()->compositionType = HWC_FRAMEBUFFER; |
| 1068 | getLayer()->flags |= HWC_SKIP_LAYER; |
| 1069 | getLayer()->handle = 0; |
| 1070 | } else { |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1071 | if (getLayer()->compositionType == HWC_SIDEBAND) { |
| 1072 | // If this was a sideband layer but the stream was removed, reset |
| 1073 | // it to FRAMEBUFFER. The HWC can change it to OVERLAY in prepare. |
| 1074 | getLayer()->compositionType = HWC_FRAMEBUFFER; |
| 1075 | } |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1076 | getLayer()->handle = buffer->handle; |
| 1077 | } |
| 1078 | } |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 1079 | virtual void onDisplayed() { |
Jesse Hall | e25d005 | 2012-09-05 13:03:10 -0700 | [diff] [blame] | 1080 | getLayer()->acquireFenceFd = -1; |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 1081 | } |
Pablo Ceballos | d814cf2 | 2015-09-11 14:37:39 -0700 | [diff] [blame^] | 1082 | |
| 1083 | protected: |
| 1084 | // We need to hold "copies" of these for memory management purposes. The |
| 1085 | // actual hwc_layer_1_t holds pointers to the memory within. Vector<> |
| 1086 | // internally doesn't copy the memory unless one of the copies is modified. |
| 1087 | Region mVisibleRegion; |
| 1088 | Region mSurfaceDamage; |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 1089 | }; |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* |
| 1092 | * returns an iterator initialized at a given index in the layer list |
| 1093 | */ |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 1094 | HWComposer::LayerListIterator HWComposer::getLayerIterator(int32_t id, size_t index) { |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1095 | if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 1096 | return LayerListIterator(); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1097 | } |
| 1098 | const DisplayData& disp(mDisplayData[id]); |
| 1099 | if (!mHwc || !disp.list || index > disp.list->numHwLayers) { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 1100 | return LayerListIterator(); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1101 | } |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 1102 | return LayerListIterator(new HWCLayerVersion1(mHwc, disp.list->hwLayers), index); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 1105 | /* |
| 1106 | * returns an iterator on the beginning of the layer list |
| 1107 | */ |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 1108 | HWComposer::LayerListIterator HWComposer::begin(int32_t id) { |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 1109 | return getLayerIterator(id, 0); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * returns an iterator on the end of the layer list |
| 1114 | */ |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 1115 | HWComposer::LayerListIterator HWComposer::end(int32_t id) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1116 | size_t numLayers = 0; |
| 1117 | if (uint32_t(id) <= 31 && mAllocatedDisplayIDs.hasBit(id)) { |
| 1118 | const DisplayData& disp(mDisplayData[id]); |
| 1119 | if (mHwc && disp.list) { |
| 1120 | numLayers = disp.list->numHwLayers; |
| 1121 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { |
| 1122 | // with HWC 1.1, the last layer is always the HWC_FRAMEBUFFER_TARGET, |
| 1123 | // which we ignore when iterating through the layer list. |
| 1124 | ALOGE_IF(!numLayers, "mDisplayData[%d].list->numHwLayers is 0", id); |
| 1125 | if (numLayers) { |
| 1126 | numLayers--; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | return getLayerIterator(id, numLayers); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1134 | // Converts a PixelFormat to a human-readable string. Max 11 chars. |
| 1135 | // (Could use a table of prefab String8 objects.) |
| 1136 | static String8 getFormatStr(PixelFormat format) { |
| 1137 | switch (format) { |
| 1138 | case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888"); |
| 1139 | case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888"); |
| 1140 | case PIXEL_FORMAT_RGB_888: return String8("RGB_888"); |
| 1141 | case PIXEL_FORMAT_RGB_565: return String8("RGB_565"); |
| 1142 | case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888"); |
Andy McFadden | f0058ca | 2014-05-20 13:28:50 -0700 | [diff] [blame] | 1143 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: |
| 1144 | return String8("ImplDef"); |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1145 | default: |
| 1146 | String8 result; |
| 1147 | result.appendFormat("? %08x", format); |
| 1148 | return result; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 1152 | void HWComposer::dump(String8& result) const { |
Manoj Kumar AVM | e04e4ed | 2015-06-11 14:18:14 -0700 | [diff] [blame] | 1153 | Mutex::Autolock _l(mDisplayLock); |
Jesse Hall | b685c54 | 2012-07-31 14:32:56 -0700 | [diff] [blame] | 1154 | if (mHwc) { |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1155 | result.appendFormat("Hardware Composer state (version %08x):\n", hwcApiVersion(mHwc)); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1156 | result.appendFormat(" mDebugForceFakeVSync=%d\n", mDebugForceFakeVSync); |
| 1157 | for (size_t i=0 ; i<mNumDisplays ; i++) { |
| 1158 | const DisplayData& disp(mDisplayData[i]); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1159 | if (!disp.connected) |
| 1160 | continue; |
Mathias Agopian | b4d18ed | 2012-09-20 23:14:05 -0700 | [diff] [blame] | 1161 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1162 | const Vector< sp<Layer> >& visibleLayersSortedByZ = |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 1163 | mFlinger->getLayerSortedByZForHwcDisplay(i); |
| 1164 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1165 | |
| 1166 | result.appendFormat(" Display[%zd] configurations (* current):\n", i); |
| 1167 | for (size_t c = 0; c < disp.configs.size(); ++c) { |
| 1168 | const DisplayConfig& config(disp.configs[c]); |
Dan Stoza | f2699fc | 2015-08-31 12:06:48 -0700 | [diff] [blame] | 1169 | result.appendFormat(" %s%zd: %ux%u, xdpi=%f, ydpi=%f" |
| 1170 | ", refresh=%" PRId64 ", colorTransform=%d\n", |
| 1171 | c == disp.currentConfig ? "* " : "", c, |
| 1172 | config.width, config.height, config.xdpi, config.ydpi, |
| 1173 | config.refresh, config.colorTransform); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1174 | } |
Mathias Agopian | b4d18ed | 2012-09-20 23:14:05 -0700 | [diff] [blame] | 1175 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1176 | if (disp.list) { |
Mathias Agopian | b4d18ed | 2012-09-20 23:14:05 -0700 | [diff] [blame] | 1177 | result.appendFormat( |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1178 | " numHwLayers=%zu, flags=%08x\n", |
Mathias Agopian | b4d18ed | 2012-09-20 23:14:05 -0700 | [diff] [blame] | 1179 | disp.list->numHwLayers, disp.list->flags); |
| 1180 | |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1181 | result.append( |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1182 | " type | handle | hint | flag | tr | blnd | format | source crop (l,t,r,b) | frame | name \n" |
| 1183 | "-----------+----------+------+------+----+------+-------------+--------------------------------+------------------------+------\n"); |
| 1184 | // " _________ | ________ | ____ | ____ | __ | ____ | ___________ |_____._,_____._,_____._,_____._ |_____,_____,_____,_____ | ___... |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1185 | for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { |
| 1186 | const hwc_layer_1_t&l = disp.list->hwLayers[i]; |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1187 | int32_t format = -1; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1188 | String8 name("unknown"); |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 1189 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1190 | if (i < visibleLayersSortedByZ.size()) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1191 | const sp<Layer>& layer(visibleLayersSortedByZ[i]); |
| 1192 | const sp<GraphicBuffer>& buffer( |
| 1193 | layer->getActiveBuffer()); |
| 1194 | if (buffer != NULL) { |
| 1195 | format = buffer->getPixelFormat(); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1196 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1197 | name = layer->getName(); |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 1198 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1199 | |
| 1200 | int type = l.compositionType; |
| 1201 | if (type == HWC_FRAMEBUFFER_TARGET) { |
| 1202 | name = "HWC_FRAMEBUFFER_TARGET"; |
| 1203 | format = disp.format; |
| 1204 | } |
| 1205 | |
| 1206 | static char const* compositionTypeName[] = { |
| 1207 | "GLES", |
| 1208 | "HWC", |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1209 | "BKGND", |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1210 | "FB TARGET", |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 1211 | "SIDEBAND", |
| 1212 | "HWC_CURSOR", |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1213 | "UNKNOWN"}; |
| 1214 | if (type >= NELEM(compositionTypeName)) |
| 1215 | type = NELEM(compositionTypeName) - 1; |
| 1216 | |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1217 | String8 formatStr = getFormatStr(format); |
Jesse Hall | 353ddc6 | 2013-08-20 16:11:50 -0700 | [diff] [blame] | 1218 | if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { |
| 1219 | result.appendFormat( |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1220 | " %9s | %08" PRIxPTR " | %04x | %04x | %02x | %04x | %-11s |%7.1f,%7.1f,%7.1f,%7.1f |%5d,%5d,%5d,%5d | %s\n", |
Jesse Hall | 353ddc6 | 2013-08-20 16:11:50 -0700 | [diff] [blame] | 1221 | compositionTypeName[type], |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1222 | intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, formatStr.string(), |
Jesse Hall | 353ddc6 | 2013-08-20 16:11:50 -0700 | [diff] [blame] | 1223 | l.sourceCropf.left, l.sourceCropf.top, l.sourceCropf.right, l.sourceCropf.bottom, |
| 1224 | l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, |
| 1225 | name.string()); |
| 1226 | } else { |
| 1227 | result.appendFormat( |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1228 | " %9s | %08" PRIxPTR " | %04x | %04x | %02x | %04x | %-11s |%7d,%7d,%7d,%7d |%5d,%5d,%5d,%5d | %s\n", |
Jesse Hall | 353ddc6 | 2013-08-20 16:11:50 -0700 | [diff] [blame] | 1229 | compositionTypeName[type], |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 1230 | intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, formatStr.string(), |
Jesse Hall | 353ddc6 | 2013-08-20 16:11:50 -0700 | [diff] [blame] | 1231 | l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, |
| 1232 | l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, |
| 1233 | name.string()); |
| 1234 | } |
Mathias Agopian | fb4d5d5 | 2011-09-20 15:13:14 -0700 | [diff] [blame] | 1235 | } |
| 1236 | } |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 1237 | } |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 1238 | } |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (mHwc && mHwc->dump) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 1241 | const size_t SIZE = 4096; |
| 1242 | char buffer[SIZE]; |
Mathias Agopian | 30bcc61 | 2012-08-22 15:39:48 -0700 | [diff] [blame] | 1243 | mHwc->dump(mHwc, buffer, SIZE); |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 1244 | result.append(buffer); |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1248 | // --------------------------------------------------------------------------- |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 1249 | |
| 1250 | HWComposer::VSyncThread::VSyncThread(HWComposer& hwc) |
| 1251 | : mHwc(hwc), mEnabled(false), |
| 1252 | mNextFakeVSync(0), |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 1253 | mRefreshPeriod(hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY)) |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 1254 | { |
| 1255 | } |
| 1256 | |
| 1257 | void HWComposer::VSyncThread::setEnabled(bool enabled) { |
| 1258 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 1259 | if (mEnabled != enabled) { |
| 1260 | mEnabled = enabled; |
| 1261 | mCondition.signal(); |
| 1262 | } |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | void HWComposer::VSyncThread::onFirstRef() { |
| 1266 | run("VSyncThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); |
| 1267 | } |
| 1268 | |
| 1269 | bool HWComposer::VSyncThread::threadLoop() { |
| 1270 | { // scope for lock |
| 1271 | Mutex::Autolock _l(mLock); |
| 1272 | while (!mEnabled) { |
| 1273 | mCondition.wait(mLock); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | const nsecs_t period = mRefreshPeriod; |
| 1278 | const nsecs_t now = systemTime(CLOCK_MONOTONIC); |
| 1279 | nsecs_t next_vsync = mNextFakeVSync; |
| 1280 | nsecs_t sleep = next_vsync - now; |
| 1281 | if (sleep < 0) { |
| 1282 | // we missed, find where the next vsync should be |
| 1283 | sleep = (period - ((now - next_vsync) % period)); |
| 1284 | next_vsync = now + sleep; |
| 1285 | } |
| 1286 | mNextFakeVSync = next_vsync + period; |
| 1287 | |
| 1288 | struct timespec spec; |
| 1289 | spec.tv_sec = next_vsync / 1000000000; |
| 1290 | spec.tv_nsec = next_vsync % 1000000000; |
| 1291 | |
| 1292 | int err; |
| 1293 | do { |
| 1294 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); |
| 1295 | } while (err<0 && errno == EINTR); |
| 1296 | |
| 1297 | if (err == 0) { |
| 1298 | mHwc.mEventHandler.onVSyncReceived(0, next_vsync); |
| 1299 | } |
| 1300 | |
| 1301 | return true; |
| 1302 | } |
| 1303 | |
Jesse Hall | a9a1b00 | 2013-02-27 16:39:25 -0800 | [diff] [blame] | 1304 | HWComposer::DisplayData::DisplayData() |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1305 | : configs(), |
| 1306 | currentConfig(0), |
| 1307 | format(HAL_PIXEL_FORMAT_RGBA_8888), |
Jesse Hall | a9a1b00 | 2013-02-27 16:39:25 -0800 | [diff] [blame] | 1308 | connected(false), |
| 1309 | hasFbComp(false), hasOvComp(false), |
| 1310 | capacity(0), list(NULL), |
| 1311 | framebufferTarget(NULL), fbTargetHandle(0), |
| 1312 | lastRetireFence(Fence::NO_FENCE), lastDisplayFence(Fence::NO_FENCE), |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 1313 | outbufHandle(NULL), outbufAcquireFence(Fence::NO_FENCE), |
Jesse Hall | a9a1b00 | 2013-02-27 16:39:25 -0800 | [diff] [blame] | 1314 | events(0) |
| 1315 | {} |
| 1316 | |
| 1317 | HWComposer::DisplayData::~DisplayData() { |
| 1318 | free(list); |
| 1319 | } |
| 1320 | |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 1321 | // --------------------------------------------------------------------------- |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1322 | }; // namespace android |