egl_dri2: Add support for Tizen
authorXuelian <xuelian.bai@samsung.com>
Wed, 20 Nov 2019 09:38:53 +0000 (17:38 +0800)
committerXuelian Bai <xuelian.bai@samsung.com>
Thu, 18 Jan 2024 01:29:03 +0000 (09:29 +0800)
Re-implement _eglLog based on dlog
Add build support for Tizen platform.
Added missed dri2_fini_surface() at tizen_destroy_surface().

Add platform_tizen.c that supports _EGL_PLATFORM_TIZEN. It works with libtpl-egl
(Tizen Porting Layer for egl), libtbm(Tizen Buffer Manager) where back buffers
of windows are backed by GEM objects.

In Tizen a native window has a queue (tbm_surface_queue) of back buffers
allocated by the WL_TBM(wayland client case, WL_TBM is abbreviation of
wayland-tbm protocol) or gbm ( tizen has implements gbm with tbm) or tbm
through tbm_backend.

For each frame, EGL needs to

    dequeue the next back buffer
    render to the buffer
    enqueue the buffer

After enqueuing, the buffer is no longer valid to EGL.

It supports DRI image loader extension, DRI dri2 loader extension and DRI swrast
loader extension.

It supports EGL_NATIVE_SURFACE_TIZEN  target type for eglCreateImageKHR.
(https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt)

BindWaylandDisplayWL / UnbindWaylandDisplayWL / QueryWaylandBufferWL are
overloaded because tizen platform has its own instead of WL_DRM.

Referenced documents:
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
https://wiki.tizen.org/wiki/TBM

egllog: add unlock call preventing the deadlock
Implement dlog for mesa main

_eglLog is a basic log function for mesa, re-implement
it based on dlog here for debug purpose.
Log level can be changed by setting environment variable
EGL_LOG_LEVEL.

Log API for mesa main module are all implemented in file
src/mesa/main/error.c, re-implement them based on dlog
for debug convenience

add configuration of building and packaging for rpi3 ( vc4 gpu driver )
add udev rule files for rpi3 (vc4 drm device)

Mered old commit:
commit f5205524bf20b63c2efe20e99429c9d55543b711
Author: Zhaowei Yuan <zhaowei.yuan@samsung.com>
Date:   Mon May 6 13:52:32 2019 +0800

commit 704bb72470589ede7246af8c6b0a9210df42f1c7
Author: Xuelian <xuelian.bai@samsung.com>
Date:   Wed Nov 20 19:08:41 2019 +0800

commit 247adc92138ad456f5db39acfe5be69748973df3
Author: Joonbum Ko <joonbum.ko@samsung.com>
Date:   Wed Apr 29 20:01:56 2020 +0900

Change-Id: I83348c1cff5f0f59f79bc3c016623adf6fbba32b
Signed-off-by: Xuelian <xuelian.bai@samsung.com>
16 files changed:
COPYING [new file with mode: 0644]
meson.build
meson_options.txt
packaging/99-GPU-Acceleration.rules [new file with mode: 0644]
packaging/mesa.manifest [new file with mode: 0644]
packaging/mesa.spec [new file with mode: 0644]
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_tizen.c [new file with mode: 0755]
src/egl/main/eglapi.c
src/egl/main/egldisplay.c
src/egl/main/egldisplay.h
src/egl/main/egllog.c
src/egl/meson.build
src/gallium/winsys/v3d/drm/meson.build
src/mesa/main/errors.c

diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..b50f59e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,280 @@
+Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
+
+
+Copyright (c) 2015-2017 The Khronos Group Inc. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
+
+
+
+Copyright notice for SGI FREE SOFTWARE LICENSE B files:
+
+The following file is licensed under SGI FREE SOFTWARE LICENSE B, Version 2.0
+ - include/GLES/gl.h
+ - include/GLES/glext.h
+ - include/GLES/glplatform.h
+ - include/GLES2/gl2platform.h
+ - include/GLES3/gl3ext.h
+ - include/GLES3/gl3platform.h
+
+SGI FREE SOFTWARE LICENSE B
+(Version 2.0, Sept. 18, 2008)
+Copyright (C) [dates of first publication] Silicon Graphics, Inc. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+The above copyright notice including the dates of first publication and either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be included in all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+Except as contained in this notice, the name of Silicon Graphics, Inc. shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Silicon Graphics, Inc
+
+
+
+
+Copyright (c) 2008, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
index 2902c10..39c9521 100644 (file)
@@ -338,7 +338,7 @@ endforeach
 _platforms = get_option('platforms')
 if _platforms.contains('auto')
   if system_has_kms_drm
-    _platforms = ['x11', 'wayland']
+    _platforms = ['x11', 'wayland', 'tizen']
   elif ['darwin', 'cygwin'].contains(host_machine.system())
     _platforms = ['x11']
   elif ['haiku'].contains(host_machine.system())
@@ -354,6 +354,7 @@ endif
 with_platform_android = _platforms.contains('android')
 with_platform_x11 = _platforms.contains('x11')
 with_platform_wayland = _platforms.contains('wayland')
+with_platform_tizen = _platforms.contains('tizen')
 with_platform_haiku = _platforms.contains('haiku')
 with_platform_windows = _platforms.contains('windows')
 
@@ -1966,6 +1967,18 @@ if with_platform_wayland
   pre_args += '-DWL_HIDE_DEPRECATED'
 endif
 
+if with_platform_tizen
+  dep_tpl_egl = dependency('tpl-egl')
+  dep_libtbm = dependency('libtbm')
+  dep_libtdm = dependency('libtdm')
+  dep_wayland_client = dependency('wayland-client')
+  dep_dlog = dependency('dlog')
+  dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
+  dep_wayland_client = dependency('wayland-client', version : '>=1.11')
+  dep_wayland_server = dependency('wayland-server', version : '>=1.11')
+  pre_args += ['-DHAVE_TIZEN_PLATFORM']
+endif
+
 dep_x11 = null_dep
 dep_xext = null_dep
 dep_xfixes = null_dep
