/src/skia/src/gpu/ganesh/vk/GrVkImageView.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2016 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 | | #include "src/gpu/ganesh/vk/GrVkImageView.h" |
8 | | |
9 | | #include "include/gpu/vk/VulkanTypes.h" |
10 | | #include "include/private/base/SkAssert.h" |
11 | | #include "src/gpu/ganesh/vk/GrVkCaps.h" |
12 | | #include "src/gpu/ganesh/vk/GrVkGpu.h" |
13 | | #include "src/gpu/ganesh/vk/GrVkResourceProvider.h" |
14 | | #include "src/gpu/ganesh/vk/GrVkSamplerYcbcrConversion.h" |
15 | | #include "src/gpu/ganesh/vk/GrVkUtil.h" |
16 | | |
17 | | sk_sp<const GrVkImageView> GrVkImageView::Make(GrVkGpu* gpu, |
18 | | VkImage image, |
19 | | VkFormat format, |
20 | | Type viewType, |
21 | | uint32_t miplevels, |
22 | 0 | const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo) { |
23 | 0 | void* pNext = nullptr; |
24 | 0 | VkSamplerYcbcrConversionInfo conversionInfo; |
25 | 0 | GrVkSamplerYcbcrConversion* ycbcrConversion = nullptr; |
26 | |
|
27 | 0 | if (ycbcrInfo.isValid()) { |
28 | 0 | SkASSERT(gpu->vkCaps().supportsYcbcrConversion() && format == ycbcrInfo.fFormat); |
29 | |
|
30 | 0 | ycbcrConversion = |
31 | 0 | gpu->resourceProvider().findOrCreateCompatibleSamplerYcbcrConversion(ycbcrInfo); |
32 | 0 | if (!ycbcrConversion) { |
33 | 0 | return nullptr; |
34 | 0 | } |
35 | | |
36 | 0 | conversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO; |
37 | 0 | conversionInfo.pNext = nullptr; |
38 | 0 | conversionInfo.conversion = ycbcrConversion->ycbcrConversion(); |
39 | 0 | pNext = &conversionInfo; |
40 | 0 | } |
41 | | |
42 | 0 | VkImageView imageView; |
43 | | // Create the VkImageView |
44 | 0 | VkImageViewCreateInfo viewInfo = { |
45 | 0 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType |
46 | 0 | pNext, // pNext |
47 | 0 | 0, // flags |
48 | 0 | image, // image |
49 | 0 | VK_IMAGE_VIEW_TYPE_2D, // viewType |
50 | 0 | format, // format |
51 | 0 | { VK_COMPONENT_SWIZZLE_IDENTITY, |
52 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY, |
53 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY, |
54 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY }, // components |
55 | 0 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, miplevels, 0, 1 }, // subresourceRange |
56 | 0 | }; |
57 | 0 | if (kStencil_Type == viewType) { |
58 | 0 | viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
59 | 0 | } |
60 | |
|
61 | 0 | VkResult err; |
62 | 0 | GR_VK_CALL_RESULT(gpu, err, CreateImageView(gpu->device(), &viewInfo, nullptr, &imageView)); |
63 | 0 | if (err) { |
64 | 0 | return nullptr; |
65 | 0 | } |
66 | | |
67 | 0 | return sk_sp<const GrVkImageView>(new GrVkImageView(gpu, imageView, ycbcrConversion)); |
68 | 0 | } Unexecuted instantiation: GrVkImageView::Make(GrVkGpu*, VkImage_T*, VkFormat, GrVkImageView::Type, unsigned int, skgpu::VulkanYcbcrConversionInfo const&) Unexecuted instantiation: GrVkImageView::Make(GrVkGpu*, VkImage_T*, VkFormat, GrVkImageView::Type, unsigned int, skgpu::VulkanYcbcrConversionInfo const&) |
69 | | |
70 | 0 | void GrVkImageView::freeGPUData() const { |
71 | 0 | GR_VK_CALL(fGpu->vkInterface(), DestroyImageView(fGpu->device(), fImageView, nullptr)); |
72 | |
|
73 | 0 | if (fYcbcrConversion) { |
74 | 0 | fYcbcrConversion->unref(); |
75 | 0 | } |
76 | 0 | } |
77 | | |