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 "third_party/skia/include/core/SkTypes.h" | |
10 #include "ui/gl/gl_context.h" | |
11 #include "ui/gl/gl_implementation.h" | 9 #include "ui/gl/gl_implementation.h" |
12 #include "ui/gl/gl_version_info.h" | |
13 #include "ui/gl/test/gl_surface_test_support.h" | 10 #include "ui/gl/test/gl_surface_test_support.h" |
14 | 11 |
15 #if defined(USE_OZONE) | 12 #if defined(USE_OZONE) |
16 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
17 #endif | 14 #endif |
18 | 15 |
19 namespace gfx { | 16 namespace gfx { |
20 | 17 |
21 // static | 18 // static |
22 void GLImageTestSupport::InitializeGL() { | 19 void GLImageTestSupport::InitializeGL() { |
23 #if defined(USE_OZONE) | 20 #if defined(USE_OZONE) |
24 // On Ozone, the backend initializes the event system using a UI thread. | 21 // On Ozone, the backend initializes the event system using a UI thread. |
25 base::MessageLoopForUI main_loop; | 22 base::MessageLoopForUI main_loop; |
26 #endif | 23 #endif |
27 | 24 |
28 std::vector<GLImplementation> allowed_impls; | 25 std::vector<GLImplementation> allowed_impls; |
29 GetAllowedGLImplementations(&allowed_impls); | 26 GetAllowedGLImplementations(&allowed_impls); |
30 DCHECK(!allowed_impls.empty()); | 27 DCHECK(!allowed_impls.empty()); |
31 | 28 |
32 GLImplementation impl = allowed_impls[0]; | 29 GLImplementation impl = allowed_impls[0]; |
33 GLSurfaceTestSupport::InitializeOneOffImplementation(impl, true); | 30 GLSurfaceTestSupport::InitializeOneOffImplementation(impl, true); |
34 } | 31 } |
35 | 32 |
36 // static | 33 // static |
37 void GLImageTestSupport::CleanupGL() { | 34 void GLImageTestSupport::CleanupGL() { |
38 ClearGLBindings(); | 35 ClearGLBindings(); |
39 } | 36 } |
40 | 37 |
41 // static | 38 // static |
42 GLenum GLImageTestSupport::GetPreferredInternalFormat() { | |
43 bool has_texture_format_bgra8888 = | |
44 GLContext::GetCurrent()->HasExtension( | |
45 "GL_APPLE_texture_format_BGRA8888") || | |
46 GLContext::GetCurrent()->HasExtension("GL_EXT_texture_format_BGRA8888") || | |
47 !GLContext::GetCurrent()->GetVersionInfo()->is_es; | |
48 return (!SK_B32_SHIFT && has_texture_format_bgra8888) ? GL_BGRA_EXT : GL_RGBA; | |
49 } | |
50 | |
51 // static | |
52 BufferFormat GLImageTestSupport::GetPreferredBufferFormat() { | |
53 return GetPreferredInternalFormat() == GL_BGRA_EXT ? BufferFormat::BGRA_8888 | |
54 : BufferFormat::RGBA_8888; | |
55 } | |
56 | |
57 // static | |
58 void GLImageTestSupport::SetBufferDataToColor(int width, | 39 void GLImageTestSupport::SetBufferDataToColor(int width, |
59 int height, | 40 int height, |
60 int stride, | 41 int stride, |
61 BufferFormat format, | 42 BufferFormat format, |
62 const uint8_t color[4], | 43 const uint8_t color[4], |
63 uint8_t* data) { | 44 uint8_t* data) { |
64 switch (format) { | 45 switch (format) { |
| 46 case BufferFormat::RGBX_8888: |
| 47 for (int y = 0; y < height; ++y) { |
| 48 for (int x = 0; x < width; ++x) { |
| 49 data[y * stride + x * 4 + 0] = color[0]; |
| 50 data[y * stride + x * 4 + 1] = color[1]; |
| 51 data[y * stride + x * 4 + 2] = color[2]; |
| 52 data[y * stride + x * 4 + 3] = 0xaa; // unused |
| 53 } |
| 54 } |
| 55 return; |
65 case BufferFormat::RGBA_8888: | 56 case BufferFormat::RGBA_8888: |
66 for (int y = 0; y < height; ++y) { | 57 for (int y = 0; y < height; ++y) { |
67 for (int x = 0; x < width; ++x) { | 58 for (int x = 0; x < width; ++x) { |
68 data[y * stride + x * 4 + 0] = color[0]; | 59 data[y * stride + x * 4 + 0] = color[0]; |
69 data[y * stride + x * 4 + 1] = color[1]; | 60 data[y * stride + x * 4 + 1] = color[1]; |
70 data[y * stride + x * 4 + 2] = color[2]; | 61 data[y * stride + x * 4 + 2] = color[2]; |
71 data[y * stride + x * 4 + 3] = color[3]; | 62 data[y * stride + x * 4 + 3] = color[3]; |
72 } | 63 } |
73 } | 64 } |
74 return; | 65 return; |
| 66 case BufferFormat::BGRX_8888: |
| 67 for (int y = 0; y < height; ++y) { |
| 68 for (int x = 0; x < width; ++x) { |
| 69 data[y * stride + x * 4 + 0] = color[2]; |
| 70 data[y * stride + x * 4 + 1] = color[1]; |
| 71 data[y * stride + x * 4 + 2] = color[0]; |
| 72 data[y * stride + x * 4 + 3] = 0xaa; // unused |
| 73 } |
| 74 } |
| 75 return; |
75 case BufferFormat::BGRA_8888: | 76 case BufferFormat::BGRA_8888: |
76 for (int y = 0; y < height; ++y) { | 77 for (int y = 0; y < height; ++y) { |
77 for (int x = 0; x < width; ++x) { | 78 for (int x = 0; x < width; ++x) { |
78 data[y * stride + x * 4 + 0] = color[2]; | 79 data[y * stride + x * 4 + 0] = color[2]; |
79 data[y * stride + x * 4 + 1] = color[1]; | 80 data[y * stride + x * 4 + 1] = color[1]; |
80 data[y * stride + x * 4 + 2] = color[0]; | 81 data[y * stride + x * 4 + 2] = color[0]; |
81 data[y * stride + x * 4 + 3] = color[3]; | 82 data[y * stride + x * 4 + 3] = color[3]; |
82 } | 83 } |
83 } | 84 } |
84 return; | 85 return; |
85 case BufferFormat::ATC: | 86 case BufferFormat::ATC: |
86 case BufferFormat::ATCIA: | 87 case BufferFormat::ATCIA: |
87 case BufferFormat::DXT1: | 88 case BufferFormat::DXT1: |
88 case BufferFormat::DXT5: | 89 case BufferFormat::DXT5: |
89 case BufferFormat::ETC1: | 90 case BufferFormat::ETC1: |
90 case BufferFormat::R_8: | 91 case BufferFormat::R_8: |
91 case BufferFormat::RGBA_4444: | 92 case BufferFormat::RGBA_4444: |
92 case BufferFormat::BGRX_8888: | |
93 case BufferFormat::UYVY_422: | 93 case BufferFormat::UYVY_422: |
94 case BufferFormat::YUV_420_BIPLANAR: | 94 case BufferFormat::YUV_420_BIPLANAR: |
95 case BufferFormat::YUV_420: | 95 case BufferFormat::YUV_420: |
96 NOTREACHED(); | 96 NOTREACHED(); |
97 return; | 97 return; |
98 } | 98 } |
99 NOTREACHED(); | 99 NOTREACHED(); |
100 } | 100 } |
101 | 101 |
102 } // namespace gfx | 102 } // namespace gfx |
OLD | NEW |