blob: 0b62a98636d88f2579ae59648d51dc250d2e8bf4 [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 Ahmeda87da602012-07-01 23:54:19 -070043 ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
44 ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070045 ctx->mCopybitEngine = CopybitEngine::getInstance();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070046 ctx->mExtDisplay = new ExternalDisplay(ctx);
Naseer Ahmed7c958d42012-07-31 18:57:03 -070047 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070048
49 init_uevent_thread(ctx);
50
51 ALOGI("Initializing Qualcomm Hardware Composer");
52 ALOGI("MDP version: %d", ctx->mdpVersion);
Naseer Ahmed29a26812012-06-14 00:56:20 -070053}
54
55void closeContext(hwc_context_t *ctx)
56{
57 if(ctx->mOverlay) {
58 delete ctx->mOverlay;
59 ctx->mOverlay = NULL;
60 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070061
Naseer Ahmed31da0b12012-07-31 18:55:33 -070062 if(ctx->mCopybitEngine) {
63 delete ctx->mCopybitEngine;
64 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070066
67 if(ctx->mFbDev) {
68 framebuffer_close(ctx->mFbDev);
69 ctx->mFbDev = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070070 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070071
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 if(ctx->qbuf) {
73 delete ctx->qbuf;
74 ctx->qbuf = NULL;
75 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070076
77 if(ctx->mExtDisplay) {
78 delete ctx->mExtDisplay;
79 ctx->mExtDisplay = NULL;
80 }
81
82
83 free(const_cast<hwc_methods_t *>(ctx->device.methods));
84
Naseer Ahmed29a26812012-06-14 00:56:20 -070085}
86
87void dumpLayer(hwc_layer_t const* l)
88{
89 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
90 ", {%d,%d,%d,%d}",
91 l->compositionType, l->flags, l->handle, l->transform, l->blending,
92 l->sourceCrop.left,
93 l->sourceCrop.top,
94 l->sourceCrop.right,
95 l->sourceCrop.bottom,
96 l->displayFrame.left,
97 l->displayFrame.top,
98 l->displayFrame.right,
99 l->displayFrame.bottom);
100}
101
102void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
103{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 //Video specific stats
105 int yuvCount = 0;
106 int yuvLayerIndex = -1;
107 bool isYuvLayerSkip = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700108 int skipCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109
110 for (size_t i = 0; i < list->numHwLayers; i++) {
111 private_handle_t *hnd =
112 (private_handle_t *)list->hwLayers[i].handle;
113
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115 yuvCount++;
116 yuvLayerIndex = i;
117 //Animating
118 if (isSkipLayer(&list->hwLayers[i])) {
119 isYuvLayerSkip = true;
120 }
121 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
122 //If video layer is below a skip layer
123 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
124 isYuvLayerSkip = true;
125 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700126 skipCount++;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700127 }
128 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700129
130 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700131 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700132 MDPComp::setStats(skipCount);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134 ctx->numHwLayers = list->numHwLayers;
135 return;
136}
137
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700138//Crops source buffer against destination and FB boundaries
139void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
140 const int fbWidth, const int fbHeight) {
141
142 int& crop_x = crop.left;
143 int& crop_y = crop.top;
144 int& crop_r = crop.right;
145 int& crop_b = crop.bottom;
146 int crop_w = crop.right - crop.left;
147 int crop_h = crop.bottom - crop.top;
148
149 int& dst_x = dst.left;
150 int& dst_y = dst.top;
151 int& dst_r = dst.right;
152 int& dst_b = dst.bottom;
153 int dst_w = dst.right - dst.left;
154 int dst_h = dst.bottom - dst.top;
155
156 if(dst_x < 0) {
157 float scale_x = crop_w * 1.0f / dst_w;
158 float diff_factor = (scale_x * abs(dst_x));
159 crop_x = crop_x + (int)diff_factor;
160 crop_w = crop_r - crop_x;
161
162 dst_x = 0;
163 dst_w = dst_r - dst_x;;
164 }
165 if(dst_r > fbWidth) {
166 float scale_x = crop_w * 1.0f / dst_w;
167 float diff_factor = scale_x * (dst_r - fbWidth);
168 crop_r = crop_r - diff_factor;
169 crop_w = crop_r - crop_x;
170
171 dst_r = fbWidth;
172 dst_w = dst_r - dst_x;
173 }
174 if(dst_y < 0) {
175 float scale_y = crop_h * 1.0f / dst_h;
176 float diff_factor = scale_y * abs(dst_y);
177 crop_y = crop_y + diff_factor;
178 crop_h = crop_b - crop_y;
179
180 dst_y = 0;
181 dst_h = dst_b - dst_y;
182 }
183 if(dst_b > fbHeight) {
184 float scale_y = crop_h * 1.0f / dst_h;
185 float diff_factor = scale_y * (dst_b - fbHeight);
186 crop_b = crop_b - diff_factor;
187 crop_h = crop_b - crop_y;
188
189 dst_b = fbHeight;
190 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191 }
192}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700193
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194};//namespace