blob: 210dca54290155d20ad740960300a62f7b835232 [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
Alec Mouria90a5702021-04-16 16:36:21 +000017#include <renderengine/RenderEngine.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080018#include <renderengine/impl/ExternalTexture.h>
Alec Mouria90a5702021-04-16 16:36:21 +000019#include <ui/GraphicBuffer.h>
20
21#include "log/log_main.h"
22
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 Mouria90a5702021-04-16 16:36:21 +000027 : mBuffer(buffer), mRenderEngine(renderEngine) {
28 LOG_ALWAYS_FATAL_IF(buffer == nullptr,
29 "Attempted to bind a null buffer to an external texture!");
30 // GLESRenderEngine has a separate texture cache for output buffers,
Vishnu Nairdbbe3852022-01-12 20:22:11 -080031 if (usage == WRITEABLE &&
32 (mRenderEngine.getRenderEngineType() ==
33 renderengine::RenderEngine::RenderEngineType::GLES ||
34 mRenderEngine.getRenderEngineType() ==
35 renderengine::RenderEngine::RenderEngineType::THREADED)) {
Alec Mouria90a5702021-04-16 16:36:21 +000036 return;
37 }
Vishnu Nairdbbe3852022-01-12 20:22:11 -080038 mRenderEngine.mapExternalTextureBuffer(mBuffer, usage & WRITEABLE);
Alec Mouria90a5702021-04-16 16:36:21 +000039}
40
41ExternalTexture::~ExternalTexture() {
Alec Mouri92f89fa2023-02-24 00:05:06 +000042 mRenderEngine.unmapExternalTextureBuffer(std::move(mBuffer));
Alec Mouria90a5702021-04-16 16:36:21 +000043}
44
Vishnu Nairdbbe3852022-01-12 20:22:11 -080045} // namespace android::renderengine::impl