8000 Fix code · dotnet/wpf@209af94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 209af94

Browse files
committed
Fix code
1 parent 9b7d6f7 commit 209af94

File tree

1 file changed

+16
-30
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging

1 file changed

+16
-30
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/WriteableBitmap.cs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ ref lockBufferStride
318318
/// on the back buffer and request a render pass.
319319
/// </summary>
320320
public void Unlock()
321+
{
322+
UnlockInner();
323+
}
324+
325+
private void UnlockInner(bool shouldSubscribeToCommittingBatch = true)
321326
{
322327
WritePreamble();
323328

@@ -334,34 +339,23 @@ public void Unlock()
334339
_pBackBufferLock.Dispose();
335340
_pBackBufferLock = null;
336341

337-
if (_hasDirtyRects)
342+
if(shouldSubscribeToCommittingBatch)
338343
{
339-
SubscribeToCommittingBatch();
340-
341-
//
342-
// Notify listeners that we have changed.
343-
//
344-
WritePostscript();
344+
SubscribeToCommittingBatchAndWritePostscript();
345345
}
346346
}
347347
}
348348

349-
private void UnlockWithoutSubscribeToCommittingBatch()
349+
private void SubscribeToCommittingBatchAndWritePostscript()
350350
{
351-
WritePreamble();
352-
353-
if (_lockCount == 0)
351+
if (_hasDirtyRects)
354352
{
355-
throw new InvalidOperationException(SR.Get(SRID.Image_MustBeLocked));
356-
}
357-
Invariant.Assert(_lockCount > 0, "Lock count should never be negative!");
353+
SubscribeToCommittingBatch();
358354

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();
365359
}
366360
}
367361

@@ -814,18 +808,10 @@ out _pDoubleBufferedBitmap
814808
source.CriticalCopyPixels(rcFull, _backBuffer, bufferSize, _backBufferStride.Value);
815809
AddDirtyRect(rcFull);
816810

817-
UnlockWithoutSubscribeToCommittingBatch();
811+
UnlockInner(shouldSubscribeToCommittingBatch: false);
818812
}
819813

820-
if (_hasDirtyRects)
821-
{
822-
SubscribeToCommittingBatch();
823-
824-
//
825-
// Notify listeners that we have changed.
826-
//
827-
WritePostscript();
828-
}
814+
SubscribeToCommittingBatchAndWritePostscript();
829815

830816
EndInit();
831817
}

0 commit comments

Comments
 (0)
0