surface.c revision 38bc64ae97ecf5c07e78bb420ddc1c4d039bdb19
/*
* IWineD3DSurface Implementation
*
* Copyright 1998 Lionel Ulmer
* Copyright 2000-2001 TransGaming Technologies Inc.
* Copyright 2002-2005 Jason Edmeades
* Copyright 2002-2003 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2006-2008 Stefan Dösinger for CodeWeavers
* Copyright 2007-2008 Henri Verbeet
* Copyright 2006-2008 Roderick Colenbrander
* Copyright 2009 Henri Verbeet for CodeWeavers
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include "wined3d_private.h"
#define GLINFO_LOCATION (*gl_info)
#ifdef VBOX_WITH_WDDM
{
}
{
if (VBOXSHRC_IS_LOCKED(This))
return;
/* perform data->texture synchronization */
}
{
if (!VBOXSHRC_IS_SHARED(This))
return;
}
{
if (!VBOXSHRC_IS_SHARED(This))
return;
}
#endif
{
/* Need a context to destroy the texture. Use the currently active render
* target, but only if the primary render target exists. Otherwise
* lastActiveRenderTarget is garbage. When destroying the primary render
* target, Uninit3D() will activate a context before doing anything. */
{
}
ENTER_GL();
if (This->texture_name
#ifdef VBOX_WITH_WDDM
#endif
)
{
/* Release the OpenGL texture. */
}
{
/* Delete the PBO. */
}
{
}
LEAVE_GL();
{
/* Release the DC. */
/* Release the DIB section. */
}
}
UINT surface_calculate_size(const struct wined3d_format_desc *format_desc, UINT alignment, UINT width, UINT height)
{
{
size = 0;
}
{
}
else
{
/* The pitch is a multiple of 4 bytes. */
}
return size;
}
struct blt_info
{
};
struct float_rect
{
float l;
float t;
float r;
float b;
};
{
}
static void surface_get_blt_info(GLenum target, const RECT *rect_in, GLsizei w, GLsizei h, struct blt_info *info)
{
struct float_rect f;
if (rect_in)
else
{
}
switch (target)
{
default:
/* Fall back to GL_TEXTURE_2D */
case GL_TEXTURE_2D:
break;
case GL_TEXTURE_RECTANGLE_ARB:
break;
cube_coords_float(&rect, w, h, &f);
break;
cube_coords_float(&rect, w, h, &f);
break;
cube_coords_float(&rect, w, h, &f);
break;
cube_coords_float(&rect, w, h, &f);
break;
cube_coords_float(&rect, w, h, &f);
break;
cube_coords_float(&rect, w, h, &f);
break;
}
}
{
if (rect_in)
else
{
}
}
/* GL locking and context activation is done by the caller */
void draw_textured_quad(IWineD3DSurfaceImpl *src_surface, const RECT *src_rect, const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter)
{
surface_get_blt_info(src_surface->texture_target, src_rect, src_surface->pow2Width, src_surface->pow2Height, &info);
checkGLcall("glEnable(bind_target)");
/* Bind the texture */
checkGLcall("glBindTexture");
/* Filtering for StretchRect */
checkGLcall("glTexParameteri");
checkGLcall("glTexParameteri");
checkGLcall("glTexEnvi");
/* Draw a quad */
glEnd();
/* Unbind the texture */
checkGLcall("glBindTexture(info->bind_target, 0)");
/* We changed the filtering settings on the texture. Inform the
* container about this to get the filters reset properly next draw. */
if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)src_surface, &IID_IWineD3DBaseTexture, (void **)&texture)))
{
}
}
UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
#ifdef VBOX_WITH_WDDM
, void *pvClientMem
#endif
)
{
unsigned int resource_size;
if (multisample_quality > 0)
{
multisample_quality = 0;
}
/* FIXME: Check that the format is supported by the device. */
/* Look at the implementation and set the correct Vtable. */
switch (surface_type)
{
case SURFACE_OPENGL:
break;
case SURFACE_GDI:
break;
default:
return WINED3DERR_INVALIDCALL;
}
#ifdef VBOX_WITH_WDDM
#endif
);
{
return hr;
}
#ifdef VBOX_WITH_WDDM
/* this will be a nop for the non-shared resource,
* for the shared resource this will ensure the surface is initialized properly */
#endif
/* "Standalone" surface. */
/* Flags */
#ifdef VBOX_WITH_WDDM
#endif
/* Quick lockable sanity check.
* TODO: remove this after surfaces, usage and lockability have been debugged properly
* this function is too deep to need to care about things like this.
* Levels need to be checked too, since they all affect what can be done. */
switch (pool)
{
case WINED3DPOOL_SCRATCH:
if(!lockable)
{
FIXME("Called with a pool of SCRATCH and a lockable of FALSE "
"which are mutually exclusive, setting lockable to TRUE.\n");
}
break;
case WINED3DPOOL_SYSTEMMEM:
if (!lockable)
FIXME("Called with a pool of SYSTEMMEM and a lockable of FALSE, this is acceptable but unexpected.\n");
break;
case WINED3DPOOL_MANAGED:
if (usage & WINED3DUSAGE_DYNAMIC)
FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n");
break;
case WINED3DPOOL_DEFAULT:
if (lockable && !(usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n");
break;
default:
break;
};
{
FIXME("Trying to create a render target that isn't in the default pool.\n");
}
/* Mark the texture as dirty so that it gets loaded first time around. */
TRACE("surface %p, memory %p, size %u\n", surface, surface->resource.allocatedMemory, surface->resource.size);
/* Call the private setup routine */
{
return hr;
}
#ifdef VBOX_WITH_WDDM
if (VBOXSHRC_IS_SHARED(surface))
{
if (!VBOXSHRC_IS_SHARED_OPENED(surface))
{
Assert(!(*shared_handle));
}
else
{
}
}
else
{
}
#endif
return hr;
}
{
}
{
if(srgb)
{
}
else
{
}
{
/* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the
* surface has no texture name yet. See if we can get rid of this. */
ERR("Surface has SFLAG_INTEXTURE set, but no texture name\n");
}
#ifdef VBOX_WITH_WDDM
if (VBOXSHRC_IS_SHARED(This))
{
}
#endif
}
{
{
if (target == GL_TEXTURE_RECTANGLE_ARB)
{
}
{
}
}
}
/* Context activation is done by the caller. */
/* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
* Read the unit back instead of switching to 0, this avoids messing around with the state manager's
* gl states. The current texture unit should always be a valid one.
*
* To be more specific, this is tricky because we can implicitly be called
* from sampler() in state.c. This means we can't touch anything other than
* whatever happens to be the currently active texture, or we would risk
* marking already applied sampler states dirty again.
*
* TODO: Track the current active texture per GL context instead of using glGet
*/
ENTER_GL();
LEAVE_GL();
if (active_sampler != WINED3D_UNMAPPED_STAGE)
{
}
}
/* This function checks if the primary render target uses the 8bit paletted format. */
{
return TRUE;
}
return FALSE;
}
/* This call just downloads data, the caller is responsible for binding the
* correct texture. */
/* Context activation is done by the caller. */
{
/* Only support read back of converted P8 surfaces */
{
FIXME("Read back converted textures unsupported, format=%s\n", debug_d3dformat(format_desc->format));
return;
}
ENTER_GL();
{
TRACE("(%p) : Calling glGetCompressedTexImageARB level %d, format %#x, type %#x, data %p.\n",
{
checkGLcall("glBindBufferARB");
checkGLcall("glGetCompressedTexImageARB");
checkGLcall("glBindBufferARB");
}
else
{
checkGLcall("glGetCompressedTexImageARB");
}
LEAVE_GL();
} else {
void *mem;
int src_pitch = 0;
int dst_pitch = 0;
/* In case of P8 the index is stored in the alpha component if the primary render target uses P8 */
if (format_desc->format == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.device))
{
}
} else {
}
TRACE("(%p) : Calling glGetTexImage level %d, format %#x, type %#x, data %p\n",
checkGLcall("glBindBufferARB");
checkGLcall("glGetTexImage");
checkGLcall("glBindBufferARB");
} else {
checkGLcall("glGetTexImage");
}
LEAVE_GL();
UINT y;
/*
* Some games (e.g. warhammer 40k) don't work properly with the odd pitches, preventing
* the surface pitch from being used to box non-power2 textures. Instead we have to use a hack to
* repack the texture so that the bpp * width pitch can be used instead of bpp * pow2width.
*
* We're doing this...
*
* instead of boxing the texture :
* |<-texture width ->| -->pow2width| /\
* |111111111111111111| | |
* |222 Texture 222222| boxed empty | texture height
* |3333 Data 33333333| | |
* |444444444444444444| | \/
* ----------------------------------- |
* | boxed empty | boxed empty | pow2height
* | | | \/
* -----------------------------------
*
*
* we're repacking the data to the expected texture width
*
* |<-texture width ->| -->pow2width| /\
* |111111111111111111222222222222222| |
* |222333333333333333333444444444444| texture height
* |444444 | |
* | | \/
* | | |
* | empty | pow2height
* | | \/
* -----------------------------------
*
* == is the same as
*
* |<-texture width ->| /\
* |111111111111111111|
* |222222222222222222|texture height
* |333333333333333333|
* |444444444444444444| \/
* --------------------
*
* this also means that any references to allocatedMemory should work with the data as if were a
* standard texture with a non-power2 width instead of texture boxed up to be a power2 texture.
*
* internally the texture is still stored in a boxed format so any references to textureName will
* get a boxed texture with width pow2width and not a texture of width currentDesc.Width.
*
* Performance should not be an issue, because applications normally do not lock the surfaces when
* rendering. If an app does, the SFLAG_DYNLOCK flag will kick in and the memory copy won't be released,
* and doesn't have to be re-read.
*/
/* skip the first row */
}
}
}
/* Surface has now been downloaded */
}
/* This call just uploads data, the caller is responsible for binding the
* correct texture. */
/* Context activation is done by the caller. */
{
if (srgb)
{
}
{
}
else
{
}
TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
TRACE("target %#x, level %u, resource size %u.\n",
if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
ENTER_GL();
{
checkGLcall("glBindBufferARB");
}
{
TRACE("Calling glCompressedTexSubImage2DARB.\n");
checkGLcall("glCompressedTexSubImage2DARB");
}
else
{
TRACE("Calling glTexSubImage2D.\n");
checkGLcall("glTexSubImage2D");
}
{
checkGLcall("glBindBufferARB");
}
LEAVE_GL();
{
unsigned int i;
for (i = 0; i < device->numContexts; ++i)
{
}
}
}
#ifdef VBOX_WITH_WDDM
static void surface_upload_data_rect(IWineD3DSurfaceImpl *This, IWineD3DSurfaceImpl *Src, const struct wined3d_gl_info *gl_info,
{
if (srgb)
{
}
{
}
else
{
}
TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
TRACE("target %#x, level %u, resource size %u.\n",
if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
ENTER_GL();
{
checkGLcall("glBindBufferARB");
/* the data should contain a zero-based offset */
}
{
TRACE("Calling glCompressedTexSubImage2DARB.\n");
checkGLcall("glCompressedTexSubImage2DARB");
}
else
{
TRACE("Calling glTexSubImage2D.\n");
checkGLcall("glTexSubImage2D");
}
{
checkGLcall("glBindBufferARB");
}
LEAVE_GL();
{
unsigned int i;
for (i = 0; i < device->numContexts; ++i)
{
}
}
}
#endif
/* This call just allocates the texture, the caller is responsible for binding
* the correct texture. */
/* Context activation is done by the caller. */
static void surface_allocate_surface(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
{
if (srgb)
{
}
{
}
else
{
}
if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
TRACE("(%p) : Creating surface (target %#x) level %d, d3d format %s, internal format %#x, width %d, height %d, gl format %#x, gl type=%#x\n",
ENTER_GL();
{
if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
/* In some cases we want to disable client storage.
* SFLAG_NONPOW2 has a bigger opengl texture than the client memory, and different pitches
* SFLAG_DIBSECTION: Dibsections may have read / write protections on the memory. Avoid issues...
* SFLAG_CONVERTED: The conversion destination memory is freed after loading the surface
* allocatedMemory == NULL: Not defined in the extension. Seems to disable client storage effectively
*/
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
} else {
/* Point opengl to our allocated texture memory. Do not use resource.allocatedMemory here because
* it might point into a pbo. Instead use heapMemory, but get the alignment right.
*/
mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
}
}
#ifdef VBOX_WITH_WDDM
if (!VBOXSHRC_IS_SHARED_OPENED(This))
#endif
{
{
}
else
{
checkGLcall("glTexImage2D");
}
}
if(enable_client_storage) {
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
}
LEAVE_GL();
}
/* In D3D the depth stencil dimensions have to be greater than or equal to the
* render target dimensions. With FBOs, the dimensions have to be an exact match. */
/* TODO: We should synchronize the renderbuffer's content with the texture's content. */
/* GL locking is done by the caller */
void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height) {
GLuint renderbuffer = 0;
unsigned int src_width, src_height;
/* A depth stencil smaller than the render target is not valid */
/* Remove any renderbuffer set if the sizes match */
{
return;
}
/* Look if we've already got a renderbuffer of the correct dimensions */
break;
}
}
if (!renderbuffer) {
}
checkGLcall("set_compatible_renderbuffer");
}
{
{
return GL_NONE;
}
{
if (swapchain->render_to_fbo)
{
TRACE("Returning GL_COLOR_ATTACHMENT0\n");
return GL_COLOR_ATTACHMENT0;
}
TRACE("Returning GL_BACK\n");
return GL_BACK;
}
{
TRACE("Returning GL_FRONT\n");
return GL_FRONT;
}
FIXME("Higher back buffer, returning GL_BACK\n");
return GL_BACK;
}
#ifdef VBOX_WITH_WDDM
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect);
#endif
/* Slightly inefficient way to handle multiple dirty rects but it works :) */
{
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
if (dirty_rect)
{
}
else
{
}
/* if the container is a basetexture then mark it dirty. */
if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture)))
{
TRACE("Passing to container\n");
}
}
static BOOL surface_convert_color_to_argb(IWineD3DSurfaceImpl *This, DWORD color, DWORD *argb_color)
{
{
case WINED3DFMT_P8_UINT:
{
else
alpha = 0xFF000000;
*argb_color = (alpha |
} else {
*argb_color = alpha;
}
}
break;
case WINED3DFMT_B5G6R5_UNORM:
{
if (color == 0xFFFF) {
*argb_color = 0xFFFFFFFF;
} else {
*argb_color = ((0xFF000000) |
}
}
break;
case WINED3DFMT_B8G8R8_UNORM:
break;
*argb_color = color;
break;
default:
ERR("Unhandled conversion from %s to ARGB!\n", debug_d3dformat(This->resource.format_desc->format));
return FALSE;
}
return TRUE;
}
{
if (!ref)
{
}
return ref;
}
/* ****************************************************
IWineD3DSurface IWineD3DResource parts follow
**************************************************** */
{
/* TODO: check for locks */
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
TRACE("Passing to container\n");
} else {
{
if(palette9_changed(This)) {
TRACE("Reloading surface because the d3d8/9 palette was changed\n");
/* TODO: This is not necessarily needed with hw palettized texture support */
/* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
}
}
/* Tell opengl to try and keep this texture in video ram (well mostly) */
tmp = 0.9f;
ENTER_GL();
LEAVE_GL();
}
}
}
}
/* Context activation is done by the caller. */
{
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
ENTER_GL();
checkGLcall("glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
GL_EXTCALL(glGetBufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0, This->resource.size, This->resource.allocatedMemory));
checkGLcall("glGetBufferSubDataARB");
checkGLcall("glDeleteBuffersARB");
LEAVE_GL();
}
{
{
This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
{
ERR("Out of memory\n");
return FALSE;
}
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
}
else
{
}
return TRUE;
}
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
/* Default pool resources are supposed to be destroyed before Reset is called.
* Implicit resources stay however. So this means we have an implicit render target
* or depth stencil. The content may be destroyed, but we still have to tear down
* opengl resources, so we cannot leave early.
*
* Put the surfaces into sysmem, and reset the content. The D3D content is undefined,
* but we can't set the sysmem INDRAWABLE because when we're rendering the swapchain
* or the depth stencil into an FBO the texture or render buffer will be removed
* and all flags get lost
*/
} else {
/* Load the surface into system memory */
}
/* Destroy PBOs, but load them into real sysmem before */
/* Destroy fbo render buffers. This is needed for implicit render targets, for
* all application-created targets the application has to release the surface
* before calling _Reset
*/
ENTER_GL();
LEAVE_GL();
}
/* If we're in a texture, the texture name belongs to the texture. Otherwise,
* destroy it
*/
if(!texture) {
ENTER_GL();
#ifdef VBOX_WITH_WDDM
if (!VBOXSHRC_IS_SHARED_OPENED(This))
#endif
This->texture_name = 0;
#ifdef VBOX_WITH_WDDM
if (!VBOXSHRC_IS_SHARED_OPENED(This))
#endif
This->texture_name_srgb = 0;
LEAVE_GL();
} else {
}
}
/* ******************************************************
IWineD3DSurface IWineD3DSurface parts follow
****************************************************** */
/* Read the framebuffer back into the surface */
static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, void *dest, UINT pitch)
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
int i;
if(!warned) {
ERR("The application tries to lock the render target, but render target locking is disabled\n");
}
return;
}
/* Activate the surface. Set it up for blitting now, although not necessarily needed for LockRect.
* Certain graphics drivers seem to dislike some enabled states when reading from opengl, the blitting usage
* should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find
* context->last_was_blit set on the unlock.
*/
ENTER_GL();
/* Select the correct read buffer, and give some debug output.
* There is no need to keep track of the current read buffer or reset it, every part of the code
* that reads sets the read buffer as desired.
*/
{
/* Locking the primary render target which is not on a swapchain(=offscreen render target).
* Read from the back buffer
*/
TRACE("Locking offscreen render target\n");
}
else
{
/* Onscreen surfaces are always part of a swapchain */
checkGLcall("glReadBuffer");
}
/* TODO: Get rid of the extra rectangle comparison and construction of a full surface rectangle */
if(!rect) {
local_rect.left = 0;
local_rect.top = 0;
} else {
local_rect = *rect;
}
/* TODO: Get rid of the extra GetPitch call, LockRect does that too. Cache the pitch */
{
case WINED3DFMT_P8_UINT:
{
/* In case of P8 render targets the index is stored in the alpha component */
} else {
/* GL can't return palettized data, so read ARGB pixels into a
* separate block of memory and convert them into palettized format
* in software. Slow, but if the app means to use palettized render
* targets and locks it...
*
* Use GL_RGB, GL_UNSIGNED_BYTE to read the surface for performance reasons
* Don't use GL_BGR as in the WINED3DFMT_R8G8B8 case, instead watch out
* for the color channels when palettizing the colors.
*/
pitch *= 3;
if(!mem) {
ERR("Out of memory\n");
LEAVE_GL();
return;
}
}
}
break;
default:
}
checkGLcall("glBindBufferARB");
ERR("mem not null for pbo -- unexpected\n");
}
}
/* Save old pixel store pack state */
checkGLcall("glGetIntegerv");
checkGLcall("glGetIntegerv");
checkGLcall("glGetIntegerv");
/* Setup pixel store pack state -- to glReadPixels into the correct place */
checkGLcall("glPixelStorei");
checkGLcall("glPixelStorei");
checkGLcall("glPixelStorei");
glReadPixels(local_rect.left, (!srcIsUpsideDown) ? (This->currentDesc.Height - local_rect.bottom) : local_rect.top ,
checkGLcall("glReadPixels");
/* Reset previous pixel store pack state */
checkGLcall("glPixelStorei");
checkGLcall("glPixelStorei");
checkGLcall("glPixelStorei");
checkGLcall("glBindBufferARB");
/* Check if we need to flip the image. If we need to flip use glMapBufferARB
* to get a pointer to it and perform the flipping in software. This is a lot
* faster than calling glReadPixels for each line. In case we want more speed
* we should rerender it flipped in a FBO and read the data back from the FBO. */
if(!srcIsUpsideDown) {
checkGLcall("glBindBufferARB");
checkGLcall("glMapBufferARB");
}
}
/* TODO: Merge this with the palettization loop below for P8 targets */
if(!srcIsUpsideDown) {
/* glReadPixels returns the image upside down, and there is no way to prevent this.
Flip the lines in software */
if(!row) {
ERR("Out of memory\n");
LEAVE_GL();
return;
}
}
/* Unmap the temp PBO buffer */
}
}
LEAVE_GL();
/* For P8 textures we need to perform an inverse palette lookup. This is done by searching for a palette
* index which matches the RGB value. Note this isn't guaranteed to work when there are multiple entries for
* the same color but we have no choice.
* In case of P8 render targets, the index is stored in the alpha component so no conversion is needed.
*/
if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(myDevice))
{
int x, y, c;
} else {
ERR("Palette is missing, cannot perform inverse palette lookup\n");
return ;
}
/* start lines pixels */
for(c = 0; c < 256; c++) {
{
break;
}
}
}
}
}
}
/* Read the framebuffer contents into a texture */
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
/* Activate the surface to read from. In some situations it isn't the currently active target(e.g. backbuffer
* locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any
* states in the stateblock, and no driver was found yet that had bugs in that regard.
*/
ENTER_GL();
LEAVE_GL();
/* Select the correct read buffer, and give some debug output.
* There is no need to keep track of the current read buffer or reset it, every part of the code
* that reads sets the read buffer as desired.
*/
{
ENTER_GL();
checkGLcall("glReadBuffer");
LEAVE_GL();
}
else
{
/* Locking the primary render target which is not on a swapchain(=offscreen render target).
* Read from the back buffer
*/
TRACE("Locking offscreen render target\n");
ENTER_GL();
checkGLcall("glReadBuffer");
LEAVE_GL();
}
{
}
ENTER_GL();
/* If !SrcIsUpsideDown we should flip the surface.
* This can be done using glCopyTexSubImage2D but this
* is VERY slow, so don't do that. We should prevent
* this code from getting called in such cases or perhaps
* we can use FBOs */
checkGLcall("glCopyTexSubImage2D");
checkGLcall("glReadBuffer");
LEAVE_GL();
}
/* Context activation is done by the caller. */
void surface_prepare_texture(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info, BOOL srgb)
{
struct wined3d_format_desc desc;
}
{
/* Performance optimization: Count how often a surface is locked, if it is locked regularly do not throw away the system memory copy.
* This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
* changed
*/
/* MAXLOCKCOUNT is defined in wined3d_private.h */
TRACE("Surface is locked regularly, not freeing the system memory copy any more\n");
}
}
/* Create a PBO for dynamically locked surfaces but don't do it for converted or non-pow2 surfaces.
* Also don't create a PBO for systemmem surfaces.
*/
{
struct wined3d_context *context;
ENTER_GL();
error = glGetError();
}
checkGLcall("glBindBufferARB");
GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->resource.size + 4, This->resource.allocatedMemory, GL_STREAM_DRAW_ARB));
checkGLcall("glBufferDataARB");
checkGLcall("glBindBufferARB");
/* We don't need the system memory anymore and we can't even use it for PBOs */
}
LEAVE_GL();
}
{
/* Whatever surface we have, make sure that there is memory allocated for the downloaded copy,
* or a pbo to map
*/
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
}
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
ERR("Surface without memory or pbo has SFLAG_INSYSMEM set!\n");
}
}
}
static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory);
/* This is also done in the base class, but we have to verify this before loading any data from
* gl into the sysmem copy. The PBO may be mapped, a different rectangle locked, the discard flag
* may interfere, and all other bad things may happen
*/
WARN("Surface is already locked, returning D3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
#ifdef VBOX_WITH_WDDM
#endif
{
}
if (Flags & WINED3DLOCK_DISCARD) {
/* Set SFLAG_INSYSMEM, so we'll never try to download the data from the texture. */
TRACE("WINED3DLOCK_DISCARD flag passed, marking local copy as up to date\n");
goto lock_end;
}
TRACE("Local copy is up to date, not downloading data\n");
goto lock_end;
}
/* IWineD3DSurface_LoadLocation() does not check if the rectangle specifies
* the full surface. Most callers don't need that, so do it here. */
{
}
{
}
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
ENTER_GL();
checkGLcall("glBindBufferARB");
/* This shouldn't happen but could occur if some other function didn't handle the PBO properly */
ERR("The surface already has PBO memory allocated!\n");
}
This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
checkGLcall("glMapBufferARB");
/* Make sure the pbo isn't set anymore in order not to break non-pbo calls */
checkGLcall("glBindBufferARB");
LEAVE_GL();
}
/* Don't dirtify */
} else {
/**
* Dirtify on lock
* as seen in msdn docs
*/
/** Dirtify Container if needed */
if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&pBaseTexture))) {
TRACE("Making container dirty\n");
} else {
TRACE("Surface is standalone, no need to dirty the container\n");
}
}
#ifdef VBOX_WITH_WDDM
{
}
/* if lock succeeded, we keep the shrc locked until unlock */
#endif
return hr;
}
static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This, GLenum fmt, GLenum type, UINT bpp, const BYTE *mem) {
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
/* Activate the correct context for the render target */
ENTER_GL();
{
}
else
{
/* Primary offscreen render target */
TRACE("Offscreen render target.\n");
}
checkGLcall("glGetIntegerv");
checkGLcall("glGetIntegerv");
checkGLcall("glPixelZoom");
/* If not fullscreen, we need to skip a number of bytes to find the next row of data */
checkGLcall("glRasterPos3i");
/* Some drivers(radeon dri, others?) don't like exceptions during
* glDrawPixels. If the surface is a DIB section, it might be in GDIMode
* after ReleaseDC. Reading it will cause an exception, which x11drv will
* catch to put the dib section in InSync mode, which leads to a crash
* and a blocked x server on my radeon card.
*
* The following lines read the dib section so it is put in InSync mode
* before glDrawPixels is called and the crash is prevented. There won't
* be any interfering gdi accesses, because UnlockRect is called from
* ReleaseDC, and the app won't use the dc any more afterwards.
*/
}
checkGLcall("glBindBufferARB");
}
/* When the surface is locked we only have to refresh the locked part else we need to update the whole image */
checkGLcall("glDrawPixels");
} else {
checkGLcall("glDrawPixels");
}
checkGLcall("glBindBufferARB");
}
checkGLcall("glPixelZoom");
glRasterPos3iv(&prev_rasterpos[0]);
checkGLcall("glRasterPos3iv");
/* Reset to previous pack row length */
checkGLcall("glPixelStorei(GL_UNPACK_ROW_LENGTH)");
LEAVE_GL();
}
return WINEDDERR_NOTLOCKED;
}
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
TRACE("Freeing PBO memory\n");
ENTER_GL();
checkGLcall("glUnmapBufferARB");
LEAVE_GL();
}
goto unlock_end;
}
if ((This->Flags & SFLAG_SWAPCHAIN) || (myDevice->render_targets && iface == myDevice->render_targets[0]))
{
if(!warned) {
ERR("The application tries to write to the render target, but render target locking is disabled\n");
}
goto unlock_end;
}
fullsurface = TRUE;
} else {
/* TODO: Proper partial rectangle tracking */
fullsurface = FALSE;
}
switch(wined3d_settings.rendertargetlock_mode) {
case RTL_READTEX:
IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* partial texture loading not supported yet */);
/* drop through */
case RTL_READDRAW:
break;
}
if(!fullsurface) {
/* Partial rectangle tracking is not commonly implemented, it is only done for render targets. Overwrite
* the flags to bring them back into a sane state. INSYSMEM was set before to tell LoadLocation where
* to read the rectangle from. Indrawable is set because all modifications from the partial sysmem copy
* are written back to the drawable, thus the surface is merged again in the drawable. The sysmem copy is
* not fully up to date because only a subrectangle was read in LockRect.
*/
}
FIXME("Depth Stencil buffer locking is not implemented\n");
} else {
/* The rest should be a normal texture */
/* Check if the texture is bound, if yes dirtify the sampler to force a re-upload of the texture
* Can't load the texture here because PreLoad may destroy and recreate the gl texture, so sampler
* states need resetting
*/
}
}
}
/* Overlays have to be redrawn manually after changes with the GL implementation */
if(This->overlay_dest) {
}
#ifdef VBOX_WITH_WDDM
#endif
return WINED3D_OK;
}
{
struct wined3d_context *context;
ENTER_GL();
#ifdef VBOX_WITH_WDDM
if (!VBOXSHRC_IS_SHARED_OPENED(This))
#endif
{
if(This->texture_name)
{
}
if(This->texture_name_srgb)
{
}
}
LEAVE_GL();
}
{
ERR("Not supported on surfaces with an application-provided surfaces\n");
return WINEDDERR_NODC;
}
/* Give more detailed info for ddraw */
return WINEDDERR_DCALREADYCREATED;
/* Can't GetDC if the surface is locked */
return WINED3DERR_INVALIDCALL;
/* Create a DIB section if there isn't a hdc yet */
}
/* Use the dib section from now on if we are not using a PBO */
}
/* Lock the surface */
&lock,
NULL,
0);
/* Sync the DIB with the PBO. This can't be done earlier because LockRect activates the allocatedMemory */
}
/* keep the dib section */
return hr;
}
{
/* GetDC on palettized formats is unsupported in D3D9, and the method is missing in
D3D8, so this should only be used for DX <=7 surfaces (with non-device palettes) */
unsigned int n;
} else {
#ifdef VBOX_WITH_WDDM
/* tmp work-around */
swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[This->resource.device->NumberOfSwapChains-1];
#else
#endif
}
if (pal) {
for (n=0; n<256; n++) {
col[n].rgbReserved = 0;
}
}
}
return WINED3D_OK;
}
{
return WINEDDERR_NODC;
return WINEDDERR_NODC;
}
/* Copy the contents of the DIB over to the PBO */
}
/* we locked first, so unlock now */
return WINED3D_OK;
}
/* ******************************************************
IWineD3DSurface Internal (No mapping to directx api) parts follow
****************************************************** */
HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, struct wined3d_format_desc *desc, CONVERT_TYPES *convert)
{
/* Copy the default values from the surface. Below we might perform fixups */
/* TODO: get rid of color keying desc fixups by using e.g. a table. */
*convert = NO_CONVERSION;
/* Ok, now look if we have to do any conversion */
{
case WINED3DFMT_P8_UINT:
/* ****************
Paletted Texture
**************** */
/* Use conversion when the blit_shader backend supports it. It only supports this in case of
* texturing. Further also use conversion in case of color keying.
* Paletted textures can be emulated using shaders but only do that for 2D purposes e.g. situations
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
* conflicts with this.
*/
if (!((blit_supported && device->render_targets && This == (IWineD3DSurfaceImpl*)device->render_targets[0]))
|| colorkey_active || !use_texturing)
{
if(colorkey_active) {
} else {
}
}
break;
case WINED3DFMT_B2G3R3_UNORM:
/* **********************
GL_UNSIGNED_BYTE_3_3_2
********************** */
if (colorkey_active) {
/* This texture format will never be used.. So do not care about color keying
up until the point in time it will be needed :-) */
FIXME(" ColorKeying not supported in the RGB 332 format !\n");
}
break;
case WINED3DFMT_B5G6R5_UNORM:
if (colorkey_active) {
}
break;
if (colorkey_active) {
}
break;
case WINED3DFMT_B8G8R8_UNORM:
if (colorkey_active) {
}
break;
if (colorkey_active) {
}
break;
default:
break;
}
return WINED3D_OK;
}
{
unsigned int i;
/* Old games like StarCraft, C&C, Red Alert and others use P8 render targets.
* Reading back the RGB output each lockrect (each frame as they lock the whole screen)
* is slow. Further RGB->P8 conversion is not possible because palettes can have
* duplicate entries. Store the color key in the unused alpha component to speed the
* download up and to make conversion unneeded. */
if (!pal)
{
/* In DirectDraw the palette is a property of the surface, there are no such things as device palettes. */
if (dxVersion <= 7)
{
ERR("This code should never get entered for DirectDraw!, expect problems\n");
if (index_in_alpha)
{
/* Guarantees that memory representation remains correct after sysmem<->texture transfers even if
* there's no palette at this time. */
}
}
else
{
/* Direct3D >= 8 palette usage style: P8 textures use device palettes, palette entry format is A8R8G8B8,
* alpha is stored in peFlags and may be used by the app if D3DPTEXTURECAPS_ALPHAPALETTE device
* capability flag is present (wine does advertise this capability) */
for (i = 0; i < 256; ++i)
{
}
}
}
else
{
/* Get the surface's palette */
for (i = 0; i < 256; ++i)
{
/* When index_in_alpha is set the palette index is stored in the
* alpha component. In case of a readback we can then read
* GL_ALPHA. Color keying is handled in BltOverride using a
* GL_ALPHA_TEST using GL_NOT_EQUAL. In case of index_in_alpha the
* color key itself is passed to glAlphaFunc in other cases the
* alpha component of pixels that should be masked away is set to 0. */
if (index_in_alpha)
{
table[i][3] = i;
}
{
}
{
}
else
{
}
}
}
}
{
switch (convert) {
case NO_CONVERSION:
{
break;
}
case CONVERT_PALETTED:
case CONVERT_PALETTED_CK:
{
unsigned int x, y;
/* TODO: If we are a sublevel, try to get the palette from level 0 */
}
for (y = 0; y < height; y++)
{
/* This is an 1 bpp format, using the width here is fine */
for (x = 0; x < width; x++) {
}
}
}
break;
case CONVERT_CK_565:
{
/* Converting the 565 format in 5551 packed to emulate color-keying.
Note : in all these conversion, it would be best to average the averaging
pixels to get the color of the pixel that will be color-keyed to
prevent 'color bleeding'. This will be done later on if ever it is
too visible.
Note2: Nvidia documents say that their driver does not support alpha + color keying
on the same surface and disables color keying in such a case
*/
unsigned int x, y;
TRACE("Color keyed 565\n");
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++ ) {
*Dest |= 0x0001;
}
Dest++;
}
}
}
break;
case CONVERT_CK_5551:
{
/* Converting X1R5G5B5 format to R5G5B5A1 to emulate color-keying. */
unsigned int x, y;
TRACE("Color keyed 5551\n");
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++ ) {
}
else {
}
Dest++;
}
}
}
break;
case CONVERT_CK_RGB24:
{
/* Converting R8G8B8 format to R8G8B8A8 with color-keying. */
unsigned int x, y;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++) {
dstcolor |= 0xff;
}
source += 3;
dest += 4;
}
}
}
break;
case CONVERT_RGB32_888:
{
/* Converting X8R8G8B8 format to R8G8B8A8 with color-keying. */
unsigned int x, y;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++) {
dstcolor |= 0xff;
}
source += 4;
dest += 4;
}
}
}
break;
default:
}
return WINED3D_OK;
}
{
{
/* If a ddraw-style palette is attached assume no d3d9 palette change.
* Also the palette isn't interesting if the surface format isn't P8 or A8P8
*/
return FALSE;
}
{
{
return FALSE;
}
} else {
}
return TRUE;
}
TRACE("Reloading because surface is dirty\n");
} else if(/* Reload: gl texture has ck, now no ckey is set OR */
/* Reload: vice versa OR */
/* Also reload: Color key is active AND the color key has changed */
TRACE("Reloading because of color keying\n");
/* To perform the color key conversion we need a sysmem copy of
* the surface. Make sure we have it
*/
/* Make sure the texture is reloaded because of the color key change, this kills performance though :( */
/* TODO: This is not necessarily needed with hw palettized texture support */
} else {
TRACE("surface is already in texture\n");
return WINED3D_OK;
}
/* Resources are placed in system RAM and do not need to be recreated when a device is lost.
* These resources are not bound by device size or format restrictions. Because of this,
* these resources cannot be accessed by the Direct3D device nor set as textures or render targets.
* However, these resources can always be created, locked, and copied.
*/
{
return WINED3DERR_INVALIDCALL;
}
#if 0
{
static unsigned int gen = 0;
char buffer[4096];
++gen;
if ((gen % 10) == 0) {
}
/*
* debugging crash code
if (gen == 250) {
void** test = NULL;
*test = 0;
}
*/
}
#endif
}
return WINED3D_OK;
}
/* Context activation is done by the caller. */
/* TODO: check for locks */
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
TRACE("Passing to container\n");
}
else
{
ENTER_GL();
if (!This->texture_level)
{
if (!*name) {
#ifdef VBOX_WITH_WDDM
{
}
else
#endif
{
#ifdef VBOX_WITH_WDDM
if (VBOXSHRC_IS_SHARED(This))
{
}
#endif
}
checkGLcall("glGenTextures");
checkGLcall("glBindTexture");
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)");
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
}
/* This is where we should be reducing the amount of GLMemoryUsed */
} else if (*name) {
/* Mipmap surfaces should have a base texture container */
ERR("Mipmap surface has a glTexture bound to it!\n");
}
checkGLcall("glBindTexture");
LEAVE_GL();
}
}
#include <errno.h>
#include <stdio.h>
static HRESULT WINAPI IWineD3DSurfaceImpl_SaveSnapshot(IWineD3DSurface *iface, const char* filename)
{
char *allocatedMemory;
const char *textureRow;
GLuint tmpTexture = 0;
/*FIXME:
Textures may not be stored in ->allocatedgMemory and a GlTexture
so we should lock the surface before saving a snapshot, or at least check that
*/
/* TODO: Compressed texture images can be obtained from the GL in uncompressed form
by calling GetTexImage and in compressed form by calling
GetCompressedTexImageARB. Queried compressed images can be saved and
later reused by calling CompressedTexImage[123]DARB. Pre-compressed
texture images do not need to be processed by the GL and should
significantly improve texture loading performance relative to uncompressed
images. */
/* Setup the width and height to be the internal texture width and height. */
/* check to see if we're a 'virtual' texture, e.g. we're not a pbuffer of texture, we're a back buffer*/
/* if were not a real texture then read the back buffer into a real texture */
/* we don't want to interfere with the back buffer so read the data into a temporary
* texture and then save the data out of the temporary texture
*/
ENTER_GL();
0,
0/*border*/,
NULL);
checkGLcall("glGetIntegerv");
checkGLcall("glReadBuffer");
0,
0,
0,
0);
checkGLcall("glCopyTexImage2D");
LEAVE_GL();
} else { /* bind the real texture, and make sure it up to date */
}
ENTER_GL();
glGetTexImage(GL_TEXTURE_2D, This->texture_level, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, allocatedMemory);
checkGLcall("glGetTexImage");
if (tmpTexture) {
}
LEAVE_GL();
if (NULL == f) {
return WINED3DERR_INVALIDCALL;
}
/* Save the data out to a TGA file because 1: it's an easy raw format, 2: it supports an alpha channel */
TRACE("(%p) opened %s with format %s\n", This, filename, debug_d3dformat(This->resource.format_desc->format));
/* TGA header */
fputc(0,f);
fputc(0,f);
fputc(2,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
fputc(0,f);
/* short width*/
/* short height */
/* format rgba */
fputc(0x20,f);
fputc(0x28,f);
/* raw data */
/* if the data is upside down if we've fetched it from a back buffer, so it needs flipping again to make it the correct way up */
if(swapChain)
else
for (y = 0 ; y < height; y++) {
for (i = 0; i < width; i++) {
textureRow += 4;
}
/* take two rows of the pointer to the texture memory */
if(swapChain)
}
TRACE("Closing file\n");
fclose(f);
if(swapChain) {
}
return WINED3D_OK;
}
TRACE("(%p) : glFormat %d, glFormatInternal %d, glType %d\n", This, This->resource.format_desc->glFormat,
}
return hr;
}
WARN("Surface is locked or the HDC is in use\n");
return WINED3DERR_INVALIDCALL;
}
/* Do I have to copy the old surface content? */
/* Release the DC. No need to hold the critical section for the update
* Thread because this thread runs only on front buffers, but this method
* fails for render targets in the check above.
*/
/* Release the DIB section */
}
/* Now the surface memory is most up do date. Invalidate drawable and texture */
/* For client textures opengl has to be notified */
}
/* Now free the old memory if any */
/* LockRect and GetDC will re-create the dib section and allocated memory */
/* HeapMemory should be NULL already */
}
}
return WINED3D_OK;
}
/* Flip the surface contents */
/* Flip the DC */
{
}
/* Flip the DIBsection */
{
}
/* Flip the surface data */
{
void* tmp;
}
/* Flip the PBO */
{
}
/* client_memory should not be different, but just in case */
{
}
/* Flip the opengl texture */
{
}
{
}
}
static HRESULT WINAPI IWineD3DSurfaceImpl_Flip(IWineD3DSurface *iface, IWineD3DSurface *override, DWORD Flags) {
/* Flipping is only supported on RenderTargets and overlays*/
WARN("Tried to flip a non-render target, non-overlay surface\n");
return WINEDDERR_NOTFLIPPABLE;
}
/* Update the overlay if it is visible */
if(This->overlay_dest) {
} else {
return WINED3D_OK;
}
}
if(override) {
/* DDraw sets this for the X11 surfaces, so don't confuse the user
* FIXME("(%p) Target override is not supported by now\n", This);
* Additionally, it isn't really possible to support triple-buffering
* properly on opengl at all
*/
}
if(!swapchain) {
ERR("Flipped surface is not on a swapchain\n");
return WINEDDERR_NOTFLIPPABLE;
}
/* Just overwrite the swapchain presentation interval. This is ok because only ddraw apps can call Flip,
* and only d3d8 and d3d9 apps specify the presentation interval
*/
if((Flags & (WINEDDFLIP_NOVSYNC | WINEDDFLIP_INTERVAL2 | WINEDDFLIP_INTERVAL3 | WINEDDFLIP_INTERVAL4)) == 0) {
/* Most common case first to avoid wasting time on all the other cases */
} else if(Flags & WINEDDFLIP_NOVSYNC) {
} else if(Flags & WINEDDFLIP_INTERVAL2) {
} else if(Flags & WINEDDFLIP_INTERVAL3) {
} else {
}
/* Flipping a OpenGL surface -> Use WineD3DDevice::Present */
return hr;
}
/* Does a direct frame buffer -> texture copy. Stretching is done
* with single pixel copy calls
*/
static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
{
struct wined3d_context *context;
/* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
* glCopyTexSubImage is a bit picky about the parameters we pass to it
*/
upsidedown = TRUE;
}
ENTER_GL();
/* Bind the target texture */
checkGLcall("glBindTexture");
if(surface_is_offscreen(SrcSurface)) {
TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown;
}
else
{
}
checkGLcall("glReadBuffer");
{
FIXME("Doing a pixel by pixel copy from the framebuffer to a texture, expect major performance issues\n");
ERR("Texture filtering not supported in direct blit\n");
}
}
{
ERR("Texture filtering not supported in direct blit\n");
}
if (upsidedown
{
/* Upside down copy without stretching is nice, one glCopyTexSubImage call will do */
} else {
/* I have to process this row by row to swap the image,
* otherwise it would be upside down, so stretching in y direction
* doesn't cost extra time
*
* However, stretching in x direction can be avoided if not necessary
*/
{
/* No stretching involved, so just pass negative height and let host side take care of inverting */
if (doit)
{
}
}
else
{
{
/* Well, that stuff works, but it's very slow.
* find a better way instead
*/
}
} else {
}
}
}
}
checkGLcall("glCopyTexSubImage2D");
LEAVE_GL();
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
* path is never entered
*/
}
/* Uses the hardware to stretch and flip the image */
static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
{
struct wined3d_context *context;
TRACE("Using hwstretch blit\n");
/* Activate the Proper context for reading from the source surface, set it up for blitting */
{
/* Get it a description */
}
ENTER_GL();
/* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
* This way we don't have to wait for the 2nd readback to finish to leave this function.
*/
{
/* Got more than one aux buffer? Use the 2nd aux buffer */
}
{
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
}
if(noBackBufferBackup) {
checkGLcall("glGenTextures");
checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
} else {
/* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If
* we are reading from the back buffer, the backup can be used as source texture
*/
checkGLcall("glBindTexture(texture_target, Src->texture_name)");
checkGLcall("glEnable(texture_target)");
/* For now invalidate the texture copy of the back buffer. Drawable and sysmem copy are untouched */
}
/* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
* glCopyTexSubImage is a bit picky about the parameters we pass to it
*/
upsidedown = TRUE;
}
if (src_offscreen)
{
TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown;
}
else
{
}
/* TODO: Only back up the part that will be overwritten */
0, 0 /* read offsets */,
0, 0,
fbheight);
checkGLcall("glCopyTexSubImage2D");
/* No issue with overriding these - the sampler is dirty due to blit usage */
checkGLcall("glTexParameteri");
checkGLcall("glTexParameteri");
IWineD3DSurface_GetContainer((IWineD3DSurface *)SrcSurface, &IID_IWineD3DSwapChain, (void **)&src_swapchain);
} else {
checkGLcall("glReadBuffer(GL_FRONT)");
checkGLcall("glGenTextures(1, &src)");
checkGLcall("glBindTexture(GL_TEXTURE_2D, src)");
/* TODO: Only copy the part that will be read. Use src_rect->left, src_rect->bottom as origin, but with the width watch
* out for power of 2 sizes
*/
checkGLcall("glTexImage2D");
0, 0 /* read offsets */,
0, 0,
fbheight);
checkGLcall("glTexParameteri");
checkGLcall("glTexParameteri");
checkGLcall("glReadBuffer(GL_BACK)");
if(texture_target != GL_TEXTURE_2D) {
}
}
checkGLcall("glEnd and previous");
if(upsidedown) {
} else {
}
}
/* draw the source texture stretched and upside down. The correct surface is bound already */
/* bottom left */
glVertex2i(0, fbheight);
/* top left */
/* top right */
/* bottom right */
glEnd();
checkGLcall("glEnd and previous");
{
}
/* Now read the stretched and upside down image into the destination texture */
checkGLcall("glBindTexture");
0,
0, 0, /* We blitted the image to the origin */
checkGLcall("glCopyTexSubImage2D");
if(drawBuffer == GL_BACK) {
/* Write the back buffer backup back */
if(backup) {
if(texture_target != GL_TEXTURE_2D) {
}
checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
} else {
{
}
checkGLcall("glBindTexture(Src->texture_target, Src->texture_name)");
}
/* top left */
glVertex2i(0, 0);
/* bottom left */
glVertex2i(0, fbheight);
/* bottom right */
/* top right */
glVertex2i(fbwidth, 0);
glEnd();
}
checkGLcall("glDisable(texture_target)");
/* Cleanup */
{
checkGLcall("glDeleteTextures(1, &src)");
}
if(backup) {
checkGLcall("glDeleteTextures(1, &backup)");
}
LEAVE_GL();
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
* path is never entered
*/
}
/* Until the blit_shader is ready, define some prototypes here. */
const struct wined3d_format_desc *src_format_desc,
const struct wined3d_format_desc *dst_format_desc);
/* Not called from the VTable */
{
/* Get the swapchain. One of the surfaces has to be a primary surface */
WARN("Destination is in sysmem, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
IWineD3DSurface_GetContainer( (IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&dstSwapchain);
if(Src) {
WARN("Src is in sysmem, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
IWineD3DSurface_GetContainer( (IWineD3DSurface *) Src, &IID_IWineD3DSwapChain, (void **)&srcSwapchain);
}
/* Early sort out of cases where no render target is used */
if(!dstSwapchain && !srcSwapchain &&
SrcSurface != myDevice->render_targets[0] && This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
return WINED3DERR_INVALIDCALL;
}
/* No destination color keying supported */
/* Can we support that with glBlendFunc if blitting to the frame buffer? */
TRACE("Destination color key not supported in accelerated Blit, falling back to software\n");
return WINED3DERR_INVALIDCALL;
}
/* The only case where both surfaces on a swapchain are supported is a back buffer -> front buffer blit on the same swapchain */
((IWineD3DSurface *) This == dstSwapchain->frontBuffer) && SrcSurface == dstSwapchain->backBuffer[0]) {
/* Half-life does a Blt from the back buffer to the front buffer,
* Full surface size, no flags... Use present instead
*
* This path will only be entered for d3d7 and ddraw apps, because d3d8/9 offer no way to blit TO the front buffer
*/
/* Check rects - IWineD3DDevice_Present doesn't handle them */
while(1)
{
TRACE("Looking if a Present can be done...\n");
/* Source Rectangle must be full surface */
TRACE("No, Source rectangle doesn't match\n");
break;
}
/* No stretching may occur */
TRACE("No, stretching is done\n");
break;
}
/* Destination must be full surface or match the clipping rectangle */
{
pos, 2);
{
TRACE("No, dest rectangle doesn't match(clipper)\n");
break;
}
}
else
{
TRACE("No, dest rectangle doesn't match(surface size)\n");
break;
}
}
TRACE("Yes\n");
/* These flags are unimportant for the flag check, remove them */
/* The idea behind this is that a glReadPixels and a glDrawPixels call
* take very long, while a flip is fast.
* This applies to Half-Life, which does such Blts every time it finished
* a frame, and to Prince of Persia 3D, which uses this to draw at least the main
* menu. This is also used by all apps when they do windowed rendering
*
* The problem is that flipping is not really the same as copying. After a
* Blt the front buffer is a copy of the back buffer, and the back buffer is
* untouched. Therefore it's necessary to override the swap effect
* and to set it back after the flip.
*
* Windowed Direct3D < 7 apps do the same. The D3D7 sdk demos are nice
* testcases.
*/
TRACE("Full screen back buffer -> front buffer blt, performing a flip instead\n");
return WINED3D_OK;
}
break;
}
TRACE("Unsupported blit between buffers on the same swapchain\n");
return WINED3DERR_INVALIDCALL;
FIXME("Implement hardware blit between two surfaces on the same swapchain\n");
return WINED3DERR_INVALIDCALL;
} else if(dstSwapchain && srcSwapchain) {
FIXME("Implement hardware blit between two different swapchains\n");
return WINED3DERR_INVALIDCALL;
} else if(dstSwapchain) {
TRACE("Blit from active render target to a swapchain\n");
/* Handled with regular texture -> swapchain blit */
}
FIXME("Implement blit from a swapchain to the active render target\n");
return WINED3DERR_INVALIDCALL;
}
/* Blit from render target to texture */
/* P8 read back is not implemented */
{
TRACE("P8 read back not supported by frame buffer to texture blit\n");
return WINED3DERR_INVALIDCALL;
}
TRACE("Color keying not supported by frame buffer to texture blit\n");
return WINED3DERR_INVALIDCALL;
/* Destination color key is checked above */
}
} else {
}
/* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot
* flip the image nor scale it.
*
* -> If the app asks for a unscaled, upside down copy, just perform one glCopyTexSubImage2D call
* -> If the app wants a image width an unscaled width, copy it line per line
* -> If the app wants a image that is scaled on the x axis, and the destination rectangle is smaller
* than the frame buffer, draw an upside down scaled image onto the fb, read it back and restore the
* back buffer. This is slower than reading line per line, thus not used for flipping
* -> If the app wants a scaled image with a dest rect that is bigger than the fb, it has to be copied
* pixel by pixel
*
* If EXT_framebuffer_blit is supported that can be used instead. Note that EXT_framebuffer_blit implies
* FBO support, so it doesn't really make sense to try and make it work with different offscreen rendering
* backends.
*/
)
)
{
TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
} else {
TRACE("Using hardware stretching to flip / stretch the texture\n");
}
} else {
}
return WINED3D_OK;
} else if(Src) {
/* Blit from offscreen surface to render target */
struct wined3d_context *context;
)
)
{
TRACE("Using stretch_rect_fbo\n");
/* The source is always a texture, but never the currently active render target, and the texture
* contents are never upside down
*/
return WINED3D_OK;
}
{
}
/* Color keying: Check if we have to do a color keyed blt,
* and if not check if a color key is activated.
*
* Just modify the color keying parameters in the surface and restore them afterwards
* The surface keeps track of the color key last used to load the opengl surface.
* PreLoad will catch the change to the flags and color key and reload if necessary.
*/
if(Flags & WINEDDBLT_KEYSRC) {
/* Use color key from surface */
} else if(Flags & WINEDDBLT_KEYSRCOVERRIDE) {
/* Use color key from DDBltFx */
} else {
/* Do not use color key */
}
/* Now load the surface */
/* Activate the destination context, set it up for blitting */
/* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates',
* while OpenGL coordinates are window relative.
* Also beware of the origin difference(top left vs bottom left).
* Also beware that the front buffer's surface size is screen width x screen height,
* whereas the real gl drawable size is the size of the window.
*/
UINT h;
}
{
}
{
FIXME("Unsupported blit operation falling back to software\n");
return WINED3DERR_INVALIDCALL;
}
ENTER_GL();
/* This is for color keying */
checkGLcall("glEnable(GL_ALPHA_TEST)");
/* When the primary render target uses P8, the alpha component contains the palette index.
* Which means that the colorkey is one of the palette entries. In other cases pixels that
* should be masked away have alpha set to 0. */
else
checkGLcall("glAlphaFunc");
} else {
checkGLcall("glDisable(GL_ALPHA_TEST)");
}
/* Draw a textured quad
*/
checkGLcall("glDisable(GL_ALPHA_TEST)");
}
/* Restore the color key parameters */
LEAVE_GL();
/* Leave the opengl state valid for blitting */
#ifdef VBOX_WITH_WDDM
#else
#endif
)))
wglFlush(); /* Flush to ensure ordering across contexts. */
/* TODO: If the surface is locked often, perform the Blt in software on the memory instead */
/* The surface is now in the drawable. On onscreen surfaces or without fbos the texture
* is outdated now
*/
return WINED3D_OK;
} else {
/* Source-Less Blit to render target */
if (Flags & WINEDDBLT_COLORFILL) {
TRACE("Colorfill\n");
/* The color as given in the Blt function is in the format of the frame-buffer...
* 'clear' expect it in ARGB format => we need to do some conversion :-)
*/
{
/* The color conversion function already prints an error, so need to do it here */
return WINED3DERR_INVALIDCALL;
}
{
}
{
}
return WINED3DERR_INVALIDCALL;
}
}
/* Default: Fall back to the generic blt. Not an error, a TRACE is enough */
TRACE("Didn't find any usable render target setup for hw blit, falling back to software\n");
return WINED3DERR_INVALIDCALL;
}
{
float depth;
if (Flags & WINEDDBLT_DEPTHFILL) {
{
case WINED3DFMT_D16_UNORM:
break;
break;
case WINED3DFMT_X8D24_UNORM:
break;
case WINED3DFMT_D32_UNORM:
break;
default:
depth = 0.0f;
}
(const WINED3DRECT *)DestRect,
0x00000000,
0x00000000);
}
return WINED3DERR_INVALIDCALL;
}
#ifdef VBOX_WITH_WDDM
/* Not called from the VTable */
{
struct wined3d_format_desc desc;
WARN("Destination has a SYSMEM location valid, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
WARN("Destination does NOT have a TEXTURE location valid, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
WARN("Source does NOT have a SYSMEM location valid, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
WARN("Src and Dest Formats NOT equal, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
/* No destination color keying supported */
/* Can we support that with glBlendFunc if blitting to the frame buffer? */
TRACE("Destination color key not supported in accelerated Blit, falling back to software\n");
return WINED3DERR_INVALIDCALL;
}
{
WARN("Stretching requested, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
{
WARN("TODO: test if conversion works, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
}
// /* The width is in 'length' not in bytes */
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
* but it isn't set (yet) in all cases it is getting called. */
}
/* This code is entered for texture formats which need a fixup. */
// int width = Src->currentDesc.Width;
// int pitch = IWineD3DSurface_GetPitch(SrcSurface);
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
if(!mem) {
return WINED3DERR_OUTOFVIDEOMEMORY;
}
/* This code is only entered for color keying fixups */
int outpitch;
// int width = Src->currentDesc.Width;
// int pitch = IWineD3DSurface_GetPitch(SrcSurface);
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
if(!mem) {
return WINED3DERR_OUTOFVIDEOMEMORY;
}
d3dfmt_convert_surface(Src->resource.allocatedMemory, mem, srcPitch, srcWidth, srcHeight, outpitch, convert, Src);
} else {
}
/* Make sure the correct pitch is used */
ENTER_GL();
LEAVE_GL();
/* Restore the default pitch */
ENTER_GL();
LEAVE_GL();
/* Don't delete PBO memory */
////
IWineD3DSurface_ModifyLocation((IWineD3DSurface *)This, srgb ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE, TRUE);
return WINED3D_OK;
}
#endif
static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
{
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
return WINEDDERR_SURFACEBUSY;
}
#ifdef VBOX_WITH_WDDM
#endif
/* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair,
* except depth blits, which seem to work
*/
if(iface == myDevice->stencilBufferTarget || (SrcSurface && SrcSurface == myDevice->stencilBufferTarget)) {
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
goto end;
} else if(IWineD3DSurfaceImpl_BltZ(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx) == WINED3D_OK) {
TRACE("Z Blit override handled the blit\n");
hr = WINED3D_OK;
goto end;
}
}
/* Special cases for RenderTargets */
if(IWineD3DSurfaceImpl_BltOverride(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK)
{
hr = WINED3D_OK;
goto end;
}
}
#ifdef VBOX_WITH_WDDM
if (IWineD3DSurfaceImpl_BltSys2Vram(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK)
{
hr = WINED3D_OK;
goto end;
}
#endif
/* For the rest call the X11 surface implementation.
* For RenderTargets this should be implemented OpenGL accelerated in BltOverride,
* other Blts are rather rare
*/
end:
#ifdef VBOX_WITH_WDDM
#endif
return hr;
}
{
{
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
return WINEDDERR_SURFACEBUSY;
}
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
#ifdef VBOX_WITH_WDDM
#endif
/* Special cases for RenderTargets */
/* Convert BltFast flags into Btl ones because it is called from SurfaceImpl_Blt as well */
if(trans & WINEDDBLTFAST_WAIT)
Flags |= WINEDDBLT_WAIT;
if(trans & WINEDDBLTFAST_DONOTWAIT)
if(IWineD3DSurfaceImpl_BltOverride(This, &DstRect, Source, &SrcRect, Flags, NULL, WINED3DTEXF_POINT) == WINED3D_OK)
{
hr = WINED3D_OK;
goto end;
}
}
end:
#ifdef VBOX_WITH_WDDM
#endif
return hr;
}
{
unsigned int n;
if (!pal) return WINED3D_OK;
{
{
/* Make sure the texture is up to date. This call doesn't do anything if the texture is already up to date. */
/* We want to force a palette refresh, so mark the drawable as not being up to date */
} else {
TRACE("Palette changed with surface that does not have an up to date system memory copy\n");
}
TRACE("Dirtifying surface\n");
}
}
for (n=0; n<256; n++) {
col[n].rgbReserved = 0;
}
}
/* Propagate the changes to the drawable when we have a palette. */
return WINED3D_OK;
}
#ifdef VBOX_WITH_WDDM
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect);
#endif
/** Check against the maximum texture sizes supported by the video card **/
unsigned int pow2Width, pow2Height;
This->texture_name = 0;
/* Non-power2 support */
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[WINE_NORMALIZED_TEXRECT])
{
}
else
{
/* Find the nearest pow2 match */
}
/** TODO: add support for non power two compressed textures **/
{
FIXME("(%p) Compressed non-power-two textures are not supported w(%d) h(%d)\n",
return WINED3DERR_NOTAVAILABLE;
}
}
}
if ((This->pow2Width > gl_info->limits.texture_size || This->pow2Height > gl_info->limits.texture_size)
{
/* one of three options
1: Do the same as we do with nonpow 2 and scale the texture, (any texture ops would require the texture to be scaled which is potentially slow)
2: Set the texture to the maximum size (bad idea)
3: WARN and return WINED3DERR_NOTAVAILABLE;
4: Create the surface, but allow it to be used only for DirectDraw Blts. Some apps(e.g. Swat 3) create textures with a Height of 16 and a Width > 3000 and blt 16x16 letter areas from them to the render target.
*/
{
return WINED3DERR_NOTAVAILABLE;
}
/* We should never use this surface in combination with OpenGL! */
}
else
{
/* Don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
is used in combination with texture uploads (RTL_READTEX/RTL_TEXTEX). The reason is that EXT_PALETTED_TEXTURE
doesn't work in combination with ARB_TEXTURE_RECTANGLE.
*/
{
}
}
switch(wined3d_settings.offscreen_rendering_mode) {
}
}
return WINED3D_OK;
}
/* GL locking is done by the caller */
{
GLint old_binding = 0;
glViewport(0, 0, w, h);
glEnd();
glPopAttrib();
}
if (location & ~SFLAG_DS_LOCATIONS) {
}
}
/* Context activation is done by the caller. */
void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location)
{
/* TODO: Make this work for modes other than FBO */
return;
}
if (This->current_renderbuffer) {
return;
}
if (location == SFLAG_DS_OFFSCREEN) {
GLint old_binding = 0;
ENTER_GL();
if (!device->depth_blt_texture) {
}
/* Note that we use depth_blt here as well, rather than glCopyTexImage2D
* directly on the FBO texture. That's because we need to flip. */
{
} else {
}
/* Setup the destination */
if (!device->depth_blt_rb) {
checkGLcall("glGenRenderbuffersEXT");
}
checkGLcall("glBindRenderbufferEXT");
checkGLcall("glRenderbufferStorageEXT");
}
checkGLcall("glFramebufferRenderbufferEXT");
/* Do the actual blit */
checkGLcall("depth_blt");
LEAVE_GL();
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
}
else
{
FIXME("No up to date depth stencil location\n");
}
} else if (location == SFLAG_DS_ONSCREEN) {
ENTER_GL();
checkGLcall("depth_blt");
LEAVE_GL();
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
}
else
{
FIXME("No up to date depth stencil location\n");
}
} else {
}
}
static void WINAPI IWineD3DSurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
if (surface_is_offscreen(iface))
{
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
}
else
{
}
}
if(persistent) {
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
TRACE("Passing to container\n");
}
}
/* Redraw emulated overlays, if any */
}
}
} else {
if((This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))) {
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
TRACE("Passing to container\n");
}
}
}
#ifdef VBOX_WITH_WDDM
if(VBOXSHRC_IS_SHARED_UNLOCKED(This)) {
/* with the shared resource only texture can be considered valid
* to make sure changes done to the resource in the other device context are visible
* because the resource contents is shared via texture.
* This is why we ensure texture location is the one and only which is always valid */
} else {
}
}
#endif
}
}
{
struct wined3d_context *context;
if (context->render_offscreen)
{
}
else
{
}
ENTER_GL();
LEAVE_GL();
#ifdef VBOX_WITH_WDDM
#else
#endif
)))
wglFlush(); /* Flush to ensure ordering across contexts. */
}
/*****************************************************************************
* IWineD3DSurface::LoadLocation
*
* Copies the current surface data from wherever it is to the requested
* location. The location is one of the surface flags, SFLAG_INSYSMEM,
* SFLAG_INTEXTURE and SFLAG_INDRAWABLE. When the surface is current in
* multiple locations, the gl texture is preferred over the drawable, which is
* preferred over system memory. The PBO counts as system memory. If rect is
* not NULL, only the specified rectangle is copied (only supported for
* sysmem<->drawable copies at the moment). If rect is NULL, the destination
* location is marked up to date after the copy.
*
* Parameters:
* flag: Surface location flag to be updated
* rect: rectangle to be copied
*
* Returns:
* WINED3D_OK on success
* WINED3DERR_DEVICELOST on an internal error
*
*****************************************************************************/
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
struct wined3d_format_desc desc;
if (surface_is_offscreen(iface))
{
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets.
* Prefer SFLAG_INTEXTURE. */
}
else
{
}
}
if(rect) {
}
TRACE("Location already up to date\n");
#ifdef VBOX_WITH_WDDM
goto post_process;
#else
return WINED3D_OK;
#endif
}
return WINED3DERR_DEVICELOST;
}
if(flag == SFLAG_INSYSMEM) {
/* Download the surface to system memory */
{
}
else
{
/* Note: It might be faster to download into a texture first. */
}
} else if(flag == SFLAG_INDRAWABLE) {
} else {
int byte_count;
/* This needs a shader to convert the srgb data sampled from the GL texture into RGB
* values, otherwise we get incorrect values in the target. For now go the slow way
* via a system memory copy
*/
}
d3dfmt_get_conv(This, FALSE /* We need color keying */, FALSE /* We won't use textures */, &desc, &convert);
/* The width is in 'length' not in bytes */
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
* but it isn't set (yet) in all cases it is getting called. */
{
}
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
if(!mem) {
return WINED3DERR_OUTOFVIDEOMEMORY;
}
d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
} else {
}
/* Don't delete PBO memory */
}
} else /* if(flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) */ {
}
else
{
/* Upload from system memory */
if(srgb) {
/* Performance warning ... */
}
} else {
/* Performance warning ... */
}
}
/* Should not happen */
ERR("Trying to load a texture from sysmem, but SFLAG_INSYSMEM is not set\n");
/* Lets hope we get it from somewhere... */
}
}
/* The width is in 'length' not in bytes */
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
* but it isn't set (yet) in all cases it is getting called. */
}
/* This code is entered for texture formats which need a fixup. */
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
if(!mem) {
return WINED3DERR_OUTOFVIDEOMEMORY;
}
/* This code is only entered for color keying fixups */
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
if(!mem) {
return WINED3DERR_OUTOFVIDEOMEMORY;
}
d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
} else {
}
/* Make sure the correct pitch is used */
ENTER_GL();
LEAVE_GL();
/* Restore the default pitch */
ENTER_GL();
LEAVE_GL();
/* Don't delete PBO memory */
}
}
#ifdef VBOX_WITH_WDDM
{
/* with the shared resource only texture can be considered valid
* to make sure changes done to the resource in the other device context are visible
* because the resource contents is shared via texture.
* One can load and use other locations as needed,
* but they should be reloaded each time on each usage */
/* @todo: SFLAG_INSRGBTEX ?? */
// if (in_fbo)
// {
// This->Flags |= SFLAG_INDRAWABLE;
// }
}
else
#endif
{
}
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
}
}
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container)
{
/* Update the drawable size method */
if(container) {
}
if(swapchain) {
switch(wined3d_settings.offscreen_rendering_mode) {
}
}
}
return SURFACE_OPENGL;
}
/* If there's no destination surface there is nothing to do */
/* Blt calls ModifyLocation on the dest surface, which in turn calls DrawOverlay to
* update the overlay. Prevent an endless recursion
*/
return WINED3D_OK;
}
return hr;
}
{
/* Not on a swapchain - must be offscreen */
/* The front buffer is always onscreen */
/* If the swapchain is rendered to an FBO, the backbuffer is
* offscreen, otherwise onscreen */
return swapchain->render_to_fbo;
}
{
/* IUnknown */
/* IWineD3DResource */
/* IWineD3DSurface */
/* Internal use: */
};
/* Context activation is done by the caller. */
/* This function is used in case of 8bit paletted textures using GL_EXT_paletted_texture */
/* Context activation is done by the caller. */
static void ffp_blit_p8_upload_palette(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info)
{
TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
ENTER_GL();
GL_EXTCALL(glColorTableEXT(surface->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
LEAVE_GL();
}
/* Context activation is done by the caller. */
{
/* When EXT_PALETTED_TEXTURE is around, palette conversion is done by the GPU
* else the surface is converted in software at upload time in LoadLocation.
*/
ENTER_GL();
checkGLcall("glEnable(surface->texture_target)");
LEAVE_GL();
return WINED3D_OK;
}
/* Context activation is done by the caller. */
{
ENTER_GL();
checkGLcall("glDisable(GL_TEXTURE_2D)");
{
checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
}
{
checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
}
LEAVE_GL();
}
const struct wined3d_format_desc *src_format_desc,
const struct wined3d_format_desc *dst_format_desc)
{
enum complex_fixup src_fixup;
if (blit_op == BLIT_OP_COLOR_FILL)
{
if (!(dst_usage & WINED3DUSAGE_RENDERTARGET))
{
TRACE("Color fill not supported\n");
return FALSE;
}
return TRUE;
}
{
TRACE("Checking support for fixup:\n");
}
if (blit_op != BLIT_OP_BLIT)
{
return FALSE;
}
{
TRACE("Destination fixups are not supported\n");
return FALSE;
}
{
TRACE("P8 fixup supported\n");
return TRUE;
}
/* We only support identity conversions. */
{
TRACE("[OK]\n");
return TRUE;
}
TRACE("[FAILED]\n");
return FALSE;
}
static HRESULT ffp_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color)
{
}
const struct blit_shader ffp_blit = {
};
{
return WINED3D_OK;
}
/* Context activation is done by the caller. */
{
}
/* Context activation is done by the caller. */
{
return WINED3D_OK;
}
/* Context activation is done by the caller. */
{
}
const struct wined3d_format_desc *src_format_desc,
const struct wined3d_format_desc *dst_format_desc)
{
if (blit_op == BLIT_OP_COLOR_FILL)
{
return TRUE;
}
return FALSE;
}
static HRESULT cpu_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color)
{
BltFx.u5.dwFillColor = color_convert_argb_to_fmt(fill_color, dst_surface->resource.format_desc->format);
return IWineD3DBaseSurfaceImpl_Blt((IWineD3DSurface*)dst_surface, dst_rect, NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
}
const struct blit_shader cpu_blit = {
};
const struct wined3d_format_desc *src_format_desc,
const struct wined3d_format_desc *dst_format_desc)
{
return FALSE;
/* We only support blitting. Things like color keying / color fill should
* be handled by other blitters.
*/
if (blit_op != BLIT_OP_BLIT)
return FALSE;
return FALSE;
if(!((src_format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (src_usage & WINED3DUSAGE_RENDERTARGET))
&& ((dst_format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (dst_usage & WINED3DUSAGE_RENDERTARGET)))
return FALSE;
return FALSE;
return FALSE;
return TRUE;
}