blob: d69f8fcaf94908a2d60b802875d039e87bbdaae4 [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 Wu5bac7f32017-04-06 12:34:32 -070050 // The imported outHandle must be freed with freeBuffer when no longer
51 // needed. rawHandle is owned by the caller.
52 status_t importBuffer(buffer_handle_t rawHandle,
53 buffer_handle_t* outHandle);
Chia-I Wu7bd8adb2017-02-10 14:53:12 -080054
Chia-I Wu5bac7f32017-04-06 12:34:32 -070055 // This is temporary and will be removed soon
56 status_t importBuffer(const GraphicBuffer* buffer);
Mathias Agopian0926f502009-05-04 14:17:04 -070057
Chia-I Wu5bac7f32017-04-06 12:34:32 -070058 status_t freeBuffer(buffer_handle_t handle);
Craig Donner58a1ef22017-02-02 12:40:05 -080059
Mathias Agopian0926f502009-05-04 14:17:04 -070060 status_t lock(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080061 uint32_t usage, const Rect& bounds, void** vaddr);
Mathias Agopian0926f502009-05-04 14:17:04 -070062
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070063 status_t lockYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080064 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070065
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 status_t unlock(buffer_handle_t handle);
Francis Hart8f396012014-04-01 15:30:53 +030067
68 status_t lockAsync(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080069 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030070
Craig Donnere96a3252017-02-02 12:13:34 -080071 status_t lockAsync(buffer_handle_t handle,
72 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds,
73 void** vaddr, int fenceFd);
74
Francis Hart8f396012014-04-01 15:30:53 +030075 status_t lockAsyncYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080076 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
77 int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030078
79 status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
Dan Stoza303b9a52014-11-17 12:03:59 -080080
Chia-I Wu9ba189d2016-09-22 17:13:08 +080081 const Gralloc2::Mapper& getGrallocMapper() const
82 {
83 return *mMapper;
84 }
85
Mathias Agopian076b1cc2009-04-10 14:24:30 -070086private:
Mathias Agopian3330b202009-10-05 17:07:12 -070087 friend class Singleton<GraphicBufferMapper>;
Dan Stoza8deb4da2016-06-01 18:21:44 -070088
Mathias Agopian3330b202009-10-05 17:07:12 -070089 GraphicBufferMapper();
Dan Stoza8deb4da2016-06-01 18:21:44 -070090
Chia-I Wu9ba189d2016-09-22 17:13:08 +080091 const std::unique_ptr<const Gralloc2::Mapper> mMapper;
92
Dan Stoza8deb4da2016-06-01 18:21:44 -070093 std::unique_ptr<Gralloc1::Loader> mLoader;
94 std::unique_ptr<Gralloc1::Device> mDevice;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070095};
96
97// ---------------------------------------------------------------------------
98
99}; // namespace android
100
101#endif // ANDROID_UI_BUFFER_MAPPER_H
102