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

Side by Side Diff: ui/gfx/buffer_format_util.cc

Issue 1415723006: ui: Add RGBX_8888 buffer format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gles but no conversion needed case Created 5 years, 2 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/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc ('k') | ui/gfx/buffer_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/gfx/buffer_format_util.h" 5 #include "ui/gfx/buffer_format_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 9
10 namespace gfx { 10 namespace gfx {
11 namespace { 11 namespace {
12 12
13 const BufferFormat kBufferFormats[] = { 13 const BufferFormat kBufferFormats[] = {BufferFormat::ATC,
14 BufferFormat::ATC, BufferFormat::ATCIA, 14 BufferFormat::ATCIA,
15 BufferFormat::DXT1, BufferFormat::DXT5, 15 BufferFormat::DXT1,
16 BufferFormat::ETC1, BufferFormat::R_8, 16 BufferFormat::DXT5,
17 BufferFormat::RGBA_4444, BufferFormat::RGBA_8888, 17 BufferFormat::ETC1,
18 BufferFormat::BGRX_8888, BufferFormat::BGRA_8888, 18 BufferFormat::R_8,
19 BufferFormat::UYVY_422, BufferFormat::YUV_420_BIPLANAR, 19 BufferFormat::RGBA_4444,
20 BufferFormat::YUV_420}; 20 BufferFormat::RGBX_8888,
21 BufferFormat::RGBA_8888,
22 BufferFormat::BGRX_8888,
23 BufferFormat::BGRA_8888,
24 BufferFormat::UYVY_422,
25 BufferFormat::YUV_420_BIPLANAR,
26 BufferFormat::YUV_420};
21 27
22 static_assert(arraysize(kBufferFormats) == 28 static_assert(arraysize(kBufferFormats) ==
23 (static_cast<int>(BufferFormat::LAST) + 1), 29 (static_cast<int>(BufferFormat::LAST) + 1),
24 "BufferFormat::LAST must be last value of kBufferFormats"); 30 "BufferFormat::LAST must be last value of kBufferFormats");
25 31
26 32
27 bool RowSizeForBufferFormatChecked( 33 bool RowSizeForBufferFormatChecked(
28 size_t width, BufferFormat format, int plane, size_t* size_in_bytes) { 34 size_t width, BufferFormat format, int plane, size_t* size_in_bytes) {
29 base::CheckedNumeric<size_t> checked_size = width; 35 base::CheckedNumeric<size_t> checked_size = width;
30 switch (format) { 36 switch (format) {
(...skipping 16 matching lines...) Expand all
47 *size_in_bytes = checked_size.ValueOrDie() & ~0x3; 53 *size_in_bytes = checked_size.ValueOrDie() & ~0x3;
48 return true; 54 return true;
49 case BufferFormat::RGBA_4444: 55 case BufferFormat::RGBA_4444:
50 case BufferFormat::UYVY_422: 56 case BufferFormat::UYVY_422:
51 checked_size *= 2; 57 checked_size *= 2;
52 if (!checked_size.IsValid()) 58 if (!checked_size.IsValid())
53 return false; 59 return false;
54 *size_in_bytes = checked_size.ValueOrDie(); 60 *size_in_bytes = checked_size.ValueOrDie();
55 return true; 61 return true;
56 case BufferFormat::BGRX_8888: 62 case BufferFormat::BGRX_8888:
63 case BufferFormat::RGBX_8888:
57 case BufferFormat::RGBA_8888: 64 case BufferFormat::RGBA_8888:
58 case BufferFormat::BGRA_8888: 65 case BufferFormat::BGRA_8888:
59 checked_size *= 4; 66 checked_size *= 4;
60 if (!checked_size.IsValid()) 67 if (!checked_size.IsValid())
61 return false; 68 return false;
62 *size_in_bytes = checked_size.ValueOrDie(); 69 *size_in_bytes = checked_size.ValueOrDie();
63 return true; 70 return true;
64 case BufferFormat::YUV_420: 71 case BufferFormat::YUV_420:
65 DCHECK_EQ(0u, width % 2); 72 DCHECK_EQ(0u, width % 2);
66 *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane); 73 *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane);
(...skipping 16 matching lines...) Expand all
83 90
84 size_t NumberOfPlanesForBufferFormat(BufferFormat format) { 91 size_t NumberOfPlanesForBufferFormat(BufferFormat format) {
85 switch (format) { 92 switch (format) {
86 case BufferFormat::ATC: 93 case BufferFormat::ATC:
87 case BufferFormat::ATCIA: 94 case BufferFormat::ATCIA:
88 case BufferFormat::DXT1: 95 case BufferFormat::DXT1:
89 case BufferFormat::DXT5: 96 case BufferFormat::DXT5:
90 case BufferFormat::ETC1: 97 case BufferFormat::ETC1:
91 case BufferFormat::R_8: 98 case BufferFormat::R_8:
92 case BufferFormat::RGBA_4444: 99 case BufferFormat::RGBA_4444:
100 case BufferFormat::RGBX_8888:
93 case BufferFormat::RGBA_8888: 101 case BufferFormat::RGBA_8888:
94 case BufferFormat::BGRX_8888: 102 case BufferFormat::BGRX_8888:
95 case BufferFormat::BGRA_8888: 103 case BufferFormat::BGRA_8888:
96 case BufferFormat::UYVY_422: 104 case BufferFormat::UYVY_422:
97 return 1; 105 return 1;
98 case BufferFormat::YUV_420_BIPLANAR: 106 case BufferFormat::YUV_420_BIPLANAR:
99 return 2; 107 return 2;
100 case BufferFormat::YUV_420: 108 case BufferFormat::YUV_420:
101 return 3; 109 return 3;
102 } 110 }
103 NOTREACHED(); 111 NOTREACHED();
104 return 0; 112 return 0;
105 } 113 }
106 114
107 size_t SubsamplingFactorForBufferFormat(BufferFormat format, int plane) { 115 size_t SubsamplingFactorForBufferFormat(BufferFormat format, int plane) {
108 switch (format) { 116 switch (format) {
109 case BufferFormat::ATC: 117 case BufferFormat::ATC:
110 case BufferFormat::ATCIA: 118 case BufferFormat::ATCIA:
111 case BufferFormat::DXT1: 119 case BufferFormat::DXT1:
112 case BufferFormat::DXT5: 120 case BufferFormat::DXT5:
113 case BufferFormat::ETC1: 121 case BufferFormat::ETC1:
114 case BufferFormat::R_8: 122 case BufferFormat::R_8:
115 case BufferFormat::RGBA_4444: 123 case BufferFormat::RGBA_4444:
124 case BufferFormat::RGBX_8888:
116 case BufferFormat::RGBA_8888: 125 case BufferFormat::RGBA_8888:
117 case BufferFormat::BGRX_8888: 126 case BufferFormat::BGRX_8888:
118 case BufferFormat::BGRA_8888: 127 case BufferFormat::BGRA_8888:
119 case BufferFormat::UYVY_422: 128 case BufferFormat::UYVY_422:
120 return 1; 129 return 1;
121 case BufferFormat::YUV_420: { 130 case BufferFormat::YUV_420: {
122 static size_t factor[] = {1, 2, 2}; 131 static size_t factor[] = {1, 2, 2};
123 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); 132 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
124 return factor[plane]; 133 return factor[plane];
125 } 134 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 size_t plane) { 183 size_t plane) {
175 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format)); 184 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format));
176 switch (format) { 185 switch (format) {
177 case BufferFormat::ATC: 186 case BufferFormat::ATC:
178 case BufferFormat::ATCIA: 187 case BufferFormat::ATCIA:
179 case BufferFormat::DXT1: 188 case BufferFormat::DXT1:
180 case BufferFormat::DXT5: 189 case BufferFormat::DXT5:
181 case BufferFormat::ETC1: 190 case BufferFormat::ETC1:
182 case BufferFormat::R_8: 191 case BufferFormat::R_8:
183 case BufferFormat::RGBA_4444: 192 case BufferFormat::RGBA_4444:
193 case BufferFormat::RGBX_8888:
184 case BufferFormat::RGBA_8888: 194 case BufferFormat::RGBA_8888:
185 case BufferFormat::BGRX_8888: 195 case BufferFormat::BGRX_8888:
186 case BufferFormat::BGRA_8888: 196 case BufferFormat::BGRA_8888:
187 case BufferFormat::UYVY_422: 197 case BufferFormat::UYVY_422:
188 return 0; 198 return 0;
189 case BufferFormat::YUV_420: { 199 case BufferFormat::YUV_420: {
190 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4, 5}; 200 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4, 5};
191 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); 201 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
192 return offset_in_2x2_sub_sampling_sizes[plane] * 202 return offset_in_2x2_sub_sampling_sizes[plane] *
193 (size.width() / 2 + size.height() / 2); 203 (size.width() / 2 + size.height() / 2);
194 } 204 }
195 case gfx::BufferFormat::YUV_420_BIPLANAR: { 205 case gfx::BufferFormat::YUV_420_BIPLANAR: {
196 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4}; 206 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4};
197 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); 207 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
198 return offset_in_2x2_sub_sampling_sizes[plane] * 208 return offset_in_2x2_sub_sampling_sizes[plane] *
199 (size.width() / 2 + size.height() / 2); 209 (size.width() / 2 + size.height() / 2);
200 } 210 }
201 } 211 }
202 NOTREACHED(); 212 NOTREACHED();
203 return 0; 213 return 0;
204 } 214 }
205 215
206 } // namespace gfx 216 } // namespace gfx
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc ('k') | ui/gfx/buffer_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698