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 a21a444a823d361d9481de12291b556726a27845..71cf5343d767393844424340bf72a74753884b29 100644 |
--- a/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
+++ b/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
@@ -5,35 +5,100 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
#include "ui/gfx/buffer_types.h" |
#include "ui/gl/gl_image_ozone_native_pixmap.h" |
+#include "ui/gl/gl_utils.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 { |
-class GLImageOzoneNativePixmapTestDelegate { |
reveman
2015/11/30 21:03:43
Note: this previous test is only useful for chrome
|
+template <gfx::BufferFormat format, gfx::BufferUsage usage> |
+class GLImageOzoneNativePixmapTestDelegateForScanout { |
public: |
scoped_refptr<gl::GLImage> CreateSolidColorImage( |
const gfx::Size& size, |
const uint8_t color[4]) const { |
+ DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); |
ui::SurfaceFactoryOzone* surface_factory = |
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); |
+ EXPECT_EQ(format, pixmap->GetBufferFormat()); |
scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
- new gfx::GLImageOzoneNativePixmap(size, GL_RGBA)); |
- EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
+ new gfx::GLImageOzoneNativePixmap(size, |
+ gl::GetTextureFormatFrom(format))); |
+ EXPECT_TRUE(image->Initialize(pixmap.get(), format)); |
return image; |
} |
}; |
-INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
+using GLImageTestTypesForScanout = testing::Types< |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::RGBA_8888, |
+ gfx::BufferUsage::GPU_READ>, |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::BGRX_8888, |
+ gfx::BufferUsage::GPU_READ>, |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::BGRA_8888, |
+ gfx::BufferUsage::GPU_READ>, |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::RGBA_8888, |
+ gfx::BufferUsage::SCANOUT>, |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::BGRX_8888, |
+ gfx::BufferUsage::SCANOUT>, |
+ GLImageOzoneNativePixmapTestDelegateForScanout<gfx::BufferFormat::BGRA_8888, |
+ gfx::BufferUsage::SCANOUT>>; |
+ |
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmapForScanout, |
+ GLImageTest, |
+ GLImageTestTypesForScanout); |
+ |
+template <gfx::BufferFormat format, gfx::BufferUsage usage> |
+class GLImageOzoneNativePixmapTestDelegateForCPUReadWrite { |
+ public: |
+ scoped_refptr<gl::GLImage> CreateSolidColorImage( |
+ const gfx::Size& size, |
+ const uint8_t color[4]) const { |
+ DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); |
+ 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); |
+ EXPECT_EQ(format, pixmap->GetBufferFormat()); |
+ |
+ gfx::NativePixmapHandle handle = pixmap->ExportHandle(); |
+ scoped_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, format, color, |
+ reinterpret_cast<uint8_t*>(native_pixmap->Map())); |
+ native_pixmap->Unmap(); |
+ |
+ scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
+ new gfx::GLImageOzoneNativePixmap(size, |
+ gl::GetTextureFormatFrom(format))); |
+ EXPECT_TRUE(image->Initialize(pixmap.get(), format)); |
+ return image; |
+ } |
+}; |
+ |
+using GLImageTestTypesForCPUReadWrite = |
+ testing::Types<GLImageOzoneNativePixmapTestDelegateForCPUReadWrite< |
+ gfx::BufferFormat::BGRA_8888, |
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, |
+ GLImageOzoneNativePixmapTestDelegateForCPUReadWrite< |
+ gfx::BufferFormat::BGRA_8888, |
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; |
+ |
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmapForCPUReadWrite, |
GLImageTest, |
- GLImageOzoneNativePixmapTestDelegate); |
+ GLImageTestTypesForCPUReadWrite); |
} // namespace |
} // namespace gl |