Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
device_buffer_gles_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" // IWYU pragma: keep
6#include "gtest/gtest.h"
9
10namespace impeller {
11namespace testing {
12
13using ::testing::_;
14
15namespace {
16class TestWorker : public ReactorGLES::Worker {
17 public:
19 const ReactorGLES& reactor) const override {
20 return true;
21 }
22};
23} // namespace
24
25// A Flush() that lands while BindAndUploadDataIfNecessary is mid-upload (as
26// happens when another thread writes to a host-visible buffer during the GL
27// upload) must not be discarded; the next bind must upload the new range.
28TEST(DeviceBufferGLESTest, FlushDuringUploadIsNotDiscarded) {
29 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
30
31 DeviceBufferGLES* device_buffer_ptr = nullptr;
32 int upload_count = 0;
33 EXPECT_CALL(*mock_gles_impl, BufferSubData(_, _, _, _))
34 .Times(2)
35 .WillRepeatedly([&](GLenum target, GLintptr offset, GLsizeiptr size,
36 const void* data) {
37 ++upload_count;
38 if (upload_count == 1) {
39 // Simulates a writer thread flushing new data during the upload.
40 device_buffer_ptr->Flush(Range{0, 4});
41 }
42 });
43
44 std::shared_ptr<MockGLES> mock_gles =
45 MockGLES::Init(std::move(mock_gles_impl));
47 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
48 auto worker = std::make_shared<TestWorker>();
49 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
50 reactor->AddWorker(worker);
51
52 auto backing_store = std::make_unique<Allocation>();
53 ASSERT_TRUE(backing_store->Truncate(Bytes{16}));
55 std::move(backing_store));
56 device_buffer_ptr = &device_buffer;
57
58 device_buffer.Flush(Range{0, 4});
59 // First bind uploads the flushed range; the mock flushes again mid-upload.
60 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
62 // Second bind must see the mid-upload flush and upload again.
63 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
65 EXPECT_EQ(upload_count, 2);
66}
67
68TEST(DeviceBufferGLESTest, BindUniformData) {
69 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
70
71 EXPECT_CALL(*mock_gles_impl, GenBuffers(1, _)).Times(1);
72
73 std::shared_ptr<MockGLES> mock_gled =
74 MockGLES::Init(std::move(mock_gles_impl));
76 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
77 auto worker = std::make_shared<TestWorker>();
78 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
79 reactor->AddWorker(worker);
80
81 auto backing_store = std::make_unique<Allocation>();
82 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
83 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
84 reactor, std::move(backing_store));
85 EXPECT_FALSE(device_buffer.GetHandle().has_value());
86 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
88 EXPECT_TRUE(device_buffer.GetHandle().has_value());
89}
90
91} // namespace testing
92} // namespace impeller
void Flush(std::optional< Range > range=std::nullopt) const override
std::function< void *(const char *function_name)> Resolver
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0")
Definition mock_gles.cc:417
bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const override
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
uint32_t * target
TEST(FrameTimingsRecorderTest, RecordVsync)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
const ProcTableGLES::Resolver kMockResolverGLES
Definition mock_gles.cc:459
std::shared_ptr< ReactorGLES > reactor