OSDN Git Service

レンダーターゲットをクラス変数として持たせておく意味はない
authortest <test@yahoo.co.jp>
Sun, 23 Aug 2020 01:16:16 +0000 (10:16 +0900)
committertest <test@yahoo.co.jp>
Sun, 23 Aug 2020 01:16:16 +0000 (10:16 +0900)
Core/Direct2D/CustomTextRenderer.cs
Core/Direct2D/D2DRenderCommon.cs
Core/Direct2D/InlineChar.cs
Core/Direct2D/MultiSet.cs
Core/Direct2D/MyTextLayout.cs
UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs
WPF/FooEditEngine/Direct2D/D2DRender.cs
Windows/FooEditEngine/D2DTextRender.cs

index 6b77527..ee4daa7 100644 (file)
@@ -17,13 +17,11 @@ namespace FooEditEngine
 {
     sealed class CustomTextRenderer : CallbackBase, DW.TextRenderer
     {
-        D2D.RenderTarget render;
         ColorBrushCollection brushes;
         StrokeCollection strokes;
 
-        public CustomTextRenderer(D2D.RenderTarget render, ColorBrushCollection brushes,StrokeCollection strokes,Color4 defalut)
+        public CustomTextRenderer(ColorBrushCollection brushes,StrokeCollection strokes,Color4 defalut)
         {
-            this.render = render;
             this.DefaultFore = defalut;
             this.brushes = brushes;
             this.strokes = strokes;
@@ -39,7 +37,11 @@ namespace FooEditEngine
 
         public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, D2D.MeasuringMode measuringMode, DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
         {
-            D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                return SharpDX.Result.Ok;
+
+            D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
             bool isDrawGlyphRun = true;
             if (clientDrawingEffect != null)
             {
@@ -53,12 +55,12 @@ namespace FooEditEngine
                 }
                 else if(selectedEffect != null)
                 {
-                    foreBrush = this.brushes.Get(selectedEffect.Fore);
+                    foreBrush = this.brushes.Get(render, selectedEffect.Fore);
                 }
                 else if (drawingEffect != null)
                 {
                     if (drawingEffect.Stroke == HilightType.Url)
-                        foreBrush = this.brushes.Get(drawingEffect.Fore);
+                        foreBrush = this.brushes.Get(render, drawingEffect.Fore);
                 }
             }
 
@@ -109,39 +111,51 @@ namespace FooEditEngine
 
         public Result DrawInlineObject(object clientDrawingContext, float originX, float originY, DW.InlineObject inlineObject, bool isSideways, bool isRightToLeft, ComObject clientDrawingEffect)
         {
-            inlineObject.Draw(this.render, this, originX, originY, isSideways, isRightToLeft, clientDrawingEffect);
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                return SharpDX.Result.Ok;
+
+            inlineObject.Draw(render, this, originX, originY, isSideways, isRightToLeft, clientDrawingEffect);
             return Result.Ok;
         }
 
         public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref DW.Strikethrough strikethrough, ComObject clientDrawingEffect)
         {
-            D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                return SharpDX.Result.Ok;
+
+            D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
             DrawingEffect effect = clientDrawingEffect as DrawingEffect;
             if (clientDrawingEffect != null && clientDrawingEffect != null)
             {
-                foreBrush = this.brushes.Get(effect.Fore);
+                foreBrush = this.brushes.Get(render, effect.Fore);
             }
             if (effect == null)
             {
                 render.DrawLine(new Vector2(baselineOriginX, baselineOriginY + strikethrough.Offset),
                     new Vector2(baselineOriginX + strikethrough.Width - 1, baselineOriginY + strikethrough.Offset),
                     foreBrush,
-                    GetThickness(strikethrough.Thickness));
+                    GetThickness(render, strikethrough.Thickness));
             }
             return Result.Ok;
         }
 
         public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref DW.Underline underline, ComObject clientDrawingEffect)
         {
-            D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                return SharpDX.Result.Ok;
+
+            D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
             DrawingEffect effect = clientDrawingEffect as DrawingEffect;
             if (clientDrawingEffect != null && effect != null)
             {
-                foreBrush = this.brushes.Get(effect.Fore);
+                foreBrush = this.brushes.Get(render, effect.Fore);
                 float thickness = effect.isBoldLine ? D2DRenderCommon.BoldThickness : D2DRenderCommon.NormalThickness;
                 if (effect.Stroke == HilightType.Squiggle)
                 {
-                    SquilleLineMarker marker = new D2DSquilleLineMarker(this.render, this.brushes.Get(effect.Fore), this.strokes.Get(this.render,effect.Stroke), 1);
+                    SquilleLineMarker marker = new D2DSquilleLineMarker(render, this.brushes.Get(render, effect.Fore), this.strokes.Get(render,effect.Stroke), 1);
                     marker.Draw(
                         baselineOriginX, baselineOriginY + underline.Offset,
                         underline.Width, underline.RunHeight
@@ -149,7 +163,7 @@ namespace FooEditEngine
                 }
                 else
                 {
-                    LineMarker marker = new LineMarker(this.render, this.brushes.Get(effect.Fore), this.strokes.Get(this.render,effect.Stroke), GetThickness(thickness));
+                    LineMarker marker = new LineMarker(render, this.brushes.Get(render, effect.Fore), this.strokes.Get(render,effect.Stroke), GetThickness(render, thickness));
                     marker.Draw(
                         baselineOriginX, baselineOriginY + underline.Offset,
                         underline.Width, 0
@@ -161,7 +175,7 @@ namespace FooEditEngine
                 render.DrawLine(new Vector2(baselineOriginX, baselineOriginY + underline.Offset),
                     new Vector2(baselineOriginX + underline.Width - 1, baselineOriginY + underline.Offset),
                     foreBrush,
-                    GetThickness(underline.Thickness));
+                    GetThickness(render,underline.Thickness));
             }
 
             return SharpDX.Result.Ok;
@@ -173,12 +187,20 @@ namespace FooEditEngine
 
         public SharpDX.Mathematics.Interop.RawMatrix3x2 GetCurrentTransform(object clientDrawingContext)
         {
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                throw new InvalidOperationException("render is null");
+
             SharpDX.Mathematics.Interop.RawMatrix3x2 d2Dmatrix = render.Transform;
             return d2Dmatrix;
         }
 
         public float GetPixelsPerDip(object clientDrawingContext)
         {
+            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+            if (render == null)
+                throw new InvalidOperationException("render is null");
+
             return render.PixelSize.Width / 96f;
         }
 
@@ -189,9 +211,9 @@ namespace FooEditEngine
 
         #endregion
 
-        float GetThickness(float thickness)
+        float GetThickness(D2D.RenderTarget render,float thickness)
         {
-            if (this.render.AntialiasMode == D2D.AntialiasMode.Aliased)
+            if (render.AntialiasMode == D2D.AntialiasMode.Aliased)
                 return (int)(thickness + 0.5);
             else
                 return thickness;
index 2622201..efcf138 100644 (file)
@@ -55,30 +55,13 @@ namespace FooEditEngine
 
         public event EventHandler RenderChanged;
 
-        public D2D.RenderTarget Render
+        public D2D.SolidColorBrush Get(D2D.RenderTarget render,Color4 key)
         {
-            get
-            {
-                return this._render;
-            }
-            set
-            {
-                this._render = value;
-                this.Clear();
-                if (this.RenderChanged != null)
-                    this.RenderChanged(this, null);
-            }
-        }
-
-        public D2D.SolidColorBrush Get(Color4 key)
-        {
-            if (this.Render == null || this.Render.IsDisposed)
-                throw new InvalidOperationException();
             D2D.SolidColorBrush brush;
             bool result = cache.TryGetValue(key, out brush);
             if (!result)
             {
-                brush = new D2D.SolidColorBrush(this.Render, key);
+                brush = new D2D.SolidColorBrush(render, key);
                 cache.Add(key, brush);
             }
             
@@ -173,7 +156,7 @@ namespace FooEditEngine
             {
                 if (_D2DFactory == null)
                 {
-                    _D2DFactory = new D2D.Factory1(D2D.FactoryType.MultiThreaded);
+                    _D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
                 }
                 return _D2DFactory;
             }
@@ -186,7 +169,7 @@ namespace FooEditEngine
             {
                 if (_D2DFactory == null)
                 {
-                    _D2DFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded);
+                    _D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
                 }
                 return _D2DFactory;
             }
@@ -229,7 +212,6 @@ namespace FooEditEngine
             {
                 _render = value;
                 this.TextAntialiasMode = this._TextAntialiasMode;
-                this.Brushes.Render = this.render;
             }
         }
 
@@ -253,9 +235,6 @@ namespace FooEditEngine
             if(this.format != null)
                 this.format.Dispose();
 
-            if (this.HiddenChars != null)
-                this.HiddenChars = null;
-
             float dpix, dpiy;
             this.GetDpi(out dpix, out dpiy);
 
@@ -595,8 +574,8 @@ namespace FooEditEngine
             ellipse.Point = p;
             ellipse.RadiusX = (float)radius;
             ellipse.RadiusY = (float)radius;
-            this.render.FillEllipse(ellipse, this.Brushes.Get(this.Background));
-            this.render.DrawEllipse(ellipse, this.Brushes.Get(this.Foreground));
+            this.render.FillEllipse(ellipse, this.Brushes.Get(this.render,this.Background));
+            this.render.DrawEllipse(ellipse, this.Brushes.Get(this.render, this.Foreground));
         }
 
 
@@ -638,10 +617,10 @@ namespace FooEditEngine
             switch (colorType)
             {
                 case StringColorType.Forground:
-                    brush = this.Brushes.Get(this.Foreground);
+                    brush = this.Brushes.Get(this.render, this.Foreground);
                     break;
                 case StringColorType.LineNumber:
-                    brush = this.Brushes.Get(this.LineNumber);
+                    brush = this.Brushes.Get(this.render, this.LineNumber);
                     break;
                 default:
                     throw new ArgumentOutOfRangeException();
@@ -667,23 +646,23 @@ namespace FooEditEngine
             switch(type)
             {
                 case FillRectType.OverwriteCaret:
-                    brush = this.Brushes.Get(this.OverwriteCaret);
+                    brush = this.Brushes.Get(this.render, this.OverwriteCaret);
                     this.render.FillRectangle(rect, brush);
                     break;
                 case FillRectType.InsertCaret:
-                    brush = this.Brushes.Get(this.InsertCaret);
+                    brush = this.Brushes.Get(this.render, this.InsertCaret);
                     this.render.FillRectangle(rect, brush);
                     break;
                 case FillRectType.InsertPoint:
-                    brush = this.Brushes.Get(this.Hilight);
+                    brush = this.Brushes.Get(this.render, this.Hilight);
                     this.render.FillRectangle(rect, brush);
                     break;
                 case FillRectType.LineMarker:
-                    brush = this.Brushes.Get(this.LineMarker);
+                    brush = this.Brushes.Get(this.render, this.LineMarker);
                     this.render.DrawRectangle(rect, brush, EditView.LineMarkerThickness);
                     break;
                 case FillRectType.UpdateArea:
-                    brush = this.Brushes.Get(this.UpdateArea);
+                    brush = this.Brushes.Get(this.render, this.UpdateArea);
                     this.render.FillRectangle(rect, brush);
                     break;
             }
@@ -727,7 +706,7 @@ namespace FooEditEngine
                 }
             }
 
-            layout.Draw(textRender, (float)x, (float)y);
+            layout.Draw(this.render,textRender, (float)x, (float)y);
 
         }
 
