Repository navigation
[Flutter GPU] Add surface API for framework presentation #187358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
41527d3
Add Flutter GPU surface API
bdero 7ec7a99
Address Flutter GPU surface review comments
bdero 8e36788
Compile GPU surface only with Impeller rendering
bdero 93e2999
Revert "Compile GPU surface only with Impeller rendering"
bdero 76757fd
Fix Flutter GPU unit test build deps
bdero e65e2a4
Use [[maybe_unused]] instead of (void) casts in surface.cc
bdero 8a6a8d1
Retrigger CI
bdero 7592dbc
Throw a clear error when a presented surface frame is never submitted
bdero 7e2f158
Refactor surface API into a sealed GpuSurface family
bdero 331f030
Return Dart_Null from PresentFrame on success
bdero d54fc5e
Drop deprecated gmock Invoke wrapper in command buffer test
bdero c092c5a
Add test fixtures dependency to gpu_unittests
bdero 98a7800
Document the present or discard contract on GpuSurfaceFrame
bdero 6d7012b
Run clang-format on command_buffer_unittests.cc
bdero 9c25938
Merge branch 'master' into bdero/flutter-gpu-surface
bdero 4680042
Merge branch 'master' into bdero/flutter-gpu-surface
bdero 840d040
Drop removed TextureCoordinateSystem references
bdero feca459
Merge branch 'master' into bdero/flutter-gpu-surface
bdero e7a20b8
Merge branch 'master' into bdero/flutter-gpu-surface
bdero 4caeea8
Merge branch 'master' into bdero/flutter-gpu-surface
bdero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/lib/gpu/command_buffer.h" | ||
|
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "fml/status.h" | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
| #include "impeller/renderer/testing/mocks.h" | ||
|
|
||
| namespace flutter::gpu { | ||
| namespace { | ||
|
|
||
| using ::impeller::testing::MockCommandBuffer; | ||
| using ::impeller::testing::MockCommandQueue; | ||
| using ::impeller::testing::MockImpellerContext; | ||
| using ::testing::_; | ||
| using ::testing::DoAll; | ||
| using ::testing::Return; | ||
|
|
||
| TEST(FlutterGpuCommandBufferTest, | ||
| InvokesRegisteredCompletionCallbacksOnSubmit) { | ||
| auto context = std::make_shared<MockImpellerContext>(); | ||
| auto impeller_command_buffer = std::make_shared<MockCommandBuffer>(context); | ||
| auto command_queue = std::make_shared<MockCommandQueue>(); | ||
| CommandBuffer command_buffer(context, impeller_command_buffer); | ||
|
|
||
| std::vector<impeller::CommandBuffer::Status> statuses; | ||
|
|
||
| EXPECT_TRUE(command_buffer.AddCompletionCallback( | ||
| [&statuses](impeller::CommandBuffer::Status status) { | ||
| statuses.push_back(status); | ||
| })); | ||
| EXPECT_TRUE(command_buffer.AddCompletionCallback( | ||
| [&statuses](impeller::CommandBuffer::Status status) { | ||
| statuses.push_back(status); | ||
| })); | ||
|
|
||
| EXPECT_CALL(*context, GetBackendType) | ||
| .WillOnce(Return(impeller::Context::BackendType::kMetal)); | ||
| EXPECT_CALL(*context, GetCommandQueue).WillOnce(Return(command_queue)); | ||
| EXPECT_CALL(*command_queue, Submit(_, _, _)) | ||
| .WillOnce(DoAll( | ||
| [](const std::vector<std::shared_ptr<impeller::CommandBuffer>>& | ||
| buffers, | ||
| const impeller::CommandQueue::CompletionCallback& callback, | ||
| bool block_on_schedule) { | ||
| EXPECT_EQ(buffers.size(), 1u); | ||
| EXPECT_FALSE(block_on_schedule); | ||
| callback(impeller::CommandBuffer::Status::kCompleted); | ||
| }, | ||
| Return(fml::Status()))); | ||
|
|
||
| EXPECT_TRUE(command_buffer.Submit( | ||
| [&statuses](impeller::CommandBuffer::Status status) { | ||
| statuses.push_back(status); | ||
| })); | ||
| EXPECT_EQ(statuses.size(), 3u); | ||
| EXPECT_EQ(statuses[0], impeller::CommandBuffer::Status::kCompleted); | ||
| EXPECT_EQ(statuses[1], impeller::CommandBuffer::Status::kCompleted); | ||
| EXPECT_EQ(statuses[2], impeller::CommandBuffer::Status::kCompleted); | ||
| } | ||
|
|
||
| TEST(FlutterGpuCommandBufferTest, RejectsCompletionCallbacksAfterSubmit) { | ||
| auto context = std::make_shared<MockImpellerContext>(); | ||
| auto impeller_command_buffer = std::make_shared<MockCommandBuffer>(context); | ||
| auto command_queue = std::make_shared<MockCommandQueue>(); | ||
| CommandBuffer command_buffer(context, impeller_command_buffer); | ||
|
|
||
| EXPECT_CALL(*context, GetBackendType) | ||
| .WillOnce(Return(impeller::Context::BackendType::kMetal)); | ||
| EXPECT_CALL(*context, GetCommandQueue).WillOnce(Return(command_queue)); | ||
| EXPECT_CALL(*command_queue, Submit(_, _, _)).WillOnce(Return(fml::Status())); | ||
|
|
||
| EXPECT_TRUE(command_buffer.Submit()); | ||
| EXPECT_FALSE(command_buffer.AddCompletionCallback( | ||
| [](impeller::CommandBuffer::Status status) { (void)status; })); | ||
| EXPECT_FALSE(command_buffer.Submit()); | ||
| } | ||
|
|
||
| TEST(FlutterGpuCommandBufferTest, | ||
| InvokesRegisteredCompletionCallbacksWhenSubmitFails) { | ||
| auto context = std::make_shared<MockImpellerContext>(); | ||
| auto impeller_command_buffer = std::make_shared<MockCommandBuffer>(context); | ||
| auto command_queue = std::make_shared<MockCommandQueue>(); | ||
| CommandBuffer command_buffer(context, impeller_command_buffer); | ||
|
|
||
| std::vector<impeller::CommandBuffer::Status> statuses; | ||
|
|
||
| EXPECT_TRUE(command_buffer.AddCompletionCallback( | ||
| [&statuses](impeller::CommandBuffer::Status status) { | ||
| statuses.push_back(status); | ||
| })); | ||
|
|
||
| EXPECT_CALL(*context, GetBackendType) | ||
| .WillOnce(Return(impeller::Context::BackendType::kMetal)); | ||
| EXPECT_CALL(*context, GetCommandQueue).WillOnce(Return(command_queue)); | ||
| EXPECT_CALL(*command_queue, Submit(_, _, _)) | ||
| .WillOnce(Return(fml::Status(fml::StatusCode::kInternal, | ||
| "Command queue submit failed."))); | ||
|
|
||
| EXPECT_FALSE(command_buffer.Submit()); | ||
| EXPECT_EQ(statuses.size(), 1u); | ||
| EXPECT_EQ(statuses[0], impeller::CommandBuffer::Status::kError); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace flutter::gpu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding a unit test for these c++ level changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7ec7a99.