index e885ba6..e57b676 100644 (file)
@@ -6,7 +6,7 @@ option(
   type : 'array',
   value : ['auto'],
   choices : [
-    'auto', 'x11', 'wayland', 'haiku', 'android', 'windows',
+    'auto', 'x11', 'wayland', 'haiku', 'android', 'windows', 'tizen',
   ],
   description : 'window systems to support. If this is set to `auto`, all ' +
                 'platforms applicable will be enabled.'
diff --git a/packaging/99-GPU-Acceleration.rules b/packaging/99-GPU-Acceleration.rules
new file mode 100644 (file)
index 0000000..7ae48a5
--- /dev/null
@@ -0,0 +1 @@
+KERNEL=="vc4*", MODE="0666", GROUP="display", SECLABEL{smack}="*"
diff --git a/packaging/mesa.manifest b/packaging/mesa.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/mesa.spec b/packaging/mesa.spec
new file mode 100644 (file)
index 0000000..eff7a36
--- /dev/null
@@ -0,0 +1,99 @@
+Name:           mesa
+Version:        19.3.0
+Release:        0
+License:        MIT and Apache-2.0 and SGI Free Software License B v2.0 and BSD-3-Clause
+Summary:        System for rendering interactive 3-D graphics
+Url:            http://www.mesa3d.org
+Group:          Graphics & UI Framework/Hardware Adaptation
+Source:         %{name}-%{version}.tar.gz
+Source1001:     %{name}.manifest
+Source1002:     99-GPU-Acceleration.rules
+
+BuildRequires:  bison
+BuildRequires:  flex
+BuildRequires:  pkgconfig
+BuildRequires:  pkgconfig(expat)
+BuildRequires:  pkgconfig(libdrm) >= 2.4.75
+BuildRequires:  pkgconfig(libudev) > 150
+BuildRequires:  pkgconfig(wayland-client)
+BuildRequires:  pkgconfig(wayland-server)
+BuildRequires:  pkgconfig(wayland-protocols)
+BuildRequires:  pkgconfig(tpl-egl)
+BuildRequires:  pkgconfig(libtbm)
+BuildRequires:  pkgconfig(libtdm)
+BuildRequires:  pkgconfig(zlib)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  meson
+BuildRequires:  python3
+BuildRequires:  python3-mako
+%ifarch x86_64 %ix86
+BuildRequires:  pkgconfig(libdrm_intel) >= 2.4.24
+%endif
+
+%if "%{_with_emulator}" == "1"
+ExclusiveArch:
+%endif
+
+%description
+Mesa is a 3-D graphics library with an API which is very similar to
+that of OpenGL.* To the extent that Mesa utilizes the OpenGL command
+syntax or state machine, it is being used with authorization from
+Silicon Graphics, Inc.(SGI). However, the author does not possess an
+OpenGL license from SGI, and makes no claim that Mesa is in any way a
+compatible replacement for OpenGL or associated with SGI. Those who
+want a licensed implementation of OpenGL should contact a licensed
+vendor.
+
+Please do not refer to the library as MesaGL (for legal reasons). It's
+just Mesa or The Mesa 3-D graphics library.
+
+* OpenGL is a trademark of Silicon Graphics Incorporated.
+
+%prep
+%setup -q -n %{name}-%{version}
+cp %{SOURCE1001} .
+cp %{SOURCE1002} .
+
+%build
+%{?asan:/usr/bin/gcc-unforce-options}
+mkdir build
+meson --prefix %{_prefix} build/ \
+               -Dlibdir=%{_libdir} \
+               -Dgallium-va=false \
+               -Dgallium-vdpau=false \
+               -Dgallium-xa=false \
+               -Dgallium-xvmc=false \
+               -Dglx=disabled \
+               -Ddri3=false \
+               -Dgbm=true \
+               -Dplatforms="tizen" \
+%ifarch %ix86 x86_64
+               -Dgallium-drivers="i915,swrast" \
+               -Ddri-drivers="" \
+               -Dvulkan-drivers=""
+%else
+               -Dgallium-drivers="vc4,swrast"
+%endif
+ninja -C build/
+
+%install
+DESTDIR=%{buildroot} ninja -C build/ install
+mkdir -p %{buildroot}%{_libdir}/driver
+cp -a  %{buildroot}%{_libdir}/libEGL* %{buildroot}%{_libdir}/driver
+cp -a  %{buildroot}%{_libdir}/libGLES* %{buildroot}%{_libdir}/driver
+
+mkdir -p %{buildroot}/etc/udev/rules.d
+cp 99-GPU-Acceleration.rules %{buildroot}/etc/udev/rules.d
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%define _unpackaged_files_terminate_build 0
+%manifest %{name}.manifest
+%defattr(-,root,root)
+%license COPYING
+%{_libdir}/libglapi*
+%{_libdir}/driver/*
+%{_libdir}/dri/*
+/etc/udev/rules.d/99-GPU-Acceleration.rules
index e0dd739..c791ee6 100644 (file)
@@ -1165,6 +1165,12 @@ dri2_initialize(_EGLDisplay *disp)
    case _EGL_PLATFORM_ANDROID:
       ret = dri2_initialize_android(disp);
       break;
+
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+      ret = dri2_initialize_tizen(disp);
+      break;
+#endif
    default:
       unreachable("Callers ensure we cannot get here.");
       return EGL_FALSE;
@@ -1248,6 +1254,12 @@ dri2_display_destroy(_EGLDisplay *disp)
    case _EGL_PLATFORM_WAYLAND:
       dri2_teardown_wayland(dri2_dpy);
       break;
+
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+      dri2_teardown_tizen(disp);
+      break;
+#endif
    default:
       /* TODO: add teardown for other platforms */
       break;
@@ -3344,6 +3356,94 @@ dri2_query_wayland_buffer_wl(_EGLDisplay *disp,
 }
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDisplay *disp,
+                              struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+     return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+     return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDisplay *disp,
+                                struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+     return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+     return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDisplay *disp,
+                              struct wl_resource *buffer_resource,
+                              EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+     return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+     return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+                                            (tpl_handle_t)buffer_resource,
+                                            &width, &height, &tbm_format);
+   if (res != TPL_ERROR_NONE)
+     return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+      switch (tbm_format) {
+      case TBM_FORMAT_ARGB8888:
+         *value = EGL_TEXTURE_RGBA;
+         return EGL_TRUE;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+      case TBM_FORMAT_XRGB8888:
+      case TBM_FORMAT_RGB565:
+#pragma GCC diagnostic pop
+         *value = EGL_TEXTURE_RGB;
+         return EGL_TRUE;
+      default:
+         break;
+      }
+      break;
+   case EGL_WIDTH:
+      *value = width;
+      return EGL_TRUE;
+   case EGL_HEIGHT:
+      *value = height;
+      return EGL_TRUE;
+   default:
+      break;
+   }
+
+   return EGL_FALSE;
+}
+#endif
+
 static void
 dri2_egl_ref_sync(struct dri2_egl_sync *sync)
 {
@@ -3756,6 +3856,11 @@ const _EGLDriver _eglDriver = {
    .UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl,
    .QueryWaylandBufferWL = dri2_query_wayland_buffer_wl,
 #endif
+#ifdef HAVE_TIZEN_PLATFORM
+   .BindWaylandDisplayWL = tizen_bind_wayland_display_wl,
+   .UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl,
+   .QueryWaylandBufferWL = tizen_query_wayland_buffer_wl,
+ #endif
    .GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium,
    .GetMscRateANGLE = dri2_get_msc_rate_angle,
    .CreateSyncKHR = dri2_create_sync,
index 5edd810..a4072eb 100644 (file)
@@ -80,6 +80,14 @@ struct zwp_linux_dmabuf_feedback_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include <tpl.h>
+#include <tbm_bufmgr.h>
+#include <tbm_drm_helper.h>
+#include <tbm_surface.h>
+#include <tbm_surface_internal.h>
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "eglcurrent.h"
@@ -307,7 +315,6 @@ struct dri2_egl_display {
    bool authenticated;
    uint32_t capabilities;
    char *device_name;
-   bool is_render_node;
 #endif
 
 #ifdef HAVE_ANDROID_PLATFORM
@@ -315,6 +322,12 @@ struct dri2_egl_display {
    /* gralloc vendor usage bit for front rendering */
    uint32_t front_rendering_usage;
 #endif
+
+   bool is_render_node;
+   bool is_different_gpu;
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t            *tpl_display;
+#endif
 };
 
 struct dri2_egl_context {
@@ -361,6 +374,26 @@ struct dri2_egl_surface {
    /* EGL-owned buffers */
    __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void          *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format     tbm_format;
+   __DRIimage    *dri_image_back;
+   __DRIimage    *dri_image_front;
+
+   /* Used to record all the tbm_surface created by tpl_surface and their ages.
+    * Usually Tizen uses at most triple buffers in tpl_surface (tbm_surface_queue)
+    * so hardcode the number of color_buffers to 3.
+    */
+   struct {
+      tbm_surface_h tbm_surface;
+      int age;
+   } color_buffers[3], *back;
+
+   int buffer_count;
+#endif
+
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
    struct {
 #ifdef HAVE_WAYLAND_PLATFORM
@@ -611,6 +644,19 @@ dri2_teardown_device(struct dri2_egl_display *dri2_dpy)
 { /* noop */
 }
 
+#ifdef HAVE_TIZEN_PLATFORM
+EGLBoolean
+dri2_initialize_tizen(_EGLDisplay *disp);
+void
+dri2_teardown_tizen(_EGLDisplay *disp);
+#else
+static inline EGLBoolean
+dri2_initialize_tizen(_EGLDisplay *disp)
+{
+        return _eglError(EGL_NOT_INITIALIZED, "tizen platform not built");
+}
+#endif
+
 void
 dri2_flush_drawable_for_swapbuffers_flags(
    _EGLDisplay *disp, _EGLSurface *draw,
diff --git a/src/egl/drivers/dri2/platform_tizen.c b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100755 (executable)
index 0000000..03b0d92
--- /dev/null
@@ -0,0 +1,1539 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright Â© 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gwan-gyeong Mun <kk.moon@samsung.com>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <xf86drm.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "egl_dri2.h"
+#include "loader.h"
+
+#include <wayland-client.h>
+#include <drm-uapi/drm_fourcc.h>
+
+int tbm_bufmgr_fd = -1;
+
+static void tizen_free_local_buffers(struct dri2_egl_surface *dri2_surf);
+
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return DRM_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA8888: return DRM_FORMAT_ARGB8888;
+   case TBM_FORMAT_RGBA8888: return DRM_FORMAT_ABGR8888;
+   case TBM_FORMAT_ARGB8888: return DRM_FORMAT_ARGB8888;
+   case TBM_FORMAT_ABGR8888: return DRM_FORMAT_ABGR8888;
+   case TBM_FORMAT_RGBX8888: return DRM_FORMAT_XBGR8888;
+   case TBM_FORMAT_XRGB8888: return DRM_FORMAT_XRGB8888;
+   default:
+      _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+   }
+   return -1;
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return DRM_FORMAT_NV12;
+   case TBM_FORMAT_NV21:   return DRM_FORMAT_NV12;
+   case TBM_FORMAT_YUV420: return DRM_FORMAT_YUV420;
+   case TBM_FORMAT_YVU420: return DRM_FORMAT_YVU420;
+   default:
+      _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", format);
+   }
+   return -1;
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+     return false;
+   else
+     return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA8888: return __DRI_IMAGE_FORMAT_ARGB8888;
+   case TBM_FORMAT_RGBA8888: return __DRI_IMAGE_FORMAT_ABGR8888;
+   case TBM_FORMAT_ARGB8888: return __DRI_IMAGE_FORMAT_ARGB8888;
+   case TBM_FORMAT_ABGR8888: return __DRI_IMAGE_FORMAT_ABGR8888;
+   case TBM_FORMAT_RGBX8888: return __DRI_IMAGE_FORMAT_XBGR8888;
+   case TBM_FORMAT_XRGB8888: return __DRI_IMAGE_FORMAT_XRGB8888;
+   default:
+      _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+   }
+   return -1;
+}
+
+static int get_format_bpp(tbm_format format)
+{
+   int bpp;
+
+   switch (format) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+   case TBM_FORMAT_BGRA8888:
+   case TBM_FORMAT_RGBA8888:
+   case TBM_FORMAT_RGBX8888:
+   case TBM_FORMAT_ARGB8888:
+#pragma GCC diagnostic pop
+   case TBM_FORMAT_XRGB8888:
+      bpp = 4;
+      break;
+   case TBM_FORMAT_RGB565:
+      bpp = 2;
+      break;
+   default:
+      bpp = 0;
+      break;
+   }
+
+   return bpp;
+}
+
+static int get_pitch(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, &surf_info) != TBM_SURFACE_ERROR_NONE) {
+     return 0;
+   }
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+                                 TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+     return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, &width, &height);
+   if (dri2_surf->base.Width != width ||
+       dri2_surf->base.Height != height) {
+      dri2_surf->base.Width = width;
+      dri2_surf->base.Height = height;
+      tizen_free_local_buffers(dri2_surf);
+   }
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+    *   and update back buffer * for updating buffer's age in swap_buffers.
+    */
+   EGLBoolean updated = EGL_FALSE;
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+      if (!dri2_surf->color_buffers[i].tbm_surface) {
+         dri2_surf->color_buffers[i].tbm_surface = dri2_surf->tbm_surface;
+         dri2_surf->color_buffers[i].age = 0;
+      }
+      if (dri2_surf->color_buffers[i].tbm_surface == dri2_surf->tbm_surface) {
+         dri2_surf->back = &dri2_surf->color_buffers[i];
+         updated = EGL_TRUE;
+         break;
+      }
+   }
+
+   if (!updated) {
+      /* In case of all the buffers were recreated , reset the color_buffers */
+      for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+         dri2_surf->color_buffers[i].tbm_surface = NULL;
+         dri2_surf->color_buffers[i].age = 0;
+      }
+      dri2_surf->color_buffers[0].tbm_surface = dri2_surf->tbm_surface;
+      dri2_surf->back = &dri2_surf->color_buffers[0];
+   }
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
+                                        struct dri2_egl_surface *dri2_surf,
+                                        const EGLint *rects,
+                                        EGLint n_rects)
+{
+   tpl_result_t ret;
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   /* To avoid blocking other EGL calls, release the display mutex before
+    * we enter tizen_window_enqueue_buffer() and re-acquire the mutex upon
+    * return.
+    */
+   mtx_unlock(&disp->Mutex);
+
+   if (n_rects < 1 || rects == NULL) {
+     /* if there is no damage, call the normal API tpl_surface_enqueue_buffer */
+     ret = tpl_surface_enqueue_buffer(dri2_surf->tpl_surface,
+                                      dri2_surf->tbm_surface);
+   } else {
+     /* if there are rectangles of damage region,
+        call the API tpl_surface_enqueue_buffer_with_damage() */
+     ret = tpl_surface_enqueue_buffer_with_damage(dri2_surf->tpl_surface,
+                                                  dri2_surf->tbm_surface,
+                                                  n_rects, rects);
+   }
+
+   if (ret != TPL_ERROR_NONE) {
+      _eglLog(_EGL_DEBUG, "%s : %d :tpl_surface_enqueue fail", __func__, __LINE__);
+   }
+
+   tbm_surface_internal_unref(dri2_surf->tbm_surface);
+   dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
+
+   mtx_lock(&disp->Mutex);
+
+   if (dri2_surf->dri_image_back) {
+      dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+      dri2_surf->dri_image_back = NULL;
+   }
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
+{
+   return tizen_window_enqueue_buffer_with_damage(disp, dri2_surf, NULL, 0);
+}
+
+static void
+tizen_window_cancel_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
+{
+   tizen_window_enqueue_buffer(disp, dri2_surf);
+}
+
+static __DRIbuffer *
+tizen_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+                         unsigned int att, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+      dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
+      return NULL;
+
+   if (!dri2_surf->local_buffers[att]) {
+      dri2_surf->local_buffers[att] =
+         dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen_render_gpu, att, format,
+               dri2_surf->base.Width, dri2_surf->base.Height);
+   }
+
+   return dri2_surf->local_buffers[att];
+}
+
+static void
+tizen_free_local_buffers(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+      dri2_egl_display(dri2_surf->base.Resource.Display);
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
+      if (dri2_surf->local_buffers[i]) {
+         dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen_render_gpu,
+               dri2_surf->local_buffers[i]);
+         dri2_surf->local_buffers[i] = NULL;
+      }
+   }
+}
+
+static _EGLSurface *
+tizen_create_surface(_EGLDisplay *disp, EGLint type,
+                     _EGLConfig *conf, void *native_window,
+                     const EGLint *attrib_list)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
+   struct dri2_egl_surface *dri2_surf;
+   const __DRIconfig *config;
+   tpl_surface_type_t tpl_surf_type = TPL_SURFACE_ERROR;
+   tpl_result_t ret = TPL_ERROR_INVALID_PARAMETER;
+
+   dri2_surf = calloc(1, sizeof *dri2_surf);
+   if (!dri2_surf) {
+      _eglError(EGL_BAD_ALLOC, "tizen_create_surface");
+      return NULL;
+   }
+
+   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
+                          false, native_window))
+      goto cleanup_surface;
+
+   config = dri2_get_dri_config(dri2_conf, type,
+                                dri2_surf->base.GLColorspace);
+   if (!config)
+      goto cleanup_surface;
+
+   if (type == EGL_WINDOW_BIT) {
+      unsigned int alpha, depth;
+
+      if (!native_window) {
+         _eglError(EGL_BAD_NATIVE_WINDOW, "tizen_create_surface needs vaild native window");
+         goto cleanup_surface;
+      }
+      dri2_surf->native_win = native_window;
+
+      dri2_dpy->core->getConfigAttrib(config, __DRI_ATTRIB_DEPTH_SIZE, &depth);
+      dri2_dpy->core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SIZE, &alpha);
+
+      ret = tpl_display_get_native_window_info(dri2_dpy->tpl_display,
+                                               (tpl_handle_t)native_window,
+                                               &dri2_surf->base.Width,
+                                               &dri2_surf->base.Height,
+                                               &dri2_surf->tbm_format,
+                                               depth, alpha);
+
+      if (ret != TPL_ERROR_NONE || dri2_surf->tbm_format == 0) {
+        _eglError(EGL_BAD_NATIVE_WINDOW, "tizen_create_surface fails on tpl_display_get_native_window_info()");
+        goto cleanup_surface;
+      }
+
+      tpl_surf_type = TPL_SURFACE_TYPE_WINDOW;
+   } else if (type == EGL_PIXMAP_BIT) {
+
+      if (!native_window) {
+         _eglError(EGL_BAD_NATIVE_PIXMAP, "tizen_create_surface needs valid native pixmap");
+         goto cleanup_surface;
+      }
+      ret = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+                                               (tpl_handle_t)native_window,
+                                               &dri2_surf->base.Width,
+                                               &dri2_surf->base.Height,
+                                               &dri2_surf->tbm_format);
+
+      if (ret != TPL_ERROR_NONE || dri2_surf->tbm_format == 0) {
+        _eglError(EGL_BAD_NATIVE_PIXMAP, "tizen_create_surface fails on tpl_display_get_native_pixmap_info");
+        goto cleanup_surface;
+      }
+
+      tpl_surf_type = TPL_SURFACE_TYPE_PIXMAP;
+   } else {
+      _eglError(EGL_BAD_NATIVE_WINDOW, "tizen_create_surface does not support PBuffer");
+      goto cleanup_surface;
+   }
+
+   dri2_surf->tpl_surface = tpl_surface_create(dri2_dpy->tpl_display,
+                                               (tpl_handle_t)native_window,
+                                               tpl_surf_type,
+                                               dri2_surf->tbm_format);
+   if (!dri2_surf->tpl_surface)
+      goto cleanup_surface;
+
+   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf, dri2_surf)) {
+      _eglError(EGL_BAD_ALLOC, "createNewDrawable");
+       goto cleanup_tpl_surface;
+   }
+
+   return &dri2_surf->base;
+
+cleanup_tpl_surface:
+   tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
+cleanup_surface:
+   free(dri2_surf);
+
+   return NULL;
+}
+
+static _EGLSurface *
+tizen_create_window_surface(_EGLDisplay *disp,
+                            _EGLConfig *conf, void *native_window,
+                            const EGLint *attrib_list)
+{
+   return tizen_create_surface(disp, EGL_WINDOW_BIT, conf,
+                               native_window, attrib_list);
+}
+
+static _EGLSurface *
+tizen_create_pixmap_surface(_EGLDisplay *disp,
+                            _EGLConfig *conf, void *native_pixmap,
+                            const EGLint *attrib_list)
+{
+   return tizen_create_surface(disp, EGL_PIXMAP_BIT, conf,
+                               native_pixmap, attrib_list);
+}
+
+static _EGLSurface *
+tizen_create_pbuffer_surface(_EGLDisplay *disp,
+                             _EGLConfig *conf, const EGLint *attrib_list)
+{
+   return tizen_create_surface(disp, EGL_PBUFFER_BIT, conf,
+                               NULL, attrib_list);
+}
+
+static EGLBoolean
+tizen_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   tizen_free_local_buffers(dri2_surf);
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+      if (dri2_surf->tbm_surface)
+         tizen_window_cancel_buffer(disp, dri2_surf);
+   }
+
+   if (dri2_surf->dri_image_back) {
+      _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);
+      dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+      dri2_surf->dri_image_back = NULL;
+   }
+
+   if (dri2_surf->dri_image_front) {
+      _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);
+      dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
+      dri2_surf->dri_image_front = NULL;
+   }
+
+   dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
+
+   tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
+
+   dri2_fini_surface(surf);
+
+   free(dri2_surf);
+
+   return EGL_TRUE;
+}
+
+static int
+update_buffers(struct dri2_egl_surface *dri2_surf)
+{
+   if (dri2_surf->base.Type != EGL_WINDOW_BIT)
+      return 0;
+
+   /* try to dequeue the next back buffer */
+   if (!dri2_surf->tbm_surface && !tizen_window_dequeue_buffer(dri2_surf)) {
+      _eglLog(_EGL_WARNING, "Could not dequeue buffer from native window");
+      return -1;
+   }
+
+   return 0;
+}
+
+static int
+get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+      dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front)
+      return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+      /* According current EGL spec, front buffer rendering
+       * for window surface is not supported now.
+       * and mesa doesn't have the implementation of this case.
+       * Add warning message, but not treat it as error.
+       */
+      _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+      dri2_surf->dri_image_front =
+          dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu,
+                                       dri2_surf->base.Width,
+                                       dri2_surf->base.Height,
+                                       format,
+                                       0,
+                                       dri2_surf);
+      if (!dri2_surf->dri_image_front) {
+         _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+         return -1;
+      }
+   }
+
+   return 0;
+}
+
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+      dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+      return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+      if (!dri2_surf->tbm_surface) {
+         _eglLog(_EGL_WARNING, "Could not get native buffer");
+         return -1;
+      }
+
+      fd = get_native_buffer_fd(dri2_surf->tbm_surface);
+      if (fd < 0) {
+         _eglLog(_EGL_WARNING, "Could not get native buffer FD");
+         return -1;
+      }
+
+      if (tbm_surface_get_info(dri2_surf->tbm_surface, &surf_info) != TBM_SURFACE_ERROR_NONE) {
+         _eglLog(_EGL_WARNING, "Could not get pitch");
+         return -1;
+      }
+
+      pitch = surf_info.planes[0].stride;
+      fourcc = get_fourcc(dri2_surf->tbm_format);
+
+      if (fourcc == -1 || pitch == 0) {
+         _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
+                 fourcc, pitch);
+         return -1;
+      }
+
+      dri2_surf->base.Width = surf_info.width;
+      dri2_surf->base.Height = surf_info.height;
+
+      dri2_surf->dri_image_back =
+         dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen_render_gpu,
+                                             dri2_surf->base.Width,
+                                             dri2_surf->base.Height,
+                                             fourcc,
+                                             &fd,
+                                             1,
+                                             &pitch,
+                                             &offset,
+                                             dri2_surf);
+
+      if (!dri2_surf->dri_image_back) {
+         _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
+         return -1;
+      }
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+      /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically,
+       * the spec states that they have a back buffer but no front buffer, in
+       * contrast to pixmaps, which have a front buffer but no back buffer.
+       *
+       * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate
+       * from the spec, following the precedent of Mesa's EGL X11 platform. The
+       * X11 platform correctly assigns pbuffers to single-buffered configs, but
+       * assigns the pbuffer a front buffer instead of a back buffer.
+       *
+       * Pbuffers in the X11 platform mostly work today, so let's just copy its
+       * behavior instead of trying to fix (and hence potentially breaking) the
+       * world.
+       */
+      _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface");
+   }
+
+   return 0;
+}
+
+/* Some drivers will pass multiple bits in buffer_mask.
+ * For such case, will go through all the bits, and
+ * will not return error when unsupported buffer is requested, only
+ * return error when the allocation for supported buffer failed.
+ */
+static int
+tizen_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
+                        uint32_t *stamp, void *loaderPrivate,
+                        uint32_t buffer_mask, struct __DRIimageList *images)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+
+   images->image_mask = 0;
+   images->front = NULL;
+   images->back = NULL;
+
+   if (update_buffers(dri2_surf) < 0)
+      return 0;
+
+   if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
+      if (get_front_bo(dri2_surf, format) < 0)
+         return 0;
+
+      if (dri2_surf->dri_image_front) {
+         images->front = dri2_surf->dri_image_front;
+         images->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
+      }
+   }
+
+   if (buffer_mask & __DRI_IMAGE_BUFFER_BACK) {
+      if (get_back_bo(dri2_surf, format) < 0)
+         return 0;
+
+      if (dri2_surf->dri_image_back) {
+         images->back = dri2_surf->dri_image_back;
+         images->image_mask |= __DRI_IMAGE_BUFFER_BACK;
+      }
+   }
+
+   return 1;
+}
+
+static EGLint
+tizen_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surface)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface);
+
+   if (update_buffers(dri2_surf) < 0) {
+      _eglError(EGL_BAD_ALLOC, "tizen_query_buffer_age");
+      return 0;
+   }
+
+   return dri2_surf->back->age;
+}
+
+static EGLBoolean
+tizen_swap_buffers_with_damage(_EGLDisplay *disp,
+                               _EGLSurface *draw, const EGLint *rects,
+                               EGLint n_rects)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
+
+   if (dri2_surf->base.Type != EGL_WINDOW_BIT)
+      return EGL_TRUE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+      if (dri2_surf->color_buffers[i].age > 0)
+         dri2_surf->color_buffers[i].age++;
+   }
+
+   /* Make sure we have a back buffer in case we're swapping without
+    * ever rendering. */
+   if (get_back_bo(dri2_surf, 0) < 0) {
+      _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");
+      return EGL_FALSE;
+   }
+
+   dri2_surf->back->age = 1;
+
+   /* The buffer to enqueue should be the buffer in which
+    * the gpu drawing job is completed or after flush.
+    * If this is not guaranteed, it can lead to incorrect output.
+    */
+   if (dri2_dpy->swrast) {
+      dri2_dpy->core->swapBuffers(dri2_surf->dri_drawable);
+   } else {
+      dri2_flush_drawable_for_swapbuffers(disp, draw);
+      dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
+   }
+
+   if (dri2_surf->tbm_surface)
+      tizen_window_enqueue_buffer_with_damage(disp, dri2_surf, rects, n_rects);
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
+{
+   return tizen_swap_buffers_with_damage (disp, draw, NULL, 0);
+}
+
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+                                     tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, &surf_info) != TBM_SURFACE_ERROR_NONE) {
+     _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+     return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+      tbm_bo_handle bo_handle;
+      int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+      bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+      if (bo[i] == NULL) {
+        _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+        return NULL;
+      }
+      bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+      bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+     _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+     return NULL;
+   }
+
+   switch (fourcc) {
+   case DRM_FORMAT_NV12:
+      fds[0] = bo_fd[0];
+      fds[1] = bo_fd[1];
+      offsets[0] = surf_info.planes[0].offset;
+      offsets[1] = surf_info.planes[1].offset;
+      pitches[0] = surf_info.planes[0].stride;
+      pitches[1] = surf_info.planes[1].stride;
+      break;
+   case DRM_FORMAT_YUV420:
+      fds[0] = bo_fd[0];
+      fds[1] = bo_fd[1];
+      fds[2] = bo_fd[2];
+      offsets[0] = surf_info.planes[0].offset;
+      offsets[1] = surf_info.planes[1].offset;
+      offsets[2] = surf_info.planes[2].offset;
+      pitches[0] = surf_info.planes[0].stride;
+      pitches[1] = surf_info.planes[1].stride;
+      pitches[2] = surf_info.planes[2].stride;
+      break;
+   case DRM_FORMAT_YVU420:
+      fds[0] = bo_fd[0];
+      fds[1] = bo_fd[2];
+      fds[2] = bo_fd[1];
+      offsets[0] = surf_info.planes[0].offset;
+      offsets[1] = surf_info.planes[2].offset;
+      offsets[2] = surf_info.planes[1].offset;
+      pitches[0] = surf_info.planes[0].stride;
+      pitches[1] = surf_info.planes[2].stride;
+      pitches[2] = surf_info.planes[1].stride;
+      break;
+    default:
+      _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+      return NULL;
+   }
+
+   if (num_planes == 2) {
+      const EGLint attr_list_2plane[] = {
+         EGL_WIDTH, surf_info.width,
+         EGL_HEIGHT, surf_info.height,
+         EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+         EGL_DMA_BUF_PLANE0_FD_EXT, fds[0],
+         EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0],
+         EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0],
+         EGL_DMA_BUF_PLANE1_FD_EXT, fds[1],
+         EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1],
+         EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1],
+         EGL_NONE, 0
+      };
+      return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_2plane);
+   } else if (num_planes == 3) {
+      const EGLint attr_list_3plane[] = {
+         EGL_WIDTH, surf_info.width,
+         EGL_HEIGHT, surf_info.height,
+         EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+         EGL_DMA_BUF_PLANE0_FD_EXT, fds[0],
+         EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0],
+         EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0],
+         EGL_DMA_BUF_PLANE1_FD_EXT, fds[1],
+         EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1],
+         EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1],
+         EGL_DMA_BUF_PLANE2_FD_EXT, fds[2],
+         EGL_DMA_BUF_PLANE2_PITCH_EXT, pitches[2],
+         EGL_DMA_BUF_PLANE2_OFFSET_EXT, offsets[2],
+         EGL_NONE, 0
+      };
+      return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_3plane);
+   } else {
+      _eglLog(_EGL_WARNING, "Unsupported yuv planes");
+      return NULL;
+   }
+}
+
+static _EGLImage *
+tizen_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
+                                 tbm_surface_h tbm_surface , int fd)
+{
+   unsigned int pitch;
+   tbm_surface_info_s surf_info;
+   //unsigned int flags = tbm_bo_get_flags(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   if (is_yuv_format(tbm_surface_get_format(tbm_surface)))
+      return tizen_create_image_from_prime_fd_yuv(disp, ctx, tbm_surface);
+
+   const int fourcc = get_fourcc(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+
+   if (tbm_surface_get_info(tbm_surface, &surf_info) != TBM_SURFACE_ERROR_NONE) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+   pitch = surf_info.planes[0].stride;
+
+   if (pitch == 0) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+
+   //TODO: get modifier from vendor driver/TBM
+   EGLint attr_list[50];
+   int atti = 0;
+
+   attr_list[atti++] = EGL_WIDTH;
+   attr_list[atti++] = surf_info.width;
+   attr_list[atti++] = EGL_HEIGHT;
+   attr_list[atti++] = surf_info.height;
+   attr_list[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
+   attr_list[atti++] = fourcc;
+   attr_list[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT;
+   attr_list[atti++] = fd;
+   attr_list[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
+   attr_list[atti++] = pitch;
+   attr_list[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
+   attr_list[atti++] = 0;
+
+   //TODO: v3d don't support this, need to check
+   /*if (flags == TBM_BO_TILED) {
+               attr_list[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
+               attr_list[atti++] = DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED & 0xFFFFFFFF;
+               attr_list[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
+               attr_list[atti++] = DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED >> 32;
+   }*/
+   attr_list[atti++] = EGL_NONE;
+   attr_list[atti++] = 0;
+
+   return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list);
+}
+
+static _EGLImage *
+tizen_create_image_from_name(_EGLDisplay *disp, _EGLContext *ctx,
+                             tbm_surface_h tbm_surface)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_image *dri2_img;
+   int name;
+   int format;
+   unsigned int pitch;
+   tbm_surface_info_s surf_info;
+
+   name = get_native_buffer_name(tbm_surface);
+   if (!name) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+
+   format = get_format(tbm_surface_get_format(tbm_surface));
+   if (format == -1)
+       return NULL;
+
+   if (tbm_surface_get_info(tbm_surface, &surf_info) != TBM_SURFACE_ERROR_NONE) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+   pitch = surf_info.planes[0].stride;
+
+   if (pitch == 0) {
+      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+      return NULL;
+   }
+
+   dri2_img = calloc(1, sizeof(*dri2_img));
+   if (!dri2_img) {
+      _eglError(EGL_BAD_ALLOC, "tizen_create_image_mesa_drm");
+      return NULL;
+   }
+
+   _eglInitImage(&dri2_img->base, disp);
+
+   dri2_img->dri_image =
+      dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
+                                           surf_info.width,
+                                           surf_info.height,
+                                           format,
+                                           name,
+                                           pitch,
+                                           dri2_img);
+   if (!dri2_img->dri_image) {
+      free(dri2_img);
+      _eglError(EGL_BAD_ALLOC, "tizen_create_image_mesa_drm");
+      return NULL;
+   }
+
+   return &dri2_img->base;
+}
+
+static EGLBoolean
+tizen_query_surface(_EGLDisplay *dpy, _EGLSurface *surf,
+                    EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   int width = 0, height = 0;
+
+   if (tpl_display_get_native_window_info(dri2_dpy->tpl_display,
+                                          dri2_surf->native_win,
+                                          &width, &height, NULL, 0, 0) != TPL_ERROR_NONE)
+     return EGL_FALSE;
+
+   switch (attribute) {
+      case EGL_WIDTH:
+         if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->native_win) {
+            *value = width;
+            return EGL_TRUE;
+         }
+         break;
+      case EGL_HEIGHT:
+         if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->native_win) {
+            *value = height;
+            return EGL_TRUE;
+         }
+         break;
+      default:
+         break;
+   }
+   return _eglQuerySurface(dpy, surf, attribute, value);
+}
+
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+                                      _EGLContext *ctx,
+                                      tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+      return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
+static _EGLImage *
+dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
+                                  _EGLContext *ctx,
+                                  tpl_handle_t native_pixmap)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   int fd;
+   tbm_surface_h tbm_surface = NULL;
+
+   tbm_surface = tpl_display_get_buffer_from_native_pixmap(dri2_dpy->tpl_display,
+                                                           (tpl_handle_t)native_pixmap);
+   if (!tbm_surface)
+     return NULL;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+      return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
+static _EGLImage *
+tizen_create_image_khr(_EGLDisplay *disp,
+                       _EGLContext *ctx, EGLenum target,
+                       EGLClientBuffer buffer, const EGLint *attr_list)
+{
+   switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+      return dri2_create_image_tizen_native_buffer(disp, ctx,
+                                                   (tbm_surface_h)buffer);
+   case EGL_WAYLAND_BUFFER_WL:
+      return dri2_create_image_tizen_wl_buffer(disp, ctx, (tpl_handle_t)buffer);
+   default:
+      return dri2_create_image_khr(disp, ctx, target, buffer, attr_list);
+   }
+}
+
+static void
+tizen_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
+{
+}
+
+static int
+tizen_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
+                                    unsigned int *attachments, int count)
+{
+   int num_buffers = 0, i;
+
+   /* fill dri2_surf->buffers */
+   for (i = 0; i < count * 2; i += 2) {
+      __DRIbuffer *buf, *local;
+
+      assert(num_buffers < ARRAY_SIZE(dri2_surf->buffers));
+      buf = &dri2_surf->buffers[num_buffers];
+
+      switch (attachments[i]) {
+      case __DRI_BUFFER_BACK_LEFT:
+         if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+            buf->attachment = attachments[i];
+            buf->name = get_native_buffer_name(dri2_surf->tbm_surface);
+            buf->cpp = get_format_bpp(tbm_surface_get_format(dri2_surf->tbm_surface));
+            buf->pitch = get_pitch(dri2_surf->tbm_surface);
+            buf->flags = 0;
+
+            if (buf->name)
+               num_buffers++;
+
+            break;
+         }
+         /* fall through for pbuffers */
+      case __DRI_BUFFER_DEPTH:
+      case __DRI_BUFFER_STENCIL:
+      case __DRI_BUFFER_ACCUM:
+      case __DRI_BUFFER_DEPTH_STENCIL:
+      case __DRI_BUFFER_HIZ:
+         local = tizen_alloc_local_buffer(dri2_surf, attachments[i], attachments[i + 1]);
+
+         if (local) {
+            *buf = *local;
+            num_buffers++;
+         }
+         break;
+      case __DRI_BUFFER_FRONT_LEFT:
+      case __DRI_BUFFER_FRONT_RIGHT:
+      case __DRI_BUFFER_FAKE_FRONT_LEFT:
+      case __DRI_BUFFER_FAKE_FRONT_RIGHT:
+      case __DRI_BUFFER_BACK_RIGHT:
+      default:
+         /* no front or right buffers */
+         break;
+      }
+   }
+
+   return num_buffers;
+}
+
+static __DRIbuffer *
+tizen_get_buffers_with_format(__DRIdrawable * driDrawable,
+                              int *width, int *height,
+                              unsigned int *attachments, int count,
+                              int *out_count, void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+
+   if (update_buffers(dri2_surf) < 0)
+      return NULL;
+
+   dri2_surf->buffer_count =
+      tizen_get_buffers_parse_attachments(dri2_surf, attachments, count);
+
+   if (width)
+      *width = dri2_surf->base.Width;
+   if (height)
+      *height = dri2_surf->base.Height;
+
+   *out_count = dri2_surf->buffer_count;
+
+   return dri2_surf->buffers;
+}
+
+static int
+tizen_swrast_get_stride_for_format(tbm_format format, int w)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:
+      return 2 * w;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+   case TBM_FORMAT_BGRA8888:
+   case TBM_FORMAT_RGBA8888:
+#pragma GCC diagnostic pop
+   case TBM_FORMAT_RGBX8888:
+   default:
+      return 4 * w;
+   }
+}
+
+static void
+tizen_swrast_get_drawable_info(__DRIdrawable * draw,
+                               int *x, int *y, int *w, int *h,
+                               void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+
+   if (!dri2_surf->tbm_surface) {
+      if (update_buffers(dri2_surf) < 0)
+         return;
+   }
+
+   *x = 0;
+   *y = 0;
+   *w = dri2_surf->base.Width;
+   *h = dri2_surf->base.Height;
+}
+
+static void
+tizen_swrast_get_image(__DRIdrawable * read,
+                       int x, int y, int w, int h,
+                       char *data, void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+   tbm_surface_info_s surf_info;
+   int ret = TBM_SURFACE_ERROR_NONE;
+   int internal_stride, stride, i;
+
+   if (!dri2_surf->tbm_surface) {
+      if (update_buffers(dri2_surf) < 0)
+         return;
+   }
+
+   ret = tbm_surface_map(dri2_surf->tbm_surface, TBM_SURF_OPTION_READ, &surf_info);
+
+   if (ret != TBM_SURFACE_ERROR_NONE) {
+      _eglLog(_EGL_WARNING, "Could not tbm_surface_map");
+      return;
+   }
+
+   internal_stride = surf_info.planes[0].stride;
+   stride = w * 4;
+
+   for (i = 0; i < h; i++) {
+      memcpy(data + i * stride,
+             surf_info.planes[0].ptr + (x + i) * internal_stride + y, stride);
+   }
+
+   tbm_surface_unmap(dri2_surf->tbm_surface);
+}
+
+static void
+tizen_swrast_put_image2(__DRIdrawable * draw, int op,
+                        int x, int y, int w, int h, int stride,
+                        char *data, void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+   tbm_surface_info_s surf_info;
+   int ret = TBM_SURFACE_ERROR_NONE;
+   int internal_stride, i;
+
+   if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&
+       op != __DRI_SWRAST_IMAGE_OP_SWAP)
+      return;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+      if (!dri2_surf->tbm_surface) {
+        if (update_buffers(dri2_surf) < 0) {
+           _eglLog(_EGL_WARNING, "Could not get native buffer");
+           return;
+        }
+      }
+
+      ret = tbm_surface_map(dri2_surf->tbm_surface, TBM_SURF_OPTION_WRITE, &surf_info);
+      if (ret != TBM_SURFACE_ERROR_NONE) {
+         _eglLog(_EGL_WARNING, "Could not tbm_surface_map");
+         return;
+      }
+
+      internal_stride = surf_info.planes[0].stride;
+
+      for (i = 0; i < h; i++) {
+         memcpy(surf_info.planes[0].ptr + (x + i) * internal_stride + y,
+                data + i * stride, stride);
+      }
+
+      tbm_surface_unmap(dri2_surf->tbm_surface);
+   }
+}
+
+static void
+tizen_swrast_put_image(__DRIdrawable * draw, int op,
+                         int x, int y, int w, int h,
+                         char *data, void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+   int stride;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+      if (!dri2_surf->tbm_surface) {
+        if (update_buffers(dri2_surf) < 0) {
+           _eglLog(_EGL_WARNING, "Could not get native buffer");
+           return;
+        }
+      }
+
+      stride = tizen_swrast_get_stride_for_format(dri2_surf->tbm_format, w);
+      tizen_swrast_put_image2(draw, op, x, y, w, h, stride, data, loaderPrivate);
+   }
+}
+
+static EGLBoolean
+tizen_add_configs(_EGLDisplay *dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   int count, i;
+
+   for (i = 0, count = 0; dri2_dpy->driver_configs[i]; i++) {
+      struct dri2_egl_config *dri2_cfg;
+      unsigned int red, blue, green, alpha, depth;
+      int surface_type = 0;
+      tpl_bool_t is_slow;
+      EGLint attr_list[] = {
+         EGL_NATIVE_VISUAL_ID, 0,
+         EGL_NONE,
+      };
+      tpl_result_t res;
+
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_RED_SIZE, &red);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_GREEN_SIZE, &green);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_BLUE_SIZE, &blue);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_ALPHA_SIZE, &alpha);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_DEPTH_SIZE, &depth);
+
+      res = tpl_display_query_config(dri2_dpy->tpl_display, TPL_SURFACE_TYPE_WINDOW,
+                                     red, green, blue, alpha, depth,
+                                     &attr_list[1], &is_slow);
+      if (res == TPL_ERROR_NONE)
+        surface_type |= EGL_WINDOW_BIT;
+
+      res = tpl_display_query_config(dri2_dpy->tpl_display, TPL_SURFACE_TYPE_PIXMAP,
+                                     red, green, blue, alpha, depth,
+                                     &attr_list[1], &is_slow);
+      if (res == TPL_ERROR_NONE)
+        surface_type |= EGL_PIXMAP_BIT;
+
+      if (!surface_type)
+        continue;
+
+      dri2_cfg = dri2_add_config(dpy, dri2_dpy->driver_configs[i], count + 1,
+                                 surface_type, &attr_list[0], NULL, NULL);
+      if (dri2_cfg)
+        count++;
+   }
+
+   return (count != 0);
+}
+
+static EGLBoolean tizen_set_swap_interval(_EGLDisplay *dpy,
+                                          _EGLSurface *surf, EGLint interval)
+{
+   tpl_result_t res = TPL_ERROR_NONE;
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   res = tpl_surface_set_post_interval(dri2_surf->tpl_surface, interval);
+
+   if (res != TPL_ERROR_NONE)
+     return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static struct dri2_egl_display_vtbl tizen_display_vtbl = {
+   .authenticate = NULL,
+   .create_window_surface = tizen_create_window_surface,
+   .create_pixmap_surface = tizen_create_pixmap_surface,
+   .create_pbuffer_surface = tizen_create_pbuffer_surface,
+   .destroy_surface = tizen_destroy_surface,
+   .create_image = tizen_create_image_khr,
+   .swap_interval = tizen_set_swap_interval,
+   .swap_buffers = tizen_swap_buffers,
+   .swap_buffers_with_damage = tizen_swap_buffers_with_damage,
+   .query_buffer_age = tizen_query_buffer_age,
+   .query_surface = tizen_query_surface,
+   .create_wayland_buffer_from_image = NULL,
+   .get_dri_drawable = dri2_surface_get_dri_drawable,
+};
+
+static const __DRIdri2LoaderExtension tizen_dri2_loader_extension = {
+   .base = { __DRI_DRI2_LOADER, 3 },
+
+   .getBuffers           = NULL,
+   .getBuffersWithFormat = tizen_get_buffers_with_format,
+   .flushFrontBuffer     = tizen_flush_front_buffer,
+};
+
+static const __DRIimageLoaderExtension tizen_image_loader_extension = {
+   .base = { __DRI_IMAGE_LOADER, 1 },
+
+   .getBuffers          = tizen_image_get_buffers,
+   .flushFrontBuffer    = tizen_flush_front_buffer,
+};
+
+static const __DRIswrastLoaderExtension tizen_swrast_loader_extension = {
+   .base = { __DRI_SWRAST_LOADER, 2 },
+
+   .getDrawableInfo = tizen_swrast_get_drawable_info,
+   .putImage        = tizen_swrast_put_image,
+   .getImage        = tizen_swrast_get_image,
+   .putImage2       = tizen_swrast_put_image2,
+};
+
+static const __DRIextension *tizen_dri2_loader_extensions[] = {
+   &tizen_dri2_loader_extension.base,
+   &image_lookup_extension.base,
+   &use_invalidate.base,
+   NULL,
+};
+
+static const __DRIextension *tizen_image_loader_extensions[] = {
+   &tizen_image_loader_extension.base,
+   &image_lookup_extension.base,
+   &use_invalidate.base,
+   NULL,
+};
+
+static const __DRIextension *tizen_swrast_loader_extensions[] = {
+   &tizen_swrast_loader_extension.base,
+   NULL,
+};
+
+EGLBoolean
+dri2_initialize_tizen(_EGLDisplay *disp)
+{
+   _EGLDevice *dev;
+   struct dri2_egl_display *dri2_dpy;
+   tpl_display_t *tpl_display = NULL;
+   const char *err;
+   int tbm_bufmgr_fd = -1;
+   char *tbm_bufmgr_device_name = NULL;
+   int hw_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
+
+   loader_set_logger(_eglLog);
+
+   dri2_dpy = calloc(1, sizeof *dri2_dpy);
+   if (!dri2_dpy)
+      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+
+   disp->DriverData = (void *) dri2_dpy;
+   
+   /* Allocate an new native display, if argument passed to 
+      eglGetDisplay() is EGL_DEFAULT_DISPLAY, it will cause
+      error in __tpl_wayland_egl_display_init() */
+   if (disp->PlatformDisplay == NULL) {
+      disp->PlatformDisplay = wl_display_connect(NULL);
+      if (disp->PlatformDisplay == NULL) {
+         err = "DRI2: failed to get native display";
+         goto cleanup_display;
+      }
+      dri2_dpy->own_device = 1;
+   }
+
+   /* TPL_BACKEND_UNKNOWN type make checking runtime type check */
+   tpl_display = tpl_display_create(TPL_BACKEND_UNKNOWN, disp->PlatformDisplay);
+   if (!tpl_display) {
+      err = "DRI2: failed to create tpl_display";
+      goto cleanup_display;
+   }
+   dri2_dpy->tpl_display = tpl_display;
+
+   /* Get tbm_bufmgr's fd */
+   tbm_bufmgr_fd = tbm_drm_helper_get_fd();
+
+   if (tbm_bufmgr_fd == -1) {
+      err = "DRI2: failed to get tbm_bufmgr fd";
+      goto cleanup_device;
+   }
+
+   if (hw_accel) {
+      int fd = -1;
+
+      if (drmGetNodeTypeFromFd(tbm_bufmgr_fd) == DRM_NODE_RENDER) {
+
+         tbm_bufmgr_device_name = loader_get_device_name_for_fd(tbm_bufmgr_fd);
+         if (tbm_bufmgr_device_name == NULL) {
+            err = "DRI2: failed to get tbm_bufmgr device name";
+            goto cleanup_device;
+         }
+         fd = loader_open_device(tbm_bufmgr_device_name);
+
+      } else {
+         if (!tbm_drm_helper_get_auth_info(&fd, NULL, NULL)) {
+
+            /* FIXME: tbm_drm_helper_get_auth_info() does not support the case of
+             *        display server for now. this code is fallback routine for
+             *        that Enlightenment Server fails on tbm_drm_helper_get_auth_info.
+             *        When tbm_drm_helper_get_auth_info() supports display server
+             *        case, then remove below routine.
+             */
+#if 1
+            tbm_bufmgr_device_name = loader_get_device_name_for_fd(tbm_bufmgr_fd);
+            if (tbm_bufmgr_device_name == NULL) {
+               err = "DRI2: failed to get tbm_bufmgr device name";
+               goto cleanup_device;
+            }
+            fd = loader_open_device(tbm_bufmgr_device_name);
+#else
+            err = "DRI2: failed to get fd from tbm_drm_helper_get_auth_info()";
+            goto cleanup_device;
+#endif
+         }
+      }
+
+      if (fd == -1) {
+         err = "DRI2: failed to get fd";
+         goto cleanup_device;
+      }
+      dri2_dpy->fd = fd;
+
+      dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
+      if (dri2_dpy->driver_name == NULL) {
+         err = "DRI2: failed to get driver name";
+         goto cleanup_device;
+      }
+      if (!dri2_load_driver(disp)) {
+         err = "DRI2: failed to load driver";
+         goto cleanup_driver_name;
+      }
+
+      dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER;
+      /* render nodes cannot use Gem names, and thus do not support
+       * the __DRI_DRI2_LOADER extension */
+
+      if (!dri2_dpy->is_render_node)
+        dri2_dpy->loader_extensions = tizen_dri2_loader_extensions;
+      else
+        dri2_dpy->loader_extensions = tizen_image_loader_extensions;
+
+   } else {
+      dri2_dpy->fd = tbm_bufmgr_fd;
+      dri2_dpy->driver_name = strdup("swrast");
+      if (!dri2_load_driver_swrast(disp)) {
+         err = "DRI2: failed to load swrast driver";
+         goto cleanup_device;
+      }
+      dri2_dpy->loader_extensions = tizen_swrast_loader_extensions;
+   }
+
+   if (!dri2_create_screen(disp)) {
+      err = "DRI2: failed to create screen";
+      goto cleanup_driver;
+   }
+
+
+   dev = _eglAddDevice(dri2_dpy->fd, false);
+   if (!dev) {
+      err = "DRI2: failed to find EGLDevice";
+      goto cleanup_screen;;
+   }
+
+   disp->Device = dev;
+
+   if(dri2_dpy->fd != tbm_bufmgr_fd) {
+      close(dri2_dpy->fd);
+   }
+   close(tbm_bufmgr_fd);
+   tbm_bufmgr_fd = -1;
+   dri2_dpy->fd = -1;
+
+   if (!dri2_setup_extensions(disp)) {
+      err = "DRI2: failed to find required DRI extensions";
+      goto cleanup_screen;
+   }
+
+   dri2_setup_screen(disp);
+
+   if (!tizen_add_configs(disp)) {
+      err = "DRI2: failed to add configs";
+      goto cleanup_screen;
+   }
+
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &tizen_display_vtbl;
+
+   disp->Extensions.EXT_buffer_age = EGL_FALSE;
+   disp->Extensions.EXT_swap_buffers_with_damage = EGL_FALSE; /*disable partial buffer swap*/
+   disp->Extensions.TIZEN_image_native_surface = EGL_TRUE;
+   disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
+   disp->Extensions.WL_create_wayland_buffer_from_image = EGL_FALSE;
+
+
+   return EGL_TRUE;
+
+cleanup_screen:
+   dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
+cleanup_driver:
+   dlclose(dri2_dpy->driver);
+cleanup_driver_name:
+   if (hw_accel)
+     free(dri2_dpy->driver_name);
+cleanup_device:
+   if (tbm_bufmgr_device_name)
+     free(tbm_bufmgr_device_name);
+   tpl_object_unreference((tpl_object_t *)tpl_display);
+cleanup_display:
+   if (dri2_dpy->own_device) {
+      wl_display_disconnect(disp->PlatformDisplay);
+      disp->PlatformDisplay = NULL;
+   }
+   free(dri2_dpy);
+   disp->DriverData = NULL;
+
+   return _eglError(EGL_NOT_INITIALIZED, err);
+}
+
+void
+dri2_teardown_tizen(_EGLDisplay *disp)
+{
+    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+    if (dri2_dpy->tpl_display)
+        tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+
+    if (tbm_bufmgr_fd > 0)
+        close(tbm_bufmgr_fd);
+
+    if (dri2_dpy->own_device)
+        wl_display_disconnect(disp->PlatformDisplay);
+}
index d50be23..f2ea7d7 100644 (file)
@@ -462,6 +462,18 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
    case EGL_PLATFORM_DEVICE_EXT:
       disp = _eglGetDeviceDisplay(native_display, attrib_list);
       break;
+#ifdef HAVE_TIZEN_PLATFORM
+#ifndef HAVE_DRM_PLATFORM
+   case EGL_PLATFORM_GBM_MESA:
+      disp = _eglGetTizenDisplay(native_display, attrib_list);
+      break;
+#endif
+#ifndef HAVE_WAYLAND_PLATFORM
+   case EGL_PLATFORM_WAYLAND_EXT:
+      disp = _eglGetTizenDisplay(native_display, attrib_list);
+      break;
+#endif
+#endif
    default:
       RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
    }
