Beispiel #1
0
void crte_pacman_sprtes(SDL_Surface* image)
{
    pacman = new character(7);
    pacman->screen = screen;
    //pacman moves forward sprites
    pacman->create_sprites(3,69,40,16,16,0); //move right

    imgflp2 = rotate_surface(image); //move down
    //pacman->create_sprites(3,40,68,16,16,1);
    pacman->create_sprites2(3,40,168,16,16,1);

    imgflp= flip_surface(imgflp2, FLIP_VERTICAL  ); // move up
    pacman->create_sprites(3,40,76,16,16,1);

    

    flplft = flip_surface(image,FLIP_HORIZONTAL); //move left
    pacman->create_sprites2(3,175,40,16,16,0);

    //pacman dies sprites
    pacman->create_sprites(3,14,55,16,16,0); 

    pacman->create_sprites(3,14,55,16,14,0); 
    pacman->create_sprites(2,64,57,17,14,0); 
    pacman->create_sprites(5,122,54,16,14,0); 
}
Beispiel #2
0
void	pj_init(t_gen *gen, t_pj *pj, char *dir)
{
	int				i = 0, y = 0, e = 0;
	SDL_Surface		**state, *tmp;
	
	state = load_ani(gen, STA, dir, IDLE_FLEN, 5);
	if (pj->ani[0][0][0])
		anim_destroy(pj->ani);
	while (i != IDLE_FLEN)
	{
		if (i == 2){
			y++;e = 0;
		}
		if (state[i])
		{
			pj->ani[y][0][e] = SDL_CreateTextureFromSurface(gen->render, state[i]);
			tmp = flip_surface(state[i], 1);
			pj->ani[y][1][e] = SDL_CreateTextureFromSurface(gen->render, tmp);
			pj->ani[y][0][e + 1] = pj->ani[y][1][e + 1] = NULL;
			SDL_FreeSurface(state[i]);
			SDL_FreeSurface(tmp);
		}
		i++;
		e++;
	}
	free(state);
}
surface fl_modification::operator()(const surface& src) const
{
	surface ret = src;

	if(horiz_) {
		ret = flip_surface(ret);
	}

	if(vert_) {
		ret = flop_surface(ret);
	}

	return ret;
}
surface fl_modification::operator()(const surface& src) const
{
	surface ret = src;

	if ( horiz_  && vert_ ) {
		// Slightly faster than doing both a flip and a flop.
		ret = rotate_180_surface(ret);
	}

	else if(horiz_) {
		ret = flip_surface(ret);
	}

	else if(vert_) {
		ret = flop_surface(ret);
	}

	return ret;
}
Beispiel #5
0
static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
        const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
{
    struct wined3d_surface *back_buffer = swapchain->back_buffers[0];
    const struct wined3d_fb_state *fb = &swapchain->device->fb;
    const struct wined3d_gl_info *gl_info;
    struct wined3d_context *context;
    RECT src_rect, dst_rect;
    BOOL render_to_fbo;

    context = context_acquire(swapchain->device, back_buffer);
    if (!context->valid)
    {
        context_release(context);
        WARN("Invalid context, skipping present.\n");
        return WINED3D_OK;
    }

    gl_info = context->gl_info;

    /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
    if (swapchain->device->bCursorVisible &&
        swapchain->device->cursorTexture &&
        !swapchain->device->hardwareCursor)
    {
        struct wined3d_surface cursor;
        RECT destRect =
        {
            swapchain->device->xScreenSpace - swapchain->device->xHotSpot,
            swapchain->device->yScreenSpace - swapchain->device->yHotSpot,
            swapchain->device->xScreenSpace + swapchain->device->cursorWidth - swapchain->device->xHotSpot,
            swapchain->device->yScreenSpace + swapchain->device->cursorHeight - swapchain->device->yHotSpot,
        };
        TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
        /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
         * the application because we are only supposed to copy the information out. Using a fake surface
         * allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
         */
        memset(&cursor, 0, sizeof(cursor));
        cursor.resource.ref = 1;
        cursor.resource.device = swapchain->device;
        cursor.resource.pool = WINED3D_POOL_SCRATCH;
        cursor.resource.format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
        cursor.resource.type = WINED3D_RTYPE_SURFACE;
        cursor.texture_name = swapchain->device->cursorTexture;
        cursor.texture_target = GL_TEXTURE_2D;
        cursor.texture_level = 0;
        cursor.resource.width = swapchain->device->cursorWidth;
        cursor.resource.height = swapchain->device->cursorHeight;
        /* The cursor must have pow2 sizes */
        cursor.pow2Width = cursor.resource.width;
        cursor.pow2Height = cursor.resource.height;
        /* The surface is in the texture */
        cursor.flags |= SFLAG_INTEXTURE;
        /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
         * which is exactly what we want :-)
         */
        if (swapchain->desc.windowed)
            MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2);
        wined3d_surface_blt(back_buffer, &destRect, &cursor, NULL, WINEDDBLT_KEYSRC,
                NULL, WINED3D_TEXF_POINT);
    }

    if (swapchain->device->logo_surface)
    {
        struct wined3d_surface *src_surface = swapchain->device->logo_surface;
        RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height};

        /* Blit the logo into the upper left corner of the drawable. */
        wined3d_surface_blt(back_buffer, &rect, src_surface, &rect, WINEDDBLT_KEYSRC,
                NULL, WINED3D_TEXF_POINT);
    }

    TRACE("Presenting HDC %p.\n", context->hdc);

    render_to_fbo = swapchain->render_to_fbo;

    if (src_rect_in)
    {
        src_rect = *src_rect_in;
        if (!render_to_fbo && (src_rect.left || src_rect.top
                || src_rect.right != swapchain->desc.backbuffer_width
                || src_rect.bottom != swapchain->desc.backbuffer_height))
        {
            render_to_fbo = TRUE;
        }
    }
    else
    {
        src_rect.left = 0;
        src_rect.top = 0;
        src_rect.right = swapchain->desc.backbuffer_width;
        src_rect.bottom = swapchain->desc.backbuffer_height;
    }

    if (dst_rect_in)
        dst_rect = *dst_rect_in;
    else
        GetClientRect(swapchain->win_handle, &dst_rect);

    if (!render_to_fbo && (dst_rect.left || dst_rect.top
            || dst_rect.right != swapchain->desc.backbuffer_width
            || dst_rect.bottom != swapchain->desc.backbuffer_height))
        render_to_fbo = TRUE;

    /* Rendering to a window of different size, presenting partial rectangles,
     * or rendering to a different window needs help from FBO_blit or a textured
     * draw. Render the swapchain to a FBO in the future.
     *
     * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
     * all these issues - this fails if the window is smaller than the backbuffer.
     */
    if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
    {
        surface_load_location(back_buffer, SFLAG_INTEXTURE, NULL);
        surface_modify_location(back_buffer, SFLAG_INDRAWABLE, FALSE);
        swapchain->render_to_fbo = TRUE;
        swapchain_update_draw_bindings(swapchain);
    }
    else
    {
        surface_load_location(back_buffer, back_buffer->draw_binding, NULL);
    }

    if (swapchain->render_to_fbo)
    {
        /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
         * window size mismatch is impossible(fullscreen) and src and dst rectangles are
         * not allowed(they need the COPY swapeffect)
         *
         * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
         * the swap. */
        if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP)
            FIXME("Render-to-fbo with WINED3D_SWAP_EFFECT_FLIP\n");

        swapchain_blit(swapchain, context, &src_rect, &dst_rect);
    }

    if (swapchain->num_contexts > 1)
        wglFinish();
    SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */

    TRACE("SwapBuffers called, Starting new frame\n");
    /* FPS support */
    if (TRACE_ON(fps))
    {
        DWORD time = GetTickCount();
        ++swapchain->frames;

        /* every 1.5 seconds */
        if (time - swapchain->prev_time > 1500)
        {
            TRACE_(fps)("%p @ approx %.2ffps\n",
                    swapchain, 1000.0 * swapchain->frames / (time - swapchain->prev_time));
            swapchain->prev_time = time;
            swapchain->frames = 0;
        }
    }

    /* This is disabled, but the code left in for debug purposes.
     *
     * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
     * we can clear it with some ugly color to make bad drawing visible and ease debugging.
     * The Debug runtime does the same on Windows. However, a few games do not redraw the
     * screen properly, like Max Payne 2, which leaves a few pixels undefined.
     *
     * Tests show that the content of the back buffer after a discard flip is indeed not
     * reliable, so no game can depend on the exact content. However, it resembles the
     * old contents in some way, for example by showing fragments at other locations. In
     * general, the color theme is still intact. So Max payne, which draws rather dark scenes
     * gets a dark background image. If we clear it with a bright ugly color, the game's
     * bug shows up much more than it does on Windows, and the players see single pixels
     * with wrong colors.
     * (The Max Payne bug has been confirmed on Windows with the debug runtime) */
    if (FALSE && swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_DISCARD)
    {
        static const struct wined3d_color cyan = {0.0f, 1.0f, 1.0f, 1.0f};

        TRACE("Clearing the color buffer with cyan color\n");

        wined3d_device_clear(swapchain->device, 0, NULL,
                WINED3DCLEAR_TARGET, &cyan, 1.0f, 0);
    }

    if (!swapchain->render_to_fbo && ((swapchain->front_buffer->flags & SFLAG_INSYSMEM)
            || (back_buffer->flags & SFLAG_INSYSMEM)))
    {
        /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
         * Doesn't work with render_to_fbo because we're not flipping
         */
        struct wined3d_surface *front = swapchain->front_buffer;

        if (front->resource.size == back_buffer->resource.size)
        {
            DWORD fbflags;
            flip_surface(front, back_buffer);

            /* Tell the front buffer surface that is has been modified. However,
             * the other locations were preserved during that, so keep the flags.
             * This serves to update the emulated overlay, if any. */
            fbflags = front->flags;
            surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
            front->flags = fbflags;
        }
        else
        {
            surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
            surface_modify_location(back_buffer, SFLAG_INDRAWABLE, TRUE);
        }
    }
    else
    {
        surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE);
        /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
         * and INTEXTURE copies can keep their old content if they have any defined content.
         * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
         * the texture / sysmem copy needs to be reloaded from the drawable
         */
        if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP)
            surface_modify_location(back_buffer, back_buffer->draw_binding, TRUE);
    }

    if (fb->depth_stencil)
    {
        if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
                || fb->depth_stencil->flags & SFLAG_DISCARD)
        {
            surface_modify_ds_location(fb->depth_stencil, SFLAG_DISCARDED,
                    fb->depth_stencil->resource.width,
                    fb->depth_stencil->resource.height);
            if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil)
            {
                wined3d_surface_decref(swapchain->device->onscreen_depth_stencil);
                swapchain->device->onscreen_depth_stencil = NULL;
            }
        }
    }

    context_release(context);

    TRACE("returning\n");
    return WINED3D_OK;
}
Beispiel #6
0
static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
        const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
{
    struct wined3d_surface *back_buffer = swapchain->back_buffers[0];
    const struct wined3d_fb_state *fb = &swapchain->device->fb;
    const struct wined3d_gl_info *gl_info;
    struct wined3d_context *context;
    RECT src_rect, dst_rect;
    BOOL render_to_fbo;

    context = context_acquire(swapchain->device, back_buffer);
    if (!context->valid)
    {
        context_release(context);
        WARN("Invalid context, skipping present.\n");
        return;
    }

    gl_info = context->gl_info;

    if (swapchain->device->logo_texture)
    {
        struct wined3d_surface *src_surface = surface_from_resource(
                wined3d_texture_get_sub_resource(swapchain->device->logo_texture, 0));
        RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height};

        /* Blit the logo into the upper left corner of the drawable. */
        wined3d_surface_blt(back_buffer, &rect, src_surface, &rect, WINEDDBLT_ALPHATEST,
                NULL, WINED3D_TEXF_POINT);
    }

    if (swapchain->device->bCursorVisible && swapchain->device->cursor_texture
            && !swapchain->device->hardwareCursor)
    {
        struct wined3d_surface *cursor = surface_from_resource(
                wined3d_texture_get_sub_resource(swapchain->device->cursor_texture, 0));
        RECT destRect =
        {
            swapchain->device->xScreenSpace - swapchain->device->xHotSpot,
            swapchain->device->yScreenSpace - swapchain->device->yHotSpot,
            swapchain->device->xScreenSpace + swapchain->device->cursorWidth - swapchain->device->xHotSpot,
            swapchain->device->yScreenSpace + swapchain->device->cursorHeight - swapchain->device->yHotSpot,
        };

        TRACE("Rendering the software cursor.\n");

        if (swapchain->desc.windowed)
            MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2);
        wined3d_surface_blt(back_buffer, &destRect, cursor, NULL, WINEDDBLT_ALPHATEST,
                NULL, WINED3D_TEXF_POINT);
    }

    TRACE("Presenting HDC %p.\n", context->hdc);

    render_to_fbo = swapchain->render_to_fbo;

    if (src_rect_in)
    {
        src_rect = *src_rect_in;
        if (!render_to_fbo && (src_rect.left || src_rect.top
                || src_rect.right != swapchain->desc.backbuffer_width
                || src_rect.bottom != swapchain->desc.backbuffer_height))
        {
            render_to_fbo = TRUE;
        }
    }
    else
    {
        src_rect.left = 0;
        src_rect.top = 0;
        src_rect.right = swapchain->desc.backbuffer_width;
        src_rect.bottom = swapchain->desc.backbuffer_height;
    }

    if (dst_rect_in)
        dst_rect = *dst_rect_in;
    else if (context->surface && !swapchain->desc.windowed)
    {
        dst_rect.left = 0;
        dst_rect.top = 0;
        dst_rect.right = swapchain->front_buffer->resource.width;
        dst_rect.bottom = swapchain->front_buffer->resource.height;
    }
    else
        GetClientRect(swapchain->win_handle, &dst_rect);

    if (!render_to_fbo && (dst_rect.left || dst_rect.top
            || dst_rect.right != swapchain->desc.backbuffer_width
            || dst_rect.bottom != swapchain->desc.backbuffer_height))
        render_to_fbo = TRUE;

    /* Rendering to a window of different size, presenting partial rectangles,
     * or rendering to a different window needs help from FBO_blit or a textured
     * draw. Render the swapchain to a FBO in the future.
     *
     * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
     * all these issues - this fails if the window is smaller than the backbuffer.
     */
    if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
    {
        surface_load_location(back_buffer, WINED3D_LOCATION_TEXTURE_RGB);
        surface_invalidate_location(back_buffer, WINED3D_LOCATION_DRAWABLE);
        swapchain->render_to_fbo = TRUE;
        swapchain_update_draw_bindings(swapchain);
    }
    else
    {
        surface_load_location(back_buffer, back_buffer->draw_binding);
    }

    if (swapchain->render_to_fbo)
    {
        static unsigned int once;

        if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP && !once++)
            FIXME("WINED3D_SWAP_EFFECT_FLIP not implemented.\n");

        swapchain_blit(swapchain, context, &src_rect, &dst_rect);
    }

    if (swapchain->num_contexts > 1)
        gl_info->gl_ops.gl.p_glFinish();

    /* call wglSwapBuffers through the gl table to avoid confusing the Steam overlay */
    gl_info->gl_ops.wgl.p_wglSwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */

    TRACE("SwapBuffers called, Starting new frame\n");
    /* FPS support */
    if (TRACE_ON(fps))
    {
        DWORD time = GetTickCount();
        ++swapchain->frames;

        /* every 1.5 seconds */
        if (time - swapchain->prev_time > 1500)
        {
            TRACE_(fps)("%p @ approx %.2ffps\n",
                    swapchain, 1000.0 * swapchain->frames / (time - swapchain->prev_time));
            swapchain->prev_time = time;
            swapchain->frames = 0;
        }
    }

    if (!swapchain->render_to_fbo && ((swapchain->front_buffer->locations & WINED3D_LOCATION_SYSMEM)
            || (back_buffer->locations & WINED3D_LOCATION_SYSMEM)))
    {
        /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
         * Doesn't work with render_to_fbo because we're not flipping
         */
        struct wined3d_surface *front = swapchain->front_buffer;

        if (front->resource.size == back_buffer->resource.size)
        {
            flip_surface(front, back_buffer);

            /* Tell the front buffer surface that is has been modified. However,
             * the other locations were preserved during that, so keep the flags.
             * This serves to update the emulated overlay, if any. */
            surface_validate_location(front, WINED3D_LOCATION_DRAWABLE);
        }
        else
        {
            surface_validate_location(front, WINED3D_LOCATION_DRAWABLE);
            surface_invalidate_location(front, ~WINED3D_LOCATION_DRAWABLE);
            surface_validate_location(back_buffer, WINED3D_LOCATION_DRAWABLE);
            surface_invalidate_location(back_buffer, ~WINED3D_LOCATION_DRAWABLE);
        }
    }
    else
    {
        surface_validate_location(swapchain->front_buffer, WINED3D_LOCATION_DRAWABLE);
        surface_invalidate_location(swapchain->front_buffer, ~WINED3D_LOCATION_DRAWABLE);
        /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
         * and INTEXTURE copies can keep their old content if they have any defined content.
         * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
         * the texture / sysmem copy needs to be reloaded from the drawable
         */
        if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP)
        {
            surface_validate_location(back_buffer, back_buffer->draw_binding);
            surface_invalidate_location(back_buffer, ~back_buffer->draw_binding);
        }
    }

    if (fb->depth_stencil)
    {
        if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
                || fb->depth_stencil->flags & SFLAG_DISCARD)
        {
            surface_modify_ds_location(fb->depth_stencil, WINED3D_LOCATION_DISCARDED,
                    fb->depth_stencil->resource.width,
                    fb->depth_stencil->resource.height);
            if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil)
            {
                wined3d_surface_decref(swapchain->device->onscreen_depth_stencil);
                swapchain->device->onscreen_depth_stencil = NULL;
            }
        }
    }

    context_release(context);
}
void timage::draw(surface& canvas
		, const game_logic::map_formula_callable& variables)
{
	DBG_GUI_D << "Image: draw.\n";

	/**
	 * @todo formulas are now recalculated every draw cycle which is a  bit
	 * silly unless there has been a resize. So to optimize we should use an
	 * extra flag or do the calculation in a separate routine.
	 */
	const std::string& name = image_name_(variables);

	if(name.empty()) {
		DBG_GUI_D << "Image: formula returned no value, will not be drawn.\n";
		return;
	}

	/*
	 * The locator might return a different surface for every call so we can't
	 * cache the output, also not if no formula is used.
	 */
	surface tmp(image::get_image(image::locator(name)));

	if(!tmp) {
		ERR_GUI_D << "Image: '" << name << "' not found and won't be drawn.\n";
		return;
	}

	image_.assign(make_neutral_surface(tmp));
	assert(image_);
	src_clip_ = ::create_rect(0, 0, image_->w, image_->h);

	game_logic::map_formula_callable local_variables(variables);
	local_variables.add("image_original_width", variant(image_->w));
	local_variables.add("image_original_height", variant(image_->h));

	unsigned w = w_(local_variables);
	VALIDATE_WITH_DEV_MESSAGE(
			  static_cast<int>(w) >= 0
			, _("Image doesn't fit on canvas.")
			, (formatter() << "Image '" << name
				<< "', w = " << static_cast<int>(w) << ".").str());

	unsigned h = h_(local_variables);
	VALIDATE_WITH_DEV_MESSAGE(
			  static_cast<int>(h) >= 0
			, _("Image doesn't fit on canvas.")
			, (formatter() << "Image '" << name
				<< "', h = " << static_cast<int>(h) << ".").str());

	local_variables.add("image_width", variant(w ? w : image_->w));
	local_variables.add("image_height", variant(h ? h : image_->h));

	const unsigned x = x_(local_variables);
	VALIDATE_WITH_DEV_MESSAGE(
			  static_cast<int>(x) >= 0
			, _("Image doesn't fit on canvas.")
			, (formatter() << "Image '" << name
				<< "', x = " << static_cast<int>(x) << ".").str());

	const unsigned y = y_(local_variables);
	VALIDATE_WITH_DEV_MESSAGE(
			  static_cast<int>(y) >= 0
			, _("Image doesn't fit on canvas.")
			, (formatter() << "Image '" << name
				<< "', y = " << static_cast<int>(y) << ".").str());

	// Copy the data to local variables to avoid overwriting the originals.
	SDL_Rect src_clip = src_clip_;
	SDL_Rect dst_clip = ::create_rect(x, y, 0, 0);
	surface surf;

	// Test whether we need to scale and do the scaling if needed.
	if(w || h) {
		bool done = false;
		bool stretch_image = (resize_mode_ == stretch) && (!!w ^ !!h);
		if(!w) {
			if(stretch_image) {
				DBG_GUI_D << "Image: vertical stretch from " << image_->w
						<< ',' << image_->h << " to a height of " << h << ".\n";

				surf = stretch_surface_vertical(image_, h, false);
				done = true;
			}
			w = image_->w;
		}

		if(!h) {
			if(stretch_image) {
				DBG_GUI_D << "Image: horizontal stretch from " << image_->w
						<< ',' << image_->h << " to a width of " << w << ".\n";

				surf = stretch_surface_horizontal(image_, w, false);
				done = true;
			}
			h = image_->h;
		}

		if(!done) {

			if(resize_mode_ == tile) {
				DBG_GUI_D << "Image: tiling from " << image_->w
						<< ',' << image_->h << " to " << w << ',' << h << ".\n";

				const int columns = (w + image_->w - 1) / image_->w;
				const int rows = (h + image_->h - 1) / image_->h;
				surf = create_neutral_surface(w, h);

				for(int x = 0; x < columns; ++x) {
					for(int y = 0; y < rows; ++y) {
						const SDL_Rect dest = ::create_rect(
								  x * image_->w
								, y * image_->h
								, 0
								, 0);
						blit_surface(image_, NULL, surf, &dest);
					}
				}

			} else {
				if(resize_mode_ == stretch) {
					ERR_GUI_D << "Image: failed to stretch image, "
							"fall back to scaling.\n";
				}

				DBG_GUI_D << "Image: scaling from " << image_->w
						<< ',' << image_->h << " to " << w << ',' << h << ".\n";

				surf = scale_surface(image_, w, h, false);
			}
		}
		src_clip.w = w;
		src_clip.h = h;
	} else {
		surf = image_;
	}

	if(vertical_mirror_(local_variables)) {
		surf = flip_surface(surf, false);
	}

	blit_surface(surf, &src_clip, canvas, &dst_clip);
}
Beispiel #8
0
int lndmzeimg()
{
    maze[0] = NULL;
    maze[1] = load_image_mem(maze1,822);//load_image( "maze/maze1.bmp" );

    maze[2] = load_image_mem(maze2,822);//load_image( "maze/maze2.bmp" );  

    maze[3] = load_image_mem(maze3,1078);//load_image( "maze/maze3.bmp" );

    maze[4] = flip_surface(maze[3],FLIP_HORIZONTAL);
    maze[5] = flip_surface(maze[1],FLIP_HORIZONTAL);


    maze[6] = load_image_mem(maze6,1078);//load_image( "maze/maze6.bmp" );

    maze[7] = load_image_mem(maze7,1078);//load_image( "maze/maze7.bmp" );
    maze[8] = load_image_mem(maze8,1078);//load_image( "maze/maze8.bmp" );
    maze[9] = load_image_mem(maze9,1078);//load_image( "maze/maze9.bmp" );
    maze[10] = load_image_mem(maze10,1078);//load_image( "maze/maze10.bmp" );
    maze[11] = load_image_mem(maze11,1078);//load_image( "maze/maze11.bmp" );
    maze[12] = load_image_mem(maze12,1078);//load_image( "maze/maze12.bmp" );
    maze[13] = load_image_mem(maze13,1078);//load_image( "maze/maze13.bmp" );
    maze[14] = load_image_mem(maze14,1078);//load_image( "maze/maze14.bmp" );
    maze[15] = load_image_mem(maze15,1078);//load_image( "maze/maze15.bmp" );
    maze[16] = flip_surface(maze[14],FLIP_HORIZONTAL);
    maze[17] = flip_surface(maze[6],FLIP_HORIZONTAL);
    maze[18] = load_image_mem(maze18,1078);//load_image( "maze/maze18.bmp" );
    maze[19] = flip_surface(maze[12],FLIP_HORIZONTAL);
    maze[20] = flip_surface(maze[8], FLIP_HORIZONTAL);
    maze[21] = flip_surface(maze[7], FLIP_HORIZONTAL);
    maze[22] = flip_surface(maze[6], FLIP_HORIZONTAL);
    maze[23] = load_image_mem(maze23,1078);//load_image( "maze/maze23.bmp" );
    maze[24] = flip_surface(maze[23], FLIP_HORIZONTAL);
    maze[25] = load_image_mem(maze24,1078);//load_image( "maze/maze24.bmp" );
    maze[26] = load_image_mem(maze26,1078);//load_image("maze/maze26.bmp");
    maze[27] = load_image_mem(maze27,1078);//load_image("maze/maze27.bmp");
    maze[28] = load_image_mem(maze28,1078);//load_image("maze/maze28.bmp");
    maze[29] = load_image_mem(maze29,1078);//load_image("maze/maze29.bmp");
    maze[30] = load_image_mem(maze30,1078);//load_image("maze/maze30.bmp");
    maze[31] = flip_surface(maze[28], FLIP_HORIZONTAL);
    maze[32] = flip_surface(maze[26], FLIP_HORIZONTAL);
    maze[33] = flip_surface(maze[6], FLIP_HORIZONTAL);
    maze[34] = flip_surface(maze[25], FLIP_HORIZONTAL);
    maze[35] = load_image_mem(maze31,1078);//load_image("maze/maze31.bmp");
    maze[36] = load_image_mem(maze32,1078);//load_image("maze/maze32.bmp");
    maze[37] = load_image_mem(maze32,1078);//load_image("maze/maze32.bmp");
    maze[38] = load_image_mem(maze37,1078);//load_image("maze/maze37.bmp");
    maze[39] = load_image_mem(maze38,1078);//load_image("maze/maze38.bmp");
    maze[40] = flip_surface(maze[39], FLIP_HORIZONTAL);
    maze[41] = flip_surface(maze[38], FLIP_HORIZONTAL);
    maze[42] = flip_surface(maze[35], FLIP_HORIZONTAL);
    maze[43] = load_image_mem(maze39,1078);//load_image("maze/maze39.bmp");
    maze[44] = flip_surface(maze[43], FLIP_HORIZONTAL);
    maze[45] = load_image_mem(maze40,1078);//load_image("maze/maze40.bmp");
    maze[46] = flip_surface(maze[45],FLIP_HORIZONTAL);
    maze[47] = load_image_mem(maze41,1078);//load_image("maze/maze41.bmp");
    maze[48] = flip_surface(maze[47],FLIP_HORIZONTAL);   
    maze[49] = load_image_mem(maze42,1078);//load_image("maze/maze42.bmp");
    maze[50] = load_image_mem(maze43,1078);//load_image("maze/maze43.bmp");
    maze[51] = load_image_mem(maze44,1078);//load_image("maze/maze44.bmp");
    maze[52] = load_image_mem(maze45,1078);//load_image("maze/maze45.bmp");
    maze[53] = load_image_mem(maze46,1078);//load_image("maze/maze46.bmp");
    maze[54] = load_image_mem(maze47,1078);//load_image("maze/maze47.bmp");
    maze[55] = flip_surface(maze[54],FLIP_HORIZONTAL);   
    maze[56] = flip_surface(maze[53],FLIP_HORIZONTAL); 
    maze[57] = flip_surface(maze[52],FLIP_HORIZONTAL); 
    maze[58] = flip_surface(maze[51],FLIP_HORIZONTAL);  
    maze[59] = flip_surface(maze[50],FLIP_HORIZONTAL);  
    maze[60] = flip_surface(maze[49],FLIP_HORIZONTAL);  
    maze[61] = flip_surface(maze[7],FLIP_HORIZONTAL); 
    maze[62] = load_image_mem(maze48,1078);//load_image("maze/maze48.bmp"); 
    maze[63] = load_image_mem(maze49,1078);//load_image("maze/maze49.bmp"); 
    maze[64] = flip_surface(maze[52],FLIP_VERTICAL); 
    maze[65] = flip_surface(maze[53],FLIP_VERTICAL); 
    maze[66] = load_image_mem(maze50,1078);//load_image("maze/maze50.bmp");
    maze[67] = flip_surface(maze[66],FLIP_HORIZONTAL); 
    maze[68] = flip_surface(maze[65],FLIP_HORIZONTAL); 
    maze[69] = flip_surface(maze[64],FLIP_HORIZONTAL); 
    maze[70] = flip_surface(maze[51],FLIP_HORIZONTAL); 
    maze[71] = flip_surface(maze[63],FLIP_HORIZONTAL); 
    maze[72] = flip_surface(maze[8],FLIP_HORIZONTAL); 
    maze[73] = load_image_mem(maze51,1078);//load_image("maze/maze51.bmp");
    maze[74] = flip_surface(maze[45],FLIP_VERTICAL); 
    maze[75] = flip_surface(maze[46],FLIP_VERTICAL);
    maze[76] = load_image_mem(maze52,1078);//load_image("maze/maze52.bmp");
    maze[77] = load_image_mem(maze53,1078);//load_image("maze/maze53.bmp");
    maze[78] = flip_surface(maze[77],FLIP_HORIZONTAL);
    maze[79] = flip_surface(maze[76],FLIP_HORIZONTAL);
    maze[80] = flip_surface(maze[75],FLIP_HORIZONTAL);
    maze[81] = flip_surface(maze[74],FLIP_HORIZONTAL);
    maze[82] = flip_surface(maze[73],FLIP_HORIZONTAL);
    maze[83] = load_image_mem(maze55,1078);//load_image("maze/maze55.bmp");
    maze[84] = flip_surface(maze[83],FLIP_HORIZONTAL);
    maze[85] = load_image_mem(maze56,1078);//load_image("maze/maze56.bmp");
    maze[86] = flip_surface(maze[85],FLIP_HORIZONTAL);
    maze[87] = flip_surface(maze[50],FLIP_HORIZONTAL);
    maze[88] = load_image_mem(maze58,1078);//load_image("maze/maze58.bmp");
    maze[89] = flip_surface(maze[51],FLIP_HORIZONTAL);
    maze[90] = load_image_mem(maze59,1078);//load_image("maze/maze59.bmp");
    maze[91] = load_image_mem(maze60,1078);//load_image("maze/maze60.bmp");
    maze[92] = flip_surface(maze[90],FLIP_HORIZONTAL);
    maze[93] = flip_surface(maze[88],FLIP_HORIZONTAL);
    maze[94] = flip_surface(maze[45],FLIP_VERTICAL);
    maze[95] = flip_surface(maze[46],FLIP_VERTICAL);
    maze[96] = flip_surface(maze[73],FLIP_HORIZONTAL);
    maze[97] = flip_surface(maze[12],FLIP_HORIZONTAL);
    maze[98] = flip_surface(maze[53],FLIP_HORIZONTAL);
    maze[99] = load_image_mem(maze61,1078);//load_image("maze/maze61.bmp");
    maze[100] = load_image_mem(maze62,1078);//load_image("maze/maze62.bmp");
    maze[101] = load_image_mem(maze63,1078);//load_image("maze/maze63.bmp");
    maze[102] = flip_surface(maze[101],FLIP_HORIZONTAL);
    maze[103] = flip_surface(maze[99],FLIP_HORIZONTAL);
    maze[104] = flip_surface(maze[53],FLIP_HORIZONTAL);
    maze[105] = flip_surface(maze[98],FLIP_HORIZONTAL);
    maze[106] = load_image_mem(maze64,1078);//load_image("maze/maze64.bmp");
    maze[107] = load_image_mem(maze65,1078);//load_image("maze/maze65.bmp");
    maze[108] = load_image_mem(maze66,1078);//load_image("maze/maze66.bmp");
    maze[109] = load_image_mem(maze67,1078);//load_image("maze/maze67.bmp");
    maze[110] = load_image_mem(maze68,1078);//load_image("maze/maze68.bmp");
    maze[111] = load_image_mem(maze69,1078);//load_image("maze/maze69.bmp");
    maze[112] = flip_surface(maze[111],FLIP_HORIZONTAL);
    maze[113] = flip_surface(maze[110],FLIP_HORIZONTAL);
    maze[114] = flip_surface(maze[108],FLIP_HORIZONTAL);
    maze[115] = flip_surface(maze[107],FLIP_HORIZONTAL);
    maze[116] = flip_surface(maze[106],FLIP_HORIZONTAL);
    maze[117] = load_image_mem(maze70,1078);//load_image("maze/maze70.bmp");
    maze[118] = load_image_mem(maze71,1078);//load_image("maze/maze71.bmp");
    maze[119] = load_image_mem(maze72,1078);//load_image("maze/maze72.bmp");
    maze[120] = flip_surface(maze[118],FLIP_HORIZONTAL);
    maze[121] = flip_surface(maze[117],FLIP_HORIZONTAL);
    maze[122] = load_image_mem(maze73,1078);//load_image("maze/maze73.bmp");
    maze[123] = load_image_mem(maze74,1078);//load_image("maze/maze74.bmp");
    maze[124] = load_image_mem(maze75,1078);//load_image("maze/maze75.bmp");
    maze[125] = flip_surface(maze[124],FLIP_HORIZONTAL);
    maze[126] = flip_surface(maze[122],FLIP_HORIZONTAL);
    maze[127] = load_image_mem(maze76,1078);//load_image("maze/maze76.bmp");
    maze[128] = flip_surface(maze[127],FLIP_HORIZONTAL);
    maze[129] = flip_surface(maze[126],FLIP_HORIZONTAL);
    maze[130] = flip_surface(maze[125],FLIP_HORIZONTAL);
    maze[131] = flip_surface(maze[124],FLIP_HORIZONTAL);
    maze[132] = flip_surface(maze[122],FLIP_HORIZONTAL);
    maze[133] = flip_surface(maze[123],FLIP_HORIZONTAL);
    maze[134] = load_image_mem(maze78,1078);//load_image("maze/maze78.bmp");
    maze[135] = flip_surface(maze[123],FLIP_VERTICAL);
    maze[136] = load_image_mem(maze79,1078);//load_image("maze/maze79.bmp");
    maze[137] = flip_surface(maze[134],FLIP_HORIZONTAL);
    maze[138] = flip_surface(maze[137],FLIP_HORIZONTAL);
    maze[139] = flip_surface(maze[134],FLIP_HORIZONTAL);

    for (int i=1;i< 139;i++)
    {
        if (maze[i] == NULL) return 0;
    }

    //maze[137] = turn_maze_white(maze[137]);
   
    for (int j=1;j < 139;j++)
    {
	mazewhite[j] = turn_maze_white(maze[j]);
    }

    return 1;
}
static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
    IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
    struct wined3d_context *context;
    RECT src_rect, dst_rect;
    BOOL render_to_fbo;
    unsigned int sync;
    int retval;

