2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/window-render-surface.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/gl-abstraction.h>
26 #include <dali/integration-api/adaptor-framework/thread-synchronization-interface.h>
27 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
29 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
30 #include <dali/internal/graphics/gles/egl-graphics.h>
31 #include <dali/internal/graphics/gles/egl-implementation.h>
32 #include <dali/internal/system/common/environment-variables.h>
33 #include <dali/internal/window-system/common/window-base.h>
34 #include <dali/internal/window-system/common/window-factory.h>
35 #include <dali/internal/window-system/common/window-system.h>
45 const int MINIMUM_DIMENSION_CHANGE(1); ///< Minimum change for window to be considered to have moved
46 const float FULL_UPDATE_RATIO(0.8f); ///< Force full update when the dirty area is larget than this ratio
48 #if defined(DEBUG_ENABLED)
49 Debug::Filter* gWindowRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_WINDOW_RENDER_SURFACE");
52 void MergeRects(Rect<int>& mergingRect, const std::vector<Rect<int>>& rects)
55 if(mergingRect.IsEmpty())
57 for(; i < rects.size(); i++)
59 if(!rects[i].IsEmpty())
61 mergingRect = rects[i];
67 for(; i < rects.size(); i++)
69 mergingRect.Merge(rects[i]);
73 void InsertRects(WindowRenderSurface::DamagedRectsContainer& damagedRectsList, const std::vector<Rect<int>>& damagedRects)
75 damagedRectsList.push_front(damagedRects);
76 if(damagedRectsList.size() > 4) // past triple buffers + current
78 damagedRectsList.pop_back();
82 Rect<int32_t> RecalculateRect0(Rect<int32_t>& rect, const Rect<int32_t>& surfaceSize)
87 Rect<int32_t> RecalculateRect90(Rect<int32_t>& rect, const Rect<int32_t>& surfaceSize)
89 Rect<int32_t> newRect;
90 newRect.x = surfaceSize.height - (rect.y + rect.height);
92 newRect.width = rect.height;
93 newRect.height = rect.width;
97 Rect<int32_t> RecalculateRect180(Rect<int32_t>& rect, const Rect<int32_t>& surfaceSize)
99 Rect<int32_t> newRect;
100 newRect.x = surfaceSize.width - (rect.x + rect.width);
101 newRect.y = surfaceSize.height - (rect.y + rect.height);
102 newRect.width = rect.width;
103 newRect.height = rect.height;
107 Rect<int32_t> RecalculateRect270(Rect<int32_t>& rect, const Rect<int32_t>& surfaceSize)
109 Rect<int32_t> newRect;
111 newRect.y = surfaceSize.width - (rect.x + rect.width);
112 newRect.width = rect.height;
113 newRect.height = rect.width;
117 using RecalculateRectFunction = Rect<int32_t> (*)(Rect<int32_t>&, const Rect<int32_t>&);
119 RecalculateRectFunction RecalculateRect[4] = {RecalculateRect0, RecalculateRect90, RecalculateRect180, RecalculateRect270};
121 } // unnamed namespace
123 WindowRenderSurface::WindowRenderSurface(Dali::PositionSize positionSize, Any surface, bool isTransparent)
125 mDisplayConnection(nullptr),
126 mPositionSize(positionSize),
128 mThreadSynchronization(nullptr),
129 mRenderNotification(nullptr),
130 mRotationTrigger(nullptr),
131 mFrameRenderedTrigger(),
133 mEGLSurface(nullptr),
134 mEGLContext(nullptr),
135 mColorDepth(isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24),
136 mOutputTransformedSignal(),
137 mFrameCallbackInfoContainer(),
138 mBufferDamagedRects(),
140 mWindowRotationAngle(0),
141 mScreenRotationAngle(0),
145 mWindowRotationFinished(true),
146 mScreenRotationFinished(true),
147 mResizeFinished(true),
148 mDefaultScreenRotationAvailable(false)
150 DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n");
154 WindowRenderSurface::~WindowRenderSurface()
158 delete mRotationTrigger;
162 void WindowRenderSurface::Initialize(Any surface)
164 // If width or height are zero, go full screen.
165 if((mPositionSize.width == 0) || (mPositionSize.height == 0))
167 // Default window size == screen size
170 WindowSystem::GetScreenSize(mPositionSize.width, mPositionSize.height);
173 // Create a window base
174 auto windowFactory = Dali::Internal::Adaptor::GetWindowFactory();
175 mWindowBase = windowFactory->CreateWindowBase(mPositionSize, surface, (mColorDepth == COLOR_DEPTH_32 ? true : false));
178 mWindowBase->OutputTransformedSignal().Connect(this, &WindowRenderSurface::OutputTransformed);
180 // Check screen rotation
181 mScreenRotationAngle = mWindowBase->GetScreenRotationAngle();
182 if(mScreenRotationAngle != 0)
184 mScreenRotationFinished = false;
185 mResizeFinished = false;
186 mDefaultScreenRotationAvailable = true;
187 DALI_LOG_RELEASE_INFO("WindowRenderSurface::Initialize, screen rotation is enabled, screen rotation angle:[%d]\n", mScreenRotationAngle);
191 Any WindowRenderSurface::GetNativeWindow()
193 return mWindowBase->GetNativeWindow();
196 int WindowRenderSurface::GetNativeWindowId()
198 return mWindowBase->GetNativeWindowId();
201 void WindowRenderSurface::Map()
206 void WindowRenderSurface::SetRenderNotification(TriggerEventInterface* renderNotification)
208 mRenderNotification = renderNotification;
211 void WindowRenderSurface::SetTransparency(bool transparent)
213 mWindowBase->SetTransparency(transparent);
216 void WindowRenderSurface::RequestRotation(int angle, int width, int height)
218 if(!mRotationTrigger)
220 mRotationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessRotationRequest), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
223 mPositionSize.width = width;
224 mPositionSize.height = height;
226 mWindowRotationAngle = angle;
227 mWindowRotationFinished = false;
229 mWindowBase->SetWindowRotationAngle(mWindowRotationAngle);
231 DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: angle = %d screen rotation = %d\n", mWindowRotationAngle, mScreenRotationAngle);
234 WindowBase* WindowRenderSurface::GetWindowBase()
236 return mWindowBase.get();
239 WindowBase::OutputSignalType& WindowRenderSurface::OutputTransformedSignal()
241 return mOutputTransformedSignal;
244 PositionSize WindowRenderSurface::GetPositionSize() const
246 return mPositionSize;
249 void WindowRenderSurface::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
251 if(mDpiHorizontal == 0 || mDpiVertical == 0)
253 const char* environmentDpiHorizontal = std::getenv(DALI_ENV_DPI_HORIZONTAL);
254 mDpiHorizontal = environmentDpiHorizontal ? std::atoi(environmentDpiHorizontal) : 0;
256 const char* environmentDpiVertical = std::getenv(DALI_ENV_DPI_VERTICAL);
257 mDpiVertical = environmentDpiVertical ? std::atoi(environmentDpiVertical) : 0;
259 if(mDpiHorizontal == 0 || mDpiVertical == 0)
261 mWindowBase->GetDpi(mDpiHorizontal, mDpiVertical);
265 dpiHorizontal = mDpiHorizontal;
266 dpiVertical = mDpiVertical;
269 int WindowRenderSurface::GetOrientation() const
271 return mWindowBase->GetOrientation();
274 void WindowRenderSurface::InitializeGraphics()
276 mGraphics = &mAdaptor->GetGraphicsInterface();
278 DALI_ASSERT_ALWAYS(mGraphics && "Graphics interface is not created");
280 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
281 mEGL = &eglGraphics->GetEglInterface();
283 if(mEGLContext == NULL)
285 // Create the OpenGL context for this window
286 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
287 eglImpl.ChooseConfig(true, mColorDepth);
288 eglImpl.CreateWindowContext(mEGLContext);
290 // Create the OpenGL surface
295 void WindowRenderSurface::CreateSurface()
297 DALI_LOG_TRACE_METHOD(gWindowRenderSurfaceLogFilter);
300 if(mScreenRotationAngle == 0 || mScreenRotationAngle == 180)
302 width = mPositionSize.width;
303 height = mPositionSize.height;
307 width = mPositionSize.height;
308 height = mPositionSize.width;
311 // Create the EGL window
312 EGLNativeWindowType window = mWindowBase->CreateEglWindow(width, height);
314 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
316 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
317 mEGLSurface = eglImpl.CreateSurfaceWindow(window, mColorDepth);
319 DALI_LOG_RELEASE_INFO("WindowRenderSurface::CreateSurface: WinId (%d), w = %d h = %d angle = %d screen rotation = %d\n",
320 mWindowBase->GetNativeWindowId(),
322 mPositionSize.height,
323 mWindowRotationAngle,
324 mScreenRotationAngle);
327 void WindowRenderSurface::DestroySurface()
329 DALI_LOG_TRACE_METHOD(gWindowRenderSurfaceLogFilter);
331 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
334 DALI_LOG_RELEASE_INFO("WindowRenderSurface::DestroySurface: WinId (%d)\n", mWindowBase->GetNativeWindowId());
336 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
338 eglImpl.DestroySurface(mEGLSurface);
339 mEGLSurface = nullptr;
341 // Destroy context also
342 eglImpl.DestroyContext(mEGLContext);
343 mEGLContext = nullptr;
345 mWindowBase->DestroyEglWindow();
349 bool WindowRenderSurface::ReplaceGraphicsSurface()
351 DALI_LOG_TRACE_METHOD(gWindowRenderSurfaceLogFilter);
353 // Destroy the old one
354 mWindowBase->DestroyEglWindow();
357 if(mScreenRotationAngle == 0 || mScreenRotationAngle == 180)
359 width = mPositionSize.width;
360 height = mPositionSize.height;
364 width = mPositionSize.height;
365 height = mPositionSize.width;
368 // Create the EGL window
369 EGLNativeWindowType window = mWindowBase->CreateEglWindow(width, height);
371 // Set screen rotation
372 mScreenRotationFinished = false;
374 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
376 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
377 return eglImpl.ReplaceSurfaceWindow(window, mEGLSurface, mEGLContext);
380 void WindowRenderSurface::MoveResize(Dali::PositionSize positionSize)
382 bool needToMove = false;
383 bool needToResize = false;
386 if((fabs(positionSize.x - mPositionSize.x) >= MINIMUM_DIMENSION_CHANGE) ||
387 (fabs(positionSize.y - mPositionSize.y) >= MINIMUM_DIMENSION_CHANGE))
393 if((fabs(positionSize.width - mPositionSize.width) >= MINIMUM_DIMENSION_CHANGE) ||
394 (fabs(positionSize.height - mPositionSize.height) >= MINIMUM_DIMENSION_CHANGE))
403 mWindowBase->MoveResize(positionSize);
407 mWindowBase->Resize(positionSize);
410 mResizeFinished = false;
411 mPositionSize = positionSize;
417 mWindowBase->Move(positionSize);
419 mPositionSize = positionSize;
423 DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height);
426 void WindowRenderSurface::StartRender()
430 bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
432 Dali::Integration::Scene::FrameCallbackContainer callbacks;
434 Dali::Integration::Scene scene = mScene.GetHandle();
437 bool needFrameRenderedTrigger = false;
439 scene.GetFrameRenderedCallback(callbacks);
440 if(!callbacks.empty())
442 int frameRenderedSync = mWindowBase->CreateFrameRenderedSyncFence();
443 if(frameRenderedSync != -1)
445 Dali::Mutex::ScopedLock lock(mMutex);
447 DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: CreateFrameRenderedSyncFence [%d]\n", frameRenderedSync);
449 mFrameCallbackInfoContainer.push_back(std::unique_ptr<FrameCallbackInfo>(new FrameCallbackInfo(callbacks, frameRenderedSync)));
451 needFrameRenderedTrigger = true;
455 DALI_LOG_ERROR("WindowRenderSurface::PreRender: CreateFrameRenderedSyncFence is failed\n");
462 scene.GetFramePresentedCallback(callbacks);
463 if(!callbacks.empty())
465 int framePresentedSync = mWindowBase->CreateFramePresentedSyncFence();
466 if(framePresentedSync != -1)
468 Dali::Mutex::ScopedLock lock(mMutex);
470 DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: CreateFramePresentedSyncFence [%d]\n", framePresentedSync);
472 mFrameCallbackInfoContainer.push_back(std::unique_ptr<FrameCallbackInfo>(new FrameCallbackInfo(callbacks, framePresentedSync)));
474 needFrameRenderedTrigger = true;
478 DALI_LOG_ERROR("WindowRenderSurface::PreRender: CreateFramePresentedSyncFence is failed\n");
485 if(needFrameRenderedTrigger)
487 if(!mFrameRenderedTrigger)
489 mFrameRenderedTrigger = std::unique_ptr<TriggerEventInterface>(TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessFrameCallback),
490 TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
492 mFrameRenderedTrigger->Trigger();
496 MakeContextCurrent();
499 * wl_egl_window_tizen_set_rotation(SetEglWindowRotation) -> PreRotation
500 * wl_egl_window_tizen_set_buffer_transform(SetEglWindowBufferTransform) -> Screen Rotation
501 * wl_egl_window_tizen_set_window_transform(SetEglWindowTransform) -> Window Rotation
502 * These function should be called before calling first drawing gl Function.
503 * Notice : PreRotation is not used in the latest tizen,
504 * because output transform event should be occured before egl window is not created.
507 if(resizingSurface || mDefaultScreenRotationAvailable)
509 int totalAngle = (mWindowRotationAngle + mScreenRotationAngle) % 360;
511 // Window rotate or screen rotate
512 if(!mWindowRotationFinished || !mScreenRotationFinished)
514 mWindowBase->SetEglWindowBufferTransform(totalAngle);
516 // Reset only screen rotation flag
517 mScreenRotationFinished = true;
519 DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set rotation [%d] [%d]\n", mWindowRotationAngle, mScreenRotationAngle);
522 // Only window rotate
523 if(!mWindowRotationFinished)
525 mWindowBase->SetEglWindowTransform(mWindowRotationAngle);
531 Dali::PositionSize positionSize;
532 positionSize.x = mPositionSize.x;
533 positionSize.y = mPositionSize.y;
534 if(totalAngle == 0 || totalAngle == 180)
536 positionSize.width = mPositionSize.width;
537 positionSize.height = mPositionSize.height;
541 positionSize.width = mPositionSize.height;
542 positionSize.height = mPositionSize.width;
544 mWindowBase->ResizeEglWindow(positionSize);
545 mResizeFinished = true;
547 DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize\n");
550 SetFullSwapNextFrame();
551 mDefaultScreenRotationAvailable = false;
554 SetBufferDamagedRects(damagedRects, clippingRect);
559 void WindowRenderSurface::PostRender(bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects)
561 // Inform the gl implementation that rendering has finished before informing the surface
562 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
565 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
577 if(!mWindowRotationFinished)
579 if(mThreadSynchronization)
581 // Enable PostRender flag
582 mThreadSynchronization->PostRenderStarted();
585 DALI_LOG_RELEASE_INFO("WindowRenderSurface::PostRender: Trigger rotation event\n");
587 mRotationTrigger->Trigger();
589 if(mThreadSynchronization)
591 // Wait until the event-thread complete the rotation event processing
592 mThreadSynchronization->PostRenderWaitForCompletion();
598 SwapBuffers(damagedRects);
600 if(mRenderNotification)
602 mRenderNotification->Trigger();
607 void WindowRenderSurface::StopRender()
611 void WindowRenderSurface::SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization)
613 DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::SetThreadSynchronization: called\n");
615 mThreadSynchronization = &threadSynchronization;
618 void WindowRenderSurface::ReleaseLock()
623 Dali::RenderSurfaceInterface::Type WindowRenderSurface::GetSurfaceType()
625 return Dali::RenderSurfaceInterface::WINDOW_RENDER_SURFACE;
628 void WindowRenderSurface::MakeContextCurrent()
632 mEGL->MakeContextCurrent(mEGLSurface, mEGLContext);
636 Integration::DepthBufferAvailable WindowRenderSurface::GetDepthBufferRequired()
638 return mGraphics ? mGraphics->GetDepthBufferRequired() : Integration::DepthBufferAvailable::FALSE;
641 Integration::StencilBufferAvailable WindowRenderSurface::GetStencilBufferRequired()
643 return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE;
646 void WindowRenderSurface::OutputTransformed()
648 int screenRotationAngle = mWindowBase->GetScreenRotationAngle();
650 if(mScreenRotationAngle != screenRotationAngle)
652 mScreenRotationAngle = screenRotationAngle;
653 mScreenRotationFinished = false;
654 mResizeFinished = false;
656 mOutputTransformedSignal.Emit();
658 DALI_LOG_RELEASE_INFO("WindowRenderSurface::OutputTransformed: window = %d screen = %d\n", mWindowRotationAngle, mScreenRotationAngle);
662 DALI_LOG_RELEASE_INFO("WindowRenderSurface::OutputTransformed: Ignore output transform [%d]\n", mScreenRotationAngle);
666 void WindowRenderSurface::ProcessRotationRequest()
668 mWindowRotationFinished = true;
670 mWindowBase->WindowRotationCompleted(mWindowRotationAngle, mPositionSize.width, mPositionSize.height);
672 DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::ProcessRotationRequest: Rotation Done\n");
674 if(mThreadSynchronization)
676 mThreadSynchronization->PostRenderComplete();
680 void WindowRenderSurface::ProcessFrameCallback()
682 Dali::Mutex::ScopedLock lock(mMutex);
684 for(auto&& iter : mFrameCallbackInfoContainer)
686 if(!iter->fileDescriptorMonitor)
688 iter->fileDescriptorMonitor = std::unique_ptr<FileDescriptorMonitor>(new FileDescriptorMonitor(iter->fileDescriptor,
689 MakeCallback(this, &WindowRenderSurface::OnFileDescriptorEventDispatched),
690 FileDescriptorMonitor::FD_READABLE));
692 DALI_LOG_RELEASE_INFO("WindowRenderSurface::ProcessFrameCallback: Add handler [%d]\n", iter->fileDescriptor);
697 void WindowRenderSurface::OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor)
699 if(!(eventBitMask & FileDescriptorMonitor::FD_READABLE))
701 DALI_LOG_ERROR("WindowRenderSurface::OnFileDescriptorEventDispatched: file descriptor error [%d]\n", eventBitMask);
702 close(fileDescriptor);
706 DALI_LOG_RELEASE_INFO("WindowRenderSurface::OnFileDescriptorEventDispatched: Frame rendered [%d]\n", fileDescriptor);
708 std::unique_ptr<FrameCallbackInfo> callbackInfo;
710 Dali::Mutex::ScopedLock lock(mMutex);
711 auto frameCallbackInfo = std::find_if(mFrameCallbackInfoContainer.begin(), mFrameCallbackInfoContainer.end(), [fileDescriptor](std::unique_ptr<FrameCallbackInfo>& callbackInfo) {
712 return callbackInfo->fileDescriptor == fileDescriptor;
714 if(frameCallbackInfo != mFrameCallbackInfoContainer.end())
716 callbackInfo = std::move(*frameCallbackInfo);
718 mFrameCallbackInfoContainer.erase(frameCallbackInfo);
722 // Call the connected callback
725 for(auto&& iter : (callbackInfo)->callbacks)
727 CallbackBase::Execute(*(iter.first), iter.second);
732 void WindowRenderSurface::SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
734 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
737 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
738 if(!eglImpl.IsPartialUpdateRequired())
743 Rect<int> surfaceRect(0, 0, mPositionSize.width, mPositionSize.height);
745 if(mFullSwapNextFrame)
747 InsertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
748 clippingRect = Rect<int>();
752 EGLint bufferAge = eglImpl.GetBufferAge(mEGLSurface);
754 // Buffer age 0 means the back buffer in invalid and requires full swap
755 if(!damagedRects.size() || bufferAge == 0)
757 InsertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
758 clippingRect = Rect<int>();
762 // We push current frame damaged rects here, zero index for current frame
763 InsertRects(mBufferDamagedRects, damagedRects);
765 // Merge damaged rects into clipping rect
766 auto bufferDamagedRects = mBufferDamagedRects.begin();
767 while(bufferAge-- >= 0 && bufferDamagedRects != mBufferDamagedRects.end())
769 const std::vector<Rect<int>>& rects = *bufferDamagedRects++;
770 MergeRects(clippingRect, rects);
773 if(!clippingRect.Intersect(surfaceRect) || clippingRect.Area() > surfaceRect.Area() * FULL_UPDATE_RATIO)
775 // clipping area too big or doesn't intersect surface rect
776 clippingRect = Rect<int>();
780 std::vector<Rect<int>> damagedRegion;
781 Dali::Integration::Scene scene = mScene.GetHandle();
784 damagedRegion.push_back(RecalculateRect[std::min(scene.GetCurrentSurfaceOrientation() / 90, 3)](clippingRect, scene.GetCurrentSurfaceRect()));
788 damagedRegion.push_back(clippingRect);
791 eglImpl.SetDamageRegion(mEGLSurface, damagedRegion);
795 void WindowRenderSurface::SwapBuffers(const std::vector<Rect<int>>& damagedRects)
797 auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
800 Rect<int32_t> surfaceRect;
801 int32_t orientation = 0;
803 Dali::Integration::Scene scene = mScene.GetHandle();
806 surfaceRect = scene.GetCurrentSurfaceRect();
807 orientation = std::min(scene.GetCurrentSurfaceOrientation() / 90, 3);
810 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
812 if(!eglImpl.IsPartialUpdateRequired() || mFullSwapNextFrame || !damagedRects.size() || (damagedRects[0].Area() > surfaceRect.Area() * FULL_UPDATE_RATIO))
814 mFullSwapNextFrame = false;
815 eglImpl.SwapBuffers(mEGLSurface);
819 mFullSwapNextFrame = false;
821 std::vector<Rect<int>> mergedRects = damagedRects;
823 // Merge intersecting rects, form an array of non intersecting rects to help driver a bit
824 // Could be optional and can be removed, needs to be checked with and without on platform
825 const int n = mergedRects.size();
826 for(int i = 0; i < n - 1; i++)
828 if(mergedRects[i].IsEmpty())
833 for(int j = i + 1; j < n; j++)
835 if(mergedRects[j].IsEmpty())
840 if(mergedRects[i].Intersects(mergedRects[j]))
842 mergedRects[i].Merge(mergedRects[j]);
843 mergedRects[j].width = 0;
844 mergedRects[j].height = 0;
850 for(int i = 0; i < n; i++)
852 if(!mergedRects[i].IsEmpty())
854 mergedRects[j++] = RecalculateRect[orientation](mergedRects[i], surfaceRect);
860 mergedRects.resize(j);
863 if(!mergedRects.size() || (mergedRects[0].Area() > surfaceRect.Area() * FULL_UPDATE_RATIO))
865 eglImpl.SwapBuffers(mEGLSurface);
869 eglImpl.SwapBuffers(mEGLSurface, mergedRects);
874 } // namespace Adaptor
876 } // namespace Internal