Add ApplyCustomFragmentPrefix
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-native-image.h
index 896ce52..fb9451c 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __TEST_NATIVE_IMAGE_H__
-#define __TEST_NATIVE_IMAGE_H__
+#ifndef TEST_NATIVE_IMAGE_H
+#define TEST_NATIVE_IMAGE_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
 
 // INTERNAL INCLUDES
 #include <dali/public-api/images/native-image-interface.h>
-#include <dali/devel-api/images/native-image-interface-extension.h>
+
 #include <dali/integration-api/gl-defines.h>
 
 namespace Dali
 {
 class TestNativeImage;
-class TestNativeImageNoExt;
 typedef IntrusivePtr<TestNativeImage> TestNativeImagePointer;
-typedef IntrusivePtr<TestNativeImageNoExt> TestNativeImageNoExtPointer;
 
-class DALI_IMPORT_API TestNativeImageExtension: public Dali::NativeImageInterface::Extension
+class DALI_CORE_API TestNativeImage : public Dali::NativeImageInterface
 {
 public:
-  inline const char* GetCustomFragmentPreFix(){return "#extension GL_OES_EGL_image_external:require\n";}
-  inline const char* GetCustomSamplerTypename(){return "samplerExternalOES";}
-
-  inline int GetEglImageTextureTarget(){return GL_TEXTURE_EXTERNAL_OES;}
-
-};
-
-class DALI_IMPORT_API TestNativeImage : public Dali::NativeImageInterface
-{
-public:
-  static TestNativeImagePointer New(int width, int height);
-
-  inline void SetGlExtensionCreateResult(bool result){ createResult = result;}
-  inline virtual bool GlExtensionCreate() { ++mExtensionCreateCalls; return createResult;};
-  inline virtual void GlExtensionDestroy() { ++mExtensionDestroyCalls; };
-  inline virtual GLenum TargetTexture() { ++mTargetTextureCalls; return 0;};
-  inline virtual void PrepareTexture() {};
-  inline virtual unsigned int GetWidth() const {return mWidth;};
-  inline virtual unsigned int GetHeight() const {return mHeight;};
-  inline virtual bool RequiresBlending() const {return true;};
-  inline virtual Dali::NativeImageInterface::Extension* GetExtension() {return mExtension;}
+  static TestNativeImagePointer New(uint32_t width, uint32_t height);
+
+  inline void SetGlExtensionCreateResult(bool result)
+  {
+    createResult = result;
+  }
+  inline virtual bool CreateResource()
+  {
+    ++mExtensionCreateCalls;
+    mCallStack.PushCall("CreateResource", "");
+    return createResult;
+  };
+  inline virtual void DestroyResource()
+  {
+    ++mExtensionDestroyCalls;
+    mCallStack.PushCall("DestroyResource", "");
+  };
+  inline virtual GLenum TargetTexture()
+  {
+    ++mTargetTextureCalls;
+    mCallStack.PushCall("TargetTexture", "");
+    return mTargetTextureError--;
+  };
+  inline virtual void PrepareTexture()
+  {
+    mCallStack.PushCall("PrepareTexture", "");
+  };
+  inline virtual uint32_t GetWidth() const
+  {
+    mCallStack.PushCall("GetWidth", "");
+    return mWidth;
+  };
+  inline virtual uint32_t GetHeight() const
+  {
+    mCallStack.PushCall("GetHeight", "");
+    return mHeight;
+  };
+  inline virtual bool RequiresBlending() const
+  {
+    mCallStack.PushCall("RequiresBlending", "");
+    return true;
+  };
+  inline virtual int GetTextureTarget() const
+  {
+    mCallStack.PushCall("GetTextureTarget", "");
+    return GL_TEXTURE_EXTERNAL_OES;
+  };
+  inline virtual const char* GetCustomFragmentPrefix() const
+  {
+    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 "samplerExternalOES";
+  };
+
+  inline Any GetNativeImageHandle() const override
+  {
+    return nullptr;
+  };
+  inline bool SourceChanged() const override
+  {
+    return false;
+  };
+
+  inline virtual Dali::NativeImageInterface::Extension* GetExtension()
+  {
+    return nullptr;
+  }
 
 private:
-  TestNativeImage(int width, int height);
+  TestNativeImage(uint32_t width, uint32_t height);
   virtual ~TestNativeImage();
 
-  int mWidth;
-  int mHeight;
-public:
-  int mExtensionCreateCalls;
-  int mExtensionDestroyCalls;
-  int mTargetTextureCalls;
-
-  bool createResult;
-  TestNativeImageExtension* mExtension;
-};
-
-
-class DALI_IMPORT_API TestNativeImageNoExt : public Dali::NativeImageInterface
-{
-public:
-  static TestNativeImageNoExtPointer New(int width, int height);
-
-  inline void SetGlExtensionCreateResult(bool result){ createResult = result;}
-  inline virtual bool GlExtensionCreate() { ++mExtensionCreateCalls; return createResult;};
-  inline virtual void GlExtensionDestroy() { ++mExtensionDestroyCalls; };
-  inline virtual GLenum TargetTexture() { ++mTargetTextureCalls; return 1;};
-  inline virtual void PrepareTexture() {};
-  inline virtual unsigned int GetWidth() const {return mWidth;};
-  inline virtual unsigned int GetHeight() const {return mHeight;};
-  inline virtual bool RequiresBlending() const {return true;};
-
-private:
-  TestNativeImageNoExt(int width, int height);
-  virtual ~TestNativeImageNoExt();
+  uint32_t mWidth;
+  uint32_t mHeight;
 
-  int mWidth;
-  int mHeight;
 public:
-  int mExtensionCreateCalls;
-  int mExtensionDestroyCalls;
-  int mTargetTextureCalls;
-  bool createResult;
+  int32_t                mExtensionCreateCalls;
+  int32_t                mExtensionDestroyCalls;
+  int32_t                mTargetTextureCalls;
+  uint32_t               mTargetTextureError{0u};
+  bool                   createResult;
+  mutable TraceCallStack mCallStack;
 };
 
-} // Dali
+} // namespace Dali
 
-#endif
+#endif // TEST_NATIVE_IMAGE_H