Flutter Engine
 
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, Binds2DTexture) {
73 desc.size = {100, 100};
77
78 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
79
80 ASSERT_TRUE(texture);
81
82 if (GetContext()->GetCapabilities()->SupportsImplicitResolvingMSAA()) {
83 EXPECT_EQ(
84 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
86 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
88 } else {
89 EXPECT_EQ(
90 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
92 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
94 }
95}
96
100 desc.size = {100, 100};
104
105 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
106
107 ASSERT_TRUE(texture);
108
109 std::optional<GLuint> handle = TextureGLES::Cast(*texture).GetGLHandle();
110 EXPECT_TRUE(handle.has_value());
111
112 TextureGLES::Cast(*texture).Leak();
113
114 ScopedValidationDisable disable_validation;
115 handle = TextureGLES::Cast(*texture).GetGLHandle();
116 EXPECT_FALSE(handle.has_value());
117}
118
119} // namespace impeller::testing
static ContextGLES & Cast(Context &base)
const std::shared_ptr< ReactorGLES > & GetReactor() const
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
std::optional< HandleGLES > GetSyncFence() const
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
FlTexture * texture
TEST_P(AiksTest, DrawAtlasNoColor)
#define INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(playground)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...