| Flutter Impeller |

render_pass_cache_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 #include "impeller/playground/playground_test.h"
8 #include "impeller/renderer/backend/vulkan/texture_vk.h"
9 #include "impeller/renderer/render_target.h"
10
11 namespace impeller {
12 namespace testing {
13
14 using RendererTest = PlaygroundTest;
15
16 TEST_P(RendererTest, CachesRenderPassAndFramebuffer) {
17 if (GetBackend() != PlaygroundBackend::kVulkan) {
18 GTEST_SKIP() << "Test only applies to Vulkan";
19 }
20
21 auto allocator = std::make_shared<RenderTargetAllocator>(
22 GetContext()->GetResourceAllocator());
23
24 auto render_target =
25 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
26 auto resolve_texture = render_target.GetColorAttachment(0).resolve_texture;
27 auto& texture_vk = TextureVK::Cast(*resolve_texture);
28
29 EXPECT_EQ(texture_vk.GetCachedFramebuffer(), nullptr);
30 EXPECT_EQ(texture_vk.GetCachedRenderPass(), nullptr);
31
32 auto buffer = GetContext()->CreateCommandBuffer();
33 auto render_pass = buffer->CreateRenderPass(render_target);
34
35 EXPECT_NE(texture_vk.GetCachedFramebuffer(), nullptr);
36 EXPECT_NE(texture_vk.GetCachedRenderPass(), nullptr);
37
38 render_pass->EncodeCommands();
39 GetContext()->GetCommandQueue()->Submit({buffer});
40
41 // Can be reused without error.
42 auto buffer_2 = GetContext()->CreateCommandBuffer();
43 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
44
45 EXPECT_TRUE(render_pass_2->EncodeCommands());
46 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
47 }
48
49 } // namespace testing
50 } // namespace impeller
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:13
impeller::PlaygroundTest
Definition: playground_test.h:22
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:57
impeller
Definition: allocation.cc:12
impeller::PlaygroundBackend::kVulkan
@ kVulkan
playground_test.h
render_target.h
texture_vk.h