blob: 553068f4edc2563c94b45c3b93094b5d8ad9bcde [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070018#include <EGL/egl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070019#include <overlay.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070020#include <cutils/properties.h>
21#include <gralloc_priv.h>
22#include <fb_priv.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070023#include "hwc_utils.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070024#include "mdp_version.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070025#include "hwc_video.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include "hwc_qbuf.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070027#include "hwc_copybit.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070028#include "hwc_external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070029#include "hwc_mdpcomp.h"
Naseer Ahmed4c588a22012-07-31 19:12:17 -070030#include "hwc_extonly.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070031
Naseer Ahmed29a26812012-06-14 00:56:20 -070032namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070033
34// Opens Framebuffer device
35static void openFramebufferDevice(hwc_context_t *ctx)
36{
37 hw_module_t const *module;
38 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
39 framebuffer_open(module, &(ctx->mFbDev));
40 }
41}
42
Naseer Ahmed29a26812012-06-14 00:56:20 -070043void initContext(hwc_context_t *ctx)
44{
Naseer Ahmed72cf9762012-07-21 12:17:13 -070045 openFramebufferDevice(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070046 ctx->mOverlay = overlay::Overlay::getInstance();
47 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmed96c4c952012-07-25 18:27:14 -070048 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
49 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
50 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070051 ctx->mCopybitEngine = CopybitEngine::getInstance();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070052 ctx->mExtDisplay = new ExternalDisplay(ctx);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070053 memset(ctx->dpys,(int)EGL_NO_DISPLAY, MAX_NUM_DISPLAYS);
Naseer Ahmed7c958d42012-07-31 18:57:03 -070054 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070055
Naseer Ahmed72cf9762012-07-21 12:17:13 -070056 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -070057 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -070058}
59
60void closeContext(hwc_context_t *ctx)
61{
62 if(ctx->mOverlay) {
63 delete ctx->mOverlay;
64 ctx->mOverlay = NULL;
65 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066
Naseer Ahmed31da0b12012-07-31 18:55:33 -070067 if(ctx->mCopybitEngine) {
68 delete ctx->mCopybitEngine;
69 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070071
72 if(ctx->mFbDev) {
73 framebuffer_close(ctx->mFbDev);
74 ctx->mFbDev = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070075 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070076
Naseer Ahmed29a26812012-06-14 00:56:20 -070077 if(ctx->qbuf) {
78 delete ctx->qbuf;
79 ctx->qbuf = NULL;
80 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070081
82 if(ctx->mExtDisplay) {
83 delete ctx->mExtDisplay;
84 ctx->mExtDisplay = NULL;
85 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070086}
87
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070088void dumpLayer(hwc_layer_1_t const* l)
Naseer Ahmed29a26812012-06-14 00:56:20 -070089{
90 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
91 ", {%d,%d,%d,%d}",
92 l->compositionType, l->flags, l->handle, l->transform, l->blending,
93 l->sourceCrop.left,
94 l->sourceCrop.top,
95 l->sourceCrop.right,
96 l->sourceCrop.bottom,
97 l->displayFrame.left,
98 l->displayFrame.top,
99 l->displayFrame.right,
100 l->displayFrame.bottom);
101}
102
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700103void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105 //Video specific stats
106 int yuvCount = 0;
107 int yuvLayerIndex = -1;
108 bool isYuvLayerSkip = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700109 int skipCount = 0;
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700110 int ccLayerIndex = -1; //closed caption
111 int extLayerIndex = -1; //ext-only or block except closed caption
112 int extCount = 0; //ext-only except closed caption
113 bool isExtBlockPresent = false; //is BLOCK layer present
Saurabh Shahf395d092012-08-27 12:33:42 -0700114 bool yuvSecure = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115
116 for (size_t i = 0; i < list->numHwLayers; i++) {
117 private_handle_t *hnd =
118 (private_handle_t *)list->hwLayers[i].handle;
119
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700120 if (UNLIKELY(isYuvBuffer(hnd))) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121 yuvCount++;
122 yuvLayerIndex = i;
Saurabh Shahf395d092012-08-27 12:33:42 -0700123 yuvSecure = isSecureBuffer(hnd);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700124 //Animating
Saurabh Shahf395d092012-08-27 12:33:42 -0700125 //Do not mark as SKIP if it is secure buffer
126 if (isSkipLayer(&list->hwLayers[i]) && !yuvSecure) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127 isYuvLayerSkip = true;
128 }
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700129 } else if(UNLIKELY(isExtCC(hnd))) {
130 ccLayerIndex = i;
131 } else if(UNLIKELY(isExtBlock(hnd))) {
132 extCount++;
133 extLayerIndex = i;
134 isExtBlockPresent = true;
135 } else if(UNLIKELY(isExtOnly(hnd))) {
136 extCount++;
137 //If BLOCK layer present, dont cache index, display BLOCK only.
138 if(isExtBlockPresent == false) extLayerIndex = i;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
140 //If video layer is below a skip layer
141 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
Saurabh Shahf395d092012-08-27 12:33:42 -0700142 //Do not mark as SKIP if it is secure buffer
143 if (!yuvSecure) {
144 isYuvLayerSkip = true;
145 skipCount++;
146 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700147 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148 }
149 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700150
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700151 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip,
152 ccLayerIndex);
153 ExtOnly::setStats(extCount, extLayerIndex, isExtBlockPresent);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700154 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700155 MDPComp::setStats(skipCount);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156
Naseer Ahmed29a26812012-06-14 00:56:20 -0700157 ctx->numHwLayers = list->numHwLayers;
158 return;
159}
160
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161//Crops source buffer against destination and FB boundaries
162void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
163 const int fbWidth, const int fbHeight) {
164
165 int& crop_x = crop.left;
166 int& crop_y = crop.top;
167 int& crop_r = crop.right;
168 int& crop_b = crop.bottom;
169 int crop_w = crop.right - crop.left;
170 int crop_h = crop.bottom - crop.top;
171
172 int& dst_x = dst.left;
173 int& dst_y = dst.top;
174 int& dst_r = dst.right;
175 int& dst_b = dst.bottom;
176 int dst_w = dst.right - dst.left;
177 int dst_h = dst.bottom - dst.top;
178
179 if(dst_x < 0) {
180 float scale_x = crop_w * 1.0f / dst_w;
181 float diff_factor = (scale_x * abs(dst_x));
182 crop_x = crop_x + (int)diff_factor;
183 crop_w = crop_r - crop_x;
184
185 dst_x = 0;
186 dst_w = dst_r - dst_x;;
187 }
188 if(dst_r > fbWidth) {
189 float scale_x = crop_w * 1.0f / dst_w;
190 float diff_factor = scale_x * (dst_r - fbWidth);
191 crop_r = crop_r - diff_factor;
192 crop_w = crop_r - crop_x;
193
194 dst_r = fbWidth;
195 dst_w = dst_r - dst_x;
196 }
197 if(dst_y < 0) {
198 float scale_y = crop_h * 1.0f / dst_h;
199 float diff_factor = scale_y * abs(dst_y);
200 crop_y = crop_y + diff_factor;
201 crop_h = crop_b - crop_y;
202
203 dst_y = 0;
204 dst_h = dst_b - dst_y;
205 }
206 if(dst_b > fbHeight) {
207 float scale_y = crop_h * 1.0f / dst_h;
208 float diff_factor = scale_y * (dst_b - fbHeight);
209 crop_b = crop_b - diff_factor;
210 crop_h = crop_b - crop_y;
211
212 dst_b = fbHeight;
213 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214 }
215}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700216
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700217void wait4fbPost(hwc_context_t* ctx) {
218 framebuffer_device_t *fbDev = ctx->mFbDev;
219 if(fbDev) {
220 private_module_t* m = reinterpret_cast<private_module_t*>(
221 fbDev->common.module);
222 //wait for the fb_post to be called
223 pthread_mutex_lock(&m->fbPostLock);
224 while(m->fbPostDone == false) {
225 pthread_cond_wait(&(m->fbPostCond), &(m->fbPostLock));
226 }
227 m->fbPostDone = false;
228 pthread_mutex_unlock(&m->fbPostLock);
229 }
230}
231
232void wait4Pan(hwc_context_t* ctx) {
233 framebuffer_device_t *fbDev = ctx->mFbDev;
234 if(fbDev) {
235 private_module_t* m = reinterpret_cast<private_module_t*>(
236 fbDev->common.module);
237 //wait for the fb_post's PAN to finish
238 pthread_mutex_lock(&m->fbPanLock);
239 while(m->fbPanDone == false) {
240 pthread_cond_wait(&(m->fbPanCond), &(m->fbPanLock));
241 }
242 m->fbPanDone = false;
243 pthread_mutex_unlock(&m->fbPanLock);
244 }
245}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246};//namespace