blob: 4fc8e3c88e9e181144f763f689d43260deb1cbae [file] [log] [blame]
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05301/*
2 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
3
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __GR_DEVICE_IMPL_H__
31#define __GR_DEVICE_IMPL_H__
32
33#include <hardware/hardware.h>
34#include <hardware/gralloc1.h>
35#include "gr_buf_mgr.h"
36
37struct private_module_t {
38 hw_module_t base;
39};
40
41#define GRALLOC_IMPL(exp) reinterpret_cast<GrallocImpl const *>(exp)
42
43namespace gralloc1 {
44
45class GrallocImpl : public gralloc1_device_t {
46 public:
47 explicit GrallocImpl(const private_module_t *module);
48 ~GrallocImpl();
49 bool Init();
50 static int CloseDevice(hw_device_t *device);
51 static void GetCapabilities(struct gralloc1_device *device, uint32_t *out_count,
52 int32_t * /*gralloc1_capability_t*/ out_capabilities);
53 static gralloc1_function_pointer_t GetFunction(
54 struct gralloc1_device *device, int32_t /*gralloc1_function_descriptor_t*/ descriptor);
55
56 private:
57 static inline gralloc1_error_t CheckDeviceAndDescriptor(gralloc1_device_t *device,
58 gralloc1_buffer_descriptor_t descriptor);
59 static inline gralloc1_error_t CheckDeviceAndHandle(gralloc1_device_t *device,
60 buffer_handle_t buffer);
61 static gralloc1_error_t CreateBufferDescriptor(gralloc1_device_t *device,
62 gralloc1_buffer_descriptor_t *out_descriptor);
63 static gralloc1_error_t DestroyBufferDescriptor(gralloc1_device_t *device,
64 gralloc1_buffer_descriptor_t descriptor);
65 static gralloc1_error_t SetConsumerUsage(gralloc1_device_t *device,
66 gralloc1_buffer_descriptor_t descriptor,
67 gralloc1_consumer_usage_t usage);
68 static gralloc1_error_t SetBufferDimensions(gralloc1_device_t *device,
69 gralloc1_buffer_descriptor_t descriptor,
70 uint32_t width, uint32_t height);
71 static gralloc1_error_t SetColorFormat(gralloc1_device_t *device,
72 gralloc1_buffer_descriptor_t descriptor, int32_t format);
73 static gralloc1_error_t SetProducerUsage(gralloc1_device_t *device,
74 gralloc1_buffer_descriptor_t descriptor,
75 gralloc1_producer_usage_t usage);
76 static gralloc1_error_t GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer,
77 gralloc1_backing_store_t *out_store);
78 static gralloc1_error_t GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
79 gralloc1_consumer_usage_t *out_usage);
80 static gralloc1_error_t GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer,
81 uint32_t *out_width, uint32_t *out_height);
82 static gralloc1_error_t GetColorFormat(gralloc1_device_t *device, buffer_handle_t descriptor,
83 int32_t *outFormat);
84 static gralloc1_error_t GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
85 gralloc1_producer_usage_t *out_usage);
86 static gralloc1_error_t GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer,
87 uint32_t *out_stride);
88 static gralloc1_error_t AllocateBuffers(gralloc1_device_t *device, uint32_t num_dptors,
89 const gralloc1_buffer_descriptor_t *descriptors,
90 buffer_handle_t *out_buffers);
91 static gralloc1_error_t RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
92 static gralloc1_error_t ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
93 static gralloc1_error_t getNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
94 uint32_t *out_num_planes);
95 static gralloc1_error_t LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
96 gralloc1_producer_usage_t prod_usage,
97 gralloc1_consumer_usage_t cons_usage,
98 const gralloc1_rect_t *access_region, void **out_data,
99 int32_t acquire_fence);
100 static gralloc1_error_t LockFlex(gralloc1_device_t *device, buffer_handle_t buffer,
101 gralloc1_producer_usage_t prod_usage,
102 gralloc1_consumer_usage_t cons_usage,
103 const gralloc1_rect_t *access_region,
104 struct android_flex_layout *out_flex_layout,
105 int32_t acquireFence);
106 /* TODO(user) : LOCK_YCBCR changed to LOCK_FLEX but structure is not known yet.
107 * Need to implement after clarification from Google.
108 static gralloc1_error_t LockYCbCrBuffer(gralloc1_device_t* device, buffer_handle_t buffer,
109 gralloc1_producer_usage_t producerUsage, gralloc1_consumer_usage_t consumerUsage,
110 const gralloc1_rect_t* Region, struct android_ycbcr* outYCbCr, int32_t* outAcquireFence);
111 */
112 static gralloc1_error_t UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
113 int32_t *release_fence);
114 static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...);
115
116 BufferManager *buf_mgr_ = NULL;
117};
118
119} // namespace gralloc1
120
121#endif // __GR_DEVICE_IMPL_H__