OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdint.h> | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "ui/gfx/buffer_types.h" | |
9 #include "ui/gl/test/gl_image_test_template.h" | |
10 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h" | |
11 #include "ui/ozone/public/client_native_pixmap.h" | |
12 #include "ui/ozone/public/client_native_pixmap_factory.h" | |
13 #include "ui/ozone/public/ozone_platform.h" | |
14 #include "ui/ozone/public/surface_factory_ozone.h" | |
15 | |
16 namespace gl { | |
17 namespace { | |
18 | |
19 const uint8_t kRed[] = {0xF0, 0x0, 0x0, 0xFF}; | |
20 const uint8_t kGreen[] = {0x0, 0xFF, 0x0, 0xFF}; | |
21 | |
22 template <gfx::BufferUsage usage, gfx::BufferFormat format> | |
23 class GLImageOzoneNativePixmapTestDelegate { | |
24 public: | |
25 GLImageOzoneNativePixmapTestDelegate() { | |
26 client_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); | |
27 } | |
28 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, | |
29 const uint8_t color[4]) const { | |
30 ui::SurfaceFactoryOzone* surface_factory = | |
31 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | |
32 scoped_refptr<ui::NativePixmap> pixmap = | |
33 surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | |
34 format, usage); | |
35 DCHECK(pixmap); | |
36 if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) { | |
37 auto client_pixmap = client_pixmap_factory_->ImportFromHandle( | |
38 pixmap->ExportHandle(), size, usage); | |
39 void* data = client_pixmap->Map(); | |
40 EXPECT_TRUE(data); | |
41 GLImageTestSupport::SetBufferDataToColor( | |
42 size.width(), size.height(), pixmap->GetDmaBufPitch(0), 0, | |
43 pixmap->GetBufferFormat(), color, static_cast<uint8_t*>(data)); | |
44 client_pixmap->Unmap(); | |
45 } | |
46 | |
47 scoped_refptr<ui::GLImageOzoneNativePixmap> image( | |
48 new ui::GLImageOzoneNativePixmap( | |
49 size, | |
50 ui::GLImageOzoneNativePixmap::GetInternalFormatForTesting(format))); | |
51 EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat())); | |
52 return image; | |
53 } | |
54 | |
55 unsigned GetTextureTarget() const { return GL_TEXTURE_EXTERNAL_OES; } | |
56 | |
57 const uint8_t* GetImageColor() { | |
58 return format == gfx::BufferFormat::R_8 ? kRed : kGreen; | |
59 } | |
60 | |
61 private: | |
62 std::unique_ptr<ui::ClientNativePixmapFactory> client_pixmap_factory_; | |
63 }; | |
64 | |
65 using GLImageScanoutType = testing::Types< | |
66 GLImageOzoneNativePixmapTestDelegate<gfx::BufferUsage::SCANOUT, | |
67 gfx::BufferFormat::BGRA_8888>>; | |
68 | |
69 INSTANTIATE_TYPED_TEST_CASE_P(GLImageOzoneNativePixmapScanout, | |
70 GLImageTest, | |
71 GLImageScanoutType); | |
72 | |
73 using GLImageReadWriteType = | |
74 testing::Types<GLImageOzoneNativePixmapTestDelegate< | |
75 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
76 gfx::BufferFormat::R_8>>; | |
77 | |
78 using GLImageBindTestTypes = | |
79 testing::Types<GLImageOzoneNativePixmapTestDelegate< | |
80 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
81 gfx::BufferFormat::BGRA_8888>, | |
82 GLImageOzoneNativePixmapTestDelegate< | |
83 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
84 gfx::BufferFormat::R_8>>; | |
85 | |
86 // These tests are disabled since the trybots are running with Ozone X11 | |
87 // implementation that doesn't support creating ClientNativePixmap. | |
88 // TODO(dcastagna): Implement ClientNativePixmapFactory on Ozone X11. | |
89 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapReadWrite, | |
90 GLImageTest, | |
91 GLImageReadWriteType); | |
92 | |
93 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmap, | |
94 GLImageBindTest, | |
95 GLImageBindTestTypes); | |
96 | |
97 } // namespace | |
98 } // namespace gl | |
OLD | NEW |