Chromium Code Reviews| 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 <stdint.h> | 5 #include <stdint.h> | 
| 6 | 6 | 
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" | 
| 8 #include "ui/gfx/buffer_types.h" | 8 #include "ui/gfx/buffer_types.h" | 
| 9 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 9 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 
| 10 #include "ui/gl/test/gl_image_test_template.h" | 10 #include "ui/gl/test/gl_image_test_template.h" | 
| 11 #include "ui/ozone/public/client_native_pixmap_factory.h" | |
| 11 #include "ui/ozone/public/ozone_platform.h" | 12 #include "ui/ozone/public/ozone_platform.h" | 
| 12 #include "ui/ozone/public/surface_factory_ozone.h" | 13 #include "ui/ozone/public/surface_factory_ozone.h" | 
| 13 | 14 | 
| 14 namespace gl { | 15 namespace gl { | 
| 15 namespace { | 16 namespace { | 
| 16 | 17 | 
| 18 GLenum TextureFormat(gfx::BufferFormat format) { | |
| 19 switch (format) { | |
| 20 case gfx::BufferFormat::R_8: | |
| 21 return GL_RED; | |
| 22 case gfx::BufferFormat::RGBA_8888: | |
| 23 return GL_RGBA; | |
| 24 case gfx::BufferFormat::BGRA_8888: | |
| 25 return GL_BGRA_EXT; | |
| 26 case gfx::BufferFormat::RGBX_8888: | |
| 27 case gfx::BufferFormat::BGRX_8888: | |
| 28 return GL_RGB; | |
| 29 case gfx::BufferFormat::ATC: | |
| 30 case gfx::BufferFormat::ATCIA: | |
| 31 case gfx::BufferFormat::DXT1: | |
| 32 case gfx::BufferFormat::DXT5: | |
| 33 case gfx::BufferFormat::ETC1: | |
| 34 case gfx::BufferFormat::RGBA_4444: | |
| 35 case gfx::BufferFormat::YUV_420: | |
| 36 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
| 37 case gfx::BufferFormat::UYVY_422: | |
| 38 NOTREACHED(); | |
| 39 return 0; | |
| 40 } | |
| 41 | |
| 42 NOTREACHED(); | |
| 43 return 0; | |
| 44 } | |
| 45 | |
| 46 template <gfx::BufferFormat format, gfx::BufferUsage usage> | |
| 17 class GLImageOzoneNativePixmapTestDelegate { | 47 class GLImageOzoneNativePixmapTestDelegate { | 
| 18 public: | 48 public: | 
| 49 scoped_refptr<GLImage> CreateImage(const gfx::Size& size) const { | |
| 50 ui::SurfaceFactoryOzone* surface_factory = | |
| 51 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | |
| 52 scoped_refptr<ui::NativePixmap> pixmap = | |
| 53 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | |
| 54 format, usage); | |
| 55 EXPECT_TRUE(pixmap != nullptr); | |
| 56 | |
| 57 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | |
| 58 new gfx::GLImageOzoneNativePixmap(size, TextureFormat(format))); | |
| 59 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | |
| 60 return image; | |
| 61 } | |
| 62 | |
| 19 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 63 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 
| 20 const gfx::Size& size, | 64 const gfx::Size& size, | 
| 21 const uint8_t color[4]) const { | 65 const uint8_t color[4]) const { | 
| 22 ui::SurfaceFactoryOzone* surface_factory = | 66 ui::SurfaceFactoryOzone* surface_factory = | 
| 23 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 67 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 
| 24 scoped_refptr<ui::NativePixmap> pixmap = | 68 scoped_refptr<ui::NativePixmap> pixmap = | 
| 25 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 69 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 
| 26 gfx::BufferFormat::RGBA_8888, | 70 format, usage); | 
| 27 gfx::BufferUsage::SCANOUT); | |
| 28 EXPECT_TRUE(pixmap != nullptr); | 71 EXPECT_TRUE(pixmap != nullptr); | 
| 72 | |
| 73 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE || | |
| 74 usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT) { | |
| 75 gfx::NativePixmapHandle handle = pixmap->ExportHandle(); | |
| 76 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = | |
| 77 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | |
| 78 handle, size, usage); | |
| 79 EXPECT_TRUE(native_pixmap != nullptr); | |
| 80 | |
| 81 GLImageTestSupport::SetBufferDataToColor( | |
| 82 size.width(), size.height(), handle.stride, 0, format, color, | |
| 83 reinterpret_cast<uint8_t*>(native_pixmap->Map())); | |
| 84 native_pixmap->Unmap(); | |
| 85 } else { | |
| 86 // Cannot paint |color| on GPU_READ and SCANOUT buffer, but GLImageTest | |
| 87 // doesn't check actual color, so it's fine so far. | |
| 88 } | |
| 89 | |
| 29 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | 90 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | 
| 30 new gfx::GLImageOzoneNativePixmap(size, GL_RGBA)); | 91 new gfx::GLImageOzoneNativePixmap(size, TextureFormat(format))); | 
| 31 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | 92 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | 
| 32 return image; | 93 return image; | 
| 33 } | 94 } | 
| 34 | 95 | 
| 35 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } | 96 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } | 
| 97 | |
| 98 gfx::BufferFormat GetBufferFormat() const { return format; } | |
| 99 | |
| 100 bool IsSupported() { | |
| 101 return ui::ClientNativePixmapFactory::GetInstance() | |
| 102 ->IsConfigurationSupported(format, usage); | |
| 103 } | |
| 36 }; | 104 }; | 
| 37 | 105 | 
| 106 using GLImageTestTypes = testing::Types< | |
| 107 GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::RGBA_8888, | |
| 108 gfx::BufferUsage::SCANOUT>, | |
| 109 GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::RGBX_8888, | |
| 110 gfx::BufferUsage::SCANOUT>, | |
| 111 GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::BGRA_8888, | |
| 112 gfx::BufferUsage::SCANOUT>, | |
| 113 GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::BGRX_8888, | |
| 114 gfx::BufferUsage::SCANOUT>>; | |
| 115 | |
| 38 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, | 116 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, | 
| 39 GLImageTest, | 117 GLImageTest, | 
| 40 GLImageOzoneNativePixmapTestDelegate); | 118 GLImageTestTypes); | 
| 119 | |
| 120 using GLImageBindTestTypes = | |
| 121 testing::Types<GLImageOzoneNativePixmapTestDelegate< | |
| 122 gfx::BufferFormat::R_8, | |
| 123 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>, | |
| 124 GLImageOzoneNativePixmapTestDelegate< | |
| 125 gfx::BufferFormat::BGRA_8888, | |
| 126 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; | |
| 
 
dshwang
2016/05/03 11:40:25
R_8 and BGRA_8888 bind test passes on only ozone g
 
 | |
| 127 | |
| 128 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, | |
| 129 GLImageBindTest, | |
| 130 GLImageBindTestTypes); | |
| 41 | 131 | 
| 42 } // namespace | 132 } // namespace | 
| 43 } // namespace gl | 133 } // namespace gl | 
| OLD | NEW |