12ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu/* 22ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> 32ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * Copyright (C) 2010-2011 LunarG Inc. 42ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * 52ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * Permission is hereby granted, free of charge, to any person obtaining a 62ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * copy of this software and associated documentation files (the "Software"), 72ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * to deal in the Software without restriction, including without limitation 82ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * the rights to use, copy, modify, merge, publish, distribute, sublicense, 92ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * and/or sell copies of the Software, and to permit persons to whom the 102ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * Software is furnished to do so, subject to the following conditions: 112ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * 122ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * The above copyright notice and this permission notice shall be included 132ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * in all copies or substantial portions of the Software. 142ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * 152ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 162ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 172ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 182ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 192ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 202ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 212ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu * DEALINGS IN THE SOFTWARE. 222ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu */ 232ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 242ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#ifndef _GRALLOC_DRM_HANDLE_H_ 252ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#define _GRALLOC_DRM_HANDLE_H_ 262ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 2731b96bf8cedee688b2b15ca990805d983c9158c1Ben Chan#include <cutils/log.h> 282ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#include <cutils/native_handle.h> 293e00d3255ba6de08761a6b8f40b838680d502d0bSean V Kelley#include <system/graphics.h> 302ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 314b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#ifdef __cplusplus 324b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huangextern "C" { 334b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#endif 344b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang 3568a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huangstruct gralloc_drm_bo_t; 3668a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huang 372ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wustruct gralloc_drm_handle_t { 382ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu native_handle_t base; 392ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 40879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul /* file descriptors */ 41879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul int prime_fd; 42879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul 43879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul /* integers */ 442ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int magic; 452ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 462ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int width; 472ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int height; 482ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int format; 492ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int usage; 502ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 512ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int name; /* the name of the bo */ 522ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu int stride; /* the stride in bytes */ 532ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 5468a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huang struct gralloc_drm_bo_t *data; /* pointer to struct gralloc_drm_bo_t */ 55879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul 56879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul // FIXME: the attributes below should be out-of-line 57879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul uint64_t unknown __attribute__((aligned(8))); 58879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul int data_owner; /* owner of data (for validation) */ 592ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu}; 60879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_MAGIC 0x12345678 61879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_NUM_FDS 1 62879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_NUM_INTS ( \ 63879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int)) \ 64879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul - GRALLOC_DRM_HANDLE_NUM_FDS) 652ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 662ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wustatic inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle) 672ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu{ 682ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu struct gralloc_drm_handle_t *handle = 692ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu (struct gralloc_drm_handle_t *) _handle; 702ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 7175ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu if (handle && (handle->base.version != sizeof(handle->base) || 7275ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu handle->base.numInts != GRALLOC_DRM_HANDLE_NUM_INTS || 7375ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu handle->base.numFds != GRALLOC_DRM_HANDLE_NUM_FDS || 74879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul handle->magic != GRALLOC_DRM_HANDLE_MAGIC)) { 75879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x", 76879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul handle->base.version, handle->base.numInts, 77879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul handle->base.numFds, handle->magic); 782ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu handle = NULL; 79879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul } 802ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 812ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu return handle; 822ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu} 832ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu 845a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan/* 855a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan * The functions supported by gralloc_drm's temporary private API are listed 865a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan * below. Use of these functions is highly discouraged and should only be 875a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan * reserved for cases where no alternative to get same information (such as 885a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan * querying ANativeWindow) exists. 895a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan */ 905a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tanenum { 915a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan GRALLOC_DRM_GET_STRIDE, 925a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan GRALLOC_DRM_GET_FORMAT, 935a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan GRALLOC_DRM_GET_DIMENSIONS, 945a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan GRALLOC_DRM_GET_BACKING_STORE, 955a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan}; 965a1d7decd7bf60ba0c389687d2fc9210363eb922Garfield Tan 974b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#ifdef __cplusplus 984b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang} 994b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#endif 1002ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#endif /* _GRALLOC_DRM_HANDLE_H_ */ 101