OSDN Git Service

1bd0e77f19afe0c245ba28c6bbc67c82704d9992
[android-x86/external-IA-Hardware-Composer.git] / os / android / gralloc1bufferhandler.h
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OS_ANDROID_Gralloc1BufferHandler_H_
18 #define OS_ANDROID_Gralloc1BufferHandler_H_
19
20 #include <nativebufferhandler.h>
21
22 #include <hardware/gralloc1.h>
23
24 #include <i915_private_android_types.h>
25
26 namespace hwcomposer {
27
28 class GpuDevice;
29
30 class Gralloc1BufferHandler : public NativeBufferHandler {
31  public:
32   explicit Gralloc1BufferHandler(uint32_t fd);
33   ~Gralloc1BufferHandler() override;
34
35   bool Init();
36
37   bool CreateBuffer(uint32_t w, uint32_t h, int format, HWCNativeHandle *handle,
38                     uint32_t layer_type) const override;
39   bool CanReleaseGemHandles(HWCNativeHandle handle) const;
40   bool ReleaseBuffer(HWCNativeHandle handle,
41                      bool release_gem_handles = false) const override;
42   void DestroyHandle(HWCNativeHandle handle) const override;
43   bool ImportBuffer(HWCNativeHandle handle) const override;
44   void CopyHandle(HWCNativeHandle source,
45                   HWCNativeHandle *target) const override;
46   uint32_t GetTotalPlanes(HWCNativeHandle handle) const override;
47   void *Map(HWCNativeHandle handle, uint32_t x, uint32_t y, uint32_t width,
48             uint32_t height, uint32_t *stride, void **map_data,
49             size_t plane) const override;
50   int32_t UnMap(HWCNativeHandle handle, void *map_data) const override;
51
52   uint32_t GetFd() const override {
53     return fd_;
54   }
55
56  private:
57   uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
58   uint32_t fd_;
59   const hw_module_t *gralloc_;
60   hw_device_t *device_;
61   GRALLOC1_PFN_RETAIN register_;
62   GRALLOC1_PFN_RELEASE release_;
63   GRALLOC1_PFN_GET_DIMENSIONS dimensions_;
64   GRALLOC1_PFN_LOCK lock_;
65   GRALLOC1_PFN_UNLOCK unlock_;
66   GRALLOC1_PFN_CREATE_DESCRIPTOR create_descriptor_;
67   GRALLOC1_PFN_DESTROY_DESCRIPTOR destroy_descriptor_;
68   GRALLOC1_PFN_SET_CONSUMER_USAGE set_consumer_usage_;
69   GRALLOC1_PFN_SET_DIMENSIONS set_dimensions_;
70   GRALLOC1_PFN_SET_FORMAT set_format_;
71   GRALLOC1_PFN_SET_PRODUCER_USAGE set_producer_usage_;
72   GRALLOC1_PFN_ALLOCATE allocate_;
73 };
74
75 }  // namespace hwcomposer
76 #endif  // OS_ANDROID_Gralloc1BufferHandler_H_