blob: cda45e4660ca7a7045a3bc571759e323b2b9efb4 [file] [log] [blame]
Fedor Kudasov15e58b42019-07-04 17:52:39 +01001/*
2 * Copyright (C) 2019 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_GRAPHIC_BUFFER_H
18#define ANDROID_GRAPHIC_BUFFER_H
19
20#include <stdint.h>
21#include <sys/types.h>
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010022#include <ui/ANativeObjectBase.h>
Fedor Kudasov15e58b42019-07-04 17:52:39 +010023#include <ui/PixelFormat.h>
24#include <ui/Rect.h>
Fedor Kudasov15e58b42019-07-04 17:52:39 +010025#include <utils/RefBase.h>
26
Jerome Gaillardc935f272024-04-23 14:26:29 +010027#include <vector>
28
Fedor Kudasov15e58b42019-07-04 17:52:39 +010029namespace android {
30
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010031class GraphicBuffer : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase> {
Fedor Kudasov15e58b42019-07-04 17:52:39 +010032public:
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010033 GraphicBuffer(uint32_t w, uint32_t h) {
Jerome Gaillardc935f272024-04-23 14:26:29 +010034 data.resize(w * h);
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010035 reserved[0] = data.data();
36 width = w;
37 height = h;
Fedor Kudasov15e58b42019-07-04 17:52:39 +010038 }
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010039
Jerome Gaillardc935f272024-04-23 14:26:29 +010040 uint32_t getWidth() const {
41 return static_cast<uint32_t>(width);
42 }
Fedor Kudasov15e58b42019-07-04 17:52:39 +010043
Jerome Gaillardc935f272024-04-23 14:26:29 +010044 uint32_t getHeight() const {
45 return static_cast<uint32_t>(height);
46 }
47
48 uint32_t getStride() const {
49 return static_cast<uint32_t>(width);
50 }
51
52 uint64_t getUsage() const {
53 return 0;
54 }
55
56 PixelFormat getPixelFormat() const {
57 return PIXEL_FORMAT_RGBA_8888;
58 }
59
60 Rect getBounds() const {
61 return Rect(width, height);
62 }
63
64 status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, android_ycbcr* ycbcr, int fenceFd) {
65 return OK;
66 }
Fedor Kudasov15e58b42019-07-04 17:52:39 +010067
68 status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, int fenceFd,
69 int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr) {
70 *vaddr = data.data();
71 return OK;
72 }
73
Jerome Gaillardc935f272024-04-23 14:26:29 +010074 status_t unlockAsync(int* fenceFd) {
75 return OK;
76 }
Fedor Kudasov15e58b42019-07-04 17:52:39 +010077
78private:
Fedor Kudasov15e58b42019-07-04 17:52:39 +010079 std::vector<uint32_t> data;
80};
81
82}; // namespace android
83
84#endif // ANDROID_GRAPHIC_BUFFER_H