• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 namespace skgpu::graphite {
19 class Recorder;
20 class VulkanSharedContext;
21 }
22 #endif
23 
24 
25 #include "include/gpu/GrBackendSurface.h"
26 #include "include/gpu/vk/GrVkTypes.h"
27 
28 class GrDirectContext;
29 class GrVkGpu;
30 
31 // This helper will create and hold data for a Vulkan YCbCr backend texture. This format is
32 // particularly interesting because its sampler is immutable.
33 class VkYcbcrSamplerHelper {
34 public:
35 #if defined(SK_GRAPHITE)
VkYcbcrSamplerHelper(const skgpu::graphite::VulkanSharedContext * ctxt,VkPhysicalDevice physDev)36     VkYcbcrSamplerHelper(const skgpu::graphite::VulkanSharedContext* ctxt,
37                          VkPhysicalDevice physDev)
38             : fSharedCtxt(ctxt)
39             , fPhysDev(physDev) {
40         SkASSERT(ctxt);
41         fDContext = nullptr;
42         fGrTexture = {};
43     }
44 
backendTexture()45     const skgpu::graphite::BackendTexture& backendTexture() const { return fTexture; }
46 
47     bool createBackendTexture(uint32_t width, uint32_t height);
48 #endif
49 
50     VkYcbcrSamplerHelper(GrDirectContext*);
51 
grBackendTexture()52     const GrBackendTexture& grBackendTexture() const { return fGrTexture; }
53 
54     ~VkYcbcrSamplerHelper();
55 
56     bool isYCbCrSupported();
57 
58     bool createGrBackendTexture(uint32_t width, uint32_t height);
59 
60     static int GetExpectedY(int x, int y, int width, int height);
61     static std::pair<int, int> GetExpectedUV(int x, int y, int width, int height);
62 
63 private:
64 #if defined(SK_GRAPHITE)
65     skgpu::graphite::BackendTexture             fTexture;
66     const skgpu::graphite::VulkanSharedContext* fSharedCtxt;
67     // Needed to query PhysicalDeviceFormatProperties for relevant VkFormat(s)
68     VkPhysicalDevice                            fPhysDev;
69 #endif
70 
71     GrVkGpu* vkGpu();
72 
73     GrDirectContext* fDContext;
74     GrBackendTexture fGrTexture;
75 
76     VkImage fImage = VK_NULL_HANDLE;
77     VkDeviceMemory fImageMemory = VK_NULL_HANDLE;
78 };
79 
80 #endif // SK_VULKAN
81 #endif // VkYcbcrSamplerHelper_DEFINED
82