/// <summary> /// Causes the layer to render a given region of interest (roi) to the given destination surface. /// </summary> /// <param name="args">Contains information about which objects to use for rendering</param> /// <param name="roi">The region to be rendered.</param> public void Render(RenderArgs args, GeometryRegion roi) { Rectangle roiBounds = roi.GetBoundsInt(); if (!IsInBounds(roiBounds)) { throw new ArgumentOutOfRangeException("roi"); } Rectangle[] rects = roi.GetRegionScansReadOnlyInt(); RenderImpl(args, rects); }
public void SaveRegion(GeometryRegion saveMeRegion, Rectangle saveMeBounds) { var activeLayer = (BitmapLayer)ActiveLayer; if (_savedTiles == null) { _savedTiles = new BitVector2D( (activeLayer.Width + SaveTileGranularity - 1) / SaveTileGranularity, (activeLayer.Height + SaveTileGranularity - 1) / SaveTileGranularity); _savedTiles.Clear(false); } Rectangle regionBounds; if (saveMeRegion == null) { regionBounds = saveMeBounds; } else { regionBounds = saveMeRegion.GetBoundsInt(); } Rectangle bounds = Rectangle.Union(regionBounds, saveMeBounds); bounds.Intersect(activeLayer.Bounds); int leftTile = bounds.Left / SaveTileGranularity; int topTile = bounds.Top / SaveTileGranularity; int rightTile = (bounds.Right - 1) / SaveTileGranularity; int bottomTile = (bounds.Bottom - 1) / SaveTileGranularity; for (int tileY = topTile; tileY <= bottomTile; ++tileY) { Rectangle rowAccumBounds = Rectangle.Empty; for (int tileX = leftTile; tileX <= rightTile; ++tileX) { if (!_savedTiles.Get(tileX, tileY)) { Rectangle tileBounds = new Rectangle(tileX * SaveTileGranularity, tileY * SaveTileGranularity, SaveTileGranularity, SaveTileGranularity); tileBounds.Intersect(activeLayer.Bounds); if (rowAccumBounds == Rectangle.Empty) { rowAccumBounds = tileBounds; } else { rowAccumBounds = Rectangle.Union(rowAccumBounds, tileBounds); } _savedTiles.Set(tileX, tileY, true); } else { if (rowAccumBounds != Rectangle.Empty) { using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds), src = activeLayer.Surface.CreateWindow(rowAccumBounds)) { dst.CopySurface(src); } rowAccumBounds = Rectangle.Empty; } } } if (rowAccumBounds != Rectangle.Empty) { using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds), src = activeLayer.Surface.CreateWindow(rowAccumBounds)) { dst.CopySurface(src); } rowAccumBounds = Rectangle.Empty; } } if (this._saveRegion != null) { this._saveRegion.Dispose(); this._saveRegion = null; } if (saveMeRegion != null) { this._saveRegion = saveMeRegion.Clone(); } }