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