File: shared_memory_region_wrapper_unittest.cc

package info (click to toggle)
chromium 144.0.7559.109-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,915,868 kB
  • sloc: cpp: 35,866,215; ansic: 7,599,035; javascript: 3,623,761; python: 1,639,407; xml: 833,084; asm: 716,173; pascal: 185,323; sh: 88,763; perl: 88,699; objc: 79,984; sql: 58,217; cs: 42,430; fortran: 24,101; makefile: 20,747; tcl: 15,277; php: 14,022; yacc: 9,059; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,192 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/shared_memory_region_wrapper.h"

#include "components/viz/common/resources/shared_image_format_utils.h"
#include "gpu/command_buffer/service/shared_image/shared_memory_image_backing_factory.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gpu {
namespace {

gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferHandle(
    const gfx::Size& size,
    viz::SharedImageFormat format) {
  return SharedMemoryImageBackingFactory::CreateGpuMemoryBufferHandle(size,
                                                                      format);
}

TEST(SharedMemoryRegionWrapperTest, SinglePlaneRGBA_8888) {
  constexpr gfx::Size size(100, 100);
  constexpr viz::SharedImageFormat format = viz::SinglePlaneFormat::kRGBA_8888;

  auto handle = CreateGpuMemoryBufferHandle(size, format);

  SharedMemoryRegionWrapper wrapper;
  EXPECT_TRUE(wrapper.Initialize(std::move(handle), size, format));
}

TEST(SharedMemoryRegionWrapperTest, MultiPlaneY_UV_420) {
  constexpr gfx::Size size(100, 100);
  constexpr viz::SharedImageFormat format = viz::MultiPlaneFormat::kNV12;

  auto handle = CreateGpuMemoryBufferHandle(size, format);

  SharedMemoryRegionWrapper wrapper;
  EXPECT_TRUE(wrapper.Initialize(std::move(handle), size, format));

  uint8_t* memory_y_plane = wrapper.GetMemory(0);
  uint8_t* memory_uv_plane = wrapper.GetMemory(1);

  // UV plane should be 100*100*1 bytes after Y plane.
  size_t offset = memory_uv_plane - memory_y_plane;
  EXPECT_EQ(offset, 10000u);
}

TEST(SharedMemoryRegionWrapperTest, MultiPlaneY_V_U_420) {
  constexpr gfx::Size size(100, 100);
  constexpr viz::SharedImageFormat format = viz::MultiPlaneFormat::kYV12;

  auto handle = CreateGpuMemoryBufferHandle(size, format);

  SharedMemoryRegionWrapper wrapper;
  EXPECT_TRUE(wrapper.Initialize(std::move(handle), size, format));

  uint8_t* memory_y_plane = wrapper.GetMemory(0);
  uint8_t* memory_v_plane = wrapper.GetMemory(1);
  uint8_t* memory_u_plane = wrapper.GetMemory(2);

  // V plane should be 100*100*1 bytes after Y plane.
  size_t v_offset = memory_v_plane - memory_y_plane;
  EXPECT_EQ(v_offset, 10000u);

  // U plane should be 50*50*1 bytes after V plane.
  size_t u_offset = memory_u_plane - memory_v_plane;
  EXPECT_EQ(u_offset, 2500u);
}

TEST(SharedMemoryRegionWrapperTest, BufferTooSmallWrongFormat) {
  constexpr gfx::Size size(100, 100);
  constexpr viz::SharedImageFormat format = viz::MultiPlaneFormat::kNV12;

  auto handle = CreateGpuMemoryBufferHandle(size, viz::SinglePlaneFormat::kR_8);

  SharedMemoryRegionWrapper wrapper;
  EXPECT_FALSE(wrapper.Initialize(std::move(handle), size, format));
}

TEST(SharedMemoryRegionWrapperTest, BufferTooSmallWrongSize) {
  constexpr gfx::Size size(100, 100);
  constexpr viz::SharedImageFormat format = viz::MultiPlaneFormat::kNV12;

  auto handle = CreateGpuMemoryBufferHandle(size, format);

  SharedMemoryRegionWrapper wrapper;
  EXPECT_FALSE(
      wrapper.Initialize(std::move(handle), gfx::Size(200, 200), format));
}

}  // namespace
}  // namespace gpu