// Class: openfl.display.CairoRenderer

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
var $extend = require("./../../extend_stub").default;
function openfl_display_DisplayObjectRenderer() {return require("./../../openfl/display/DisplayObjectRenderer");}

// Constructor

var CairoRenderer = function(cairo) {
	(openfl_display_DisplayObjectRenderer().default).call(this);
}

// Meta

CairoRenderer.__name__ = ["openfl","display","CairoRenderer"];
CairoRenderer.__super__ = (openfl_display_DisplayObjectRenderer().default);
CairoRenderer.prototype = $extend((openfl_display_DisplayObjectRenderer().default).prototype, {
	applyMatrix: function(transform,cairo) {
		if(cairo == null) {
			cairo = this.cairo;
		}
		this.__matrix.copyFrom(transform);
		if(this.cairo == cairo && this.__worldTransform != null) {
			this.__matrix.concat(this.__worldTransform);
		}
		this.__matrix3.a = this.__matrix.a;
		this.__matrix3.b = this.__matrix.b;
		this.__matrix3.c = this.__matrix.c;
		this.__matrix3.d = this.__matrix.d;
		if(this.__roundPixels) {
			this.__matrix3.tx = Math.round(this.__matrix.tx);
			this.__matrix3.ty = Math.round(this.__matrix.ty);
		} else {
			this.__matrix3.tx = this.__matrix.tx;
			this.__matrix3.ty = this.__matrix.ty;
		}
		cairo.set_matrix(this.__matrix3);
	},
	__clear: function() {
		if(this.cairo == null) {
			return;
		}
		this.cairo.identityMatrix();
		if(this.__stage != null && this.__stage.__clearBeforeRender) {
			var cacheBlendMode = this.__blendMode;
			this.__setBlendMode("normal");
			this.cairo.setSourceRGB(this.__stage.__colorSplit[0],this.__stage.__colorSplit[1],this.__stage.__colorSplit[2]);
			this.cairo.paint();
			this.__setBlendMode(cacheBlendMode);
		}
	},
	__popMask: function() {
		this.cairo.restore();
	},
	__popMaskObject: function(object,handleScrollRect) {
		if(handleScrollRect == null) {
			handleScrollRect = true;
		}
		if(!object.__isCacheBitmapRender && object.__mask != null) {
			this.__popMask();
		}
		if(handleScrollRect && object.__scrollRect != null) {
			this.__popMaskRect();
		}
	},
	__popMaskRect: function() {
		this.cairo.restore();
	},
	__pushMask: function(mask) {
		this.cairo.save();
		this.applyMatrix(mask.__renderTransform,this.cairo);
		this.cairo.newPath();
		mask.__renderCairoMask(this);
		this.cairo.clip();
	},
	__pushMaskObject: function(object,handleScrollRect) {
		if(handleScrollRect == null) {
			handleScrollRect = true;
		}
		if(handleScrollRect && object.__scrollRect != null) {
			this.__pushMaskRect(object.__scrollRect,object.__renderTransform);
		}
		if(!object.__isCacheBitmapRender && object.__mask != null) {
			this.__pushMask(object.__mask);
		}
	},
	__pushMaskRect: function(rect,transform) {
		this.cairo.save();
		this.applyMatrix(transform,this.cairo);
		this.cairo.newPath();
		this.cairo.rectangle(rect.x,rect.y,rect.width,rect.height);
		this.cairo.clip();
	},
	__render: function(object) {
		if(this.cairo == null) {
			return;
		}
		object.__renderCairo(this);
	},
	__renderStage3D: function(stage) {
		if(this.cairo == null) {
			return;
		}
		var _g = 0;
		var _g1 = stage.stage3Ds;
		while(_g < _g1.get_length()) {
			var stage3D = _g1.get(_g);
			++_g;
			stage3D.__renderCairo(stage,this);
		}
	},
	__setBlendMode: function(value) {
		if(this.__blendMode == value) {
			return;
		}
		this.__blendMode = value;
		switch(value) {
		case "add":
			this.cairo.set_operator(12);
			break;
		case "darken":
			this.cairo.set_operator(17);
			break;
		case "difference":
			this.cairo.set_operator(23);
			break;
		case "hardlight":
			this.cairo.set_operator(21);
			break;
		case "layer":
			this.cairo.set_operator(2);
			break;
		case "lighten":
			this.cairo.set_operator(18);
			break;
		case "multiply":
			this.cairo.set_operator(14);
			break;
		case "overlay":
			this.cairo.set_operator(16);
			break;
		case "screen":
			this.cairo.set_operator(15);
			break;
		default:
			this.cairo.set_operator(2);
		}
	}
});
CairoRenderer.prototype.__class__ = $hxClasses["openfl.display.CairoRenderer"] = CairoRenderer;

// Init



// Statics




// Export

exports.default = CairoRenderer;