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