Merge "[Tizen][AT-SPI] Rework intercepting key events" into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
index 2ecd85e..a77acc2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/public-api/dali-adaptor-common.h>
 
 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
-#include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
+#include <dali/internal/graphics/gles/egl-graphics.h>
 
 #include <dali/devel-api/text-abstraction/font-client.h>
 
 #include <dali/internal/accessibility/common/tts-player-impl.h>
-#include <dali/internal/clipboard/common/clipboard-impl.h>
 #include <dali/internal/graphics/common/egl-image-extensions.h>
 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
 #include <dali/internal/graphics/gles/gl-implementation.h>
 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
 #include <dali/internal/system/common/callback-manager.h>
 #include <dali/internal/system/common/object-profiler.h>
+#include <dali/internal/system/common/system-factory.h>
 #include <dali/internal/window-system/common/display-connection.h>
 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
 #include <dali/internal/window-system/common/event-handler.h>
@@ -162,7 +162,7 @@ void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
   mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
   mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
 
-  mCallbackManager = CallbackManager::New();
+  mCallbackManager = Dali::Internal::Adaptor::GetSystemFactory()->CreateCallbackManager();
 
   Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
 
@@ -181,6 +181,9 @@ void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
                                  mGraphics->GetStencilBufferRequired(),
                                  mGraphics->GetPartialUpdateRequired());
 
+  // Create TextureUploadManager after mCore created
+  mTextureUploadManager = Dali::Devel::TextureUploadManager::Get();
+
   defaultWindow->SetAdaptor(Get());
 
   Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
@@ -322,24 +325,6 @@ void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
   mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
 }
 
-void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
-{
-  Accessibility::KeyEventType type;
-  if(event.GetState() == Dali::KeyEvent::DOWN)
-  {
-    type = Accessibility::KeyEventType::KEY_PRESSED;
-  }
-  else if(event.GetState() == Dali::KeyEvent::UP)
-  {
-    type = Accessibility::KeyEventType::KEY_RELEASED;
-  }
-  else
-  {
-    return;
-  }
-  Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
-}
-
 Adaptor::~Adaptor()
 {
   Accessibility::Bridge::GetCurrentBridge()->Terminate();
@@ -365,7 +350,9 @@ Adaptor::~Adaptor()
 
   delete mDisplayConnection;
   delete mPlatformAbstraction;
-  delete mCallbackManager;
+
+  mCallbackManager.reset();
+
   delete mPerformanceInterface;
 
   mGraphics->Destroy();
@@ -400,7 +387,6 @@ void Adaptor::Start()
   auto bridge  = Accessibility::Bridge::GetCurrentBridge();
   bridge->SetApplicationName(appName);
   bridge->Initialize();
-  Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
 
   Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
 
@@ -568,6 +554,8 @@ void Adaptor::Stop()
 
     mState = STOPPED;
 
+    RemoveSystemInformation();
+
     DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
   }
 }
@@ -656,16 +644,22 @@ Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
   return mTtsPlayers[mode];
 }
 
-bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
 {
   bool idleAdded(false);
 
-  // Only add an idle if the Adaptor is actually running
-  if(RUNNING == mState || READY == mState || forceAdd)
+  // We want to run the processes even when paused
+  if(STOPPED != mState)
   {
     idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
   }
 
+  if(!idleAdded)
+  {
+    // Delete callback
+    delete callback;
+  }
+
   return idleAdded;
 }
 
@@ -844,6 +838,11 @@ void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
   windows = mWindows;
 }
 
+Devel::TextureUploadManager& Adaptor::GetTextureUploadManager()
+{
+  return mTextureUploadManager;
+}
+
 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
 {
   if(mTtsPlayers[mode])
@@ -924,6 +923,16 @@ void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
   }
 }
 
