4dc66bb4b2403b5781c60ecb365db838142a5392
[platform/core/uifw/pepper-dali.git] / pepper-dali / internal / output-impl.h
1 #ifndef __DALI_PEPPER_INTERNAL_OUTPUT_H__
2 #define __DALI_PEPPER_INTERNAL_OUTPUT_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <pepper-dali/internal/output.h>
23 #include <pepper-dali/internal/object.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/public-api/common/intrusive-ptr.h>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/object/base-object.h>
29 #include <dali/public-api/signals/connection-tracker.h>
30 #include <dali/integration-api/adaptors/thread-synchronization-interface.h>
31 #include <pepper-output-backend.h>
32
33 // TODO: temp
34 #include <dali/public-api/adaptor-framework/timer.h>
35
36 namespace Dali
37 {
38
39 namespace Pepper
40 {
41
42 namespace Internal
43 {
44
45 class Output;
46 typedef IntrusivePtr<Output> OutputPtr;
47
48 class Output : public BaseObject, public ConnectionTracker, public ThreadSynchronizationInterface
49 {
50 public:
51
52   static OutputPtr New( Pepper::Compositor compositor, Application application, Pepper::Input input );
53
54   static void OnDestroy( void* data );
55   static int32_t OnGetSubpixelOrder( void* data );
56   static const char* OnGetMakerName( void* data );
57   static const char* OnGetModelName( void* data );
58   static int OnGetModeCount( void* data );
59   static void OnGetMode( void* data, int index, pepper_output_mode_t* mode );
60   static pepper_bool_t OnSetMode( void* data, const pepper_output_mode_t* mode );
61   static void OnAssignPlanes( void* data, const pepper_list_t* viewList );
62   static void OnStartRepaintLoop( void* data );
63   static void OnRepaint( void* data, const pepper_list_t* planeList );
64   static void OnAttachSurface( void* data, pepper_surface_t* surface, int* width, int* height );
65   static void OnFlushSurface( void* data, pepper_surface_t* surface, pepper_bool_t* keepBuffer );
66
67 public: //Signals
68
69   Pepper::Output::OutputSignalType& ObjectViewAddedSignal();
70   Pepper::Output::OutputSignalType& ObjectViewDeletedSignal();
71
72 private:
73
74   /**
75    * Construct a new Output.
76    */
77   Output();
78
79   /**
80    * A reference counted object may only be deleted by calling Unreference()
81    */
82   virtual ~Output();
83
84   /**
85    * Second-phase constructor. Must be called immediately after creating a new Output;
86    */
87   void Initialize( Pepper::Compositor& compositor, Application application, Pepper::Input input );
88
89   void OnResize( Application& application );
90
91   void OnObjectViewAdded( Pepper::Object object, Pepper::ObjectView objectView );
92   void OnObjectViewDeleted( Pepper::Object object, Pepper::ObjectView objectView );
93
94 private: // From ThreadSynchronizationInterface
95
96   /////////////////////////////////////////////////////////////////////////////////////////////////
97   // Called by the Event Thread if post-rendering is required
98   /////////////////////////////////////////////////////////////////////////////////////////////////
99
100   /**
101    * @copydoc ThreadSynchronizationInterface::PostRenderComplete()
102    */
103   virtual void PostRenderComplete();
104
105   /////////////////////////////////////////////////////////////////////////////////////////////////
106   //// Called by the Render Thread if post-rendering is required
107   /////////////////////////////////////////////////////////////////////////////////////////////////
108
109   /**
110    * @copydoc ThreadSynchronizationInterface::PostRenderStarted()
111    */
112   virtual void PostRenderStarted();
113
114   /**
115    * @copydoc ThreadSynchronizationInterface::PostRenderStarted()
116    */
117   virtual void PostRenderWaitForCompletion();
118
119   // TODO: temp
120   bool OnRenderFinishTimerTick();
121
122 private:
123
124   // Undefined
125   Output( const Output& );
126
127   // Undefined
128   Output& operator=( const Output& rhs );
129
130 private: // Data
131
132   Pepper::Compositor mCompositor;
133
134   Vector2 mSize;
135
136   Pepper::Input mInput;
137   std::vector<Pepper::Object> mObjectList;
138
139   pepper_output_t* mOutput;
140   pepper_plane_t* mPrimaryPlane;
141
142   // Signals
143   Pepper::Output::OutputSignalType mObjectViewAddedSignal;
144   Pepper::Output::OutputSignalType mObjectViewDeletedSignal;
145
146   bool mRepaintRequest;
147
148   // TODO: temp
149   Timer mRenderFinishTimer;
150 };
151
152 } // namespace Internal
153
154 // Helpers for public-api forwarding methods
155
156 inline Pepper::Internal::Output& GetImplementation( Pepper::Output& output )
157 {
158   DALI_ASSERT_ALWAYS( output && "Output handle is empty" );
159
160   BaseObject& handle = output.GetBaseObject();
161
162   return static_cast< Internal::Output& >( handle );
163 }
164
165 inline const Pepper::Internal::Output& GetImplementation( const Pepper::Output& output )
166 {
167   DALI_ASSERT_ALWAYS( output && "Output handle is empty" );
168
169   const BaseObject& handle = output.GetBaseObject();
170
171   return static_cast< const Internal::Output& >( handle );
172 }
173
174 } // namespace Pepper
175
176 } // namespace Dali
177
178 #endif // __DALI_PEPPER_INTERNAL_OUTPUT_H__