#ifdef VBOX_WITH_WDDM
    /* quickly sort out invalid swapchains */
    if (!This->hDC)
    {
        WARN("Invalid swapchain");
        return WINED3D_OK;
    }
#endif

    IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);

    context = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
    if (!context->valid)
    {
        context_release(context);
        WARN("Invalid context, skipping present.\n");
        return WINED3D_OK;
    }

    /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
    if (This->device->bCursorVisible && This->device->cursorTexture)
    {
        IWineD3DSurfaceImpl cursor;
        RECT destRect =
        {
            This->device->xScreenSpace - This->device->xHotSpot,
            This->device->yScreenSpace - This->device->yHotSpot,
            This->device->xScreenSpace + This->device->cursorWidth - This->device->xHotSpot,
            This->device->yScreenSpace + This->device->cursorHeight - This->device->yHotSpot,
        };
        TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
        /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
         * the application because we are only supposed to copy the information out. Using a fake surface
         * allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
         */
        memset(&cursor, 0, sizeof(cursor));
        cursor.lpVtbl = &IWineD3DSurface_Vtbl;
        cursor.resource.ref = 1;
        cursor.resource.device = This->device;
        cursor.resource.pool = WINED3DPOOL_SCRATCH;
        cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, context->gl_info);
        cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
        cursor.texture_name = This->device->cursorTexture;
        cursor.texture_target = GL_TEXTURE_2D;
        cursor.texture_level = 0;
        cursor.currentDesc.Width = This->device->cursorWidth;
        cursor.currentDesc.Height = This->device->cursorHeight;
        /* The cursor must have pow2 sizes */
        cursor.pow2Width = cursor.currentDesc.Width;
        cursor.pow2Height = cursor.currentDesc.Height;
        /* The surface is in the texture */
        cursor.Flags |= SFLAG_INTEXTURE;
        /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
         * which is exactly what we want :-)
         */
        if (This->presentParms.Windowed) {
#ifdef VBOX_WITH_WDDM
            /* @todo: can we actualy be here? */
#endif
            MapWindowPoints(NULL, This->win_handle, (LPPOINT)&destRect, 2);
        }
        IWineD3DSurface_Blt(This->backBuffer[0], &destRect, (IWineD3DSurface *)&cursor,
                NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT);
    }

    if (This->device->logo_surface)
    {
        /* Blit the logo into the upper left corner of the drawable. */
        IWineD3DSurface_BltFast(This->backBuffer[0], 0, 0, This->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
    }

#ifdef VBOX_WITH_WDDM
    TRACE("Presenting HDC %p.\n", context->currentSwapchain->hDC);
#else
    TRACE("Presenting HDC %p.\n", context->hdc);
#endif

    render_to_fbo = This->render_to_fbo;

    if (pSourceRect)
    {
        src_rect = *pSourceRect;
        if (!render_to_fbo && (src_rect.left || src_rect.top
                || src_rect.right != This->presentParms.BackBufferWidth
                || src_rect.bottom != This->presentParms.BackBufferHeight))
        {
            render_to_fbo = TRUE;
        }
    }
    else
    {
        src_rect.left = 0;
        src_rect.top = 0;
        src_rect.right = This->presentParms.BackBufferWidth;
        src_rect.bottom = This->presentParms.BackBufferHeight;
    }

    if (pDestRect) dst_rect = *pDestRect;
#ifndef VBOX_WITH_WDDM
    else
        GetClientRect(This->win_handle, &dst_rect);

    if (!render_to_fbo && (dst_rect.left || dst_rect.top
            || dst_rect.right != This->presentParms.BackBufferWidth
            || dst_rect.bottom != This->presentParms.BackBufferHeight))
    {
        render_to_fbo = TRUE;
    }
#else
    else
    {
        dst_rect.left = 0;
        dst_rect.top = 0;
        dst_rect.right = This->presentParms.BackBufferWidth;
        dst_rect.bottom = This->presentParms.BackBufferHeight;
    }
#endif

    /* Rendering to a window of different size, presenting partial rectangles,
     * or rendering to a different window needs help from FBO_blit or a textured
     * draw. Render the swapchain to a FBO in the future.
     *
     * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
     * all these issues - this fails if the window is smaller than the backbuffer.
     */
    if (!This->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
    {
        IWineD3DSurface_LoadLocation(This->backBuffer[0], SFLAG_INTEXTURE, NULL);
        IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, FALSE);
        This->render_to_fbo = TRUE;

        /* Force the context manager to update the render target configuration next draw. */
        context->current_rt = NULL;
    }

    if(This->render_to_fbo)
    {
        /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
         * window size mismatch is impossible(fullscreen) and src and dst rectangles are
         * not allowed(they need the COPY swapeffect)
         *
         * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
         * the swap
         */
        if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP )
        {
            FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n");
        }

        swapchain_blit(This, context, &src_rect, &dst_rect);
    }

