OSDN Git Service

プラットフォームごとにバラバラなので、ビットマップキャッシュの部分は分離することにした
authorgdkhd812 <test@nnn.co.jp>
Tue, 27 Oct 2015 07:08:51 +0000 (12:38 +0530)
committergdkhd812 <test@nnn.co.jp>
Tue, 27 Oct 2015 07:08:51 +0000 (12:38 +0530)
Core/Direct2D/D2DRenderCommon.cs
WPF/FooEditEngine/Direct2D/D2DRender.cs
Windows/FooEditEngine/D2DTextRender.cs

index 2238410..47417eb 100644 (file)
@@ -186,13 +186,24 @@ namespace FooEditEngine
         D2D.Factory D2DFactory;
 #endif
         DW.TextFormat format;
-        D2D.Bitmap bitmap;
-        D2D.RenderTarget render;
+        protected D2D.Bitmap cachedBitMap;
         CustomTextRenderer textRender;
         int tabLength = 8;
-        bool hasCache, _ShowLineBreak;
-        Size renderSize = new Size();
+        bool _ShowLineBreak;
         Color4 _Comment, _Literal, _Keyword1, _Keyword2;
+        protected bool hasCache;
+
+        protected Size renderSize
+        {
+            get;
+            private set;
+        }
+
+        protected D2D.RenderTarget render
+        {
+            get;
+            private set;
+        }
 
         public D2DRenderCommon()
         {
@@ -205,6 +216,7 @@ namespace FooEditEngine
             this.Strokes.Factory = this.D2DFactory;
             this.ChangedRenderResource += (s, e) => { };
             this.ChangedRightToLeft += (s, e) => { };
+            this.renderSize = new Size();
         }
 
         public event ChangedRenderResourceEventHandler ChangedRenderResource;
@@ -560,18 +572,10 @@ namespace FooEditEngine
 
         public virtual void DrawCachedBitmap(Rectangle rect)
         {
-            if (this.render == null || this.render.IsDisposed)
-                return;
-            render.DrawBitmap(this.bitmap, rect, 1.0f, D2D.BitmapInterpolationMode.Linear, rect);
         }
 
         public virtual void CacheContent()
         {
-            if (this.render == null || this.bitmap == null || this.bitmap.IsDisposed || this.render.IsDisposed)
-                return;
-            render.Flush();
-            this.bitmap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
-            this.hasCache = true;
         }
 
         public virtual bool IsVaildCache()
@@ -869,15 +873,14 @@ namespace FooEditEngine
             bmpProp.DpiX = dpiX;
             bmpProp.DpiY = dpiY;
             bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Ignore);
-            this.bitmap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
+            this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
             this.hasCache = false;
 
             this.ConstrctedResource();
 
             this.textRender = new CustomTextRenderer(this.render, this.Brushes,this.Strokes, this.Foreground);
 
-            this.renderSize.Width = width;
-            this.renderSize.Height = height;
+            this.renderSize = new Size(width,height);
 
             this.TextAntialiasMode = this._TextAntialiasMode;
         }
@@ -915,8 +918,8 @@ namespace FooEditEngine
         public void DestructDeviceResource()
         {
             this.hasCache = false;
-            if (this.bitmap != null)
-                this.bitmap.Dispose();
+            if (this.cachedBitMap != null)
+                this.cachedBitMap.Dispose();
             this.Brushes.Clear();
             this.Strokes.Clear();
             this.Effects.Clear();
index e9c0832..4f31c7b 100644 (file)
@@ -258,6 +258,22 @@ namespace FooEditEngine.WPF
             return (DW.FontWeight)Enum.Parse(typeof(DW.FontWeight), weigth.ToString());
         }
 
+        public override void DrawCachedBitmap(Rectangle rect)
+        {
+            if (this.render == null || this.render.IsDisposed)
+                return;
+            render.DrawBitmap(this.cachedBitMap, rect, 1.0f, D2D.BitmapInterpolationMode.Linear, rect);
+        }
+
+        public override void CacheContent()
+        {
+            if (this.render == null || this.cachedBitMap == null || this.cachedBitMap.IsDisposed || this.render.IsDisposed)
+                return;
+            render.Flush();
+            this.cachedBitMap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
+            this.hasCache = true;
+        }
+
         void CreateDevice()
         {
             D3D10.FeatureLevel[] levels = new D3D10.FeatureLevel[]{D3D10.FeatureLevel.Level_10_1,
index bb6e5fe..f4b87bb 100644 (file)
@@ -84,6 +84,22 @@ namespace FooEditEngine.Windows
                 null);
         }
 
+        public override void DrawCachedBitmap(Rectangle rect)
+        {
+            if (this.render == null || this.render.IsDisposed)
+                return;
+            render.DrawBitmap(this.cachedBitMap, rect, 1.0f, D2D.BitmapInterpolationMode.Linear, rect);
+        }
+
+        public override void CacheContent()
+        {
+            if (this.render == null || this.cachedBitMap == null || this.cachedBitMap.IsDisposed || this.render.IsDisposed)
+                return;
+            render.Flush();
+            this.cachedBitMap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
+            this.hasCache = true;
+        }
+
         D2D.WindowRenderTarget WindowRender;
 
         protected override D2D.RenderTarget ConstructRender(D2D.Factory factory, D2D.RenderTargetProperties prop, double width, double height)