@@ -745,12 +724,12 @@ namespace FooEditEngine
         {
             if (color == null)
                 return;
-            layout.SetDrawingEffect(this.Brushes.Get((Color4)color), new DW.TextRange(start, length));
+            layout.SetDrawingEffect(this.Brushes.Get(this.render, (Color4)color), new DW.TextRange(start, length));
         }
 
         public void DrawLine(Point from, Point to)
         {
-            D2D.Brush brush = this.Brushes.Get(this.Foreground);
+            D2D.Brush brush = this.Brushes.Get(this.render, this.Foreground);
             D2D.StrokeStyle stroke = this.Strokes.Get(D2DRenderShared.D2DFactory,HilightType.Sold);
             this.render.DrawLine(from, to, brush, 1.0f, stroke);
         }
@@ -774,7 +753,7 @@ namespace FooEditEngine
                 color = this.Foreground;
 
             IMarkerEffecter effecter = null;
-            D2D.SolidColorBrush brush = this.Brushes.Get(color);
+            D2D.SolidColorBrush brush = this.Brushes.Get(this.render, color);
 
             if (type == HilightType.Squiggle)
                 effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory, HilightType.Squiggle), thickness);
@@ -816,20 +795,20 @@ namespace FooEditEngine
             {
                 foreach (SyntaxInfo s in syntaxCollection)
                 {
-                    D2D.SolidColorBrush brush = this.Brushes.Get(this.Foreground);
+                    D2D.SolidColorBrush brush = this.Brushes.Get(this.render, this.Foreground);
                     switch (s.type)
                     {
                         case TokenType.Comment:
-                            brush = this.Brushes.Get(this.Comment);
+                            brush = this.Brushes.Get(this.render, this.Comment);
                             break;
                         case TokenType.Keyword1:
-                            brush = this.Brushes.Get(this.Keyword1);
+                            brush = this.Brushes.Get(this.render, this.Keyword1);
                             break;
                         case TokenType.Keyword2:
-                            brush = this.Brushes.Get(this.Keyword2);
+                            brush = this.Brushes.Get(this.render, this.Keyword2);
                             break;
                         case TokenType.Literal:
-                            brush = this.Brushes.Get(this.Literal);
+                            brush = this.Brushes.Get(this.render, this.Literal);
                             break;
                     }
                     newLayout.SetDrawingEffect(brush, new DW.TextRange(s.index, s.length));
@@ -942,10 +921,10 @@ namespace FooEditEngine
                 if (inlineObject != null)
                 {
                     layout.SetInlineObject(inlineObject, new DW.TextRange(i, 1));
-                    layout.SetDrawingEffect(this.Brushes.Get(this.ControlChar), new DW.TextRange(i, 1));
+                    layout.SetDrawingEffect(this.Brushes.Get(this.render, this.ControlChar), new DW.TextRange(i, 1));
                 }
             }
-            layout.SetLineBreakBrush(this.Brushes.Get(this.ControlChar));
+            layout.SetLineBreakBrush(this.Brushes.Get(this.render, this.ControlChar));
         }
     }
 }
