Index: ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
diff --git a/ui/gl/gl_image_ozone_native_pixmap_unittest.cc b/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
index 223ba6980265d186830c794424e9700dbfece1f5..59e4d2a5b000fed6d5c62702bbe980bc006efed7 100644 |
--- a/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
+++ b/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
@@ -8,14 +8,58 @@ |
#include "ui/gfx/buffer_types.h" |
#include "ui/gl/gl_image_ozone_native_pixmap.h" |
#include "ui/gl/test/gl_image_test_template.h" |
+#include "ui/ozone/public/client_native_pixmap_factory.h" |
#include "ui/ozone/public/ozone_platform.h" |
#include "ui/ozone/public/surface_factory_ozone.h" |
namespace gl { |
namespace { |
+GLenum TextureFormat(gfx::BufferFormat format) { |
+ switch (format) { |
+ case gfx::BufferFormat::R_8: |
+ return GL_RED; |
+ case gfx::BufferFormat::RGBA_8888: |
+ return GL_RGBA; |
+ case gfx::BufferFormat::BGRA_8888: |
+ return GL_BGRA_EXT; |
+ case gfx::BufferFormat::RGBX_8888: |
+ case gfx::BufferFormat::BGRX_8888: |
+ return GL_RGB; |
+ case gfx::BufferFormat::ATC: |
+ case gfx::BufferFormat::ATCIA: |
+ case gfx::BufferFormat::DXT1: |
+ case gfx::BufferFormat::DXT5: |
+ case gfx::BufferFormat::ETC1: |
+ case gfx::BufferFormat::RGBA_4444: |
+ case gfx::BufferFormat::YUV_420: |
+ case gfx::BufferFormat::YUV_420_BIPLANAR: |
+ case gfx::BufferFormat::UYVY_422: |
+ NOTREACHED(); |
+ return 0; |
+ } |
+ |
+ NOTREACHED(); |
+ return 0; |
+} |
+ |
+template <gfx::BufferFormat format, gfx::BufferUsage usage> |
class GLImageOzoneNativePixmapTestDelegate { |
public: |
+ scoped_refptr<GLImage> CreateImage(const gfx::Size& size) const { |
+ ui::SurfaceFactoryOzone* surface_factory = |
+ ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
+ scoped_refptr<ui::NativePixmap> pixmap = |
+ surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, |
+ format, usage); |
+ EXPECT_TRUE(pixmap != nullptr); |
+ |
+ scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
+ new gfx::GLImageOzoneNativePixmap(size, TextureFormat(format))); |
+ EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
+ return image; |
+ } |
+ |
scoped_refptr<gl::GLImage> CreateSolidColorImage( |
const gfx::Size& size, |
const uint8_t color[4]) const { |
@@ -23,21 +67,67 @@ class GLImageOzoneNativePixmapTestDelegate { |
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
scoped_refptr<ui::NativePixmap> pixmap = |
surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, |
- gfx::BufferFormat::RGBA_8888, |
- gfx::BufferUsage::SCANOUT); |
+ format, usage); |
EXPECT_TRUE(pixmap != nullptr); |
+ |
+ if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE || |
+ usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT) { |
+ gfx::NativePixmapHandle handle = pixmap->ExportHandle(); |
+ std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
+ ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
+ handle, size, usage); |
+ EXPECT_TRUE(native_pixmap != nullptr); |
+ |
+ GLImageTestSupport::SetBufferDataToColor( |
+ size.width(), size.height(), handle.stride, 0, format, color, |
+ reinterpret_cast<uint8_t*>(native_pixmap->Map())); |
+ native_pixmap->Unmap(); |
+ } else { |
+ // Cannot paint |color| on GPU_READ and SCANOUT buffer, but GLImageTest |
+ // doesn't check actual color, so it's fine so far. |
+ } |
+ |
scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
- new gfx::GLImageOzoneNativePixmap(size, GL_RGBA)); |
+ new gfx::GLImageOzoneNativePixmap(size, TextureFormat(format))); |
EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
return image; |
} |
unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } |
+ |
+ gfx::BufferFormat GetBufferFormat() const { return format; } |
+ |
+ bool IsSupported() { |
+ return ui::ClientNativePixmapFactory::GetInstance() |
+ ->IsConfigurationSupported(format, usage); |
+ } |
}; |
+using GLImageTestTypes = testing::Types< |
+ GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::RGBA_8888, |
+ gfx::BufferUsage::SCANOUT>, |
+ GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::RGBX_8888, |
+ gfx::BufferUsage::SCANOUT>, |
+ GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::BGRA_8888, |
+ gfx::BufferUsage::SCANOUT>, |
+ GLImageOzoneNativePixmapTestDelegate<gfx::BufferFormat::BGRX_8888, |
+ gfx::BufferUsage::SCANOUT>>; |
+ |
INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
GLImageTest, |
- GLImageOzoneNativePixmapTestDelegate); |
+ GLImageTestTypes); |
+ |
+using GLImageBindTestTypes = |
+ testing::Types<GLImageOzoneNativePixmapTestDelegate< |
+ gfx::BufferFormat::R_8, |
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>, |
+ GLImageOzoneNativePixmapTestDelegate< |
+ gfx::BufferFormat::BGRA_8888, |
+ 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
|
+ |
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
+ GLImageBindTest, |
+ GLImageBindTestTypes); |
} // namespace |
} // namespace gl |