OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrVkTextureRenderTarget.h" | 8 #include "GrVkTextureRenderTarget.h" |
9 | 9 |
10 #include "GrRenderTargetPriv.h" | 10 #include "GrRenderTargetPriv.h" |
11 #include "GrVkGpu.h" | 11 #include "GrVkGpu.h" |
12 #include "GrVkImageView.h" | 12 #include "GrVkImageView.h" |
13 #include "GrVkUtil.h" | 13 #include "GrVkUtil.h" |
14 | 14 |
15 #include "vk/GrVkTypes.h" | 15 #include "vk/GrVkTypes.h" |
16 | 16 |
17 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 17 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
18 | 18 |
19 GrVkTextureRenderTarget* | 19 template<typename ResourceType> |
20 GrVkTextureRenderTarget::Create(GrVkGpu* gpu, | 20 GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, |
21 const GrSurfaceDesc& desc, | 21 ResourceType resourceTy
pe, |
22 GrGpuResource::LifeCycle lifeCycle, | 22 const GrSurfaceDesc& de
sc, |
23 VkFormat format, | 23 VkFormat format, |
24 const GrVkImage::Resource* imageResource) { | 24 const GrVkImage::Resour
ce* imageResource) { |
25 | |
26 VkImage image = imageResource->fImage; | 25 VkImage image = imageResource->fImage; |
27 // Create the texture ImageView | 26 // Create the texture ImageView |
28 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, | 27 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, |
29 GrVkImageView::kColor
_Type); | 28 GrVkImageView::kColor
_Type); |
30 if (!imageView) { | 29 if (!imageView) { |
31 return nullptr; | 30 return nullptr; |
32 } | 31 } |
33 | 32 |
34 VkFormat pixelFormat; | 33 VkFormat pixelFormat; |
35 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); | 34 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 GrVkImageView::kColor_Type); | 91 GrVkImageView::kColor_Type); |
93 if (!colorAttachmentView) { | 92 if (!colorAttachmentView) { |
94 if (msaaImageResource) { | 93 if (msaaImageResource) { |
95 resolveAttachmentView->unref(gpu); | 94 resolveAttachmentView->unref(gpu); |
96 msaaImageResource->unref(gpu); | 95 msaaImageResource->unref(gpu); |
97 } | 96 } |
98 imageView->unref(gpu); | 97 imageView->unref(gpu); |
99 return nullptr; | 98 return nullptr; |
100 } | 99 } |
101 } | 100 } |
102 | |
103 GrVkTextureRenderTarget* texRT; | 101 GrVkTextureRenderTarget* texRT; |
104 if (msaaImageResource) { | 102 if (msaaImageResource) { |
105 texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle, | 103 texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc, |
106 imageResource, imageView, msaaImageR
esource, | 104 imageResource, imageView, msaaImageR
esource, |
107 colorAttachmentView, | 105 colorAttachmentView, |
108 resolveAttachmentView); | 106 resolveAttachmentView); |
109 msaaImageResource->unref(gpu); | 107 msaaImageResource->unref(gpu); |
110 } else { | 108 } else { |
111 texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle, | 109 texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc, |
112 imageResource, imageView, | 110 imageResource, imageView, |
113 colorAttachmentView); | 111 colorAttachmentView); |
114 } | 112 } |
115 return texRT; | 113 return texRT; |
116 } | 114 } |
117 | 115 |
118 GrVkTextureRenderTarget* | 116 GrVkTextureRenderTarget* |
119 GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu, | 117 GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu, |
120 const GrSurfaceDesc& desc, | 118 SkBudgeted budgeted, |
121 GrGpuResource::LifeCycle li
feCycle, | 119 const GrSurfaceDesc& desc, |
122 const GrVkImage::ImageDesc&
imageDesc) { | 120 const GrVkImage::ImageDesc
& imageDesc) { |
123 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); | 121 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
124 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT); | 122 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT); |
125 | 123 |
126 const GrVkImage::Resource* imageRsrc = GrVkImage::CreateResource(gpu, imageD
esc); | 124 const GrVkImage::Resource* imageRsrc = GrVkImage::CreateResource(gpu, imageD
esc); |
127 | 125 |
128 if (!imageRsrc) { | 126 if (!imageRsrc) { |
129 return nullptr; | 127 return nullptr; |
130 } | 128 } |
131 | 129 |
132 GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, li
feCycle, | 130 GrVkTextureRenderTarget* trt = Create(gpu, budgeted, desc, imageDesc.fFormat
, |
133 imageDesc.fFo
rmat, imageRsrc); | 131 imageRsrc); |
134 // Create() will increment the refCount of the image resource if it succeeds | 132 // Create() will increment the refCount of the image resource if it succeeds |
135 imageRsrc->unref(gpu); | 133 imageRsrc->unref(gpu); |
136 | 134 |
137 return trt; | 135 return trt; |
138 } | 136 } |
139 | 137 |
140 GrVkTextureRenderTarget* | 138 GrVkTextureRenderTarget* |
141 GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu, | 139 GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu, |
142 const GrSurfaceDesc& d
esc, | 140 const GrSurfaceDesc& d
esc, |
143 GrGpuResource::LifeCyc
le lifeCycle, | 141 GrWrapOwnership owners
hip, |
144 VkFormat format, | 142 VkFormat format, |
145 const GrVkTextureInfo*
info) { | 143 const GrVkTextureInfo*
info) { |
146 SkASSERT(info); | 144 SkASSERT(info); |
147 // Wrapped textures require both image and allocation (because they can be m
apped) | 145 // Wrapped textures require both image and allocation (because they can be m
apped) |
148 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc); | 146 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc); |
149 | 147 |
150 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) | 148 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) |
151 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; | 149 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; |
152 | 150 |
153 const GrVkImage::Resource* imageResource; | 151 const GrVkImage::Resource* imageResource; |
154 if (kBorrowed_LifeCycle == lifeCycle) { | 152 if (kBorrow_GrWrapOwnership == ownership) { |
155 imageResource = new GrVkImage::BorrowedResource(info->fImage, | 153 imageResource = new GrVkImage::BorrowedResource(info->fImage, |
156 info->fAlloc, | 154 info->fAlloc, |
157 flags, | 155 flags, |
158 info->fFormat); | 156 info->fFormat); |
159 } else { | 157 } else { |
160 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flag
s, info->fFormat); | 158 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flag
s, info->fFormat); |
161 } | 159 } |
162 if (!imageResource) { | 160 if (!imageResource) { |
163 return nullptr; | 161 return nullptr; |
164 } | 162 } |
165 | 163 GrVkTextureRenderTarget* trt = Create(gpu, kWrapped, desc, format, imageReso
urce); |
166 GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, li
feCycle, | |
167 format, image
Resource); | |
168 if (trt) { | 164 if (trt) { |
169 trt->fCurrentLayout = info->fImageLayout; | 165 trt->fCurrentLayout = info->fImageLayout; |
170 } | 166 } |
171 // Create() will increment the refCount of the image resource if it succeeds | 167 // Create() will increment the refCount of the image resource if it succeeds |
172 imageResource->unref(gpu); | 168 imageResource->unref(gpu); |
173 | 169 |
174 return trt; | 170 return trt; |
175 } | 171 } |
OLD | NEW |