blob: 90c32fea1202c43ba393d0f6c5e96e98cbea0180 [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
18#include "hwc_utils.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070019#include "mdp_version.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070020#include "hwc_video.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070021
22namespace qhwc {
23void initContext(hwc_context_t *ctx)
24{
25 //XXX: target specific initializations here
26 openFramebufferDevice(ctx);
27 ctx->mOverlay = overlay::Overlay::getInstance();
28 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmeda87da602012-07-01 23:54:19 -070029 ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
30 ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
31 ALOGI("MDP version: %d",ctx->mdpVersion);
Naseer Ahmed29a26812012-06-14 00:56:20 -070032
33}
34
35void closeContext(hwc_context_t *ctx)
36{
37 if(ctx->mOverlay) {
38 delete ctx->mOverlay;
39 ctx->mOverlay = NULL;
40 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070041
Naseer Ahmed29a26812012-06-14 00:56:20 -070042 if(ctx->fbDev) {
43 framebuffer_close(ctx->fbDev);
44 ctx->fbDev = NULL;
45 }
46
47 if(ctx->qbuf) {
48 delete ctx->qbuf;
49 ctx->qbuf = NULL;
50 }
51}
52
53// Opens Framebuffer device
54void openFramebufferDevice(hwc_context_t *ctx) {
55 hw_module_t const *module;
56 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
57 framebuffer_open(module, &(ctx->fbDev));
58 }
59}
60
61void dumpLayer(hwc_layer_t const* l)
62{
63 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
64 ", {%d,%d,%d,%d}",
65 l->compositionType, l->flags, l->handle, l->transform, l->blending,
66 l->sourceCrop.left,
67 l->sourceCrop.top,
68 l->sourceCrop.right,
69 l->sourceCrop.bottom,
70 l->displayFrame.left,
71 l->displayFrame.top,
72 l->displayFrame.right,
73 l->displayFrame.bottom);
74}
75
76void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
77{
Naseer Ahmedf48aef62012-07-20 09:05:53 -070078 //Video specific stats
79 int yuvCount = 0;
80 int yuvLayerIndex = -1;
81 bool isYuvLayerSkip = false;
82
83 for (size_t i = 0; i < list->numHwLayers; i++) {
84 private_handle_t *hnd =
85 (private_handle_t *)list->hwLayers[i].handle;
86
Naseer Ahmed29a26812012-06-14 00:56:20 -070087 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070088 yuvCount++;
89 yuvLayerIndex = i;
90 //Animating
91 if (isSkipLayer(&list->hwLayers[i])) {
92 isYuvLayerSkip = true;
93 }
94 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
95 //If video layer is below a skip layer
96 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
97 isYuvLayerSkip = true;
98 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 }
100 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101
102 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
103
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104 ctx->numHwLayers = list->numHwLayers;
105 return;
106}
107
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108//Crops source buffer against destination and FB boundaries
109void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
110 const int fbWidth, const int fbHeight) {
111
112 int& crop_x = crop.left;
113 int& crop_y = crop.top;
114 int& crop_r = crop.right;
115 int& crop_b = crop.bottom;
116 int crop_w = crop.right - crop.left;
117 int crop_h = crop.bottom - crop.top;
118
119 int& dst_x = dst.left;
120 int& dst_y = dst.top;
121 int& dst_r = dst.right;
122 int& dst_b = dst.bottom;
123 int dst_w = dst.right - dst.left;
124 int dst_h = dst.bottom - dst.top;
125
126 if(dst_x < 0) {
127 float scale_x = crop_w * 1.0f / dst_w;
128 float diff_factor = (scale_x * abs(dst_x));
129 crop_x = crop_x + (int)diff_factor;
130 crop_w = crop_r - crop_x;
131
132 dst_x = 0;
133 dst_w = dst_r - dst_x;;
134 }
135 if(dst_r > fbWidth) {
136 float scale_x = crop_w * 1.0f / dst_w;
137 float diff_factor = scale_x * (dst_r - fbWidth);
138 crop_r = crop_r - diff_factor;
139 crop_w = crop_r - crop_x;
140
141 dst_r = fbWidth;
142 dst_w = dst_r - dst_x;
143 }
144 if(dst_y < 0) {
145 float scale_y = crop_h * 1.0f / dst_h;
146 float diff_factor = scale_y * abs(dst_y);
147 crop_y = crop_y + diff_factor;
148 crop_h = crop_b - crop_y;
149
150 dst_y = 0;
151 dst_h = dst_b - dst_y;
152 }
153 if(dst_b > fbHeight) {
154 float scale_y = crop_h * 1.0f / dst_h;
155 float diff_factor = scale_y * (dst_b - fbHeight);
156 crop_b = crop_b - diff_factor;
157 crop_h = crop_b - crop_y;
158
159 dst_b = fbHeight;
160 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 }
162}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700163
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164};//namespace