d2a624c4f61c27a04a6d8443dd2f41b97111d8eb
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / animated-image-loading-impl.h
1 #ifndef DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H
2 #define DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/dali-vector.h>
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
29 #include <dali/public-api/dali-adaptor-common.h>
30
31 namespace Dali
32 {
33 class PixelData;
34 typedef Dali::Uint16Pair ImageDimensions;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class AnimatedImageLoading;
41 typedef IntrusivePtr<AnimatedImageLoading> AnimatedImageLoadingPtr;
42
43 /**
44  * Class interface for animated image loading.
45  * Each loading classes for animated image file format(e.g., gif and webp) needs to inherit this interface
46  */
47 class AnimatedImageLoading : public BaseObject
48 {
49 public:
50   /**
51    * @copydoc Dali::AnimatedImageLoading::New()
52    */
53   static AnimatedImageLoadingPtr New(const std::string& url, bool isLocalResource);
54
55   AnimatedImageLoading() = default;
56
57   // Moveable but not copyable
58   AnimatedImageLoading(const AnimatedImageLoading&);
59   AnimatedImageLoading& operator               =(const AnimatedImageLoading&);
60   AnimatedImageLoading(AnimatedImageLoading&&) = default;
61   AnimatedImageLoading& operator=(AnimatedImageLoading&&) = default;
62
63   /**
64    * @brief Destructor
65    */
66   ~AnimatedImageLoading() override = default;
67
68   /**
69    * @copydoc Dali::AnimatedImageLoading::LoadNextNFrames()
70    */
71   virtual bool LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData) = 0;
72
73   /**
74    * @copydoc Dali::AnimatedImageLoading::LoadFrame()
75    */
76   virtual Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) = 0;
77
78   /**
79    * @copydoc Dali::AnimatedImageLoading::GetImageSize()
80    */
81   virtual ImageDimensions GetImageSize() const = 0;
82
83   /**
84    * @copydoc Dali::AnimatedImageLoading::GetImageCount()
85    */
86   virtual uint32_t GetImageCount() const = 0;
87
88   /**
89    * @copydoc Dali::AnimatedImageLoading::LoadFrameDelays()
90    */
91   virtual uint32_t GetFrameInterval(uint32_t frameIndex) const = 0;
92
93   /**
94    * @copydoc Dali::AnimatedImageLoading::GetUrl()
95    */
96   virtual std::string GetUrl() const = 0;
97
98   /**
99    * @copydoc Dali::AnimatedImageLoading::HasLoadingSucceeded()
100    */
101   virtual bool HasLoadingSucceeded() const = 0;
102 };
103
104 } // namespace Adaptor
105
106 } // namespace Internal
107
108 // Helpers for api forwarding methods
109
110 inline Internal::Adaptor::AnimatedImageLoading& GetImplementation(Dali::AnimatedImageLoading& handle)
111 {
112   DALI_ASSERT_ALWAYS(handle && "AnimatedImageLoading handle is empty");
113
114   BaseObject& object = handle.GetBaseObject();
115
116   return static_cast<Internal::Adaptor::AnimatedImageLoading&>(object);
117 }
118
119 inline const Internal::Adaptor::AnimatedImageLoading& GetImplementation(const Dali::AnimatedImageLoading& handle)
120 {
121   DALI_ASSERT_ALWAYS(handle && "AnimatedImageLoading handle is empty");
122
123   const BaseObject& object = handle.GetBaseObject();
124
125   return static_cast<const Internal::Adaptor::AnimatedImageLoading&>(object);
126 }
127
128 } // namespace Dali
129
130 #endif // DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H