|
| 1 | +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#include "tizen_native_window.h" |
| 6 | + |
| 7 | +#include "flutter/shell/platform/tizen/logger.h" |
| 8 | + |
| 9 | +class TizenWl2Display { |
| 10 | + public: |
| 11 | + TizenWl2Display() { |
| 12 | + if (!ecore_wl2_init()) { |
| 13 | + LoggerE("Could not initialize ecore_wl2"); |
| 14 | + return; |
| 15 | + } |
| 16 | + // ecore_wl2 DISPLAY |
| 17 | + wl2_display_ = ecore_wl2_display_connect(nullptr); |
| 18 | + if (wl2_display_ == nullptr) { |
| 19 | + LoggerE("Display not found"); |
| 20 | + return; |
| 21 | + } |
| 22 | + ecore_wl2_sync(); |
| 23 | + } |
| 24 | + |
| 25 | + ~TizenWl2Display() { |
| 26 | + if (wl2_display_) { |
| 27 | + ecore_wl2_display_destroy(wl2_display_); |
| 28 | + wl2_display_ = nullptr; |
| 29 | + } |
| 30 | + ecore_wl2_shutdown(); |
| 31 | + } |
| 32 | + Ecore_Wl2_Display* GetHandle() { return wl2_display_; } |
| 33 | + |
| 34 | + private: |
| 35 | + Ecore_Wl2_Display* wl2_display_{nullptr}; |
| 36 | +}; |
| 37 | +TizenWl2Display g_tizen_wl2_display; |
| 38 | + |
| 39 | +TizenNativeEGLWindow::TizenNativeEGLWindow( |
| 40 | + TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) { |
| 41 | + egl_window_ = |
| 42 | + ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h); |
| 43 | + |
| 44 | + egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get( |
| 45 | + g_tizen_wl2_display.GetHandle())); |
| 46 | + if (egl_display_ == EGL_NO_DISPLAY) { |
| 47 | + LoggerE("Could not access EGL display"); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + EGLint major_version; |
| 52 | + EGLint minor_version; |
| 53 | + if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) { |
| 54 | + LoggerE("Could not initialize EGL display"); |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + LoggerD("eglInitialized: %d.%d", major_version, minor_version); |
| 59 | + |
| 60 | + if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) { |
| 61 | + LoggerE("Could not bind API"); |
| 62 | + return; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +TizenNativeEGLWindow::~TizenNativeEGLWindow() { |
| 67 | + if (egl_window_) { |
| 68 | + ecore_wl2_egl_window_destroy(egl_window_); |
| 69 | + egl_window_ = nullptr; |
| 70 | + } |
| 71 | + if (egl_display_ != EGL_NO_CONTEXT) { |
| 72 | + eglTerminate(egl_display_); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w, |
| 77 | + int32_t h) { |
| 78 | + if (g_tizen_wl2_display.GetHandle() == nullptr) { |
| 79 | + LoggerE("Faild to get display handle"); |
| 80 | + return; |
| 81 | + } |
| 82 | + if (w == 0 || h == 0) { |
| 83 | + LoggerE("Failed to create because of the wrong size"); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + wl2_window_ = ecore_wl2_window_new(g_tizen_wl2_display.GetHandle(), nullptr, |
| 88 | + x, y, w, h); |
| 89 | + |
| 90 | + ecore_wl2_window_type_set(wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL); |
| 91 | + ecore_wl2_window_alpha_set(wl2_window_, EINA_FALSE); |
| 92 | + ecore_wl2_window_aux_hint_add(wl2_window_, 0, "wm.policy.win.user.geometry", |
| 93 | + "1"); |
| 94 | + ecore_wl2_window_show(wl2_window_); |
| 95 | + |
| 96 | + tizen_native_egl_window_ = std::make_unique<TizenNativeEGLWindow>(this, w, h); |
| 97 | + is_valid_ = true; |
| 98 | +} |
| 99 | + |
| 100 | +TizenNativeWindow::~TizenNativeWindow() { |
| 101 | + if (wl2_window_) { |
| 102 | + ecore_wl2_window_free(wl2_window_); |
| 103 | + wl2_window_ = nullptr; |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() { |
| 108 | + TizenNativeWindowGeometry result; |
| 109 | + ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w, |
| 110 | + &result.h); |
| 111 | + return result; |
| 112 | +} |
0 commit comments