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 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 // static | 33 // static |
34 void GLImageTestSupport::CleanupGL() { | 34 void GLImageTestSupport::CleanupGL() { |
35 ClearGLBindings(); | 35 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 strides[], |
42 BufferFormat format, | 42 BufferFormat format, |
43 const uint8_t color[4], | 43 const uint8_t color[4], |
44 uint8_t* data) { | 44 uint8_t* data[]) { |
45 switch (format) { | 45 switch (format) { |
46 case BufferFormat::RGBX_8888: | 46 case BufferFormat::RGBX_8888: { |
| 47 uint8_t* rgbx_data = data[0]; |
| 48 int stride = strides[0]; |
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 rgbx_data[y * stride + x * 4 + 0] = color[0]; |
50 data[y * stride + x * 4 + 1] = color[1]; | 52 rgbx_data[y * stride + x * 4 + 1] = color[1]; |
51 data[y * stride + x * 4 + 2] = color[2]; | 53 rgbx_data[y * stride + x * 4 + 2] = color[2]; |
52 data[y * stride + x * 4 + 3] = 0xaa; // unused | 54 rgbx_data[y * stride + x * 4 + 3] = 0xaa; // unused |
53 } | 55 } |
54 } | 56 } |
| 57 } |
55 return; | 58 return; |
56 case BufferFormat::RGBA_8888: | 59 case BufferFormat::RGBA_8888: { |
| 60 uint8_t* rgba_data = data[0]; |
| 61 int stride = strides[0]; |
57 for (int y = 0; y < height; ++y) { | 62 for (int y = 0; y < height; ++y) { |
58 for (int x = 0; x < width; ++x) { | 63 for (int x = 0; x < width; ++x) { |
59 data[y * stride + x * 4 + 0] = color[0]; | 64 rgba_data[y * stride + x * 4 + 0] = color[0]; |
60 data[y * stride + x * 4 + 1] = color[1]; | 65 rgba_data[y * stride + x * 4 + 1] = color[1]; |
61 data[y * stride + x * 4 + 2] = color[2]; | 66 rgba_data[y * stride + x * 4 + 2] = color[2]; |
62 data[y * stride + x * 4 + 3] = color[3]; | 67 rgba_data[y * stride + x * 4 + 3] = color[3]; |
63 } | 68 } |
64 } | 69 } |
| 70 } |
65 return; | 71 return; |
66 case BufferFormat::BGRX_8888: | 72 case BufferFormat::BGRX_8888: { |
| 73 uint8_t* bgrx_data = data[0]; |
| 74 int stride = strides[0]; |
67 for (int y = 0; y < height; ++y) { | 75 for (int y = 0; y < height; ++y) { |
68 for (int x = 0; x < width; ++x) { | 76 for (int x = 0; x < width; ++x) { |
69 data[y * stride + x * 4 + 0] = color[2]; | 77 bgrx_data[y * stride + x * 4 + 0] = color[2]; |
70 data[y * stride + x * 4 + 1] = color[1]; | 78 bgrx_data[y * stride + x * 4 + 1] = color[1]; |
71 data[y * stride + x * 4 + 2] = color[0]; | 79 bgrx_data[y * stride + x * 4 + 2] = color[0]; |
72 data[y * stride + x * 4 + 3] = 0xaa; // unused | 80 bgrx_data[y * stride + x * 4 + 3] = 0xaa; // unused |
73 } | 81 } |
74 } | 82 } |
| 83 } |
75 return; | 84 return; |
76 case BufferFormat::BGRA_8888: | 85 case BufferFormat::BGRA_8888: { |
| 86 uint8_t* bgra_data = data[0]; |
| 87 int stride = strides[0]; |
77 for (int y = 0; y < height; ++y) { | 88 for (int y = 0; y < height; ++y) { |
78 for (int x = 0; x < width; ++x) { | 89 for (int x = 0; x < width; ++x) { |
79 data[y * stride + x * 4 + 0] = color[2]; | 90 bgra_data[y * stride + x * 4 + 0] = color[2]; |
80 data[y * stride + x * 4 + 1] = color[1]; | 91 bgra_data[y * stride + x * 4 + 1] = color[1]; |
81 data[y * stride + x * 4 + 2] = color[0]; | 92 bgra_data[y * stride + x * 4 + 2] = color[0]; |
82 data[y * stride + x * 4 + 3] = color[3]; | 93 bgra_data[y * stride + x * 4 + 3] = color[3]; |
83 } | 94 } |
84 } | 95 } |
| 96 } |
| 97 return; |
| 98 case BufferFormat::YUV_420_BIPLANAR: { |
| 99 // These values are used in the transformation from YUV to RGB color |
| 100 // values. They are taken from the following webpage: |
| 101 // http://www.fourcc.org/fccyvrgb.php |
| 102 uint8_t yuv[] = { |
| 103 (0.257 * color[0]) + (0.504 * color[1]) + (0.098 * color[2]) + 16, |
| 104 -(0.148 * color[0]) - (0.291 * color[1]) + (0.439 * color[2]) + 128, |
| 105 (0.439 * color[0]) - (0.368 * color[1]) - (0.071 * color[2]) + 128}; |
| 106 uint8_t* y_data = data[0]; |
| 107 uint8_t* uv_data = data[1]; |
| 108 int y_stride = strides[0]; |
| 109 int uv_stride = strides[1]; |
| 110 for (int y = 0; y < height; ++y) { |
| 111 for (int x = 0; x < width; ++x) { |
| 112 y_data[y_stride * y + x] = yuv[0]; |
| 113 } |
| 114 } |
| 115 DCHECK(height % 2 == 0); |
| 116 DCHECK(width % 2 == 0); |
| 117 for (int y = 0; y < height / 2; ++y) { |
| 118 for (int x = 0; x < width / 2; ++x) { |
| 119 uv_data[uv_stride * y + x * 2] = yuv[1]; |
| 120 uv_data[uv_stride * y + x * 2 + 1] = yuv[2]; |
| 121 } |
| 122 } |
| 123 } |
85 return; | 124 return; |
86 case BufferFormat::ATC: | 125 case BufferFormat::ATC: |
87 case BufferFormat::ATCIA: | 126 case BufferFormat::ATCIA: |
88 case BufferFormat::DXT1: | 127 case BufferFormat::DXT1: |
89 case BufferFormat::DXT5: | 128 case BufferFormat::DXT5: |
90 case BufferFormat::ETC1: | 129 case BufferFormat::ETC1: |
91 case BufferFormat::R_8: | 130 case BufferFormat::R_8: |
92 case BufferFormat::RGBA_4444: | 131 case BufferFormat::RGBA_4444: |
93 case BufferFormat::UYVY_422: | 132 case BufferFormat::UYVY_422: |
94 case BufferFormat::YUV_420_BIPLANAR: | |
95 case BufferFormat::YUV_420: | 133 case BufferFormat::YUV_420: |
96 NOTREACHED(); | 134 NOTREACHED(); |
97 return; | 135 return; |
98 } | 136 } |
99 NOTREACHED(); | 137 NOTREACHED(); |
100 } | 138 } |
101 | 139 |
| 140 // static |
| 141 void GLImageTestSupport::SetBufferDataToColor(int width, |
| 142 int height, |
| 143 int stride, |
| 144 BufferFormat format, |
| 145 const uint8_t color[4], |
| 146 uint8_t* data) { |
| 147 uint8_t* planes_data[] = {data}; |
| 148 int strides[] = {stride}; |
| 149 SetBufferDataToColor(width, height, strides, format, color, planes_data); |
| 150 } |
| 151 |
102 } // namespace gfx | 152 } // namespace gfx |
OLD | NEW |