blob: 870a7586b5ddba1c9883a49c1c503e37cbbf0722 [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"
25
Naseer Ahmed29a26812012-06-14 00:56:20 -070026namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070027
28// Opens Framebuffer device
29static void openFramebufferDevice(hwc_context_t *ctx)
30{
31 hw_module_t const *module;
32 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
33 framebuffer_open(module, &(ctx->mFbDev));
34 }
35}
36
Naseer Ahmed29a26812012-06-14 00:56:20 -070037void initContext(hwc_context_t *ctx)
38{
Naseer Ahmed72cf9762012-07-21 12:17:13 -070039 openFramebufferDevice(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 ctx->mOverlay = overlay::Overlay::getInstance();
41 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmeda87da602012-07-01 23:54:19 -070042 ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
43 ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070044 ctx->mCopybitEngine = CopybitEngine::getInstance();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070045 ctx->mExtDisplay = new ExternalDisplay(ctx);
46
47 init_uevent_thread(ctx);
48
49 ALOGI("Initializing Qualcomm Hardware Composer");
50 ALOGI("MDP version: %d", ctx->mdpVersion);
Naseer Ahmed29a26812012-06-14 00:56:20 -070051}
52
53void closeContext(hwc_context_t *ctx)
54{
55 if(ctx->mOverlay) {
56 delete ctx->mOverlay;
57 ctx->mOverlay = NULL;
58 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070059
Naseer Ahmed31da0b12012-07-31 18:55:33 -070060 if(ctx->mCopybitEngine) {
61 delete ctx->mCopybitEngine;
62 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070063 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070064
65 if(ctx->mFbDev) {
66 framebuffer_close(ctx->mFbDev);
67 ctx->mFbDev = NULL;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070068 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070069
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 if(ctx->qbuf) {
71 delete ctx->qbuf;
72 ctx->qbuf = NULL;
73 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070074
75 if(ctx->mExtDisplay) {
76 delete ctx->mExtDisplay;
77 ctx->mExtDisplay = NULL;
78 }
79
80
81 free(const_cast<hwc_methods_t *>(ctx->device.methods));
82
Naseer Ahmed29a26812012-06-14 00:56:20 -070083}
84
85void dumpLayer(hwc_layer_t const* l)
86{
87 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
88 ", {%d,%d,%d,%d}",
89 l->compositionType, l->flags, l->handle, l->transform, l->blending,
90 l->sourceCrop.left,
91 l->sourceCrop.top,
92 l->sourceCrop.right,
93 l->sourceCrop.bottom,
94 l->displayFrame.left,
95 l->displayFrame.top,
96 l->displayFrame.right,
97 l->displayFrame.bottom);
98}
99
100void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
101{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102 //Video specific stats
103 int yuvCount = 0;
104 int yuvLayerIndex = -1;
105 bool isYuvLayerSkip = false;
106
107 for (size_t i = 0; i < list->numHwLayers; i++) {
108 private_handle_t *hnd =
109 (private_handle_t *)list->hwLayers[i].handle;
110
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112 yuvCount++;
113 yuvLayerIndex = i;
114 //Animating
115 if (isSkipLayer(&list->hwLayers[i])) {
116 isYuvLayerSkip = true;
117 }
118 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
119 //If video layer is below a skip layer
120 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
121 isYuvLayerSkip = true;
122 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700123 }
124 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125
126 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700127 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700128
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129 ctx->numHwLayers = list->numHwLayers;
130 return;
131}
132
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133//Crops source buffer against destination and FB boundaries
134void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
135 const int fbWidth, const int fbHeight) {
136
137 int& crop_x = crop.left;
138 int& crop_y = crop.top;
139 int& crop_r = crop.right;
140 int& crop_b = crop.bottom;
141 int crop_w = crop.right - crop.left;
142 int crop_h = crop.bottom - crop.top;
143
144 int& dst_x = dst.left;
145 int& dst_y = dst.top;
146 int& dst_r = dst.right;
147 int& dst_b = dst.bottom;
148 int dst_w = dst.right - dst.left;
149 int dst_h = dst.bottom - dst.top;
150
151 if(dst_x < 0) {
152 float scale_x = crop_w * 1.0f / dst_w;
153 float diff_factor = (scale_x * abs(dst_x));
154 crop_x = crop_x + (int)diff_factor;
155 crop_w = crop_r - crop_x;
156
157 dst_x = 0;
158 dst_w = dst_r - dst_x;;
159 }
160 if(dst_r > fbWidth) {
161 float scale_x = crop_w * 1.0f / dst_w;
162 float diff_factor = scale_x * (dst_r - fbWidth);
163 crop_r = crop_r - diff_factor;
164 crop_w = crop_r - crop_x;
165
166 dst_r = fbWidth;
167 dst_w = dst_r - dst_x;
168 }
169 if(dst_y < 0) {
170 float scale_y = crop_h * 1.0f / dst_h;
171 float diff_factor = scale_y * abs(dst_y);
172 crop_y = crop_y + diff_factor;
173 crop_h = crop_b - crop_y;
174
175 dst_y = 0;
176 dst_h = dst_b - dst_y;
177 }
178 if(dst_b > fbHeight) {
179 float scale_y = crop_h * 1.0f / dst_h;
180 float diff_factor = scale_y * (dst_b - fbHeight);
181 crop_b = crop_b - diff_factor;
182 crop_h = crop_b - crop_y;
183
184 dst_b = fbHeight;
185 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 }
187}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189};//namespace