• R/O
  • HTTP
  • SSH
  • HTTPS

FooEditEngine: Commit


Commit MetaInfo

Revisionbefa91ef48fce8db03ac6d4251e0db69e28665ea (tree)
Time2020-08-22 16:02:25
Authortest <test@yaho...>
Commitertest

Log Message

ファクトリーの類は共有にしないといけない

Change Summary

Incremental Difference

--- a/Core/Direct2D/D2DRenderCommon.cs
+++ b/Core/Direct2D/D2DRenderCommon.cs
@@ -94,8 +94,6 @@ namespace FooEditEngine
9494 {
9595 ResourceManager<HilightType, D2D.StrokeStyle> cache = new ResourceManager<HilightType, D2D.StrokeStyle>();
9696
97- public D2D.Factory Factory;
98-
9997 public D2D.StrokeStyle Get(D2D.RenderTarget render,HilightType type)
10098 {
10199 return this.Get(render.Factory, type);
@@ -104,13 +102,11 @@ namespace FooEditEngine
104102 [Obsolete]
105103 public D2D.StrokeStyle Get(HilightType type)
106104 {
107- return this.Get(this.Factory, type);
105+ return this.Get(D2DRenderShared.D2DFactory, type);
108106 }
109107
110108 public D2D.StrokeStyle Get(D2D.Factory factory,HilightType type)
111109 {
112- if(this.Factory == null || this.Factory.IsDisposed)
113- throw new InvalidOperationException();
114110 D2D.StrokeStyle stroke;
115111 if (this.cache.TryGetValue(type, out stroke))
116112 return stroke;
@@ -143,7 +139,7 @@ namespace FooEditEngine
143139 prop.DashStyle = D2D.DashStyle.Dot;
144140 break;
145141 }
146- stroke = new D2D.StrokeStyle(this.Factory, prop);
142+ stroke = new D2D.StrokeStyle(D2DRenderShared.D2DFactory, prop);
147143 this.cache.Add(type, stroke);
148144 return stroke;
149145 }
@@ -153,12 +149,56 @@ namespace FooEditEngine
153149 }
154150 }
155151
152+ class D2DRenderShared
153+ {
154+ static DW.Factory _DWFactory;
155+ static public DW.Factory DWFactory
156+ {
157+ get
158+ {
159+ if(_DWFactory == null)
160+ {
161+ _DWFactory = new DW.Factory(DW.FactoryType.Shared);
162+ }
163+ return _DWFactory;
164+ }
165+ }
166+#if METRO || WINDOWS_UWP
167+ static D2D.Factory1 _D2DFactory;
168+
169+ static public D2D.Factory1 D2DFactory
170+ {
171+ get
172+ {
173+ if (_D2DFactory == null)
174+ {
175+ _D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
176+ }
177+ return _D2DFactory;
178+ }
179+ }
180+#else
181+ static D2D.Factory _D2DFactory;
182+ static public D2D.Factory D2DFactory
183+ {
184+ get
185+ {
186+ if (_D2DFactory == null)
187+ {
188+ _D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
189+ }
190+ return _D2DFactory;
191+ }
192+ }
193+#endif
194+
195+ }
196+
156197 class D2DRenderCommon : IDisposable
157198 {
158199 InlineManager HiddenChars;
159200 TextAntialiasMode _TextAntialiasMode;
160201 Color4 _ControlChar,_Forground,_URL,_Hilight;
161- DW.Factory DWFactory;
162202 DW.TextFormat format;
163203 protected CustomTextRenderer textRender;
164204 protected D2D.Bitmap cachedBitMap;
@@ -168,20 +208,6 @@ namespace FooEditEngine
168208 protected bool hasCache = false;
169209 protected Size renderSize;
170210
171-#if METRO || WINDOWS_UWP
172- protected D2D.Factory1 D2DFactory
173- {
174- get;
175- private set;
176- }
177-#else
178- protected D2D.Factory D2DFactory
179- {
180- get;
181- private set;
182- }
183-#endif
184-
185211 protected ColorBrushCollection Brushes
186212 {
187213 get;
@@ -208,15 +234,8 @@ namespace FooEditEngine
208234
209235 public D2DRenderCommon()
210236 {
211- this.DWFactory = new DW.Factory(DW.FactoryType.Shared);
212-#if METRO || WINDOWS_UWP
213- this.D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
214-#else
215- this.D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
216-#endif
217237 this.Brushes = new ColorBrushCollection();
218238 this.Strokes = new StrokeCollection();
219- this.Strokes.Factory = this.D2DFactory;
220239 this.ChangedRenderResource += (s, e) => { };
221240 this.ChangedRightToLeft += (s, e) => { };
222241 this.renderSize = new Size();
@@ -236,12 +255,12 @@ namespace FooEditEngine
236255 float dpix, dpiy;
237256 this.GetDpi(out dpix, out dpiy);
238257
239- this.format = new DW.TextFormat(this.DWFactory, fontName, fontWeigth, fontStyle, fontSize);
258+ this.format = new DW.TextFormat(D2DRenderShared.DWFactory, fontName, fontWeigth, fontStyle, fontSize);
240259 this.format.WordWrapping = DW.WordWrapping.NoWrap;
241260 this.format.ReadingDirection = GetDWRightDirect(_RightToLeft);
242261
243262 if (this.HiddenChars == null)
244- this.HiddenChars = new InlineManager(this.DWFactory, this.format, this.ControlChar, this.Brushes);
263+ this.HiddenChars = new InlineManager(D2DRenderShared.DWFactory, this.format, this.ControlChar, this.Brushes);
245264 else
246265 this.HiddenChars.Format = this.format;
247266
@@ -249,12 +268,12 @@ namespace FooEditEngine
249268
250269 this.hasCache = false;
251270
252- MyTextLayout layout = new MyTextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false);
271+ MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false);
253272 layout.RightToLeft = false;
254273 this.emSize = new Size(layout.Width, layout.Height);
255274 layout.Dispose();
256275
257- layout = new MyTextLayout(this.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false);
276+ layout = new MyTextLayout(D2DRenderShared.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false);
258277 layout.RightToLeft = false;
259278 #if METRO
260279 this.FoldingWidth = Math.Max(D2DRenderCommon.MiniumeWidth, layout.Width);
@@ -552,7 +571,7 @@ namespace FooEditEngine
552571 if (value == 0)
553572 return;
554573 this.tabLength = value;
555- DW.TextLayout layout = new DW.TextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue);
574+ DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue);
556575 float width = (float)(layout.Metrics.Width * value);
557576 this.HiddenChars.TabWidth = width;
558577 this.format.IncrementalTabStop = width;
@@ -624,7 +643,7 @@ namespace FooEditEngine
624643 throw new ArgumentOutOfRangeException();
625644 }
626645 this.GetDpi(out dpix, out dpiy);
627- MyTextLayout layout = new MyTextLayout(this.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false);
646+ MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false);
628647 layout.StringAlignment = align;
629648 layout.Draw(this.render, (float)x, (float)y, brush);
630649 layout.Dispose();
@@ -728,7 +747,7 @@ namespace FooEditEngine
728747 public void DrawLine(Point from, Point to)
729748 {
730749 D2D.Brush brush = this.Brushes.Get(this.Foreground);
731- D2D.StrokeStyle stroke = this.Strokes.Get(this.D2DFactory,HilightType.Sold);
750+ D2D.StrokeStyle stroke = this.Strokes.Get(D2DRenderShared.D2DFactory,HilightType.Sold);
732751 this.render.DrawLine(from, to, brush, 1.0f, stroke);
733752 }
734753
@@ -754,13 +773,13 @@ namespace FooEditEngine
754773 D2D.SolidColorBrush brush = this.Brushes.Get(color);
755774
756775 if (type == HilightType.Squiggle)
757- effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory, HilightType.Squiggle), thickness);
776+ effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory, HilightType.Squiggle), thickness);
758777 else if (type == HilightType.Select)
759778 effecter = new HilightMarker(this.render, brush);
760779 else if (type == HilightType.None)
761780 effecter = null;
762781 else
763- effecter = new LineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory,type), thickness);
782+ effecter = new LineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory,type), thickness);
764783
765784 if (effecter != null)
766785 {
@@ -781,7 +800,7 @@ namespace FooEditEngine
781800 this.GetDpi(out dpix,out dpiy);
782801
783802 bool hasNewLine = str.Length > 0 && str[str.Length - 1] == Document.NewLine;
784- MyTextLayout newLayout = new MyTextLayout(this.DWFactory,
803+ MyTextLayout newLayout = new MyTextLayout(D2DRenderShared.DWFactory,
785804 str,
786805 this.format,
787806 this.TextArea.Width,
@@ -853,7 +872,7 @@ namespace FooEditEngine
853872
854873 foreach (string str in doc.GetLines(startIndex, endIndex))
855874 {
856- DW.TextLayout layout = new DW.TextLayout(this.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue);
875+ DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue);
857876
858877 int i = startIndex;
859878 foreach (DW.LineMetrics metrics in layout.GetLineMetrics())
@@ -891,10 +910,6 @@ namespace FooEditEngine
891910 this.HiddenChars.Clear();
892911 if (this.format != null)
893912 this.format.Dispose();
894- if (this.DWFactory != null)
895- this.DWFactory.Dispose();
896- if (this.D2DFactory != null)
897- this.D2DFactory.Dispose();
898913 }
899914 this._Disposed = true;
900915 }
--- a/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs
+++ b/UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs
@@ -79,7 +79,7 @@ namespace FooEditEngine
7979
8080 public virtual void ConstructRenderAndResoruce(double width, double height)
8181 {
82- this.D2DDevice = new D2D.Device(this.D2DFactory, this.DXGIDevice);
82+ this.D2DDevice = new D2D.Device(D2DRenderShared.D2DFactory, this.DXGIDevice);
8383 this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
8484 float dpiX, dpiY;
8585 this.GetDpi(out dpiX, out dpiY);
--- a/WPF/FooEditEngine/Direct2D/D2DRender.cs
+++ b/WPF/FooEditEngine/Direct2D/D2DRender.cs
@@ -407,7 +407,7 @@ namespace FooEditEngine.WPF
407407 resource.Dispose();
408408 texture.Dispose();
409409
410- this.render = new D2D.RenderTarget(this.D2DFactory, this.surface, prop);
410+ this.render = new D2D.RenderTarget(D2DRenderShared.D2DFactory, this.surface, prop);
411411
412412 D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
413413 bmpProp.DpiX = dpiX;
--- a/Windows/FooEditEngine/D2DTextRender.cs
+++ b/Windows/FooEditEngine/D2DTextRender.cs
@@ -131,7 +131,7 @@ namespace FooEditEngine.Windows
131131 hwndProp.Hwnd = this.TextBox.Handle;
132132 hwndProp.PixelSize = new SharpDX.Size2((int)(this.TextBox.Size.Width * this.GetScale()), (int)(this.TextBox.Size.Height * this.GetScale()));
133133 hwndProp.PresentOptions = D2D.PresentOptions.Immediately;
134- this.render = new D2D.WindowRenderTarget(this.D2DFactory, prop, hwndProp);
134+ this.render = new D2D.WindowRenderTarget(D2DRenderShared.D2DFactory, prop, hwndProp);
135135
136136 D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
137137 bmpProp.DpiX = dpiX;
Show on old repository browser