Chromium Code Reviews| 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..147f651132ad9787d176bd760cf056b00b27cb59 100644 |
| --- a/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
| +++ b/ui/gl/gl_image_ozone_native_pixmap_unittest.cc |
| @@ -5,35 +5,82 @@ |
| #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 { |
| +template <gfx::BufferUsage usage> |
| class GLImageOzoneNativePixmapTestDelegate { |
| public: |
| scoped_refptr<gl::GLImage> CreateSolidColorImage( |
| const gfx::Size& size, |
| + gfx::BufferFormat format, |
| 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()); |
| + |
| + if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE || |
| + usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT) { |
| + 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, 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)); |
| - EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
| + new gfx::GLImageOzoneNativePixmap(size, |
| + gl::GetTextureFormatFrom(format))); |
| + EXPECT_TRUE(image->Initialize(pixmap.get(), format)); |
| return image; |
| } |
| + |
| + static bool IsSupported(gfx::BufferFormat format) { |
| + return ui::ClientNativePixmapFactory::GetInstance() |
| + ->IsConfigurationSupported(format, usage); |
|
dshwang
2015/12/15 13:44:38
It's because ozone knows supported configuration i
|
| + } |
| }; |
| +using GLImageTestTypesForGLImageTest = testing::Types< |
| + GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ>, |
| + GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT>, |
| + GLImageOzoneNativePixmapTestDelegate< |
| + gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, |
| + GLImageOzoneNativePixmapTestDelegate< |
| + gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; |
| + |
| INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
| GLImageTest, |
| - GLImageOzoneNativePixmapTestDelegate); |
| + GLImageTestTypesForGLImageTest); |
| + |
| +using GLImageTestTypesForGLImageBindTest = |
| + testing::Types<GLImageOzoneNativePixmapTestDelegate< |
| + gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, |
| + GLImageOzoneNativePixmapTestDelegate< |
| + gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; |
| + |
| +INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
| + GLImageBindTest, |
| + GLImageTestTypesForGLImageBindTest); |
| } // namespace |
| } // namespace gl |