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.h" | 11 #include "ui/ozone/public/client_native_pixmap.h" |
12 #include "ui/ozone/public/client_native_pixmap_factory.h" | 12 #include "ui/ozone/public/client_native_pixmap_factory.h" |
13 #include "ui/ozone/public/ozone_platform.h" | 13 #include "ui/ozone/public/ozone_platform.h" |
14 #include "ui/ozone/public/surface_factory_ozone.h" | 14 #include "ui/ozone/public/surface_factory_ozone.h" |
15 | 15 |
16 namespace gl { | 16 namespace gl { |
17 namespace { | 17 namespace { |
18 | 18 |
19 template <gfx::BufferUsage usage> | 19 template <gfx::BufferUsage usage> |
20 class GLImageOzoneNativePixmapTestDelegate { | 20 class GLImageOzoneNativePixmapTestDelegate { |
21 public: | 21 public: |
22 GLImageOzoneNativePixmapTestDelegate() { | 22 GLImageOzoneNativePixmapTestDelegate() { |
23 client_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); | 23 client_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); |
24 } | 24 } |
25 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 25 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, |
26 const gfx::Size& size, | 26 const uint8_t color[4]) const { |
27 const uint8_t color[4]) const { | |
28 ui::SurfaceFactoryOzone* surface_factory = | 27 ui::SurfaceFactoryOzone* surface_factory = |
29 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 28 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
30 scoped_refptr<ui::NativePixmap> pixmap = | 29 scoped_refptr<ui::NativePixmap> pixmap = |
31 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 30 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, |
32 gfx::BufferFormat::BGRA_8888, | 31 gfx::BufferFormat::BGRA_8888, |
33 usage); | 32 usage); |
34 DCHECK(pixmap); | 33 DCHECK(pixmap); |
35 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) { | 34 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) { |
36 auto client_pixmap = client_pixmap_factory_->ImportFromHandle( | 35 auto client_pixmap = client_pixmap_factory_->ImportFromHandle( |
37 pixmap->ExportHandle(), size, usage); | 36 pixmap->ExportHandle(), size, usage); |
38 void* data = client_pixmap->Map(); | 37 void* data = client_pixmap->Map(); |
39 EXPECT_TRUE(data); | 38 EXPECT_TRUE(data); |
40 GLImageTestSupport::SetBufferDataToColor( | 39 GLImageTestSupport::SetBufferDataToColor( |
41 size.width(), size.height(), pixmap->GetDmaBufPitch(0), 0, | 40 size.width(), size.height(), pixmap->GetDmaBufPitch(0), 0, |
42 pixmap->GetBufferFormat(), color, static_cast<uint8_t*>(data)); | 41 pixmap->GetBufferFormat(), color, static_cast<uint8_t*>(data)); |
43 client_pixmap->Unmap(); | 42 client_pixmap->Unmap(); |
44 } | 43 } |
45 | 44 |
46 scoped_refptr<gl::GLImageOzoneNativePixmap> image( | 45 scoped_refptr<GLImageOzoneNativePixmap> image( |
47 new gl::GLImageOzoneNativePixmap(size, GL_RGBA)); | 46 new GLImageOzoneNativePixmap(size, GL_RGBA)); |
48 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | 47 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
49 return image; | 48 return image; |
50 } | 49 } |
51 | 50 |
52 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } | 51 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } |
53 | 52 |
54 private: | 53 private: |
55 std::unique_ptr<ui::ClientNativePixmapFactory> client_pixmap_factory_; | 54 std::unique_ptr<ui::ClientNativePixmapFactory> client_pixmap_factory_; |
56 }; | 55 }; |
57 | 56 |
58 INSTANTIATE_TYPED_TEST_CASE_P( | 57 INSTANTIATE_TYPED_TEST_CASE_P( |
59 GLImageOzoneNativePixmap, | 58 GLImageOzoneNativePixmap, |
60 GLImageTest, | 59 GLImageTest, |
61 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT>); | 60 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT>); |
62 | 61 |
63 // This test is disabled since the trybots are running with Ozone X11 | 62 // This test is disabled since the trybots are running with Ozone X11 |
64 // implementation that doesn't support creating ClientNativePixmap. | 63 // implementation that doesn't support creating ClientNativePixmap. |
65 // TODO(dcastagna): Implement ClientNativePixmapFactory on Ozone X11. | 64 // TODO(dcastagna): Implement ClientNativePixmapFactory on Ozone X11. |
66 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmap, | 65 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmap, |
67 GLImageBindTest, | 66 GLImageBindTest, |
68 GLImageOzoneNativePixmapTestDelegate< | 67 GLImageOzoneNativePixmapTestDelegate< |
69 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>); | 68 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE>); |
70 | 69 |
71 } // namespace | 70 } // namespace |
72 } // namespace gl | 71 } // namespace gl |
OLD | NEW |