Thank you dear Josh. Actually it wasn't contentScaleFactor, sorry for misunderstanding the problem. White areas appear when my Sprite content is bigger than starling stage. The BitmapData is trimmed to the starling stage width and height.
Here is the code for drawToBitmapData:
public function drawToBitmapData(out:BitmapData = null,
color:uint = 0x0, alpha:Number = 0.0):BitmapData {
var painter:Painter = Starling.painter;
var stage:Stage = Starling.current.stage;
var viewPort:Rectangle = Starling.current.viewPort;
var stageWidth:Number = stage.stageWidth; //<<<<<<<<<
var stageHeight:Number = stage.stageHeight; //<<<<<<<<<
var scaleX:Number = viewPort.width / stageWidth;
var scaleY:Number = viewPort.height / stageHeight;
var backBufferScale:Number = painter.backBufferScaleFactor;
var projectionX:Number, projectionY:Number;
var bounds:Rectangle;
if (this is Stage) {
projectionX = viewPort.x < 0 ? -viewPort.x / scaleX : 0.0;
projectionY = viewPort.y < 0 ? -viewPort.y / scaleY : 0.0;
out ||= new BitmapData(painter.backBufferWidth * backBufferScale,
painter.backBufferHeight * backBufferScale);
}
else {
bounds = getBounds(_parent, sHelperRect);
projectionX = bounds.x;
projectionY = bounds.y;
out ||= new BitmapData(Math.ceil(bounds.width * scaleX * backBufferScale),
Math.ceil(bounds.height * scaleY * backBufferScale));
trace("draw", stageWidth, stageHeight, scaleX, scaleY, backBufferScale, projectionX, projectionY, bounds);
}
color = Color.multiply(color, alpha); // premultiply alpha
painter.clear(color, alpha);
painter.pushState();
painter.setupContextDefaults();
painter.state.renderTarget = null;
painter.state.setModelviewMatricesToIdentity();
painter.setStateTo(transformationMatrix);
painter.state.setProjectionMatrix(projectionX, projectionY,
painter.backBufferWidth / scaleX, painter.backBufferHeight / scaleY,
stageWidth, stageHeight, stage.cameraPosition);
if (_mask) painter.drawMask(mask, this);
if (_filter) _filter.render(painter);
else render(painter);
if (_mask) painter.eraseMask(mask, this);
painter.finishMeshBatch();
painter.context.drawToBitmapData(out);
painter.popState();
return out;
}
If I replace the stageWidth and stageHeight values (marked with <<<) by my own parent sprite dimensions the problem will solve. But changing Starling source code doesn't smell good. Any idea?