blob: b6d4021c3f4cbbea4f08424667c7ce29b50ad0c0 [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
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080023#include <memory>
24
Dan Stoza8deb4da2016-06-01 18:21:44 -070025#include <ui/Gralloc1.h>
26
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027#include <utils/Singleton.h>
28
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080029
30// Needed by code that still uses the GRALLOC_USAGE_* constants.
31// when/if we get rid of gralloc, we should provide aliases or fix call sites.
32#include <hardware/gralloc.h>
33
34
Mathias Agopian076b1cc2009-04-10 14:24:30 -070035namespace android {
36
37// ---------------------------------------------------------------------------
38
Chia-I Wu9ba189d2016-09-22 17:13:08 +080039namespace Gralloc2 {
40class Mapper;
41}
42
Mathias Agopian076b1cc2009-04-10 14:24:30 -070043class Rect;
44
Mathias Agopian3330b202009-10-05 17:07:12 -070045class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070046{
47public:
Mathias Agopian3330b202009-10-05 17:07:12 -070048 static inline GraphicBufferMapper& get() { return getInstance(); }
Mathias Agopian0926f502009-05-04 14:17:04 -070049
Chia-I Wu7bd8adb2017-02-10 14:53:12 -080050 // This may NOT work on devices without a valid Gralloc2::Mapper.
Mathias Agopian0926f502009-05-04 14:17:04 -070051 status_t registerBuffer(buffer_handle_t handle);
Chia-I Wu7bd8adb2017-02-10 14:53:12 -080052
Dan Stoza8deb4da2016-06-01 18:21:44 -070053 status_t registerBuffer(const GraphicBuffer* buffer);
Mathias Agopian0926f502009-05-04 14:17:04 -070054
55 status_t unregisterBuffer(buffer_handle_t handle);
Dan Stoza303b9a52014-11-17 12:03:59 -080056
Craig Donner58a1ef22017-02-02 12:40:05 -080057 status_t getDimensions(buffer_handle_t handle,
58 uint32_t* outWidth, uint32_t* outHeight) const;
59
60 status_t getFormat(buffer_handle_t handle, int32_t* outFormat) const;
61
62 status_t getLayerCount(buffer_handle_t handle,
63 uint32_t* outLayerCount) const;
64
65 status_t getProducerUsage(buffer_handle_t handle,
66 uint64_t* outProducerUsage) const;
67
68 status_t getConsumerUsage(buffer_handle_t handle,
69 uint64_t* outConsumerUsage) const;
70
71 status_t getBackingStore(buffer_handle_t handle,
72 uint64_t* outBackingStore) const;
73
74 status_t getStride(buffer_handle_t handle, uint32_t* outStride) const;
75
Mathias Agopian0926f502009-05-04 14:17:04 -070076 status_t lock(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080077 uint32_t usage, const Rect& bounds, void** vaddr);
Mathias Agopian0926f502009-05-04 14:17:04 -070078
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070079 status_t lockYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080080 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070081
Mathias Agopian076b1cc2009-04-10 14:24:30 -070082 status_t unlock(buffer_handle_t handle);
Francis Hart8f396012014-04-01 15:30:53 +030083
84 status_t lockAsync(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080085 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030086
Craig Donnere96a3252017-02-02 12:13:34 -080087 status_t lockAsync(buffer_handle_t handle,
88 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds,
89 void** vaddr, int fenceFd);
90
Francis Hart8f396012014-04-01 15:30:53 +030091 status_t lockAsyncYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080092 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
93 int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030094
95 status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
Dan Stoza303b9a52014-11-17 12:03:59 -080096
Chia-I Wu9ba189d2016-09-22 17:13:08 +080097 const Gralloc2::Mapper& getGrallocMapper() const
98 {
99 return *mMapper;
100 }
101
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700102private:
Mathias Agopian3330b202009-10-05 17:07:12 -0700103 friend class Singleton<GraphicBufferMapper>;
Dan Stoza8deb4da2016-06-01 18:21:44 -0700104
Mathias Agopian3330b202009-10-05 17:07:12 -0700105 GraphicBufferMapper();
Dan Stoza8deb4da2016-06-01 18:21:44 -0700106
Chia-I Wu9ba189d2016-09-22 17:13:08 +0800107 const std::unique_ptr<const Gralloc2::Mapper> mMapper;
108
Dan Stoza8deb4da2016-06-01 18:21:44 -0700109 std::unique_ptr<Gralloc1::Loader> mLoader;
110 std::unique_ptr<Gralloc1::Device> mDevice;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700111};
112
113// ---------------------------------------------------------------------------
114
115}; // namespace android
116
117#endif // ANDROID_UI_BUFFER_MAPPER_H
118