@@ -318,6 +318,11 @@ ref lockBufferStride
318
318
/// on the back buffer and request a render pass.
319
319
/// </summary>
320
320
public void Unlock ( )
321
+ {
322
+ UnlockInner ( ) ;
323
+ }
324
+
325
+ private void UnlockInner ( bool shouldSubscribeToCommittingBatch = true )
321
326
{
322
327
WritePreamble ( ) ;
323
328
@@ -334,34 +339,23 @@ public void Unlock()
334
339
_pBackBufferLock . Dispose ( ) ;
335
340
_pBackBufferLock = null ;
336
341
337
- if ( _hasDirtyRects )
342
+ if ( shouldSubscribeToCommittingBatch )
338
343
{
339
- SubscribeToCommittingBatch ( ) ;
340
-
341
- //
342
- // Notify listeners that we have changed.
343
- //
344
- WritePostscript ( ) ;
344
+ SubscribeToCommittingBatchAndWritePostscript ( ) ;
345
345
}
346
346
}
347
347
}
348
348
349
- private void UnlockWithoutSubscribeToCommittingBatch ( )
349
+ private void SubscribeToCommittingBatchAndWritePostscript ( )
350
350
{
351
- WritePreamble ( ) ;
352
-
353
- if ( _lockCount == 0 )
351
+ if ( _hasDirtyRects )
354
352
{
355
- throw new InvalidOperationException ( SR . Get ( SRID . Image_MustBeLocked ) ) ;
356
- }
357
- Invariant . Assert ( _lockCount > 0 , "Lock count should never be negative!" ) ;
353
+ SubscribeToCommittingBatch ( ) ;
358
354
359
- _lockCount -- ;
360
- if ( _lockCount == 0 )
361
- {
362
- // This makes the back buffer read-only.
363
- _pBackBufferLock . Dispose ( ) ;
364
- _pBackBufferLock = null ;
355
+ //
356
+ // Notify listeners that we have changed.
357
+ //
358
+ WritePostscript ( ) ;
365
359
}
366
360
}
367
361
@@ -814,18 +808,10 @@ out _pDoubleBufferedBitmap
814
808
source . CriticalCopyPixels ( rcFull , _backBuffer , bufferSize , _backBufferStride . Value ) ;
815
809
AddDirtyRect ( rcFull ) ;
816
810
817
- UnlockWithoutSubscribeToCommittingBatch ( ) ;
811
+ UnlockInner ( shouldSubscribeToCommittingBatch : false ) ;
818
812
}
819
813
820
- if ( _hasDirtyRects )
821
- {
822
- SubscribeToCommittingBatch ( ) ;
823
-
824
- //
825
- // Notify listeners that we have changed.
826
- //
827
- WritePostscript ( ) ;
828
- }
814
+ SubscribeToCommittingBatchAndWritePostscript ( ) ;
829
815
830
816
EndInit ( ) ;
831
817
}
0 commit comments