1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // HardwareBufferImageSiblingVkAndroid.cpp: Implements HardwareBufferImageSiblingVkAndroid.
8
9 #include "libANGLE/renderer/vulkan/android/HardwareBufferImageSiblingVkAndroid.h"
10
11 #include "common/android_util.h"
12
13 #include "libANGLE/Display.h"
14 #include "libANGLE/renderer/vulkan/DisplayVk.h"
15 #include "libANGLE/renderer/vulkan/RendererVk.h"
16 #include "libANGLE/renderer/vulkan/android/AHBFunctions.h"
17 #include "libANGLE/renderer/vulkan/android/DisplayVkAndroid.h"
18
19 namespace rx
20 {
21
22 namespace
23 {
AhbDescUsageToVkImageTiling(const AHardwareBuffer_Desc & ahbDescription)24 VkImageTiling AhbDescUsageToVkImageTiling(const AHardwareBuffer_Desc &ahbDescription)
25 {
26 // A note about the choice of OPTIMAL here.
27
28 // When running Android on certain GPUs, there are problems creating Vulkan
29 // image siblings of AHardwareBuffers because it's currently assumed that
30 // the underlying driver can create linear tiling images that have input
31 // attachment usage, which isn't supported on NVIDIA for example, resulting
32 // in failure to create the image siblings. Yet, we don't currently take
33 // advantage of linear elsewhere in ANGLE. To maintain maximum
34 // compatibility on Android for such drivers, use optimal tiling for image
35 // siblings.
36 //
37 // Note that while we have switched to optimal unconditionally in this path
38 // versus linear, it's possible that previously compatible linear usages
39 // might become uncompatible after switching to optimal. However, from what
40 // we've seen on Samsung/NVIDIA/Intel/AMD GPUs so far, formats generally
41 // have more possible usages in optimal tiling versus linear tiling:
42 //
43 // http://vulkan.gpuinfo.org/displayreport.php?id=10804#formats_linear
44 // http://vulkan.gpuinfo.org/displayreport.php?id=10804#formats_optimal
45 //
46 // http://vulkan.gpuinfo.org/displayreport.php?id=10807#formats_linear
47 // http://vulkan.gpuinfo.org/displayreport.php?id=10807#formats_optimal
48 //
49 // http://vulkan.gpuinfo.org/displayreport.php?id=10809#formats_linear
50 // http://vulkan.gpuinfo.org/displayreport.php?id=10809#formats_optimal
51 //
52 // http://vulkan.gpuinfo.org/displayreport.php?id=10787#formats_linear
53 // http://vulkan.gpuinfo.org/displayreport.php?id=10787#formats_optimal
54 //
55 // Also, as an aside, in terms of what's generally expected from the Vulkan
56 // ICD in Android when determining AHB compatibility, if the vendor wants
57 // to declare a particular combination of format/tiling/usage/etc as not
58 // supported AHB-wise, it's up to the ICD vendor to zero out bits in
59 // supportedHandleTypes in the vkGetPhysicalDeviceImageFormatProperties2
60 // query:
61 //
62 // ``` *
63 // [VUID-VkImageCreateInfo-pNext-00990](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkImageCreateInfo-pNext-00990)
64 // If the pNext chain includes a VkExternalMemoryImageCreateInfo structure,
65 // its handleTypes member must only contain bits that are also in
66 // VkExternalImageFormatProperties::externalMemoryProperties.compatibleHandleTypes,
67 // as returned by vkGetPhysicalDeviceImageFormatProperties2 with format,
68 // imageType, tiling, usage, and flags equal to those in this structure,
69 // and with a VkPhysicalDeviceExternalImageFormatInfo structure included in
70 // the pNext chain, with a handleType equal to any one of the handle types
71 // specified in VkExternalMemoryImageCreateInfo::handleTypes ```
72
73 return VK_IMAGE_TILING_OPTIMAL;
74 }
75
76 // Map AHB usage flags to VkImageUsageFlags using this table from the Vulkan spec
77 // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap11.html#memory-external-android-hardware-buffer-usage
AhbDescUsageToVkImageUsage(const AHardwareBuffer_Desc & ahbDescription,bool isDepthOrStencilFormat)78 VkImageUsageFlags AhbDescUsageToVkImageUsage(const AHardwareBuffer_Desc &ahbDescription,
79 bool isDepthOrStencilFormat)
80 {
81 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
82
83 if ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) != 0)
84 {
85 usage |= VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
86 }
87
88 if ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER) != 0)
89 {
90 if (isDepthOrStencilFormat)
91 {
92 usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
93 }
94 else
95 {
96 usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
97 }
98 }
99
100 return usage;
101 }
102
103 // Map AHB usage flags to VkImageCreateFlags using this table from the Vulkan spec
104 // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap11.html#memory-external-android-hardware-buffer-usage
AhbDescUsageToVkImageCreateFlags(const AHardwareBuffer_Desc & ahbDescription)105 VkImageCreateFlags AhbDescUsageToVkImageCreateFlags(const AHardwareBuffer_Desc &ahbDescription)
106 {
107 VkImageCreateFlags imageCreateFlags = vk::kVkImageCreateFlagsNone;
108
109 if ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP) != 0)
110 {
111 imageCreateFlags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
112 }
113
114 if ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) != 0)
115 {
116 imageCreateFlags |= VK_IMAGE_CREATE_PROTECTED_BIT;
117 }
118
119 return imageCreateFlags;
120 }
121
122 // Deduce texture type based on AHB usage flags and layer count
AhbDescUsageToTextureType(const AHardwareBuffer_Desc & ahbDescription,const uint32_t layerCount)123 gl::TextureType AhbDescUsageToTextureType(const AHardwareBuffer_Desc &ahbDescription,
124 const uint32_t layerCount)
125 {
126 gl::TextureType textureType = layerCount > 1 ? gl::TextureType::_2DArray : gl::TextureType::_2D;
127 if ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP) != 0)
128 {
129 textureType = layerCount > gl::kCubeFaceCount ? gl::TextureType::CubeMapArray
130 : gl::TextureType::CubeMap;
131 }
132 return textureType;
133 }
134 // TODO(anglebug.com/7956): remove when NDK header is updated to contain FRONT_BUFFER usage flag
135 constexpr uint64_t kAHardwareBufferUsageFrontBuffer = (1ULL << 32);
136 } // namespace
137
HardwareBufferImageSiblingVkAndroid(EGLClientBuffer buffer)138 HardwareBufferImageSiblingVkAndroid::HardwareBufferImageSiblingVkAndroid(EGLClientBuffer buffer)
139 : mBuffer(buffer),
140 mFormat(GL_NONE),
141 mRenderable(false),
142 mTextureable(false),
143 mYUV(false),
144 mLevelCount(0),
145 mUsage(0),
146 mSamples(0),
147 mImage(nullptr)
148 {}
149
~HardwareBufferImageSiblingVkAndroid()150 HardwareBufferImageSiblingVkAndroid::~HardwareBufferImageSiblingVkAndroid() {}
151
152 // Static
ValidateHardwareBuffer(RendererVk * renderer,EGLClientBuffer buffer,const egl::AttributeMap & attribs)153 egl::Error HardwareBufferImageSiblingVkAndroid::ValidateHardwareBuffer(
154 RendererVk *renderer,
155 EGLClientBuffer buffer,
156 const egl::AttributeMap &attribs)
157 {
158 struct ANativeWindowBuffer *windowBuffer =
159 angle::android::ClientBufferToANativeWindowBuffer(buffer);
160 struct AHardwareBuffer *hardwareBuffer =
161 angle::android::ANativeWindowBufferToAHardwareBuffer(windowBuffer);
162
163 VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties = {};
164 bufferFormatProperties.sType =
165 VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID;
166 bufferFormatProperties.pNext = nullptr;
167
168 VkAndroidHardwareBufferPropertiesANDROID bufferProperties = {};
169 bufferProperties.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID;
170 bufferProperties.pNext = &bufferFormatProperties;
171
172 VkDevice device = renderer->getDevice();
173 VkResult result =
174 vkGetAndroidHardwareBufferPropertiesANDROID(device, hardwareBuffer, &bufferProperties);
175 if (result != VK_SUCCESS)
176 {
177 return egl::EglBadParameter() << "Failed to query AHardwareBuffer properties";
178 }
179
180 if (bufferFormatProperties.format == VK_FORMAT_UNDEFINED)
181 {
182 ASSERT(bufferFormatProperties.externalFormat != 0);
183 // We must have an external format, check that it supports texture sampling
184 if (!(bufferFormatProperties.formatFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
185 {
186 return egl::EglBadParameter()
187 << "Sampling from AHardwareBuffer externalFormat 0x" << std::hex
188 << bufferFormatProperties.externalFormat << " is unsupported ";
189 }
190 }
191 else
192 {
193 angle::FormatID formatID = vk::GetFormatIDFromVkFormat(bufferFormatProperties.format);
194 if (!HasFullTextureFormatSupport(renderer, formatID))
195 {
196 return egl::EglBadParameter()
197 << "AHardwareBuffer format " << bufferFormatProperties.format
198 << " does not support enough features to use as a texture.";
199 }
200 }
201
202 if (attribs.getAsInt(EGL_PROTECTED_CONTENT_EXT, EGL_FALSE) == EGL_TRUE)
203 {
204 int width = 0;
205 int height = 0;
206 int depth = 0;
207 int pixelFormat = 0;
208 uint64_t usage = 0;
209 angle::android::GetANativeWindowBufferProperties(windowBuffer, &width, &height, &depth,
210 &pixelFormat, &usage);
211 if ((usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) == 0)
212 {
213 return egl::EglBadAccess()
214 << "EGL_PROTECTED_CONTENT_EXT attribute does not match protected state "
215 "of EGLCleintBuffer.";
216 }
217 }
218
219 return egl::NoError();
220 }
221
initialize(const egl::Display * display)222 egl::Error HardwareBufferImageSiblingVkAndroid::initialize(const egl::Display *display)
223 {
224 DisplayVk *displayVk = vk::GetImpl(display);
225 return angle::ToEGL(initImpl(displayVk), EGL_BAD_PARAMETER);
226 }
227
initImpl(DisplayVk * displayVk)228 angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk)
229 {
230 const AHBFunctions &functions = static_cast<DisplayVkAndroid *>(displayVk)->getAHBFunctions();
231 ANGLE_VK_CHECK(displayVk, functions.valid(), VK_ERROR_INITIALIZATION_FAILED);
232
233 RendererVk *renderer = displayVk->getRenderer();
234
235 struct ANativeWindowBuffer *windowBuffer =
236 angle::android::ClientBufferToANativeWindowBuffer(mBuffer);
237
238 int pixelFormat = 0;
239 angle::android::GetANativeWindowBufferProperties(windowBuffer, &mSize.width, &mSize.height,
240 &mSize.depth, &pixelFormat, &mUsage);
241
242 // BUG: b/223456677 Android sometimes uses an uninitialized value for layerCount of the
243 // ANativeWindowBuffer. Force depth <= 256 here. If we see a bigger value,
244 // force to 1.
245 mSize.depth = mSize.depth > 256 ? 1 : mSize.depth;
246
247 struct AHardwareBuffer *hardwareBuffer =
248 angle::android::ANativeWindowBufferToAHardwareBuffer(windowBuffer);
249
250 functions.acquire(hardwareBuffer);
251 VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties;
252 bufferFormatProperties.sType =
253 VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID;
254 bufferFormatProperties.pNext = nullptr;
255
256 VkAndroidHardwareBufferPropertiesANDROID bufferProperties = {};
257 bufferProperties.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID;
258 bufferProperties.pNext = &bufferFormatProperties;
259
260 VkDevice device = renderer->getDevice();
261 ANGLE_VK_TRY(displayVk, vkGetAndroidHardwareBufferPropertiesANDROID(device, hardwareBuffer,
262 &bufferProperties));
263
264 const bool isExternal = bufferFormatProperties.format == VK_FORMAT_UNDEFINED;
265
266 VkExternalFormatANDROID externalFormat = {};
267 externalFormat.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID;
268 externalFormat.externalFormat = 0;
269
270 // Use bufferFormatProperties.format directly when possible. For RGBX, the spec requires the
271 // corresponding format to be RGB, which is not _technically_ correct. The Vulkan backend uses
272 // the RGBX8_ANGLE format, so that's overriden.
273 //
274 // Where bufferFormatProperties.format returns UNDEFINED, NativePixelFormatToGLInternalFormat is
275 // used to infer the format.
276 const vk::Format *vkFormat = nullptr;
277 if (pixelFormat == AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM)
278 {
279 vkFormat = &renderer->getFormat(GL_RGBX8_ANGLE);
280 }
281 else if (!isExternal)
282 {
283 vkFormat = &renderer->getFormat(vk::GetFormatIDFromVkFormat(bufferFormatProperties.format));
284 }
285 else
286 {
287 vkFormat =
288 &renderer->getFormat(angle::android::NativePixelFormatToGLInternalFormat(pixelFormat));
289 }
290
291 const vk::Format &externalVkFormat = renderer->getFormat(angle::FormatID::NONE);
292 const angle::Format &imageFormat = vkFormat->getActualRenderableImageFormat();
293 bool isDepthOrStencilFormat = imageFormat.hasDepthOrStencilBits();
294 mFormat = gl::Format(vkFormat->getIntendedGLFormat());
295
296 // TODO (b/223456677): VK_EXT_ycbcr_attachment Extension query
297 bool externalRenderTargetSupported = false;
298
299 // Can assume based on us getting here already. The supportsYUVSamplerConversion
300 // check below should serve as a backup otherwise.
301 bool externalTexturingSupported = true;
302
303 // Query AHB description and do the following -
304 // 1. Derive VkImageTiling mode based on AHB usage flags
305 // 2. Map AHB usage flags to VkImageUsageFlags
306 AHardwareBuffer_Desc ahbDescription;
307 functions.describe(hardwareBuffer, &ahbDescription);
308 VkImageTiling imageTilingMode = AhbDescUsageToVkImageTiling(ahbDescription);
309 VkImageUsageFlags usage = AhbDescUsageToVkImageUsage(ahbDescription, isDepthOrStencilFormat);
310
311 if (isExternal)
312 {
313 ANGLE_VK_CHECK(displayVk, bufferFormatProperties.externalFormat != 0, VK_ERROR_UNKNOWN);
314 externalFormat.externalFormat = bufferFormatProperties.externalFormat;
315
316 // VkImageCreateInfo struct: If the pNext chain includes a VkExternalFormatANDROID structure
317 // whose externalFormat member is not 0, usage must not include any usages except
318 // VK_IMAGE_USAGE_SAMPLED_BIT
319 if (!externalRenderTargetSupported)
320 {
321 // Clear all other bits except sampled
322 usage = VK_IMAGE_USAGE_SAMPLED_BIT;
323 }
324
325 // If the pNext chain includes a VkExternalFormatANDROID structure whose externalFormat
326 // member is not 0, tiling must be VK_IMAGE_TILING_OPTIMAL
327 imageTilingMode = VK_IMAGE_TILING_OPTIMAL;
328 }
329
330 VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo = {};
331 externalMemoryImageCreateInfo.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;
332 externalMemoryImageCreateInfo.pNext = &externalFormat;
333 externalMemoryImageCreateInfo.handleTypes =
334 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
335
336 VkExtent3D vkExtents;
337 gl_vk::GetExtent(mSize, &vkExtents);
338
339 // Setup level count
340 mLevelCount = ((ahbDescription.usage & AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE) != 0)
341 ? static_cast<uint32_t>(log2(std::max(mSize.width, mSize.height))) + 1
342 : 1;
343
344 // Setup layer count
345 const uint32_t layerCount = mSize.depth;
346 vkExtents.depth = 1;
347
348 mImage = new vk::ImageHelper();
349
350 // disable robust init for this external image.
351 bool robustInitEnabled = false;
352
353 mImage->setTilingMode(imageTilingMode);
354 VkImageCreateFlags imageCreateFlags = AhbDescUsageToVkImageCreateFlags(ahbDescription);
355
356 const vk::Format &format = isExternal ? externalVkFormat : *vkFormat;
357 const gl::TextureType textureType = AhbDescUsageToTextureType(ahbDescription, layerCount);
358
359 VkImageFormatListCreateInfoKHR imageFormatListInfoStorage;
360 vk::ImageHelper::ImageListFormats imageListFormatsStorage;
361 const void *imageCreateInfoPNext = vk::ImageHelper::DeriveCreateInfoPNext(
362 displayVk, format.getActualRenderableImageFormatID(), &externalMemoryImageCreateInfo,
363 &imageFormatListInfoStorage, &imageListFormatsStorage, &imageCreateFlags);
364
365 ANGLE_TRY(mImage->initExternal(displayVk, textureType, vkExtents, format.getIntendedFormatID(),
366 format.getActualRenderableImageFormatID(), 1, usage,
367 imageCreateFlags, vk::ImageLayout::ExternalPreInitialized,
368 imageCreateInfoPNext, gl::LevelIndex(0), mLevelCount, layerCount,
369 robustInitEnabled, hasProtectedContent()));
370
371 VkImportAndroidHardwareBufferInfoANDROID importHardwareBufferInfo = {};
372 importHardwareBufferInfo.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID;
373 importHardwareBufferInfo.buffer = hardwareBuffer;
374
375 VkMemoryDedicatedAllocateInfo dedicatedAllocInfo = {};
376 dedicatedAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
377 dedicatedAllocInfo.pNext = &importHardwareBufferInfo;
378 dedicatedAllocInfo.image = mImage->getImage().getHandle();
379 dedicatedAllocInfo.buffer = VK_NULL_HANDLE;
380 const void *dedicatedAllocInfoPtr = &dedicatedAllocInfo;
381
382 VkMemoryRequirements externalMemoryRequirements = {};
383 externalMemoryRequirements.size = bufferProperties.allocationSize;
384 externalMemoryRequirements.alignment = 0;
385 externalMemoryRequirements.memoryTypeBits = bufferProperties.memoryTypeBits;
386
387 const VkMemoryPropertyFlags flags =
388 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
389 (hasProtectedContent() ? VK_MEMORY_PROPERTY_PROTECTED_BIT : 0);
390
391 if (isExternal)
392 {
393 // Note from Vulkan spec: Since GL_OES_EGL_image_external does not require the same sampling
394 // and conversion calculations as Vulkan does, achieving identical results between APIs may
395 // not be possible on some implementations.
396 ANGLE_VK_CHECK(displayVk, renderer->getFeatures().supportsYUVSamplerConversion.enabled,
397 VK_ERROR_FEATURE_NOT_PRESENT);
398 ASSERT(externalFormat.pNext == nullptr);
399
400 // Update the SamplerYcbcrConversionCache key
401 mImage->updateYcbcrConversionDesc(
402 renderer, bufferFormatProperties.externalFormat,
403 bufferFormatProperties.suggestedYcbcrModel, bufferFormatProperties.suggestedYcbcrRange,
404 bufferFormatProperties.suggestedXChromaOffset,
405 bufferFormatProperties.suggestedYChromaOffset, vk::kDefaultYCbCrChromaFilter,
406 bufferFormatProperties.samplerYcbcrConversionComponents, angle::FormatID::NONE);
407 // This may not actually mean the format is YUV. But the rest of ANGLE makes this
408 // assumption and needs this member variable.
409 mYUV = true;
410 }
411
412 ANGLE_TRY(mImage->initExternalMemory(displayVk, renderer->getMemoryProperties(),
413 externalMemoryRequirements, 1, &dedicatedAllocInfoPtr,
414 VK_QUEUE_FAMILY_FOREIGN_EXT, flags));
415
416 if (isExternal)
417 {
418 // External format means that we are working with VK_FORMAT_UNDEFINED,
419 // so hasImageFormatFeatureBits will assert. Set these based on
420 // presence of extensions or assumption.
421 mRenderable = externalRenderTargetSupported;
422 mTextureable = externalTexturingSupported;
423 }
424 else
425 {
426 constexpr uint32_t kColorRenderableRequiredBits = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
427 constexpr uint32_t kDepthStencilRenderableRequiredBits =
428 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
429 mRenderable =
430 renderer->hasImageFormatFeatureBits(vkFormat->getActualRenderableImageFormatID(),
431 kColorRenderableRequiredBits) ||
432 renderer->hasImageFormatFeatureBits(vkFormat->getActualRenderableImageFormatID(),
433 kDepthStencilRenderableRequiredBits);
434 constexpr uint32_t kTextureableRequiredBits =
435 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
436 mTextureable = renderer->hasImageFormatFeatureBits(
437 vkFormat->getActualRenderableImageFormatID(), kTextureableRequiredBits);
438 }
439
440 return angle::Result::Continue;
441 }
442
onDestroy(const egl::Display * display)443 void HardwareBufferImageSiblingVkAndroid::onDestroy(const egl::Display *display)
444 {
445 const AHBFunctions &functions = GetImplAs<DisplayVkAndroid>(display)->getAHBFunctions();
446 ASSERT(functions.valid());
447
448 functions.release(angle::android::ANativeWindowBufferToAHardwareBuffer(
449 angle::android::ClientBufferToANativeWindowBuffer(mBuffer)));
450
451 ASSERT(mImage == nullptr);
452 }
453
getFormat() const454 gl::Format HardwareBufferImageSiblingVkAndroid::getFormat() const
455 {
456 return mFormat;
457 }
458
isRenderable(const gl::Context * context) const459 bool HardwareBufferImageSiblingVkAndroid::isRenderable(const gl::Context *context) const
460 {
461 return mRenderable;
462 }
463
isTexturable(const gl::Context * context) const464 bool HardwareBufferImageSiblingVkAndroid::isTexturable(const gl::Context *context) const
465 {
466 return mTextureable;
467 }
468
isYUV() const469 bool HardwareBufferImageSiblingVkAndroid::isYUV() const
470 {
471 return mYUV;
472 }
473
hasFrontBufferUsage() const474 bool HardwareBufferImageSiblingVkAndroid::hasFrontBufferUsage() const
475 {
476 return (mUsage & kAHardwareBufferUsageFrontBuffer) != 0;
477 }
478
isCubeMap() const479 bool HardwareBufferImageSiblingVkAndroid::isCubeMap() const
480 {
481 return (mUsage & AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP) != 0;
482 }
483
hasProtectedContent() const484 bool HardwareBufferImageSiblingVkAndroid::hasProtectedContent() const
485 {
486 return ((mUsage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) != 0);
487 }
488
getSize() const489 gl::Extents HardwareBufferImageSiblingVkAndroid::getSize() const
490 {
491 return mSize;
492 }
493
getSamples() const494 size_t HardwareBufferImageSiblingVkAndroid::getSamples() const
495 {
496 return mSamples;
497 }
498
getLevelCount() const499 uint32_t HardwareBufferImageSiblingVkAndroid::getLevelCount() const
500 {
501 return mLevelCount;
502 }
503
504 // ExternalImageSiblingVk interface
getImage() const505 vk::ImageHelper *HardwareBufferImageSiblingVkAndroid::getImage() const
506 {
507 return mImage;
508 }
509
release(RendererVk * renderer)510 void HardwareBufferImageSiblingVkAndroid::release(RendererVk *renderer)
511 {
512 if (mImage != nullptr)
513 {
514 // TODO: Handle the case where the EGLImage is used in two contexts not in the same share
515 // group. https://issuetracker.google.com/169868803
516 mImage->releaseImage(renderer);
517 mImage->releaseStagedUpdates(renderer);
518 SafeDelete(mImage);
519 }
520 }
521
522 } // namespace rx
523