1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
21 #include <dali/public-api/actors/image-actor.h>
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/shader-effects/shader-effect.h>
24 #include <dali/internal/common/event-to-update.h>
25 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
26 #include <dali/internal/update/resources/bitmap-metadata.h>
34 // value types used by messages
35 template <> struct ParameterType< Dali::ImageActor::Style >
36 : public BasicType< Dali::ImageActor::Style > {};
45 * An attachment for rendering images in various ways.
47 class ImageAttachment : public RenderableAttachment
51 typedef Dali::ImageActor::Style Style;
52 typedef Dali::ImageActor::PixelArea PixelArea;
55 * Create a new ImageAttachment.
56 * @param [in] textureId The resource ID of a texture.
57 * @return The newly allocated ImageAttachment.
59 static ImageAttachment* New( unsigned int textureId );
64 virtual ~ImageAttachment();
67 * @copydoc RenderableAttachment::GetRenderer().
69 virtual Renderer& GetRenderer();
72 * @copydoc RenderableAttachment::GetRenderer().
74 virtual const Renderer& GetRenderer() const;
77 * Set the ID used to retrieve a texture from ResourceManager.
78 * @param[in] updateBufferIndex The current update buffer index.
79 * @param[in] textureId The texture ID.
81 void SetTextureId( BufferIndex updateBufferIndex, unsigned int textureId );
84 * Set the area of the texture to display.
85 * @param[in] updateBufferIndex The current update buffer index.
86 * @param [in] pixelArea The area to display, in pixels relative to the top-left (0,0) of the image.
88 void SetPixelArea( BufferIndex updateBufferIndex, const PixelArea& pixelArea );
91 * Query whether a pixel area has been set.
92 * @return True if a pixel area has been set.
94 bool IsPixelAreaSet() const
96 return mIsPixelAreaSet;
100 * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
101 * @pre image must be initialized.
103 void ClearPixelArea();
106 * Set how the attachment is rendered; the default is STYLE_QUAD.
107 * @param [in] style The new style.
109 void SetStyle( Style style );
112 * Retrieve how the attachment is rendered.
121 * Set the border; this is applied with STYLE_NINE_PATCH.
122 * @param [in] updateBufferIndex to use.
123 * @param [in] border The new border setting.
124 * @param [in] inPixels if the border is in pixels.
126 void SetBorder( BufferIndex updateBufferIndex, const Vector4& border, bool inPixels );
129 * @copydoc RenderableAttachment::ShaderChanged()
131 virtual void ShaderChanged( BufferIndex updateBufferIndex );
134 * @copydoc RenderableAttachment::SizeChanged()
136 virtual void SizeChanged( BufferIndex updateBufferIndex );
139 * @copydoc RenderableAttachment::DoPrepareRender()
141 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
144 * @copydoc RenderableAttachment::IsFullyOpaque()
146 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex );
151 * Protected constructor
153 ImageAttachment( unsigned int textureId );
158 * @copydoc RenderableAttachment::ConnectToSceneGraph2().
160 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
163 * @copydoc RenderableAttachment::OnDestroy2().
165 virtual void OnDestroy2();
168 * @copydoc RenderableAttachment::DoPrepareResources()
170 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
172 // Helper to check whether a geometry hint was set
173 bool PreviousHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const
175 return mPreviousRefreshHints & hint;
179 ImageAttachment(const ImageAttachment&);
182 ImageAttachment& operator=(const ImageAttachment& rhs);
186 ImageRenderer* mImageRenderer; ///< Raw-pointers to renderer that is owned by RenderManager
187 unsigned int mTextureId; ///< The resource ID for a texture
189 // bitfields to fit in single byte
190 bool mRefreshMeshData : 1; ///< Whether the vertex/index buffers needs regenerating
191 bool mIsPixelAreaSet : 1; ///< Whether pixel area is set, cached for image actor to be able to ask for it
192 int mPreviousRefreshHints : 4; ///< The shader geometry hints, when the vertex buffer was last refreshed, 4 bits is enough as there's 4 flags
193 Style mStyle : 2; ///< rendering style, 2 bits is enough as only 2 values in the enum
195 BitmapMetadata mBitmapMetadata;///< The bitmap metadata
196 Vector2 mGeometrySize; ///< The size of the currently used geometry
200 // Messages for ImageAttachment
202 inline void SetTextureIdMessage( EventToUpdate& eventToUpdate, const ImageAttachment& attachment, unsigned int id )
204 typedef MessageDoubleBuffered1< ImageAttachment, unsigned int > LocalType;
206 // Reserve some memory inside the message queue
207 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
209 // Construct message in the message queue memory; note that delete should not be called on the return value
210 new (slot) LocalType( &attachment, &ImageAttachment::SetTextureId, id );
213 inline void SetPixelAreaMessage( EventToUpdate& eventToUpdate, const ImageAttachment& attachment, const Dali::ImageActor::PixelArea& area )
215 typedef MessageDoubleBuffered1< ImageAttachment, Dali::ImageActor::PixelArea > LocalType;
217 // Reserve some memory inside the message queue
218 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
220 // Construct message in the message queue memory; note that delete should not be called on the return value
221 new (slot) LocalType( &attachment, &ImageAttachment::SetPixelArea, area );
224 inline void ClearPixelAreaMessage( EventToUpdate& eventToUpdate, const ImageAttachment& attachment )
226 typedef Message< ImageAttachment > LocalType;
228 // Reserve some memory inside the message queue
229 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
231 // Construct message in the message queue memory; note that delete should not be called on the return value
232 new (slot) LocalType( &attachment, &ImageAttachment::ClearPixelArea );
235 inline void SetStyleMessage( EventToUpdate& eventToUpdate, const ImageAttachment& attachment, Dali::ImageActor::Style style )
237 typedef MessageValue1< ImageAttachment, Dali::ImageActor::Style > LocalType;
239 // Reserve some memory inside the message queue
240 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
242 // Construct message in the message queue memory; note that delete should not be called on the return value
243 new (slot) LocalType( &attachment, &ImageAttachment::SetStyle, style );
246 inline void SetNinePatchBorderMessage( EventToUpdate& eventToUpdate, const ImageAttachment& attachment, const Vector4& border, bool inPixels )
248 typedef MessageDoubleBuffered2< ImageAttachment, Vector4, bool > LocalType;
250 // Reserve some memory inside the message queue
251 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
253 // Construct message in the message queue memory; note that delete should not be called on the return value
254 new (slot) LocalType( &attachment, &ImageAttachment::SetBorder, border, inPixels );
257 } // namespace SceneGraph
259 } // namespace Internal
263 #endif // __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__