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