1 #ifndef DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/render/renderers/render-frame-buffer.h>
26 #include <dali/integration-api/render-surface.h>
39 class SurfaceFrameBuffer : public FrameBuffer
45 * @param[in] surface The render surface
47 SurfaceFrameBuffer( Integration::RenderSurface* surface );
52 virtual ~SurfaceFrameBuffer();
55 * @copydoc Dali::Internal::Renderer::FrameBuffer::Initialize()
57 void Initialize( Context& context ) override;
60 * @copydoc Dali::Internal::Renderer::FrameBuffer::Destroy()
62 void Destroy( Context& context ) override;
65 * @copydoc Dali::Internal::Renderer::FrameBuffer::GlContextDestroyed()
67 void GlContextDestroyed() override;
70 * @copydoc Dali::Internal::Renderer::FrameBuffer::Bind()
72 void Bind( Context& context ) override;
75 * @copydoc Dali::Internal::Renderer::FrameBuffer::GetWidth()
77 uint32_t GetWidth() const override;
80 * @copydoc Dali::Internal::Renderer::FrameBuffer::GetHeight()
82 uint32_t GetHeight() const override;
85 * @copydoc Dali::Internal::Renderer::FrameBuffer::IsSurfaceBacked()
87 bool IsSurfaceBacked() override { return true; };
90 * @brief Sets the frame buffer size.
91 * @param[in] width The width size
92 * @param[in] height The height size
94 void SetSize( uint32_t width, uint32_t height );
97 * @brief Sets the background color.
98 * @param[in] color The new background color
100 void SetBackgroundColor( const Vector4& color );
103 * @copydoc Dali::Internal::FrameBuffer::MarkSurfaceAsInvalid()
105 void MarkSurfaceAsInvalid() { mIsSurfaceInvalid = true; };
108 * @brief Gets whether the render surface in this frame buffer is valid or not
109 * @note The render surface becomes invalid when it is deleted in the event thread
110 * @return Whether the render surface is valid or not
112 bool IsSurfaceValid() const;
117 * Called after this frame buffer is rendered in the render manager
122 * Gets the context holding the GL state of rendering for the surface
123 * @return the context
125 Context* GetContext();
128 * @brief Makes the graphics context current
130 void MakeContextCurrent();
133 * @brief Gets the background color of the surface.
134 * @return The background color
136 Vector4 GetBackgroundColor();
140 Integration::RenderSurface* mSurface; ///< The render surface
141 Context* mContext; ///< The context holding the GL state of rendering for the surface backed frame buffer
145 Vector4 mBackgroundColor;
147 std::atomic<bool> mIsSurfaceInvalid; ///< This is set only from the event thread and read only from the render thread
150 // Messages for FrameBuffer
151 inline void SetFrameBufferSizeMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, uint32_t width, uint32_t height )
153 typedef MessageValue2< SurfaceFrameBuffer, uint32_t, uint32_t > LocalType;
155 // Reserve some memory inside the message queue
156 uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
158 // Construct message in the message queue memory; note that delete should not be called on the return value
159 new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetSize, width, height );
162 inline void SetFrameBufferBackgroundColorMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, const Vector4& color )
164 typedef MessageValue1< SurfaceFrameBuffer, Vector4 > LocalType;
166 // Reserve some memory inside the message queue
167 uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
169 // Construct message in the message queue memory; note that delete should not be called on the return value
170 new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetBackgroundColor, color );
173 } // namespace Render
175 } // namespace Internal
180 #endif // DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H