blob: ca0dcbf4aeb4bd154a2fcfab309bb7ba8f5e8bfd [file] [log] [blame]
Ian Elliott1f0911e2022-09-09 16:31:47 -06001/*
2 * Copyright 2022 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 SF_SKIAVKRENDERENGINE_H_
18#define SF_SKIAVKRENDERENGINE_H_
19
20#include <vk/GrVkBackendContext.h>
21
22#include "SkiaRenderEngine.h"
Nolan Scobief52ad202024-03-06 18:18:28 -050023#include "VulkanInterface.h"
Ian Elliott1f0911e2022-09-09 16:31:47 -060024
25namespace android {
26namespace renderengine {
27namespace skia {
28
29class SkiaVkRenderEngine : public SkiaRenderEngine {
30public:
Ian Elliott1f0911e2022-09-09 16:31:47 -060031 static std::unique_ptr<SkiaVkRenderEngine> create(const RenderEngineCreationArgs& args);
32 ~SkiaVkRenderEngine() override;
33
34 int getContextPriority() override;
35
Nolan Scobief52ad202024-03-06 18:18:28 -050036 class DestroySemaphoreInfo {
37 public:
38 DestroySemaphoreInfo() = delete;
39 DestroySemaphoreInfo(const DestroySemaphoreInfo&) = delete;
40 DestroySemaphoreInfo& operator=(const DestroySemaphoreInfo&) = delete;
41 DestroySemaphoreInfo& operator=(DestroySemaphoreInfo&&) = delete;
42
43 DestroySemaphoreInfo(VulkanInterface& vulkanInterface, std::vector<VkSemaphore> semaphores)
44 : mVulkanInterface(vulkanInterface), mSemaphores(std::move(semaphores)) {}
45 DestroySemaphoreInfo(VulkanInterface& vulkanInterface, VkSemaphore semaphore)
46 : DestroySemaphoreInfo(vulkanInterface, std::vector<VkSemaphore>(1, semaphore)) {}
47
48 void unref() {
49 --mRefs;
50 if (!mRefs) {
51 for (VkSemaphore semaphore : mSemaphores) {
52 mVulkanInterface.destroySemaphore(semaphore);
53 }
54 delete this;
55 }
56 }
57
58 private:
59 ~DestroySemaphoreInfo() = default;
60
61 VulkanInterface& mVulkanInterface;
62 std::vector<VkSemaphore> mSemaphores;
63 // We need to make sure we don't delete the VkSemaphore until it is done being used by both
64 // Skia (including by the GPU) and inside SkiaVkRenderEngine. So we always start with two
65 // refs, one owned by Skia and one owned by the SkiaVkRenderEngine. The refs are decremented
66 // each time unref() is called on this object. Skia will call unref() once it is done with
67 // the semaphore and the GPU has finished work on the semaphore. SkiaVkRenderEngine calls
68 // unref() after sending the semaphore to Skia and exporting it if need be.
69 int mRefs = 2;
70 };
71
Ian Elliott1f0911e2022-09-09 16:31:47 -060072protected:
73 // Implementations of abstract SkiaRenderEngine functions specific to
74 // rendering backend
75 virtual SkiaRenderEngine::Contexts createDirectContexts(const GrContextOptions& options);
76 bool supportsProtectedContentImpl() const override;
77 bool useProtectedContextImpl(GrProtected isProtected) override;
78 void waitFence(GrDirectContext* grContext, base::borrowed_fd fenceFd) override;
79 base::unique_fd flushAndSubmit(GrDirectContext* context) override;
80 void appendBackendSpecificInfoToDump(std::string& result) override;
81
82private:
83 SkiaVkRenderEngine(const RenderEngineCreationArgs& args);
84 base::unique_fd flush();
85
86 GrVkBackendContext mBackendContext;
87};
88
89} // namespace skia
90} // namespace renderengine
91} // namespace android
92
Ian Elliottbe705072023-01-04 08:31:37 -070093#endif