Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 1 | /* |
| 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 Gaillard | 52f95ff | 2024-04-23 12:58:59 +0100 | [diff] [blame] | 22 | #include <ui/ANativeObjectBase.h> |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 23 | #include <ui/PixelFormat.h> |
| 24 | #include <ui/Rect.h> |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 25 | #include <utils/RefBase.h> |
| 26 | |
Jerome Gaillard | c935f27 | 2024-04-23 14:26:29 +0100 | [diff] [blame^] | 27 | #include <vector> |
| 28 | |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 29 | namespace android { |
| 30 | |
Jerome Gaillard | 52f95ff | 2024-04-23 12:58:59 +0100 | [diff] [blame] | 31 | class GraphicBuffer : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase> { |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 32 | public: |
Jerome Gaillard | 52f95ff | 2024-04-23 12:58:59 +0100 | [diff] [blame] | 33 | GraphicBuffer(uint32_t w, uint32_t h) { |
Jerome Gaillard | c935f27 | 2024-04-23 14:26:29 +0100 | [diff] [blame^] | 34 | data.resize(w * h); |
Jerome Gaillard | 52f95ff | 2024-04-23 12:58:59 +0100 | [diff] [blame] | 35 | reserved[0] = data.data(); |
| 36 | width = w; |
| 37 | height = h; |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 38 | } |
Jerome Gaillard | 52f95ff | 2024-04-23 12:58:59 +0100 | [diff] [blame] | 39 | |
Jerome Gaillard | c935f27 | 2024-04-23 14:26:29 +0100 | [diff] [blame^] | 40 | uint32_t getWidth() const { |
| 41 | return static_cast<uint32_t>(width); |
| 42 | } |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 43 | |
Jerome Gaillard | c935f27 | 2024-04-23 14:26:29 +0100 | [diff] [blame^] | 44 | 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 Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 67 | |
| 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 Gaillard | c935f27 | 2024-04-23 14:26:29 +0100 | [diff] [blame^] | 74 | status_t unlockAsync(int* fenceFd) { |
| 75 | return OK; |
| 76 | } |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 77 | |
| 78 | private: |
Fedor Kudasov | 15e58b4 | 2019-07-04 17:52:39 +0100 | [diff] [blame] | 79 | std::vector<uint32_t> data; |
| 80 | }; |
| 81 | |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_GRAPHIC_BUFFER_H |