blob: e0702e96a1b81c34c1e4afd596aa5ac64a5c4918 [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
Mathias Agopian076b1cc2009-04-10 14:24:30 -070025#include <utils/Singleton.h>
26
Mathias Agopianfe2f54f2017-02-15 19:48:58 -080027
28// Needed by code that still uses the GRALLOC_USAGE_* constants.
29// when/if we get rid of gralloc, we should provide aliases or fix call sites.
30#include <hardware/gralloc.h>
31
32
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033namespace android {
34
35// ---------------------------------------------------------------------------
36
Chia-I Wu9ba189d2016-09-22 17:13:08 +080037namespace Gralloc2 {
38class Mapper;
39}
40
Mathias Agopian076b1cc2009-04-10 14:24:30 -070041class Rect;
42
Mathias Agopian3330b202009-10-05 17:07:12 -070043class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070044{
45public:
Mathias Agopian3330b202009-10-05 17:07:12 -070046 static inline GraphicBufferMapper& get() { return getInstance(); }
Mathias Agopian0926f502009-05-04 14:17:04 -070047
Chia-I Wu5bac7f32017-04-06 12:34:32 -070048 // The imported outHandle must be freed with freeBuffer when no longer
49 // needed. rawHandle is owned by the caller.
50 status_t importBuffer(buffer_handle_t rawHandle,
51 buffer_handle_t* outHandle);
Chia-I Wu7bd8adb2017-02-10 14:53:12 -080052
Chia-I Wu5bac7f32017-04-06 12:34:32 -070053 status_t freeBuffer(buffer_handle_t handle);
Craig Donner58a1ef22017-02-02 12:40:05 -080054
Mathias Agopian0926f502009-05-04 14:17:04 -070055 status_t lock(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080056 uint32_t usage, const Rect& bounds, void** vaddr);
Mathias Agopian0926f502009-05-04 14:17:04 -070057
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070058 status_t lockYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080059 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -070060
Mathias Agopian076b1cc2009-04-10 14:24:30 -070061 status_t unlock(buffer_handle_t handle);
Francis Hart8f396012014-04-01 15:30:53 +030062
63 status_t lockAsync(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080064 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030065
Craig Donnere96a3252017-02-02 12:13:34 -080066 status_t lockAsync(buffer_handle_t handle,
67 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds,
68 void** vaddr, int fenceFd);
69
Francis Hart8f396012014-04-01 15:30:53 +030070 status_t lockAsyncYCbCr(buffer_handle_t handle,
Dan Stoza303b9a52014-11-17 12:03:59 -080071 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
72 int fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +030073
74 status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
Dan Stoza303b9a52014-11-17 12:03:59 -080075
Chia-I Wu9ba189d2016-09-22 17:13:08 +080076 const Gralloc2::Mapper& getGrallocMapper() const
77 {
78 return *mMapper;
79 }
80
Mathias Agopian076b1cc2009-04-10 14:24:30 -070081private:
Mathias Agopian3330b202009-10-05 17:07:12 -070082 friend class Singleton<GraphicBufferMapper>;
Dan Stoza8deb4da2016-06-01 18:21:44 -070083
Mathias Agopian3330b202009-10-05 17:07:12 -070084 GraphicBufferMapper();
Dan Stoza8deb4da2016-06-01 18:21:44 -070085
Chia-I Wu9ba189d2016-09-22 17:13:08 +080086 const std::unique_ptr<const Gralloc2::Mapper> mMapper;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070087};
88
89// ---------------------------------------------------------------------------
90
91}; // namespace android
92
93#endif // ANDROID_UI_BUFFER_MAPPER_H
94