public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (!this.QueryCanExecute(historyWorkspace))
            {
                return(null);
            }
            HistoryMemento          memento                    = this.OnPreRender(historyWorkspace);
            int                     activeLayerIndex           = historyWorkspace.ActiveLayerIndex;
            BitmapLayer             activeLayer                = (BitmapLayer)historyWorkspace.ActiveLayer;
            RectInt32               num2                       = activeLayer.Bounds();
            RectDouble              bounds                     = historyWorkspace.Selection.GetCachedClippingMask().Bounds;
            IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value);
            IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.OnCreateContentRenderers(historyWorkspace, num2.Width, num2.Height);
            ContentBlendMode    contentBlendMode = this.GetContentBlendMode();
            ContentRendererBgra renderer         = new ContentRendererBgra(activeLayer.Surface, contentBlendMode, contentRenderers, cachedClippingMaskRenderer);

            base.EnterCriticalRegion();
            HistoryMemento memento2 = new ApplyRendererToBitmapLayerHistoryFunction(this.HistoryMementoName, this.HistoryMementoImage, activeLayerIndex, renderer, bounds.Int32Bound, 4, 0x7d0, ActionFlags.None).Execute(historyWorkspace);
            HistoryMemento memento3 = this.OnPostRender(historyWorkspace);

            HistoryMemento[] items   = new HistoryMemento[] { memento, memento2, memento3 };
            HistoryMemento[] actions = ArrayUtil.Infer <HistoryMemento>(items).WhereNotNull <HistoryMemento>().ToArrayEx <HistoryMemento>();
            if (actions.Length == 0)
            {
                return(null);
            }
            return(new CompoundHistoryMemento(this.HistoryMementoName, this.HistoryMementoImage, actions));
        }
        private BitmapLayerToolLayerOverlay <TTool, TChanges> CreateLayerOverlay(BitmapLayer layer, TChanges changes)
        {
            IRenderer <ColorAlpha8> renderer;
            RectInt32 num;

            this.tool.VerifyAccess <TTool>();
            if (this.autoClipToSelection)
            {
                this.GetDefaultContentClip(changes, out num, out renderer);
            }
            else
            {
                this.tool.GetContentClip(changes, out num, out renderer);
            }
            ContentBlendMode blendMode = this.tool.GetBlendMode(changes);
            IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.tool.CreateContentRenderers(layer, changes);

            if (contentRenderers == null)
            {
                ExceptionUtil.ThrowInternalErrorException("OnCreateContentRenderer() returned null");
            }
            RectInt32 maxRenderBounds = changes.GetMaxRenderBounds();

            return(new BitmapLayerToolLayerOverlay <TTool, TChanges>(layer, RectInt32.Intersect(layer.Bounds(), RectInt32.Intersect(num, maxRenderBounds)), changes, blendMode, contentRenderers, renderer));
        }
 public BitmapLayerToolLayerOverlay(BitmapLayer layer, RectInt32 affectedBounds, TChanges changes, ContentBlendMode blendMode, IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers, IRenderer <ColorAlpha8> clipMaskRenderer) : base(layer, affectedBounds)
 {
     Validate.IsNotNull <TChanges>(changes, "changes");
     this.changes          = changes;
     this.blendMode        = blendMode;
     this.contentRenderers = contentRenderers.ToArrayEx <IMaskedRenderer <ColorBgra, ColorAlpha8> >();
     this.clipMaskRenderer = clipMaskRenderer;
     this.renderer         = new ContentRendererBgra(base.Layer.Surface, this.blendMode, this.contentRenderers, this.clipMaskRenderer);
 }