    # File lib/rubygame/surface.rb, line 83
      def initialize( size, depth=0, flags=[] )

        # Cheating a bit. First arg can be a SDL::Surface to wrap it.
        #
        if( size.kind_of? SDL::Surface )
          surf = size
          if( surf.pointer.null? )
            raise Rubygame::SDLError, "Surface cannot wrap NULL Surface!"
          else
            @struct = surf
          end
          return
        end

        unless size.kind_of? Array
          raise TypeError, "Surface size is not an Array: #{size.inspect}"
        end

        unless size.length == 2 and size.all?{ |n| n.kind_of? Numeric }
          raise ArgumentError, "Invalid Surface size: #{size.inspect}"
        end

        pixformat = nil

        vs = SDL.GetVideoSurface()

        unless( vs.pointer.null? )
          # Pixel format is retrieved from the video surface.
          pixformat = vs.format
        else
          # We can only get the system color depth when the
          # video system has been initialized.
          if( Rubygame.init_video_system == 0 )
            pixformat = SDL.GetVideoInfo().vfmt
          else
            raise(Rubygame::SDLError,
                  "Could not initialize SDL video subsystem.")
          end
        end

        rmask = pixformat.Rmask
        gmask = pixformat.Gmask
        bmask = pixformat.Bmask
        amask = pixformat.Amask

        if( depth <= 0 )
          depth = pixformat.BitsPerPixel
        end

        w, h = size

        flags = Rubygame.collapse_flags(flags)

        @struct = SDL.CreateRGBSurface(flags, w, h, depth,
                                       rmask, gmask, bmask, amask)
      end