CEFInterfaceBrowserApp.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Engine/Source/Runtime/WebBrowser/Private/CEF/CEFBrowserApp.cpp
  2. #include "CEF/CEFInterfaceBrowserApp.h"
  3. #include "HAL/IConsoleManager.h"
  4. #if WITH_CEF3
  5. #include "WebInterfaceBrowserLog.h"
  6. //#define DEBUG_CEFMESSAGELOOP_FRAMERATE 1 // uncomment this to have debug spew about the FPS we call the CefDoMessageLoopWork function
  7. DEFINE_LOG_CATEGORY(LogCEFInterfaceBrowser);
  8. /*
  9. static bool bCEFGPUAcceleration = true;
  10. static FAutoConsoleVariableRef CVarCEFGPUAcceleration(
  11. TEXT("r.CEFGPUAcceleration"),
  12. bCEFGPUAcceleration,
  13. TEXT("Enables GPU acceleration in CEF\n"),
  14. ECVF_Default);
  15. */
  16. FCEFInterfaceBrowserApp::FCEFInterfaceBrowserApp(bool bInGPU)
  17. : MessagePumpCountdown(0)
  18. , bGPU(bInGPU)
  19. {
  20. }
  21. void FCEFInterfaceBrowserApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> CommandLine)
  22. {
  23. }
  24. void FCEFInterfaceBrowserApp::OnBeforeCommandLineProcessing(const CefString& ProcessType, CefRefPtr< CefCommandLine > CommandLine)
  25. {
  26. if (bGPU)
  27. {
  28. UE_LOG(LogCEFInterfaceBrowser, Log, TEXT("CEF GPU acceleration enabled"));
  29. CommandLine->AppendSwitch("enable-gpu");
  30. CommandLine->AppendSwitch("enable-gpu-compositing");
  31. }
  32. else
  33. {
  34. UE_LOG(LogCEFInterfaceBrowser, Log, TEXT("CEF GPU acceleration disabled"));
  35. CommandLine->AppendSwitch("disable-gpu");
  36. CommandLine->AppendSwitch("disable-gpu-compositing");
  37. }
  38. #if PLATFORM_LINUX
  39. CommandLine->AppendSwitchWithValue("ozone-platform", "headless");
  40. CommandLine->AppendSwitchWithValue("use-gl", "angle");
  41. CommandLine->AppendSwitchWithValue("use-angle", "vulkan");
  42. CommandLine->AppendSwitch("use-vulkan");
  43. #endif
  44. CommandLine->AppendSwitch("enable-begin-frame-scheduling");
  45. CommandLine->AppendSwitch("disable-pinch"); // the web pages we have don't expect zoom to work right now so disable touchpad pinch zoom
  46. CommandLine->AppendSwitch("disable-gpu-shader-disk-cache"); // Don't create a "GPUCache" directory when cache-path is unspecified.
  47. #if PLATFORM_MAC
  48. CommandLine->AppendSwitch("use-mock-keychain"); // Disable the toolchain prompt on macOS.
  49. #endif
  50. }
  51. void FCEFInterfaceBrowserApp::OnScheduleMessagePumpWork(int64 delay_ms)
  52. {
  53. FScopeLock Lock(&MessagePumpCountdownCS);
  54. // As per CEF documentation, if delay_ms is <= 0, then the call to CefDoMessageLoopWork should happen reasonably soon. If delay_ms is > 0, then the call
  55. // to CefDoMessageLoopWork should be scheduled to happen after the specified delay and any currently pending scheduled call should be canceled.
  56. if(delay_ms < 0)
  57. {
  58. delay_ms = 0;
  59. }
  60. MessagePumpCountdown = delay_ms;
  61. }
  62. bool FCEFInterfaceBrowserApp::TickMessagePump(float DeltaTime, bool bForce)
  63. {
  64. bool bPump = false;
  65. {
  66. FScopeLock Lock(&MessagePumpCountdownCS);
  67. // count down in order to call message pump
  68. if (MessagePumpCountdown >= 0)
  69. {
  70. MessagePumpCountdown -= (DeltaTime * 1000);
  71. if (MessagePumpCountdown <= 0)
  72. {
  73. bPump = true;
  74. }
  75. if (bPump || bForce)
  76. {
  77. // -1 indicates that no countdown is currently happening
  78. MessagePumpCountdown = -1;
  79. }
  80. }
  81. }
  82. #ifdef DEBUG_CEFMESSAGELOOP_FRAMERATE
  83. static float SecondsFrameRate = 0;
  84. static int NumFrames = 0;
  85. SecondsFrameRate += DeltaTime;
  86. #endif
  87. if (bPump || bForce)
  88. {
  89. #ifdef DEBUG_CEFMESSAGELOOP_FRAMERATE
  90. ++NumFrames;
  91. if (NumFrames % 100 == 0 || SecondsFrameRate > 5.0f)
  92. {
  93. UE_LOG(LogWebBrowser, Error, TEXT("CefDoMessageLoopWork call Frame Rate %0.2f"), NumFrames / SecondsFrameRate);
  94. SecondsFrameRate = 0;
  95. NumFrames = 0;
  96. }
  97. #endif
  98. CefDoMessageLoopWork();
  99. return true;
  100. }
  101. return false;
  102. }
  103. #endif