Debian Codegraph @

tools/gpu/vk/VkYcbcrSamplerHelper.h

raw
1 /*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef VkYcbcrSamplerHelper_DEFINED
9 #define VkYcbcrSamplerHelper_DEFINED
10
11 #include "include/core/SkTypes.h"
12
13 #ifdef SK_VULKAN
14
15 #if defined(SK_GRAPHITE)
16 #include "include/gpu/graphite/BackendTexture.h"
17 #endif
18
19 #if defined (SK_GANESH)
20 #include "include/gpu/ganesh/GrBackendSurface.h"
21 #include "include/gpu/ganesh/vk/GrVkTypes.h"
22 #endif
23
24 #include "include/gpu/vk/VulkanTypes.h"
25
26 namespace skgpu::graphite {
27 class Recorder;
28 class VulkanSharedContext;
29 }
30
31 class GrDirectContext;
32 class GrVkGpu;
33 class GrBackendTexture;
34
35 // This helper will create and hold data for a Vulkan YCbCr backend texture. This format is
36 // particularly interesting because its sampler is immutable.
37 class VkYcbcrSamplerHelper {
38 public:
39 #if defined(SK_GRAPHITE)
40 VkYcbcrSamplerHelper(const skgpu::graphite::VulkanSharedContext* ctxt)
41 : fSharedCtxt(ctxt) {
42 SkASSERT(ctxt);
43 }
44
45 const skgpu::graphite::BackendTexture& backendTexture() const { return fTexture; }
46
47 bool createBackendTexture(uint32_t width, uint32_t height);
48 #endif
49
50 #if defined(SK_GANESH)
51 VkYcbcrSamplerHelper(GrDirectContext*);
52 #endif
53
54 ~VkYcbcrSamplerHelper();
55
56 bool isYCbCrSupported();
57
58 #if defined(SK_GANESH)
59 const GrBackendTexture& grBackendTexture() const { return fGrTexture; }
60 bool createGrBackendTexture(uint32_t width, uint32_t height);
61 #endif
62
63 static int GetExpectedY(int x, int y, int width, int height);
64 static std::pair<int, int> GetExpectedUV(int x, int y, int width, int height);
65
66 private:
67 #if defined(SK_GRAPHITE)
68 skgpu::graphite::BackendTexture fTexture;
69 const skgpu::graphite::VulkanSharedContext* fSharedCtxt = nullptr;
70 #endif
71
72 #if defined(SK_GANESH)
73 GrVkGpu* vkGpu();
74
75 GrDirectContext* fDContext = nullptr;
76 GrBackendTexture fGrTexture;
77 #endif
78
79 VkImage fImage = VK_NULL_HANDLE;
80 VkDeviceMemory fImageMemory = VK_NULL_HANDLE;
81 };
82
83 #endif // SK_VULKAN
84 #endif // VkYcbcrSamplerHelper_DEFINED