index 642cfb3..2389d74 100644 (file)
@@ -41,7 +41,7 @@ namespace FooEditEngine
             if (render == null)
                 return;
 
-            D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+            D2D.SolidColorBrush foreBrush = this.brushes.Get(render,this.DefaultFore);
             if (clientDrawingEffect != null)
             {
                 var drawingForeBrush = clientDrawingEffect as D2D.SolidColorBrush;
@@ -53,7 +53,7 @@ namespace FooEditEngine
                 }
                 else if (selectedEffect != null)
                 {
-                    foreBrush = this.brushes.Get(selectedEffect.Fore);
+                    foreBrush = this.brushes.Get(render, selectedEffect.Fore);
                 }
             }
 
@@ -174,7 +174,7 @@ namespace FooEditEngine
             D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
             if (render == null)
                 return;
-            D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+            D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
             if (clientDrawingEffect != null)
             {
                 var drawingForeBrush = clientDrawingEffect as D2D.SolidColorBrush;
@@ -186,7 +186,7 @@ namespace FooEditEngine
                 }
                 else if (selectedEffect != null)
                 {
-                    foreBrush = this.brushes.Get(selectedEffect.Fore);
+                    foreBrush = this.brushes.Get(render, selectedEffect.Fore);
                 }
             }
             DW.InlineObjectMetrics metrics = this.Metrics;
