blob: 5fd911f876be1a84c61d98aa624299d24c1fd40b [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"
Nolan Scobiefc125ec2024-03-11 20:08:27 -040024#include "compat/SkiaGpuContext.h"
Ian Elliott1f0911e2022-09-09 16:31:47 -060025
26namespace android {
27namespace renderengine {
28namespace skia {
29
30class SkiaVkRenderEngine : public SkiaRenderEngine {
31public:
Ian Elliott1f0911e2022-09-09 16:31:47 -060032 static std::unique_ptr<SkiaVkRenderEngine> create(const RenderEngineCreationArgs& args);
33 ~SkiaVkRenderEngine() override;
34
35 int getContextPriority() override;
36
Nolan Scobief52ad202024-03-06 18:18:28 -050037 class DestroySemaphoreInfo {
38 public:
39 DestroySemaphoreInfo() = delete;
40 DestroySemaphoreInfo(const DestroySemaphoreInfo&) = delete;
41 DestroySemaphoreInfo& operator=(const DestroySemaphoreInfo&) = delete;
42 DestroySemaphoreInfo& operator=(DestroySemaphoreInfo&&) = delete;
43
44 DestroySemaphoreInfo(VulkanInterface& vulkanInterface, std::vector<VkSemaphore> semaphores)
45 : mVulkanInterface(vulkanInterface), mSemaphores(std::move(semaphores)) {}
46 DestroySemaphoreInfo(VulkanInterface& vulkanInterface, VkSemaphore semaphore)
47 : DestroySemaphoreInfo(vulkanInterface, std::vector<VkSemaphore>(1, semaphore)) {}
48
49 void unref() {
50 --mRefs;
51 if (!mRefs) {
52 for (VkSemaphore semaphore : mSemaphores) {
53 mVulkanInterface.destroySemaphore(semaphore);
54 }
55 delete this;
56 }
57 }
58
59 private:
60 ~DestroySemaphoreInfo() = default;
61
62 VulkanInterface& mVulkanInterface;
63 std::vector<VkSemaphore> mSemaphores;
64 // We need to make sure we don't delete the VkSemaphore until it is done being used by both
65 // Skia (including by the GPU) and inside SkiaVkRenderEngine. So we always start with two
66 // refs, one owned by Skia and one owned by the SkiaVkRenderEngine. The refs are decremented
67 // each time unref() is called on this object. Skia will call unref() once it is done with
68 // the semaphore and the GPU has finished work on the semaphore. SkiaVkRenderEngine calls
69 // unref() after sending the semaphore to Skia and exporting it if need be.
70 int mRefs = 2;
71 };
72
Ian Elliott1f0911e2022-09-09 16:31:47 -060073protected:
Nolan Scobie02c160c2024-03-18 10:40:23 -040074 // Redeclare parent functions that Ganesh vs. Graphite subclasses must implement.
75 virtual void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override = 0;
76 virtual base::unique_fd flushAndSubmit(SkiaGpuContext* context) override = 0;
77
78 SkiaVkRenderEngine(const RenderEngineCreationArgs& args);
79
Ian Elliott1f0911e2022-09-09 16:31:47 -060080 // Implementations of abstract SkiaRenderEngine functions specific to
Nolan Scobie02c160c2024-03-18 10:40:23 -040081 // Vulkan, but shareable between Ganesh and Graphite.
Nolan Scobiefc125ec2024-03-11 20:08:27 -040082 SkiaRenderEngine::Contexts createContexts() override;
Ian Elliott1f0911e2022-09-09 16:31:47 -060083 bool supportsProtectedContentImpl() const override;
84 bool useProtectedContextImpl(GrProtected isProtected) override;
Ian Elliott1f0911e2022-09-09 16:31:47 -060085 void appendBackendSpecificInfoToDump(std::string& result) override;
86
Nolan Scobie02c160c2024-03-18 10:40:23 -040087 // TODO: b/300533018 - refactor this to be non-static
88 static VulkanInterface& getVulkanInterface(bool protectedContext);
Ian Elliott1f0911e2022-09-09 16:31:47 -060089};
90
91} // namespace skia
92} // namespace renderengine
93} // namespace android
94
Ian Elliottbe705072023-01-04 08:31:37 -070095#endif