[dali_2.3.38] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / legacy / common / tizen-platform-abstraction.h
1 #ifndef DALI_TIZEN_PLATFORM_ABSTRACTION_H
2 #define DALI_TIZEN_PLATFORM_ABSTRACTION_H
3
4 /*
5  * Copyright (c) 2024 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 <dali/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/dali-adaptor-common.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/integration-api/platform-abstraction.h>
27 #include <cstdint>
28 #include <memory>
29 #include <string>
30
31 namespace Dali
32 {
33 class CallbackBase;
34
35 namespace TizenPlatform
36 {
37 class ResourceLoader;
38
39 /**
40  * Concrete implementation of the platform abstraction class.
41  */
42 class TizenPlatformAbstraction : public Integration::PlatformAbstraction
43 {
44 public: // Construction & Destruction
45   /**
46    * Constructor
47    */
48   TizenPlatformAbstraction();
49
50   /**
51    * Destructor
52    */
53   ~TizenPlatformAbstraction() override;
54
55 public: // PlatformAbstraction overrides
56   /**
57    * @copydoc PlatformAbstraction::GetClosestImageSize()
58    */
59   ImageDimensions GetClosestImageSize(const std::string& filename,
60                                       ImageDimensions    size,
61                                       FittingMode::Type  fittingMode,
62                                       SamplingMode::Type samplingMode,
63                                       bool               orientationCorrection) override;
64
65   /**
66    * @copydoc PlatformAbstraction::GetClosestImageSize()
67    */
68   ImageDimensions GetClosestImageSize(Integration::ResourcePointer resourceBuffer,
69                                       ImageDimensions              size,
70                                       FittingMode::Type            fittingMode,
71                                       SamplingMode::Type           samplingMode,
72                                       bool                         orientationCorrection) override;
73
74   /**
75    * @copydoc PlatformAbstraction::LoadImageSynchronously()
76    */
77   Integration::ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath) override;
78
79   /**
80    * @copydoc PlatformAbstraction::DecodeBuffer()
81    */
82   Integration::BitmapPtr DecodeBuffer(const Integration::BitmapResourceType& resource, uint8_t* buffer, size_t size) override;
83
84   /**
85    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
86    */
87   bool LoadShaderBinaryFile(const std::string& filename, Dali::Vector<unsigned char>& buffer) const override;
88
89   /**
90    * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
91    */
92   bool SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const override;
93
94   /**
95    * @copydoc PlatformAbstraction::StartTimer()
96    */
97   uint32_t StartTimer(uint32_t milliseconds, CallbackBase* callback) override;
98
99   /**
100    * @copydoc PlatformAbstraction::CancelTimer()
101    */
102   void CancelTimer(uint32_t timerId) override;
103
104   /**
105    * Sets path for data/resource storage.
106    * @param[in] path data/resource storage path
107    */
108   void SetDataStoragePath(const std::string& path);
109
110   /**
111    * Clears the timers that have completed
112    */
113   void CleanupTimers();
114
115 private:
116   struct TimerCallback;
117
118   /*
119    * Executes callback function and cleans up timer
120    */
121   void RunTimerFunction(TimerCallback& timerPtr);
122
123   /**
124    * @brief Requests cleanup of timers into idler.
125    */
126   void RequestCleanupTimers();
127
128   TizenPlatformAbstraction(const TizenPlatformAbstraction&);            ///< Undefined
129   TizenPlatformAbstraction& operator=(const TizenPlatformAbstraction&); ///< Undefined
130
131   std::string mDataStoragePath;
132
133   std::vector<std::unique_ptr<TimerCallback> > mTimerPairsWaiting;
134   std::vector<std::unique_ptr<TimerCallback> > mTimerPairsSpent;
135
136   Dali::CallbackBase* mCleanupIdleCallback;
137 };
138
139 /**
140  * Construct a platform abstraction and return it.
141  * @return TizenPlatformAbstraction instance
142  */
143 TizenPlatformAbstraction* CreatePlatformAbstraction();
144
145 /**
146  * Save a file to disk
147  * @param filename to create
148  * @param buffer to store
149  * @param numBytes to store
150  * @return true if successful, false otherwise
151  */
152 bool SaveFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes);
153
154 } // namespace TizenPlatform
155
156 } // namespace Dali
157
158 #endif // DALI_TIZEN_PLATFORM_ABSTRACTION_H