Skip to content

Remove FlutterWindowProperties and get the screen size automatically #72

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 1 commit into from
Apr 27, 2021
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
3 changes: 1 addition & 2 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ struct FlutterWindowControllerState {
};

FlutterWindowControllerRef FlutterCreateWindow(
const FlutterWindowProperties& window_properties,
const FlutterEngineProperties& engine_properties) {
StartLogging();

auto state = std::make_unique<FlutterWindowControllerState>();
state->engine = std::make_unique<TizenEmbedderEngine>(window_properties);
state->engine = std::make_unique<TizenEmbedderEngine>();

if (!state->engine->RunEngine(engine_properties)) {
FT_LOGE("Failed to run the Flutter engine.");
Expand Down
15 changes: 1 addition & 14 deletions shell/platform/tizen/public/flutter_tizen.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ extern "C" {
// Opaque reference to a Flutter window controller.
typedef struct FlutterWindowControllerState* FlutterWindowControllerRef;

// Properties for configuring the initial settings of a Flutter window.
typedef struct {
// The display title.
const char* title;
int32_t x;
int32_t y;
// Width in screen coordinates.
int32_t width;
// Height in screen coordinates.
int32_t height;
} FlutterWindowProperties;

// Properties for configuring a Flutter engine instance.
typedef struct {
// The path to the flutter_assets folder for the application to be run.
Expand All @@ -50,8 +38,7 @@ typedef struct {
} FlutterEngineProperties;

FLUTTER_EXPORT FlutterWindowControllerRef
FlutterCreateWindow(const FlutterWindowProperties& window_properties,
const FlutterEngineProperties& engine_properties);
FlutterCreateWindow(const FlutterEngineProperties& engine_properties);

// Returns the plugin registrar handle for the plugin with the given name.
//
Expand Down
27 changes: 8 additions & 19 deletions shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,12 @@ static DeviceProfile GetDeviceProfile() {
return DeviceProfile::kUnknown;
}

static double GetDeviceDpi() {
int feature_dpi;
system_info_get_platform_int("http://tizen.org/feature/screen.dpi",
&feature_dpi);
return (double)feature_dpi;
}

TizenEmbedderEngine::TizenEmbedderEngine(
const FlutterWindowProperties& window_properties)
: device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) {
TizenEmbedderEngine::TizenEmbedderEngine()
: device_profile(GetDeviceProfile()) {
#ifdef TIZEN_RENDERER_EVAS_GL
tizen_renderer = std::make_unique<TizenRendererEvasGL>(
*this, window_properties.x, window_properties.y, window_properties.width,
window_properties.height);
tizen_renderer = std::make_unique<TizenRendererEvasGL>(*this);
#else
tizen_renderer = std::make_unique<TizenRendererEcoreWl2>(
*this, window_properties.x, window_properties.y, window_properties.width,
window_properties.height);
tizen_renderer = std::make_unique<TizenRendererEcoreWl2>(*this);
#endif

// Run flutter task on Tizen main loop.
Expand Down Expand Up @@ -296,17 +284,18 @@ void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height,
// The scale factor is computed based on the display DPI and the current
// profile. A fixed DPI value (72) is used on TVs. See:
// https://docs.tizen.org/application/native/guides/ui/efl/multiple-screens
double dpi = 72.0;
if (tizen_renderer && device_profile != DeviceProfile::kTV) {
dpi = (double)tizen_renderer->GetDpi();
}
double profile_factor = 1.0;
if (device_profile == DeviceProfile::kWearable) {
profile_factor = 0.4;
} else if (device_profile == DeviceProfile::kMobile) {
profile_factor = 0.7;
} else if (device_profile == DeviceProfile::kTV) {
profile_factor = 2.0;
} else if (device_profile == DeviceProfile::kCommon) {
profile_factor = 0.5;
}
double dpi = device_profile == DeviceProfile::kTV ? 72.0 : device_dpi;
double scale_factor = dpi / 90.0 * profile_factor;
event.pixel_ratio = std::max(scale_factor, 1.0);
} else {
Expand Down
4 changes: 1 addition & 3 deletions shell/platform/tizen/tizen_embedder_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ enum DeviceProfile { kUnknown, kMobile, kWearable, kTV, kCommon };
// Manages state associated with the underlying FlutterEngine.
class TizenEmbedderEngine : public TizenRenderer::Delegate {
public:
explicit TizenEmbedderEngine(
const FlutterWindowProperties& window_properties);
explicit TizenEmbedderEngine();
virtual ~TizenEmbedderEngine();
bool RunEngine(const FlutterEngineProperties& engine_properties);
bool StopEngine();
Expand Down Expand Up @@ -114,7 +113,6 @@ class TizenEmbedderEngine : public TizenRenderer::Delegate {
std::unique_ptr<PlatformViewChannel> platform_view_channel;

const DeviceProfile device_profile;
const double device_dpi;

private:
static bool MakeContextCurrent(void* user_data);
Expand Down
1 change: 1 addition & 0 deletions shell/platform/tizen/tizen_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TizenRenderer {
virtual void* OnProcResolver(const char* name) = 0;

virtual TizenWindowGeometry GetGeometry() = 0;
virtual int32_t GetDpi() = 0;
virtual uintptr_t GetWindowId() = 0;

virtual void SetRotate(int angle) = 0;
Expand Down
44 changes: 26 additions & 18 deletions shell/platform/tizen/tizen_renderer_ecore_wl2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

#include "flutter/shell/platform/tizen/tizen_log.h"

TizenRendererEcoreWl2::TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate,
int32_t x, int32_t y, int32_t w,
int32_t h)
TizenRendererEcoreWl2::TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate)
: TizenRenderer(delegate) {
InitializeRenderer(x, y, w, h);
InitializeRenderer();
}

TizenRendererEcoreWl2::~TizenRendererEcoreWl2() { DestroyRenderer(); }
Expand Down Expand Up @@ -217,21 +215,30 @@ TizenRenderer::TizenWindowGeometry TizenRendererEcoreWl2::GetGeometry() {
return result;
}

int32_t TizenRendererEcoreWl2::GetDpi() {
auto *output = ecore_wl2_window_output_find(ecore_wl2_window_);
if (!output) {
FT_LOGE("Could not find an output associated with the window.");
return 0;
}
return ecore_wl2_output_dpi_get(output);
}

uintptr_t TizenRendererEcoreWl2::GetWindowId() {
return (uintptr_t)ecore_wl2_window_id_get(ecore_wl2_window_);
}

bool TizenRendererEcoreWl2::InitializeRenderer(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (!SetupDisplay()) {
bool TizenRendererEcoreWl2::InitializeRenderer() {
int32_t width, height;
if (!SetupDisplay(width, height)) {
FT_LOGE("SetupDisplay fail");
return false;
}
if (!SetupEcoreWlWindow(x, y, w, h)) {
if (!SetupEcoreWlWindow(width, height)) {
FT_LOGE("SetupEcoreWlWindow fail");
return false;
}
if (!SetupEglWindow(w, h)) {
if (!SetupEglWindow(width, height)) {
FT_LOGE("SetupEglWindow fail");
return false;
}
Expand All @@ -253,7 +260,7 @@ void TizenRendererEcoreWl2::DestroyRenderer() {
ShutdownDisplay();
}

bool TizenRendererEcoreWl2::SetupDisplay() {
bool TizenRendererEcoreWl2::SetupDisplay(int32_t &width, int32_t &height) {
if (!ecore_wl2_init()) {
FT_LOGE("Could not initialize ecore_wl2");
return false;
Expand All @@ -265,20 +272,20 @@ bool TizenRendererEcoreWl2::SetupDisplay() {
}
FT_LOGD("ecore_wl2_display_: %p", ecore_wl2_display_);
ecore_wl2_sync();
ecore_wl2_display_screen_size_get(ecore_wl2_display_, &width, &height);
return true;
}

bool TizenRendererEcoreWl2::SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (w == 0 || h == 0) {
FT_LOGE("Failed to create because of the wrong size");
bool TizenRendererEcoreWl2::SetupEcoreWlWindow(int32_t width, int32_t height) {
if (width == 0 || height == 0) {
FT_LOGE("Invalid screen size: %d x %d", width, height);
return false;
}
ecore_wl2_window_ =
ecore_wl2_window_new(ecore_wl2_display_, nullptr, x, y, w, h);
ecore_wl2_window_new(ecore_wl2_display_, nullptr, 0, 0, width, height);
ecore_wl2_window_type_set(ecore_wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
ecore_wl2_window_alpha_set(ecore_wl2_window_, EINA_FALSE);
ecore_wl2_window_position_set(ecore_wl2_window_, x, y);
ecore_wl2_window_position_set(ecore_wl2_window_, 0, 0);
ecore_wl2_window_aux_hint_add(ecore_wl2_window_, 0,
"wm.policy.win.user.geometry", "1");
int rotations[4] = {0, 90, 180, 270};
Expand All @@ -288,8 +295,9 @@ bool TizenRendererEcoreWl2::SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w,
return true;
}

bool TizenRendererEcoreWl2::SetupEglWindow(int32_t w, int32_t h) {
ecore_wl2_egl_window_ = ecore_wl2_egl_window_create(ecore_wl2_window_, w, h);
bool TizenRendererEcoreWl2::SetupEglWindow(int32_t width, int32_t height) {
ecore_wl2_egl_window_ =
ecore_wl2_egl_window_create(ecore_wl2_window_, width, height);
return ecore_wl2_egl_window_ != nullptr;
}

Expand Down
12 changes: 6 additions & 6 deletions shell/platform/tizen/tizen_renderer_ecore_wl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class TizenRendererEcoreWl2 : public TizenRenderer {
public:
explicit TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate, int32_t x,
int32_t y, int32_t w, int32_t h);
explicit TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate);
virtual ~TizenRendererEcoreWl2();

bool OnMakeCurrent() override;
Expand All @@ -25,20 +24,21 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
void *OnProcResolver(const char *name) override;

TizenWindowGeometry GetGeometry() override;
int32_t GetDpi() override;
uintptr_t GetWindowId() override;

void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
int32_t angle) override;
void SetRotate(int angle) override;

private:
bool InitializeRenderer(int32_t x, int32_t y, int32_t w, int32_t h);
bool InitializeRenderer();
void Show();
void DestroyRenderer();

bool SetupDisplay();
bool SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, int32_t h);
bool SetupEglWindow(int32_t w, int32_t h);
bool SetupDisplay(int32_t &width, int32_t &height);
bool SetupEcoreWlWindow(int32_t width, int32_t height);
bool SetupEglWindow(int32_t width, int32_t height);
EGLDisplay GetEGLDisplay();
EGLNativeWindowType GetEGLNativeWindowType();
void DestroyEglWindow();
Expand Down
55 changes: 32 additions & 23 deletions shell/platform/tizen/tizen_renderer_evas_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ EVAS_GL_GLOBAL_GLES3_DEFINE();

#include "flutter/shell/platform/tizen/tizen_log.h"

TizenRendererEvasGL::TizenRendererEvasGL(TizenRenderer::Delegate& delegate,
int32_t x, int32_t y, int32_t w,
int32_t h)
TizenRendererEvasGL::TizenRendererEvasGL(TizenRenderer::Delegate& delegate)
: TizenRenderer(delegate) {
InitializeRenderer(x, y, w, h);
InitializeRenderer();

// Clear once to remove noise.
OnMakeCurrent();
Expand Down Expand Up @@ -549,16 +547,23 @@ TizenRenderer::TizenWindowGeometry TizenRendererEvasGL::GetGeometry() {
return result;
}

int32_t TizenRendererEvasGL::GetDpi() {
auto* ecore_evas =
ecore_evas_ecore_evas_get(evas_object_evas_get(evas_window_));
int32_t xdpi, ydpi;
ecore_evas_screen_dpi_get(ecore_evas, &xdpi, &ydpi);
return xdpi;
}

uintptr_t TizenRendererEvasGL::GetWindowId() {
return ecore_evas_window_get(
ecore_evas_ecore_evas_get(evas_object_evas_get(evas_window_)));
}

void* TizenRendererEvasGL::GetImageHandle() { return (void*)graphics_adapter_; }

bool TizenRendererEvasGL::InitializeRenderer(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (!SetupEvasGL(x, y, w, h)) {
bool TizenRendererEvasGL::InitializeRenderer() {
if (!SetupEvasGL()) {
FT_LOGE("SetupEvasGL fail");
return false;
}
Expand All @@ -577,10 +582,10 @@ void TizenRendererEvasGL::DestroyRenderer() {
DestroyEvasWindow();
}

bool TizenRendererEvasGL::SetupEvasGL(int32_t x, int32_t y, int32_t w,
int32_t h) {
bool TizenRendererEvasGL::SetupEvasGL() {
int32_t width, height;
evas_gl_ = evas_gl_new(
evas_object_evas_get((Evas_Object*)SetupEvasWindow(x, y, w, h)));
evas_object_evas_get((Evas_Object*)SetupEvasWindow(width, height)));
if (!evas_gl_) {
FT_LOGE("SetupEvasWindow fail");
return false;
Expand Down Expand Up @@ -612,10 +617,10 @@ bool TizenRendererEvasGL::SetupEvasGL(int32_t x, int32_t y, int32_t w,
}

EVAS_GL_GLOBAL_GLES3_USE(g_evas_gl, gl_context_);
gl_surface_ = evas_gl_surface_create(evas_gl_, gl_config_, w, h);
gl_surface_ = evas_gl_surface_create(evas_gl_, gl_config_, width, height);

gl_resource_surface_ =
evas_gl_pbuffer_surface_create(evas_gl_, gl_config_, w, h, NULL);
evas_gl_pbuffer_surface_create(evas_gl_, gl_config_, width, height, NULL);

Evas_Native_Surface ns;
evas_gl_native_surface_get(evas_gl_, gl_surface_, &ns);
Expand All @@ -624,18 +629,22 @@ bool TizenRendererEvasGL::SetupEvasGL(int32_t x, int32_t y, int32_t w,
return true;
}

void* TizenRendererEvasGL::SetupEvasWindow(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (w == 0 || h == 0) {
FT_LOGE("Failed to create because of the wrong size");
return nullptr;
}
void* TizenRendererEvasGL::SetupEvasWindow(int32_t& width, int32_t& height) {
elm_config_accel_preference_set("hw:opengl");

evas_window_ = elm_win_add(NULL, NULL, ELM_WIN_BASIC);
auto* ecore_evas =
ecore_evas_ecore_evas_get(evas_object_evas_get(evas_window_));
int32_t x, y;
ecore_evas_screen_geometry_get(ecore_evas, &x, &y, &width, &height);
if (width == 0 || height == 0) {
FT_LOGE("Invalid screen size: %d x %d", width, height);
return nullptr;
}

elm_win_alpha_set(evas_window_, EINA_FALSE);
evas_object_move(evas_window_, x, y);
evas_object_resize(evas_window_, w, h);
evas_object_move(evas_window_, 0, 0);
evas_object_resize(evas_window_, width, height);
evas_object_raise(evas_window_);

Evas_Object* bg = elm_bg_add(evas_window_);
Expand All @@ -646,9 +655,9 @@ void* TizenRendererEvasGL::SetupEvasWindow(int32_t x, int32_t y, int32_t w,

graphics_adapter_ =
evas_object_image_filled_add(evas_object_evas_get(evas_window_));
evas_object_resize(graphics_adapter_, w, h);
evas_object_move(graphics_adapter_, x, y);
evas_object_image_size_set(graphics_adapter_, w, h);
evas_object_resize(graphics_adapter_, width, height);
evas_object_move(graphics_adapter_, 0, 0);
evas_object_image_size_set(graphics_adapter_, width, height);
evas_object_image_alpha_set(graphics_adapter_, EINA_TRUE);
elm_win_resize_object_add(evas_window_, graphics_adapter_);

Expand Down
10 changes: 5 additions & 5 deletions shell/platform/tizen/tizen_renderer_evas_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

class TizenRendererEvasGL : public TizenRenderer {
public:
explicit TizenRendererEvasGL(TizenRenderer::Delegate& delegate, int32_t x,
int32_t y, int32_t w, int32_t h);
explicit TizenRendererEvasGL(TizenRenderer::Delegate& delegate);
virtual ~TizenRendererEvasGL();

bool OnMakeCurrent() override;
Expand All @@ -26,6 +25,7 @@ class TizenRendererEvasGL : public TizenRenderer {
void* OnProcResolver(const char* name) override;

TizenWindowGeometry GetGeometry() override;
int32_t GetDpi() override;
uintptr_t GetWindowId() override;

void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
Expand All @@ -37,12 +37,12 @@ class TizenRendererEvasGL : public TizenRenderer {
private:
void ClearColor(float r, float g, float b, float a);

bool InitializeRenderer(int32_t x, int32_t y, int32_t w, int32_t h);
bool InitializeRenderer();
void Show();
void DestroyRenderer();

bool SetupEvasGL(int32_t x, int32_t y, int32_t w, int32_t h);
void* SetupEvasWindow(int32_t x, int32_t y, int32_t w, int32_t h);
bool SetupEvasGL();
void* SetupEvasWindow(int32_t& width, int32_t& height);
void DestroyEvasGL();
void DestroyEvasWindow();

Expand Down