|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 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 | +#include "Lifetimes.h" |
| 18 | + |
| 19 | +#include "backend/Platform.h" |
| 20 | +#include "private/backend/DriverApi.h" |
| 21 | + |
| 22 | +RenderFrame::RenderFrame(filament::backend::DriverApi& api): mApi(api) { |
| 23 | + mApi.beginFrame(0, 0, 0); |
| 24 | +} |
| 25 | + |
| 26 | +RenderFrame::~RenderFrame() { |
| 27 | + mApi.endFrame(0); |
| 28 | +} |
| 29 | + |
| 30 | +Cleanup::Cleanup(filament::backend::DriverApi& driverApi) : mDriverApi(driverApi) {} |
| 31 | + |
| 32 | +Cleanup::~Cleanup() { |
| 33 | + for (const auto swapChain: mSwapChains) { |
| 34 | + mDriverApi.destroySwapChain(swapChain); |
| 35 | + } |
| 36 | + for (const auto descriptorSet : mDescriptorSets) { |
| 37 | + mDriverApi.destroyDescriptorSet(descriptorSet); |
| 38 | + } |
| 39 | + for (const auto descriptorSetLayout : mDescriptorSetLayouts) { |
| 40 | + mDriverApi.destroyDescriptorSetLayout(descriptorSetLayout); |
| 41 | + } |
| 42 | + for (const auto bufferObject : mBufferObjects) { |
| 43 | + mDriverApi.destroyBufferObject(bufferObject); |
| 44 | + } |
| 45 | + for (const auto program : mPrograms) { |
| 46 | + mDriverApi.destroyProgram(program); |
| 47 | + } |
| 48 | + for (const auto texture : mTextures) { |
| 49 | + mDriverApi.destroyTexture(texture); |
| 50 | + } |
| 51 | + for (const auto renderTarget : mRenderTargets) { |
| 52 | + mDriverApi.destroyRenderTarget(renderTarget); |
| 53 | + } |
| 54 | + |
| 55 | + for (const auto& callback : mCallbacks) { |
| 56 | + callback(); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +template <> |
| 61 | +void Cleanup::addInternal(filament::backend::SwapChainHandle handle) { |
| 62 | + mSwapChains.push_back(handle); |
| 63 | +} |
| 64 | +template <> |
| 65 | +void Cleanup::addInternal(filament::backend::DescriptorSetHandle handle) { |
| 66 | + mDescriptorSets.push_back(handle); |
| 67 | +} |
| 68 | +template <> |
| 69 | +void Cleanup::addInternal( |
| 70 | + filament::backend::DescriptorSetLayoutHandle handle) { |
| 71 | + mDescriptorSetLayouts.push_back(handle); |
| 72 | +} |
| 73 | +template <> |
| 74 | +void Cleanup::addInternal(filament::backend::BufferObjectHandle handle) { |
| 75 | + mBufferObjects.push_back(handle); |
| 76 | +} |
| 77 | +template <> |
| 78 | +void Cleanup::addInternal(filament::backend::ProgramHandle handle) { |
| 79 | + mPrograms.push_back(handle); |
| 80 | +} |
| 81 | +template <> |
| 82 | +void Cleanup::addInternal(filament::backend::TextureHandle handle) { |
| 83 | + mTextures.push_back(handle); |
| 84 | +} |
| 85 | +template <> |
| 86 | +void Cleanup::addInternal(filament::backend::RenderTargetHandle handle) { |
| 87 | + mRenderTargets.push_back(handle); |
| 88 | +} |
| 89 | + |
| 90 | +void Cleanup::addPostCall(std::function<void()> callback){ |
| 91 | + mCallbacks.emplace_back(std::move(callback)); |
| 92 | +} |
0 commit comments