mCallStack.PushCall("GetCustomFragmentPrefix", "");
return "#extension GL_OES_EGL_image_external:require\n";
};
+ inline virtual bool ApplyNativeFragmentShader(std::string& shader)
+ {
+ mCallStack.PushCall("ApplyNativeFragmentShader", "");
+ shader = "#extension GL_OES_EGL_image_external:require\n" + shader;
+
+ //Get custom sampler type name
+ const char* customSamplerTypename = GetCustomSamplerTypename();
+ if(customSamplerTypename)
+ {
+ size_t samplerPosition = shader.find("sampler2D");
+ if(samplerPosition != std::string::npos)
+ {
+ shader.replace(samplerPosition, strlen("sampler2D"), customSamplerTypename);
+ }
+ }
+ return true;
+ };
inline const char* GetCustomSamplerTypename() const override
{
mCallStack.PushCall("GetCustomSamplerTypename", "");
return mImpl->GetCustomFragmentPrefix();
}
+bool NativeImageSourceQueue::ApplyNativeFragmentShader(std::string& shader)
+{
+ return mImpl->ApplyNativeFragmentShader(shader);
+}
+
const char* NativeImageSourceQueue::GetCustomSamplerTypename() const
{
return mImpl->GetCustomSamplerTypename();
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
return mGLES->GetShadingLanguageVersion();
}
- const char* GetEglImageExtensionString()
+ bool ApplyNativeFragmentShader(std::string& shader, const char* customSamplerType)
{
- return mGLES->GetEglImageExtensionString();
+ return mGLES->ApplyNativeFragmentShader(shader, customSamplerType);
}
void CacheConfigurations(ConfigurationManager& configurationManager) override;
#include <dali/integration-api/gl-abstraction.h>
#include <dali/internal/graphics/common/egl-include.h>
#include <cstdlib>
+#include <cstring>
#include <memory>
// INTERNAL INCLUDES
{
static constexpr int32_t INITIAL_GLES_VERSION = 30;
static constexpr int32_t GLES_VERSION_SUPPORT_BLEND_EQUATION_ADVANCED = 32;
+static constexpr const char* LEGACY_SHADING_LANGUAGE_VERSION = "100";
static constexpr const char* KHR_BLEND_EQUATION_ADVANCED = "GL_KHR_blend_equation_advanced";
+static constexpr const char* DEFAULT_SAMPLER_TYPE = "sampler2D";
+
static constexpr const char* FRAGMENT_SHADER_ADVANCED_BLEND_EQUATION_PREFIX =
"#extension GL_KHR_blend_equation_advanced : enable\n"
return mShadingLanguageVersion;
}
- const char* GetEglImageExtensionString()
+ bool ApplyNativeFragmentShader(std::string& shader, const char* customSamplerType)
{
- ConditionalWait::ScopedLock lock(mContextCreatedWaitCondition);
- if(!mIsContextCreated)
+ bool modified = false;
+ std::string versionString = "#version";
+ size_t versionPosition = shader.find(versionString);
+ if(versionPosition != std::string::npos)
{
- mContextCreatedWaitCondition.Wait(lock);
+ std::string extensionString;
+ size_t shadingLanguageVersionPosition = shader.find_first_not_of(" \t", versionPosition + versionString.length());
+ if(shadingLanguageVersionPosition != std::string::npos &&
+ shader.substr(shadingLanguageVersionPosition, 3) == LEGACY_SHADING_LANGUAGE_VERSION)
+ {
+ extensionString = OES_EGL_IMAGE_EXTERNAL_STRING;
+ }
+ else
+ {
+ extensionString = OES_EGL_IMAGE_EXTERNAL_STRING_ESSL3;
+ }
+
+ if(shader.find(extensionString) == std::string::npos)
+ {
+ modified = true;
+ size_t extensionPosition = shader.find_first_of("\n", versionPosition) + 1;
+ shader.insert(extensionPosition, extensionString);
+ }
}
- if(mShadingLanguageVersion < 300)
+ else
{
- return OES_EGL_IMAGE_EXTERNAL_STRING;
+ if(shader.find(OES_EGL_IMAGE_EXTERNAL_STRING) == std::string::npos)
+ {
+ modified = true;
+ shader = OES_EGL_IMAGE_EXTERNAL_STRING + shader;
+ }
}
- else
+
+ if(shader.find(customSamplerType) == std::string::npos)
{
- return OES_EGL_IMAGE_EXTERNAL_STRING_ESSL3;
+ size_t pos = shader.find(DEFAULT_SAMPLER_TYPE);
+ if(pos != std::string::npos)
+ {
+ modified = true;
+ shader.replace(pos, strlen(DEFAULT_SAMPLER_TYPE), customSamplerType);
+ }
}
+
+ return modified;
}
/* OpenGL ES 2.0 */
return nullptr;
}
+bool NativeImageSourceAndroid::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
+}
+
const char* NativeImageSourceAndroid::GetCustomSamplerTypename() const
{
return nullptr;
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
{
namespace Adaptor
{
-namespace
-{
-const char* FRAGMENT_PREFIX = "\n";
-const char* SAMPLER_TYPE = "sampler2D";
-
-} // namespace
NativeImageSourceQueueAndroid* NativeImageSourceQueueAndroid::New(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue)
{
const char* NativeImageSourceQueueAndroid::GetCustomFragmentPrefix() const
{
- return FRAGMENT_PREFIX;
+ return nullptr;
+}
+
+bool NativeImageSourceQueueAndroid::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
}
const char* NativeImageSourceQueueAndroid::GetCustomSamplerTypename() const
{
- return SAMPLER_TYPE;
+ return nullptr;
}
int NativeImageSourceQueueAndroid::GetTextureTarget() const
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
return nullptr;
}
+bool NativeBitmapBuffer::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
+}
+
const char* NativeBitmapBuffer::GetCustomSamplerTypename() const
{
return nullptr;
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
virtual const char* GetCustomFragmentPrefix() const = 0;
/**
+ * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
+ */
+ virtual bool ApplyNativeFragmentShader(std::string& shader) = 0;
+
+ /**
* @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
*/
virtual const char* GetCustomSamplerTypename() const = 0;
virtual const char* GetCustomFragmentPrefix() const = 0;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ virtual bool ApplyNativeFragmentShader(std::string& shader) = 0;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
virtual const char* GetCustomSamplerTypename() const = 0;
return nullptr;
}
+bool NativeImageSourceCocoa::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
+}
+
const char* NativeImageSourceCocoa::GetCustomSamplerTypename() const
{
return nullptr;
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
{
namespace
{
-const char* SAMPLER_TYPE = "samplerExternalOES";
+const char* FRAGMENT_PREFIX = "#extension GL_OES_EGL_image_external:require\n";
+const char* SAMPLER_TYPE = "samplerExternalOES";
// clang-format off
tbm_format FORMATS_BLENDING_REQUIRED[] = {
}
NativeImageSourceTizen::NativeImageSourceTizen(uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource)
-: mCustomFragmentPrefix(),
- mWidth(width),
+: mWidth(width),
mHeight(height),
mOwnTbmSurface(false),
mTbmSurface(NULL),
GraphicsInterface* graphics = &(Adaptor::GetImplementation(Adaptor::Get()).GetGraphicsInterface());
mEglGraphics = static_cast<EglGraphics*>(graphics);
- mCustomFragmentPrefix = mEglGraphics->GetEglImageExtensionString();
-
mTbmSurface = GetSurfaceFromAny(nativeImageSource);
if(mTbmSurface != NULL)
const char* NativeImageSourceTizen::GetCustomFragmentPrefix() const
{
- return mCustomFragmentPrefix;
+ return FRAGMENT_PREFIX;
+}
+
+bool NativeImageSourceTizen::ApplyNativeFragmentShader(std::string& shader)
+{
+ return mEglGraphics->ApplyNativeFragmentShader(shader, SAMPLER_TYPE);
}
const char* NativeImageSourceTizen::GetCustomSamplerTypename() const
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader(std::string& shader)
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
void DestroySurface();
private:
- const char* mCustomFragmentPrefix; ///< Prefix for CustomFragment
- uint32_t mWidth; ///< image width
- uint32_t mHeight; ///< image height
- bool mOwnTbmSurface; ///< Whether we created pixmap or not
+ uint32_t mWidth; ///< image width
+ uint32_t mHeight; ///< image height
+ bool mOwnTbmSurface; ///< Whether we created pixmap or not
tbm_surface_h mTbmSurface;
tbm_format mTbmFormat;
bool mBlendingRequired; ///< Whether blending is required
{
#define TBM_SURFACE_QUEUE_SIZE 3
-const char* SAMPLER_TYPE = "samplerExternalOES";
+const char* FRAGMENT_PREFIX = "#extension GL_OES_EGL_image_external:require\n";
+const char* SAMPLER_TYPE = "samplerExternalOES";
// clang-format off
int FORMATS_BLENDING_REQUIRED[] = {
}
NativeImageSourceQueueTizen::NativeImageSourceQueueTizen(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue)
-: mCustomFragmentPrefix(),
- mMutex(),
+: mMutex(),
mWidth(width),
mHeight(height),
mTbmQueue(NULL),
GraphicsInterface* graphics = &(Adaptor::GetImplementation(Adaptor::Get()).GetGraphicsInterface());
mEglGraphics = static_cast<EglGraphics*>(graphics);
- mCustomFragmentPrefix = mEglGraphics->GetEglImageExtensionString();
-
mTbmQueue = GetSurfaceFromAny(nativeImageSourceQueue);
if(mTbmQueue != NULL)
const char* NativeImageSourceQueueTizen::GetCustomFragmentPrefix() const
{
- return mCustomFragmentPrefix;
+ return FRAGMENT_PREFIX;
+}
+
+bool NativeImageSourceQueueTizen::ApplyNativeFragmentShader(std::string& shader)
+{
+ return mEglGraphics->ApplyNativeFragmentShader(shader, SAMPLER_TYPE);
}
const char* NativeImageSourceQueueTizen::GetCustomSamplerTypename() const
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
private:
typedef std::pair<tbm_surface_h, void*> EglImagePair;
- const char* mCustomFragmentPrefix; ///< Prefix for CustomFragment
- Dali::Mutex mMutex; ///< Mutex
- uint32_t mWidth; ///< image width
- uint32_t mHeight; ///< image height
- tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
- tbm_surface_h mConsumeSurface; ///< The current tbm surface
- std::vector<EglImagePair> mEglImages; ///< EGL Image vector
- EglGraphics* mEglGraphics; ///< EGL Graphics
- EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
- bool mOwnTbmQueue; ///< Whether we created tbm queue
- bool mBlendingRequired; ///< Whether blending is required
+ Dali::Mutex mMutex; ///< Mutex
+ uint32_t mWidth; ///< image width
+ uint32_t mHeight; ///< image height
+ tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
+ tbm_surface_h mConsumeSurface; ///< The current tbm surface
+ std::vector<EglImagePair> mEglImages; ///< EGL Image vector
+ EglGraphics* mEglGraphics; ///< EGL Graphics
+ EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
+ bool mOwnTbmQueue; ///< Whether we created tbm queue
+ bool mBlendingRequired; ///< Whether blending is required
};
} // namespace Adaptor
return nullptr;
}
+bool NativeImageSourceX::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
+}
+
const char* NativeImageSourceX::GetCustomSamplerTypename() const
{
return nullptr;
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
namespace
{
#define TBM_SURFACE_QUEUE_SIZE 3
-
-const char* FRAGMENT_PREFIX = "\n";
-const char* SAMPLER_TYPE = "sampler2D";
-
} // namespace
NativeImageSourceQueueX* NativeImageSourceQueueX::New(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue)
const char* NativeImageSourceQueueX::GetCustomFragmentPrefix() const
{
- return FRAGMENT_PREFIX;
+ return nullptr;
+}
+
+bool NativeImageSourceQueueX::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
}
const char* NativeImageSourceQueueX::GetCustomSamplerTypename() const
{
- return SAMPLER_TYPE;
+ return nullptr;
}
int NativeImageSourceQueueX::GetTextureTarget() const
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
return nullptr;
}
+bool NativeImageSourceWin::ApplyNativeFragmentShader(std::string& shader)
+{
+ return false;
+}
+
const char* NativeImageSourceWin::GetCustomSamplerTypename() const
{
return nullptr;
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;
return mImpl->GetCustomFragmentPrefix();
}
+bool NativeImageSource::ApplyNativeFragmentShader(std::string& shader)
+{
+ return mImpl->ApplyNativeFragmentShader(shader);
+}
+
const char* NativeImageSource::GetCustomSamplerTypename() const
{
return mImpl->GetCustomSamplerTypename();
const char* GetCustomFragmentPrefix() const override;
/**
+ * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
+ */
+ bool ApplyNativeFragmentShader(std::string& shader) override;
+
+ /**
* @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
*/
const char* GetCustomSamplerTypename() const override;