#ifdef VBOX_WITH_WDDM
    if (This->device->numContexts > 1) wglFinish();
#else
    if (This->num_contexts > 1) wglFinish();
#endif

#if defined(VBOX_WITH_WDDM) && defined(DEBUG)
    {
        HWND wnd = WindowFromDC(context->currentSwapchain->hDC);
        Assert(wnd == context->currentSwapchain->win_handle);
    }
#endif

#ifdef VBOX_WITH_WDDM
    /* We're directly using wglMakeCurrent calls skipping GDI layer, which causes GDI SwapBuffers to fail trying to
     * call glFinish, which doesn't have any context set. So we use wglSwapLayerBuffers directly as well.
     */
    pwglSwapLayerBuffers(context->currentSwapchain->hDC, WGL_SWAP_MAIN_PLANE);
#else
# ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
    pwglSwapLayerBuffers(context->hdc, WGL_SWAP_MAIN_PLANE);
# else
    SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
# endif
#endif

    TRACE("SwapBuffers called, Starting new frame\n");
    /* FPS support */
    if (TRACE_ON(fps))
    {
        DWORD time = GetTickCount();
        This->frames++;
        /* every 1.5 seconds */
        if (time - This->prev_time > 1500) {
            TRACE_(fps)("%p @ approx %.2ffps\n", This, 1000.0*This->frames/(time - This->prev_time));
            This->prev_time = time;
            This->frames = 0;
        }
    }

