COMPMID-2549: Add GLES Runtime Context interfaces.

* Creates interfaces and concrete classes
* Ports GCActivationalLayer
* Adapts test framework and relevant tests

Change-Id: Ide36cd65ebf185958db3c4a5bebd630fcb2f39b3
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Reviewed-on: https://review.mlplatform.org/c/2199
Reviewed-by: Pablo Marquez <pablo.tello@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
diff --git a/arm_compute/runtime/CL/CLHelpers.h b/arm_compute/runtime/CL/CLHelpers.h
index 84f155a..6d00026 100644
--- a/arm_compute/runtime/CL/CLHelpers.h
+++ b/arm_compute/runtime/CL/CLHelpers.h
@@ -29,8 +29,10 @@
 
 namespace arm_compute
 {
+// Forward declarations
 class CLRuntimeContext;
 class ICLKernel;
+
 /** This function creates an OpenCL context and a device.
  *
  * @note In debug builds, the function will automatically enable cl_arm_printf if the driver/device supports it.
diff --git a/arm_compute/runtime/CL/CLScheduler.h b/arm_compute/runtime/CL/CLScheduler.h
index 720c8b3..3620820 100644
--- a/arm_compute/runtime/CL/CLScheduler.h
+++ b/arm_compute/runtime/CL/CLScheduler.h
@@ -153,5 +153,5 @@
     ICLTuner                 *_cl_tuner;
     std::unique_ptr<ICLTuner> _cl_default_static_tuner;
 };
-}
+} // namespace arm_compute
 #endif /* __ARM_COMPUTE_CLSCHEDULER_H__ */
diff --git a/arm_compute/runtime/CL/ICLSimpleFunction.h b/arm_compute/runtime/CL/ICLSimpleFunction.h
index 8399a3d..5b6b608 100644
--- a/arm_compute/runtime/CL/ICLSimpleFunction.h
+++ b/arm_compute/runtime/CL/ICLSimpleFunction.h
@@ -32,7 +32,9 @@
 
 namespace arm_compute
 {
+// Forward declarations
 class CLRuntimeContext;
+
 /** Basic interface for functions which have a single OpenCL kernel */
 class ICLSimpleFunction : public IFunction
 {
@@ -60,5 +62,5 @@
     CLFillBorderKernel         _border_handler; /**< Kernel to handle  borders */
     CLRuntimeContext          *_ctx;            /**< Context to use */
 };
-}
+} // namespace arm_compute
 #endif /*__ARM_COMPUTE_ICLSIMPLEFUNCTION_H__ */
