blob: ae5c526faa9cd07615ceca66e024d5e38c30cfd8 [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 Ahmed0c8b7b52012-07-20 09:06:13 -070021#include "hwc_ext_observer.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070022#include "hwc_copybit.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070023namespace qhwc {
24void initContext(hwc_context_t *ctx)
25{
26 //XXX: target specific initializations here
Naseer Ahmed29a26812012-06-14 00:56:20 -070027 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
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070033 ctx->mExtDisplayObserver = ExtDisplayObserver::getInstance();
34 ctx->mExtDisplayObserver->setHwcContext(ctx);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070035 ctx->mFbDevice = FbDevice::getInstance();
36 ctx->mCopybitEngine = CopybitEngine::getInstance();
37 CopyBit::openEglLibAndGethandle();
Naseer Ahmed29a26812012-06-14 00:56:20 -070038}
39
40void closeContext(hwc_context_t *ctx)
41{
42 if(ctx->mOverlay) {
43 delete ctx->mOverlay;
44 ctx->mOverlay = NULL;
45 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046
Naseer Ahmed31da0b12012-07-31 18:55:33 -070047 if(ctx->mCopybitEngine) {
48 delete ctx->mCopybitEngine;
49 ctx->mCopybitEngine = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -070050 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -070051 if(ctx->mFbDevice) {
52 delete ctx->mFbDevice;
53 ctx->mFbDevice = NULL;
54 }
Naseer Ahmed29a26812012-06-14 00:56:20 -070055 if(ctx->qbuf) {
56 delete ctx->qbuf;
57 ctx->qbuf = NULL;
58 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -070059 CopyBit::closeEglLib();
Naseer Ahmed29a26812012-06-14 00:56:20 -070060}
61
62void dumpLayer(hwc_layer_t const* l)
63{
64 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
65 ", {%d,%d,%d,%d}",
66 l->compositionType, l->flags, l->handle, l->transform, l->blending,
67 l->sourceCrop.left,
68 l->sourceCrop.top,
69 l->sourceCrop.right,
70 l->sourceCrop.bottom,
71 l->displayFrame.left,
72 l->displayFrame.top,
73 l->displayFrame.right,
74 l->displayFrame.bottom);
75}
76
77void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
78{
Naseer Ahmedf48aef62012-07-20 09:05:53 -070079 //Video specific stats
80 int yuvCount = 0;
81 int yuvLayerIndex = -1;
82 bool isYuvLayerSkip = false;
83
84 for (size_t i = 0; i < list->numHwLayers; i++) {
85 private_handle_t *hnd =
86 (private_handle_t *)list->hwLayers[i].handle;
87
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070089 yuvCount++;
90 yuvLayerIndex = i;
91 //Animating
92 if (isSkipLayer(&list->hwLayers[i])) {
93 isYuvLayerSkip = true;
94 }
95 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
96 //If video layer is below a skip layer
97 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
98 isYuvLayerSkip = true;
99 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 }
101 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102
103 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700104 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 ctx->numHwLayers = list->numHwLayers;
107 return;
108}
109
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110//Crops source buffer against destination and FB boundaries
111void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
112 const int fbWidth, const int fbHeight) {
113
114 int& crop_x = crop.left;
115 int& crop_y = crop.top;
116 int& crop_r = crop.right;
117 int& crop_b = crop.bottom;
118 int crop_w = crop.right - crop.left;
119 int crop_h = crop.bottom - crop.top;
120
121 int& dst_x = dst.left;
122 int& dst_y = dst.top;
123 int& dst_r = dst.right;
124 int& dst_b = dst.bottom;
125 int dst_w = dst.right - dst.left;
126 int dst_h = dst.bottom - dst.top;
127
128 if(dst_x < 0) {
129 float scale_x = crop_w * 1.0f / dst_w;
130 float diff_factor = (scale_x * abs(dst_x));
131 crop_x = crop_x + (int)diff_factor;
132 crop_w = crop_r - crop_x;
133
134 dst_x = 0;
135 dst_w = dst_r - dst_x;;
136 }
137 if(dst_r > fbWidth) {
138 float scale_x = crop_w * 1.0f / dst_w;
139 float diff_factor = scale_x * (dst_r - fbWidth);
140 crop_r = crop_r - diff_factor;
141 crop_w = crop_r - crop_x;
142
143 dst_r = fbWidth;
144 dst_w = dst_r - dst_x;
145 }
146 if(dst_y < 0) {
147 float scale_y = crop_h * 1.0f / dst_h;
148 float diff_factor = scale_y * abs(dst_y);
149 crop_y = crop_y + diff_factor;
150 crop_h = crop_b - crop_y;
151
152 dst_y = 0;
153 dst_h = dst_b - dst_y;
154 }
155 if(dst_b > fbHeight) {
156 float scale_y = crop_h * 1.0f / dst_h;
157 float diff_factor = scale_y * (dst_b - fbHeight);
158 crop_b = crop_b - diff_factor;
159 crop_h = crop_b - crop_y;
160
161 dst_b = fbHeight;
162 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 }
164}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700166//FbDevice class functions
167FbDevice* FbDevice::sInstance = 0;;
168struct framebuffer_device_t* FbDevice::getFb() {
169 return sFb;
170}
171
172FbDevice* FbDevice::getInstance() {
173 if(sInstance == NULL)
174 sInstance = new FbDevice();
175 return sInstance;
176}
177
178FbDevice::FbDevice(){
179 hw_module_t const *module;
180 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
181 framebuffer_open(module, &sFb);
182 } else {
183 ALOGE("FATAL ERROR: framebuffer open failed.");
184 }
185}
186FbDevice::~FbDevice()
187{
188 if(sFb)
189 {
190 framebuffer_close(sFb);
191 sFb = NULL;
192 }
193}
194
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195};//namespace