blob: 8d0fbba2e0631e6766797d90f8361ac6ba23a82b [file] [log] [blame]
Alec Mouria90a5702021-04-16 16:36:21 +00001/*
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 Nair40d80012024-07-13 23:25:06 +000017#include <common/trace.h>
Alec Mouri74c7ae12023-03-26 02:57:47 +000018#include <log/log.h>
Alec Mouria90a5702021-04-16 16:36:21 +000019#include <renderengine/RenderEngine.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080020#include <renderengine/impl/ExternalTexture.h>
Alec Mouria90a5702021-04-16 16:36:21 +000021#include <ui/GraphicBuffer.h>
Alec Mouria90a5702021-04-16 16:36:21 +000022
Vishnu Nairdbbe3852022-01-12 20:22:11 -080023namespace android::renderengine::impl {
Alec Mouria90a5702021-04-16 16:36:21 +000024
Vishnu Nairdbbe3852022-01-12 20:22:11 -080025ExternalTexture::ExternalTexture(const sp<GraphicBuffer>& buffer,
26 renderengine::RenderEngine& renderEngine, uint32_t usage)
Alec Mouri74c7ae12023-03-26 02:57:47 +000027 : mBuffer(buffer), mRenderEngine(renderEngine), mWritable(usage & WRITEABLE) {
Alec Mouria90a5702021-04-16 16:36:21 +000028 LOG_ALWAYS_FATAL_IF(buffer == nullptr,
29 "Attempted to bind a null buffer to an external texture!");
Alec Mouri74c7ae12023-03-26 02:57:47 +000030 mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable);
Alec Mouria90a5702021-04-16 16:36:21 +000031}
32
33ExternalTexture::~ExternalTexture() {
Alec Mouri92f89fa2023-02-24 00:05:06 +000034 mRenderEngine.unmapExternalTextureBuffer(std::move(mBuffer));
Alec Mouria90a5702021-04-16 16:36:21 +000035}
36
Alec Mouri74c7ae12023-03-26 02:57:47 +000037void ExternalTexture::remapBuffer() {
Vishnu Nair40d80012024-07-13 23:25:06 +000038 SFTRACE_CALL();
Alec Mouri74c7ae12023-03-26 02:57:47 +000039 {
40 auto buf = mBuffer;
41 mRenderEngine.unmapExternalTextureBuffer(std::move(buf));
42 }
43 mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable);
44}
45
Vishnu Nairdbbe3852022-01-12 20:22:11 -080046} // namespace android::renderengine::impl