diff --git a/arm_compute/runtime/GLES_COMPUTE/GCHelpers.h b/arm_compute/runtime/GLES_COMPUTE/GCHelpers.h
new file mode 100644
index 0000000..efc95e7
--- /dev/null
+++ b/arm_compute/runtime/GLES_COMPUTE/GCHelpers.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_GC_HELPERS_H__
+#define __ARM_COMPUTE_GC_HELPERS_H__
+
+#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
+
+namespace arm_compute
+{
+/** This function creates an OpenGL-ES context and a display.
+ *
+ * @return A std::tuple where the first element is the opengl display, the second element is the opengl context
+ *         and the third one an error code. The error code will be EGL_TRUE upon successful creation, otherwise
+ *         a value telling why the function failed.
+ */
+std::tuple<EGLDisplay, EGLContext, EGLBoolean> create_opengl_display_and_context();
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GC_HELPERS_H__ */
diff --git a/arm_compute/runtime/GLES_COMPUTE/GCRuntimeContext.h b/arm_compute/runtime/GLES_COMPUTE/GCRuntimeContext.h
new file mode 100644
index 0000000..353e9ec
--- /dev/null
+++ b/arm_compute/runtime/GLES_COMPUTE/GCRuntimeContext.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_GCRUNTIME_CONTEXT_H__
+#define __ARM_COMPUTE_GCRUNTIME_CONTEXT_H__
+
+#include "arm_compute/core/GLES_COMPUTE/GCCoreRuntimeContext.h"
+#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h"
+#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
+#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
+#include "arm_compute/runtime/IScheduler.h"
+#include "arm_compute/runtime/RuntimeContext.h"
+
+namespace arm_compute
+{
+/** Runtime context */
+class GCRuntimeContext : public RuntimeContext
+{
+public:
+    /** Default Constructor */
+    GCRuntimeContext();
+    /** Destructor */
+    ~GCRuntimeContext() = default;
+    /** Prevent instances of this class from being copied (As this class contains pointers) */
+    GCRuntimeContext(const GCRuntimeContext &) = delete;
+    /** Default move constructor */
+    GCRuntimeContext(GCRuntimeContext &&) = default;
+    /** Prevent instances of this class from being copied (As this class contains pointers) */
+    GCRuntimeContext &operator=(const GCRuntimeContext &) = delete;
+    /** Default move assignment operator */
+    GCRuntimeContext &operator=(GCRuntimeContext &&) = default;
+    /** CPU Scheduler setter */
+    void set_gpu_scheduler(GCScheduler *scheduler);
+
+    // Inherited overridden methods
+    GCScheduler          *gpu_scheduler();
+    GCKernelLibrary      &kernel_library();
+    GCCoreRuntimeContext *core_runtime_context();
+
+private:
+    std::unique_ptr<GCScheduler> _gpu_owned_scheduler{ nullptr };
+    GCScheduler                 *_gpu_scheduler{ nullptr };
+    GCKernelLibrary              _kernel_lib{};
+    GCCoreRuntimeContext         _core_context{};
+};
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_GCRUNTIME_CONTEXT_H__ */
diff --git a/arm_compute/runtime/GLES_COMPUTE/GCScheduler.h b/arm_compute/runtime/GLES_COMPUTE/GCScheduler.h
index 1cf2af4..e26e311 100644
--- a/arm_compute/runtime/GLES_COMPUTE/GCScheduler.h
+++ b/arm_compute/runtime/GLES_COMPUTE/GCScheduler.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -30,40 +30,50 @@
 
 namespace arm_compute
 {
+// Forward declarations
 class IGCKernel;
 
 /** Provides global access to a OpenGL ES context and command queue. */
-class GCScheduler
+class GCScheduler final
 {
 public:
+    /** Constructor */
+    GCScheduler();
+    /** Destructor */
+    ~GCScheduler();
+    /** Prevent instances of this class from being copied */
+    GCScheduler(const GCScheduler &) = delete;
+    /** Prevent instances of this class from being copied */
+    GCScheduler &operator=(const GCScheduler &) = delete;
     /** Access the scheduler singleton.
      *
      * @return The scheduler
      */
     static GCScheduler &get();
-
     /** Initialises the context and command queue used by the scheduler to default values
      *  and sets a default device and kernel path for the @ref GCKernelLibrary.
      */
     void default_init();
-
+    /** Initializes the context and display used by the Scheduler.
+     *
+     * @param[in] display Display to use
+     * @param[in] ctx     Context to use
+     */
+    void default_init_with_context(EGLDisplay display, EGLContext ctx);
     /** Schedule the execution of the passed kernel if possible.
      *
      * @param[in] kernel Kernel to execute.
      * @param[in] flush  (Optional) Specifies if the command queue will be flushed after running the kernel.
      */
     void dispatch(IGCKernel &kernel, bool flush = true);
-
     /** Initialises the display and context to be used by the scheduler.
      *
      * @param[in] dpy The EGL display connection
      * @param[in] ctx The EGL rendering context
      */
     void init(EGLDisplay dpy, EGLContext ctx);
-
     /** Defines a barrier ordering memory transactions. */
     void memory_barrier();
-
     /** Get the target GPU.
      *
      * @return The target GPU.
@@ -72,7 +82,6 @@
     {
         return _target;
     }
-
     /** Accessor to set target GPU to be used by the scheduler.
      *
      * @param[in] target The target GPU.
@@ -83,15 +92,6 @@
     }
 
 private:
-    /** Constructor */
-    GCScheduler();
-    /** Destructor */
-    ~GCScheduler();
-    /** Prevent instances of this class from being copied */
-    GCScheduler(const GCScheduler &) = delete;
-    /** Prevent instances of this class from being copied */
-    GCScheduler &operator=(const GCScheduler &) = delete;
-
     /** Set up EGL context */
     void setup_context();
 
diff --git a/arm_compute/runtime/GLES_COMPUTE/IGCSimpleFunction.h b/arm_compute/runtime/GLES_COMPUTE/IGCSimpleFunction.h
index 15bbfff..c3bd463 100644
--- a/arm_compute/runtime/GLES_COMPUTE/IGCSimpleFunction.h
+++ b/arm_compute/runtime/GLES_COMPUTE/IGCSimpleFunction.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -26,6 +26,7 @@
 
 #include "arm_compute/core/GLES_COMPUTE/IGCKernel.h"
 #include "arm_compute/core/GLES_COMPUTE/kernels/GCFillBorderKernel.h"
+#include "arm_compute/runtime/GLES_COMPUTE/GCRuntimeContext.h"
 #include "arm_compute/runtime/IFunction.h"
 
 #include <memory>
@@ -36,8 +37,19 @@
 class IGCSimpleFunction : public IFunction
 {
 public:
-    /** Default constructor */
-    IGCSimpleFunction();
+    /** Default Constructor
+     *
+     * @param[in] ctx Runtime context to be used by the function
+     */
+    IGCSimpleFunction(GCRuntimeContext *ctx = nullptr);
+    /** Prevent instances of this class from being copied (As this class contains pointers) */
+    IGCSimpleFunction(const IGCSimpleFunction &) = delete;
+    /** Default move constructor */
+    IGCSimpleFunction(IGCSimpleFunction &&) = default;
+    /** Prevent instances of this class from being copied (As this class contains pointers) */
+    IGCSimpleFunction &operator=(const IGCSimpleFunction &) = delete;
+    /** Default move assignment operator */
+    IGCSimpleFunction &operator=(IGCSimpleFunction &&) = default;
 
     // Inherited methods overridden:
     void run() override final;
@@ -45,6 +57,7 @@
 protected:
     std::unique_ptr<IGCKernel> _kernel;         /**< Kernel to run */
     GCFillBorderKernel         _border_handler; /**< Kernel to handle  borders */
+    GCRuntimeContext          *_ctx;            /**< Context to use */
 };
-}
+} // namespace arm_compute
 #endif /*__ARM_COMPUTE_IGCSIMPLEFUNCTION_H__ */
diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
index 5e0effe..a046d1b 100644
--- a/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
+++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
@@ -29,6 +29,7 @@
 
 namespace arm_compute
 {
+// Forward declarations
 class IGCTensor;
 
 /** Basic function to run @ref GCActivationLayerKernel
@@ -40,9 +41,9 @@
 public:
     /** Constructor
      *
-     * @param[in] ctx Runtime context to be used by the function
+     * @param[in, out] ctx Runtime context to be used by the function
      */
-    GCActivationLayer(void *ctx = nullptr);
+    explicit GCActivationLayer(GCRuntimeContext *ctx = nullptr);
     /** Prevent instances of this class from being copied (As this class contains pointers) */
     GCActivationLayer(const GCActivationLayer &) = delete;
     /** Default move constructor */