Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 | |
Vishnu Nair | 40d8001 | 2024-07-13 23:25:06 +0000 | [diff] [blame] | 17 | #include <common/trace.h> |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 18 | #include <log/log.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 19 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 20 | #include <renderengine/impl/ExternalTexture.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 21 | #include <ui/GraphicBuffer.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 22 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 23 | namespace android::renderengine::impl { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 24 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 25 | ExternalTexture::ExternalTexture(const sp<GraphicBuffer>& buffer, |
| 26 | renderengine::RenderEngine& renderEngine, uint32_t usage) |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 27 | : mBuffer(buffer), mRenderEngine(renderEngine), mWritable(usage & WRITEABLE) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 28 | LOG_ALWAYS_FATAL_IF(buffer == nullptr, |
| 29 | "Attempted to bind a null buffer to an external texture!"); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 30 | mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | ExternalTexture::~ExternalTexture() { |
Alec Mouri | 92f89fa | 2023-02-24 00:05:06 +0000 | [diff] [blame] | 34 | mRenderEngine.unmapExternalTextureBuffer(std::move(mBuffer)); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 37 | void ExternalTexture::remapBuffer() { |
Vishnu Nair | 40d8001 | 2024-07-13 23:25:06 +0000 | [diff] [blame] | 38 | SFTRACE_CALL(); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 39 | { |
| 40 | auto buf = mBuffer; |
| 41 | mRenderEngine.unmapExternalTextureBuffer(std::move(buf)); |
| 42 | } |
| 43 | mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable); |
| 44 | } |
| 45 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 46 | } // namespace android::renderengine::impl |