blob: a2ba499bb012917f6189194c4561e51a94cb6bd9 [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>
Naseer Ahmed29a26812012-06-14 00:56:20 -070020#include "hwc_utils.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070021#include "mdp_version.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070022#include "hwc_video.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070023#include "hwc_qbuf.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070024#include "hwc_copybit.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070025#include "hwc_external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070026#include "hwc_mdpcomp.h"
Naseer Ahmed4c588a22012-07-31 19:12:17 -070027#include "hwc_extonly.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070028
Naseer Ahmed29a26812012-06-14 00:56:20 -070029namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070030
31// Opens Framebuffer device
32static void openFramebufferDevice(hwc_context_t *ctx)
33{
34 hw_module_t const *module;
35 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
36 framebuffer_open(module, &(ctx->mFbDev));
37 }
38}
39
Naseer Ahmed29a26812012-06-14 00:56:20 -070040void initContext(hwc_context_t *ctx)
41{
Naseer Ahmed72cf9762012-07-21 12:17:13 -070042 openFramebufferDevice(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070043 ctx->mOverlay = overlay::Overlay::getInstance();
44 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmed96c4c952012-07-25 18:27:14 -070045 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
46 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
47 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070048 ctx->mCopybitEngine = CopybitEngine::getInstance();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070049 ctx->mExtDisplay = new ExternalDisplay(ctx);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070050 memset(ctx->dpys,(int)EGL_NO_DISPLAY, MAX_NUM_DISPLAYS);
Naseer Ahmed7c958d42012-07-31 18:57:03 -070051 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070052
53 init_uevent_thread(ctx);
54
55 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -070056 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -070057}
58
59void closeContext(hwc_context_t *ctx)
60{
61 if(ctx->mOverlay) {
62 delete ctx->mOverlay;
63 ctx->mOverlay = NULL;
64 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070065
Naseer Ahmed31da0b12012-07-31 18:55:33 -070066 if(ctx->mCopybitEngine) {
67 delete ctx->mCopybitEngine;
68 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070070
71 if(ctx->mFbDev) {
72 framebuffer_close(ctx->mFbDev);
73 ctx->mFbDev = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070074 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070075
Naseer Ahmed29a26812012-06-14 00:56:20 -070076 if(ctx->qbuf) {
77 delete ctx->qbuf;
78 ctx->qbuf = NULL;
79 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070080
81 if(ctx->mExtDisplay) {
82 delete ctx->mExtDisplay;
83 ctx->mExtDisplay = NULL;
84 }
85
86
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070087 free(const_cast<hwc_methods_1_t *>(ctx->device.methods));
Naseer Ahmed72cf9762012-07-21 12:17:13 -070088
Naseer Ahmed29a26812012-06-14 00:56:20 -070089}
90
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070091void dumpLayer(hwc_layer_1_t const* l)
Naseer Ahmed29a26812012-06-14 00:56:20 -070092{
93 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
94 ", {%d,%d,%d,%d}",
95 l->compositionType, l->flags, l->handle, l->transform, l->blending,
96 l->sourceCrop.left,
97 l->sourceCrop.top,
98 l->sourceCrop.right,
99 l->sourceCrop.bottom,
100 l->displayFrame.left,
101 l->displayFrame.top,
102 l->displayFrame.right,
103 l->displayFrame.bottom);
104}
105
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700106void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108 //Video specific stats
109 int yuvCount = 0;
110 int yuvLayerIndex = -1;
111 bool isYuvLayerSkip = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700112 int skipCount = 0;
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700113 int ccLayerIndex = -1; //closed caption
114 int extLayerIndex = -1; //ext-only or block except closed caption
115 int extCount = 0; //ext-only except closed caption
116 bool isExtBlockPresent = false; //is BLOCK layer present
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700117
118 for (size_t i = 0; i < list->numHwLayers; i++) {
119 private_handle_t *hnd =
120 (private_handle_t *)list->hwLayers[i].handle;
121
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700122 if (UNLIKELY(isYuvBuffer(hnd))) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700123 yuvCount++;
124 yuvLayerIndex = i;
125 //Animating
126 if (isSkipLayer(&list->hwLayers[i])) {
127 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) {
142 isYuvLayerSkip = true;
143 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700144 skipCount++;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145 }
146 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700147
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700148 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip,
149 ccLayerIndex);
150 ExtOnly::setStats(extCount, extLayerIndex, isExtBlockPresent);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700151 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700152 MDPComp::setStats(skipCount);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700153
Naseer Ahmed29a26812012-06-14 00:56:20 -0700154 ctx->numHwLayers = list->numHwLayers;
155 return;
156}
157
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158//Crops source buffer against destination and FB boundaries
159void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
160 const int fbWidth, const int fbHeight) {
161
162 int& crop_x = crop.left;
163 int& crop_y = crop.top;
164 int& crop_r = crop.right;
165 int& crop_b = crop.bottom;
166 int crop_w = crop.right - crop.left;
167 int crop_h = crop.bottom - crop.top;
168
169 int& dst_x = dst.left;
170 int& dst_y = dst.top;
171 int& dst_r = dst.right;
172 int& dst_b = dst.bottom;
173 int dst_w = dst.right - dst.left;
174 int dst_h = dst.bottom - dst.top;
175
176 if(dst_x < 0) {
177 float scale_x = crop_w * 1.0f / dst_w;
178 float diff_factor = (scale_x * abs(dst_x));
179 crop_x = crop_x + (int)diff_factor;
180 crop_w = crop_r - crop_x;
181
182 dst_x = 0;
183 dst_w = dst_r - dst_x;;
184 }
185 if(dst_r > fbWidth) {
186 float scale_x = crop_w * 1.0f / dst_w;
187 float diff_factor = scale_x * (dst_r - fbWidth);
188 crop_r = crop_r - diff_factor;
189 crop_w = crop_r - crop_x;
190
191 dst_r = fbWidth;
192 dst_w = dst_r - dst_x;
193 }
194 if(dst_y < 0) {
195 float scale_y = crop_h * 1.0f / dst_h;
196 float diff_factor = scale_y * abs(dst_y);
197 crop_y = crop_y + diff_factor;
198 crop_h = crop_b - crop_y;
199
200 dst_y = 0;
201 dst_h = dst_b - dst_y;
202 }
203 if(dst_b > fbHeight) {
204 float scale_y = crop_h * 1.0f / dst_h;
205 float diff_factor = scale_y * (dst_b - fbHeight);
206 crop_b = crop_b - diff_factor;
207 crop_h = crop_b - crop_y;
208
209 dst_b = fbHeight;
210 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211 }
212}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700213
Naseer Ahmed29a26812012-06-14 00:56:20 -0700214};//namespace