blob: 8e93f724ffce1ff9de25ccae8e92ead716f63901 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
2 * Copyright (C) 2007 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 ANDROID_UI_BUFFER_MAPPER_H
18#define ANDROID_UI_BUFFER_MAPPER_H
19
20#include <stdint.h>
21#include <sys/types.h>
Mathias Agopian8b765b72009-04-10 20:34:46 -070022
Dan Stoza8deb4da2016-06-01 18:21:44 -070023#include <ui/Gralloc1.h>
24
Mathias Agopian076b1cc2009-04-10 14:24:30 -070025#include <utils/Singleton.h>
26
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027namespace android {
28
29// ---------------------------------------------------------------------------
30
Chia-I Wu9ba189d2016-09-22 17:13:08 +080031namespace Gralloc2 {
32class Mapper;
33}
34
Mathias Agopian076b1cc2009-04-10 14:24:30 -070035class Rect;
36
Mathias Agopian3330b202009-10-05 17:07:12 -070037class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070038{
39public:
Mathias Agopian3330b202009-10-05 17:07:12 -070040 static inline GraphicBufferMapper& get() { return getInstance(); }
Mathias Agopian0926f502009-05-04 14:17:04 -070041
42 status_t registerBuffer(buffer_handle_t handle);
Dan Stoza8deb4da2016-06-01 18:21:44 -070043 status_t registerBuffer(const GraphicBuffer* buffer);
Mathias Agopian0926f502009-05-04 14:17:04 -070044
45 status_t unregisterBuffer(buffer_handle_t handle);
Dan Stoza303b9a52014-11-17 12:03:59 -080046
Craig Donner58a1ef22017-02-02 12:40:05 -080047 status_t getDimensions(buffer_handle_t handle,
48 uint32_t* outWidth, uint32_t* outHeight) const;
49
50 status_t getFormat(buffer_handle_t handle, int32_t* outFormat) const;
51
52 status_t getLayerCount(buffer_handle_t handle,
53 uint32_t* outLayerCount) const;
54
55 status_t getProducerUsage(buffer_handle_t handle,
56 uint64_t* outProducerUsage) const;
57
58 status_t getConsumerUsage(buffer_handle_t handle,
59 uint64_t* outConsumerUsage) const;
60
61 status_t getBackingStore(buffer_handle_t handle,
62 uint64_t* outBackingStore) const;
63
64 status_t getStride(buffer_handle_t handle, uint32_t* outStride) const;
65
Mathias Agopian0926f502009-05-04 14:17:04 -070066 status_t lock(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080067 uint32_t usage, const Rect& bounds, void** vaddr);
Mathias Agopian0926f502009-05-04 14:17:04 -070068
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070069 status_t lockYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080070 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070071
Mathias Agopian076b1cc2009-04-10 14:24:30 -070072 status_t unlock(buffer_handle_t handle);
Francis Hart8f396012014-04-01 15:30:53 +030073
74 status_t lockAsync(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080075 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030076
Craig Donnere96a3252017-02-02 12:13:34 -080077 status_t lockAsync(buffer_handle_t handle,
78 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds,
79 void** vaddr, int fenceFd);
80
Francis Hart8f396012014-04-01 15:30:53 +030081 status_t lockAsyncYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080082 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
83 int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030084
85 status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
Dan Stoza303b9a52014-11-17 12:03:59 -080086
Chia-I Wu9ba189d2016-09-22 17:13:08 +080087 const Gralloc2::Mapper& getGrallocMapper() const
88 {
89 return *mMapper;
90 }
91
Mathias Agopian076b1cc2009-04-10 14:24:30 -070092private:
Mathias Agopian3330b202009-10-05 17:07:12 -070093 friend class Singleton<GraphicBufferMapper>;
Dan Stoza8deb4da2016-06-01 18:21:44 -070094
Mathias Agopian3330b202009-10-05 17:07:12 -070095 GraphicBufferMapper();
Dan Stoza8deb4da2016-06-01 18:21:44 -070096
Chia-I Wu9ba189d2016-09-22 17:13:08 +080097 const std::unique_ptr<const Gralloc2::Mapper> mMapper;
98
Dan Stoza8deb4da2016-06-01 18:21:44 -070099 std::unique_ptr<Gralloc1::Loader> mLoader;
100 std::unique_ptr<Gralloc1::Device> mDevice;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700101};
102
103// ---------------------------------------------------------------------------
104
105}; // namespace android
106
107#endif // ANDROID_UI_BUFFER_MAPPER_H
108