@@ -597,6 +609,10 @@ _eglCreateExtensionsString(_EGLDisplay *disp)
 
    _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+#ifdef HAVE_TIZEN_PLATFORM
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+#endif
+
    _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
    _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
index 4eadb8f..04cb1bb 100644 (file)
@@ -83,6 +83,7 @@ static const struct {
    {_EGL_PLATFORM_SURFACELESS, "surfaceless"},
    {_EGL_PLATFORM_DEVICE, "device"},
    {_EGL_PLATFORM_WINDOWS, "windows"},
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 /**
@@ -98,7 +99,13 @@ _eglGetNativePlatformFromEnv(void)
    static_assert(ARRAY_SIZE(egl_platforms) == _EGL_NUM_PLATFORMS,
                  "Missing platform");
 
+   /* EFL will set EGL_PLATFORM as wayland */
+#ifdef HAVE_TIZEN_PLATFORM
+   plat_name = getenv("EGL_PLATFORM_MESA");
+#else
    plat_name = getenv("EGL_PLATFORM");
+#endif
+
    /* try deprecated env variable */
    if (!plat_name || !plat_name[0])
       plat_name = getenv("EGL_DISPLAY");
@@ -136,6 +143,12 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
    if (_eglPointerIsDereferenceable(nativeDisplay)) {
       void *first_pointer = *(void **)nativeDisplay;
 
+      (void) first_pointer; /* silence unused var warning */
+
+#ifdef HAVE_TIZEN_PLATFORM
+      /* In Tizen Platform, _EGL_PLATFORM_TIZEN handles DRM(gbm) and wayland_egl platform together */
+      return _EGL_PLATFORM_TIZEN;
+#endif
 #ifdef HAVE_WAYLAND_PLATFORM
       /* wl_display is a wl_proxy, which is a wl_object.
        * wl_object's first element points to the interfacetype. */
@@ -164,9 +177,14 @@ _eglGetNativePlatform(void *nativeDisplay)
    const char *detection_method = "environment";
 
    if (detected_platform == _EGL_INVALID_PLATFORM) {
-      detected_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
-      detection_method = "autodetected";
-   }
+         detected_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
+         detection_method = "autodetected";
+
+#ifdef HAVE_TIZEN_PLATFORM
+      if (detected_platform != _EGL_INVALID_PLATFORM)
+         detected_platform = _EGL_PLATFORM_TIZEN;
+#endif
+  }
 
    if (detected_platform == _EGL_INVALID_PLATFORM) {
       detected_platform = _EGL_NATIVE_PLATFORM;
@@ -695,6 +713,22 @@ _eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list)
 }
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+_EGLDisplay*
+_eglGetTizenDisplay(void *native_display,
+                    const EGLAttrib *attrib_list)
+{
+   if (attrib_list != NULL && attrib_list[0] != EGL_NONE) {
+      _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
+      return NULL;
+   }
+
+   return _eglFindDisplay(_EGL_PLATFORM_TIZEN, native_display,
+                          attrib_list);
+}
+#endif /* HAVE_TIZEN_PLATFORM */
+
+
 _EGLDisplay *
 _eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list)
 {
index ea75cd3..5aa8683 100644 (file)
@@ -55,6 +55,7 @@ enum _egl_platform_type {
    _EGL_PLATFORM_SURFACELESS,
    _EGL_PLATFORM_DEVICE,
    _EGL_PLATFORM_WINDOWS,
+   _EGL_PLATFORM_TIZEN,
 
    _EGL_NUM_PLATFORMS,
    _EGL_INVALID_PLATFORM = -1
@@ -150,6 +151,10 @@ struct _egl_extensions {
 
    EGLBoolean NV_post_sub_buffer;
 
+#ifdef HAVE_TIZEN_PLATFORM
+   EGLBoolean TIZEN_image_native_surface;
+#endif
+
    EGLBoolean WL_bind_wayland_display;
    EGLBoolean WL_create_wayland_buffer_from_image;
 };
@@ -333,6 +338,12 @@ _eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list);
 _EGLDisplay *
 _eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list);
 
