blob: d3c0e675c18664232e4b345f4f276faf0188ff43 [file] [log] [blame]
Prabhanjan Kandula96e92342016-03-24 21:03:35 +05301/*
2 * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
3 * Not a Contribution
4 *
5 * Copyright (C) 2008 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#ifndef __GR_BUF_MGR_H__
21#define __GR_BUF_MGR_H__
22
23#include <pthread.h>
24#include <unordered_map>
25#include <mutex>
26
27#include "gralloc_priv.h"
28#include "gr_allocator.h"
29
30namespace gralloc1 {
31
32class BufferManager {
33 public:
34 BufferManager();
35 ~BufferManager();
36 bool Init();
37 gralloc1_error_t AllocateBuffers(uint32_t numDescriptors, const BufferDescriptor *descriptors,
38 buffer_handle_t *outBuffers);
39 gralloc1_error_t RetainBuffer(private_handle_t const *hnd);
40 gralloc1_error_t ReleaseBuffer(private_handle_t const *hnd);
41 gralloc1_error_t LockBuffer(const private_handle_t *hnd, gralloc1_producer_usage_t prod_usage,
42 gralloc1_consumer_usage_t cons_usage);
43 gralloc1_error_t UnlockBuffer(const private_handle_t *hnd);
44 gralloc1_error_t Perform(int operation, va_list args);
45
46 private:
47 gralloc1_error_t MapBuffer(private_handle_t const *hnd);
48 gralloc1_error_t FreeBuffer(private_handle_t const *hnd);
49 int GetBufferType(int format);
50 int AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
51 unsigned int bufferSize = 0);
52 int AllocateBuffer(unsigned int size, int aligned_w, int aligned_h, int real_w, int real_h,
53 int format, int bufferType, gralloc1_producer_usage_t prod_usage,
54 gralloc1_consumer_usage_t cons_usage, buffer_handle_t *handle);
55 int GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
56 gralloc1_consumer_usage_t cons_usage);
57 int GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
58 gralloc1_consumer_usage_t cons_usage);
59 void CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor,
60 buffer_handle_t *out_buffer);
61
62 bool map_fb_mem_ = false;
63 bool ubwc_for_fb_ = false;
64 Allocator *allocator_ = NULL;
65 std::mutex locker_;
66 std::unordered_map<private_handle_t const *, int> handles_map_ = {};
67};
68
69} // namespace gralloc1
70
71#endif // __GR_BUF_MGR_H__