1202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/* 2202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Copyright (C) 2008 The Android Open Source Project 3aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. 4202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 5202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License"); 6202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * you may not use this file except in compliance with the License. 7202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * You may obtain a copy of the License at 8202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 9202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * http://www.apache.org/licenses/LICENSE-2.0 10202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 11202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Unless required by applicable law or agreed to in writing, software 12202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS, 13202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * See the License for the specific language governing permissions and 15202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * limitations under the License. 16202a77d28ac251545f6f998a974690212309b927Iliyan Malchev */ 17202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 18202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#ifndef GRALLOC_PRIV_H_ 19202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#define GRALLOC_PRIV_H_ 20202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 21202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <stdint.h> 22202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <limits.h> 23202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <sys/cdefs.h> 24202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <hardware/gralloc.h> 25202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <pthread.h> 26202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <errno.h> 27202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <unistd.h> 28202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 29202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <cutils/native_handle.h> 30202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 31202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <cutils/log.h> 32202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 33c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan#define ROUND_UP_PAGESIZE(x) ( (((unsigned long)(x)) + PAGE_SIZE-1) & \ 34c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan (~(PAGE_SIZE-1)) ) 35c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan 36202a77d28ac251545f6f998a974690212309b927Iliyan Malchevenum { 37202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* gralloc usage bits indicating the type 38202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * of allocation that should be used */ 39202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 40202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* SYSTEM heap comes from kernel vmalloc, 41202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * can never be uncached, is not secured*/ 4201d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP = GRALLOC_USAGE_PRIVATE_0, 4301d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed /* SF heap is used for application buffers, is not secured */ 4401d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP = GRALLOC_USAGE_PRIVATE_1, 45202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* IOMMU heap comes from manually allocated pages, 46202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * can be cached/uncached, is not secured */ 4701d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_IOMMU_HEAP = GRALLOC_USAGE_PRIVATE_2, 48202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* MM heap is a carveout heap for video, can be secured*/ 4901d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_MM_HEAP = GRALLOC_USAGE_PRIVATE_3, 50513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava /* CAMERA heap is a carveout heap for camera, is not secured*/ 51513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava GRALLOC_USAGE_PRIVATE_CAMERA_HEAP = 0x01000000, 52202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 53202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* Set this for allocating uncached memory (using O_DSYNC) 54202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * cannot be used with noncontiguous heaps */ 5501d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_UNCACHED = 0x02000000, 56202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 57202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* Buffer content should be displayed on an external display only */ 584c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY = 0x08000000, 59202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 60202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* Only this buffer content should be displayed on external, even if 61202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * other EXTERNAL_ONLY buffers are available. Used during suspend. 62202a77d28ac251545f6f998a974690212309b927Iliyan Malchev */ 634c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed GRALLOC_USAGE_PRIVATE_EXTERNAL_BLOCK = 0x00100000, 644c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed 654c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed /* Close Caption displayed on an external display only */ 664c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed GRALLOC_USAGE_PRIVATE_EXTERNAL_CC = 0x00200000, 6729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed 68513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava /* Use this flag to request content protected buffers. Please note 69513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava * that this flag is different from the GRALLOC_USAGE_PROTECTED flag 70513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava * which can be used for buffers that are not secured for DRM 71513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava * but still need to be protected from screen captures 72513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava */ 73513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava GRALLOC_USAGE_PRIVATE_CP_BUFFER = 0x00400000, 74202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 75202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 76202a77d28ac251545f6f998a974690212309b927Iliyan Malchevenum { 77202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* Gralloc perform enums 78202a77d28ac251545f6f998a974690212309b927Iliyan Malchev */ 79da429776b96f9e81aee0b250ab3c0fb9cdcd3254Naseer Ahmed GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 1, 80bb0862a8db32349e2c1fc14f8287e815dde4d9a7Naomi Luis GRALLOC_MODULE_PERFORM_GET_STRIDE, 815d1d54ff7c44559f664fdf071164c56c740ab79aNaseer Ahmed GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE, 82202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 83202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 8401d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed#define GRALLOC_HEAP_MASK (GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |\ 8501d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP |\ 8601d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |\ 8701d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed GRALLOC_USAGE_PRIVATE_MM_HEAP |\ 88513ddc2124abf90c63af41999201f0d2031af0c8Vineeta Srivastava GRALLOC_USAGE_PRIVATE_CAMERA_HEAP) 89202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 90202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#define INTERLACE_MASK 0x80 91202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#define S3D_FORMAT_MASK 0xFF000 92202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/*****************************************************************************/ 93202a77d28ac251545f6f998a974690212309b927Iliyan Malchevenum { 94202a77d28ac251545f6f998a974690212309b927Iliyan Malchev /* OEM specific HAL formats */ 9565f16566210422e4fd3b7e6bbedaae22d67fc281Naseer Ahmed HAL_PIXEL_FORMAT_NV12_ENCODEABLE = 0x102, 96d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04, 9765f16566210422e4fd3b7e6bbedaae22d67fc281Naseer Ahmed HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03, 98202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109, 99ad766cd2d88073a5f7e56b24bc82eb638e45ed3fNaseer Ahmed HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01, 100202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_PIXEL_FORMAT_YCrCb_422_SP = 0x10B, 101202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_PIXEL_FORMAT_R_8 = 0x10D, 102202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_PIXEL_FORMAT_RG_88 = 0x10E, 10329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed HAL_PIXEL_FORMAT_YCbCr_444_SP = 0x10F, 10429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed HAL_PIXEL_FORMAT_YCrCb_444_SP = 0x110, 105202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_PIXEL_FORMAT_INTERLACE = 0x180, 106202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 107202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 108202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 109202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/* possible formats for 3D content*/ 110202a77d28ac251545f6f998a974690212309b927Iliyan Malchevenum { 111202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_NO_3D = 0x0000, 112202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, 113202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_IN_TOP_BOTTOM = 0x20000, 114202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_IN_INTERLEAVE = 0x40000, 115202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000, 116202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_OUT_SIDE_BY_SIDE = 0x1000, 117202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_OUT_TOP_BOTTOM = 0x2000, 118202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_OUT_INTERLEAVE = 0x4000, 119202a77d28ac251545f6f998a974690212309b927Iliyan Malchev HAL_3D_OUT_MONOSCOPIC = 0x8000 120202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 121202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 122202a77d28ac251545f6f998a974690212309b927Iliyan Malchevenum { 12329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed BUFFER_TYPE_UI = 0, 12429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed BUFFER_TYPE_VIDEO 125202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 126202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 127202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/*****************************************************************************/ 128202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 129202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#ifdef __cplusplus 130202a77d28ac251545f6f998a974690212309b927Iliyan Malchevstruct private_handle_t : public native_handle { 131202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#else 13229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed struct private_handle_t { 13329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed native_handle_t nativeHandle; 134202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#endif 13529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed enum { 13629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_FRAMEBUFFER = 0x00000001, 13729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_USES_PMEM = 0x00000002, 13829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_USES_PMEM_ADSP = 0x00000004, 13929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_USES_ION = 0x00000008, 14029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_USES_ASHMEM = 0x00000010, 14129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_NEEDS_FLUSH = 0x00000020, 14229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_DO_NOT_FLUSH = 0x00000040, 14329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_SW_LOCK = 0x00000080, 14429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_NONCONTIGUOUS_MEM = 0x00000100, 14529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // Set by HWC when storing the handle 14629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_HWC_LOCK = 0x00000200, 14729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_SECURE_BUFFER = 0x00000400, 14829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // For explicit synchronization 14929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_UNSYNCHRONIZED = 0x00000800, 15029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // Not mapped in userspace 15129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_NOT_MAPPED = 0x00001000, 15229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // Display on external only 15329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000, 15429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // Display only this buffer on external 15529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed PRIV_FLAGS_EXTERNAL_BLOCK = 0x00004000, 1564c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed // Display this buffer on external as close caption 1574c588a200c537224d4eb5f63fb0a88f791511ff2Naseer Ahmed PRIV_FLAGS_EXTERNAL_CC = 0x00008000, 15859802500bc68ec349bd2ac2e3a01daa94c81a88aNaseer Ahmed PRIV_FLAGS_VIDEO_ENCODER = 0x00010000, 15959802500bc68ec349bd2ac2e3a01daa94c81a88aNaseer Ahmed PRIV_FLAGS_CAMERA_WRITE = 0x00020000, 16059802500bc68ec349bd2ac2e3a01daa94c81a88aNaseer Ahmed PRIV_FLAGS_CAMERA_READ = 0x00040000, 161ae658e884cc703419ad281d25fa5957db74131ccNaseer Ahmed PRIV_FLAGS_HW_COMPOSER = 0x00080000, 162f2b80d8abab47595b83e3ce9759d4ddccfeafe94Shuzhen Wang PRIV_FLAGS_HW_TEXTURE = 0x00100000, 163e4d4d1c2d57885a3a4d23461c317284f232dd3cdNaseer Ahmed PRIV_FLAGS_ITU_R_601 = 0x00200000, 164e4d4d1c2d57885a3a4d23461c317284f232dd3cdNaseer Ahmed PRIV_FLAGS_ITU_R_601_FR = 0x00400000, 165e4d4d1c2d57885a3a4d23461c317284f232dd3cdNaseer Ahmed PRIV_FLAGS_ITU_R_709 = 0x00800000, 16629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed }; 16729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed 16829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // file-descriptors 16929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int fd; 170c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan int fd_metadata; // fd for the meta-data 17129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // ints 17229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int magic; 17329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int flags; 17429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int size; 17529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int offset; 17629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int bufferType; 17729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int base; 178c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan int offset_metadata; 17929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed // The gpu address mapped into the mmu. 18029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int gpuaddr; 18129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int format; 18229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int width; 18329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int height; 184c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan int base_metadata; 185202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 186202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#ifdef __cplusplus 187aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed static const int sNumInts = 12; 188aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed static const int sNumFds = 2; 18929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed static const int sMagic = 'gmsm'; 19029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed 19129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed private_handle_t(int fd, int size, int flags, int bufferType, 192c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan int format,int width, int height, int eFd = -1, 193c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan int eOffset = 0, int eBase = 0) : 194aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed fd(fd), fd_metadata(eFd), magic(sMagic), 195c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan flags(flags), size(size), offset(0), bufferType(bufferType), 196aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed base(0), offset_metadata(eOffset), gpuaddr(0), 197aee73e2656d1176ee29d20218947fc3a379818b3Naseer Ahmed format(format), width(width), height(height), 198c0945d8a389f71cdf8432947a6911838d1219c4bRamkumar Radhakrishnan base_metadata(eBase) 19929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed { 20029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed version = sizeof(native_handle); 20129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed numInts = sNumInts; 20229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed numFds = sNumFds; 20329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed } 20429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ~private_handle_t() { 20529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed magic = 0; 20629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed } 207202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 20829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed bool usesPhysicallyContiguousMemory() { 20929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed return (flags & PRIV_FLAGS_USES_PMEM) != 0; 21029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed } 211202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 21229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed static int validate(const native_handle* h) { 21329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed const private_handle_t* hnd = (const private_handle_t*)h; 21429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed if (!h || h->version != sizeof(native_handle) || 215202a77d28ac251545f6f998a974690212309b927Iliyan Malchev h->numInts != sNumInts || h->numFds != sNumFds || 216202a77d28ac251545f6f998a974690212309b927Iliyan Malchev hnd->magic != sMagic) 21729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed { 21829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ALOGD("Invalid gralloc handle (at %p): " 21929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed "ver(%d/%d) ints(%d/%d) fds(%d/%d) magic(%c%c%c%c/%c%c%c%c)", 22029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed h, 22129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed h ? h->version : -1, sizeof(native_handle), 22229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed h ? h->numInts : -1, sNumInts, 22329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed h ? h->numFds : -1, sNumFds, 22429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hnd ? (((hnd->magic >> 24) & 0xFF)? 22529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ((hnd->magic >> 24) & 0xFF) : '-') : '?', 22629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hnd ? (((hnd->magic >> 16) & 0xFF)? 22729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ((hnd->magic >> 16) & 0xFF) : '-') : '?', 22829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hnd ? (((hnd->magic >> 8) & 0xFF)? 22929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ((hnd->magic >> 8) & 0xFF) : '-') : '?', 23029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hnd ? (((hnd->magic >> 0) & 0xFF)? 23129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed ((hnd->magic >> 0) & 0xFF) : '-') : '?', 23229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed (sMagic >> 24) & 0xFF, 23329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed (sMagic >> 16) & 0xFF, 23429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed (sMagic >> 8) & 0xFF, 23529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed (sMagic >> 0) & 0xFF); 23629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed return -EINVAL; 23729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed } 23829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed return 0; 239202a77d28ac251545f6f998a974690212309b927Iliyan Malchev } 240202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 24129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed static private_handle_t* dynamicCast(const native_handle* in) { 24229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed if (validate(in) == 0) { 24329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed return (private_handle_t*) in; 24429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed } 24529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed return NULL; 246202a77d28ac251545f6f998a974690212309b927Iliyan Malchev } 247202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#endif 24829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed }; 249202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 250202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#endif /* GRALLOC_PRIV_H_ */ 251