+#ifdef HAVE_TIZEN_PLATFORM
+_EGLDisplay*
+_eglGetTizenDisplay(void *native_display,
+                    const EGLAttrib *attrib_list);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 678bb75..86421a2 100644 (file)
 #include "util/u_string.h"
 
 #include "egllog.h"
+#ifdef HAVE_TIZEN_PLATFORM
+#define LOG_TAG "MESA"
+#include <dlog.h>
+#endif
 
 #ifdef HAVE_ANDROID_PLATFORM
 #define LOG_TAG "EGL-MAIN"
@@ -75,6 +79,8 @@ static const char *level_strings[] = {
    [_EGL_DEBUG] = "debug",
 };
 
+
+#ifndef HAVE_TIZEN_PLATFORM
 /**
  * The default logger.  It prints the message to stderr.
  */
@@ -93,6 +99,7 @@ _eglDefaultLogger(EGLint level, const char *msg)
    fprintf(stderr, "libEGL %s: %s\n", level_strings[level], msg);
 #endif /* HAVE_ANDROID_PLATFORM */
 }
+#endif
 
 /**
  * Initialize the logging facility.
@@ -146,8 +153,10 @@ void
 _eglLog(EGLint level, const char *fmtStr, ...)
 {
    va_list args;
+#ifndef HAVE_TIZEN_PLATFORM
    char msg[MAXSTRING];
    int ret;
+#endif
 
    /* one-time initialization; a little race here is fine */
    if (!logging.initialized)
