#define DALI_H
/*
- * 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.
// Application / UI Framework adaption
#include <dali/public-api/adaptor-framework/application.h>
#include <dali/public-api/adaptor-framework/device-status.h>
+#include <dali/public-api/adaptor-framework/graphics-backend.h>
#include <dali/public-api/adaptor-framework/input-method.h>
#include <dali/public-api/adaptor-framework/key-grab.h>
#include <dali/public-api/adaptor-framework/key.h>
// INTERNAL INCLUDES
#include <dali/internal/window-system/common/display-utils.h>
+#include <dali/public-api/adaptor-framework/graphics-backend.h>
#if defined(VULKAN_ENABLED)
#include <dali/internal/graphics/vulkan/vulkan-graphics-factory.h>
AdaptorBuilder::AdaptorBuilder(EnvironmentOptions& environmentOptions)
: mEnvironmentOptions(environmentOptions)
{
+ switch(Graphics::GetCurrentGraphicsBackend())
+ {
+ case Graphics::Backend::GLES:
+ {
+ DALI_LOG_RELEASE_INFO("DALi Graphics Backend: GLES\n");
+ // TODO: Load GLES library
+ break;
+ }
+
+ case Graphics::Backend::VULKAN:
+ {
+ DALI_LOG_RELEASE_INFO("DALi Graphics Backend: VULKAN\n");
+ // TODO: Attempt to load Vulkan library
+ break;
+ }
+ }
+
// Construct Graphics Factory
mGraphicsFactory = Utils::MakeUnique<GraphicsFactory>(environmentOptions);
}
#include <dali/internal/window-system/common/window-impl.h>
#include <dali/internal/window-system/common/window-render-surface.h>
#include <dali/internal/window-system/common/window-system.h>
+#include <dali/public-api/adaptor-framework/graphics-backend.h>
// To disable a macro with the same name from one of OpenGL headers
#undef Status
{
mEnvironmentOptions = std::unique_ptr<EnvironmentOptions>(new EnvironmentOptions());
+ // Call will be ignored if this function has already been called by the application.
+ Graphics::SetGraphicsBackend(mEnvironmentOptions->GetGraphicsBackend());
+
mFramework->AddAbortCallback(MakeCallback(this, &Application::QuitFromMainLoop));
auto& adaptorBuilder = AdaptorBuilder::Get(*mEnvironmentOptions);
// EXTERNAL INCLUDES
#include <dali/integration-api/render-controller.h>
#include <dali/public-api/math/math-utils.h>
+#include <algorithm>
#include <cstdlib>
#include <functional>
}
}
+void SetGraphicsBackendFromEnvironmentVariable(Graphics::Backend& api)
+{
+ const char* charValue = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_GRAPHICS_BACKEND);
+ if(charValue)
+ {
+ // Expecting upper/lower case variations of GLES and VULKAN/VK, and 0 and 1 too so just check the first character
+ switch(*charValue)
+ {
+ case '0':
+ case '1':
+ {
+ api = static_cast<Graphics::Backend>(*charValue - '0');
+ break;
+ }
+
+ case 'g':
+ case 'G':
+ {
+ std::string stringValue(charValue);
+ if(stringValue.size() == 4)
+ {
+ std::transform(stringValue.begin(), stringValue.end(), stringValue.begin(), ::toupper);
+ if(stringValue == "GLES")
+ {
+ api = Graphics::Backend::GLES;
+ }
+ }
+ break;
+ }
+
+ case 'v':
+ case 'V':
+ {
+ std::string stringValue(charValue);
+ const auto stringValueSize = stringValue.size();
+ if(stringValueSize == 2 || stringValueSize == 6)
+ {
+ std::transform(stringValue.begin(), stringValue.end(), stringValue.begin(), ::toupper);
+ if(stringValue == "VULKAN" || stringValue == "VK")
+ {
+ api = Graphics::Backend::VULKAN;
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
/// Provides a functor which ensures a non-negative number is set for the given member variable
struct MinimumZero
{
mGlesCallTime(0),
mMultiSamplingLevel(DEFAULT_MULTI_SAMPLING_LEVEL),
mThreadingMode(ThreadingMode::COMBINED_UPDATE_RENDER),
+ mGraphicsBackend(Graphics::Backend::DEFAULT),
mGlesCallAccumulate(false),
mDepthBufferRequired(DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING),
mStencilBufferRequired(DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING),
return mThreadingMode;
}
+Graphics::Backend EnvironmentOptions::GetGraphicsBackend() const
+{
+ return mGraphicsBackend;
+}
+
unsigned int EnvironmentOptions::GetRenderRefreshRate() const
{
return mRenderRefreshRate;
}
});
+ SetGraphicsBackendFromEnvironmentVariable(mGraphicsBackend);
+
SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
#include <dali/internal/adaptor/common/threading-mode.h>
+#include <dali/public-api/adaptor-framework/graphics-backend.h>
namespace Dali
{
*/
ThreadingMode::Type GetThreadingMode() const;
+ /**
+ * @return The graphics backend to use.
+ */
+ Graphics::Backend GetGraphicsBackend() const;
+
/**
* @return The render refresh rate.
*/
int mGlesCallTime; ///< time in seconds between status updates
int mMultiSamplingLevel; ///< The number of samples required in multisample buffers
- ThreadingMode::Type mThreadingMode; ///< threading mode
+ ThreadingMode::Type mThreadingMode; ///< Threading mode
+ Graphics::Backend mGraphicsBackend; ///< The graphics backend
bool mGlesCallAccumulate; ///< Whether or not to accumulate gles call statistics
bool mDepthBufferRequired; ///< Whether the depth buffer is required
#define DALI_THREADING_MODE "DALI_THREADING_MODE"
+/**
+ * Specify the Graphics Backend to use.
+ * Can be "GLES" or "VULKAN", or the appropriate integer value from Graphics::Backend.
+ */
+#define DALI_GRAPHICS_BACKEND "DALI_GRAPHICS_BACKEND"
+
#define DALI_REFRESH_RATE "DALI_REFRESH_RATE"
#define DALI_WATCH_REFRESH_RATE "DALI_WATCH_REFRESH_RATE"
--- /dev/null
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// HEADER
+#include <dali/public-api/adaptor-framework/graphics-backend.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+namespace Dali::Graphics
+{
+namespace
+{
+Backend gCurrentGraphicsBackend = Backend::DEFAULT;
+}
+
+Backend GetCurrentGraphicsBackend()
+{
+// TODO: Remove below once we actually have it dynamic, but for now just use define
+// return gCurrentGraphics;
+#if VULKAN_ENABLED
+ return Backend::VULKAN;
+#else
+ return Backend::GLES;
+#endif
+}
+
+void SetGraphicsBackend(Backend backend)
+{
+ static bool setOnce = false;
+ if(!setOnce)
+ {
+ setOnce = true;
+ gCurrentGraphicsBackend = backend;
+ }
+ else if(backend != gCurrentGraphicsBackend)
+ {
+ DALI_LOG_ERROR("Graphics backend already set to: %s\n", gCurrentGraphicsBackend == Backend::GLES ? "GLES" : "VULKAN");
+ }
+}
+
+} // namespace Dali::Graphics
--- /dev/null
+#ifndef DALI_GRAPHICS_BACKEND_H
+#define DALI_GRAPHICS_BACKEND_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/dali-adaptor-common.h>
+
+namespace Dali
+{
+/**
+ * @addtogroup dali_adaptor_framework
+ * @{
+ */
+
+namespace Graphics
+{
+enum class Backend
+{
+ GLES, ///< The graphics backend uses GLES. @SINCE_2_3.53
+ VULKAN, ///< The graphics backend uses VULKAN. @SINCE_2_3.53
+
+ DEFAULT = GLES, ///< The default graphics backend. @SINCE_2_3.53
+};
+
+/**
+ * @brief Returns the graphics backend currently in use.
+ * @SINCE_2_3.53
+ * @return The graphics backend currently in use.
+ */
+DALI_ADAPTOR_API Backend GetCurrentGraphicsBackend();
+
+/**
+ * @brief Sets the graphics backend.
+ * @details Generally, calling this is not required and can be set using the environment variable (DALI_GRAPHICS_BACKEND) instead.
+ * If called before the Application class is created, then the environment variable is ignored.
+ * @SINCE_2_3.53
+ * @param[in] backend The graphics backend to use
+ * @note This can only be called once and only before the graphics backend has been created (i.e. before the Application Class is started).
+ * If called again or after the graphics backend has started, then the call will not change anything.
+ * @note Currently has no effect as the Graphics backend is chosen at compile time
+ */
+DALI_ADAPTOR_API void SetGraphicsBackend(Backend backend);
+
+} // namespace Graphics
+
+/**
+ * @}
+ */
+} // namespace Dali
+
+#endif // DALI_GRAPHICS_BACKEND_H
SET( adaptor_public_api_src_files
${adaptor_public_api_dir}/adaptor-framework/application.cpp
${adaptor_public_api_dir}/adaptor-framework/encoded-image-buffer.cpp
+ ${adaptor_public_api_dir}/adaptor-framework/graphics-backend.cpp
${adaptor_public_api_dir}/adaptor-framework/key.cpp
${adaptor_public_api_dir}/adaptor-framework/window.cpp
${adaptor_public_api_dir}/adaptor-framework/timer.cpp
${adaptor_public_api_dir}/adaptor-framework/application.h
${adaptor_public_api_dir}/adaptor-framework/device-status.h
${adaptor_public_api_dir}/adaptor-framework/encoded-image-buffer.h
+ ${adaptor_public_api_dir}/adaptor-framework/graphics-backend.h
${adaptor_public_api_dir}/adaptor-framework/input-method.h
${adaptor_public_api_dir}/adaptor-framework/key.h
${adaptor_public_api_dir}/adaptor-framework/key-grab.h