1 /* 2 // Copyright(c)2014 IntelCorporation 3 // 4 // LicensedundertheApacheLicense,Version2.0(the"License"); 5 // youmaynotusethisfileexceptincompliancewiththeLicense. 6 // YoumayobtainacopyoftheLicenseat 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software 11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS, 12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. 13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand 14 // limitationsundertheLicense. 15 */ 16 17 #include <HwcTrace.h> 18 #include <BufferMapper.h> 19 #include <common/GrallocSubBuffer.h> 20 #include <common/VideoPayloadManager.h> 21 #include <common/VideoPayloadBuffer.h> 22 23 namespace android { 24 namespace intel { 25 26 VideoPayloadManager::VideoPayloadManager() 27 : IVideoPayloadManager() 28 { 29 } 30 31 VideoPayloadManager::~VideoPayloadManager() 32 { 33 } 34 35 bool VideoPayloadManager::getMetaData(BufferMapper *mapper, MetaData *metadata) 36 { 37 if (!mapper || !metadata) { 38 ETRACE("Null input params"); 39 return false; 40 } 41 42 VideoPayloadBuffer *p = (VideoPayloadBuffer*) mapper->getCpuAddress(SUB_BUFFER1); 43 if (!p) { 44 ETRACE("Got null payload from display buffer"); 45 return false; 46 } 47 48 metadata->format = p->format; 49 metadata->transform = p->metadata_transform; 50 metadata->timestamp = p->timestamp; 51 52 metadata->normalBuffer.khandle = p->khandle; 53 metadata->normalBuffer.width = p->crop_width; 54 metadata->normalBuffer.height = p->crop_height; 55 metadata->normalBuffer.bufWidth = p->width; 56 metadata->normalBuffer.bufHeight = p->height; 57 metadata->normalBuffer.lumaStride = p->luma_stride; 58 metadata->normalBuffer.chromaUStride = p->chroma_u_stride; 59 metadata->normalBuffer.chromaVStride = p->chroma_v_stride; 60 metadata->normalBuffer.offsetX = 0; 61 metadata->normalBuffer.offsetY = 0; 62 metadata->normalBuffer.tiled = (p->width > 1280); 63 64 metadata->scalingBuffer.khandle = p->scaling_khandle; 65 metadata->scalingBuffer.width = p->scaling_width; 66 metadata->scalingBuffer.height = p->scaling_height; 67 metadata->scalingBuffer.bufWidth = align_to(p->scaling_width, 32); 68 metadata->scalingBuffer.bufHeight = align_to(p->scaling_height, 32); 69 metadata->scalingBuffer.lumaStride = p->scaling_luma_stride; 70 metadata->scalingBuffer.chromaUStride = p->scaling_chroma_u_stride; 71 metadata->scalingBuffer.chromaVStride = p->scaling_chroma_v_stride; 72 metadata->scalingBuffer.offsetX = 0; 73 metadata->scalingBuffer.offsetY = 0; 74 metadata->scalingBuffer.tiled = false; 75 76 metadata->rotationBuffer.khandle = p->rotated_buffer_handle; 77 uint16_t rotSrcWidth; 78 uint16_t rotSrcHeight; 79 if (metadata->scalingBuffer.khandle) { 80 rotSrcWidth = metadata->scalingBuffer.width; 81 rotSrcHeight = metadata->scalingBuffer.height; 82 } else { 83 rotSrcWidth = metadata->normalBuffer.width; 84 rotSrcHeight = metadata->normalBuffer.height; 85 } 86 if (metadata->transform == 0 || metadata->transform == HAL_TRANSFORM_ROT_180) { 87 metadata->rotationBuffer.width = rotSrcWidth; 88 metadata->rotationBuffer.height = rotSrcHeight; 89 } else { 90 metadata->rotationBuffer.width = rotSrcHeight; 91 metadata->rotationBuffer.height = rotSrcWidth; 92 } 93 metadata->rotationBuffer.bufWidth = p->rotated_width; 94 metadata->rotationBuffer.bufHeight = p->rotated_height; 95 metadata->rotationBuffer.lumaStride = p->rotate_luma_stride; 96 metadata->rotationBuffer.chromaUStride = p->rotate_chroma_u_stride; 97 metadata->rotationBuffer.chromaVStride = p->rotate_chroma_v_stride; 98 metadata->rotationBuffer.offsetX = (-metadata->rotationBuffer.width) & 0xf; 99 metadata->rotationBuffer.offsetY = (-metadata->rotationBuffer.height) & 0xf; 100 metadata->rotationBuffer.tiled = metadata->normalBuffer.tiled; 101 102 return true; 103 } 104 105 bool VideoPayloadManager::setRenderStatus(BufferMapper *mapper, bool renderStatus) 106 { 107 if (!mapper) { 108 ETRACE("Null mapper param"); 109 return false; 110 } 111 112 VideoPayloadBuffer* p = (VideoPayloadBuffer*) mapper->getCpuAddress(SUB_BUFFER1); 113 if (!p) { 114 ETRACE("Got null payload from display buffer"); 115 return false; 116 } 117 118 p->renderStatus = renderStatus ? 1 : 0; 119 return true; 120 } 121 122 } // namespace intel 123 } // namespace android 124