@@ -157,13 +166,41 @@ _eglLog(EGLint level, const char *fmtStr, ...)
 
    simple_mtx_lock(&logging.mutex);
 
+#ifdef HAVE_TIZEN_PLATFORM
+   log_priority dlog_prio;
+
+   switch (level) {
+   case _EGL_FATAL:
+      dlog_prio = DLOG_ERROR;
+      break;
+   case _EGL_WARNING:
+      dlog_prio = DLOG_WARN;
+      break;
+   case _EGL_INFO:
+      dlog_prio = DLOG_INFO;
+      break;
+   case _EGL_DEBUG:
+      dlog_prio = DLOG_DEBUG;
+      break;
+   default:
+      simple_mtx_unlock(&logging.mutex);
+      return;
+   }
+#endif
+
    va_start(args, fmtStr);
+#ifdef HAVE_TIZEN_PLATFORM
+   __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, fmtStr, args);
+#else
    ret = vsnprintf(msg, MAXSTRING, fmtStr, args);
    if (ret < 0 || ret >= MAXSTRING)
       strcpy(msg, "<message truncated>");
+#endif
    va_end(args);
 
+#ifndef HAVE_TIZEN_PLATFORM
    _eglDefaultLogger(level, msg);
+#endif
 
    simple_mtx_unlock(&logging.mutex);
 
