| 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 |
| 17 template <gfx::BufferUsage usage> | 18 template <gfx::BufferUsage usage> |
| 18 class GLImageOzoneNativePixmapTestDelegate { | 19 class GLImageOzoneNativePixmapTestDelegate { |
| 19 public: | 20 public: |
| 20 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 21 scoped_refptr<gl::GLImage> CreateSolidColorImage( |
| 21 const gfx::Size& size, | 22 const gfx::Size& size, |
| 22 gfx::BufferFormat format, | 23 gfx::BufferFormat format, |
| 23 const uint8_t color[4]) const { | 24 const uint8_t color[4]) const { |
| 24 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); | 25 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); |
| 25 ui::SurfaceFactoryOzone* surface_factory = | 26 ui::SurfaceFactoryOzone* surface_factory = |
| 26 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 27 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
| 27 scoped_refptr<ui::NativePixmap> pixmap = | 28 scoped_refptr<ui::NativePixmap> pixmap = |
| 28 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 29 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, |
| 29 format, usage); | 30 format, usage); |
| 30 EXPECT_TRUE(pixmap != nullptr); | 31 EXPECT_TRUE(pixmap != nullptr); |
| 31 EXPECT_EQ(format, pixmap->GetBufferFormat()); | 32 EXPECT_EQ(format, pixmap->GetBufferFormat()); |
| 32 | 33 |
| 34 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE || |
| 35 usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT) { |
| 36 gfx::NativePixmapHandle handle = pixmap->ExportHandle(); |
| 37 scoped_ptr<ui::ClientNativePixmap> native_pixmap = |
| 38 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
| 39 handle, size, usage); |
| 40 EXPECT_TRUE(native_pixmap != nullptr); |
| 41 |
| 42 GLImageTestSupport::SetBufferDataToColor( |
| 43 size.width(), size.height(), handle.stride, 0, format, color, |
| 44 reinterpret_cast<uint8_t*>(native_pixmap->Map())); |
| 45 native_pixmap->Unmap(); |
| 46 } else { |
| 47 // Cannot paint |color| on GPU_READ and SCANOUT buffer, but GLImageTest |
| 48 // doesn't check actual color, so it's fine so far. |
| 49 } |
| 50 |
| 33 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | 51 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
| 34 new gfx::GLImageOzoneNativePixmap( | 52 new gfx::GLImageOzoneNativePixmap( |
| 35 size, gl::GLImage::GetTextureFormatFrom(format))); | 53 size, gl::GLImage::GetTextureFormatFrom(format))); |
| 36 EXPECT_TRUE(image->Initialize(pixmap.get(), format)); | 54 EXPECT_TRUE(image->Initialize(pixmap.get(), format)); |
| 37 return image; | 55 return image; |
| 38 } | 56 } |
| 39 | 57 |
| 40 static bool IsSupported(gfx::BufferFormat format) { | 58 static bool IsSupported(gfx::BufferFormat format) { |
| 41 switch (format) { | 59 return ui::ClientNativePixmapFactory::GetInstance() |
| 42 case gfx::BufferFormat::RGBA_8888: | 60 ->IsConfigurationSupported(format, usage); |
| 43 return true; | |
| 44 default: | |
| 45 return false; | |
| 46 } | |
| 47 } | 61 } |
| 48 }; | 62 }; |
| 49 | 63 |
| 50 using GLImageTestTypesForGLImageTest = testing::Types< | 64 using GLImageTestTypesForGLImageTest = testing::Types< |
| 51 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ>, | 65 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ>, |
| 52 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT>, | 66 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT>, |
| 53 GLImageOzoneNativePixmapTestDelegate< | 67 GLImageOzoneNativePixmapTestDelegate< |
| 54 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, | 68 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, |
| 55 GLImageOzoneNativePixmapTestDelegate< | 69 GLImageOzoneNativePixmapTestDelegate< |
| 56 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; | 70 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; |
| 57 | 71 |
| 58 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, | 72 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
| 59 GLImageTest, | 73 GLImageTest, |
| 60 GLImageTestTypesForGLImageTest); | 74 GLImageTestTypesForGLImageTest); |
| 61 | 75 |
| 76 using GLImageTestTypesForGLImageBindTest = |
| 77 testing::Types<GLImageOzoneNativePixmapTestDelegate< |
| 78 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>, |
| 79 GLImageOzoneNativePixmapTestDelegate< |
| 80 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT>>; |
| 81 |
| 82 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmap, |
| 83 GLImageBindTest, |
| 84 GLImageTestTypesForGLImageBindTest); |
| 85 |
| 62 } // namespace | 86 } // namespace |
| 63 } // namespace gl | 87 } // namespace gl |
| OLD | NEW |