index 963f4da..3d93d9e 100644 (file)
@@ -33,7 +33,6 @@ namespace FooEditEngine
             this._Format = format;
             this._Fore = fore;
             this.Brushes = brushes;
-            this.Brushes.RenderChanged += Brushes_RenderChanged;
         }
 
         public bool ContainsSymbol(char c)
@@ -51,7 +50,6 @@ namespace FooEditEngine
             }
             else
             {
-                D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
                 for (int i = 0; i < DuplicateCount; i++)
                 {
                     this.InlineChars.Add(c, new InlineChar(this.Factory, this.Format, this.Brushes, this.Fore, alt));
@@ -128,7 +126,6 @@ namespace FooEditEngine
                 if (!this.InlineTabs.TryGet(width, out collection))
                 {
                     collection = new List<InlineTab>();
-                    D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
                     for (int i = 0; i < DuplicateCount; i++)
                         collection.Add(new InlineTab(this.Brushes, this.Fore, width, layout.Height));
                     this.InlineTabs.Add(width, collection);
@@ -165,16 +162,11 @@ namespace FooEditEngine
 
             this.InlineTabs.Clear();
 
-            D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
             foreach (KeyValuePair<char, char> kv in list)
                 for (int i = 0; i < DuplicateCount; i++)
                     this.InlineChars.Add(kv.Key, new InlineChar(this.Factory, this.Format, this.Brushes, this.Fore, kv.Value));
         }
 
-        void Brushes_RenderChanged(object sender, EventArgs e)
-        {
-            this.ReGenerate();
-        }
     }
     sealed class MultiSet<T, J>
         where J : IDisposable
index 6d90504..0a1f90a 100644 (file)
@@ -187,9 +187,9 @@ namespace FooEditEngine
             }
         }
 
-        public void Draw(DW.TextRenderer render, float x, float y)
+        public void Draw(D2D.RenderTarget d2drender, DW.TextRenderer render, float x, float y)
         {
-            this.layout.Draw(render, x, y);
+            this.layout.Draw(d2drender, render, x, y);
         }
 
         public void Draw(D2D.RenderTarget render, float x, float y, D2D.Brush brush)
index 2e7e937..9fb0075 100644 (file)
@@ -86,7 +86,7 @@ namespace FooEditEngine
             this.D2DContext.DotsPerInch = new Size2F(dpiX, dpiY);
             this.render = this.D2DContext;
             this.renderSize = new Size(width, height);
-            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+            this.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
         }
 
         public void ReinitTextFormat()
index 7bc47bb..e12f559 100644 (file)
@@ -416,7 +416,7 @@ namespace FooEditEngine.WPF
             this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
             this.hasCache = false;
 
-            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+            this.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
 
             this.renderSize = new Size(width, height);
         }
index 3828a3c..9c5e946 100644 (file)
@@ -140,7 +140,7 @@ namespace FooEditEngine.Windows
             this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
             this.hasCache = false;
 
-            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+            this.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
 
             this.renderSize = new Size(width, height);