Add a GlesVideoTexture sample
authorSukwon Suh <sukwon.suh@samsung.com>
Mon, 18 Mar 2013 08:27:42 +0000 (17:27 +0900)
committerSukwon Suh <sukwon.suh@samsung.com>
Mon, 18 Mar 2013 08:27:42 +0000 (17:27 +0900)
Change-Id: I2c59248c8de156e548a1142f5137fbb42139b8fc
Signed-off-by: Sukwon Suh <sukwon.suh@samsung.com>
14 files changed:
LICENSE.Flora [new file with mode: 0644]
NOTICE [new file with mode: 0644]
description.xml [new file with mode: 0644]
project/data/sample.mp4 [new file with mode: 0644]
project/inc/GlesVideoTexture.h [new file with mode: 0644]
project/manifest.xml [new file with mode: 0644]
project/res/nofile.dummy [new file with mode: 0644]
project/shared/data/nofile.dummy [new file with mode: 0644]
project/shared/res/screen-density-xhigh/mainmenu.png [new file with mode: 0644]
project/shared/trusted/nofile.dummy [new file with mode: 0644]
project/src/GlesVideoTexture.cpp [new file with mode: 0644]
project/src/GlesVideoTextureEntry.cpp [new file with mode: 0644]
sample.xml [new file with mode: 0644]
screenshot.png [new file with mode: 0644]