index 00a1da3..63a2674 100644 (file)
@@ -125,13 +125,17 @@ if with_dri2
     deps_for_egl += dep_libdrm
   endif
   if with_platform_wayland
-    deps_for_egl += [dep_wayland_client, dep_wayland_server, dep_wayland_egl_headers]
+    deps_for_egl += [dep_wayland_client, dep_wayland_server]
     link_for_egl += libwayland_drm
     files_egl += files('drivers/dri2/platform_wayland.c')
     files_egl += wp_files['linux-dmabuf-unstable-v1']
     files_egl += [wayland_drm_client_protocol_h]
     incs_for_egl += include_directories('wayland/wayland-drm')
   endif
+  if with_platform_tizen
+    files_egl += files('drivers/dri2/platform_tizen.c')
+    deps_for_egl += [dep_libdrm, dep_tpl_egl, dep_libtbm, dep_libtdm, dep_wayland_client, dep_dlog]
+  endif
   if with_platform_android
     deps_for_egl += dep_android
     files_egl += files('drivers/dri2/platform_android.c')
index 3d3cc5b..262129e 100644 (file)
@@ -26,5 +26,5 @@ libv3dwinsys = static_library(
     inc_gallium, inc_gallium_aux, inc_gallium_drivers,
   ],
   gnu_symbol_visibility : 'hidden',
