-
Notifications
You must be signed in to change notification settings - Fork 128
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
[Ozone] Move ownership of SbWindow to the platform window class #4688
Open
TyHolc
wants to merge
2
commits into
youtube:experimental/ozone
Choose a base branch
from
TyHolc:content_area_size
base: experimental/ozone
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
−32
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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
76 changes: 76 additions & 0 deletions
76
ui/ozone/platform/starboard/test/platform_window_starboard_unittest.cc
This file contains 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,76 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "ui/ozone/platform/starboard/platform_window_starboard.h" | ||
|
||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "ui/events/base_event_utils.h" | ||
#include "ui/events/event.h" | ||
#include "ui/events/event_utils.h" | ||
#include "ui/events/types/event_type.h" | ||
#include "ui/ozone/platform/starboard/test/starboard_test_helper.h" | ||
|
||
namespace ui { | ||
namespace { | ||
// Using OzoneStarboardTest to allow SbWindowCreate and SbWindowDestroy. | ||
class PlatformWindowStarboardTest : public OzoneStarboardTest { | ||
public: | ||
PlatformWindowStarboardTest() { | ||
sb_window_ = | ||
std::make_unique<PlatformWindowStarboard>(&delegate_, gfx::Rect(0, 0)); | ||
} | ||
|
||
~PlatformWindowStarboardTest() { | ||
// Reset |sb_window_| before parent destructor is called so SbWindowDestroy | ||
// can run. | ||
sb_window_.reset(); | ||
} | ||
|
||
PlatformWindowStarboard* window() { return sb_window_.get(); } | ||
|
||
protected: | ||
MockPlatformWindowDelegate delegate_; | ||
|
||
private: | ||
// Using a pointer to delay initialization of the window until after starting | ||
// the main Starboard thread in partent constructor. | ||
std::unique_ptr<PlatformWindowStarboard> sb_window_; | ||
}; | ||
|
||
TEST_F(PlatformWindowStarboardTest, CanDispatchEvent) { | ||
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | ||
ui::EventTimeForNow(), 0, 0); | ||
const PlatformEvent& platform_event = &event; | ||
|
||
EXPECT_TRUE(window()->CanDispatchEvent(platform_event)); | ||
} | ||
|
||
TEST_F(PlatformWindowStarboardTest, DispatchEvent) { | ||
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | ||
ui::EventTimeForNow(), 0, 0); | ||
const PlatformEvent& platform_event = &event; | ||
|
||
ui::EventType type; | ||
EXPECT_CALL(delegate_, DispatchEvent(testing::_)) | ||
.Times(1) | ||
.WillOnce([&type](const PlatformEvent& event) { | ||
type = ui::EventTypeFromNative(event); | ||
}); | ||
|
||
auto result = window()->DispatchEvent(platform_event); | ||
EXPECT_EQ(result, ui::POST_DISPATCH_STOP_PROPAGATION); | ||
EXPECT_EQ(type, ui::ET_MOUSE_PRESSED); | ||
} | ||
} // namespace | ||
} // namespace ui |
This file contains 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,73 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "ui/ozone/platform/starboard/test/starboard_test_helper.h" | ||
|
||
#include "starboard/system.h" | ||
|
||
namespace ui { | ||
// SbEventHandle needs to call into the test class' event handler to signal the | ||
// |started_condition_|, so the test object is tracked here. | ||
OzoneStarboardTest* ozone_starboard_test_instance = nullptr; | ||
|
||
// Static callback for SbEvents. This will pass events to the test class' | ||
// implementation of |EventHandleInternal| to signal the main thread has | ||
// started. | ||
void SbEventHandle(const SbEvent* event) { | ||
if (ozone_starboard_test_instance) { | ||
ozone_starboard_test_instance->EventHandleInternal(event); | ||
} | ||
} | ||
|
||
OzoneStarboardTest::OzoneStarboardTest() { | ||
ozone_starboard_test_instance = this; | ||
|
||
started_condition_ = std::make_unique<ConditionVariable>(started_mutex_); | ||
|
||
// Start the main starboard thread to allow Starboard function calls. | ||
sb_main_ = std::make_unique<OzoneStarboardThread>(); | ||
started_mutex_.Acquire(); | ||
sb_main_->Start(); | ||
// Wait for the |kSbEventTypeStart| to signal the initialization completion | ||
// before continuing. | ||
started_condition_->Wait(); | ||
started_mutex_.Release(); | ||
} | ||
|
||
OzoneStarboardTest::~OzoneStarboardTest() { | ||
// Kill and clean up the Starboard main thread. | ||
SbSystemRequestStop(0); | ||
sb_main_->Join(); | ||
sb_main_.reset(); | ||
|
||
started_condition_.reset(); | ||
ozone_starboard_test_instance = nullptr; | ||
} | ||
|
||
// Note: If overriding this function, be sure to signal the started_condition_ | ||
// or the test will hang. | ||
void OzoneStarboardTest::EventHandleInternal(const SbEvent* event) { | ||
switch (event->type) { | ||
case kSbEventTypeStart: | ||
started_condition_->Signal(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void OzoneStarboardTest::OzoneStarboardThread::Run() { | ||
SbRunStarboardMain(0, nullptr, &SbEventHandle); | ||
} | ||
} // namespace ui |
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 chose an arbitrary size here for now, but I was thinking we could create a default SbOptions object and get the height and width from that if we wanted to initialize to those. Lmk thoughts on that.
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.
(Leaving that Q for @y4vor )
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.
We should use the existing
SbWindowGetSize
.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.
This is running before the starboard window is created, and will actually inform the initial size of the starboard window once it's created.
Because this will propagate to the SbWindow, I thought we could do something like: