| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 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 |  | 
| Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 18 | #define LOG_TAG "hwcomposer-drm" | 
|  | 19 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 20 | #include "drm_hwcomposer.h" | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 21 | #include "drmresources.h" | 
| Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 22 | #include "importer.h" | 
| Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 23 | #include "vsyncworker.h" | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 24 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 25 | #include <stdlib.h> | 
|  | 26 |  | 
|  | 27 | #include <map> | 
|  | 28 | #include <vector> | 
|  | 29 |  | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 30 | #include <errno.h> | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 31 | #include <fcntl.h> | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 32 | #include <pthread.h> | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 33 | #include <sys/param.h> | 
| Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 34 | #include <sys/resource.h> | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 35 | #include <xf86drm.h> | 
|  | 36 | #include <xf86drmMode.h> | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 37 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 38 | #include <cutils/log.h> | 
|  | 39 | #include <cutils/properties.h> | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 40 | #include <hardware/hardware.h> | 
|  | 41 | #include <hardware/hwcomposer.h> | 
| Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 42 | #include <utils/Trace.h> | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 43 |  | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 44 | #define UM_PER_INCH 25400 | 
| Stéphane Marchesin | cb3f984 | 2015-06-19 14:50:45 -0700 | [diff] [blame] | 45 | #define HWC_FB_BUFFERS 3 | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 46 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 47 | namespace android { | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 48 |  | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 49 | typedef struct hwc_drm_display { | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 50 | struct hwc_context_t *ctx; | 
|  | 51 | int display; | 
| Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 52 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 53 | std::vector<uint32_t> config_ids; | 
| Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 54 |  | 
| Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 55 | VSyncWorker vsync_worker; | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 56 | } hwc_drm_display_t; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 57 |  | 
|  | 58 | struct hwc_context_t { | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 59 | // map of display:hwc_drm_display_t | 
|  | 60 | typedef std::map<int, hwc_drm_display_t> DisplayMap; | 
|  | 61 | typedef DisplayMap::iterator DisplayMapIter; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 62 |  | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 63 | hwc_context_t() : procs(NULL), importer(NULL), use_framebuffer_target(false) { | 
| Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
|  | 66 | ~hwc_context_t() { | 
|  | 67 | delete importer; | 
|  | 68 | } | 
|  | 69 |  | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 70 | hwc_composer_device_1_t device; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 71 | hwc_procs_t const *procs; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 72 |  | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 73 | DisplayMap displays; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 74 | DrmResources drm; | 
| Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 75 | Importer *importer; | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 76 | bool use_framebuffer_target; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 77 | }; | 
|  | 78 |  | 
| Zach Reizner | c6520e4 | 2015-08-13 14:32:09 -0700 | [diff] [blame] | 79 | static void hwc_dump(struct hwc_composer_device_1 *dev, char *buff, | 
| Sean Paul | 9046c64 | 2015-06-10 17:27:47 -0400 | [diff] [blame] | 80 | int buff_len) { | 
|  | 81 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
|  | 82 | std::ostringstream out; | 
|  | 83 |  | 
|  | 84 | ctx->drm.compositor()->Dump(&out); | 
|  | 85 | std::string out_str = out.str(); | 
|  | 86 | strncpy(buff, out_str.c_str(), std::min((size_t)buff_len, out_str.length())); | 
|  | 87 | } | 
|  | 88 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 89 | static int hwc_prepare(hwc_composer_device_1_t *dev, size_t num_displays, | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 90 | hwc_display_contents_1_t **display_contents) { | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 91 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | char use_framebuffer_target[PROPERTY_VALUE_MAX]; | 
|  | 94 | property_get("hwc.drm.use_framebuffer_target", use_framebuffer_target, "0"); | 
|  | 95 | bool new_use_framebuffer_target = atoi(use_framebuffer_target); | 
|  | 96 | if (ctx->use_framebuffer_target != new_use_framebuffer_target) | 
|  | 97 | ALOGW("Starting to %s HWC_FRAMEBUFFER_TARGET", | 
|  | 98 | new_use_framebuffer_target ? "use" : "not use"); | 
|  | 99 | ctx->use_framebuffer_target = new_use_framebuffer_target; | 
|  | 100 |  | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 101 | for (int i = 0; i < (int)num_displays; ++i) { | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 102 | if (!display_contents[i]) | 
|  | 103 | continue; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 104 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 105 | DrmCrtc *crtc = ctx->drm.GetCrtcForDisplay(i); | 
|  | 106 | if (!crtc) { | 
|  | 107 | ALOGE("No crtc for display %d", i); | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 108 | return -ENODEV; | 
|  | 109 | } | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 110 |  | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 111 | int num_layers = display_contents[i]->numHwLayers; | 
|  | 112 | for (int j = 0; j < num_layers; j++) { | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 113 | hwc_layer_1_t *layer = &display_contents[i]->hwLayers[j]; | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 114 |  | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 115 | if (!ctx->use_framebuffer_target) { | 
|  | 116 | if (layer->compositionType == HWC_FRAMEBUFFER) | 
|  | 117 | layer->compositionType = HWC_OVERLAY; | 
|  | 118 | } else { | 
|  | 119 | switch (layer->compositionType) { | 
|  | 120 | case HWC_OVERLAY: | 
|  | 121 | case HWC_BACKGROUND: | 
|  | 122 | case HWC_SIDEBAND: | 
|  | 123 | case HWC_CURSOR_OVERLAY: | 
|  | 124 | layer->compositionType = HWC_FRAMEBUFFER; | 
|  | 125 | break; | 
|  | 126 | } | 
|  | 127 | } | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 128 | } | 
|  | 129 | } | 
| Sean Paul | dffca95 | 2015-02-04 10:19:55 -0800 | [diff] [blame] | 130 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 131 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 134 | static void hwc_set_cleanup(size_t num_displays, | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 135 | hwc_display_contents_1_t **display_contents) { | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 136 | for (int i = 0; i < (int)num_displays; ++i) { | 
|  | 137 | if (!display_contents[i]) | 
|  | 138 | continue; | 
|  | 139 |  | 
|  | 140 | hwc_display_contents_1_t *dc = display_contents[i]; | 
|  | 141 | for (size_t j = 0; j < dc->numHwLayers; ++j) { | 
|  | 142 | hwc_layer_1_t *layer = &dc->hwLayers[j]; | 
|  | 143 | if (layer->acquireFenceFd >= 0) { | 
|  | 144 | close(layer->acquireFenceFd); | 
|  | 145 | layer->acquireFenceFd = -1; | 
|  | 146 | } | 
|  | 147 | } | 
|  | 148 | if (dc->outbufAcquireFenceFd >= 0) { | 
|  | 149 | close(dc->outbufAcquireFenceFd); | 
|  | 150 | dc->outbufAcquireFenceFd = -1; | 
|  | 151 | } | 
|  | 152 | } | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 155 | static void hwc_add_layer_to_retire_fence( | 
|  | 156 | hwc_layer_1_t *layer, hwc_display_contents_1_t *display_contents) { | 
| Sean Paul | 0420612 | 2015-07-16 15:59:24 -0400 | [diff] [blame] | 157 | if (layer->releaseFenceFd < 0) | 
|  | 158 | return; | 
|  | 159 |  | 
|  | 160 | if (display_contents->retireFenceFd >= 0) { | 
|  | 161 | int old_retire_fence = display_contents->retireFenceFd; | 
| Zach Reizner | c6520e4 | 2015-08-13 14:32:09 -0700 | [diff] [blame] | 162 | display_contents->retireFenceFd = | 
|  | 163 | sync_merge("dc_retire", old_retire_fence, layer->releaseFenceFd); | 
| Sean Paul | 0420612 | 2015-07-16 15:59:24 -0400 | [diff] [blame] | 164 | close(old_retire_fence); | 
|  | 165 | } else { | 
|  | 166 | display_contents->retireFenceFd = dup(layer->releaseFenceFd); | 
|  | 167 | } | 
|  | 168 | } | 
|  | 169 |  | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 170 | static int hwc_set(hwc_composer_device_1_t *dev, size_t num_displays, | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 171 | hwc_display_contents_1_t **display_contents) { | 
| Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 172 | ATRACE_CALL(); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 173 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 174 | int ret; | 
|  | 175 | std::unique_ptr<DrmComposition> composition( | 
|  | 176 | ctx->drm.compositor()->CreateComposition(ctx->importer)); | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 177 | if (!composition) { | 
|  | 178 | ALOGE("Drm composition init failed"); | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 179 | hwc_set_cleanup(num_displays, display_contents); | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 180 | return -EINVAL; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 181 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 182 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 183 | std::vector<DrmCompositionDisplayLayersMap> layers_map; | 
|  | 184 | std::vector<std::vector<size_t>> layers_indices; | 
|  | 185 | layers_map.reserve(num_displays); | 
|  | 186 | layers_indices.reserve(num_displays); | 
|  | 187 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 188 | for (int i = 0; i < (int)num_displays; ++i) { | 
|  | 189 | if (!display_contents[i]) | 
|  | 190 | continue; | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 191 | hwc_display_contents_1_t *dc = display_contents[i]; | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 192 |  | 
|  | 193 | layers_map.emplace_back(); | 
|  | 194 | DrmCompositionDisplayLayersMap &map = layers_map[i]; | 
|  | 195 | map.display = i; | 
|  | 196 | map.layers = dc->hwLayers; | 
|  | 197 |  | 
|  | 198 | std::vector<size_t> indices_to_composite; | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 199 | unsigned num_dc_layers = dc->numHwLayers; | 
| Haixia Shi | 1034bb7 | 2015-09-09 12:08:20 -0700 | [diff] [blame] | 200 | int framebuffer_target_index = -1; | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 201 | for (int j = 0; j < (int)num_dc_layers; ++j) { | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 202 | hwc_layer_1_t *layer = &dc->hwLayers[j]; | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 203 | if (layer->flags & HWC_SKIP_LAYER) | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 204 | continue; | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 205 | if (!ctx->use_framebuffer_target) { | 
|  | 206 | if (layer->compositionType == HWC_OVERLAY) | 
|  | 207 | indices_to_composite.push_back(j); | 
| Haixia Shi | 1034bb7 | 2015-09-09 12:08:20 -0700 | [diff] [blame] | 208 | if (layer->compositionType == HWC_FRAMEBUFFER_TARGET) | 
|  | 209 | framebuffer_target_index = j; | 
| Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 210 | } else { | 
|  | 211 | if (layer->compositionType == HWC_FRAMEBUFFER_TARGET) | 
|  | 212 | indices_to_composite.push_back(j); | 
|  | 213 | } | 
|  | 214 | } | 
|  | 215 | if (ctx->use_framebuffer_target) { | 
|  | 216 | if (indices_to_composite.size() != 1) { | 
|  | 217 | ALOGE("Expected 1 (got %d) layer with HWC_FRAMEBUFFER_TARGET", | 
|  | 218 | indices_to_composite.size()); | 
|  | 219 | hwc_set_cleanup(num_displays, display_contents); | 
|  | 220 | return -EINVAL; | 
|  | 221 | } | 
| Haixia Shi | 1034bb7 | 2015-09-09 12:08:20 -0700 | [diff] [blame] | 222 | } else { | 
|  | 223 | if (indices_to_composite.empty() && framebuffer_target_index >= 0) { | 
|  | 224 | // Fall back to use HWC_FRAMEBUFFER_TARGET if all HWC_OVERLAY layers | 
|  | 225 | // are skipped. | 
|  | 226 | hwc_layer_1_t *layer = &dc->hwLayers[framebuffer_target_index]; | 
|  | 227 | if (!layer->handle || (layer->flags & HWC_SKIP_LAYER)) { | 
|  | 228 | ALOGE("Expected valid layer with HWC_FRAMEBUFFER_TARGET when all " | 
|  | 229 | "HWC_OVERLAY layers are skipped."); | 
|  | 230 | hwc_set_cleanup(num_displays, display_contents); | 
|  | 231 | return -EINVAL; | 
|  | 232 | } | 
|  | 233 | indices_to_composite.push_back(framebuffer_target_index); | 
|  | 234 | } | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 235 | } | 
|  | 236 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 237 | map.num_layers = indices_to_composite.size(); | 
|  | 238 | layers_indices.emplace_back(std::move(indices_to_composite)); | 
|  | 239 | map.layer_indices = layers_indices.back().data(); | 
|  | 240 | } | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 241 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 242 | ret = composition->SetLayers(layers_map.size(), layers_map.data()); | 
|  | 243 | if (ret) { | 
|  | 244 | hwc_set_cleanup(num_displays, display_contents); | 
|  | 245 | return -EINVAL; | 
|  | 246 | } | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 247 |  | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 248 | ret = ctx->drm.compositor()->QueueComposition(std::move(composition)); | 
|  | 249 | if (ret) { | 
|  | 250 | hwc_set_cleanup(num_displays, display_contents); | 
|  | 251 | return -EINVAL; | 
|  | 252 | } | 
|  | 253 |  | 
|  | 254 | composition.reset(NULL); | 
|  | 255 |  | 
|  | 256 | for (int i = 0; i < (int)num_displays; ++i) { | 
|  | 257 | if (!display_contents[i]) | 
|  | 258 | continue; | 
|  | 259 | hwc_display_contents_1_t *dc = display_contents[i]; | 
|  | 260 | unsigned num_dc_layers = dc->numHwLayers; | 
|  | 261 | for (int j = 0; j < (int)num_dc_layers; ++j) { | 
| Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 262 | hwc_layer_1_t *layer = &dc->hwLayers[j]; | 
|  | 263 | if (layer->flags & HWC_SKIP_LAYER) | 
|  | 264 | continue; | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 265 | if (layer->compositionType == HWC_OVERLAY) | 
|  | 266 | hwc_add_layer_to_retire_fence(layer, dc); | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 267 | } | 
|  | 268 | } | 
|  | 269 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 270 | if (ret) { | 
|  | 271 | ALOGE("Failed to queue the composition"); | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 272 | } | 
| Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 273 | hwc_set_cleanup(num_displays, display_contents); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 274 | return ret; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 275 | } | 
|  | 276 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 277 | static int hwc_event_control(struct hwc_composer_device_1 *dev, int display, | 
|  | 278 | int event, int enabled) { | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 279 | if (event != HWC_EVENT_VSYNC || (enabled != 0 && enabled != 1)) | 
|  | 280 | return -EINVAL; | 
| Sean Paul | eb9e75c | 2015-01-25 23:31:30 -0500 | [diff] [blame] | 281 |  | 
| Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 282 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
|  | 283 | hwc_drm_display_t *hd = &ctx->displays[display]; | 
|  | 284 | return hd->vsync_worker.VSyncControl(enabled); | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 285 | } | 
|  | 286 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 287 | static int hwc_set_power_mode(struct hwc_composer_device_1 *dev, int display, | 
|  | 288 | int mode) { | 
|  | 289 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 290 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 291 | uint64_t dpmsValue = 0; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 292 | switch (mode) { | 
|  | 293 | case HWC_POWER_MODE_OFF: | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 294 | dpmsValue = DRM_MODE_DPMS_OFF; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 295 | break; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 296 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 297 | /* We can't support dozing right now, so go full on */ | 
|  | 298 | case HWC_POWER_MODE_DOZE: | 
|  | 299 | case HWC_POWER_MODE_DOZE_SUSPEND: | 
|  | 300 | case HWC_POWER_MODE_NORMAL: | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 301 | dpmsValue = DRM_MODE_DPMS_ON; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 302 | break; | 
|  | 303 | }; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 304 | return ctx->drm.SetDpmsMode(display, dpmsValue); | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 305 | } | 
|  | 306 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 307 | static int hwc_query(struct hwc_composer_device_1 * /* dev */, int what, | 
|  | 308 | int *value) { | 
|  | 309 | switch (what) { | 
|  | 310 | case HWC_BACKGROUND_LAYER_SUPPORTED: | 
|  | 311 | *value = 0; /* TODO: We should do this */ | 
|  | 312 | break; | 
|  | 313 | case HWC_VSYNC_PERIOD: | 
|  | 314 | ALOGW("Query for deprecated vsync value, returning 60Hz"); | 
|  | 315 | *value = 1000 * 1000 * 1000 / 60; | 
|  | 316 | break; | 
|  | 317 | case HWC_DISPLAY_TYPES_SUPPORTED: | 
|  | 318 | *value = HWC_DISPLAY_PRIMARY | HWC_DISPLAY_EXTERNAL; | 
|  | 319 | break; | 
|  | 320 | } | 
|  | 321 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 322 | } | 
|  | 323 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 324 | static void hwc_register_procs(struct hwc_composer_device_1 *dev, | 
|  | 325 | hwc_procs_t const *procs) { | 
|  | 326 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 327 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 328 | ctx->procs = procs; | 
| Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 329 |  | 
|  | 330 | for (hwc_context_t::DisplayMapIter iter = ctx->displays.begin(); | 
|  | 331 | iter != ctx->displays.end(); ++iter) { | 
|  | 332 | iter->second.vsync_worker.SetProcs(procs); | 
|  | 333 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 334 | } | 
|  | 335 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 336 | static int hwc_get_display_configs(struct hwc_composer_device_1 *dev, | 
|  | 337 | int display, uint32_t *configs, | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 338 | size_t *num_configs) { | 
|  | 339 | if (!*num_configs) | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 340 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 341 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 342 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 343 | hwc_drm_display_t *hd = &ctx->displays[display]; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 344 | hd->config_ids.clear(); | 
|  | 345 |  | 
|  | 346 | DrmConnector *connector = ctx->drm.GetConnectorForDisplay(display); | 
|  | 347 | if (!connector) { | 
|  | 348 | ALOGE("Failed to get connector for display %d", display); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 349 | return -ENODEV; | 
|  | 350 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 351 |  | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 352 | int ret = connector->UpdateModes(); | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 353 | if (ret) { | 
|  | 354 | ALOGE("Failed to update display modes %d", ret); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 355 | return ret; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 356 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 357 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 358 | for (DrmConnector::ModeIter iter = connector->begin_modes(); | 
|  | 359 | iter != connector->end_modes(); ++iter) { | 
|  | 360 | size_t idx = hd->config_ids.size(); | 
|  | 361 | if (idx == *num_configs) | 
|  | 362 | break; | 
|  | 363 | hd->config_ids.push_back(iter->id()); | 
|  | 364 | configs[idx] = iter->id(); | 
|  | 365 | } | 
|  | 366 | *num_configs = hd->config_ids.size(); | 
|  | 367 | return *num_configs == 0 ? -1 : 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 368 | } | 
|  | 369 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 370 | static int hwc_get_display_attributes(struct hwc_composer_device_1 *dev, | 
|  | 371 | int display, uint32_t config, | 
|  | 372 | const uint32_t *attributes, | 
|  | 373 | int32_t *values) { | 
|  | 374 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 375 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 376 | if (!c) { | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 377 | ALOGE("Failed to get DrmConnector for display %d", display); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 378 | return -ENODEV; | 
|  | 379 | } | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 380 | DrmMode mode; | 
|  | 381 | for (DrmConnector::ModeIter iter = c->begin_modes(); iter != c->end_modes(); | 
|  | 382 | ++iter) { | 
|  | 383 | if (iter->id() == config) { | 
|  | 384 | mode = *iter; | 
|  | 385 | break; | 
|  | 386 | } | 
|  | 387 | } | 
|  | 388 | if (mode.id() == 0) { | 
|  | 389 | ALOGE("Failed to find active mode for display %d", display); | 
|  | 390 | return -ENOENT; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 391 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 392 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 393 | uint32_t mm_width = c->mm_width(); | 
|  | 394 | uint32_t mm_height = c->mm_height(); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 395 | for (int i = 0; attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; ++i) { | 
|  | 396 | switch (attributes[i]) { | 
|  | 397 | case HWC_DISPLAY_VSYNC_PERIOD: | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 398 | values[i] = 1000 * 1000 * 1000 / mode.v_refresh(); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 399 | break; | 
|  | 400 | case HWC_DISPLAY_WIDTH: | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 401 | values[i] = mode.h_display(); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 402 | break; | 
|  | 403 | case HWC_DISPLAY_HEIGHT: | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 404 | values[i] = mode.v_display(); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 405 | break; | 
|  | 406 | case HWC_DISPLAY_DPI_X: | 
|  | 407 | /* Dots per 1000 inches */ | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 408 | values[i] = mm_width ? (mode.h_display() * UM_PER_INCH) / mm_width : 0; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 409 | break; | 
|  | 410 | case HWC_DISPLAY_DPI_Y: | 
|  | 411 | /* Dots per 1000 inches */ | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 412 | values[i] = | 
|  | 413 | mm_height ? (mode.v_display() * UM_PER_INCH) / mm_height : 0; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 414 | break; | 
|  | 415 | } | 
|  | 416 | } | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 417 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 420 | static int hwc_get_active_config(struct hwc_composer_device_1 *dev, | 
|  | 421 | int display) { | 
|  | 422 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 423 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); | 
|  | 424 | if (!c) { | 
|  | 425 | ALOGE("Failed to get DrmConnector for display %d", display); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 426 | return -ENODEV; | 
|  | 427 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 428 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 429 | DrmMode mode = c->active_mode(); | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 430 | hwc_drm_display_t *hd = &ctx->displays[display]; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 431 | for (size_t i = 0; i < hd->config_ids.size(); ++i) { | 
|  | 432 | if (hd->config_ids[i] == mode.id()) | 
|  | 433 | return i; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 434 | } | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 435 | return -1; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 436 | } | 
|  | 437 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 438 | static int hwc_set_active_config(struct hwc_composer_device_1 *dev, int display, | 
|  | 439 | int index) { | 
|  | 440 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 441 | hwc_drm_display_t *hd = &ctx->displays[display]; | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 442 | if (index >= (int)hd->config_ids.size()) { | 
|  | 443 | ALOGE("Invalid config index %d passed in", index); | 
|  | 444 | return -EINVAL; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 445 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 446 |  | 
| Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 447 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); | 
|  | 448 | if (!c) { | 
|  | 449 | ALOGE("Failed to get connector for display %d", display); | 
|  | 450 | return -ENODEV; | 
|  | 451 | } | 
|  | 452 | DrmMode mode; | 
|  | 453 | for (DrmConnector::ModeIter iter = c->begin_modes(); iter != c->end_modes(); | 
|  | 454 | ++iter) { | 
|  | 455 | if (iter->id() == hd->config_ids[index]) { | 
|  | 456 | mode = *iter; | 
|  | 457 | break; | 
|  | 458 | } | 
|  | 459 | } | 
|  | 460 | if (mode.id() != hd->config_ids[index]) { | 
|  | 461 | ALOGE("Could not find active mode for %d/%d", index, hd->config_ids[index]); | 
|  | 462 | return -ENOENT; | 
|  | 463 | } | 
|  | 464 | int ret = ctx->drm.SetDisplayActiveMode(display, mode); | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 465 | if (ret) { | 
| Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 466 | ALOGE("Failed to set active config %d", ret); | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 467 | return ret; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 468 | } | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 469 | return ret; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 470 | } | 
|  | 471 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 472 | static int hwc_device_close(struct hw_device_t *dev) { | 
|  | 473 | struct hwc_context_t *ctx = (struct hwc_context_t *)dev; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 474 | delete ctx; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 475 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 476 | } | 
|  | 477 |  | 
| Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 478 | /* | 
|  | 479 | * TODO: This function sets the active config to the first one in the list. This | 
|  | 480 | * should be fixed such that it selects the preferred mode for the display, or | 
|  | 481 | * some other, saner, method of choosing the config. | 
|  | 482 | */ | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 483 | static int hwc_set_initial_config(hwc_drm_display_t *hd) { | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 484 | uint32_t config; | 
|  | 485 | size_t num_configs = 1; | 
|  | 486 | int ret = hwc_get_display_configs(&hd->ctx->device, hd->display, &config, | 
|  | 487 | &num_configs); | 
|  | 488 | if (ret || !num_configs) | 
|  | 489 | return 0; | 
| Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 490 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 491 | ret = hwc_set_active_config(&hd->ctx->device, hd->display, 0); | 
|  | 492 | if (ret) { | 
|  | 493 | ALOGE("Failed to set active config d=%d ret=%d", hd->display, ret); | 
|  | 494 | return ret; | 
|  | 495 | } | 
| Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 496 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 497 | return ret; | 
| Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 498 | } | 
|  | 499 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 500 | static int hwc_initialize_display(struct hwc_context_t *ctx, int display) { | 
| Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 501 | hwc_drm_display_t *hd = &ctx->displays[display]; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 502 | hd->ctx = ctx; | 
|  | 503 | hd->display = display; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 504 |  | 
| Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 505 | int ret = hwc_set_initial_config(hd); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 506 | if (ret) { | 
|  | 507 | ALOGE("Failed to set initial config for d=%d ret=%d", display, ret); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 508 | return ret; | 
|  | 509 | } | 
| Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 510 |  | 
| Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 511 | ret = hd->vsync_worker.Init(&ctx->drm, display); | 
|  | 512 | if (ret) { | 
|  | 513 | ALOGE("Failed to create event worker for display %d %d\n", display, ret); | 
|  | 514 | return ret; | 
|  | 515 | } | 
|  | 516 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 517 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 518 | } | 
|  | 519 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 520 | static int hwc_enumerate_displays(struct hwc_context_t *ctx) { | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 521 | int ret; | 
|  | 522 | for (DrmResources::ConnectorIter c = ctx->drm.begin_connectors(); | 
|  | 523 | c != ctx->drm.end_connectors(); ++c) { | 
|  | 524 | ret = hwc_initialize_display(ctx, (*c)->display()); | 
|  | 525 | if (ret) { | 
|  | 526 | ALOGE("Failed to initialize display %d", (*c)->display()); | 
|  | 527 | return ret; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 528 | } | 
|  | 529 | } | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 530 |  | 
|  | 531 | return 0; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 532 | } | 
|  | 533 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 534 | static int hwc_device_open(const struct hw_module_t *module, const char *name, | 
|  | 535 | struct hw_device_t **dev) { | 
|  | 536 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) { | 
|  | 537 | ALOGE("Invalid module name- %s", name); | 
|  | 538 | return -EINVAL; | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 | struct hwc_context_t *ctx = new hwc_context_t(); | 
|  | 542 | if (!ctx) { | 
|  | 543 | ALOGE("Failed to allocate hwc context"); | 
|  | 544 | return -ENOMEM; | 
|  | 545 | } | 
|  | 546 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 547 | int ret = ctx->drm.Init(); | 
|  | 548 | if (ret) { | 
|  | 549 | ALOGE("Can't initialize Drm object %d", ret); | 
|  | 550 | delete ctx; | 
|  | 551 | return ret; | 
|  | 552 | } | 
|  | 553 |  | 
| Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 554 | ctx->importer = Importer::CreateInstance(&ctx->drm); | 
|  | 555 | if (!ctx->importer) { | 
|  | 556 | ALOGE("Failed to create importer instance"); | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 557 | delete ctx; | 
|  | 558 | return ret; | 
|  | 559 | } | 
|  | 560 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 561 | ret = hwc_enumerate_displays(ctx); | 
|  | 562 | if (ret) { | 
|  | 563 | ALOGE("Failed to enumerate displays: %s", strerror(ret)); | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 564 | delete ctx; | 
|  | 565 | return ret; | 
|  | 566 | } | 
|  | 567 |  | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 568 | ctx->device.common.tag = HARDWARE_DEVICE_TAG; | 
|  | 569 | ctx->device.common.version = HWC_DEVICE_API_VERSION_1_4; | 
|  | 570 | ctx->device.common.module = const_cast<hw_module_t *>(module); | 
|  | 571 | ctx->device.common.close = hwc_device_close; | 
|  | 572 |  | 
| Sean Paul | 9046c64 | 2015-06-10 17:27:47 -0400 | [diff] [blame] | 573 | ctx->device.dump = hwc_dump; | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 574 | ctx->device.prepare = hwc_prepare; | 
|  | 575 | ctx->device.set = hwc_set; | 
|  | 576 | ctx->device.eventControl = hwc_event_control; | 
|  | 577 | ctx->device.setPowerMode = hwc_set_power_mode; | 
|  | 578 | ctx->device.query = hwc_query; | 
|  | 579 | ctx->device.registerProcs = hwc_register_procs; | 
|  | 580 | ctx->device.getDisplayConfigs = hwc_get_display_configs; | 
|  | 581 | ctx->device.getDisplayAttributes = hwc_get_display_attributes; | 
|  | 582 | ctx->device.getActiveConfig = hwc_get_active_config; | 
|  | 583 | ctx->device.setActiveConfig = hwc_set_active_config; | 
|  | 584 | ctx->device.setCursorPositionAsync = NULL; /* TODO: Add cursor */ | 
|  | 585 |  | 
|  | 586 | *dev = &ctx->device.common; | 
|  | 587 |  | 
|  | 588 | return 0; | 
|  | 589 | } | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 590 | } | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 591 |  | 
| Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 592 | static struct hw_module_methods_t hwc_module_methods = { | 
|  | 593 | open : android::hwc_device_open | 
|  | 594 | }; | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 595 |  | 
|  | 596 | hwc_module_t HAL_MODULE_INFO_SYM = { | 
| Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 597 | common : { | 
|  | 598 | tag : HARDWARE_MODULE_TAG, | 
|  | 599 | version_major : 1, | 
|  | 600 | version_minor : 0, | 
|  | 601 | id : HWC_HARDWARE_MODULE_ID, | 
|  | 602 | name : "DRM hwcomposer module", | 
|  | 603 | author : "The Android Open Source Project", | 
|  | 604 | methods : &hwc_module_methods, | 
|  | 605 | dso : NULL, | 
|  | 606 | reserved : {0}, | 
|  | 607 | } | 
| Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 608 | }; |