#pragma once
#include "Device.h"
#include "Surface.h"

#ifdef GUI_ENABLE_SKIA

#include "2D/Skia/Skia.h"

namespace gui {

	class SkiaDevice;

	/**
	 * Rendering context for Skia.
	 */
	class SkiaContext : public GLDevice::Context {
	public:
		// Create.
		SkiaContext(SkiaDevice *owner, GdkWindow *window, GdkGLContext *context);

		// Destroy.
		~SkiaContext();

		// Skia context.
		sk_sp<GrDirectContext> skia;

		// Make sure this context is active. Skia does not seem to switch contexts itself, so we
		// will need to do it for Skia. As such, we try to minimize calls to "gl_area_make_current".
		void makeCurrent();

		// Clear which context is the current one, in case someone manually modifies the current
		// context.
		void clearCurrent();

	private:
		// Pointer to the device, so that we may know which context is the current one.
		SkiaDevice *device;
	};


	/**
	 * Device for Skia. Supports both 2D and 3D rendering.
	 */
	class SkiaDevice : public GLDevice {
		friend class SkiaContext;
	public:
		// Create.
		SkiaDevice(Engine &e);

		// Create a text manager.
		virtual TextMgr *createTextMgr();

	protected:
		// Create a context.
		virtual SkiaContext *createContext(GdkWindow *window, GdkGLContext *context);

		// Create a surface.
		virtual Surface2D *createSurface2D(GtkWidget *widget, Context *context);

	private:
		// Current active context. To skip calls to make_current.
		SkiaContext *current;
	};

}

#endif
