Skip to content

Commit

Permalink
Introduce TizenViewEventHandlerDelegate and rework FlutterDesktopView…
Browse files Browse the repository at this point in the history
…Resize (#309)

* `TizenViewEventHandlerDelegate` only provides a limited interface for delegating event handling.
* `FlutterDesktopViewResize` should work on all types of views.
* Implementations of `TizenViewBase::SetGeometry` only manipulate top-level raw object such as window, container.
  other components in the view are manipulated on a resize callback.
* window channel use `SetGeometry` normally.
   
Signed-off-by: Boram Bae <[email protected]>
  • Loading branch information
bbrto21 authored Jul 11, 2022
1 parent 97c6cd1 commit 45cc5b5
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 195 deletions.
5 changes: 1 addition & 4 deletions shell/platform/tizen/channels/window_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ void WindowChannel::HandleMethodCall(
EncodableValueHolder<int32_t> height(arguments, "height");

TizenGeometry geometry = window_->GetGeometry();
// FIXME: Use SetGeometry() instead of OnGeometryChanged()
// After the SetGeometry was successfully executed, I expected a
// handler of ECORE_WL2_EVENT_WINDOW_CONFIGURE to be called, but it didn't.
window_->OnGeometryChanged({
window_->SetGeometry({
x ? *x : geometry.left,
y ? *y : geometry.top,
width ? *width : geometry.width,
Expand Down
11 changes: 11 additions & 0 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ FlutterDesktopEngineRef HandleForEngine(flutter::FlutterTizenEngine* engine) {
return reinterpret_cast<FlutterDesktopEngineRef>(engine);
}

// Returns the view corresponding to the given opaque API handle.
flutter::FlutterTizenView* ViewFromHandle(FlutterDesktopViewRef view) {
return reinterpret_cast<flutter::FlutterTizenView*>(view);
}

// Returns the texture registrar corresponding to the given opaque API handle.
flutter::FlutterTizenTextureRegistrar* TextureRegistrarFromHandle(
FlutterDesktopTextureRegistrarRef ref) {
Expand Down Expand Up @@ -176,6 +181,12 @@ void FlutterDesktopEngineNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->lifecycle_channel()->AppIsDetached();
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view,
int32_t width,
int32_t height) {
ViewFromHandle(view)->Resize(width, height);
}

void FlutterDesktopRegisterViewFactory(
FlutterDesktopPluginRegistrarRef registrar,
const char* view_type,
Expand Down
6 changes: 0 additions & 6 deletions shell/platform/tizen/flutter_tizen_ecore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,3 @@ void* FlutterDesktopViewGetEvasObject(FlutterDesktopViewRef view_ref) {
FT_LOG(Warn) << "Not applicable!";
return nullptr;
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view_ref,
int32_t width,
int32_t height) {
FT_LOG(Warn) << "Not applicable!";
}
7 changes: 0 additions & 7 deletions shell/platform/tizen/flutter_tizen_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,3 @@ void* FlutterDesktopViewGetEvasObject(FlutterDesktopViewRef view_ref) {
}
return nullptr;
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view_ref,
int32_t width,
int32_t height) {
auto* view = reinterpret_cast<flutter::FlutterTizenView*>(view_ref);
view->OnResize(0, 0, width, height);
}
13 changes: 10 additions & 3 deletions shell/platform/tizen/flutter_tizen_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void FlutterTizenView::DestroyRenderSurface() {
}
}

void FlutterTizenView::Resize(int32_t width, int32_t height) {
TizenGeometry geometry = tizen_view_->GetGeometry();
geometry.width = width;
geometry.height = height;
tizen_view_->SetGeometry(geometry);
}

bool FlutterTizenView::OnMakeCurrent() {
return engine_->renderer()->OnMakeCurrent();
}
Expand Down Expand Up @@ -135,7 +142,8 @@ void FlutterTizenView::OnResize(int32_t left,
std::swap(width, height);
}

tizen_view_->ResizeWithRotation({left, top, width, height}, rotation_degree_);
engine_->renderer()->ResizeSurface(width, height);

SendWindowMetrics(left, top, width, height, 0.0);
}

Expand Down Expand Up @@ -167,8 +175,7 @@ void FlutterTizenView::OnRotate(int32_t degree) {
std::swap(width, height);
}

tizen_view_->ResizeWithRotation({geometry.left, geometry.top, width, height},
rotation_degree_);
engine_->renderer()->ResizeSurface(width, height);

// Window position does not change on rotation regardless of its orientation.
SendWindowMetrics(geometry.left, geometry.top, width, height, 0.0);
Expand Down
32 changes: 19 additions & 13 deletions shell/platform/tizen/flutter_tizen_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#include "flutter/shell/platform/tizen/channels/window_channel.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_view_base.h"
#include "flutter/shell/platform/tizen/tizen_view_event_handler_delegate.h"

namespace flutter {

class FlutterTizenView {
class FlutterTizenView : public TizenViewEventHandlerDelegate {
public:
FlutterTizenView(std::unique_ptr<TizenViewBase> tizen_view);

~FlutterTizenView();
virtual ~FlutterTizenView();

// Configures the window instance with an instance of a running Flutter
// engine.
Expand All @@ -40,6 +41,8 @@ class FlutterTizenView {
// Destroys current rendering surface if one has been allocated.
void DestroyRenderSurface();

void Resize(int32_t width, int32_t height);

// Callbacks for clearing context, settings context and swapping buffers,
// these are typically called on an engine-controlled (non-platform) thread.
bool OnMakeCurrent();
Expand All @@ -51,27 +54,30 @@ class FlutterTizenView {

void* OnProcResolver(const char* name);

void OnResize(int32_t left, int32_t top, int32_t width, int32_t height);
void OnResize(int32_t left,
int32_t top,
int32_t width,
int32_t height) override;

void OnRotate(int32_t degree);
void OnRotate(int32_t degree) override;

void OnPointerMove(double x,
double y,
size_t timestamp,
FlutterPointerDeviceKind device_kind,
int32_t device_id);
int32_t device_id) override;

void OnPointerDown(double x,
double y,
size_t timestamp,
FlutterPointerDeviceKind device_kind,
int32_t device_id);
int32_t device_id) override;

void OnPointerUp(double x,
double y,
size_t timestamp,
FlutterPointerDeviceKind device_kind,
int32_t device_id);
int32_t device_id) override;

void OnScroll(double x,
double y,
Expand All @@ -80,22 +86,22 @@ class FlutterTizenView {
int scroll_offset_multiplier,
size_t timestamp,
FlutterPointerDeviceKind device_kind,
int32_t device_id);
int32_t device_id) override;

void OnKey(const char* key,
const char* string,
const char* compose,
uint32_t modifiers,
uint32_t scan_code,
bool is_down);
bool is_down) override;

void OnComposeBegin();
void OnComposeBegin() override;

void OnComposeChange(const std::string& str, int cursor_pos);
void OnComposeChange(const std::string& str, int cursor_pos) override;

void OnComposeEnd();
void OnComposeEnd() override;

void OnCommit(const std::string& str);
void OnCommit(const std::string& str) override;

FlutterTransformation GetFlutterTransformation() {
return flutter_transformation_;
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/tizen/tizen_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TizenRenderer {

virtual bool IsSupportedExtension(const char* name) = 0;

virtual void ResizeSurface(int32_t width, int32_t height) = 0;

protected:
bool is_valid_ = false;
};
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/tizen/tizen_renderer_egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ bool TizenRendererEgl::IsSupportedExtension(const char* name) {
return strstr(egl_extension_str_.c_str(), name);
}

void TizenRendererEgl::ResizeSurface(int32_t width, int32_t height) {
// Do nothing.
}

void* TizenRendererEgl::OnProcResolver(const char* name) {
auto address = eglGetProcAddress(name);
if (address != nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/tizen/tizen_renderer_egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TizenRendererEgl : public TizenRenderer {

bool IsSupportedExtension(const char* name) override;

void ResizeSurface(int32_t width, int32_t height) override;

private:
bool ChooseEGLConfiguration();

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/tizen_renderer_evas_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TizenRendererEvasGL : public TizenRenderer {

void MarkPixelsDirty();

void ResizeSurface(int32_t width, int32_t height);
void ResizeSurface(int32_t width, int32_t height) override;

private:
Evas_GL* evas_gl_ = nullptr;
Expand Down
11 changes: 5 additions & 6 deletions shell/platform/tizen/tizen_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#include <vector>

#include "flutter/shell/platform/tizen/tizen_input_method_context.h"
#include "flutter/shell/platform/tizen/tizen_view_event_handler_delegate.h"

namespace flutter {

class FlutterTizenView;

struct TizenGeometry {
int32_t left = 0, top = 0, width = 0, height = 0;
};
Expand Down Expand Up @@ -44,9 +43,9 @@ class TizenViewBase {

// Sets the delegate used to communicate state changes from render target to
// view such as key presses, mouse position updates etc.
void SetView(FlutterTizenView* view) { view_ = view; }

virtual void ResizeWithRotation(TizenGeometry geometry, int32_t degree) = 0;
void SetView(TizenViewEventHandlerDelegate* view_delegate) {
view_delegate_ = view_delegate;
}

virtual void Show() = 0;

Expand All @@ -57,7 +56,7 @@ class TizenViewBase {
}

protected:
FlutterTizenView* view_ = nullptr;
TizenViewEventHandlerDelegate* view_delegate_ = nullptr;

// The Tizen input method context. nullptr if not set.
std::unique_ptr<TizenInputMethodContext> input_method_context_;
Expand Down
Loading

0 comments on commit 45cc5b5

Please sign in to comment.