GBUFFER.CPP 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /***************************************************************************
  15. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Westwood 32 bit Library *
  19. * *
  20. * File Name : GBUFFER.CPP *
  21. * *
  22. * Programmer : Phil W. Gorrow *
  23. * *
  24. * Start Date : May 3, 1994 *
  25. * *
  26. * Last Update : October 9, 1995 [] *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * Functions: *
  30. * VVPC::VirtualViewPort -- Default constructor for a virtual viewport *
  31. * VVPC:~VirtualViewPortClass -- Destructor for a virtual viewport *
  32. * VVPC::Clear -- Clears a graphic page to correct color *
  33. * VBC::VideoBufferClass -- Lowlevel constructor for video buffer class *
  34. * GVPC::Change -- Changes position and size of a Graphic View Port *
  35. * VVPC::Change -- Changes position and size of a Video View Port *
  36. * Set_Logic_Page -- Sets LogicPage to new buffer *
  37. * GBC::DD_Init -- Inits a direct draw surface for a GBC *
  38. * GBC::Init -- Core function responsible for initing a GBC *
  39. * GBC::Lock -- Locks a Direct Draw Surface *
  40. * GBC::Unlock -- Unlocks a direct draw surface *
  41. * GBC::GraphicBufferClass -- Default constructor (requires explicit init)*
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #ifndef GBUFFER_H
  44. #include "gbuffer.h"
  45. #include "misc.h"
  46. #endif
  47. //#pragma inline
  48. int TotalLocks;
  49. BOOL AllowHardwareBlitFills = TRUE;
  50. //int CacheAllowed;
  51. /*=========================================================================*/
  52. /* The following PRIVATE functions are in this file: */
  53. /*=========================================================================*/
  54. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  55. /***************************************************************************
  56. * GVPC::GRAPHICVIEWPORTCLASS -- Constructor for basic view port class *
  57. * m *
  58. * INPUT: GraphicBufferClass * gbuffer - buffer to attach to *
  59. * int x - x offset into buffer *
  60. * int y - y offset into buffer *
  61. * int w - view port width in pixels *
  62. * int h - view port height in pixels *
  63. * *
  64. * OUTPUT: Constructors may not have a return value *
  65. * *
  66. * HISTORY: *
  67. * 05/09/1994 PWG : Created. *
  68. *=========================================================================*/
  69. GraphicViewPortClass::GraphicViewPortClass(GraphicBufferClass *gbuffer, int x, int y, int w, int h) :
  70. LockCount(0),
  71. GraphicBuff(NULL)
  72. {
  73. Attach(gbuffer, x, y, w, h);
  74. }
  75. /***************************************************************************
  76. * GVPC::GRAPHICVIEWPORTCLASS -- Default constructor for view port class *
  77. * *
  78. * INPUT: none *
  79. * *
  80. * OUTPUT: none *
  81. * *
  82. * HISTORY: *
  83. * 05/09/1994 PWG : Created. *
  84. *=========================================================================*/
  85. GraphicViewPortClass::GraphicViewPortClass(void)
  86. {
  87. }
  88. /***************************************************************************
  89. * GVPC::~GRAPHICVIEWPORTCLASS -- Destructor for GraphicViewPortClass *
  90. * *
  91. * INPUT: none *
  92. * *
  93. * OUTPUT: A destructor may not return a value. *
  94. * *
  95. * HISTORY: *
  96. * 05/10/1994 PWG : Created. *
  97. *=========================================================================*/
  98. GraphicViewPortClass::~GraphicViewPortClass(void)
  99. {
  100. Offset = 0;
  101. Width = 0; // Record width of Buffer
  102. Height = 0; // Record height of Buffer
  103. XAdd = 0; // Record XAdd of Buffer
  104. XPos = 0; // Record XPos of Buffer
  105. YPos = 0; // Record YPos of Buffer
  106. Pitch = 0; // Record width of Buffer
  107. IsDirectDraw = FALSE;
  108. LockCount = 0;
  109. GraphicBuff = NULL;
  110. }
  111. /***************************************************************************
  112. * GVPC::ATTACH -- Attaches a viewport to a buffer class *
  113. * *
  114. * INPUT: GraphicBufferClass *g_buff - pointer to gbuff to attach to *
  115. * int x - x position to attach to *
  116. * int y - y position to attach to *
  117. * int w - width of the view port *
  118. * int h - height of the view port *
  119. * *
  120. * OUTPUT: none *
  121. * *
  122. * HISTORY: *
  123. * 05/10/1994 PWG : Created. *
  124. *=========================================================================*/
  125. void GraphicViewPortClass::Attach(GraphicBufferClass *gbuffer, int x, int y, int w, int h)
  126. {
  127. /*======================================================================*/
  128. /* Can not attach a Graphic View Port if it is actually the physical */
  129. /* representation of a Graphic Buffer. */
  130. /*======================================================================*/
  131. if (this == Get_Graphic_Buffer()) {
  132. return;
  133. }
  134. /*======================================================================*/
  135. /* Verify that the x and y coordinates are valid and placed within the */
  136. /* physical buffer. */
  137. /*======================================================================*/
  138. if (x < 0) // you cannot place view port off
  139. x = 0; // the left edge of physical buf
  140. if (x >= gbuffer->Get_Width()) // you cannot place left edge off
  141. x = gbuffer->Get_Width() - 1; // the right edge of physical buf
  142. if (y < 0) // you cannot place view port off
  143. y = 0; // the top edge of physical buf
  144. if (y >= gbuffer->Get_Height()) // you cannot place view port off
  145. y = gbuffer->Get_Height() - 1; // bottom edge of physical buf
  146. /*======================================================================*/
  147. /* Adjust the width and height of necessary */
  148. /*======================================================================*/
  149. if (x + w > gbuffer->Get_Width()) // if the x plus width is larger
  150. w = gbuffer->Get_Width() - x; // than physical, fix width
  151. if (y + h > gbuffer->Get_Height()) // if the y plus height is larger
  152. h = gbuffer->Get_Height() - y; // than physical, fix height
  153. /*======================================================================*/
  154. /* Get a pointer to the top left edge of the buffer. */
  155. /*======================================================================*/
  156. Offset = gbuffer->Get_Offset() + ((gbuffer->Get_Width()+gbuffer->Get_Pitch()) * y) + x;
  157. /*======================================================================*/
  158. /* Copy over all of the variables that we need to store. */
  159. /*======================================================================*/
  160. XPos = x;
  161. YPos = y;
  162. XAdd = gbuffer->Get_Width() - w;
  163. Width = w;
  164. Height = h;
  165. Pitch = gbuffer->Get_Pitch();
  166. GraphicBuff = gbuffer;
  167. IsDirectDraw= gbuffer->IsDirectDraw;
  168. }
  169. /***************************************************************************
  170. * GVPC::CHANGE -- Changes position and size of a Graphic View Port *
  171. * *
  172. * INPUT: int the new x pixel position of the graphic view port *
  173. * int the new y pixel position of the graphic view port *
  174. * int the new width of the viewport in pixels *
  175. * int the new height of the viewport in pixels *
  176. * *
  177. * OUTPUT: BOOL whether the Graphic View Port could be sucessfully *
  178. * resized. *
  179. * *
  180. * WARNINGS: You may not resize a Graphic View Port which is derived *
  181. * from a Graphic View Port Buffer, *
  182. * *
  183. * HISTORY: *
  184. * 09/14/1994 SKB : Created. *
  185. *=========================================================================*/
  186. BOOL GraphicViewPortClass::Change(int x, int y, int w, int h)
  187. {
  188. /*======================================================================*/
  189. /* Can not change a Graphic View Port if it is actually the physical */
  190. /* representation of a Graphic Buffer. */
  191. /*======================================================================*/
  192. if (this == Get_Graphic_Buffer()) {
  193. return(FALSE);
  194. }
  195. /*======================================================================*/
  196. /* Since there is no allocated information, just re-attach it to the */
  197. /* existing graphic buffer as if we were creating the */
  198. /* GraphicViewPort. */
  199. /*======================================================================*/
  200. Attach(Get_Graphic_Buffer(), x, y, w, h);
  201. return(TRUE);
  202. }
  203. /***************************************************************************
  204. * GBC::DD_INIT -- Inits a direct draw surface for a GBC *
  205. * *
  206. * INPUT: none *
  207. * *
  208. * OUTPUT: none *
  209. * *
  210. * HISTORY: *
  211. * 10/09/1995 : Created. *
  212. *=========================================================================*/
  213. void GraphicBufferClass::DD_Init(GBC_Enum flags)
  214. {
  215. //
  216. // Create the direct draw surface description
  217. //
  218. memset (&VideoSurfaceDescription , 0 , sizeof ( VideoSurfaceDescription ));
  219. VideoSurfaceDescription.dwSize = sizeof( VideoSurfaceDescription );
  220. VideoSurfaceDescription.dwFlags = DDSD_CAPS;
  221. VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  222. if (!(flags & GBC_VISIBLE)) {
  223. VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  224. VideoSurfaceDescription.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
  225. VideoSurfaceDescription.dwHeight = Height;
  226. VideoSurfaceDescription.dwWidth = Width;
  227. }
  228. //
  229. // Need to set the DDSCAPS_MODEX flag if we want a 320 wide mode
  230. //
  231. if ( Width == 320 ) {
  232. VideoSurfaceDescription.ddsCaps.dwCaps |= DDSCAPS_MODEX;
  233. }
  234. //
  235. // Call CreateSurface
  236. //
  237. DirectDrawObject->CreateSurface( &VideoSurfaceDescription , &VideoSurfacePtr , NULL);
  238. AllSurfaces.Add_DD_Surface (VideoSurfacePtr);
  239. if ( GBC_VISIBLE & flags ){
  240. PaletteSurface=VideoSurfacePtr;
  241. }
  242. Allocated = FALSE; // even if system alloced, dont flag it cuz
  243. // we dont want it freed.
  244. IsDirectDraw = TRUE; // flag it as a video surface
  245. Offset = NOT_LOCKED; // flag it as unavailable for reading or writing
  246. LockCount = 0; // surface is not locked
  247. }
  248. void GraphicBufferClass::Attach_DD_Surface (GraphicBufferClass * attach_buffer)
  249. {
  250. VideoSurfacePtr->AddAttachedSurface (attach_buffer->Get_DD_Surface());
  251. }
  252. /***************************************************************************
  253. * GBC::INIT -- Core function responsible for initing a GBC *
  254. * *
  255. * INPUT: int - the width in pixels of the GraphicBufferClass *
  256. * int - the heigh in pixels of the GraphicBufferClass *
  257. * void * - pointer to user supplied buffer (system will *
  258. * allocate space if buffer is NULL) *
  259. * long - size of the user provided buffer *
  260. * GBC_Enum - flags if this is defined as a direct draw *
  261. * surface *
  262. * *
  263. * OUTPUT: none *
  264. * *
  265. * HISTORY: *
  266. * 10/09/1995 : Created. *
  267. *=========================================================================*/
  268. void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum flags)
  269. {
  270. Size = size; // find size of physical buffer
  271. Width = w; // Record width of Buffer
  272. Height = h; // Record height of Buffer
  273. //
  274. // If the surface we are creating is a direct draw object then
  275. // we need to do a direct draw init. Otherwise we will do
  276. // a normal alloc.
  277. //
  278. if (flags & (GBC_VIDEOMEM | GBC_VISIBLE)) {
  279. DD_Init(flags);
  280. } else {
  281. if (buffer) { // if buffer is specified
  282. Buffer = (BYTE *)buffer; // point to it and mark
  283. Allocated = FALSE; // it as user allocated
  284. } else {
  285. if (!Size) Size = w*h;
  286. Buffer = new BYTE[Size]; // otherwise allocate it and
  287. Allocated = TRUE; // mark it system alloced
  288. }
  289. Offset = (long)Buffer; // Get offset to the buffer
  290. IsDirectDraw = FALSE;
  291. }
  292. Pitch = 0; // Record width of Buffer
  293. XAdd = 0; // Record XAdd of Buffer
  294. XPos = 0; // Record XPos of Buffer
  295. YPos = 0; // Record YPos of Buffer
  296. GraphicBuff = this; // Get a pointer to our self
  297. }
  298. /***********************************************************************************************
  299. * GBC::Un_Init -- releases the video surface belonging to this gbuffer *
  300. * *
  301. * *
  302. * *
  303. * INPUT: Nothing *
  304. * *
  305. * OUTPUT: Nothing *
  306. * *
  307. * WARNINGS: None *
  308. * *
  309. * HISTORY: *
  310. * 6/6/96 12:44PM ST : Created *
  311. *=============================================================================================*/
  312. void GraphicBufferClass::Un_Init (void)
  313. {
  314. if ( IsDirectDraw ){
  315. if ( VideoSurfacePtr ){
  316. while ( LockCount ){
  317. if (VideoSurfacePtr->Unlock ( NULL ) == DDERR_SURFACELOST){
  318. if (Gbuffer_Focus_Loss_Function){
  319. Gbuffer_Focus_Loss_Function();
  320. }
  321. AllSurfaces.Restore_Surfaces();
  322. }
  323. }
  324. AllSurfaces.Remove_DD_Surface (VideoSurfacePtr);
  325. VideoSurfacePtr->Release();
  326. VideoSurfacePtr = NULL;
  327. }
  328. }
  329. }
  330. /***************************************************************************
  331. * GBC::GRAPHICBUFFERCLASS -- Default constructor (requires explicit init) *
  332. * *
  333. * INPUT: none *
  334. * *
  335. * OUTPUT: none *
  336. * *
  337. * HISTORY: *
  338. * 10/09/1995 : Created. *
  339. *=========================================================================*/
  340. GraphicBufferClass::GraphicBufferClass(void)
  341. {
  342. GraphicBuff = this; // Get a pointer to our self
  343. VideoSurfacePtr = NULL;
  344. memset(&VideoSurfaceDescription, 0, sizeof(DDSURFACEDESC));
  345. }
  346. /***************************************************************************
  347. * GBC::GRAPHICBUFFERCLASS -- Constructor for fixed size buffers *
  348. * *
  349. * INPUT: long size - size of the buffer to create *
  350. * int w - width of buffer in pixels (default = 320) *
  351. * int h - height of buffer in pixels (default = 200) *
  352. * void *buffer - a pointer to the buffer if any (optional) *
  353. * *
  354. * OUTPUT: *
  355. * *
  356. * WARNINGS: *
  357. * *
  358. * HISTORY: *
  359. * 05/13/1994 PWG : Created. *
  360. *=========================================================================*/
  361. GraphicBufferClass::GraphicBufferClass(int w, int h, void *buffer, long size)
  362. {
  363. Init(w, h, buffer, size, GBC_NONE);
  364. }
  365. /*=========================================================================*
  366. * GBC::GRAPHICBUFFERCLASS -- inline constructor for GraphicBufferClass *
  367. * *
  368. * INPUT: int w - width of buffer in pixels (default = 320) *
  369. * int h - height of buffer in pixels (default = 200) *
  370. * void *buffer - a pointer to the buffer if any (optional) *
  371. * *
  372. * OUTPUT: none *
  373. * *
  374. * HISTORY: *
  375. * 05/03/1994 PWG : Created. *
  376. *=========================================================================*/
  377. GraphicBufferClass::GraphicBufferClass(int w, int h, void *buffer)
  378. {
  379. Init(w, h, buffer, w * h, GBC_NONE);
  380. }
  381. /*====================================================================================*
  382. * GBC::GRAPHICBUFFERCLASS -- contructor for GraphicsBufferClass with special flags *
  383. * *
  384. * INPUT: int w - width of buffer in pixels (default = 320) *
  385. * int h - height of buffer in pixels (default = 200) *
  386. * void *buffer - unused *
  387. * unsigned flags - flags for creation of special buffer types *
  388. * GBC_VISIBLE - buffer is a visible screen surface *
  389. * GBC_VIDEOMEM - buffer resides in video memory *
  390. * *
  391. * OUTPUT: none *
  392. * *
  393. * HISTORY: *
  394. * 09-21-95 04:19pm ST : Created *
  395. *====================================================================================*/
  396. GraphicBufferClass::GraphicBufferClass(int w, int h, GBC_Enum flags)
  397. {
  398. Init(w, h, NULL, w * h, flags);
  399. }
  400. /*=========================================================================*
  401. * GBC::~GRAPHICBUFFERCLASS -- Destructor for the graphic buffer class *
  402. * *
  403. * INPUT: none *
  404. * *
  405. * OUTPUT: none *
  406. * *
  407. * HISTORY: *
  408. * 05/03/1994 PWG : Created. *
  409. *=========================================================================*/
  410. GraphicBufferClass::~GraphicBufferClass()
  411. {
  412. //
  413. // Release the direct draw surface if it exists
  414. //
  415. Un_Init();
  416. }
  417. /***************************************************************************
  418. * SET_LOGIC_PAGE -- Sets LogicPage to new buffer *
  419. * *
  420. * INPUT: GraphicBufferClass * the buffer we are going to set *
  421. * *
  422. * OUTPUT: GraphicBufferClass * the previous buffer type *
  423. * *
  424. * WARNINGS: *
  425. * *
  426. * HISTORY: *
  427. * 02/23/1995 PWG : Created. *
  428. *=========================================================================*/
  429. GraphicViewPortClass *Set_Logic_Page(GraphicViewPortClass *ptr)
  430. {
  431. GraphicViewPortClass *old = LogicPage;
  432. LogicPage = ptr;
  433. return(old);
  434. }
  435. /***************************************************************************
  436. * SET_LOGIC_PAGE -- Sets LogicPage to new buffer *
  437. * *
  438. * INPUT: GraphicBufferClass & the buffer we are going to set *
  439. * *
  440. * OUTPUT: GraphicBufferClass * the previous buffer type *
  441. * *
  442. * WARNINGS: *
  443. * *
  444. * HISTORY: *
  445. * 02/23/1995 PWG : Created. *
  446. *=========================================================================*/
  447. GraphicViewPortClass *Set_Logic_Page(GraphicViewPortClass &ptr)
  448. {
  449. GraphicViewPortClass *old = LogicPage;
  450. LogicPage = &ptr;
  451. return(old);
  452. }
  453. /***************************************************************************
  454. * GBC::LOCK -- Locks a Direct Draw Surface *
  455. * *
  456. * INPUT: none *
  457. * *
  458. * OUTPUT: none *
  459. * *
  460. * HISTORY: *
  461. * 10/09/1995 : Created. *
  462. * 10/09/1995 : Code stolen from Steve Tall *
  463. *=========================================================================*/
  464. extern void Colour_Debug (int call_number);
  465. extern bool GameInFocus;
  466. extern void Block_Mouse(GraphicBufferClass *buffer);
  467. extern void Unblock_Mouse(GraphicBufferClass *buffer);
  468. BOOL GraphicBufferClass::Lock(void)
  469. {
  470. HRESULT result;
  471. int restore_attempts=0;
  472. //
  473. // If its not a direct draw surface then the lock is always sucessful.
  474. //
  475. if (!IsDirectDraw) return(TRUE);
  476. /*
  477. ** If the video surface pointer is null then return
  478. */
  479. if (!VideoSurfacePtr) return (FALSE);
  480. /*
  481. ** If we dont have focus then return failure
  482. */
  483. if (!GameInFocus) return (FALSE);
  484. Block_Mouse(this);
  485. //
  486. // If surface is already locked then inc the lock count and return true
  487. //
  488. if (LockCount){
  489. LockCount++;
  490. Unblock_Mouse(this);
  491. return(TRUE);
  492. }
  493. //
  494. // If it isn't locked at all then we will have to request that Direct
  495. // Draw actually lock the surface.
  496. //
  497. if (VideoSurfacePtr){
  498. while (!LockCount && restore_attempts<2) {
  499. result = VideoSurfacePtr->Lock ( NULL
  500. , &(VideoSurfaceDescription)
  501. , DDLOCK_WAIT
  502. , NULL);
  503. switch (result){
  504. case DD_OK :
  505. Offset = (unsigned long)VideoSurfaceDescription.lpSurface;
  506. Pitch = VideoSurfaceDescription.lPitch;
  507. Pitch -= Width;
  508. LockCount++; // increment count so we can track if
  509. TotalLocks++; // Total number of times we have locked (for debugging)
  510. //Colour_Debug (1);
  511. Unblock_Mouse(this);
  512. return (TRUE); // we locked it multiple times.
  513. case DDERR_SURFACELOST :
  514. if (Gbuffer_Focus_Loss_Function){
  515. Gbuffer_Focus_Loss_Function();
  516. }
  517. AllSurfaces.Restore_Surfaces();
  518. restore_attempts++;
  519. break;
  520. default :
  521. Unblock_Mouse(this);
  522. return (FALSE);
  523. }
  524. }
  525. }
  526. //Colour_Debug(1);
  527. Unblock_Mouse(this);
  528. return (FALSE); //Return false because we couldnt lock or restore the surface
  529. }
  530. /***************************************************************************
  531. * GBC::UNLOCK -- Unlocks a direct draw surface *
  532. * *
  533. * INPUT: none *
  534. * *
  535. * OUTPUT: none *
  536. * *
  537. * HISTORY: *
  538. * 10/09/1995 : Created. *
  539. * 10/09/1995 : Code stolen from Steve Tall *
  540. *=========================================================================*/
  541. BOOL GraphicBufferClass::Unlock(void)
  542. {
  543. //
  544. // If there is no lock count or this is not a direct draw surface
  545. // then just return true as there is no harm done.
  546. //
  547. if (!(LockCount && IsDirectDraw)) {
  548. return(TRUE);
  549. }
  550. //
  551. // If lock count is directly equal to one then we actually need to
  552. // unlock so just give it a shot.
  553. //
  554. if (LockCount == 1 && VideoSurfacePtr) {
  555. Block_Mouse(this);
  556. if ( VideoSurfacePtr->Unlock ( NULL ) != DD_OK ){
  557. Unblock_Mouse(this);
  558. return(FALSE);
  559. } else {
  560. Offset=NOT_LOCKED;
  561. LockCount--;
  562. Unblock_Mouse(this);
  563. return(TRUE);
  564. }
  565. }
  566. //Colour_Debug (0);
  567. LockCount--;
  568. return(TRUE);
  569. }
  570. /***********************************************************************************************
  571. * GVPC::DD_Linear_Blit_To_Linear -- blit using the hardware blitter *
  572. * *
  573. * *
  574. * *
  575. * INPUT: destination vvpc *
  576. * x coord to blit from *
  577. * y coord to blit from *
  578. * x coord to blit to *
  579. * y coord to blit to *
  580. * width to blit *
  581. * height to blit *
  582. * *
  583. * OUTPUT: DD_OK if successful *
  584. * *
  585. * WARNINGS: None *
  586. * *
  587. * HISTORY: *
  588. * 09-22-95 11:05am ST : Created *
  589. *=============================================================================================*/
  590. HRESULT GraphicViewPortClass::DD_Linear_Blit_To_Linear (
  591. GraphicViewPortClass &dest
  592. , int source_x
  593. , int source_y
  594. , int dest_x
  595. , int dest_y
  596. , int width
  597. , int height
  598. , BOOL mask )
  599. {
  600. RECT source_rectangle;
  601. RECT dest_rectangle;
  602. int key_source=0;
  603. if ( mask ){
  604. key_source=DDBLT_KEYSRC;
  605. }
  606. source_rectangle.left = source_x;
  607. source_rectangle.top = source_y;
  608. source_rectangle.right = source_x+width;
  609. source_rectangle.bottom = source_y+height;
  610. dest_rectangle.left = dest_x;
  611. dest_rectangle.top = dest_y;
  612. dest_rectangle.right = dest_x+width;
  613. dest_rectangle.bottom = dest_y+height;
  614. return ( dest.GraphicBuff->Get_DD_Surface()->Blt ( &dest_rectangle,
  615. GraphicBuff->Get_DD_Surface(),
  616. &source_rectangle,
  617. key_source | DDBLT_WAIT | DDBLT_ASYNC,
  618. NULL ) );
  619. }