Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ FlutterViewController::~FlutterViewController() {
}
}

FlutterViewId FlutterViewController::view_id() const {
auto view_id = FlutterDesktopViewControllerGetViewId(controller_);

return static_cast<FlutterViewId>(view_id);
}

void FlutterViewController::ForceRedraw() {
FlutterDesktopViewControllerForceRedraw(controller_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ TEST(FlutterViewControllerTest, CreateDestroy) {
EXPECT_FALSE(test_api->engine_destroyed());
}

TEST(FlutterViewControllerTest, GetViewId) {
DartProject project(L"data");
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
std::make_unique<TestWindowsApi>());
auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
FlutterViewController controller(100, 100, project);
EXPECT_EQ(controller.view_id(), 1);
}

TEST(FlutterViewControllerTest, GetEngine) {
DartProject project(L"data");
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace flutter {

// The unique identifier for a view.
typedef int64_t FlutterViewId;
Copy link
Member Author

@loic-sharma loic-sharma Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FlutterViewId typedef is new, the design doc used int64_t directly.


// A view displaying Flutter content.
class FlutterView {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ class FlutterViewController {
FlutterViewController(FlutterViewController const&) = delete;
FlutterViewController& operator=(FlutterViewController const&) = delete;

// Returns the view controller's view ID.
FlutterViewId view_id() const;

// Returns the engine running Flutter content in this view.
FlutterEngine* engine() { return engine_.get(); }
FlutterEngine* engine() const { return engine_.get(); }

// Returns the view managed by this controller.
FlutterView* view() { return view_.get(); }
FlutterView* view() const { return view_.get(); }

// Requests new frame from the engine and repaints the view.
void ForceRedraw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ void FlutterDesktopViewControllerDestroy(
}
}

FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(
FlutterDesktopViewControllerRef controller) {
// The stub ignores this, so just return an arbitrary non-zero value.
return static_cast<FlutterDesktopViewId>(1);
}

FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(
FlutterDesktopViewControllerRef controller) {
// The stub ignores this, so just return an arbitrary non-zero value.
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef ref) {
delete controller;
}

FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(
FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
return static_cast<FlutterDesktopViewId>(controller->view()->view_id());
}

FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(
FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
Expand Down
12 changes: 12 additions & 0 deletions shell/platform/windows/flutter_windows_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ TEST_F(WindowsTest, NextFrameCallback) {
captures.frame_drawn_latch.Wait();
}

// Implicit view has the implicit view ID.
TEST_F(WindowsTest, GetViewId) {
auto& context = GetContext();
WindowsConfigBuilder builder(context);
ViewControllerPtr controller{builder.Run()};
ASSERT_NE(controller, nullptr);
FlutterDesktopViewId view_id =
FlutterDesktopViewControllerGetViewId(controller.get());

ASSERT_EQ(view_id, static_cast<FlutterDesktopViewId>(kImplicitViewId));
}

TEST_F(WindowsTest, GetGraphicsAdapter) {
auto& context = GetContext();
WindowsConfigBuilder builder(context);
Expand Down
11 changes: 9 additions & 2 deletions shell/platform/windows/public/flutter_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ typedef struct FlutterDesktopView* FlutterDesktopViewRef;
struct FlutterDesktopEngine;
typedef struct FlutterDesktopEngine* FlutterDesktopEngineRef;

// The unique identifier for a view.
typedef int64_t FlutterDesktopViewId;
Copy link
Member Author

@loic-sharma loic-sharma Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FlutterDesktopViewId typedef is new, the design doc used int64_t directly.


// Properties for configuring a Flutter engine instance.
typedef struct {
// The path to the flutter_assets folder for the application to be run.
Expand Down Expand Up @@ -97,13 +100,17 @@ FlutterDesktopViewControllerCreate(int width,
FLUTTER_EXPORT void FlutterDesktopViewControllerDestroy(
FlutterDesktopViewControllerRef controller);

// Returns the view controller's view ID.
FLUTTER_EXPORT FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(
FlutterDesktopViewControllerRef view_controller);

// Returns the handle for the engine running in FlutterDesktopViewControllerRef.
//
// Its lifetime is the same as the |controller|'s.
FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(
FlutterDesktopViewControllerRef controller);
// Returns the view managed by the given controller.

// Returns the view managed by the given controller.
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView(
FlutterDesktopViewControllerRef controller);

Expand Down Expand Up @@ -205,7 +212,7 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback(

// ========== View ==========

// Return backing HWND for manipulation in host application.
// Returns the backing HWND for manipulation in host application.
FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view);

// Returns the DXGI adapter used for rendering or nullptr in case of error.
Expand Down