comparison src/video/SDL_surface.c @ 296:fab1ddc4d7bf

Removed the API changes to preserve SDL 1.2 stability
author Sam Lantinga <slouken@libsdl.org>
date Wed, 06 Mar 2002 11:05:47 +0000
parents eadc0746dfaf
children f6ffac90895c
comparison
equal deleted inserted replaced
295:54ad1d2f1325 296:fab1ddc4d7bf
628 * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) 628 * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
629 * video->LockHWSurface(video, surface); 629 * video->LockHWSurface(video, surface);
630 */ 630 */
631 int SDL_LockSurface (SDL_Surface *surface) 631 int SDL_LockSurface (SDL_Surface *surface)
632 { 632 {
633 if ( surface->locked < 0 ) {
634 SDL_SetError("Surface has a rectangle lock");
635 return(-1);
636 }
637 if ( ! surface->locked ) { 633 if ( ! surface->locked ) {
638 /* Perform the lock */ 634 /* Perform the lock */
639 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 635 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
640 SDL_VideoDevice *video = current_video; 636 SDL_VideoDevice *video = current_video;
641 SDL_VideoDevice *this = current_video; 637 SDL_VideoDevice *this = current_video;
655 ++surface->locked; 651 ++surface->locked;
656 652
657 /* Ready to go.. */ 653 /* Ready to go.. */
658 return(0); 654 return(0);
659 } 655 }
660 int SDL_LockRect (SDL_Surface *surface, SDL_Rect *rect, void **pixels, int *pitch)
661 {
662 int retval = 0;
663
664 /* Check to see if the surface is already locked */
665 *pixels = NULL;
666 if ( surface->locked != 0 ) {
667 SDL_SetError("Surface is already locked");
668 return(-1);
669 }
670
671 /* Clip the lock to the clipping rectangle of the surface */
672 {
673 SDL_Rect *clip = &surface->clip_rect;
674 int dx, dy;
675 int h = rect->h;
676 int w = rect->w;
677
678 dx = clip->x - rect->x;
679 if(dx > 0) {
680 w -= dx;
681 rect->x += dx;
682 }
683 dx = rect->x + w - clip->x - clip->w;
684 if(dx > 0)
685 w -= dx;
686
687 dy = clip->y - rect->y;
688 if(dy > 0) {
689 h -= dy;
690 rect->y += dy;
691 }
692 dy = rect->y + h - clip->y - clip->h;
693 if(dy > 0)
694 h -= dy;
695
696 if(w > 0 && h > 0) {
697 rect->w = w;
698 rect->h = h;
699 } else {
700 rect->w = 0;
701 rect->h = 0;
702 SDL_SetError("Rectangle was clipped");
703 return(-1);
704 }
705 }
706
707 /* Perform the lock */
708 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
709 SDL_VideoDevice *video = current_video;
710 SDL_VideoDevice *this = current_video;
711 if ( video->LockHWSurfaceRect ) {
712 retval = video->LockHWSurfaceRect(this, surface, rect, pixels, pitch);
713 if ( retval == 0 ) {
714 surface->locked = -1;
715 return 0;
716 }
717 }
718 }
719 if ( SDL_MUSTLOCK(surface) ) {
720 retval = SDL_LockSurface(surface);
721 if ( retval < 0 ) {
722 return retval;
723 }
724 }
725 surface->locked = -1;
726 *pixels = (Uint8 *)surface->pixels + rect->y * surface->pitch + rect->x * surface->format->BytesPerPixel;
727 *pitch = surface->pitch;
728
729 /* Ready to go.. */
730 return(0);
731 }
732 /* 656 /*
733 * Unlock a previously locked surface 657 * Unlock a previously locked surface
734 * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse 658 * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse
735 * Instead, use: 659 * Instead, use:
736 * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) 660 * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
737 * video->UnlockHWSurface(video, surface); 661 * video->UnlockHWSurface(video, surface);
738 */ 662 */
739 void SDL_UnlockSurface (SDL_Surface *surface) 663 void SDL_UnlockSurface (SDL_Surface *surface)
740 { 664 {
741 /* Only perform an unlock if we are locked */ 665 /* Only perform an unlock if we are locked */
742 if ( surface->locked < 0 ) {
743 return;
744 }
745 if ( ! surface->locked || (--surface->locked > 0) ) { 666 if ( ! surface->locked || (--surface->locked > 0) ) {
746 return; 667 return;
747 } 668 }
748 669
749 /* Perform the unlock */ 670 /* Perform the unlock */
758 /* Update RLE encoded surface with new data */ 679 /* Update RLE encoded surface with new data */
759 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { 680 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
760 surface->flags &= ~SDL_RLEACCEL; /* stop lying */ 681 surface->flags &= ~SDL_RLEACCEL; /* stop lying */
761 SDL_RLESurface(surface); 682 SDL_RLESurface(surface);
762 } 683 }
763 }
764 }
765 void SDL_UnlockRect (SDL_Surface *surface)
766 {
767 /* Only perform an unlock if we are locked */
768 if ( surface->locked != -1 ) {
769 return;
770 }
771
772 /* Perform the unlock */
773 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
774 SDL_VideoDevice *video = current_video;
775 SDL_VideoDevice *this = current_video;
776 if ( video->LockHWSurfaceRect ) {
777 video->UnlockHWSurfaceRect(this, surface);
778 return;
779 }
780 }
781 if ( SDL_MUSTLOCK(surface) ) {
782 surface->locked = 1;
783 SDL_UnlockSurface(surface);
784 } else {
785 surface->locked = 0;
786 } 684 }
787 } 685 }
788 686
789 /* 687 /*
790 * Convert a surface into the specified pixel format. 688 * Convert a surface into the specified pixel format.