+void Adaptor::FlushUpdateMessages()
+{
+  if(mCore)
+  {
+    DALI_TRACE_SCOPE(gTraceFilter, "DALI_FLUSH_UPDATE_MESSAGES");
+
+    mCore->ForceRelayout();
+  }
+}
+
 void Adaptor::ProcessCoreEvents()
 {
   if(mCore)
@@ -970,11 +979,20 @@ void Adaptor::RequestUpdate()
 
 void Adaptor::RequestProcessEventsOnIdle()
 {
-  // Only request a notification if we haven't installed the idle notification
   // We want to run the processes even when paused
-  if(!mNotificationOnIdleInstalled && STOPPED != mState)
+  if(STOPPED != mState)
   {
-    mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), true);
+    if(!mNotificationOnIdleInstalled)
+    {
+      // If we haven't installed the idle notification, install it idle enterer.
+      mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle));
+    }
+    else
+    {
+      // Request comes during ProcessCoreEventsFromIdle running.
+      // Mark as we need to call ProcessEvents in next idle events.
+      mRequiredIdleRepeat = true;
+    }
   }
 }
 
@@ -1072,6 +1090,15 @@ void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, Surfa
   ProcessCoreEvents();
 }
 
+void Adaptor::IncreaseSurfaceResizeCounter()
+{
+  // Nofify surface resizing before flushing event queue
+  if(mThreadController)
+  {
+    mThreadController->ResizeSurface();
+  }
+}
+
 void Adaptor::NotifySceneCreated()
 {
   GetCore().SceneCreated();
@@ -1124,6 +1151,13 @@ void Adaptor::RenderOnce()
 
       ProcessCoreEvents();
     }
+
+    // Force rendering
+    for(auto&& iter : mWindows)
+    {
+      iter->GetSurface()->SetFullSwapNextFrame();
+    }
+
     mThreadController->RequestUpdateOnce(updateMode);
   }
 }
@@ -1133,6 +1167,11 @@ const LogFactoryInterface& Adaptor::GetLogFactory()
   return *mEnvironmentOptions;
 }
 
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
+{
+  return *mEnvironmentOptions;
+}
+
 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
   GetCore().RegisterProcessor(processor, postProcessor);
@@ -1167,12 +1206,20 @@ void Adaptor::RequestUpdateOnce()
 
 bool Adaptor::ProcessCoreEventsFromIdle()
 {
+  // Reset repeat idler flag.
+  mRequiredIdleRepeat = false;
   ProcessCoreEvents();
 
-  // the idle handle automatically un-installs itself
-  mNotificationOnIdleInstalled = false;
+  // If someone request ProcessCoreEvents during above ProcessCoreEvents call, we might need to run idle one more times.
+  // Else, the idle handle automatically un-installs itself
+  mNotificationOnIdleInstalled = mRequiredIdleRepeat;
 
-  return false;
+  if(mRequiredIdleRepeat)
+  {
+    DALI_LOG_DEBUG_INFO("Required ProcessCoreEvents one more times\n");
+  }
+
+  return mRequiredIdleRepeat;
 }
 
 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
@@ -1244,6 +1291,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mPlatformAbstraction(nullptr),
   mCallbackManager(nullptr),
   mNotificationOnIdleInstalled(false),
+  mRequiredIdleRepeat(false),
   mNotificationTrigger(nullptr),
   mDaliFeedbackPlugin(),
   mFeedbackController(nullptr),
@@ -1253,6 +1301,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mPerformanceInterface(nullptr),
   mKernelTracer(),
   mSystemTracer(),
+  mTextureUploadManager(),
   mObjectProfiler(nullptr),
   mMemoryPoolTimerSlotDelegate(this),
   mSocketFactory(),
@@ -1278,12 +1327,12 @@ void Adaptor::SetRootLayoutDirection(std::string locale)
   }
 }
 
-bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
+bool Adaptor::AddIdleEnterer(CallbackBase* callback)
 {
   bool idleAdded(false);
 
-  // Only add an idle if the Adaptor is actually running
-  if(RUNNING == mState || READY == mState || forceAdd)
+  // We want to run the processes even when paused
+  if(STOPPED != mState)
   {
     idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
   }