#pragma once

#include <cstdint>
#include <vector>

#include "ThorRenderer.hpp" // ThorShapeDesc / ThorShapeType

namespace thor {

/**
 * GPU renderer over ThorVG's GL (OpenGL ES) engine — Android only.
 *
 * All methods must be called on the GL thread (the thread that owns the current
 * EGL context, e.g. a GLSurfaceView's renderer thread). The renderer reads the
 * current EGL display/surface/context via egl* and hands them to ThorVG.
 */
class ThorGlRenderer {
public:
  ThorGlRenderer();
  ~ThorGlRenderer();

  ThorGlRenderer(const ThorGlRenderer&) = delete;
  ThorGlRenderer& operator=(const ThorGlRenderer&) = delete;

  /** (Re)bind ThorVG to the current EGL surface at the given pixel size. */
  bool resize(uint32_t width, uint32_t height);

  /** Replay the scene into the GL framebuffer (caller swaps buffers). */
  bool renderScene(const std::vector<ThorShapeDesc>& shapes);

private:
  void* _canvas = nullptr; // tvg::GlCanvas*
  // Retained pool of tvg::Shape* (canvas-owned) reused across frames; see the
  // CPU renderer for the rationale. Freed when the canvas is deleted.
  std::vector<void*> _pool; // tvg::Shape*
  bool _targeted = false;
};

} // namespace thor
