DisplayPlane.cpp revision e2b2a5fe291662041d1bbec00996c2ba302dc4c9
1/* 2 * Copyright © 2012 Intel Corporation 3 * All rights reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 * Authors: 25 * Jackie Li <yaodong.li@intel.com> 26 * 27 */ 28#include <HwcTrace.h> 29#include <Hwcomposer.h> 30#include <DisplayPlane.h> 31 32namespace android { 33namespace intel { 34 35DisplayPlane::DisplayPlane(int index, int type, int disp) 36 : mIndex(index), 37 mType(type), 38 mDevice(disp), 39 mInitialized(false), 40 mDataBuffers(), 41 mTransform(PLANE_TRANSFORM_0) 42{ 43 CTRACE(); 44 45 mPosition.x = 0; 46 mPosition.y = 0; 47 mPosition.w = 0; 48 mPosition.h = 0; 49 50 mSrcCrop.x = 0; 51 mSrcCrop.y = 0; 52 mSrcCrop.w = 0; 53 mSrcCrop.h = 0; 54} 55 56DisplayPlane::~DisplayPlane() 57{ 58 CTRACE(); 59 deinitialize(); 60} 61 62bool DisplayPlane::initialize(uint32_t bufferCount) 63{ 64 CTRACE(); 65 66 // create buffer cache 67 mDataBuffers.setCapacity(bufferCount); 68 69 mInitialized = true; 70 return true; 71} 72 73void DisplayPlane::deinitialize() 74{ 75 // invalid buffer cache 76 invalidateBufferCache(); 77 78 mInitialized = false; 79} 80 81void DisplayPlane::setPosition(int x, int y, int w, int h) 82{ 83 ATRACE("Position = %d, %d - %dx%d", x, y, w, h); 84 85 86 mPosition.x = x; 87 mPosition.y = y; 88 mPosition.w = w; 89 mPosition.h = h; 90} 91 92void DisplayPlane::setSourceCrop(int x, int y, int w, int h) 93{ 94 ATRACE("Source crop = %d, %d - %dx%d", x, y, w, h); 95 96 mSrcCrop.x = x; 97 mSrcCrop.y = y; 98 mSrcCrop.w = w; 99 mSrcCrop.h = h; 100} 101 102void DisplayPlane::setTransform(int trans) 103{ 104 ATRACE("transform = %d", trans); 105 106 switch (trans) { 107 case PLANE_TRANSFORM_90: 108 case PLANE_TRANSFORM_180: 109 case PLANE_TRANSFORM_270: 110 mTransform = trans; 111 break; 112 default: 113 mTransform = PLANE_TRANSFORM_0; 114 } 115} 116 117bool DisplayPlane::setDataBuffer(uint32_t handle) 118{ 119 DataBuffer *buffer; 120 BufferMapper *mapper; 121 ssize_t index; 122 BufferManager *bm = Hwcomposer::getInstance().getBufferManager(); 123 124 RETURN_FALSE_IF_NOT_INIT(); 125 ATRACE("handle = %#x", handle); 126 127 if (!handle) { 128 ETRACE("invalid buffer handle"); 129 return false; 130 } 131 132 if (!bm) { 133 ETRACE("failed to get buffer manager"); 134 return false; 135 } 136 137 buffer = bm->get(handle); 138 if (!buffer) { 139 ETRACE("failed to get buffer"); 140 return false; 141 } 142 143 // update buffer's source crop 144 buffer->setCrop(mSrcCrop.x, mSrcCrop.y, mSrcCrop.w, mSrcCrop.h); 145 146 // map buffer if it's not in cache 147 index = mDataBuffers.indexOfKey(buffer->getKey()); 148 if (index < 0) { 149 VTRACE("unmapped buffer, mapping..."); 150 mapper = bm->map(*buffer); 151 if (!mapper) { 152 ETRACE("failed to map buffer"); 153 goto mapper_err; 154 } 155 156 // add it to data buffers 157 index = mDataBuffers.add(buffer->getKey(), mapper); 158 if (index < 0) { 159 ETRACE("failed to add mapper"); 160 goto add_err; 161 } 162 } else { 163 VTRACE("got mapper in saved data buffers"); 164 mapper = mDataBuffers.valueAt(index); 165 } 166 167 // put buffer after getting mapper 168 bm->put(*buffer); 169 170 return setDataBuffer(*mapper); 171add_err: 172 bm->unmap(*mapper); 173mapper_err: 174 bm->put(*buffer); 175 return false; 176} 177 178void DisplayPlane::invalidateBufferCache() 179{ 180 BufferManager *bm = Hwcomposer::getInstance().getBufferManager(); 181 BufferMapper* mapper; 182 183 RETURN_VOID_IF_NOT_INIT(); 184 185 if (!bm) { 186 ETRACE("failed to get buffer manager"); 187 return; 188 } 189 190 for (size_t i = 0; i < mDataBuffers.size(); i++) { 191 mapper = mDataBuffers.valueAt(i); 192 // unmap it 193 if (mapper) 194 bm->unmap(*mapper); 195 } 196 197 // clear recorded data buffers 198 mDataBuffers.clear(); 199} 200 201bool DisplayPlane::assignToDevice(int disp) 202{ 203 RETURN_FALSE_IF_NOT_INIT(); 204 ATRACE("disp = %d", disp); 205 206 mDevice = disp; 207 return true; 208} 209 210} // namespace intel 211} // namespace android 212