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
272ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#include <cutils/native_handle.h>
283e00d3255ba6de08761a6b8f40b838680d502d0bSean V Kelley#include <system/graphics.h>
292ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
304b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#ifdef __cplusplus
314b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huangextern "C" {
324b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#endif
334b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang
3468a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huangstruct gralloc_drm_bo_t;
3568a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huang
362ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wustruct gralloc_drm_handle_t {
372ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	native_handle_t base;
382ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
39879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	/* file descriptors */
40879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	int prime_fd;
41879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul
42879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	/* integers */
432ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int magic;
442ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
452ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int width;
462ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int height;
472ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int format;
482ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int usage;
492ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
502ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int name;   /* the name of the bo */
512ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	int stride; /* the stride in bytes */
522ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
5368a74eb31f139ad285a49451cf2ca8271c54f9bbChih-Wei Huang	struct gralloc_drm_bo_t *data; /* pointer to struct gralloc_drm_bo_t */
54879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul
55879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	// FIXME: the attributes below should be out-of-line
56879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	uint64_t unknown __attribute__((aligned(8)));
57879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	int data_owner; /* owner of data (for validation) */
582ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu};
59879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_MAGIC 0x12345678
60879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_NUM_FDS 1
61879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul#define GRALLOC_DRM_HANDLE_NUM_INTS (						\
62879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int))	\
63879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	 - GRALLOC_DRM_HANDLE_NUM_FDS)
642ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
652ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wustatic inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
662ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu{
672ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	struct gralloc_drm_handle_t *handle =
682ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu		(struct gralloc_drm_handle_t *) _handle;
692ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
7075ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu	if (handle && (handle->base.version != sizeof(handle->base) ||
7175ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu	               handle->base.numInts != GRALLOC_DRM_HANDLE_NUM_INTS ||
7275ee75c2115109c1385677c8a92f8ace27a48b60Chia-I Wu	               handle->base.numFds != GRALLOC_DRM_HANDLE_NUM_FDS ||
73879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	               handle->magic != GRALLOC_DRM_HANDLE_MAGIC)) {
74879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul		ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x",
75879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul			handle->base.version, handle->base.numInts,
76879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul			handle->base.numFds, handle->magic);
772ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu		handle = NULL;
78879cc4e7c6da5ecf631d65ddd98d12bccd5817f5Sean Paul	}
792ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
802ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu	return handle;
812ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu}
822ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu
834b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#ifdef __cplusplus
844b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang}
854b3db54505933738ec33f92ec7e2c5304cb18325Chih-Wei Huang#endif
862ec32d4f949f04d0006fff50065c904626c2e58Chia-I Wu#endif /* _GRALLOC_DRM_HANDLE_H_ */
87