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