Flutter Impeller
tessellator_playground_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/testing/testing.h"
6 #include "gtest/gtest.h"
7 
8 #include "flutter/display_list/geometry/dl_path_builder.h"
11 
12 namespace impeller {
13 namespace testing {
14 
17 
18 template <typename T>
19 std::vector<T> CopyBufferView(const BufferView& vertex_buffer) {
20  Range range = vertex_buffer.GetRange();
21  uint8_t* base_ptr = vertex_buffer.GetBuffer()->OnGetContents() + range.offset;
22  return std::vector<T>(reinterpret_cast<T*>(base_ptr),
23  reinterpret_cast<T*>(base_ptr + range.length));
24 }
25 
26 TEST_P(TessellatorPlaygroundTest, TessellateConvex16or32Bit) {
27  auto tessellator16 = std::make_shared<Tessellator>(false);
28  auto tessellator32 = std::make_shared<Tessellator>(true);
29 
30  auto data_host_buffer = HostBuffer::Create(
31  GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
32  GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
33  auto indexes_host_buffer = HostBuffer::Create(
34  GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
35  GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
36 
37  auto path = flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
38 
39  auto vertex_buffer16 = tessellator16->TessellateConvex(
40  path, *data_host_buffer, *indexes_host_buffer, 1.0, false, false);
41  auto vertex_buffer32 = tessellator32->TessellateConvex(
42  path, *data_host_buffer, *indexes_host_buffer, 1.0, false, false);
43 
44  const std::vector<Point> expected = {
45  {0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}};
46  const std::vector<uint16_t> expected_indices = {0, 1, 3, 2};
47 
48  EXPECT_EQ(vertex_buffer16.index_type, IndexType::k16bit);
49  EXPECT_EQ(expected, CopyBufferView<Point>(vertex_buffer16.vertex_buffer));
50  EXPECT_EQ(expected_indices,
51  CopyBufferView<uint16_t>(vertex_buffer16.index_buffer));
52 
53  EXPECT_EQ(vertex_buffer32.index_type, IndexType::k32bit);
54  EXPECT_EQ(expected, CopyBufferView<Point>(vertex_buffer32.vertex_buffer));
55  EXPECT_EQ(
56  std::vector<uint32_t>(expected_indices.begin(), expected_indices.end()),
57  CopyBufferView<uint32_t>(vertex_buffer32.index_buffer));
58 }
59 
60 } // namespace testing
61 } // namespace impeller
virtual uint8_t * OnGetContents() const =0
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
Definition: host_buffer.cc:21
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
std::vector< T > CopyBufferView(const BufferView &vertex_buffer)
Range GetRange() const
Definition: buffer_view.h:27
const DeviceBuffer * GetBuffer() const
Definition: buffer_view.cc:17
size_t length
Definition: range.h:15
size_t offset
Definition: range.h:14
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129