Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / graphics / opengl / FGrp_VideoTexture.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrp_VideoTexture.h
20  * @brief       This is the header file for VideoTexture class.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_VIDEO_TEXTURE_H_
25 #define _FGRP_INTERNAL_VIDEO_TEXTURE_H_
26
27 #include <X11/Xlib.h>
28 #include <X11/extensions/Xdamage.h>
29
30 #include <FGraphicsOpengl2.h>
31 #include <FBaseRtThread.h>
32 #include <FGrpIVideoTextureUpdateListener.h>
33
34 namespace Tizen { namespace Graphics {
35 class Bitmap;
36 }}
37
38 namespace Tizen { namespace Graphics { namespace Opengl
39 {
40
41 const int _VIDEO_TEXTURE_BUFFER_MAX = 4;
42
43 class VideoTexture;
44 class _VideoTexture;
45
46 enum _BufferState
47 {
48         _BUFFER_STATE_FREE = 0,
49         _BUFFER_STATE_DEQUEUE,
50         _BUFFER_STATE_ENQUEUE,
51 };
52
53 struct _VideoTextureBuffer
54 {
55         Tizen::Graphics::Bitmap* __pBitmap;
56         EGLNativePixmapType __nativePixmap;
57         EGLImageKHR     __eglImage;
58         long long __timeStamp;
59         _BufferState __bufferState;
60         EGLSyncKHR __eglSync;
61 };
62
63 class _DamageEvent
64         : public Tizen::Base::Runtime::Thread
65 {
66 public:
67         _DamageEvent(void);
68         virtual ~_DamageEvent(void);
69         result Construct(_VideoTexture* pVideoTexture);
70         Object* Run(void);
71
72 private:
73         Drawable __pixmap[_VIDEO_TEXTURE_BUFFER_MAX];
74         Damage __damage[_VIDEO_TEXTURE_BUFFER_MAX];
75         Display* __pDisplay;
76     int __eventBaseReturn;
77     _VideoTexture* __pVideoTexture;
78
79     friend class _VideoTexture;
80 };
81
82 class _VideoTexture
83 {
84 public:
85         _VideoTexture(void);
86         virtual ~_VideoTexture(void);
87
88         result Construct(int textureId, int width, int height);
89
90         result BindTexture(void);
91         void AddVideoTextureUpdateListener(IVideoTextureUpdateListener& listener, VideoTexture* pVideoTexture);
92         void RemoveVideoTextureUpdateListener(IVideoTextureUpdateListener& listener);
93
94         bool IsSupported(Tizen::Base::String string);
95         Pixmap GetPixmap(void);
96
97
98 private:
99         _VideoTexture(const _VideoTexture& rhs);
100         _VideoTexture& operator =(const _VideoTexture& rhs);
101
102 public:
103         IVideoTextureUpdateListener* pVideoTextureUpdateListener;
104
105 private:
106         result Release(void);
107         int FindFreeBuffer(void);
108
109         _VideoTextureBuffer __pBuffer[_VIDEO_TEXTURE_BUFFER_MAX];
110         int __textureId;
111         bool __isEglSyncAvailable;
112         int __glVersion;
113         EGLDisplay __eglDisplay;
114         PFNEGLCREATESYNCKHRPROC __funcEglCreateSyncKhr;
115         PFNEGLCLIENTWAITSYNCKHRPROC __funcEglClientWaitSyncKhr;
116         PFNEGLDESTROYSYNCKHRPROC __funcEglDestroySyncKhr;
117         PFNGLEGLIMAGETARGETTEXTURE2DOESPROC __funcGlEglImageTargetTexture2dOes;
118         _DamageEvent* __pDamageEvent;
119         VideoTexture* __pVideoTexture;
120         int __currentReadingBuffer;
121
122         friend class _DamageEvent;
123 }; // _VideoTexture
124
125 }}} // Tizen::Graphics
126
127 #endif //_FGRP_INTERNAL_VIDEO_TEXTURE_H_