Skip to content
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

BasicSurface: allow frame to be posted after surface destroyed #1273

Merged
merged 3 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/server/scene/basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ ms::BasicSurface::BasicSurface(
{
if (auto const o = observers.lock())
o->frame_posted(this, 1, size);
else
BOOST_THROW_EXCEPTION(std::runtime_error("Frame posted to dead surface"));
};

for (auto& layer : layers)
Expand Down Expand Up @@ -925,8 +923,6 @@ void ms::BasicSurface::set_streams(std::list<scene::StreamInfo> const& s)
{
if (auto const o = observers.lock())
o->frame_posted(this, 1, size);
else
BOOST_THROW_EXCEPTION(std::runtime_error("Frame posted to dead surface"));
});
surface_top_left = surface_rect.top_left;
}
Expand Down
52 changes: 52 additions & 0 deletions tests/unit-tests/scene/test_basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,3 +1582,55 @@ TEST_F(BasicSurfaceTest, notifies_when_first_visible)
EXPECT_THAT(observer->exposes(), Eq(1));
EXPECT_THAT(observer->hides(), Eq(0));
}

TEST_F(BasicSurfaceTest, buffer_can_be_submitted_to_original_stream_after_surface_destroyed)
{
using namespace testing;

auto local_stream = std::make_shared<NiceMock<mtd::MockBufferStream>>();
std::list<ms::StreamInfo> local_stream_list = { { local_stream, {}, {} } };
std::function<void(geom::Size const&)> callback = [](auto){};

EXPECT_CALL(*local_stream, set_frame_posted_callback(_))
.Times(AtLeast(1))
.WillRepeatedly(SaveArg<0>(&callback));

auto surface = std::make_unique<ms::BasicSurface>(
nullptr, // session
name,
rect,
mir_pointer_unconfined,
local_stream_list,
std::shared_ptr<mg::CursorImage>(),
report);

surface.reset();
callback({10, 10});
}

TEST_F(BasicSurfaceTest, buffer_can_be_submitted_to_set_stream_after_surface_destroyed)
{
using namespace testing;

auto local_stream = std::make_shared<NiceMock<mtd::MockBufferStream>>();
std::list<ms::StreamInfo> local_stream_list = { { local_stream, {}, {} } };
std::function<void(geom::Size const&)> callback = [](auto){};

EXPECT_CALL(*local_stream, set_frame_posted_callback(_))
.Times(AtLeast(1))
.WillRepeatedly(SaveArg<0>(&callback));

auto surface = std::make_unique<ms::BasicSurface>(
nullptr, // session
name,
rect,
mir_pointer_unconfined,
streams, // use the default list from the class initially
std::shared_ptr<mg::CursorImage>(),
report);

surface->set_streams(local_stream_list);

surface.reset();
callback({10, 10});
}