-  dependencies : idep_mesautil,
+  dependencies : [idep_mesautil, dep_libdrm],
 )
index 7081374..c6bd06f 100644 (file)
 #include "util/log.h"
 #include "api_exec_decl.h"
 
+#ifdef HAVE_TIZEN_PLATFORM
+#define LOG_TAG "MESA"
+#include <dlog/dlog.h>
+#endif
+
 static void
 output_if_debug(enum mesa_log_level level, const char *outputString)
 {
@@ -118,7 +123,11 @@ _mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
    if (ctx)
       flush_delayed_errors( ctx );
 
+#ifdef HAVE_TIZEN_PLATFORM
+   dlog_print(DLOG_WARN, LOG_TAG, "%s", str);
+#else
    output_if_debug(MESA_LOG_WARN, str);
+#endif
 }
 
 
@@ -144,9 +153,13 @@ _mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
       va_start( args, fmtString );
       vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
       va_end( args );
+#ifdef HAVE_TIZEN_PLATFORM
+      dlog_print(DLOG_WARN, LOG_TAG, "%s", str);
+#else
       fprintf(stderr, "Mesa " PACKAGE_VERSION " implementation error: %s\n",
               str);
       fprintf(stderr, "Please report at " PACKAGE_BUGREPORT "\n");
+#endif
    }
 }
 
@@ -318,7 +331,11 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
 
       /* Print the error to stderr if needed. */
       if (do_output) {
+#ifdef HAVE_TIZEN_PLATFORM
+         dlog_print(DLOG_ERROR, LOG_TAG, "%s", s2);
+#else
          output_if_debug(MESA_LOG_ERROR, s2);
+#endif
       }
 
       /* Log the error via ARB_debug_output if needed.*/
@@ -356,7 +373,12 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
    va_start(args, fmtString);
    vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
    va_end(args);
+
+#ifdef HAVE_TIZEN_PLATFORM
+   dlog_print(DLOG_DEBUG, LOG_TAG, "%s", s);
+#else
    output_if_debug(MESA_LOG_DEBUG, s);
+#endif
 #endif /* DEBUG */
    (void) ctx;
    (void) fmtString;
@@ -371,7 +393,11 @@ _mesa_log(const char *fmtString, ...)
    va_start(args, fmtString);
    vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
    va_end(args);
+#ifdef HAVE_TIZEN_PLATFORM
+   dlog_print(DLOG_INFO, LOG_TAG, "%s", s);
+#else
    output_if_debug(MESA_LOG_INFO, s);
+#endif
 }
 
 void