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