#if defined(FRAME_DEBUGGING)
{
    if (GetFileAttributesA("C:\\D3DTRACE") != INVALID_FILE_ATTRIBUTES) {
        if (!isOn) {
            isOn = TRUE;
            FIXME("Enabling D3D Trace\n");
            __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 1);
#if defined(SHOW_FRAME_MAKEUP)
            FIXME("Singe Frame snapshots Starting\n");
            isDumpingFrames = TRUE;
            ENTER_GL();
            glClear(GL_COLOR_BUFFER_BIT);
            LEAVE_GL();
#endif

#if defined(SINGLE_FRAME_DEBUGGING)
        } else {
#if defined(SHOW_FRAME_MAKEUP)
            FIXME("Singe Frame snapshots Finishing\n");
            isDumpingFrames = FALSE;
#endif
            FIXME("Singe Frame trace complete\n");
            DeleteFileA("C:\\D3DTRACE");
            __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
#endif
        }
    } else {
        if (isOn) {
            isOn = FALSE;
#if defined(SHOW_FRAME_MAKEUP)
            FIXME("Single Frame snapshots Finishing\n");
            isDumpingFrames = FALSE;
#endif
            FIXME("Disabling D3D Trace\n");
            __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
        }
    }
}
#endif

    /* This is disabled, but the code left in for debug purposes.
     *
     * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
     * we can clear it with some ugly color to make bad drawing visible and ease debugging.
     * The Debug runtime does the same on Windows. However, a few games do not redraw the
     * screen properly, like Max Payne 2, which leaves a few pixels undefined.
     *
     * Tests show that the content of the back buffer after a discard flip is indeed not
     * reliable, so no game can depend on the exact content. However, it resembles the
     * old contents in some way, for example by showing fragments at other locations. In
     * general, the color theme is still intact. So Max payne, which draws rather dark scenes
     * gets a dark background image. If we clear it with a bright ugly color, the game's
     * bug shows up much more than it does on Windows, and the players see single pixels
     * with wrong colors.
     * (The Max Payne bug has been confirmed on Windows with the debug runtime)
     */
    if (FALSE && This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) {
        TRACE("Clearing the color buffer with cyan color\n");

        IWineD3DDevice_Clear((IWineD3DDevice *)This->device, 0, NULL,
                WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
    }

    if(!This->render_to_fbo &&
       ( ((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags   & SFLAG_INSYSMEM ||
         ((IWineD3DSurfaceImpl *) This->backBuffer[0])->Flags & SFLAG_INSYSMEM ) ) {
        /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
         * Doesn't work with render_to_fbo because we're not flipping
         */
        IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
        IWineD3DSurfaceImpl *back = (IWineD3DSurfaceImpl *) This->backBuffer[0];

        if(front->resource.size == back->resource.size) {
            DWORD fbflags;
            flip_surface(front, back);

            /* Tell the front buffer surface that is has been modified. However,
             * the other locations were preserved during that, so keep the flags.
             * This serves to update the emulated overlay, if any
             */
            fbflags = front->Flags;
            IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
            front->Flags = fbflags;
        } else {
            IWineD3DSurface_ModifyLocation((IWineD3DSurface *) front, SFLAG_INDRAWABLE, TRUE);
            IWineD3DSurface_ModifyLocation((IWineD3DSurface *) back, SFLAG_INDRAWABLE, TRUE);
        }
    } else {
        IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
        /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
         * and INTEXTURE copies can keep their old content if they have any defined content.
         * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
         * the texture / sysmem copy needs to be reloaded from the drawable
         */
        if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP) {
            IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, TRUE);
        }
    }

    if (This->device->stencilBufferTarget)
    {
        if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
                || ((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget)->Flags & SFLAG_DISCARD)
        {
            surface_modify_ds_location(This->device->stencilBufferTarget, SFLAG_DS_DISCARDED);
        }
    }

    if (This->presentParms.PresentationInterval != WINED3DPRESENT_INTERVAL_IMMEDIATE
            && context->gl_info->supported[SGI_VIDEO_SYNC])
    {
        retval = GL_EXTCALL(glXGetVideoSyncSGI(&sync));
        if(retval != 0) {
            ERR("glXGetVideoSyncSGI failed(retval = %d\n", retval);
        }

        switch(This->presentParms.PresentationInterval) {
            case WINED3DPRESENT_INTERVAL_DEFAULT:
            case WINED3DPRESENT_INTERVAL_ONE:
                if(sync <= This->vSyncCounter) {
                    retval = GL_EXTCALL(glXWaitVideoSyncSGI(1, 0, &This->vSyncCounter));
                } else {
                    This->vSyncCounter = sync;
                }
                break;
            case WINED3DPRESENT_INTERVAL_TWO:
                if(sync <= This->vSyncCounter + 1) {
                    retval = GL_EXTCALL(glXWaitVideoSyncSGI(2, This->vSyncCounter & 0x1, &This->vSyncCounter));
                } else {
                    This->vSyncCounter = sync;
                }
                break;
            case WINED3DPRESENT_INTERVAL_THREE:
                if(sync <= This->vSyncCounter + 2) {
                    retval = GL_EXTCALL(glXWaitVideoSyncSGI(3, This->vSyncCounter % 0x3, &This->vSyncCounter));
                } else {
                    This->vSyncCounter = sync;
                }
                break;
            case WINED3DPRESENT_INTERVAL_FOUR:
                if(sync <= This->vSyncCounter + 3) {
                    retval = GL_EXTCALL(glXWaitVideoSyncSGI(4, This->vSyncCounter & 0x3, &This->vSyncCounter));
                } else {
                    This->vSyncCounter = sync;
                }
                break;
            default:
                FIXME("Unknown presentation interval %08x\n", This->presentParms.PresentationInterval);
        }
    }

    context_release(context);

    TRACE("returning\n");
    return WINED3D_OK;
}
void Shape_Blitter::SDL_Draw(SDL_Surface *dst_surface, const Image_Rect& dst)
{
    if (!dst_surface)
		return;
	
    // load shape into surface if necessary
    if (!m_surface)
    {
        byte *pixelsOut = NULL;
        SDL_Surface *tmp = get_shape_surface(m_frame, m_coll, &pixelsOut, (m_type == Shape_Texture_Interface) ? -1.0 : 1.0);
        if (!tmp)
            return;
        
        if (pixelsOut)
        {
			m_surface = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_BGRA8888, 0);
            SDL_FreeSurface(tmp);
            free(pixelsOut);
            pixelsOut = NULL;
        }
        else if (m_coll == 0 && m_frame >= 12 && m_frame <= 29)
        {
            // fix transparency on motion sensor blips
            SDL_SetColorKey(tmp, SDL_TRUE, 0);
			m_surface = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_BGRA8888, 0);
            SDL_FreeSurface(tmp);
        }
        else
            m_surface = tmp;
    }
    if (!m_surface)
        return;
    
    if (!m_scaled_surface ||
        m_scaled_surface->w != m_scaled_src.w ||
        m_scaled_surface->h != m_scaled_src.h)
    {
        if (m_scaled_surface && (m_scaled_surface != m_surface))
            SDL_FreeSurface(m_scaled_surface);
        
        if (m_scaled_src.w != m_src.w || m_scaled_src.h != m_src.h)
            m_scaled_surface = rescale_surface(m_surface, m_scaled_src.w, m_scaled_src.h);
        else
            m_scaled_surface = m_surface;
        
        if (m_type == Shape_Texture_Wall)
        {
            // rotate wall textures
            SDL_Surface *tmp = rotate_surface(m_scaled_surface, m_scaled_surface->w, m_scaled_surface->h);
            if (m_scaled_surface != m_surface)
                SDL_FreeSurface(m_scaled_surface);
            m_scaled_surface = tmp;
        }
        else if (m_type == Shape_Texture_Landscape)
        {
            // flip landscapes vertically
            SDL_Surface *tmp = flip_surface(m_scaled_surface, m_scaled_surface->w, m_scaled_surface->h);
            if (m_scaled_surface != m_surface)
                SDL_FreeSurface(m_scaled_surface);
            m_scaled_surface = tmp;
        }
    }
    
    if (!m_scaled_surface)
        return;
    
    SDL_Rect r = { crop_rect.x, crop_rect.y, crop_rect.w, crop_rect.h };
    SDL_Rect sdst = { dst.x, dst.y, dst.w, dst.h };
	SDL_BlitSurface(m_scaled_surface, &r, dst_surface, &sdst);
}
Beispiel #11
0
void Shape_Blitter::SDL_Draw(SDL_Surface *dst_surface, SDL_Rect& dst)
{
  if (!dst_surface) {
    return;
  }

  // load shape into surface if necessary
  if (!m_surface) {
    byte *pixelsOut = NULL;
    SDL_Surface *tmp =
      get_shape_surface(m_desc, NONE, &pixelsOut,
                        (m_type == Shape_Texture_Interface) ? -1.0 : 1.0);
    if (!tmp) {
      return;
    }

    if (pixelsOut) {
      m_surface = SDL_DisplayFormatAlpha(tmp);
      SDL_FreeSurface(tmp);
      free(pixelsOut);
      pixelsOut = NULL;
    }
    else{
      m_surface = tmp;
    }
  }
  if (!m_surface) {
    return;
  }

  if (!m_scaled_surface ||
      m_scaled_surface->w != m_scaled_src.w ||
      m_scaled_surface->h != m_scaled_src.h) {
    if (m_scaled_surface && (m_scaled_surface != m_surface)) {
      SDL_FreeSurface(m_scaled_surface);
    }

    if (m_scaled_src.w != m_src.w || m_scaled_src.h != m_src.h) {
      m_scaled_surface = rescale_surface(m_surface, m_scaled_src.w,
                                         m_scaled_src.h);
    }
    else{
      m_scaled_surface = m_surface;
    }

    if (m_type == Shape_Texture_Wall) {
      // rotate wall textures
      SDL_Surface *tmp = rotate_surface(m_scaled_surface, m_scaled_surface->w,
                                        m_scaled_surface->h);
      if (m_scaled_surface != m_surface) {
        SDL_FreeSurface(m_scaled_surface);
      }
      m_scaled_surface = tmp;
    }
    else if (m_type == Shape_Texture_Landscape) {
      // flip landscapes vertically
      SDL_Surface *tmp = flip_surface(m_scaled_surface, m_scaled_surface->w,
                                      m_scaled_surface->h);
      if (m_scaled_surface != m_surface) {
        SDL_FreeSurface(m_scaled_surface);
      }
      m_scaled_surface = tmp;
    }
  }

  if (!m_scaled_surface) {
    return;
  }

  SDL_Rect r = crop_rect;
  SDL_BlitSurface(m_scaled_surface, &r, dst_surface, &dst);
}