blob: dd890a975ce154f8202ae096a5f4ea36493bd577 [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 Ahmed72cf9762012-07-21 12:17:13 -070018#include <overlay.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070019#include "hwc_utils.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070020#include "mdp_version.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070021#include "hwc_video.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include "hwc_qbuf.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070023#include "hwc_copybit.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070024#include "hwc_external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070025#include "hwc_mdpcomp.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026
Naseer Ahmed29a26812012-06-14 00:56:20 -070027namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070028
29// Opens Framebuffer device
30static void openFramebufferDevice(hwc_context_t *ctx)
31{
32 hw_module_t const *module;
33 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
34 framebuffer_open(module, &(ctx->mFbDev));
35 }
36}
37
Naseer Ahmed29a26812012-06-14 00:56:20 -070038void initContext(hwc_context_t *ctx)
39{
Naseer Ahmed72cf9762012-07-21 12:17:13 -070040 openFramebufferDevice(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070041 ctx->mOverlay = overlay::Overlay::getInstance();
42 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmed96c4c952012-07-25 18:27:14 -070043 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
44 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
45 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070046 ctx->mCopybitEngine = CopybitEngine::getInstance();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070047 ctx->mExtDisplay = new ExternalDisplay(ctx);
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070049
50 init_uevent_thread(ctx);
51
52 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -070053 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -070054}
55
56void closeContext(hwc_context_t *ctx)
57{
58 if(ctx->mOverlay) {
59 delete ctx->mOverlay;
60 ctx->mOverlay = NULL;
61 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070062
Naseer Ahmed31da0b12012-07-31 18:55:33 -070063 if(ctx->mCopybitEngine) {
64 delete ctx->mCopybitEngine;
65 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070066 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070067
68 if(ctx->mFbDev) {
69 framebuffer_close(ctx->mFbDev);
70 ctx->mFbDev = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070071 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070072
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 if(ctx->qbuf) {
74 delete ctx->qbuf;
75 ctx->qbuf = NULL;
76 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070077
78 if(ctx->mExtDisplay) {
79 delete ctx->mExtDisplay;
80 ctx->mExtDisplay = NULL;
81 }
82
83
84 free(const_cast<hwc_methods_t *>(ctx->device.methods));
85
Naseer Ahmed29a26812012-06-14 00:56:20 -070086}
87
88void dumpLayer(hwc_layer_t const* l)
89{
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
103void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
104{
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 Ahmedf48aef62012-07-20 09:05:53 -0700110
111 for (size_t i = 0; i < list->numHwLayers; i++) {
112 private_handle_t *hnd =
113 (private_handle_t *)list->hwLayers[i].handle;
114
Naseer Ahmed29a26812012-06-14 00:56:20 -0700115 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700116 yuvCount++;
117 yuvLayerIndex = i;
118 //Animating
119 if (isSkipLayer(&list->hwLayers[i])) {
120 isYuvLayerSkip = true;
121 }
122 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
123 //If video layer is below a skip layer
124 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
125 isYuvLayerSkip = true;
126 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700127 skipCount++;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700128 }
129 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700130
131 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700132 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700133 MDPComp::setStats(skipCount);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135 ctx->numHwLayers = list->numHwLayers;
136 return;
137}
138
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700139//Crops source buffer against destination and FB boundaries
140void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
141 const int fbWidth, const int fbHeight) {
142
143 int& crop_x = crop.left;
144 int& crop_y = crop.top;
145 int& crop_r = crop.right;
146 int& crop_b = crop.bottom;
147 int crop_w = crop.right - crop.left;
148 int crop_h = crop.bottom - crop.top;
149
150 int& dst_x = dst.left;
151 int& dst_y = dst.top;
152 int& dst_r = dst.right;
153 int& dst_b = dst.bottom;
154 int dst_w = dst.right - dst.left;
155 int dst_h = dst.bottom - dst.top;
156
157 if(dst_x < 0) {
158 float scale_x = crop_w * 1.0f / dst_w;
159 float diff_factor = (scale_x * abs(dst_x));
160 crop_x = crop_x + (int)diff_factor;
161 crop_w = crop_r - crop_x;
162
163 dst_x = 0;
164 dst_w = dst_r - dst_x;;
165 }
166 if(dst_r > fbWidth) {
167 float scale_x = crop_w * 1.0f / dst_w;
168 float diff_factor = scale_x * (dst_r - fbWidth);
169 crop_r = crop_r - diff_factor;
170 crop_w = crop_r - crop_x;
171
172 dst_r = fbWidth;
173 dst_w = dst_r - dst_x;
174 }
175 if(dst_y < 0) {
176 float scale_y = crop_h * 1.0f / dst_h;
177 float diff_factor = scale_y * abs(dst_y);
178 crop_y = crop_y + diff_factor;
179 crop_h = crop_b - crop_y;
180
181 dst_y = 0;
182 dst_h = dst_b - dst_y;
183 }
184 if(dst_b > fbHeight) {
185 float scale_y = crop_h * 1.0f / dst_h;
186 float diff_factor = scale_y * (dst_b - fbHeight);
187 crop_b = crop_b - diff_factor;
188 crop_h = crop_b - crop_y;
189
190 dst_b = fbHeight;
191 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192 }
193}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700194
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195};//namespace