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