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

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

Issue 2636433003: [NotForReview] Enable YUV video overlay on Skylake ChromeOS.
Patch Set: Created 3 years, 11 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 | « media/video/gpu_memory_buffer_video_frame_pool_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/macros.h" 8 #include "base/macros.h"
9 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 namespace { 12 namespace {
13 13
14 const BufferFormat kBufferFormats[] = {BufferFormat::ATC, 14 const BufferFormat kBufferFormats[] = {
15 BufferFormat::ATCIA, 15 BufferFormat::ATC, BufferFormat::ATCIA,
16 BufferFormat::DXT1, 16 BufferFormat::DXT1, BufferFormat::DXT5,
17 BufferFormat::DXT5, 17 BufferFormat::ETC1, BufferFormat::R_8,
18 BufferFormat::ETC1, 18 BufferFormat::RG_88, BufferFormat::BGR_565,
19 BufferFormat::R_8, 19 BufferFormat::RGBA_4444, BufferFormat::RGBX_8888,
20 BufferFormat::RG_88, 20 BufferFormat::RGBA_8888, BufferFormat::BGRX_8888,
21 BufferFormat::BGR_565, 21 BufferFormat::BGRA_8888, BufferFormat::UYVY_422,
22 BufferFormat::RGBA_4444, 22 BufferFormat::YUYV_422, BufferFormat::YUV_420_BIPLANAR,
23 BufferFormat::RGBX_8888, 23 BufferFormat::YVU_420};
24 BufferFormat::RGBA_8888,
25 BufferFormat::BGRX_8888,
26 BufferFormat::BGRA_8888,
27 BufferFormat::UYVY_422,
28 BufferFormat::YUV_420_BIPLANAR,
29 BufferFormat::YVU_420};
30 24
31 static_assert(arraysize(kBufferFormats) == 25 static_assert(arraysize(kBufferFormats) ==
32 (static_cast<int>(BufferFormat::LAST) + 1), 26 (static_cast<int>(BufferFormat::LAST) + 1),
33 "BufferFormat::LAST must be last value of kBufferFormats"); 27 "BufferFormat::LAST must be last value of kBufferFormats");
34 28
35 29
36 bool RowSizeForBufferFormatChecked( 30 bool RowSizeForBufferFormatChecked(
37 size_t width, BufferFormat format, size_t plane, size_t* size_in_bytes) { 31 size_t width, BufferFormat format, size_t plane, size_t* size_in_bytes) {
38 base::CheckedNumeric<size_t> checked_size = width; 32 base::CheckedNumeric<size_t> checked_size = width;
39 switch (format) { 33 switch (format) {
(...skipping 12 matching lines...) Expand all
52 case BufferFormat::R_8: 46 case BufferFormat::R_8:
53 checked_size += 3; 47 checked_size += 3;
54 if (!checked_size.IsValid()) 48 if (!checked_size.IsValid())
55 return false; 49 return false;
56 *size_in_bytes = (checked_size & ~0x3).ValueOrDie(); 50 *size_in_bytes = (checked_size & ~0x3).ValueOrDie();
57 return true; 51 return true;
58 case BufferFormat::RG_88: 52 case BufferFormat::RG_88:
59 case BufferFormat::BGR_565: 53 case BufferFormat::BGR_565:
60 case BufferFormat::RGBA_4444: 54 case BufferFormat::RGBA_4444:
61 case BufferFormat::UYVY_422: 55 case BufferFormat::UYVY_422:
56 case BufferFormat::YUYV_422:
62 checked_size *= 2; 57 checked_size *= 2;
63 checked_size += 3; 58 checked_size += 3;
64 if (!checked_size.IsValid()) 59 if (!checked_size.IsValid())
65 return false; 60 return false;
66 *size_in_bytes = (checked_size & ~0x3).ValueOrDie(); 61 *size_in_bytes = (checked_size & ~0x3).ValueOrDie();
67 return true; 62 return true;
68 case BufferFormat::BGRX_8888: 63 case BufferFormat::BGRX_8888:
69 case BufferFormat::RGBX_8888: 64 case BufferFormat::RGBX_8888:
70 case BufferFormat::RGBA_8888: 65 case BufferFormat::RGBA_8888:
71 case BufferFormat::BGRA_8888: 66 case BufferFormat::BGRA_8888:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 case BufferFormat::ETC1: 98 case BufferFormat::ETC1:
104 case BufferFormat::R_8: 99 case BufferFormat::R_8:
105 case BufferFormat::RG_88: 100 case BufferFormat::RG_88:
106 case BufferFormat::BGR_565: 101 case BufferFormat::BGR_565:
107 case BufferFormat::RGBA_4444: 102 case BufferFormat::RGBA_4444:
108 case BufferFormat::RGBX_8888: 103 case BufferFormat::RGBX_8888:
109 case BufferFormat::RGBA_8888: 104 case BufferFormat::RGBA_8888:
110 case BufferFormat::BGRX_8888: 105 case BufferFormat::BGRX_8888:
111 case BufferFormat::BGRA_8888: 106 case BufferFormat::BGRA_8888:
112 case BufferFormat::UYVY_422: 107 case BufferFormat::UYVY_422:
108 case BufferFormat::YUYV_422:
113 return 1; 109 return 1;
114 case BufferFormat::YUV_420_BIPLANAR: 110 case BufferFormat::YUV_420_BIPLANAR:
115 return 2; 111 return 2;
116 case BufferFormat::YVU_420: 112 case BufferFormat::YVU_420:
117 return 3; 113 return 3;
118 } 114 }
119 NOTREACHED(); 115 NOTREACHED();
120 return 0; 116 return 0;
121 } 117 }
122 118
123 size_t SubsamplingFactorForBufferFormat(BufferFormat format, size_t plane) { 119 size_t SubsamplingFactorForBufferFormat(BufferFormat format, size_t plane) {
124 switch (format) { 120 switch (format) {
125 case BufferFormat::ATC: 121 case BufferFormat::ATC:
126 case BufferFormat::ATCIA: 122 case BufferFormat::ATCIA:
127 case BufferFormat::DXT1: 123 case BufferFormat::DXT1:
128 case BufferFormat::DXT5: 124 case BufferFormat::DXT5:
129 case BufferFormat::ETC1: 125 case BufferFormat::ETC1:
130 case BufferFormat::R_8: 126 case BufferFormat::R_8:
131 case BufferFormat::RG_88: 127 case BufferFormat::RG_88:
132 case BufferFormat::BGR_565: 128 case BufferFormat::BGR_565:
133 case BufferFormat::RGBA_4444: 129 case BufferFormat::RGBA_4444:
134 case BufferFormat::RGBX_8888: 130 case BufferFormat::RGBX_8888:
135 case BufferFormat::RGBA_8888: 131 case BufferFormat::RGBA_8888:
136 case BufferFormat::BGRX_8888: 132 case BufferFormat::BGRX_8888:
137 case BufferFormat::BGRA_8888: 133 case BufferFormat::BGRA_8888:
138 case BufferFormat::UYVY_422: 134 case BufferFormat::UYVY_422:
135 case BufferFormat::YUYV_422:
139 return 1; 136 return 1;
140 case BufferFormat::YVU_420: { 137 case BufferFormat::YVU_420: {
141 static size_t factor[] = {1, 2, 2}; 138 static size_t factor[] = {1, 2, 2};
142 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); 139 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
143 return factor[plane]; 140 return factor[plane];
144 } 141 }
145 case BufferFormat::YUV_420_BIPLANAR: { 142 case BufferFormat::YUV_420_BIPLANAR: {
146 static size_t factor[] = {1, 2}; 143 static size_t factor[] = {1, 2};
147 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); 144 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
148 return factor[plane]; 145 return factor[plane];
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 case BufferFormat::ETC1: 197 case BufferFormat::ETC1:
201 case BufferFormat::R_8: 198 case BufferFormat::R_8:
202 case BufferFormat::RG_88: 199 case BufferFormat::RG_88:
203 case BufferFormat::BGR_565: 200 case BufferFormat::BGR_565:
204 case BufferFormat::RGBA_4444: 201 case BufferFormat::RGBA_4444:
205 case BufferFormat::RGBX_8888: 202 case BufferFormat::RGBX_8888:
206 case BufferFormat::RGBA_8888: 203 case BufferFormat::RGBA_8888:
207 case BufferFormat::BGRX_8888: 204 case BufferFormat::BGRX_8888:
208 case BufferFormat::BGRA_8888: 205 case BufferFormat::BGRA_8888:
209 case BufferFormat::UYVY_422: 206 case BufferFormat::UYVY_422:
207 case BufferFormat::YUYV_422:
210 return 0; 208 return 0;
211 case BufferFormat::YVU_420: { 209 case BufferFormat::YVU_420: {
212 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4, 5}; 210 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4, 5};
213 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); 211 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
214 return offset_in_2x2_sub_sampling_sizes[plane] * 212 return offset_in_2x2_sub_sampling_sizes[plane] *
215 (size.width() / 2 + size.height() / 2); 213 (size.width() / 2 + size.height() / 2);
216 } 214 }
217 case gfx::BufferFormat::YUV_420_BIPLANAR: { 215 case gfx::BufferFormat::YUV_420_BIPLANAR: {
218 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4}; 216 static size_t offset_in_2x2_sub_sampling_sizes[] = {0, 4};
219 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); 217 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes));
220 return offset_in_2x2_sub_sampling_sizes[plane] * 218 return offset_in_2x2_sub_sampling_sizes[plane] *
221 (size.width() / 2 + size.height() / 2); 219 (size.width() / 2 + size.height() / 2);
222 } 220 }
223 } 221 }
224 NOTREACHED(); 222 NOTREACHED();
225 return 0; 223 return 0;
226 } 224 }
227 225
228 } // namespace gfx 226 } // namespace gfx
OLDNEW
« no previous file with comments | « media/video/gpu_memory_buffer_video_frame_pool_unittest.cc ('k') | ui/gfx/buffer_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698