blob: eec9b235cd6a7a03eca0d7351025f05c4b9708d9 [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>
22
23#include <vector>
24
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010025#include <ui/ANativeObjectBase.h>
Fedor Kudasov15e58b42019-07-04 17:52:39 +010026#include <ui/PixelFormat.h>
27#include <ui/Rect.h>
Fedor Kudasov15e58b42019-07-04 17:52:39 +010028#include <utils/RefBase.h>
29
30namespace android {
31
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010032class GraphicBuffer : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase> {
Fedor Kudasov15e58b42019-07-04 17:52:39 +010033public:
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010034 GraphicBuffer(uint32_t w, uint32_t h) {
Fedor Kudasov15e58b42019-07-04 17:52:39 +010035 data.resize(w*h);
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010036 reserved[0] = data.data();
37 width = w;
38 height = h;
Fedor Kudasov15e58b42019-07-04 17:52:39 +010039 }
40 uint32_t getWidth() const { return static_cast<uint32_t>(width); }
41 uint32_t getHeight() const { return static_cast<uint32_t>(height); }
42 uint32_t getStride() const { return static_cast<uint32_t>(width); }
43 uint64_t getUsage() const { return 0; }
44 PixelFormat getPixelFormat() const { return PIXEL_FORMAT_RGBA_8888; }
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010045
Fedor Kudasov15e58b42019-07-04 17:52:39 +010046 Rect getBounds() const { return Rect(width, height); }
47
48 status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
49 android_ycbcr *ycbcr, int fenceFd) { return OK; }
50
51 status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, int fenceFd,
52 int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr) {
53 *vaddr = data.data();
54 return OK;
55 }
56
57 status_t unlockAsync(int *fenceFd) { return OK; }
58
59private:
Fedor Kudasov15e58b42019-07-04 17:52:39 +010060 std::vector<uint32_t> data;
61};
62
63}; // namespace android
64
65#endif // ANDROID_GRAPHIC_BUFFER_H