DisplayPlane.cpp revision 25caf44022e04f4dc131e51b85b2fb8f966d57e7
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#include <GraphicBuffer.h> 32 33namespace android { 34namespace intel { 35 36DisplayPlane::DisplayPlane(int index, int type, int disp) 37 : mIndex(index), 38 mType(type), 39 mDevice(disp), 40 mInitialized(false), 41 mDataBuffers(), 42 mIsProtectedBuffer(false), 43 mTransform(PLANE_TRANSFORM_0) 44{ 45 CTRACE(); 46 47 mPosition.x = 0; 48 mPosition.y = 0; 49 mPosition.w = 0; 50 mPosition.h = 0; 51 52 mSrcCrop.x = 0; 53 mSrcCrop.y = 0; 54 mSrcCrop.w = 0; 55 mSrcCrop.h = 0; 56} 57 58DisplayPlane::~DisplayPlane() 59{ 60 CTRACE(); 61 deinitialize(); 62} 63 64bool DisplayPlane::initialize(uint32_t bufferCount) 65{ 66 CTRACE(); 67 68 // create buffer cache 69 mDataBuffers.setCapacity(bufferCount); 70 71 mInitialized = true; 72 return true; 73} 74 75void DisplayPlane::deinitialize() 76{ 77 // invalid buffer cache 78 invalidateBufferCache(); 79 80 mInitialized = false; 81} 82 83void DisplayPlane::setPosition(int x, int y, int w, int h) 84{ 85 ATRACE("Position = %d, %d - %dx%d", x, y, w, h); 86 87 88 mPosition.x = x; 89 mPosition.y = y; 90 mPosition.w = w; 91 mPosition.h = h; 92} 93 94void DisplayPlane::setSourceCrop(int x, int y, int w, int h) 95{ 96 ATRACE("Source crop = %d, %d - %dx%d", x, y, w, h); 97 98 mSrcCrop.x = x; 99 mSrcCrop.y = y; 100 mSrcCrop.w = w; 101 mSrcCrop.h = h; 102} 103 104void DisplayPlane::setTransform(int trans) 105{ 106 ATRACE("transform = %d", trans); 107 108 switch (trans) { 109 case PLANE_TRANSFORM_90: 110 case PLANE_TRANSFORM_180: 111 case PLANE_TRANSFORM_270: 112 mTransform = trans; 113 break; 114 default: 115 mTransform = PLANE_TRANSFORM_0; 116 } 117} 118 119bool DisplayPlane::setDataBuffer(uint32_t handle) 120{ 121 DataBuffer *buffer; 122 BufferMapper *mapper; 123 ssize_t index; 124 BufferManager *bm = Hwcomposer::getInstance().getBufferManager(); 125 126 RETURN_FALSE_IF_NOT_INIT(); 127 ATRACE("handle = %#x", handle); 128 129 if (!handle) { 130 ETRACE("invalid buffer handle"); 131 return false; 132 } 133 134 if (!bm) { 135 ETRACE("failed to get buffer manager"); 136 return false; 137 } 138 139 buffer = bm->get(handle); 140 if (!buffer) { 141 ETRACE("failed to get buffer"); 142 return false; 143 } 144 145 // update buffer's source crop 146 buffer->setCrop(mSrcCrop.x, mSrcCrop.y, mSrcCrop.w, mSrcCrop.h); 147 148 mIsProtectedBuffer = GraphicBuffer::isProtectedBuffer((GraphicBuffer*)buffer); 149 // map buffer if it's not in cache 150 index = mDataBuffers.indexOfKey(buffer->getKey()); 151 if (index < 0) { 152 VTRACE("unmapped buffer, mapping..."); 153 mapper = bm->map(*buffer); 154 if (!mapper) { 155 ETRACE("failed to map buffer"); 156 goto mapper_err; 157 } 158 159 // add it to data buffers 160 index = mDataBuffers.add(buffer->getKey(), mapper); 161 if (index < 0) { 162 ETRACE("failed to add mapper"); 163 goto add_err; 164 } 165 } else { 166 VTRACE("got mapper in saved data buffers"); 167 mapper = mDataBuffers.valueAt(index); 168 } 169 170 // put buffer after getting mapper 171 bm->put(*buffer); 172 173 return setDataBuffer(*mapper); 174add_err: 175 bm->unmap(*mapper); 176mapper_err: 177 bm->put(*buffer); 178 return false; 179} 180 181void DisplayPlane::invalidateBufferCache() 182{ 183 BufferManager *bm = Hwcomposer::getInstance().getBufferManager(); 184 BufferMapper* mapper; 185 186 RETURN_VOID_IF_NOT_INIT(); 187 188 if (!bm) { 189 ETRACE("failed to get buffer manager"); 190 return; 191 } 192 193 for (size_t i = 0; i < mDataBuffers.size(); i++) { 194 mapper = mDataBuffers.valueAt(i); 195 // unmap it 196 if (mapper) 197 bm->unmap(*mapper); 198 } 199 200 // clear recorded data buffers 201 mDataBuffers.clear(); 202} 203 204bool DisplayPlane::assignToDevice(int disp) 205{ 206 RETURN_FALSE_IF_NOT_INIT(); 207 ATRACE("disp = %d", disp); 208 209 mDevice = disp; 210 return true; 211} 212 213} // namespace intel 214} // namespace android 215