Changeset 405


Ignore:
Timestamp:
Aug 3, 1999, 10:16:20 PM (26 years ago)
Author:
hugh
Message:

Fixed bug in locked region handling

Location:
trunk/src/ddraw
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/ddraw/OS2SURFACE.CPP

    r352 r405  
    277277  Vtbl.SetOverlayPosition    = SurfSetOverlayPosition;
    278278  Vtbl.SetPalette            = SurfSetPalette;
    279   Vtbl.Unlock                = SurfUnlock;
     279  Vtbl.Unlock                = SurfUnlock4;
    280280  Vtbl.UpdateOverlay         = SurfUpdateOverlay4;
    281281  Vtbl.UpdateOverlayDisplay  = SurfUpdateOverlayDisplay;
     
    351351  }
    352352
    353   /*
    354   try
    355   {
    356     SurfaceCursorMipMap = SurfaceSequenceMipMap.newCursor();
    357   }
    358   catch(IOutOfMemory)
    359   {
    360     #ifdef DEBUG
    361       WriteLog("Internal : Error creating Cursor\n");
    362     #endif
    363     lastError = DDERR_OUTOFMEMORY ;
    364     return;
    365   }
    366 
    367   try
    368   {
    369     SurfaceCursorAttached = SurfaceSequenceAttached.newCursor();
    370   }
    371   catch(IOutOfMemory)
    372   {
    373     #ifdef DEBUG
    374       WriteLog("Internal : Error creating Cursor\n");
    375     #endif
    376     lastError = DDERR_OUTOFMEMORY ;
    377     return;
    378   }
    379   */
    380353  if( lpDDSurfaceDesc->dwFlags & DDSD_CAPS )
    381354  {
     
    570543        } //endif Backbuffer
    571544      } // endif DDSCAPS_COMPLEX
     545
     546      width  = DDSurfaceDesc.dwWidth;
     547      height = DDSurfaceDesc.dwHeight;
     548
    572549      lastError = DD_OK;
    573550      return;
     
    751728      } // End of alloc surfaces
    752729
     730      width  = DDSurfaceDesc.dwWidth;
     731      height = DDSurfaceDesc.dwHeight;
     732
    753733      if( dwCaps & DDSCAPS_COMPLEX)
    754734      {
     
    819799            if(MipMapSurface->GetLastError() != DD_OK)
    820800            {
    821               lastError = AttachedSurface->GetLastError();
     801              lastError = MipMapSurface->GetLastError();
    822802              #ifdef DEBUG
    823803                WriteLog("Attached surface creation returned error %d\n",lastError);
     
    35993579//******************************************************************************
    36003580//******************************************************************************
    3601 HRESULT __stdcall SurfLock(THIS This, LPRECT lpRect, LPDDSURFACEDESC lpSurfaceDesc,
    3602          DWORD dwFlags, HANDLE hEvent)
     3581HRESULT __stdcall SurfLock( THIS This,
     3582                            LPRECT lpRect,
     3583                            LPDDSURFACEDESC lpSurfaceDesc,
     3584                            DWORD dwFlags,
     3585                            HANDLE hEvent)
    36033586{
    36043587  DDSURFACEDESC2 SurfaceDesc4;
     
    36063589
    36073590  #ifdef DEBUG
    3608     WriteLog("SurfLock %d %d %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent);
     3591    WriteLog("SurfLock %d %08X %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent);
    36093592  #endif
    36103593
     
    36273610//******************************************************************************
    36283611//******************************************************************************
    3629 HRESULT __stdcall SurfLock4(THIS This, LPRECT lpRect, LPDDSURFACEDESC2 lpSurfaceDesc,
    3630          DWORD dwFlags, HANDLE hEvent)
     3612HRESULT __stdcall SurfLock4( THIS This,
     3613                             LPRECT lpRect,
     3614                             LPDDSURFACEDESC2 lpSurfaceDesc,
     3615                             DWORD dwFlags,
     3616                             HANDLE hEvent)
    36313617{
    36323618
     
    36413627
    36423628  #ifdef DEBUG
    3643     WriteLog("SurfLock4 %d %d %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent);
     3629    WriteLog("SurfLock4 %d %08X %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent);
    36443630  #endif
    36453631
     
    36553641
    36563642  // ToDo : the lockchecking should be done in a critcal seq.
     3643  WriteLog( "Lock Rectangle (%d/%d) x (%d/%d)\n",
     3644            pIRectNew->Top(),
     3645            pIRectNew->Left(),
     3646            pIRectNew->Bottom(),
     3647            pIRectNew->Right() );
    36573648
    36583649  if(me->fLocked)
     
    36613652    {
    36623653      // If anything is locked we can't locke the complete surface
     3654      WriteLog("Surface has locked Rectangles, and we want to complete lock it");
    36633655      Found = TRUE;
    36643656    }
     
    36683660      // be locked so check for this
    36693661
     3662      WriteLog("Surface has locked Rectangles, check if the overlap");
     3663
    36703664      i=0;
    36713665      Found = FALSE;
     
    36743668      {
    36753669        pIRectCurrent = (DDRectangle*) DPA_FastGetPtr(me->DPA_LockedRects,i);
     3670        WriteLog( "Test with Rectangle (%d/%d) x (%d/%d)\n",
     3671                  pIRectCurrent->Top(),
     3672                  pIRectCurrent->Left(),
     3673                  pIRectCurrent->Bottom(),
     3674                  pIRectCurrent->Right() );
    36763675        Found = pIRectCurrent->intersects(*pIRectNew);
    36773676        i++;
     
    36983697                                (lpRect->left * (lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount>>3)));
    36993698    #ifdef DEBUG
    3700       WriteLog("SurfLock4 %d (x,y) = (%d,%d)\n", lpSurfaceDesc->lpSurface, lpRect->top, lpRect->left);
     3699      WriteLog("SurfLock4 %08X (x,y) = (%d,%d)\n", lpSurfaceDesc->lpSurface, lpRect->top, lpRect->left);
    37013700    #endif
    37023701  }
     
    37043703  {
    37053704    #ifdef DEBUG
    3706       WriteLog("SurfLock4 %d \n", lpSurfaceDesc->lpSurface);
     3705      WriteLog("SurfLock4 %08X \n", lpSurfaceDesc->lpSurface);
    37073706    #endif
    37083707  }
    37093708  // Add the rectangle to the list of locked rectangles
     3709
     3710  pIRectNew->SetMemPtr(lpSurfaceDesc->lpSurface);
    37103711
    37113712  DPA_InsertPtr( me->DPA_LockedRects,
     
    39553956//******************************************************************************
    39563957//******************************************************************************
    3957 HRESULT __stdcall SurfUnlock(THIS This, LPRECT lpSurfaceRect)
    3958 {
    3959 
     3958HRESULT __stdcall SurfUnlock(THIS This, LPVOID lpSurfaceData)
     3959{
    39603960
    39613961  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
    39623962  int i;
    3963   DDRectangle *pIRectUnlock;
     3963  DDRectangle *pIRectUnlock, *pIRectEnum;
    39643964  BOOL Found = FALSE;
    3965 
    3966   #ifdef DEBUG
    3967     WriteLog("SurfUnlock\n");
     3965  OS2RECTL CCRect;
     3966
     3967  #ifdef DEBUG
     3968    WriteLog("SurfUnlock at %08X\n",lpSurfaceData);
     3969  #endif
     3970
     3971  if(me->fLocked == FALSE)
     3972  {
     3973    #ifdef DEBUG
     3974      WriteLog("Surface not locked!\n");
     3975    #endif
     3976    return(DDERR_NOTLOCKED);
     3977  }
     3978
     3979  #ifdef DEBUG
     3980    WriteLog("Start Emuneration of Locked Rects\n");
     3981  #endif
     3982
     3983  i=0;
     3984  if(NULL!=lpSurfaceData)
     3985  {
     3986    WriteLog("Buffer Pointer Compare");
     3987
     3988    // We got a pinter to the surface memory so we must search for
     3989    // this pointer in the locked rects DPA to unlock the right rect.
     3990
     3991    while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
     3992    {
     3993      pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
     3994      WriteLog( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n",
     3995                i,
     3996                pIRectEnum->Top(),
     3997                pIRectEnum->Left(),
     3998                pIRectEnum->Bottom(),
     3999                pIRectEnum->Right(),
     4000                pIRectEnum->GetMemPtr() );
     4001
     4002      Found = ( pIRectEnum->GetMemPtr() == lpSurfaceData);
     4003      if(!Found)
     4004      {
     4005        #ifdef DEBUG
     4006          WriteLog("Not Found, try Next rect\n");
     4007        #endif
     4008        i++;
     4009      }
     4010      #ifdef DEBUG
     4011      else
     4012      {
     4013        WriteLog("Found Rect\n");
     4014      }
     4015      #endif
     4016    }
     4017  }
     4018  else
     4019  {
     4020    // If a NULL pointer was passed in the SW tries to unlock the
     4021    // complete surface so we must compare the rects.
     4022    WriteLog("Rectangle compare");
     4023
     4024    pIRectUnlock = new DDRectangle( 0, 0, me->height, me->width);
     4025
     4026    while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
     4027    {
     4028      pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
     4029      WriteLog( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n",
     4030                i,
     4031                pIRectEnum->Top(),
     4032                pIRectEnum->Left(),
     4033                pIRectEnum->Bottom(),
     4034                pIRectEnum->Right(),
     4035                pIRectEnum->GetMemPtr() );
     4036
     4037      Found = (*pIRectEnum == *pIRectUnlock);
     4038      if(!Found)
     4039      {
     4040        #ifdef DEBUG
     4041          WriteLog("Not Found, try Next rect\n");
     4042        #endif
     4043        i++;
     4044      }
     4045      #ifdef DEBUG
     4046      else
     4047      {
     4048        WriteLog("Found Rect\n");
     4049      }
     4050      #endif
     4051    }
     4052    delete pIRectUnlock;
     4053  }
     4054
     4055  if(!Found)
     4056  {
     4057    #ifdef DEBUG
     4058      WriteLog("Rectangle not locked, wrong Rect!\n\n");
     4059    #endif
     4060    return(DDERR_INVALIDRECT);
     4061  }
     4062
     4063  #ifdef DEBUG
     4064    WriteLog("Remove Rect %d from Seq.\n",i);
     4065  #endif
     4066
     4067  DPA_DeletePtr(me->DPA_LockedRects,i);
     4068
     4069  #ifdef DEBUG
     4070    WriteLog("Test if locked Rects main\n");
     4071  #endif
     4072
     4073  if(0==DPA_GetPtrCount(me->DPA_LockedRects))  // Do we have unlocked last rectangle
     4074  {
     4075    #ifdef DEBUG
     4076      WriteLog("No Locked Rects left for surface\n");
     4077    #endif
     4078    me->fLocked = FALSE;
     4079  }
     4080  #ifdef DEBUG
     4081  else
     4082    WriteLog( "%d Rects in Seq\n",
     4083              DPA_GetPtrCount(me->DPA_LockedRects));
     4084  #endif
     4085
     4086  if(me->pFrameBuffer != me->pDiveBuffer)
     4087  {
     4088    #ifdef DEBUG
     4089      WriteLog( "ColorConversion Needed %08X != %08X\n",
     4090                me->pFrameBuffer,
     4091                me->pDiveBuffer);
     4092    #endif
     4093    if(NULL!=lpSurfaceData)
     4094    {
     4095      CCRect.yTop    = pIRectEnum->Top();
     4096      CCRect.xLeft   = pIRectEnum->Left();
     4097      CCRect.xRight  = pIRectEnum->Right();
     4098      CCRect.yBottom = pIRectEnum->Bottom();
     4099
     4100      me->ColorConversion( (LPRECT)&CCRect);
     4101    }
     4102    else
     4103    {
     4104      me->ColorConversion(NULL);
     4105    }
     4106  }
     4107  #ifdef DEBUG
     4108  else
     4109    WriteLog( "No ColorConversion Needed");
     4110  #endif
     4111
     4112  // delete tne DDRectobject of the found rectangle
     4113  delete pIRectEnum;
     4114
     4115  me->lpVtbl->ChangeUniquenessValue(me);
     4116
     4117  WriteLog("Unlock OK\n\n");
     4118
     4119  return(DD_OK);
     4120}
     4121//******************************************************************************
     4122//******************************************************************************
     4123HRESULT __stdcall SurfUnlock4(THIS This, LPRECT lpSurfaceRect)
     4124{
     4125  // MS changed the parameter from LPVOID to LPRECT with DX6
     4126  // as DX-6 allways returns a DDSurface4 on create surface this
     4127  // is a problem i not NULL is passed in.
     4128  // Solution We first test with the pointer ns assuming a rectangle
     4129  // if we don't find a rect Which is very likely if we get a pointer
     4130  // SurfaceMemory we call SurfUnlock and test for the pointer there.
     4131
     4132
     4133  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
     4134  int i;
     4135  DDRectangle *pIRectUnlock, *pIRectEnum;
     4136  BOOL Found = FALSE;
     4137
     4138  #ifdef DEBUG
     4139    WriteLog("SurfUnlock4\n");
    39684140  #endif
    39694141
     
    39904162  }
    39914163
    3992   #ifdef DEBUG
    3993     WriteLog("StartEmuneration of Locked Rects\n");
     4164  WriteLog( "Try to Unlock Rectangle (%d/%d) x (%d/%d)\n",
     4165            pIRectUnlock->Top(),
     4166            pIRectUnlock->Left(),
     4167            pIRectUnlock->Bottom(),
     4168            pIRectUnlock->Right() );
     4169
     4170  #ifdef DEBUG
     4171    WriteLog("Start Emuneration of Locked Rects\n");
    39944172  #endif
    39954173
     
    39974175  while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
    39984176  {
    3999     Found = (*((DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i)) == *pIRectUnlock);
     4177    pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
     4178    WriteLog( "Test with Rectangle (%d/%d) x (%d/%d)\n",
     4179              pIRectEnum->Top(),
     4180              pIRectEnum->Left(),
     4181              pIRectEnum->Bottom(),
     4182              pIRectEnum->Right() );
     4183
     4184    Found = (*pIRectEnum == *pIRectUnlock);
    40004185    if(!Found)
    40014186    {
     
    40154200  if(!Found)
    40164201  {
    4017     #ifdef DEBUG
    4018       WriteLog("Rectangle not locked, wrong Rect!\n\n");
    4019     #endif
    4020     return(DDERR_INVALIDRECT);
     4202
     4203    if(NULL==lpSurfaceRect)
     4204    {
     4205      #ifdef DEBUG
     4206        WriteLog("Rectangle not locked, wrong Rect!\n\n");
     4207      #endif
     4208      return(DDERR_INVALIDRECT);
     4209    }
     4210    else
     4211      return SurfUnlock(This, (LPVOID)lpSurfaceRect);
    40214212  }
    40224213
  • TabularUnified trunk/src/ddraw/OS2SURFACE.H

    r352 r405  
    145145    friend    HRESULT __stdcall SurfSetOverlayPosition(THIS, LONG, LONG );
    146146    friend    HRESULT __stdcall SurfSetPalette(THIS, LPDIRECTDRAWPALETTE);
    147     friend    HRESULT __stdcall SurfUnlock(THIS, LPRECT);
     147    friend    HRESULT __stdcall SurfUnlock(THIS, LPVOID);
     148    friend    HRESULT __stdcall SurfUnlock4(THIS, LPRECT);
    148149    friend    HRESULT __stdcall SurfUpdateOverlay(THIS, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX);
    149150    friend    HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX);
     
    211212HRESULT __stdcall SurfSetOverlayPosition(THIS, LONG, LONG );
    212213HRESULT __stdcall SurfSetPalette(THIS, LPDIRECTDRAWPALETTE);
    213 HRESULT __stdcall SurfUnlock(THIS, LPRECT);
     214HRESULT __stdcall SurfUnlock(THIS, LPVOID);
     215HRESULT __stdcall SurfUnlock4(THIS, LPRECT);
    214216HRESULT __stdcall SurfUpdateOverlay(THIS, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX);
    215217HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX);
  • TabularUnified trunk/src/ddraw/rectangle.cpp

    r352 r405  
    1010  lBottom = y2;
    1111  lRight  = x2;
     12  pMemPtr = 0;
    1213}
    1314
     
    3940}
    4041
     42DDRectangle::Coord DDRectangle::Top() const
     43{
     44  return lTop;
     45}
     46
     47DDRectangle::Coord DDRectangle::Left() const
     48{
     49  return lLeft;
     50}
     51
     52DDRectangle::Coord DDRectangle::Bottom() const
     53{
     54  return lBottom;
     55}
     56
     57DDRectangle::Coord DDRectangle::Right() const
     58{
     59  return lRight;
     60}
     61
     62void DDRectangle::SetMemPtr(void* NewMemPtr)
     63{
     64  pMemPtr = NewMemPtr;
     65}
     66
     67void* DDRectangle::GetMemPtr()
     68{
     69  return pMemPtr;
     70}
  • TabularUnified trunk/src/ddraw/rectangle.h

    r352 r405  
    3232Coord
    3333  width() const,
    34   height() const;
     34  height() const,
     35  Top() const,
     36  Left() const,
     37  Bottom() const,
     38  Right() const;
     39
     40  void* GetMemPtr();
     41  void SetMemPtr(void* NewMemPtr);
    3542
    3643private:
     44  void* pMemPtr; // Pointer to surface memory for this rectangle
    3745  long lTop,lLeft;
    3846  long lBottom,lRight;
Note: See TracChangeset for help on using the changeset viewer.