OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <libdrm/i915_drm.h> | 6 #include <libdrm/i915_drm.h> |
7 #include <linux/types.h> | 7 #include <linux/types.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 base::ScopedFD drm_fd( | 43 base::ScopedFD drm_fd( |
44 HANDLE_EINTR(open("/dev/dri/card0", O_RDWR | O_CLOEXEC))); | 44 HANDLE_EINTR(open("/dev/dri/card0", O_RDWR | O_CLOEXEC))); |
45 DCHECK(drm_fd.is_valid()) << "Couldn't open '/dev/dri/card0'"; | 45 DCHECK(drm_fd.is_valid()) << "Couldn't open '/dev/dri/card0'"; |
46 | 46 |
47 std::vector<int> pitches{RoundTo64(size.width()), RoundTo64(size.width() / 2), | 47 std::vector<int> pitches{RoundTo64(size.width()), RoundTo64(size.width() / 2), |
48 RoundTo64(size.width() / 2)}; | 48 RoundTo64(size.width() / 2)}; |
49 std::vector<int> offsets{ | 49 std::vector<int> offsets{ |
50 0, pitches[0] * size.height() + pitches[1] * size.height() / 2, | 50 0, pitches[0] * size.height() + pitches[1] * size.height() / 2, |
51 pitches[0] * size.height(), | 51 pitches[0] * size.height(), |
52 }; | 52 }; |
53 std::vector<size_t> sizes{pitches[0] * size.height(), | |
54 pitches[1] * size.height() / 2, | |
55 pitches[2] * size.height() / 2}; | |
56 | |
57 size_t byte_number = pitches[0] * size.height() + | 53 size_t byte_number = pitches[0] * size.height() + |
58 pitches[1] * size.height() / 2 + | 54 pitches[1] * size.height() / 2 + |
59 pitches[2] * size.height() / 2; | 55 pitches[2] * size.height() / 2; |
60 | 56 |
61 struct drm_i915_gem_create gem_create {}; | 57 struct drm_i915_gem_create gem_create {}; |
62 gem_create.size = byte_number; | 58 gem_create.size = byte_number; |
63 int ret = drmIoctl(drm_fd.get(), DRM_IOCTL_I915_GEM_CREATE, &gem_create); | 59 int ret = drmIoctl(drm_fd.get(), DRM_IOCTL_I915_GEM_CREATE, &gem_create); |
64 DCHECK(!ret) << "Can't create the GEM buffer."; | 60 DCHECK(!ret) << "Can't create the GEM buffer."; |
65 struct drm_i915_gem_set_tiling gem_set_tiling {}; | 61 struct drm_i915_gem_set_tiling gem_set_tiling {}; |
66 do { | 62 do { |
(...skipping 19 matching lines...) Expand all Loading... |
86 struct drm_i915_gem_pwrite gem_pwrite {}; | 82 struct drm_i915_gem_pwrite gem_pwrite {}; |
87 gem_pwrite.handle = gem_create.handle; | 83 gem_pwrite.handle = gem_create.handle; |
88 gem_pwrite.size = byte_number; | 84 gem_pwrite.size = byte_number; |
89 gem_pwrite.data_ptr = reinterpret_cast<uint64_t>(&data[0]); | 85 gem_pwrite.data_ptr = reinterpret_cast<uint64_t>(&data[0]); |
90 ret = drmIoctl(drm_fd.get(), DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite); | 86 ret = drmIoctl(drm_fd.get(), DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite); |
91 DCHECK(!ret) << "Problems with drmIoctl when writing data."; | 87 DCHECK(!ret) << "Problems with drmIoctl when writing data."; |
92 | 88 |
93 gfx::NativePixmapHandle pixmap_handle; | 89 gfx::NativePixmapHandle pixmap_handle; |
94 pixmap_handle.fds.emplace_back(fd, false); | 90 pixmap_handle.fds.emplace_back(fd, false); |
95 for (int i = 0; i < 3; i++) { | 91 for (int i = 0; i < 3; i++) { |
96 pixmap_handle.planes.emplace_back(pitches[i], offsets[i], sizes[i], 0); | 92 pixmap_handle.planes.emplace_back(pitches[i], offsets[i], 0); |
97 } | 93 } |
98 ui::SurfaceFactoryOzone* surface_factory = | 94 ui::SurfaceFactoryOzone* surface_factory = |
99 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); | 95 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
100 return surface_factory->CreateNativePixmapFromHandle( | 96 return surface_factory->CreateNativePixmapFromHandle( |
101 gfx::kNullAcceleratedWidget, size, gfx::BufferFormat::YVU_420, | 97 gfx::kNullAcceleratedWidget, size, gfx::BufferFormat::YVU_420, |
102 pixmap_handle); | 98 pixmap_handle); |
103 } | 99 } |
104 | 100 |
105 // Delegate to test EGL images created directly using drm. | 101 // Delegate to test EGL images created directly using drm. |
106 // YVU420 buffers can't be created yet via Ozone, we still | 102 // YVU420 buffers can't be created yet via Ozone, we still |
(...skipping 27 matching lines...) Expand all Loading... |
134 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapDrm, | 130 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapDrm, |
135 GLImageTest, | 131 GLImageTest, |
136 GLImageOzoneNativePixmapDrmTestDelegate); | 132 GLImageOzoneNativePixmapDrmTestDelegate); |
137 | 133 |
138 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapDrm, | 134 INSTANTIATE_TYPED_TEST_CASE_P(DISABLED_GLImageOzoneNativePixmapDrm, |
139 GLImageBindTest, | 135 GLImageBindTest, |
140 GLImageOzoneNativePixmapDrmTestDelegate); | 136 GLImageOzoneNativePixmapDrmTestDelegate); |
141 | 137 |
142 } // namespace | 138 } // namespace |
143 } // namespace gl | 139 } // namespace gl |
OLD | NEW |