Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
texture_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
9#include "gtest/gtest.h"
16
17namespace impeller::testing {
18
21
22TEST_P(TextureGLESTest, CanSetSyncFence) {
23 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
24 if (!context_gles.GetReactor()
25 ->GetProcTable()
26 .GetDescription()
27 ->GetGlVersion()
28 .IsAtLeast(Version{3, 0, 0})) {
29 GTEST_SKIP() << "GL Version too low to test sync fence.";
30 }
31
34 desc.size = {100, 100};
36
37 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
38 ASSERT_TRUE(!!texture);
39
40 EXPECT_TRUE(GetContext()->AddTrackingFence(texture));
41 EXPECT_TRUE(context_gles.GetReactor()->React());
42
43 std::optional<HandleGLES> sync_fence =
45 ASSERT_TRUE(sync_fence.has_value());
46 if (!sync_fence.has_value()) {
47 return;
48 }
49 EXPECT_EQ(sync_fence.value().GetType(), HandleType::kFence);
50
51 std::optional<GLsync> sync =
52 context_gles.GetReactor()->GetGLFence(sync_fence.value());
53 ASSERT_TRUE(sync.has_value());
54 if (!sync.has_value()) {
55 return;
56 }
57
58 // Now queue up operation that binds texture to verify that sync fence is
59 // waited and removed.
60
61 EXPECT_TRUE(
62 context_gles.GetReactor()->AddOperation([&](const ReactorGLES& reactor) {
63 return TextureGLES::Cast(*texture).Bind();
64 }));
65
66 sync_fence = TextureGLES::Cast(*texture).GetSyncFence();
67 ASSERT_FALSE(sync_fence.has_value());
68}
69
70TEST_P(TextureGLESTest, TextureDtorDeletesFence) {
71 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
72 if (!context_gles.GetReactor()
73 ->GetProcTable()
74 .GetDescription()
75 ->GetGlVersion()
76 .IsAtLeast(Version{3, 0, 0})) {
77 GTEST_SKIP() << "GL Version too low to test sync fence.";
78 }
79
82 desc.size = {100, 100};
84
85 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
86 ASSERT_TRUE(!!texture);
87
88 HandleGLES fence =
89 context_gles.GetReactor()->CreateHandle(HandleType::kFence);
90 bool fence_collected = false;
91 context_gles.GetReactor()->RegisterCleanupCallback(
92 fence, [&]() { fence_collected = true; });
93 TextureGLES::Cast(*texture).SetFence(fence);
94
95 texture.reset();
96 ASSERT_TRUE(context_gles.GetReactor()->AddOperation(
97 [](const ReactorGLES& reactor) {}));
98 ASSERT_TRUE(context_gles.GetReactor()->React());
99 EXPECT_TRUE(fence_collected);
100}
101
102TEST_P(TextureGLESTest, Binds2DTexture) {
105 desc.size = {100, 100};
109
110 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
111
112 ASSERT_TRUE(texture);
113
114 if (GetContext()->GetCapabilities()->SupportsImplicitResolvingMSAA()) {
115 EXPECT_EQ(
116 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
118 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
120 } else {
121 EXPECT_EQ(
122 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
124 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
126 }
127}
128
132 desc.size = {100, 100};
136
137 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
138
139 ASSERT_TRUE(texture);
140
141 std::optional<GLuint> handle = TextureGLES::Cast(*texture).GetGLHandle();
142 EXPECT_TRUE(handle.has_value());
143
144 TextureGLES::Cast(*texture).Leak();
145
146 ScopedValidationDisable disable_validation;
147 handle = TextureGLES::Cast(*texture).GetGLHandle();
148 EXPECT_FALSE(handle.has_value());
149}
150
151TEST_P(TextureGLESTest, CreatingAndBindingEmptyTexturesDoesNotCrash) {
152 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
153 const ProcTableGLES& gl = context_gles.GetReactor()->GetProcTable();
154 GLuint texture_name;
155 gl.GenTextures(1, &texture_name);
156
157 TextureDescriptor texture_descriptor;
158 texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
159 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
160 texture_descriptor.size = ISize(0, 0);
161 texture_descriptor.mip_count = 1u;
162
163 impeller::HandleGLES texture_handle = context_gles.GetReactor()->CreateHandle(
164 impeller::HandleType::kTexture, texture_name);
165 auto texture = TextureGLES::WrapTexture(context_gles.GetReactor(),
166 texture_descriptor, texture_handle);
167 // The texture descriptor is invalid because its size is empty, so WrapTexture
168 // will return null.
169 ASSERT_EQ(texture, nullptr);
170}
171
172} // namespace impeller::testing
static ContextGLES & Cast(Context &base)
const std::shared_ptr< ReactorGLES > & GetReactor() const
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition handle_gles.h:42
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
std::optional< HandleGLES > GetSyncFence() const
void SetFence(HandleGLES fence)
Attach a sync fence to this texture that will be waited on before encoding a rendering operation that...
void Leak()
Reset the internal texture state so that the reactor will not free the associated handle.
Type ComputeTypeForBinding(GLenum target) const
std::optional< GLuint > GetGLHandle() const
static std::shared_ptr< TextureGLES > WrapTexture(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is as...
FlTexture * texture
TEST_P(AiksTest, DrawAtlasNoColor)
ISize64 ISize
Definition size.h:162
#define INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(playground)
std::shared_ptr< ReactorGLES > reactor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...