Remove RenderableActor
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / image-attachment-impl.h
1 #ifndef __DALI_INTERNAL_IMAGE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_IMAGE_ATTACHMENT_H__
3
4 /*
5  * Copyright (c) 2014 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/actors/image-actor.h>
23 #include <dali/public-api/actors/blending.h>
24 #include <dali/devel-api/rendering/cull-face.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/image-sampler.h>
27 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
28 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
29 #include <dali/internal/event/images/image-impl.h>
30 #include <dali/internal/event/images/image-connector.h>
31 #include <dali/internal/event/effects/shader-declarations.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace SceneGraph
40 {
41 class ImageAttachment;
42 class Node;
43 }
44
45 /**
46  * An attachment for rendering images in various ways.
47  */
48 class ImageAttachment : public RenderableAttachment
49 {
50 public:
51
52   typedef Dali::ImageActor::Style Style;
53   typedef Dali::ImageActor::PixelArea PixelArea;
54
55   /**
56    * Create a new ImageAttachment.
57    * @param[in] eventThreadServices to use
58    * @param[in] parentNode The node to attach a scene-object to.
59    * @return A smart-pointer to the newly allocated ImageAttachment.
60    */
61   static ImageAttachmentPtr New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode );
62
63   /**
64    * Sets image rendered by the attachment.
65    * @param [in] image A pointer to the image to display or NULL to clear. Reference to avoid unnecessary increment/decrement reference count.
66    */
67   void SetImage( ImagePtr& image );
68
69   /**
70    * Retrieve the image rendered by the attachment.
71    * @return The image or an uninitialized image in case the ImageActor was cleared.
72    */
73   ImagePtr GetImage();
74
75   /**
76    * Set a region of the image to display, in pixels.
77    * @param [in] pixelArea The area of the image to display.
78    * This in pixels, relative to the top-left (0,0) of the image.
79    */
80   void SetPixelArea(const PixelArea& pixelArea);
81
82   /**
83    * Retrieve the region of the image to display, in pixels.
84    * @return The pixel area, or a default-constructed area if none was set.
85    */
86   const PixelArea& GetPixelArea() const
87   {
88     // This is not animatable; the cached value is up-to-date.
89     return mPixelArea;
90   }
91
92   /**
93    * Query whether a pixel area has been set.
94    * @return True if a pixel area has been set.
95    */
96   bool IsPixelAreaSet() const
97   {
98     // This is not animatable; the cached value is up-to-date.
99     return mIsPixelAreaSet;
100   }
101
102   /**
103    * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
104    * @pre image must be initialized.
105    */
106   void ClearPixelArea();
107
108   /**
109    * Set how the ImageAttachment is rendered; the default is STYLE_QUAD.
110    * @param [in] style The new style.
111    */
112   void SetStyle(Style style);
113
114   /**
115    * Query how the image is rendered.
116    * @return The rendering style.
117    */
118   Style GetStyle()
119   {
120     // This is not animatable; the cached value is up-to-date.
121     return mStyle;
122   }
123
124   /**
125    * @copydoc Dali::ImageActor::SetNinePatchBorder
126    */
127   void SetNinePatchBorder(const Vector4& border, bool inPixels);
128
129   /**
130    * @copydoc Dali::ImageActor::GetNinePatchBorder
131    */
132   Vector4 GetNinePatchBorder()
133   {
134     // This is not animatable; the cached value is up-to-date.
135     return mBorder;
136   }
137
138
139   /**
140    * Set the depth-sort modifier for the renderable.
141    * This modifies the back-to-front distance calculation, when rendering with transparency.
142    * This is useful for ordering transparent objects that are positioned close to each other.
143    * @param[in] modifier The depth-sort modifier.
144    */
145   void SetSortModifier(float modifier);
146
147   /**
148    * From Renderable; Retrieve the depth-sort modifier for the renderable.
149    * @return The depth-sort modifier.
150    */
151   float GetSortModifier() const;
152
153   /**
154    * Set the face-culling mode for this attachment.
155    * @param[in] mode The culling mode.
156    */
157   void SetCullFace(CullFaceMode mode);
158
159   /**
160    * Retrieve the face-culling mode for this attachment.
161    * @return mode The culling mode.
162    */
163   CullFaceMode GetCullFace() const;
164
165   /**
166    * @copydoc Dali::RenderableActor::SetBlendMode()
167    */
168   void SetBlendMode( BlendingMode::Type mode );
169
170   /**
171    * @copydoc Dali::RenderableActor::GetBlendMode()
172    */
173   BlendingMode::Type GetBlendMode() const;
174
175   /**
176    * @copydoc Dali::RenderableActor::SetBlendFunc()
177    */
178   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
179                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
180
181   /**
182    * @copydoc Dali::RenderableActor::GetBlendFunc()
183    */
184   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
185                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
186
187   /**
188    * @copydoc Dali::RenderableActor::SetBlendEquation()
189    */
190   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
191
192   /**
193    * @copydoc Dali::RenderableActor::GetBlendEquation()
194    */
195   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
196
197   /**
198    * @copydoc Dali::RenderableActor::SetBlendColor()
199    */
200   void SetBlendColor( const Vector4& color );
201
202   /**
203    * @copydoc Dali::RenderableActor::GetBlendColor()
204    */
205   const Vector4& GetBlendColor() const;
206
207   /**
208    * @copydoc Dali::RenderableActor::SetFilterMode()
209    */
210   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
211
212   /**
213    * @copydoc Dali::RenderableActor::GetFilterMode()
214    */
215   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
216
217   /**
218    * @copydoc Dali::RenderableActor::SetShaderEffect
219    */
220   void SetShaderEffect(ShaderEffect& effect);
221
222   /**
223    * @copydoc Dali::RenderableActor::GetShaderEffect
224    */
225   ShaderEffectPtr GetShaderEffect() const;
226
227   /**
228    * @copydoc Dali::RenderableActor::RemoveShaderEffect
229    */
230   void RemoveShaderEffect();
231
232 private:
233
234   /**
235    * First stage construction of a ImageAttachment.
236    * @param[in] eventThreadServices Used for messaging to and reading from scene-graph.
237    */
238   ImageAttachment( EventThreadServices& eventThreadServices );
239
240   /**
241    * Creates the corresponding scene-graph ImageAttachment.
242    * @return A newly allocated scene object.
243    */
244   static SceneGraph::ImageAttachment* CreateSceneObject();
245
246   /**
247    * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
248    */
249   virtual void OnStageConnection2();
250
251   /**
252    * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
253    */
254   virtual void OnStageDisconnection2();
255
256   /**
257    * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
258    */
259   const SceneGraph::ImageAttachment& GetSceneObject() const;
260
261 protected:
262
263   /**
264    * A reference counted object may only be deleted by calling Unreference()
265    */
266   virtual ~ImageAttachment();
267
268 private:
269
270   const SceneGraph::ImageAttachment* mSceneObject; ///< Not owned
271
272   ImageConnector mImageConnectable; ///< Manages the image displayed by the attachment
273
274   // Cached for public getters
275
276   PixelArea mPixelArea;
277
278   Style mStyle;
279   Vector4 mBorder;
280
281   bool mIsPixelAreaSet : 1;
282   bool mBorderInPixels : 1;
283
284   BlendingOptions    mBlendingOptions;
285   unsigned int       mSamplerBitfield;
286   float              mSortModifier;
287   CullFaceMode       mCullFaceMode:3;  ///< cullface mode, 3 bits enough for 4 values
288   BlendingMode::Type mBlendingMode:2;  ///< blending mode, 2 bits enough for 3 values
289
290   ShaderEffectPtr    mShaderEffect;    ///< Optional referenced shader effect
291 };
292
293 } // namespace Internal
294
295 } // namespace Dali
296
297 #endif // __DALI_INTERNAL_IMAGE_ATTACHMENT_H__