Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
6#include "gtest/gtest.h"
7
11
12namespace impeller {
13namespace testing {
14
17
18template <typename T>
19std::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
26TEST_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
static DlPath MakeRect(const DlRect &rect)
Definition dl_path.cc:39
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)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
std::vector< T > CopyBufferView(const BufferView &vertex_buffer)
TEST_P(AiksTest, DrawAtlasNoColor)
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
Range GetRange() const
Definition buffer_view.h:27
const DeviceBuffer * GetBuffer() const
size_t length
Definition range.h:15
size_t offset
Definition range.h:14
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129