diff --git a/LICENSE.Flora b/LICENSE.Flora
new file mode 100644 (file)
index 0000000..9c95663
--- /dev/null
@@ -0,0 +1,206 @@
+Flora License
+
+Version 1.0, May, 2012
+
+http://floralicense.org/license/
+
+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.
+
+"Tizen Certified Platform" shall mean a software platform that complies
+with the standards set forth in the Compatibility Definition Document
+and passes the Compatibility Test Suite as defined from time to time
+by the Tizen Technical Steering Group and certified by the Tizen
+Association or its designated agent.
+
+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
+solely as incorporated into a Tizen Certified Platform, 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 solely
+as incorporated into a Tizen Certified Platform 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 pursuant to the copyright license
+above, in any medium, with or without modifications, and in Source or
+Object form, provided that You meet the following conditions:
+
+  1. You must give any other recipients of the Work or Derivative Works
+     a copy of this License; and
+  2. You must cause any modified files to carry prominent notices stating
+     that You changed the files; and
+  3. 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
+  4. 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 Flora License to your work
+
+To apply the Flora 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 Flora License, Version 1.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://floralicense.org/license/
+
+   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.
+
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..f37f329
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,4 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.
+Please, see the LICENSE.Flora file for Flora License terms and conditions.
+
diff --git a/description.xml b/description.xml
new file mode 100644 (file)
index 0000000..7839d5f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?> 
+<?xml-stylesheet type="text/xsl" href="../../../../description.xsl"?>
+
+<Overview version="0.17.1">
+  <SampleName> GlesVideoTexture </SampleName>
+  <SampleVersion>1.0</SampleVersion>
+  <Preview>screenshot.png</Preview>
+  <Description>The Purpose of this application, GlesVideoTexture, is to demonstrate the functionalities of VideoTexture.</Description>
+</Overview>
diff --git a/project/data/sample.mp4 b/project/data/sample.mp4
new file mode 100644 (file)
index 0000000..685cdf6
Binary files /dev/null and b/project/data/sample.mp4 differ
diff --git a/project/inc/GlesVideoTexture.h b/project/inc/GlesVideoTexture.h
new file mode 100644 (file)
index 0000000..df9f02f
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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.
+//
+
+#ifndef _GLES_VIDEO_TEXTURE_H_
+#define _GLES_VIDEO_TEXTURE_H_
+
+
+#include <new>
+#include <FBase.h>
+#include <FSystem.h>
+#include <FGraphics.h>
+#include <FUi.h>
+#include <FApp.h>
+#include <FGraphicsOpengl2.h>
+#include <FGrpFloatMatrix4.h>
+#include <FGrpVideoTexture.h>
+#include <FGrpIVideoTextureUpdateListener.h>
+#include <FMedia.h>
+
+class GlesVideoTexture
+       : public Tizen::App::Application
+       , public Tizen::System::IScreenEventListener
+       , public Tizen::Ui::IKeyEventListener
+       , public Tizen::Base::Runtime::ITimerEventListener
+       , public Tizen::Media::IPlayerEventListener
+       , public Tizen::Graphics::Opengl::IVideoTextureUpdateListener
+{
+public:
+       static Tizen::App::Application* CreateInstance(void);
+
+       GlesVideoTexture(void);
+       ~GlesVideoTexture(void);
+
+       virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
+       virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
+       virtual void OnForeground(void);
+       virtual void OnBackground(void);
+       virtual void OnLowMemory(void);
+       virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
+       virtual void OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+       virtual void OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+       virtual void OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+
+       virtual void OnScreenOn(void);
+       virtual void OnScreenOff(void);
+
+       virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+       bool Draw(void);
+       void Update(void);
+       virtual void OnTextureUpdated(Tizen::Graphics::Opengl::VideoTexture* pVideoTexture);
+
+protected:
+    void OnPlayerOpened(result r) {}
+    void OnPlayerEndOfClip(void) {}
+       void OnPlayerBuffering(int percent) {}
+    void OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r ) {}
+    void OnPlayerInterrupted(void)  {}
+    void OnPlayerReleased(void) {}
+
+private:
+       bool InitEGL(void);
+       bool InitGL(void);
+       bool InitVideoTexture(void);
+       void DestroyGL(void);
+       void DestroyVideoTexture(void);
+       void Cleanup(void);
+
+       void Frustum(Tizen::Graphics::FloatMatrix4* pResult, float left, float right, float bottom, float top, float near, float far);
+       void Perspective(Tizen::Graphics::FloatMatrix4* pResult, float fovY, float aspect, float near, float far);
+       void Translate(Tizen::Graphics::FloatMatrix4* pResult, float tx, float ty, float tz);
+       void Rotate(Tizen::Graphics::FloatMatrix4* pResult, float angle, float x, float y, float z);
+
+private:
+       Tizen::Graphics::Opengl::EGLDisplay    __eglDisplay;
+       Tizen::Graphics::Opengl::EGLSurface    __eglSurface;
+       Tizen::Graphics::Opengl::EGLConfig     __eglConfig;
+       Tizen::Graphics::Opengl::EGLContext    __eglContext;
+       Tizen::Graphics::Opengl::GLuint        __programObject;
+       Tizen::Graphics::Opengl::GLint         __indexPosition;
+       Tizen::Graphics::Opengl::GLint         __indexTexture;
+       Tizen::Graphics::Opengl::GLint         __indexTextureSample;
+       Tizen::Graphics::Opengl::GLint         __indexMVP;
+       Tizen::Graphics::Opengl::GLfloat       __angle;
+       Tizen::Base::Runtime::Timer*           __pTimer;
+       Tizen::Graphics::FloatMatrix4          __matMVP;
+
+       Tizen::Ui::Controls::Form*             __pForm;
+
+       Tizen::Graphics::Opengl::GLuint        __textureId;
+       Tizen::Graphics::Opengl::VideoTexture* __pVideoTexture;
+
+       Tizen::Media::Player*                  __pPlayer;
+       bool                                   __isVideoTextureReady;
+};
+
+#endif // _GLES_VIDEO_TEXTURE_H_
diff --git a/project/manifest.xml b/project/manifest.xml
new file mode 100644 (file)
index 0000000..b07a122
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/12/manifest">
+    <Id>$(manifestAppId)</Id>
+    <Version>2.0.1</Version>
+    <Type>C++App</Type>
+    <Apps>
+        <ApiVersion>2.0</ApiVersion>
+        <Privileges/>
+        <UiApp Main="True" MenuIconVisible="True" Name="$(projectName)">
+            <UiScalability CoordinateSystem="Physical"/>
+            <UiTheme SystemTheme="Black"/>
+            <DisplayNames>
+                <DisplayName Locale="eng-GB">$(projectName)</DisplayName>
+            </DisplayNames>
+            <Icons>
+                <Icon Section="MainMenu" Type="Xhigh">mainmenu.png</Icon>
+            </Icons>
+            <LaunchConditions/>
+            <Notifications/>
+        </UiApp>
+    </Apps>
+</Manifest>
diff --git a/project/res/nofile.dummy b/project/res/nofile.dummy
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project/shared/data/nofile.dummy b/project/shared/data/nofile.dummy
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project/shared/res/screen-density-xhigh/mainmenu.png b/project/shared/res/screen-density-xhigh/mainmenu.png
new file mode 100644 (file)
index 0000000..983c883
Binary files /dev/null and b/project/shared/res/screen-density-xhigh/mainmenu.png differ
diff --git a/project/shared/trusted/nofile.dummy b/project/shared/trusted/nofile.dummy
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project/src/GlesVideoTexture.cpp b/project/src/GlesVideoTexture.cpp
new file mode 100644 (file)
index 0000000..93aaaa7
--- /dev/null
@@ -0,0 +1,760 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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.
+//
+
+#include <math.h>
+#include "GlesVideoTexture.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Graphics;
+using namespace Tizen::Locales;
+using namespace Tizen::System;
+using namespace Tizen::App;
+using namespace Tizen::System;
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
+using namespace Tizen::Graphics::Opengl;
+using namespace Tizen::Media;
+
+const int TIME_OUT = 10;
+const float PI = 3.1415926535897932384626433832795f;
+//#define DISPLAY_FPS
+
+const char* VERTEX_TEXT =
+               "uniform mat4 uPositionMatrix;\n"
+               "attribute vec4 aPosition;\n"
+               "attribute vec4 aTextureCoord;\n"
+               "varying vec4 vTextureCoord;\n"
+               "\n"
+               "void main()\n"
+               "{\n"
+               "    gl_Position = uPositionMatrix * aPosition;\n"
+               "    vTextureCoord = aTextureCoord;\n"
+               "}";
+
+const char* FRAGMENT_TEXT =
+       "precision highp float;\n"
+       "uniform sampler2D sTexture;\n"
+       "varying vec4 vTextureCoord;\n"
+       "\n"
+       "void main (void)\n"
+       "{\n"
+       "       float borderSize = 0.01;"
+       "       if (vTextureCoord.x < borderSize || vTextureCoord.x > 1.0 - borderSize || vTextureCoord.y < borderSize || vTextureCoord.y > 1.0 - borderSize)"
+       "       {"
+       "               gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
+       "       }"
+       "       else"
+       "       {"
+       "               gl_FragColor = texture2D(sTexture, vTextureCoord.xy);\n"
+       "       }"
+       "}";
+
+class GlesForm
+       : public Tizen::Ui::Controls::Form
+{
+public:
+       GlesForm(GlesVideoTexture* pApp)
+               : __pApp(pApp)
+       {
+       }
+
+       virtual ~GlesForm(void)
+       {
+       }
+
+       virtual result OnDraw(void)
+       {
+               if (__pApp != null)
+               {
+                       __pApp->Draw();
+               }
+
+               return E_SUCCESS;
+       }
+
+private:
+       GlesVideoTexture* __pApp;
+};
+
+
+const GLfloat VERTICES[] =
+{
+       -0.5f,  0.5f,  0.0f,
+       -0.5f, -0.5f,  0.0f,
+        0.5f, -0.5f,  0.0f,
+        0.5f,  0.5f,  0.0f,
+       -0.5f,  0.5f,  0.0f,
+       -0.5f, -0.5f,  0.0f,
+        0.5f, -0.5f,  0.0f,
+        0.5f,  0.5f,  0.0f,
+};
+
+const GLfloat TEXTURES[] = {
+       0.0f, 0.0f,
+       0.0f, 1.0f,
+       1.0f, 1.0f,
+       1.0f, 0.0f,
+       1.0f, 0.0f,
+       1.0f, 1.0f,
+       0.0f, 1.0f,
+       0.0f, 0.0f,
+};
+
+const GLshort INDICES[] =
+{
+        0, 1, 2,
+        0, 2, 3,
+        7, 6, 5,
+        7, 5, 4,
+};
+
+const int numIndices = 12;
+
+GlesVideoTexture::GlesVideoTexture(void)
+       : __eglDisplay(EGL_DEFAULT_DISPLAY)
+       , __eglSurface(EGL_NO_SURFACE)
+       , __eglConfig(null)
+       , __eglContext(EGL_NO_DISPLAY)
+       , __programObject(0)
+       , __indexPosition(0)
+       , __indexTexture(0)
+       , __indexTextureSample(0)
+       , __indexMVP(0)
+       , __angle(0.0f)
+       , __pTimer(null)
+       , __pForm(null)
+       , __textureId(0)
+       , __pVideoTexture(null)
+       , __pPlayer(null)
+       , __isVideoTextureReady(false)
+{
+}
+
+
+GlesVideoTexture::~GlesVideoTexture(void)
+{
+}
+
+
+void
+GlesVideoTexture::Cleanup(void)
+{
+       if (__pTimer != null)
+       {
+               __pTimer->Cancel();
+               delete __pTimer;
+               __pTimer = null;
+       }
+
+       DestroyGL();
+       DestroyVideoTexture();
+}
+
+
+Application*
+GlesVideoTexture::CreateInstance(void)
+{
+       return new (std::nothrow) GlesVideoTexture();
+}
+
+bool
+GlesVideoTexture::OnAppInitializing(AppRegistry& appRegistry)
+{
+       result r = E_SUCCESS;
+       Frame* pAppFrame = new (std::nothrow) Frame();
+       TryReturn(pAppFrame != null, false, "Generating a frame failed.");
+
+       r = pAppFrame->Construct();
+       TryReturn(!IsFailed(r), false, "pAppFrame->Construct() failed.");
+
+       AddFrame(*pAppFrame);
+
+       __pForm = new (std::nothrow) GlesForm(this);
+       TryCatch(__pForm != null, , "Allocation of GlesForm failed.");
+
+       r = __pForm->Construct(FORM_STYLE_NORMAL);
+       TryCatch(!IsFailed(r), , "__pForm->Construct(FORM_STYLE_NORMAL) failed.");
+
+       r = GetAppFrame()->GetFrame()->AddControl(*__pForm);
+       TryCatch(!IsFailed(r), , "GetAppFrame()->GetFrame()->AddControl(*__pForm) failed.");
+
+       TryCatch(InitEGL(), , "InitEGL() failed.");
+
+       TryCatch(InitGL(), , "InitGL() failed.");
+
+       TryCatch(InitVideoTexture(), , "InitVideoTexture() failed.");
+
+       __pTimer = new (std::nothrow) Timer;
+       TryCatch(__pTimer != null, , "Failed to allocate memory.");
+
+       r = __pTimer->Construct(*this);
+       TryCatch(!IsFailed(r), , "__pTimer->Construct(*this) failed.");
+
+       // Comment the following statement to stop listen to the screen on/off events.
+       PowerManager::SetScreenEventListener(*this);
+
+       return true;
+
+CATCH:
+       delete pAppFrame;
+       delete __pForm;
+       __pForm = null;
+
+       AppLog("eglError : %#x glError : %#x VENDOR : %s GL_RENDERER : %s GL_VERSION : %s"
+                       , static_cast<unsigned int>(eglGetError())
+                       , static_cast<unsigned int>(glGetError())
+                       , glGetString(GL_VENDOR)
+                       , glGetString(GL_RENDERER)
+                       , glGetString(GL_VERSION));
+
+       Cleanup();
+
+       return false;
+}
+
+
+bool
+GlesVideoTexture::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
+{
+       Cleanup();
+
+       return true;
+}
+
+
+void
+GlesVideoTexture::OnForeground(void)
+{
+       if (__pTimer != null)
+       {
+               __pTimer->Start(TIME_OUT);
+       }
+
+       if(__pPlayer != null)
+       {
+               __pPlayer->Play();
+       }
+}
+
+
+void
+GlesVideoTexture::OnBackground(void)
+{
+       if (__pTimer != null)
+       {
+               __pTimer->Cancel();
+       }
+
+       if(__pPlayer != null)
+       {
+               __pPlayer->Pause();
+       }
+}
+
+
+void
+GlesVideoTexture::OnBatteryLevelChanged(BatteryLevel batteryLevel)
+{
+}
+
+
+void
+GlesVideoTexture::OnLowMemory(void)
+{
+}
+
+void
+GlesVideoTexture::OnKeyPressed(const Control& source, KeyCode keyCode)
+{
+}
+
+
+void
+GlesVideoTexture::OnKeyReleased(const Control& source, KeyCode keyCode)
+{
+}
+
+
+void
+GlesVideoTexture::OnKeyLongPressed(const Control& source, KeyCode keyCode)
+{
+}
+
+void
+GlesVideoTexture::OnScreenOn(void)
+{
+       if (__pTimer != null)
+       {
+               __pTimer->Start(TIME_OUT);
+       }
+
+       if(__pPlayer != null)
+       {
+               __pPlayer->Play();
+       }
+}
+
+void
+GlesVideoTexture::OnScreenOff(void)
+{
+       if (__pTimer != null)
+       {
+               __pTimer->Cancel();
+       }
+
+       if(__pPlayer != null)
+       {
+               __pPlayer->Pause();
+       }
+}
+
+void
+GlesVideoTexture::OnTimerExpired(Timer& timer)
+{
+       if (__pTimer == null)
+       {
+               return;
+       }
+
+       __pTimer->Start(TIME_OUT);
+
+       if (__isVideoTextureReady)
+       {
+               Update();
+
+               if (!Draw())
+               {
+                       AppLog("Draw() failed.");
+               }
+       }
+}
+
+
+bool
+GlesVideoTexture::InitEGL(void)
+{
+       EGLint numConfigs = 1;
+
+       EGLint eglConfigList[] =
+       {
+               EGL_RED_SIZE,   5,
+               EGL_GREEN_SIZE, 6,
+               EGL_BLUE_SIZE,  5,
+               EGL_ALPHA_SIZE, 0,
+               EGL_DEPTH_SIZE, 8,
+               EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+               EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+               EGL_NONE
+       };
+
+       EGLint eglContextList[] = 
+       {
+               EGL_CONTEXT_CLIENT_VERSION, 2,
+               EGL_NONE
+       };
+
+       eglBindAPI(EGL_OPENGL_ES_API);
+
+       if (__eglDisplay)
+       {
+               DestroyGL();
+       }
+
+       __eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
+       TryCatch(__eglDisplay != EGL_NO_DISPLAY, , "eglGetDisplay() failed.");
+
+       TryCatch(!(eglInitialize(__eglDisplay, null, null) == EGL_FALSE || eglGetError() != EGL_SUCCESS), , "[GlesVideoTexture] eglInitialize() failed.");
+
+       TryCatch(!(eglChooseConfig(__eglDisplay, eglConfigList, &__eglConfig, 1, &numConfigs) == EGL_FALSE ||
+                       eglGetError() != EGL_SUCCESS), , "eglChooseConfig() failed.");
+
+       TryCatch(numConfigs, , "eglChooseConfig() failed. because of matching config doesn't exist");
+
+       __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, (EGLNativeWindowType)__pForm, null);
+       TryCatch(!(__eglSurface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS), , "eglCreateWindowSurface() failed.");
+
+       __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextList);
+       TryCatch(!(__eglContext == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS), , "eglCreateContext() failed.");
+
+       TryCatch(!(eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) == EGL_FALSE ||
+                       eglGetError() != EGL_SUCCESS), , "eglMakeCurrent() failed.");
+
+       return true;
+
+CATCH:
+       {
+               AppLog("GlesVideoTexture can run on systems which supports OpenGL ES(R) 2.0.\n"
+                               "When GlesVideoTexture does not correctly execute, there are a few reasons.\n"
+                               "1. The current device(real-target or emulator) does not support OpenGL ES(R) 2.0."
+                               " Check the Release Notes.\n"
+                               "2. The system running on emulator cannot support OpenGL(R) 2.1 or later."
+                               " Try with other system.\n"
+                               "3. The system running on emulator does not maintain the latest graphics driver."
+                               " Update the graphics driver.");
+       }
+
+       DestroyGL();
+
+       return false;
+}
+
+
+bool
+GlesVideoTexture::InitGL(void)
+{
+    GLint linked = GL_FALSE;
+    GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+    GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
+
+    glShaderSource(fragShader, 1, static_cast<const char**> (&FRAGMENT_TEXT), null);
+    glCompileShader(fragShader);
+    GLint bShaderCompiled = GL_FALSE;
+    glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bShaderCompiled);
+
+    TryCatch(bShaderCompiled != GL_FALSE, , "bShaderCompiled == GL_FALSE");
+
+    glShaderSource(vertShader, 1, static_cast<const char**> (&VERTEX_TEXT), null);
+    glCompileShader(vertShader);
+    glGetShaderiv(vertShader, GL_COMPILE_STATUS, &bShaderCompiled);
+
+    TryCatch(bShaderCompiled != GL_FALSE, , "bShaderCompiled == GL_FALSE");
+
+       __programObject = glCreateProgram();
+       glAttachShader(__programObject, fragShader);
+       glAttachShader(__programObject, vertShader);
+       glLinkProgram(__programObject);
+       glGetProgramiv(__programObject, GL_LINK_STATUS, &linked);
+
+       if (linked == GL_FALSE)
+       {
+               GLint infoLen = 0;
+               glGetProgramiv(__programObject, GL_INFO_LOG_LENGTH, &infoLen);
+
+               if (infoLen > 1)
+               {
+                       char* infoLog = new (std::nothrow) char[infoLen];
+                       glGetProgramInfoLog(__programObject, infoLen, null, infoLog);
+                       AppLog("Linking failed. log: %s", infoLog);
+                       delete [] infoLog;
+               }
+
+               TryCatch(false, , "linked == GL_FALSE");
+       }
+
+       __indexPosition = glGetAttribLocation(__programObject, "aPosition");
+       __indexTexture = glGetAttribLocation(__programObject, "aTextureCoord");
+       __indexTextureSample = glGetUniformLocation(__programObject, "sTexture");
+       __indexMVP = glGetUniformLocation(__programObject, "uPositionMatrix");
+
+       glUseProgram(__programObject);
+
+       glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+       glEnable(GL_DEPTH_TEST);
+
+       __angle = 45.0f;
+
+       glDeleteShader(vertShader);
+       glDeleteShader(fragShader);
+
+       glClearColor(0, 0, 0, 1);
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       glEnable(GL_CULL_FACE);
+
+       return true;
+
+CATCH:
+       glDeleteShader(vertShader);
+       glDeleteShader(fragShader);
+
+       return false;
+}
+
+bool
+GlesVideoTexture::InitVideoTexture(void)
+{
+       result r = E_SUCCESS;
+       Rectangle rect = __pForm->GetBounds();
+
+       glGenTextures(1, &__textureId);
+       glBindTexture(GL_TEXTURE_2D, __textureId);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+       __pVideoTexture = new Tizen::Graphics::Opengl::VideoTexture;
+       TryCatch(__pVideoTexture != null,  , "Allocation of VideoTexture failed.");
+
+       r = __pVideoTexture->Construct(__textureId, rect.width, rect.height);
+       TryCatch(!IsFailed(r),  , "__pVideoTexture->Construct() failed.");
+
+       __pVideoTexture->AddVideoTextureUpdateListener(*this);
+
+       __pPlayer = new Player();
+       TryCatch(__pPlayer != null,  , "Allocation of Player() failed.");
+
+       r = __pPlayer->Construct(*this, *__pVideoTexture);
+       TryCatch(!IsFailed(r),  , "__pPlayer->Construct() failed.");
+
+       r = __pPlayer->OpenFile(GetInstance()->GetAppRootPath() + L"data/sample.mp4");
+       TryCatch(!IsFailed(r),  , "__pPlayer->OpenFile() failed.");
+
+       __pPlayer->SetLooping(true);
+
+       return true;
+
+CATCH:
+       DestroyVideoTexture();
+
+       return false;
+}
+
+void
+GlesVideoTexture::DestroyGL(void)
+{
+       if (__programObject)
+       {
+               glDeleteProgram(__programObject);
+       }
+
+       if (__eglDisplay)
+       {
+               eglMakeCurrent(__eglDisplay, null, null, null);
+
+               if (__eglContext)
+               {
+                       eglDestroyContext(__eglDisplay, __eglContext);
+                       __eglContext = EGL_NO_CONTEXT;
+               }
+
+               if (__eglSurface)
+               {
+                       eglDestroySurface(__eglDisplay, __eglSurface);
+                       __eglSurface = EGL_NO_SURFACE;
+               }
+
+               eglTerminate(__eglDisplay);
+               __eglDisplay = EGL_NO_DISPLAY;
+       }
+
+       return;
+}
+
+void
+GlesVideoTexture::DestroyVideoTexture(void)
+{
+       if (__textureId != 0)
+       {
+               glDeleteTextures(1, &__textureId);
+       }
+
+       delete __pVideoTexture;
+       __pVideoTexture = null;
+
+       delete __pPlayer;
+       __pPlayer = null;
+}
+
+void
+GlesVideoTexture::Update(void)
+{
+       FloatMatrix4 matPerspective;
+       FloatMatrix4 matModelview;
+
+       __angle += 0.1f;
+
+       if (__angle >= 360.0f)
+       {
+               __angle -= 360.0f;
+       }
+
+       int x, y, width, height;
+       __pForm->GetBounds(x, y, width, height);
+
+       float aspect = float(width) / float(height);
+
+       Perspective(&matPerspective, 50.0f, aspect, 1.0f, 20.0f);
+
+       Translate(&matModelview, 0.0f, 0.0f, -2.0f);
+       Rotate(&matModelview, __angle, 0.0f, 1.0f, 0.0f);
+
+       __matMVP = matPerspective * matModelview;
+}
+
+
+bool
+GlesVideoTexture::Draw(void)
+{
+       if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) == GL_FALSE ||
+                       eglGetError() != EGL_SUCCESS)
+       {
+               AppLog("eglMakeCurrent() failed.");
+
+               return false;
+       }
+
+       int x, y, width, height;
+       __pForm->GetBounds(x, y, width, height);
+
+       glViewport(0, 0, width, height);
+
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       glVertexAttribPointer(__indexPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GL_FLOAT), VERTICES);
+       glVertexAttribPointer(__indexTexture, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GL_FLOAT), TEXTURES);
+
+       glEnableVertexAttribArray(__indexPosition);
+       glEnableVertexAttribArray(__indexTexture);
+
+       glUniformMatrix4fv(__indexMVP, 1, GL_FALSE, (GLfloat*)__matMVP.matrix);
+       glUniform1i(__indexTextureSample, 0);
+
+       result r = __pVideoTexture->BindTexture();
+       TryReturn(!IsFailed(r), false, "__pVideoTexture->BindTexture() failed. %s", GetErrorMessage(r));
+
+       glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, INDICES);
+
+       eglSwapBuffers(__eglDisplay, __eglSurface);
+
+#ifdef DISPLAY_FPS
+       static float     fps = 0.0f;
+       static float     updateInterval = 1000.0f;
+       static float     timeSinceLastUpdate = 0.0f;
+       static float     frameCount = 0;
+       static long long currentTick;
+       static long long lastTick;
+       static bool      isFirst = true;
+
+       if (isFirst)
+       {
+               SystemTime::GetTicks(currentTick);
+               lastTick = currentTick;
+               isFirst = false;
+       }
+
+       frameCount++;
+       SystemTime::GetTicks(currentTick);
+
+       float elapsed = currentTick - lastTick;
+
+       lastTick = currentTick;
+       timeSinceLastUpdate += elapsed;
+
+       if (timeSinceLastUpdate > updateInterval)
+       {
+               if (timeSinceLastUpdate)
+               {
+                       fps = (frameCount / timeSinceLastUpdate) * 1000.f;
+                       AppLog("FPS: %f frames/sec", fps);
+
+                       frameCount = 0;
+                       timeSinceLastUpdate -= updateInterval;
+               }
+       }
+#endif
+
+       return true;
+}
+
+
+void
+GlesVideoTexture::Frustum(FloatMatrix4* pResult, float left, float right, float bottom, float top, float near, float far)
+{
+    float diffX = right - left;
+    float diffY = top - bottom;
+    float diffZ = far - near;
+
+    if ((near <= 0.0f) || (far <= 0.0f) ||
+        (diffX <= 0.0f) || (diffY <= 0.0f) || (diffZ <= 0.0f))
+       {
+       return;
+       }
+
+    pResult->matrix[0][0] = 2.0f * near / diffX;
+    pResult->matrix[1][1] = 2.0f * near / diffY;
+    pResult->matrix[2][0] = (right + left) / diffX;
+    pResult->matrix[2][1] = (top + bottom) / diffY;
+    pResult->matrix[2][2] = -(near + far) / diffZ;
+    pResult->matrix[2][3] = -1.0f;
+    pResult->matrix[3][2] = -2.0f * near * far / diffZ;
+
+    pResult->matrix[0][1] = pResult->matrix[0][2] = pResult->matrix[0][3] = 0.0f;
+    pResult->matrix[1][0] = pResult->matrix[1][2] = pResult->matrix[1][3] = 0.0f;
+    pResult->matrix[3][0] = pResult->matrix[3][1] = pResult->matrix[3][3] = 0.0f;
+}
+
+void
+GlesVideoTexture::Perspective(FloatMatrix4* pResult, float fovY, float aspect, float near, float far)
+{
+       float fovRadian = fovY / 360.0f * PI;
+       float top = tanf(fovRadian) * near;
+       float right = top * aspect;
+
+       Frustum(pResult, -right, right, -top, top, near, far);
+}
+
+void
+GlesVideoTexture::Translate(FloatMatrix4* pResult, float tx, float ty, float tz)
+{
+       pResult->matrix[3][0] += (pResult->matrix[0][0] * tx + pResult->matrix[1][0] * ty + pResult->matrix[2][0] * tz);
+       pResult->matrix[3][1] += (pResult->matrix[0][1] * tx + pResult->matrix[1][1] * ty + pResult->matrix[2][1] * tz);
+    pResult->matrix[3][2] += (pResult->matrix[0][2] * tx + pResult->matrix[1][2] * ty + pResult->matrix[2][2] * tz);
+    pResult->matrix[3][3] += (pResult->matrix[0][3] * tx + pResult->matrix[1][3] * ty + pResult->matrix[2][3] * tz);
+}
+
+void
+GlesVideoTexture::Rotate(FloatMatrix4* pResult, float angle, float x, float y, float z)
+{
+       FloatMatrix4 rotate;
+
+       float cos = cosf(angle * PI / 180.0f);
+       float sin = sinf(angle * PI / 180.0f);
+       float cos1 = 1.0f - cos;
+
+       FloatVector4 vector(x, y, z, 0.0f);
+       vector.Normalize();
+       x = vector.x;
+       y = vector.y;
+       z = vector.z;
+
+       rotate.matrix[0][0] = (x * x) * cos1 + cos;
+       rotate.matrix[0][1] = (x * y) * cos1 - z * sin;
+       rotate.matrix[0][2] = (z * x) * cos1 + y * sin;
+       rotate.matrix[0][3] = 0.0f;
+
+       rotate.matrix[1][0] = (x * y) * cos1 + z * sin;
+       rotate.matrix[1][1] = (y * y) * cos1 + cos;
+       rotate.matrix[1][2] = (y * z) * cos1 - x * sin;
+       rotate.matrix[1][3] = 0.0f;
+
+       rotate.matrix[2][0] = (z * x) * cos1 - y * sin;
+       rotate.matrix[2][1] = (y * z) * cos1 + x * sin;
+       rotate.matrix[2][2] = (z * z) * cos1 + cos;
+
+       rotate.matrix[2][3] = rotate.matrix[3][0] = rotate.matrix[3][1] = rotate.matrix[3][2] = 0.0f;
+       rotate.matrix[3][3] = 1.0f;
+
+       *pResult *= rotate;
+}
+
+void
+GlesVideoTexture::OnTextureUpdated(Tizen::Graphics::Opengl::VideoTexture* pVideoTexture)
+{
+       __isVideoTextureReady = true;
+}
diff --git a/project/src/GlesVideoTextureEntry.cpp b/project/src/GlesVideoTextureEntry.cpp
new file mode 100644 (file)
index 0000000..76385f9
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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.
+//
+
+/**
+ * This file contains the Tizen C++ application entry point.
+ */
+#include "GlesVideoTexture.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+
+_EXPORT_ int OspMain(int argc, char* pArgv[]);
+
+
+/**
+ * The entry function of Tizen C++ application called by the operating system.
+ */
+int
+OspMain(int argc, char* pArgv[])
+{
+       AppLog("Application started.");
+       ArrayList args;
+       args.Construct();
+
+       for (int i = 0; i < argc; i++)
+       {
+               args.Add(*(new (std::nothrow) String(pArgv[i])));
+       }
+
+       result r = Tizen::App::Application::Execute(GlesVideoTexture::CreateInstance, &args);
+
+       TryLog(r == E_SUCCESS, "[%s] Application execution failed", GetErrorMessage(r));
+
+       args.RemoveAll(true);
+       AppLog("Application finished.");
+
+       return static_cast<int>(r);
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/sample.xml b/sample.xml
new file mode 100644 (file)
index 0000000..0f706b0
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<template>
+                
+       <slp-property>
+               <property-group>
+                       <sample-name>GlesVideoTexture</sample-name>
+                       <category>Sample</category>
+                       <sdk-version>1.00</sdk-version>
+                       <project-type>org.tizen.nativecpp.buildArtefactType.app</project-type>                  
+                       <sample-description>description.xml</sample-description>
+               </property-group>
+       </slp-property>
+       
+       <process type="org.tizen.nativeappcommon.TizenCopyFolder">
+               <simple name="projectName" value="$(projectName)"/>
+               <simple name="folderPath" value="project"/>
+               <complex-array name="replaceableFiles">
+                 <element>
+                               <simple name="sourcePath" value="manifest.xml"/>
+                               <simple name="targetPath" value="manifest.xml"/>
+                               <simple name="replaceable" value = "true"/>
+                       </element>
+               </complex-array>
+       </process>
+       <process type="org.tizen.nativecpp.SetDefaultFrameworks">
+               <simple name="projectName" value="$(projectName)"/>
+               <complex-array name="frameworkList">
+                       <element>
+                               <simple name="framework" value="osp"/>
+                       </element>
+               </complex-array>
+       </process>
+       
+</template>
diff --git a/screenshot.png b/screenshot.png
new file mode 100644 (file)
index 0000000..7a8a36d
Binary files /dev/null and b/screenshot.png differ