Revert "[3.0] Added missing newline chars to logging commands"
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / emscripten / emscripten-platform-abstraction.h
1 #ifndef __DALI_EMSCRIPTEN_PLATFORM_ABSTRACTION_H__
2 #define __DALI_EMSCRIPTEN_PLATFORM_ABSTRACTION_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 // EXTERNAL INCLUDES
22 #include <set>
23 #include <stdint.h>
24 #include <cstring>
25 #include <queue>
26
27 // INTERNAL INCLUDES
28 #include <dali/integration-api/platform-abstraction.h>
29 #include <dali/integration-api/bitmap.h>
30
31 namespace Dali
32 {
33
34 /**
35  * An Dali Platform abstraction using libSDL for Emscripten.
36  *
37  * Emscripten already wraps the SDL API so we can use this API to create windows/canvas in the browser
38  *
39  */
40 class DALI_IMPORT_API EmscriptenPlatformAbstraction : public Dali::Integration::PlatformAbstraction
41 {
42
43 public:
44
45   struct Resources
46   {
47     bool                         loaded;
48     Integration::ResourceId      loadedId;
49     Integration::ResourceTypeId  loadedType;
50     Integration::ResourcePointer loadedResource;
51
52     bool                         loadFailed;
53     Integration::ResourceId      loadFailedId;
54     Integration::ResourceFailure loadFailure;
55
56     bool                         saved;
57     Integration::ResourceId      savedId;
58     Integration::ResourceTypeId  savedType;
59
60     bool                         saveFailed;
61     Integration::ResourceId      saveFailedId;
62     Integration::ResourceFailure saveFailure;
63   };
64
65   struct LoadFileResult
66   {
67     LoadFileResult()
68     : loadResult(false)
69     {
70
71     }
72
73     bool loadResult;
74     std::vector< unsigned char> buffer;
75   };
76
77
78   /**
79    * Constructor
80    */
81   EmscriptenPlatformAbstraction();
82
83
84   /**
85    * Destructor
86    */
87   virtual ~EmscriptenPlatformAbstraction();
88
89   /**
90    * @copydoc PlatformAbstraction::GetTimeMicroseconds()
91    */
92   virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
93
94   void IncrementGetTimeResult(size_t milliseconds);
95
96   /**
97    * @copydoc PlatformAbstraction::Suspend()
98    */
99   virtual void Suspend();
100
101   /**
102    * @copydoc PlatformAbstraction::Resume()
103    */
104   virtual void Resume();
105
106   /**
107    * @copydoc PlatformAbstraction::GetClosestImageSize()
108    */
109   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
110                                                ImageDimensions size,
111                                                FittingMode::Type fittingMode,
112                                                SamplingMode::Type samplingMode,
113                                                bool orientationCorrection );
114   /**
115    * @copydoc PlatformAbstraction::GetClosestImageSize()
116    */
117   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
118                                                ImageDimensions size,
119                                                FittingMode::Type fittingMode,
120                                                SamplingMode::Type samplingMode,
121                                                bool orientationCorrection );
122
123   /**
124    * @copydoc PlatformAbstraction::LoadResource()
125    */
126   virtual void LoadResource(const Integration::ResourceRequest& request);
127
128   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
129
130   /**
131    * @copydoc PlatformAbstraction::SaveResource()
132    */
133   virtual void SaveResource(const Integration::ResourceRequest& request);
134
135   /**
136    * @copydoc PlatformAbstraction::DecodeBuffer()
137    */
138   virtual Integration::BitmapPtr DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t bufferSize );
139
140   /**
141    * @copydoc PlatformAbstraction::CancelLoad()
142    */
143   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
144
145   /**
146    * @copydoc PlatformAbstraction::GetResources()
147    */
148   virtual void GetResources(Integration::ResourceCache& cache);
149
150   /**
151    * @copydoc PlatformAbstraction::IsLoading()
152    */
153   virtual bool IsLoading();
154
155   /**
156    * @copydoc PlatformAbstraction::GetDefaultFontFamily()
157    */
158   virtual const std::string& GetDefaultFontFamily() const;
159
160   /**
161    * @copydoc PlatformAbstraction::GetDefaultFontSize()
162    */
163   virtual int GetDefaultFontSize() const;
164
165   /**
166    * Sets horizontal and vertical pixels per inch value that is used by the display
167    * @param[in] dpiHorizontal horizontal dpi value
168    * @param[in] dpiVertical   vertical dpi value
169    */
170   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
171
172   /**
173    * @copydoc PlatformAbstraction::LoadFile()
174    */
175   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
176
177   /**
178    * @copydoc PlatformAbstraction::SaveFile()
179    */
180   virtual bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
181
182   /**
183    * @copydoc PlatformAbstraction::JoinLoaderThreads()
184    */
185   virtual void JoinLoaderThreads();
186
187   /**
188    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
189    */
190   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
191
192   /**
193    * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
194    */
195   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
196
197   /**
198    * @copydoc PlatformAbstraction::UpdateDefaultsFromDevice()
199    */
200   virtual void UpdateDefaultsFromDevice();
201
202 private:
203   std::string                   mGetDefaultFontFamilyResult;
204   Resources                     mResources;
205   Vector2                       mSize;
206
207   LoadFileResult                mLoadFileResult;
208
209   typedef std::pair< Integration::ResourceId, Integration::BitmapPtr > ResourceIdBitmapPair;
210   std::queue<ResourceIdBitmapPair> mResourceQueue;
211
212 };
213
214 } // Dali
215
216 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */