blob: ee7c25d7f5727cf9327a07d0e294fdf8100302a3 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08003 * Copyright (C) 2012-2013, The Linux Foundation All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080020#define HWC_UTILS_DEBUG 0
Naseer Ahmed758bfc52012-11-28 17:02:08 -050021#include <sys/ioctl.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070022#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070023#include <cutils/properties.h>
24#include <gralloc_priv.h>
25#include <fb_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050026#include <overlay.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070027#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050028#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080029#include "hwc_fbupdate.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070030#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080031#include "hwc_copybit.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070032#include "external.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070033#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080034#include "comptype.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070035namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070036
37// Opens Framebuffer device
38static void openFramebufferDevice(hwc_context_t *ctx)
39{
40 hw_module_t const *module;
41 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
42 framebuffer_open(module, &(ctx->mFbDev));
Saurabh Shah3e858eb2012-09-17 16:53:21 -070043 private_module_t* m = reinterpret_cast<private_module_t*>(
44 ctx->mFbDev->common.module);
45 //xres, yres may not be 32 aligned
Naseer Ahmed54821fe2012-11-28 18:44:38 -050046 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = m->finfo.line_length /
47 (m->info.xres/8);
Saurabh Shah3e858eb2012-09-17 16:53:21 -070048 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = m->info.xres;
49 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = m->info.yres;
50 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = ctx->mFbDev->xdpi;
51 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ctx->mFbDev->ydpi;
52 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
53 1000000000l / ctx->mFbDev->fps;
54 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = openFb(HWC_DISPLAY_PRIMARY);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070055 }
56}
57
Naseer Ahmed29a26812012-06-14 00:56:20 -070058void initContext(hwc_context_t *ctx)
59{
Naseer Ahmed72cf9762012-07-21 12:17:13 -070060 openFramebufferDevice(ctx);
Saurabh Shahc4d034f2012-09-27 15:55:15 -070061 overlay::Overlay::initOverlay();
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah56f610d2012-08-07 15:27:06 -070063 ctx->mQService = qService::QService::getInstance(ctx);
Naseer Ahmed96c4c952012-07-25 18:27:14 -070064 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
65 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
66 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Saurabh Shahcf053c62012-12-13 12:32:55 -080067 //Is created and destroyed only once for primary
68 //For external it could get created and destroyed multiple times depending
69 //on what external we connect to.
70 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
71 IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
72 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080073
74 char value[PROPERTY_VALUE_MAX];
75 // Check if the target supports copybit compostion (dyn/mdp/c2d) to
76 // decide if we need to open the copybit module.
77 int compositionType =
78 qdutils::QCCompositionType::getInstance().getCompositionType();
79
80 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
81 qdutils::COMPOSITION_TYPE_MDP |
82 qdutils::COMPOSITION_TYPE_C2D)) {
83 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit();
84 }
85
Naseer Ahmed72cf9762012-07-21 12:17:13 -070086 ctx->mExtDisplay = new ExternalDisplay(ctx);
Naseer Ahmede78f0522012-12-07 18:24:28 -050087 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++)
88 ctx->mLayerCache[i] = new LayerCache();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080089 ctx->mMDPComp = MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres);
Naseer Ahmed54821fe2012-11-28 18:44:38 -050090 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070091
Naseer Ahmedff4f0252012-10-01 13:03:01 -040092 pthread_mutex_init(&(ctx->vstate.lock), NULL);
93 pthread_cond_init(&(ctx->vstate.cond), NULL);
94 ctx->vstate.enable = false;
Amara Venkata Mastan Manoj Kumar75526f52012-12-27 18:27:01 -080095 ctx->mExtDispConfiguring = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070096 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -070097 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -070098}
99
100void closeContext(hwc_context_t *ctx)
101{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500102 if(ctx->mOverlay) {
103 delete ctx->mOverlay;
104 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800107 for(int i = 0; i< HWC_NUM_DISPLAY_TYPES; i++) {
108 if(ctx->mCopyBit[i]) {
109 delete ctx->mCopyBit[i];
110 ctx->mCopyBit[i] = NULL;
111 }
112 }
113
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700114 if(ctx->mFbDev) {
115 framebuffer_close(ctx->mFbDev);
116 ctx->mFbDev = NULL;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700117 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
118 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700120
121 if(ctx->mExtDisplay) {
122 delete ctx->mExtDisplay;
123 ctx->mExtDisplay = NULL;
124 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400125
Saurabh Shahcf053c62012-12-13 12:32:55 -0800126 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
127 if(ctx->mFBUpdate[i]) {
128 delete ctx->mFBUpdate[i];
129 ctx->mFBUpdate[i] = NULL;
130 }
131 }
132
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800133 if(ctx->mMDPComp) {
134 delete ctx->mMDPComp;
135 ctx->mMDPComp = NULL;
136 }
137
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400138 pthread_mutex_destroy(&(ctx->vstate.lock));
139 pthread_cond_destroy(&(ctx->vstate.cond));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700140}
141
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500142
143void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700144{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500145 va_list varargs;
146 va_start(varargs, fmt);
147 buf.appendFormatV(fmt, varargs);
148 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149}
150
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800151/* Calculates the destination position based on the action safe rectangle */
152void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
153 uint32_t& y, uint32_t& w, uint32_t& h) {
154
155 // if external supports underscan, do nothing
156 // it will be taken care in the driver
157 if(ctx->mExtDisplay->isCEUnderscanSupported())
158 return;
159
160 float wRatio = 1.0;
161 float hRatio = 1.0;
162 float xRatio = 1.0;
163 float yRatio = 1.0;
164
165 float fbWidth = ctx->dpyAttr[dpy].xres;
166 float fbHeight = ctx->dpyAttr[dpy].yres;
167
168 float asX = 0;
169 float asY = 0;
170 float asW = fbWidth;
171 float asH= fbHeight;
172 char value[PROPERTY_VALUE_MAX];
173
174 // Apply action safe parameters
175 property_get("hw.actionsafe.width", value, "0");
176 int asWidthRatio = atoi(value);
177 property_get("hw.actionsafe.height", value, "0");
178 int asHeightRatio = atoi(value);
179 // based on the action safe ratio, get the Action safe rectangle
180 asW = fbWidth * (1.0f - asWidthRatio / 100.0f);
181 asH = fbHeight * (1.0f - asHeightRatio / 100.0f);
182 asX = (fbWidth - asW) / 2;
183 asY = (fbHeight - asH) / 2;
184
185 // calculate the position ratio
186 xRatio = (float)x/fbWidth;
187 yRatio = (float)y/fbHeight;
188 wRatio = (float)w/fbWidth;
189 hRatio = (float)h/fbHeight;
190
191 //Calculate the position...
192 x = (xRatio * asW) + asX;
193 y = (yRatio * asH) + asY;
194 w = (wRatio * asW);
195 h = (hRatio * asH);
196
197 return;
198}
199
Naseer Ahmed018e5452012-12-03 14:46:15 -0500200static inline bool isAlphaScaled(hwc_layer_1_t const* layer) {
201 int dst_w, dst_h, src_w, src_h;
202
203 hwc_rect_t displayFrame = layer->displayFrame;
204 hwc_rect_t sourceCrop = layer->sourceCrop;
205
206 dst_w = displayFrame.right - displayFrame.left;
207 dst_h = displayFrame.bottom - displayFrame.top;
208
209 src_w = sourceCrop.right - sourceCrop.left;
210 src_h = sourceCrop.bottom - sourceCrop.top;
211
212 if(((src_w != dst_w) || (src_h != dst_h))) {
213 if(layer->blending != HWC_BLENDING_NONE)
214 return true;
215 }
216 return false;
217}
218
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700219void setListStats(hwc_context_t *ctx,
220 const hwc_display_contents_1_t *list, int dpy) {
221
222 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
223 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700224 ctx->listStats[dpy].skipCount = 0;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500225 ctx->listStats[dpy].needsAlphaScale = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800226 ctx->listStats[dpy].yuvCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700227
228 for (size_t i = 0; i < list->numHwLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500229 hwc_layer_1_t const* layer = &list->hwLayers[i];
230 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700231
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800232 //reset stored yuv index
233 ctx->listStats[dpy].yuvIndices[i] = -1;
234
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700235 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
236 continue;
237 //We disregard FB being skip for now! so the else if
Saurabh Shah35712cb2012-09-14 10:28:18 -0700238 } else if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700239 ctx->listStats[dpy].skipCount++;
240 }
241
Naseer Ahmed018e5452012-12-03 14:46:15 -0500242 if(!ctx->listStats[dpy].needsAlphaScale)
243 ctx->listStats[dpy].needsAlphaScale = isAlphaScaled(layer);
244
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700245 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800246 int& yuvCount = ctx->listStats[dpy].yuvCount;
247 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
248 yuvCount++;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700249 }
250 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251}
252
Naseer Ahmed018e5452012-12-03 14:46:15 -0500253
Saurabh Shah541b59d2012-10-11 11:08:12 -0700254static inline void calc_cut(float& leftCutRatio, float& topCutRatio,
255 float& rightCutRatio, float& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700256 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700257 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700258 }
259 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700260 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700261 }
262 if(orient & HAL_TRANSFORM_ROT_90) {
263 //Anti clock swapping
Saurabh Shah541b59d2012-10-11 11:08:12 -0700264 float tmpCutRatio = leftCutRatio;
265 leftCutRatio = topCutRatio;
266 topCutRatio = rightCutRatio;
267 rightCutRatio = bottomCutRatio;
268 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700269 }
270}
271
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500272bool isSecuring(hwc_context_t* ctx) {
273 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
274 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
275 ctx->mSecuring) {
276 return true;
277 }
278 return false;
279}
280
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800281bool isSecureModePolicy(int mdpVersion) {
282 if (mdpVersion < qdutils::MDSS_V5)
283 return true;
284 else
285 return false;
286}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500287
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700288//Crops source buffer against destination and FB boundaries
289void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Saurabh Shah27c1d652012-08-14 19:30:28 -0700290 const int fbWidth, const int fbHeight, int orient) {
291 int& crop_l = crop.left;
292 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700293 int& crop_r = crop.right;
294 int& crop_b = crop.bottom;
295 int crop_w = crop.right - crop.left;
296 int crop_h = crop.bottom - crop.top;
297
Saurabh Shah27c1d652012-08-14 19:30:28 -0700298 int& dst_l = dst.left;
299 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700300 int& dst_r = dst.right;
301 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700302 int dst_w = abs(dst.right - dst.left);
303 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700304
Saurabh Shah541b59d2012-10-11 11:08:12 -0700305 float leftCutRatio = 0.0f, rightCutRatio = 0.0f, topCutRatio = 0.0f,
306 bottomCutRatio = 0.0f;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700307
Saurabh Shah27c1d652012-08-14 19:30:28 -0700308 if(dst_l < 0) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700309 leftCutRatio = (float)(0.0f - dst_l) / (float)dst_w;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700310 dst_l = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700311 }
312 if(dst_r > fbWidth) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700313 rightCutRatio = (float)(dst_r - fbWidth) / (float)dst_w;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700314 dst_r = fbWidth;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700315 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700316 if(dst_t < 0) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700317 topCutRatio = (float)(0 - dst_t) / (float)dst_h;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700318 dst_t = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700319 }
320 if(dst_b > fbHeight) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700321 bottomCutRatio = (float)(dst_b - fbHeight) / (float)dst_h;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700322 dst_b = fbHeight;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700324
Saurabh Shah541b59d2012-10-11 11:08:12 -0700325 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
326 crop_l += crop_w * leftCutRatio;
327 crop_t += crop_h * topCutRatio;
328 crop_r -= crop_w * rightCutRatio;
329 crop_b -= crop_h * bottomCutRatio;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700331
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700332bool isExternalActive(hwc_context_t* ctx) {
333 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700334}
335
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800336int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
337 int fd) {
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700338 int ret = 0;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700339 struct mdp_buf_sync data;
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400340 int acquireFd[MAX_NUM_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700341 int count = 0;
342 int releaseFd = -1;
343 int fbFd = -1;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800344 memset(&data, 0, sizeof(data));
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500345 bool swapzero = false;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700346 data.flags = MDP_BUF_SYNC_FLAG_WAIT;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700347 data.acq_fen_fd = acquireFd;
348 data.rel_fen_fd = &releaseFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500349 char property[PROPERTY_VALUE_MAX];
350 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
351 if(atoi(property) == 0)
352 swapzero = true;
353 }
354
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700355 //Accumulate acquireFenceFds
356 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800357 if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
358 list->hwLayers[i].acquireFenceFd != -1) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500359 if(UNLIKELY(swapzero))
360 acquireFd[count++] = -1;
361 else
362 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700363 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800364 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
365 if(UNLIKELY(swapzero))
366 acquireFd[count++] = -1;
367 else if(fd != -1) {
368 //set the acquireFD from fd - which is coming from c2d
369 acquireFd[count++] = fd;
370 // Buffer sync IOCTL should be async when using c2d fence is
371 // used
372 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
373 } else if(list->hwLayers[i].acquireFenceFd != -1)
374 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
375 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700376 }
377
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700378 data.acq_fen_fd_cnt = count;
379 fbFd = ctx->dpyAttr[dpy].fd;
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700380 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800381 if(LIKELY(!swapzero)) {
382 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500383 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800384 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
385 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
386 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700387 if(ret < 0) {
388 ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s",
389 strerror(errno));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700390 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700391 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800392 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
393 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700394 //Close the acquireFenceFds
395 if(list->hwLayers[i].acquireFenceFd > 0) {
396 close(list->hwLayers[i].acquireFenceFd);
397 list->hwLayers[i].acquireFenceFd = -1;
398 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800399 if(fd > 0) {
400 close(fd);
401 fd = -1;
402 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700403 //Populate releaseFenceFds.
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500404 if(UNLIKELY(swapzero))
405 list->hwLayers[i].releaseFenceFd = -1;
406 else
407 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700408 }
409 }
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500410 if(UNLIKELY(swapzero)){
411 list->retireFenceFd = -1;
412 close(releaseFd);
413 } else {
414 list->retireFenceFd = releaseFd;
415 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700416 return ret;
417}
418
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400419void LayerCache::resetLayerCache(int num) {
420 for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) {
421 hnd[i] = NULL;
422 }
423 numHwLayers = num;
424}
425
426void LayerCache::updateLayerCache(hwc_display_contents_1_t* list) {
427
428 int numFbLayers = 0;
429 int numCacheableLayers = 0;
430
431 canUseLayerCache = false;
432 //Bail if geometry changed or num of layers changed
433 if(list->flags & HWC_GEOMETRY_CHANGED ||
434 list->numHwLayers != numHwLayers ) {
435 resetLayerCache(list->numHwLayers);
436 return;
437 }
438
439 for(uint32_t i = 0; i < list->numHwLayers; i++) {
440 //Bail on skip layers
441 if(list->hwLayers[i].flags & HWC_SKIP_LAYER) {
442 resetLayerCache(list->numHwLayers);
443 return;
444 }
445
446 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) {
447 numFbLayers++;
448 if(hnd[i] == NULL) {
449 hnd[i] = list->hwLayers[i].handle;
450 } else if (hnd[i] ==
451 list->hwLayers[i].handle) {
452 numCacheableLayers++;
453 } else {
454 hnd[i] = NULL;
455 return;
456 }
457 } else {
458 hnd[i] = NULL;
459 }
460 }
461 if(numFbLayers == numCacheableLayers)
462 canUseLayerCache = true;
463
464 //XXX: The marking part is separate, if MDP comp wants
465 // to use it in the future. Right now getting MDP comp
466 // to use this is more trouble than it is worth.
467 markCachedLayersAsOverlay(list);
468}
469
470void LayerCache::markCachedLayersAsOverlay(hwc_display_contents_1_t* list) {
471 //This optimization only works if ALL the layer handles
472 //that were on the framebuffer didn't change.
473 if(canUseLayerCache){
474 for(uint32_t i = 0; i < list->numHwLayers; i++) {
475 if (list->hwLayers[i].handle &&
476 list->hwLayers[i].handle == hnd[i] &&
477 list->hwLayers[i].compositionType != HWC_FRAMEBUFFER_TARGET)
478 {
479 list->hwLayers[i].compositionType = HWC_OVERLAY;
480 }
481 }
482 }
483
484}
485
Naseer Ahmed29a26812012-06-14 00:56:20 -0700486};//namespace