internal CachedBitmap(BitmapSourceSafeMILHandle bitmap) : base(true) { if (bitmap == null) { throw new ArgumentNullException("bitmap"); } // We're not calling CachedBitmap.Begin/EndInit because that would // invoke FinalizeCreation which calls CreateCachedBitmap that does // unnecessary work and only deals with BitmapFrames _bitmapInit.BeginInit(); _source = null; _createOptions = BitmapCreateOptions.None; _cacheOption = BitmapCacheOption.OnLoad; // // This constructor is used by D3DImage, which does not calculate memory pressure for // the bitmap parameter before calling the constructor. // bitmap.CalculateSize(); // This will QI to IWICBitmapSource for us. QI also AddRefs, of course. WicSourceHandle = bitmap; _syncObject = WicSourceHandle; IsSourceCached = true; CreationCompleted = true; _bitmapInit.EndInit(); }
private void InitFromWICSource( SafeMILHandle wicSource ) { _bitmapInit.BeginInit(); BitmapSourceSafeMILHandle bitmapSource = null; lock (_syncObject) { using (FactoryMaker factoryMaker = new FactoryMaker()) { HRESULT.Check(UnsafeNativeMethods.WICImagingFactory.CreateBitmapFromSource( factoryMaker.ImagingFactoryPtr, wicSource, WICBitmapCreateCacheOptions.WICBitmapCacheOnLoad, out bitmapSource)); } bitmapSource.CalculateSize(); } WicSourceHandle = bitmapSource; _isSourceCached = true; _bitmapInit.EndInit(); UpdateCachedSettings(); }
internal override void FinalizeCreation() { try { using (FactoryMaker myFactory = new FactoryMaker()) { SafeMILHandle renderTargetBitmap = null; HRESULT.Check(UnsafeNativeMethods.MILFactory2.CreateBitmapRenderTarget( myFactory.FactoryPtr, (uint)_pixelWidth, (uint)_pixelHeight, _format.Format, (float)_dpiX, (float)_dpiY, MILRTInitializationFlags.MIL_RT_INITIALIZE_DEFAULT, out renderTargetBitmap)); Debug.Assert(renderTargetBitmap != null && !renderTargetBitmap.IsInvalid); BitmapSourceSafeMILHandle bitmapSource = null; HRESULT.Check(MILRenderTargetBitmap.GetBitmap( renderTargetBitmap, out bitmapSource)); Debug.Assert(bitmapSource != null && !bitmapSource.IsInvalid); lock (_syncObject) { _renderTargetBitmap = renderTargetBitmap; bitmapSource.CalculateSize(); WicSourceHandle = bitmapSource; // For the purpose of rendering a RenderTargetBitmap, we always treat it as if it's // not cached. This is to ensure we never render and write to the same bitmap source // by the UCE thread and managed thread. _isSourceCached = false; } } CreationCompleted = true; UpdateCachedSettings(); } catch { _bitmapInit.Reset(); throw; } }
private void EnsureSource() { if (_frameSource == null) { if (_decoder == null) { HRESULT.Check((int)WinCodecErrors.WINCODEC_ERR_NOTINITIALIZED); } // // Its possible that the frame was originally created with a network URI // and DelayCreation was enabled. In this case, the decoder may not yet // exist even though the download is complete. The code below creates a // decoder if one does not exist. // if (_decoder.InternalDecoder == null) { Debug.Assert(_decoder is LateBoundBitmapDecoder); Debug.Assert(IsDownloading == false); _decoder = ((LateBoundBitmapDecoder)_decoder).Decoder; _syncObject = _decoder.SyncObject; Debug.Assert(_decoder.InternalDecoder != null); } IntPtr frameDecode = IntPtr.Zero; Debug.Assert(_syncObject != null); lock (_syncObject) { HRESULT.Check(UnsafeNativeMethods.WICBitmapDecoder.GetFrame( _decoder.InternalDecoder, (uint)_frameNumber, out frameDecode )); _frameSource = new BitmapSourceSafeMILHandle(frameDecode); _frameSource.CalculateSize(); } } }
private void EnsureSource() { if (_frameSource == null) { if (_decoder == null) { HRESULT.Check((int)WinCodecErrors.WINCODEC_ERR_NOTINITIALIZED); } // // Its possible that the frame was originally created with a network URI // and DelayCreation was enabled. In this case, the decoder may not yet // exist even though the download is complete. The code below creates a // decoder if one does not exist. // if (_decoder.InternalDecoder == null) { Debug.Assert(_decoder is LateBoundBitmapDecoder); Debug.Assert(IsDownloading == false); _decoder = ((LateBoundBitmapDecoder)_decoder).Decoder; _syncObject = _decoder.SyncObject; Debug.Assert(_decoder.InternalDecoder != null); } IntPtr frameDecode = IntPtr.Zero; Debug.Assert(_syncObject != null); lock (_syncObject) { HRESULT.Check(UnsafeNativeMethods.WICBitmapDecoder.GetFrame( _decoder.InternalDecoder, (uint)_frameNumber, out frameDecode )); _frameSource = new BitmapSourceSafeMILHandle(frameDecode); _frameSource.CalculateSize(); } } }
internal CachedBitmap(BitmapSourceSafeMILHandle bitmap) : base(true) { if (bitmap == null) { throw new ArgumentNullException("bitmap"); } // We're not calling CachedBitmap.Begin/EndInit because that would // invoke FinalizeCreation which calls CreateCachedBitmap that does // unnecessary work and only deals with BitmapFrames _bitmapInit.BeginInit(); _source = null; _createOptions = BitmapCreateOptions.None; _cacheOption = BitmapCacheOption.OnLoad; // // This constructor is used by D3DImage, which does not calculate memory pressure for // the bitmap parameter before calling the constructor. // bitmap.CalculateSize(); // This will QI to IWICBitmapSource for us. QI also AddRefs, of course. WicSourceHandle = bitmap; _syncObject = WicSourceHandle; IsSourceCached = true; CreationCompleted = true; _bitmapInit.EndInit(); }