Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: gpu/vulkan/vulkan_surface.cc

Issue 1963983002: Support vulkan surface formats for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/vulkan/vulkan_surface.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/vulkan/vulkan_surface.h" 5 #include "gpu/vulkan/vulkan_surface.h"
6 6
7 #include <vulkan/vulkan.h> 7 #include <vulkan/vulkan.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "gpu/vulkan/vulkan_command_buffer.h" 10 #include "gpu/vulkan/vulkan_command_buffer.h"
11 #include "gpu/vulkan/vulkan_device_queue.h" 11 #include "gpu/vulkan/vulkan_device_queue.h"
12 #include "gpu/vulkan/vulkan_implementation.h" 12 #include "gpu/vulkan/vulkan_implementation.h"
13 #include "gpu/vulkan/vulkan_platform.h" 13 #include "gpu/vulkan/vulkan_platform.h"
14 #include "gpu/vulkan/vulkan_swap_chain.h" 14 #include "gpu/vulkan/vulkan_swap_chain.h"
15 15
16 #if defined(USE_X11) 16 #if defined(USE_X11)
17 #include "ui/gfx/x/x11_types.h" 17 #include "ui/gfx/x/x11_types.h"
18 #endif // defined(USE_X11) 18 #endif // defined(USE_X11)
19 19
20 namespace gpu { 20 namespace gpu {
21 21
22 namespace { 22 namespace {
23 const VkFormat kNativeVkFormat[] = { 23 const VkFormat kNativeVkFormat[] = {
piman 2016/05/11 17:11:56 This is not used anymore, please remove.
sohanjg 2016/05/12 06:34:30 Done.
24 VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, 24 VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888,
25 VK_FORMAT_R8G8B8A8_UNORM, // FORMAT_RGBA8888,
25 VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565, 26 VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565,
26 }; 27 };
27 static_assert(arraysize(kNativeVkFormat) == VulkanSurface::NUM_SURFACE_FORMATS, 28
29 const VkFormat kPreferredVkFormats32[] = {
30 VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888,
31 VK_FORMAT_R8G8B8A8_UNORM, // FORMAT_RGBA8888,
32 };
33
34 const VkFormat kPreferredVkFormats16[] = {
35 VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565,
36 };
37
38 static_assert(arraysize(kNativeVkFormat) ==
39 VulkanSurface::NUM_SURFACE_FORMATS + 1,
28 "Array size for kNativeVkFormat must match surface formats."); 40 "Array size for kNativeVkFormat must match surface formats.");
29 41
30 } // namespace 42 } // namespace
31 43
32 class VulkanWSISurface : public VulkanSurface { 44 class VulkanWSISurface : public VulkanSurface {
33 public: 45 public:
34 explicit VulkanWSISurface(gfx::AcceleratedWidget window) : window_(window) {} 46 explicit VulkanWSISurface(gfx::AcceleratedWidget window) : window_(window) {}
35 47
36 ~VulkanWSISurface() override { 48 ~VulkanWSISurface() override {
37 DCHECK_EQ(static_cast<VkSurfaceKHR>(VK_NULL_HANDLE), surface_); 49 DCHECK_EQ(static_cast<VkSurfaceKHR>(VK_NULL_HANDLE), surface_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 std::vector<VkSurfaceFormatKHR> formats(format_count); 99 std::vector<VkSurfaceFormatKHR> formats(format_count);
88 result = vkGetPhysicalDeviceSurfaceFormatsKHR( 100 result = vkGetPhysicalDeviceSurfaceFormatsKHR(
89 device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count, 101 device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count,
90 formats.data()); 102 formats.data());
91 if (VK_SUCCESS != result) { 103 if (VK_SUCCESS != result) {
92 DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceFormatsKHR() failed: " 104 DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceFormatsKHR() failed: "
93 << result; 105 << result;
94 return false; 106 return false;
95 } 107 }
96 108
97 const VkFormat preferred_format = kNativeVkFormat[format]; 109 const VkFormat* preferred_formats = (format == FORMAT_RGBA_32)
110 ? kPreferredVkFormats32
111 : kPreferredVkFormats16;
112
98 if (formats.size() == 1 && VK_FORMAT_UNDEFINED == formats[0].format) { 113 if (formats.size() == 1 && VK_FORMAT_UNDEFINED == formats[0].format) {
99 surface_format_.format = preferred_format; 114 surface_format_.format = preferred_formats[0];
100 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; 115 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
101 } else { 116 } else {
102 bool format_set = false; 117 bool format_set = false;
103 for (VkSurfaceFormatKHR supported_format : formats) { 118 for (VkSurfaceFormatKHR supported_format : formats) {
104 if (supported_format.format == preferred_format) { 119 uint counter = 0;
piman 2016/05/11 17:11:56 nit: uint->unsigned int
sohanjg 2016/05/12 06:34:30 Done.
105 surface_format_ = supported_format; 120 uint size = (format == FORMAT_RGBA_32)
piman 2016/05/11 17:11:56 nit: uint->unsigned int. This can be hoisted out o
sohanjg 2016/05/12 06:34:30 Done.
106 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; 121 ? arraysize(kPreferredVkFormats32)
107 format_set = true; 122 : arraysize(kPreferredVkFormats16);
123 while (counter < size && format_set == false) {
124 if (supported_format.format == *(preferred_formats + counter)) {
piman 2016/05/11 17:11:56 nit: *(preferred_formats + counter) -> preferred_f
sohanjg 2016/05/12 06:34:30 Done.
125 surface_format_ = supported_format;
126 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
127 format_set = true;
128 }
129 counter++;
130 }
131 if (format_set)
108 break; 132 break;
109 }
110 } 133 }
111 if (!format_set) { 134 if (!format_set) {
112 DLOG(ERROR) << "Format not supported."; 135 DLOG(ERROR) << "Format not supported.";
113 return false; 136 return false;
114 } 137 }
115 } 138 }
116 139
117 // Get Surface Information. 140 // Get Surface Information.
118 VkSurfaceCapabilitiesKHR surface_caps; 141 VkSurfaceCapabilitiesKHR surface_caps;
119 result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR( 142 result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 185
163 // static 186 // static
164 std::unique_ptr<VulkanSurface> VulkanSurface::CreateViewSurface( 187 std::unique_ptr<VulkanSurface> VulkanSurface::CreateViewSurface(
165 gfx::AcceleratedWidget window) { 188 gfx::AcceleratedWidget window) {
166 return std::unique_ptr<VulkanSurface>(new VulkanWSISurface(window)); 189 return std::unique_ptr<VulkanSurface>(new VulkanWSISurface(window));
167 } 190 }
168 191
169 VulkanSurface::VulkanSurface() {} 192 VulkanSurface::VulkanSurface() {}
170 193
171 } // namespace gpu 194 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/vulkan/vulkan_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698