| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/buffer_types.h" | 10 #include "ui/gfx/buffer_types.h" |
| 11 #include "ui/gl/gl_image_native_pixmap.h" |
| 11 #include "ui/gl/test/gl_image_test_template.h" | 12 #include "ui/gl/test/gl_image_test_template.h" |
| 12 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h" | |
| 13 #include "ui/ozone/public/client_native_pixmap.h" | 13 #include "ui/ozone/public/client_native_pixmap.h" |
| 14 #include "ui/ozone/public/client_native_pixmap_factory.h" | 14 #include "ui/ozone/public/client_native_pixmap_factory.h" |
| 15 #include "ui/ozone/public/ozone_platform.h" | 15 #include "ui/ozone/public/ozone_platform.h" |
| 16 #include "ui/ozone/public/surface_factory_ozone.h" | 16 #include "ui/ozone/public/surface_factory_ozone.h" |
| 17 | 17 |
| 18 namespace gl { | 18 namespace gl { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const uint8_t kRed[] = {0xF0, 0x0, 0x0, 0xFF}; | 21 const uint8_t kRed[] = {0xF0, 0x0, 0x0, 0xFF}; |
| 22 const uint8_t kGreen[] = {0x0, 0xFF, 0x0, 0xFF}; | 22 const uint8_t kGreen[] = {0x0, 0xFF, 0x0, 0xFF}; |
| 23 | 23 |
| 24 // These values are picked so that RGB -> YVU on the CPU converted | 24 // These values are picked so that RGB -> YVU on the CPU converted |
| 25 // back to RGB on the GPU produces the original RGB values without | 25 // back to RGB on the GPU produces the original RGB values without |
| 26 // any error. | 26 // any error. |
| 27 const uint8_t kYvuColor[] = {0x10, 0x20, 0, 0xFF}; | 27 const uint8_t kYvuColor[] = {0x10, 0x20, 0, 0xFF}; |
| 28 | 28 |
| 29 template <gfx::BufferUsage usage, gfx::BufferFormat format> | 29 template <gfx::BufferUsage usage, gfx::BufferFormat format> |
| 30 class GLImageOzoneNativePixmapTestDelegate { | 30 class GLImageNativePixmapTestDelegate { |
| 31 public: | 31 public: |
| 32 GLImageOzoneNativePixmapTestDelegate() { | 32 GLImageNativePixmapTestDelegate() { |
| 33 client_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); | 33 client_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); |
| 34 } | 34 } |
| 35 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, | 35 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, |
| 36 const uint8_t color[4]) const { | 36 const uint8_t color[4]) const { |
| 37 ui::SurfaceFactoryOzone* surface_factory = | 37 ui::SurfaceFactoryOzone* surface_factory = |
| 38 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 38 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
| 39 scoped_refptr<ui::NativePixmap> pixmap = | 39 scoped_refptr<ui::NativePixmap> pixmap = |
| 40 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 40 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, |
| 41 format, usage); | 41 format, usage); |
| 42 DCHECK(pixmap); | 42 DCHECK(pixmap); |
| 43 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) { | 43 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) { |
| 44 auto client_pixmap = client_pixmap_factory_->ImportFromHandle( | 44 auto client_pixmap = client_pixmap_factory_->ImportFromHandle( |
| 45 pixmap->ExportHandle(), size, usage); | 45 pixmap->ExportHandle(), size, usage); |
| 46 bool mapped = client_pixmap->Map(); | 46 bool mapped = client_pixmap->Map(); |
| 47 EXPECT_TRUE(mapped); | 47 EXPECT_TRUE(mapped); |
| 48 | 48 |
| 49 for (size_t plane = 0; plane < NumberOfPlanesForBufferFormat(format); | 49 for (size_t plane = 0; plane < NumberOfPlanesForBufferFormat(format); |
| 50 ++plane) { | 50 ++plane) { |
| 51 void* data = client_pixmap->GetMemoryAddress(plane); | 51 void* data = client_pixmap->GetMemoryAddress(plane); |
| 52 GLImageTestSupport::SetBufferDataToColor( | 52 GLImageTestSupport::SetBufferDataToColor( |
| 53 size.width(), size.height(), pixmap->GetDmaBufPitch(plane), plane, | 53 size.width(), size.height(), pixmap->GetDmaBufPitch(plane), plane, |
| 54 pixmap->GetBufferFormat(), color, static_cast<uint8_t*>(data)); | 54 pixmap->GetBufferFormat(), color, static_cast<uint8_t*>(data)); |
| 55 } | 55 } |
| 56 client_pixmap->Unmap(); | 56 client_pixmap->Unmap(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 scoped_refptr<ui::GLImageOzoneNativePixmap> image( | 59 scoped_refptr<ui::GLImageNativePixmap> image(new ui::GLImageNativePixmap( |
| 60 new ui::GLImageOzoneNativePixmap( | 60 size, ui::GLImageNativePixmap::GetInternalFormatForTesting(format))); |
| 61 size, | |
| 62 ui::GLImageOzoneNativePixmap::GetInternalFormatForTesting(format))); | |
| 63 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | 61 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); |
| 64 return image; | 62 return image; |
| 65 } | 63 } |
| 66 | 64 |
| 67 unsigned GetTextureTarget() const { return GL_TEXTURE_EXTERNAL_OES; } | 65 unsigned GetTextureTarget() const { return GL_TEXTURE_EXTERNAL_OES; } |
| 68 | 66 |
| 69 const uint8_t* GetImageColor() { | 67 const uint8_t* GetImageColor() { |
| 70 if (format == gfx::BufferFormat::R_8) { | 68 if (format == gfx::BufferFormat::R_8) { |
| 71 return kRed; | 69 return kRed; |
| 72 } else if (format == gfx::BufferFormat::YVU_420) { | 70 } else if (format == gfx::BufferFormat::YVU_420) { |
| 73 return kYvuColor; | 71 return kYvuColor; |
| 74 } | 72 } |
| 75 return kGreen; | 73 return kGreen; |
| 76 } | 74 } |
| 77 | 75 |
| 78 private: | 76 private: |
| 79 std::unique_ptr<ui::ClientNativePixmapFactory> client_pixmap_factory_; | 77 std::unique_ptr<ui::ClientNativePixmapFactory> client_pixmap_factory_; |
| 80 }; | 78 }; |
| 81 | 79 |
| 82 using GLImageScanoutType = testing::Types< | 80 using GLImageScanoutType = testing::Types< |
| 83 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT, | 81 GLImageNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT, |
| 84 gfx::BufferFormat::BGRA_8888>>; | 82 gfx::BufferFormat::BGRA_8888>>; |
| 85 | 83 |
| 86 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmapScanout, | 84 INSTANTIATE_TYPED_TEST_CASE_P(GLImageNativePixmapScanout, |
| 87 GLImageTest, | 85 GLImageTest, |
| 88 GLImageScanoutType); | 86 GLImageScanoutType); |
| 89 | 87 |
| 90 using GLImageReadWriteType = | 88 using GLImageReadWriteType = testing::Types< |
| 91 testing::Types<GLImageOzoneNativePixmapTestDelegate< | 89 GLImageNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 92 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 90 gfx::BufferFormat::R_8>>; |
| 93 gfx::BufferFormat::R_8>>; | |
| 94 | 91 |
| 95 using GLImageBindTestTypes = | 92 using GLImageBindTestTypes = testing::Types< |
| 96 testing::Types<GLImageOzoneNativePixmapTestDelegate< | 93 GLImageNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 97 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 94 gfx::BufferFormat::BGRA_8888>, |
| 98 gfx::BufferFormat::BGRA_8888>, | 95 GLImageNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 99 GLImageOzoneNativePixmapTestDelegate< | 96 gfx::BufferFormat::R_8>, |
| 100 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 97 GLImageNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 101 gfx::BufferFormat::R_8>, | 98 gfx::BufferFormat::YVU_420>, |
| 102 GLImageOzoneNativePixmapTestDelegate< | 99 GLImageNativePixmapTestDelegate<gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 103 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 100 gfx::BufferFormat::YUV_420_BIPLANAR>>; |
| 104 gfx::BufferFormat::YVU_420>, | |
| 105 GLImageOzoneNativePixmapTestDelegate< | |
| 106 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
| 107 gfx::BufferFormat::YUV_420_BIPLANAR>>; | |
| 108 | 101 |
| 109 // These tests are disabled since the trybots are running with Ozone X11 | 102 // These tests are disabled since the trybots are running with Ozone X11 |
| 110 // implementation that doesn't support creating ClientNativePixmap. | 103 // implementation that doesn't support creating ClientNativePixmap. |
| 111 // TODO(dcastagna): Implement ClientNativePixmapFactory on Ozone X11. | 104 // TODO(dcastagna): Implement ClientNativePixmapFactory on Ozone X11. |
| 112 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapReadWrite, | 105 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageNativePixmapReadWrite, |
| 113 GLImageTest, | 106 GLImageTest, |
| 114 GLImageReadWriteType); | 107 GLImageReadWriteType); |
| 115 | 108 |
| 116 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmap, | 109 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageNativePixmap, |
| 117 GLImageBindTest, | 110 GLImageBindTest, |
| 118 GLImageBindTestTypes); | 111 GLImageBindTestTypes); |
| 119 | 112 |
| 120 } // namespace | 113 } // namespace |
| 121 } // namespace gl | 114 } // namespace gl |
| OLD | NEW |