Пример #1
0
        private void CreateOrUpdateDirect2D()
        {
            // Dispose and recreate all devices only if the DirectXDevice changed
            if (dxDeviceCache != dx11Service.DirectXDevice)
            {
                dxDeviceCache = dx11Service.DirectXDevice;

                if (d2dDevice != null)
                {
                    d2dDevice.DisposeAll();
                }

                var d3dDevice = dxDeviceCache.Device;
                d2dDevice = new Direct2DDevice(services, d3dDevice,
                                               d3dDevice.CreationFlags.HasFlag(DeviceCreationFlags.Debug) ? DebugLevel.Warning : DebugLevel.None);

                var deviceSettings = services.GetService <IDirectXDeviceSettings>();
                if (!MathHelper.ScalarNearEqual(deviceSettings.HorizontalDpi, d2dDevice.HorizontalDpi) ||
                    !MathHelper.ScalarNearEqual(deviceSettings.VerticalDpi, d2dDevice.VerticalDpi))
                {
                    throw new InvalidOperationException("Direct2D device DPI values do not match Direct3D device DPI values");
                }

                LayoutManager.Scale = deviceSettings.PreferredBackBufferWidth / 1920f;

                OnDeviceCreated(EventArgs.Empty);
            }
        }
Пример #2
0
 protected Bitmap(string name, Direct2DDevice device, Size2 size, BitmapProperties1 bitmapProperties)
     : base(name, device)
 {
     Properties = bitmapProperties;
     Resource   = ToDispose(new Bitmap1(device, size, bitmapProperties));
     Size       = size;
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Direct2DSurface"/> class.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="device"></param>
        /// <param name="services">The service provider from where to get <see cref="IDirectXDeviceService"/> and <see cref="IDirect2DDevice"/>.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="services"/> is null.</exception>
        protected Direct2DSurface(string name, Direct2DDevice device)
            : base(name, device)
        {
            this.services = device.Services;

            IsDirty   = true;
            IsVisible = true;
        }
Пример #4
0
        public static BitmapTarget New(string name, Direct2DDevice device, int width, int height, PixelFormat format)
        {
            Texture2DDescription renderTargetDescription = new Texture2DDescription
            {
                Width             = width,
                Height            = height,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                BindFlags         = BindFlags.RenderTarget,
                Format            = format,
                MipLevels         = CalculateMipMapCount(width, height),
                Usage             = ResourceUsage.Default,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            };

            Texture2D texture = new Texture2D(device, renderTargetDescription);

            return(new BitmapTarget(name, device, texture.QueryInterface <Surface>(), CreateDescription(device.HorizontalDpi, device.VerticalDpi, format)));
        }
Пример #5
0
 public static BitmapTarget New(string name, Direct2DDevice device, Surface surface)
 {
     return(new BitmapTarget(name, device, surface, CreateDescription(device.HorizontalDpi, device.VerticalDpi, surface.Description.Format)));
 }
Пример #6
0
 protected BitmapTarget(string name, Direct2DDevice device, Surface surface, BitmapProperties1 description)
     : base(name, device, surface, description)
 {
     Initialize(Resource);
 }
Пример #7
0
 protected Direct2DResource(string name, Direct2DDevice device)
     : base(name)
 {
     Contract.Requires <ArgumentNullException>(device != null, "device");
     Device = device;
 }
Пример #8
0
 protected Bitmap(string name, Direct2DDevice device, Surface surface, BitmapProperties1 bitmapProperties)
     : base(name, device)
 {
     Properties = bitmapProperties;
     Resource   = ToDispose(new Bitmap1(device, ToDispose(surface), bitmapProperties));
 }
Пример #9
0
 public static BackBufferSurface New(Direct2DDevice device)
 {
     return(new BackBufferSurface(device));
 }
Пример #10
0
 protected BackBufferSurface(Direct2DDevice device)
     : base("D2D_Backbuffer", device)
 {
 }