#pragma once
#include "Gui/2D/Surface.h"
#include "Gui/DeviceDX.h"

#ifdef GUI_WIN32

namespace gui {

	/**
	 * Direct 2D surface.
	 */
	class D2DSurface : public Surface2D {
		friend class DXDevice;
	public:
		// Destroy.
		~D2DSurface();

		// Create a suitable Graphics object.
		virtual WindowGraphics *createGraphics(Engine &e);

		// Resize.
		virtual void resize(Size size, Float scale);

		// Present.
		virtual PresentStatus present(bool waitForVSync);

		// Get the render target.
		ID2D1RenderTarget *target() const { return renderTarget.v; }

		// Prepare for grabbing the surface.
		virtual void prepareGrab(Size size, Float scale);

		// Grab the surface as an integer.
		virtual Image *grabImage(Engine &e);

	private:
		// Create.
		D2DSurface(Size size, Float scale, DXDevice *device, const ComPtr<IDXGISwapChain> &swap, Nat id);

		// ID of the underlying device.
		Nat deviceId;

		// DX resources.
		DXDevice *device;
		ComPtr<IDXGISwapChain> swapChain;
		ComPtr<ID2D1RenderTarget> renderTarget;

		// Surface used when grabbing an image.
		ComPtr<ID3D10Texture2D> grabSurface;
	};


}

#endif
