[dali_1.2.29] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / frame-buffer-impl.h
1 #ifndef DALI_INTERNAL_FRAME_BUFFER_H
2 #define DALI_INTERNAL_FRAME_BUFFER_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/internal/event/common/event-thread-services.h>
27 #include <dali/internal/event/rendering/texture-impl.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Render
34 {
35 class FrameBuffer;
36 }
37
38 class FrameBuffer;
39 typedef IntrusivePtr<FrameBuffer> FrameBufferPtr;
40
41 class FrameBuffer : public BaseObject
42 {
43 public:
44
45   /**
46    * @brief Create a new FrameBuffer
47    *
48    * @param[in] width       The width of the FrameBuffer
49    * @param[in] height      The height of the FrameBuffer
50    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
51    * @return A smart-pointer to the newly allocated Texture.
52    */
53   static FrameBufferPtr New( unsigned int width, unsigned int height, unsigned int attachments );
54
55   /**
56    * @brief Get the FrameBuffer render object
57    *
58    * @return the FrameBuffer render object
59    */
60   Render::FrameBuffer* GetRenderObject() const;
61
62   /**
63    * @copydoc Dali::FrameBuffer::AttachColorTexture()
64    */
65   void AttachColorTexture( TexturePtr texture, unsigned int mipmapLevel, unsigned int layer );
66
67   /**
68    * @copydoc Dali::FrameBuffer::GetColorTexture()
69    */
70   Texture* GetColorTexture();
71
72 private: // implementation
73
74   /**
75    * Constructor
76    * @param[in] width       The width of the FrameBuffer
77    * @param[in] height      The height of the FrameBuffer
78    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
79    */
80   FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments );
81
82   /**
83    * Second stage initialization of the Texture
84    */
85   void Initialize();
86
87 protected:
88
89   /**
90    * A reference counted object may only be deleted by calling Unreference()
91    */
92   virtual ~FrameBuffer();
93
94 private: // unimplemented methods
95   FrameBuffer( const FrameBuffer& );
96   FrameBuffer& operator=( const FrameBuffer& );
97
98 private: // data
99
100   Internal::EventThreadServices& mEventThreadServices; ///< Used to send messages to the render thread via update thread
101   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
102
103   TexturePtr mColor;
104   unsigned int mWidth;
105   unsigned int mHeight;
106   unsigned int mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
107
108 };
109
110 } // namespace Internal
111
112 // Helpers for public-api forwarding methods
113 inline Internal::FrameBuffer& GetImplementation(Dali::FrameBuffer& handle)
114 {
115   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
116
117   BaseObject& object = handle.GetBaseObject();
118
119   return static_cast<Internal::FrameBuffer&>(object);
120 }
121
122 inline const Internal::FrameBuffer& GetImplementation(const Dali::FrameBuffer& handle)
123 {
124   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
125
126   const BaseObject& object = handle.GetBaseObject();
127
128   return static_cast<const Internal::FrameBuffer&>(object);
129 }
130
131 } // namespace Dali
132
133 #endif // DALI_INTERNAL_FRAME_BUFFER_H