Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1 | /* |
| 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 Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 23 | #include "VulkanInterface.h" |
Nolan Scobie | fc125ec | 2024-03-11 20:08:27 -0400 | [diff] [blame] | 24 | #include "compat/SkiaGpuContext.h" |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace renderengine { |
| 28 | namespace skia { |
| 29 | |
| 30 | class SkiaVkRenderEngine : public SkiaRenderEngine { |
| 31 | public: |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 32 | ~SkiaVkRenderEngine() override; |
| 33 | |
| 34 | int getContextPriority() override; |
| 35 | |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 36 | 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 Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 72 | protected: |
Nolan Scobie | 342d394 | 2024-03-21 16:41:39 -0400 | [diff] [blame] | 73 | virtual std::unique_ptr<SkiaGpuContext> createContext(VulkanInterface& vulkanInterface) = 0; |
Nolan Scobie | 02c160c | 2024-03-18 10:40:23 -0400 | [diff] [blame] | 74 | // Redeclare parent functions that Ganesh vs. Graphite subclasses must implement. |
| 75 | virtual void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override = 0; |
Nolan Scobie | 1e06f2d | 2024-03-21 14:56:38 -0400 | [diff] [blame] | 76 | virtual base::unique_fd flushAndSubmit(SkiaGpuContext* context, |
| 77 | sk_sp<SkSurface> dstSurface) override = 0; |
Nolan Scobie | 02c160c | 2024-03-18 10:40:23 -0400 | [diff] [blame] | 78 | |
| 79 | SkiaVkRenderEngine(const RenderEngineCreationArgs& args); |
| 80 | |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 81 | // Implementations of abstract SkiaRenderEngine functions specific to |
Nolan Scobie | 02c160c | 2024-03-18 10:40:23 -0400 | [diff] [blame] | 82 | // Vulkan, but shareable between Ganesh and Graphite. |
Nolan Scobie | fc125ec | 2024-03-11 20:08:27 -0400 | [diff] [blame] | 83 | SkiaRenderEngine::Contexts createContexts() override; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 84 | bool supportsProtectedContentImpl() const override; |
| 85 | bool useProtectedContextImpl(GrProtected isProtected) override; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 86 | void appendBackendSpecificInfoToDump(std::string& result) override; |
| 87 | |
Nolan Scobie | 02c160c | 2024-03-18 10:40:23 -0400 | [diff] [blame] | 88 | // TODO: b/300533018 - refactor this to be non-static |
| 89 | static VulkanInterface& getVulkanInterface(bool protectedContext); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace skia |
| 93 | } // namespace renderengine |
| 94 | } // namespace android |
| 95 | |
Ian Elliott | be70507 | 2023-01-04 08:31:37 -0700 | [diff] [blame] | 96 | #endif |