From befa91ef48fce8db03ac6d4251e0db69e28665ea Mon Sep 17 00:00:00 2001 From: test Date: Sat, 22 Aug 2020 16:02:25 +0900 Subject: [PATCH] =?utf8?q?=E3=83=95=E3=82=A1=E3=82=AF=E3=83=88=E3=83=AA?= =?utf8?q?=E3=83=BC=E3=81=AE=E9=A1=9E=E3=81=AF=E5=85=B1=E6=9C=89=E3=81=AB?= =?utf8?q?=E3=81=97=E3=81=AA=E3=81=84=E3=81=A8=E3=81=84=E3=81=91=E3=81=AA?= =?utf8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Core/Direct2D/D2DRenderCommon.cs | 101 ++++++++++++++---------- UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs | 2 +- WPF/FooEditEngine/Direct2D/D2DRender.cs | 2 +- Windows/FooEditEngine/D2DTextRender.cs | 2 +- 4 files changed, 61 insertions(+), 46 deletions(-) diff --git a/Core/Direct2D/D2DRenderCommon.cs b/Core/Direct2D/D2DRenderCommon.cs index 505fcd7..cc76282 100644 --- a/Core/Direct2D/D2DRenderCommon.cs +++ b/Core/Direct2D/D2DRenderCommon.cs @@ -94,8 +94,6 @@ namespace FooEditEngine { ResourceManager cache = new ResourceManager(); - public D2D.Factory Factory; - public D2D.StrokeStyle Get(D2D.RenderTarget render,HilightType type) { return this.Get(render.Factory, type); @@ -104,13 +102,11 @@ namespace FooEditEngine [Obsolete] public D2D.StrokeStyle Get(HilightType type) { - return this.Get(this.Factory, type); + return this.Get(D2DRenderShared.D2DFactory, type); } public D2D.StrokeStyle Get(D2D.Factory factory,HilightType type) { - if(this.Factory == null || this.Factory.IsDisposed) - throw new InvalidOperationException(); D2D.StrokeStyle stroke; if (this.cache.TryGetValue(type, out stroke)) return stroke; @@ -143,7 +139,7 @@ namespace FooEditEngine prop.DashStyle = D2D.DashStyle.Dot; break; } - stroke = new D2D.StrokeStyle(this.Factory, prop); + stroke = new D2D.StrokeStyle(D2DRenderShared.D2DFactory, prop); this.cache.Add(type, stroke); return stroke; } @@ -153,12 +149,56 @@ namespace FooEditEngine } } + class D2DRenderShared + { + static DW.Factory _DWFactory; + static public DW.Factory DWFactory + { + get + { + if(_DWFactory == null) + { + _DWFactory = new DW.Factory(DW.FactoryType.Shared); + } + return _DWFactory; + } + } +#if METRO || WINDOWS_UWP + static D2D.Factory1 _D2DFactory; + + static public D2D.Factory1 D2DFactory + { + get + { + if (_D2DFactory == null) + { + _D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded); + } + return _D2DFactory; + } + } +#else + static D2D.Factory _D2DFactory; + static public D2D.Factory D2DFactory + { + get + { + if (_D2DFactory == null) + { + _D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded); + } + return _D2DFactory; + } + } +#endif + + } + class D2DRenderCommon : IDisposable { InlineManager HiddenChars; TextAntialiasMode _TextAntialiasMode; Color4 _ControlChar,_Forground,_URL,_Hilight; - DW.Factory DWFactory; DW.TextFormat format; protected CustomTextRenderer textRender; protected D2D.Bitmap cachedBitMap; @@ -168,20 +208,6 @@ namespace FooEditEngine protected bool hasCache = false; protected Size renderSize; -#if METRO || WINDOWS_UWP - protected D2D.Factory1 D2DFactory - { - get; - private set; - } -#else - protected D2D.Factory D2DFactory - { - get; - private set; - } -#endif - protected ColorBrushCollection Brushes { get; @@ -208,15 +234,8 @@ namespace FooEditEngine public D2DRenderCommon() { - this.DWFactory = new DW.Factory(DW.FactoryType.Shared); -#if METRO || WINDOWS_UWP - this.D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded); -#else - this.D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded); -#endif this.Brushes = new ColorBrushCollection(); this.Strokes = new StrokeCollection(); - this.Strokes.Factory = this.D2DFactory; this.ChangedRenderResource += (s, e) => { }; this.ChangedRightToLeft += (s, e) => { }; this.renderSize = new Size(); @@ -236,12 +255,12 @@ namespace FooEditEngine float dpix, dpiy; this.GetDpi(out dpix, out dpiy); - this.format = new DW.TextFormat(this.DWFactory, fontName, fontWeigth, fontStyle, fontSize); + this.format = new DW.TextFormat(D2DRenderShared.DWFactory, fontName, fontWeigth, fontStyle, fontSize); this.format.WordWrapping = DW.WordWrapping.NoWrap; this.format.ReadingDirection = GetDWRightDirect(_RightToLeft); if (this.HiddenChars == null) - this.HiddenChars = new InlineManager(this.DWFactory, this.format, this.ControlChar, this.Brushes); + this.HiddenChars = new InlineManager(D2DRenderShared.DWFactory, this.format, this.ControlChar, this.Brushes); else this.HiddenChars.Format = this.format; @@ -249,12 +268,12 @@ namespace FooEditEngine this.hasCache = false; - MyTextLayout layout = new MyTextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false); + MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false); layout.RightToLeft = false; this.emSize = new Size(layout.Width, layout.Height); layout.Dispose(); - layout = new MyTextLayout(this.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false); + layout = new MyTextLayout(D2DRenderShared.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false); layout.RightToLeft = false; #if METRO this.FoldingWidth = Math.Max(D2DRenderCommon.MiniumeWidth, layout.Width); @@ -552,7 +571,7 @@ namespace FooEditEngine if (value == 0) return; this.tabLength = value; - DW.TextLayout layout = new DW.TextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue); + DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue); float width = (float)(layout.Metrics.Width * value); this.HiddenChars.TabWidth = width; this.format.IncrementalTabStop = width; @@ -624,7 +643,7 @@ namespace FooEditEngine throw new ArgumentOutOfRangeException(); } this.GetDpi(out dpix, out dpiy); - MyTextLayout layout = new MyTextLayout(this.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false); + MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false); layout.StringAlignment = align; layout.Draw(this.render, (float)x, (float)y, brush); layout.Dispose(); @@ -728,7 +747,7 @@ namespace FooEditEngine public void DrawLine(Point from, Point to) { D2D.Brush brush = this.Brushes.Get(this.Foreground); - D2D.StrokeStyle stroke = this.Strokes.Get(this.D2DFactory,HilightType.Sold); + D2D.StrokeStyle stroke = this.Strokes.Get(D2DRenderShared.D2DFactory,HilightType.Sold); this.render.DrawLine(from, to, brush, 1.0f, stroke); } @@ -754,13 +773,13 @@ namespace FooEditEngine D2D.SolidColorBrush brush = this.Brushes.Get(color); if (type == HilightType.Squiggle) - effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory, HilightType.Squiggle), thickness); + effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory, HilightType.Squiggle), thickness); else if (type == HilightType.Select) effecter = new HilightMarker(this.render, brush); else if (type == HilightType.None) effecter = null; else - effecter = new LineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory,type), thickness); + effecter = new LineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory,type), thickness); if (effecter != null) { @@ -781,7 +800,7 @@ namespace FooEditEngine this.GetDpi(out dpix,out dpiy); bool hasNewLine = str.Length > 0 && str[str.Length - 1] == Document.NewLine; - MyTextLayout newLayout = new MyTextLayout(this.DWFactory, + MyTextLayout newLayout = new MyTextLayout(D2DRenderShared.DWFactory, str, this.format, this.TextArea.Width, @@ -853,7 +872,7 @@ namespace FooEditEngine foreach (string str in doc.GetLines(startIndex, endIndex)) { - DW.TextLayout layout = new DW.TextLayout(this.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue); + DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue); int i = startIndex; foreach (DW.LineMetrics metrics in layout.GetLineMetrics()) @@ -891,10 +910,6 @@ namespace FooEditEngine this.HiddenChars.Clear(); if (this.format != null) this.format.Dispose(); - if (this.DWFactory != null) - this.DWFactory.Dispose(); - if (this.D2DFactory != null) - this.D2DFactory.Dispose(); } this._Disposed = true; } diff --git a/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs b/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs index 56370cd..f939545 100644 --- a/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs +++ b/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs @@ -79,7 +79,7 @@ namespace FooEditEngine public virtual void ConstructRenderAndResoruce(double width, double height) { - this.D2DDevice = new D2D.Device(this.D2DFactory, this.DXGIDevice); + this.D2DDevice = new D2D.Device(D2DRenderShared.D2DFactory, this.DXGIDevice); this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None); float dpiX, dpiY; this.GetDpi(out dpiX, out dpiY); diff --git a/WPF/FooEditEngine/Direct2D/D2DRender.cs b/WPF/FooEditEngine/Direct2D/D2DRender.cs index 54d5c74..7bc47bb 100644 --- a/WPF/FooEditEngine/Direct2D/D2DRender.cs +++ b/WPF/FooEditEngine/Direct2D/D2DRender.cs @@ -407,7 +407,7 @@ namespace FooEditEngine.WPF resource.Dispose(); texture.Dispose(); - this.render = new D2D.RenderTarget(this.D2DFactory, this.surface, prop); + this.render = new D2D.RenderTarget(D2DRenderShared.D2DFactory, this.surface, prop); D2D.BitmapProperties bmpProp = new D2D.BitmapProperties(); bmpProp.DpiX = dpiX; diff --git a/Windows/FooEditEngine/D2DTextRender.cs b/Windows/FooEditEngine/D2DTextRender.cs index 5e8b4d1..3828a3c 100644 --- a/Windows/FooEditEngine/D2DTextRender.cs +++ b/Windows/FooEditEngine/D2DTextRender.cs @@ -131,7 +131,7 @@ namespace FooEditEngine.Windows hwndProp.Hwnd = this.TextBox.Handle; hwndProp.PixelSize = new SharpDX.Size2((int)(this.TextBox.Size.Width * this.GetScale()), (int)(this.TextBox.Size.Height * this.GetScale())); hwndProp.PresentOptions = D2D.PresentOptions.Immediately; - this.render = new D2D.WindowRenderTarget(this.D2DFactory, prop, hwndProp); + this.render = new D2D.WindowRenderTarget(D2DRenderShared.D2DFactory, prop, hwndProp); D2D.BitmapProperties bmpProp = new D2D.BitmapProperties(); bmpProp.DpiX = dpiX; -- 2.11.0