OLD | NEW |
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/gl/test/gl_image_test_support.h" | 5 #include "ui/gl/test/gl_image_test_support.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ui/gl/gl_implementation.h" | 9 #include "ui/gl/gl_implementation.h" |
10 #include "ui/gl/test/gl_surface_test_support.h" | 10 #include "ui/gl/test/gl_surface_test_support.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 // static | 33 // static |
34 void GLImageTestSupport::CleanupGL() { | 34 void GLImageTestSupport::CleanupGL() { |
35 gfx::ClearGLBindings(); | 35 gfx::ClearGLBindings(); |
36 } | 36 } |
37 | 37 |
38 // static | 38 // static |
39 void GLImageTestSupport::SetBufferDataToColor(int width, | 39 void GLImageTestSupport::SetBufferDataToColor(int width, |
40 int height, | 40 int height, |
41 int stride, | 41 int stride, |
| 42 int plane, |
42 gfx::BufferFormat format, | 43 gfx::BufferFormat format, |
43 const uint8_t color[4], | 44 const uint8_t color[4], |
44 uint8_t* data) { | 45 uint8_t* data) { |
45 switch (format) { | 46 switch (format) { |
46 case gfx::BufferFormat::RGBX_8888: | 47 case gfx::BufferFormat::RGBX_8888: |
| 48 DCHECK_EQ(0, plane); |
47 for (int y = 0; y < height; ++y) { | 49 for (int y = 0; y < height; ++y) { |
48 for (int x = 0; x < width; ++x) { | 50 for (int x = 0; x < width; ++x) { |
49 data[y * stride + x * 4 + 0] = color[0]; | 51 data[y * stride + x * 4 + 0] = color[0]; |
50 data[y * stride + x * 4 + 1] = color[1]; | 52 data[y * stride + x * 4 + 1] = color[1]; |
51 data[y * stride + x * 4 + 2] = color[2]; | 53 data[y * stride + x * 4 + 2] = color[2]; |
52 data[y * stride + x * 4 + 3] = 0xaa; // unused | 54 data[y * stride + x * 4 + 3] = 0xaa; // unused |
53 } | 55 } |
54 } | 56 } |
55 return; | 57 return; |
56 case gfx::BufferFormat::RGBA_8888: | 58 case gfx::BufferFormat::RGBA_8888: |
| 59 DCHECK_EQ(0, plane); |
57 for (int y = 0; y < height; ++y) { | 60 for (int y = 0; y < height; ++y) { |
58 for (int x = 0; x < width; ++x) { | 61 for (int x = 0; x < width; ++x) { |
59 data[y * stride + x * 4 + 0] = color[0]; | 62 data[y * stride + x * 4 + 0] = color[0]; |
60 data[y * stride + x * 4 + 1] = color[1]; | 63 data[y * stride + x * 4 + 1] = color[1]; |
61 data[y * stride + x * 4 + 2] = color[2]; | 64 data[y * stride + x * 4 + 2] = color[2]; |
62 data[y * stride + x * 4 + 3] = color[3]; | 65 data[y * stride + x * 4 + 3] = color[3]; |
63 } | 66 } |
64 } | 67 } |
65 return; | 68 return; |
66 case gfx::BufferFormat::BGRX_8888: | 69 case gfx::BufferFormat::BGRX_8888: |
| 70 DCHECK_EQ(0, plane); |
67 for (int y = 0; y < height; ++y) { | 71 for (int y = 0; y < height; ++y) { |
68 for (int x = 0; x < width; ++x) { | 72 for (int x = 0; x < width; ++x) { |
69 data[y * stride + x * 4 + 0] = color[2]; | 73 data[y * stride + x * 4 + 0] = color[2]; |
70 data[y * stride + x * 4 + 1] = color[1]; | 74 data[y * stride + x * 4 + 1] = color[1]; |
71 data[y * stride + x * 4 + 2] = color[0]; | 75 data[y * stride + x * 4 + 2] = color[0]; |
72 data[y * stride + x * 4 + 3] = 0xaa; // unused | 76 data[y * stride + x * 4 + 3] = 0xaa; // unused |
73 } | 77 } |
74 } | 78 } |
75 return; | 79 return; |
76 case gfx::BufferFormat::BGRA_8888: | 80 case gfx::BufferFormat::BGRA_8888: |
| 81 DCHECK_EQ(0, plane); |
77 for (int y = 0; y < height; ++y) { | 82 for (int y = 0; y < height; ++y) { |
78 for (int x = 0; x < width; ++x) { | 83 for (int x = 0; x < width; ++x) { |
79 data[y * stride + x * 4 + 0] = color[2]; | 84 data[y * stride + x * 4 + 0] = color[2]; |
80 data[y * stride + x * 4 + 1] = color[1]; | 85 data[y * stride + x * 4 + 1] = color[1]; |
81 data[y * stride + x * 4 + 2] = color[0]; | 86 data[y * stride + x * 4 + 2] = color[0]; |
82 data[y * stride + x * 4 + 3] = color[3]; | 87 data[y * stride + x * 4 + 3] = color[3]; |
83 } | 88 } |
84 } | 89 } |
85 return; | 90 return; |
| 91 case gfx::BufferFormat::YUV_420_BIPLANAR: { |
| 92 DCHECK_LT(plane, 2); |
| 93 DCHECK_EQ(0, height % 2); |
| 94 DCHECK_EQ(0, width % 2); |
| 95 // These values are used in the transformation from YUV to RGB color |
| 96 // values. They are taken from the following webpage: |
| 97 // http://www.fourcc.org/fccyvrgb.php |
| 98 uint8_t yuv[] = { |
| 99 (0.257 * color[0]) + (0.504 * color[1]) + (0.098 * color[2]) + 16, |
| 100 -(0.148 * color[0]) - (0.291 * color[1]) + (0.439 * color[2]) + 128, |
| 101 (0.439 * color[0]) - (0.368 * color[1]) - (0.071 * color[2]) + 128}; |
| 102 if (plane == 0) { |
| 103 for (int y = 0; y < height; ++y) { |
| 104 for (int x = 0; x < width; ++x) { |
| 105 data[stride * y + x] = yuv[0]; |
| 106 } |
| 107 } |
| 108 } else { |
| 109 for (int y = 0; y < height / 2; ++y) { |
| 110 for (int x = 0; x < width / 2; ++x) { |
| 111 data[stride * y + x * 2] = yuv[1]; |
| 112 data[stride * y + x * 2 + 1] = yuv[2]; |
| 113 } |
| 114 } |
| 115 } |
| 116 return; |
| 117 } |
86 case gfx::BufferFormat::ATC: | 118 case gfx::BufferFormat::ATC: |
87 case gfx::BufferFormat::ATCIA: | 119 case gfx::BufferFormat::ATCIA: |
88 case gfx::BufferFormat::DXT1: | 120 case gfx::BufferFormat::DXT1: |
89 case gfx::BufferFormat::DXT5: | 121 case gfx::BufferFormat::DXT5: |
90 case gfx::BufferFormat::ETC1: | 122 case gfx::BufferFormat::ETC1: |
91 case gfx::BufferFormat::R_8: | 123 case gfx::BufferFormat::R_8: |
92 case gfx::BufferFormat::RGBA_4444: | 124 case gfx::BufferFormat::RGBA_4444: |
93 case gfx::BufferFormat::UYVY_422: | 125 case gfx::BufferFormat::UYVY_422: |
94 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
95 case gfx::BufferFormat::YUV_420: | 126 case gfx::BufferFormat::YUV_420: |
96 NOTREACHED(); | 127 NOTREACHED(); |
97 return; | 128 return; |
98 } | 129 } |
99 NOTREACHED(); | 130 NOTREACHED(); |
100 } | 131 } |
101 | 132 |
102 } // namespace gl | 133 } // namespace gl |
OLD | NEW |