HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain, struct wined3d_texture *dst_texture, unsigned int sub_resource_idx) { struct wined3d_surface *src_surface, *dst_surface; struct wined3d_resource *sub_resource; RECT src_rect, dst_rect; TRACE("swapchain %p, dst_texture %p, sub_resource_idx %u.\n", swapchain, dst_texture, sub_resource_idx); if (!(sub_resource = wined3d_texture_get_sub_resource(dst_texture, sub_resource_idx)) || sub_resource->type != WINED3D_RTYPE_SURFACE) return WINED3DERR_INVALIDCALL; dst_surface = surface_from_resource(sub_resource); src_surface = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); SetRect(&src_rect, 0, 0, src_surface->resource.width, src_surface->resource.height); dst_rect = src_rect; if (swapchain->desc.windowed) { MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2); FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n", wine_dbgstr_rect(&dst_rect)); } return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT); }
/* Do not call while under the GL lock. */ static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb) { UINT sub_count = texture->level_count * texture->layer_count; struct wined3d_device *device = texture->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_context *context = NULL; struct gl_texture *gl_tex; BOOL srgb_mode; UINT i; TRACE("texture %p, srgb %#x.\n", texture, srgb); srgb_mode = texture_srgb_mode(texture, srgb); gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_mode); if (!device->isInDraw) { /* No danger of recursive calls, context_acquire() sets isInDraw to TRUE * when loading offscreen render targets into the texture. */ context = context_acquire(device, NULL); } if (texture->resource.format->id == WINED3DFMT_P8_UINT || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) { for (i = 0; i < sub_count; ++i) { struct wined3d_surface *surface = surface_from_resource(texture->sub_resources[i]); if (palette9_changed(surface)) { TRACE("Reloading surface %p because the d3d8/9 palette was changed.\n", surface); /* TODO: This is not necessarily needed with hw palettized texture support. */ surface_load_location(surface, SFLAG_INSYSMEM, NULL); /* Make sure the texture is reloaded because of the palette * change, this kills performance though :( */ surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); } } } if (gl_tex->dirty) { /* Reload the surfaces if the texture is marked dirty. */ for (i = 0; i < sub_count; ++i) { surface_load(surface_from_resource(texture->sub_resources[i]), srgb_mode); } } else { TRACE("Texture %p not dirty, nothing to do.\n", texture); } /* No longer dirty. */ gl_tex->dirty = FALSE; if (context) context_release(context); }
static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in, const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags) { struct wined3d_surface *front, *back; front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); back = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0)); /* Flip the DC. */ { HDC tmp; tmp = front->hDC; front->hDC = back->hDC; back->hDC = tmp; } /* Flip the DIBsection. */ { HBITMAP tmp; tmp = front->dib.DIBsection; front->dib.DIBsection = back->dib.DIBsection; back->dib.DIBsection = tmp; } /* Flip the surface data. */ { void *tmp; tmp = front->dib.bitmap_data; front->dib.bitmap_data = back->dib.bitmap_data; back->dib.bitmap_data = tmp; if (front->resource.heap_memory) ERR("GDI Surface %p has heap memory allocated.\n", front); if (back->resource.heap_memory) ERR("GDI Surface %p has heap memory allocated.\n", back); } /* FPS support */ if (TRACE_ON(fps)) { static LONG prev_time, frames; DWORD time = GetTickCount(); ++frames; /* every 1.5 seconds */ if (time - prev_time > 1500) { TRACE_(fps)("@ approx %.2ffps\n", 1000.0 * frames / (time - prev_time)); prev_time = time; frames = 0; } } x11_copy_to_screen(swapchain, NULL); }
static void texture_cleanup(IWineD3DBaseTextureImpl *This) { unsigned int i; TRACE("(%p) : Cleaning up\n", This); for (i = 0; i < This->baseTexture.level_count; ++i) { struct wined3d_resource *sub_resource = This->baseTexture.sub_resources[i]; if (sub_resource) { IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource); /* Clean out the texture name we gave to the surface so that the * surface doesn't try and release it */ surface_set_texture_name(surface, 0, TRUE); surface_set_texture_name(surface, 0, FALSE); surface_set_texture_target(surface, 0); surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL); IWineD3DSurface_Release((IWineD3DSurface *)surface); } } TRACE("(%p) : Cleaning up base texture\n", This); basetexture_cleanup((IWineD3DBaseTextureImpl *)This); }
static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain *swapchain) { struct wined3d_context **newArray; struct wined3d_context *ctx; TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain, GetCurrentThreadId()); if (!(ctx = context_create(swapchain, surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)), swapchain->ds_format))) { ERR("Failed to create a new context for the swapchain\n"); return NULL; } context_release(ctx); newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * (swapchain->num_contexts + 1)); if(!newArray) { ERR("Out of memory when trying to allocate a new context array\n"); context_destroy(swapchain->device, ctx); return NULL; } memcpy(newArray, swapchain->context, sizeof(*newArray) * swapchain->num_contexts); HeapFree(GetProcessHeap(), 0, swapchain->context); newArray[swapchain->num_contexts] = ctx; swapchain->context = newArray; swapchain->num_contexts++; TRACE("Returning context %p\n", ctx); return ctx; }
static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource) { struct wined3d_surface *surface = surface_from_resource(sub_resource); surface_set_texture_target(surface, 0, 0); surface_set_container(surface, NULL); wined3d_surface_decref(surface); }
static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, const struct wined3d_box *dirty_region) { struct wined3d_surface *surface = surface_from_resource(sub_resource); surface_prepare_map_memory(surface); surface_load_location(surface, surface->resource.map_binding); surface_invalidate_location(surface, ~surface->resource.map_binding); }
/* Context activation is done by the caller. */ static HRESULT texture2d_bind(struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info, BOOL srgb) { BOOL set_gl_texture_desc; HRESULT hr; TRACE("texture %p, gl_info %p, srgb %#x.\n", texture, gl_info, srgb); hr = wined3d_texture_bind(texture, gl_info, srgb, &set_gl_texture_desc); if (set_gl_texture_desc && SUCCEEDED(hr)) { UINT sub_count = texture->level_count * texture->layer_count; BOOL srgb_tex = !gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && (texture->flags & WINED3D_TEXTURE_IS_SRGB); struct gl_texture *gl_tex; UINT i; gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_tex); for (i = 0; i < sub_count; ++i) { struct wined3d_surface *surface = surface_from_resource(texture->sub_resources[i]); surface_set_texture_name(surface, gl_tex->name, srgb_tex); } /* Conditinal non power of two textures use a different clamping * default. If we're using the GL_WINE_normalized_texrect partial * driver emulation, we're dealing with a GL_TEXTURE_2D texture which * has the address mode set to repeat - something that prevents us * from hitting the accelerated codepath. Thus manually set the GL * state. The same applies to filtering. Even if the texture has only * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW * fallback on macos. */ if (texture->flags & WINED3D_TEXTURE_COND_NP2) { GLenum target = texture->target; ENTER_GL(); glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)"); glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)"); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); checkGLcall("glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)"); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); checkGLcall("glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)"); LEAVE_GL(); gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP; gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP; gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT; gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE; } } return hr; }
static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, const struct wined3d_box *dirty_region) { struct wined3d_surface *surface = surface_from_resource(sub_resource); struct wined3d_context *context; context = context_acquire(surface->resource.device, NULL); wined3d_resource_prepare_map_memory(&surface->resource, context); wined3d_resource_load_location(&surface->resource, context, surface->resource.map_binding); context_release(context); wined3d_resource_invalidate_location(&surface->resource, ~surface->resource.map_binding); }
static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource) { struct wined3d_surface *surface = surface_from_resource(sub_resource); /* Clean out the texture name we gave to the surface so that the * surface doesn't try and release it. */ surface_set_texture_name(surface, 0, TRUE); surface_set_texture_name(surface, 0, FALSE); surface_set_texture_target(surface, 0, 0); surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL); wined3d_surface_decref(surface); }
HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette, DWORD flags, DWORD start, DWORD count, const PALETTEENTRY *entries) { struct wined3d_resource *resource; TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n", palette, flags, start, count, entries); TRACE("Palette flags: %#x.\n", palette->flags); if (palette->flags & WINEDDPCAPS_8BITENTRIES) { const BYTE *entry = (const BYTE *)entries; unsigned int i; for (i = start; i < count + start; ++i) palette->palents[i].peRed = *entry++; } else { memcpy(palette->palents + start, entries, count * sizeof(*palette->palents)); /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */ if (!(palette->flags & WINEDDPCAPS_ALLOW256)) { TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n"); palette->palents[0].peRed = 0; palette->palents[0].peGreen = 0; palette->palents[0].peBlue = 0; palette->palents[255].peRed = 255; palette->palents[255].peGreen = 255; palette->palents[255].peBlue = 255; } if (palette->hpal) SetPaletteEntries(palette->hpal, start, count, palette->palents + start); } /* If the palette is attached to the render target, update all render targets */ LIST_FOR_EACH_ENTRY(resource, &palette->device->resources, struct wined3d_resource, resource_list_entry) { if (resource->type == WINED3D_RTYPE_SURFACE) { struct wined3d_surface *surface = surface_from_resource(resource); if (surface->palette == palette) surface->surface_ops->surface_realize_palette(surface); } } return WINED3D_OK; }
/* Helper function that blits the front buffer contents to the target window. */ void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect) { struct wined3d_surface *front; POINT offset = {0, 0}; HDC src_dc, dst_dc; RECT draw_rect; HWND window; TRACE("swapchain %p, rect %s.\n", swapchain, wine_dbgstr_rect(rect)); front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); if (swapchain->palette) wined3d_palette_apply_to_dc(swapchain->palette, front->hDC); if (front->resource.map_count) ERR("Trying to blit a mapped surface.\n"); TRACE("Copying surface %p to screen.\n", front); surface_load_location(front, NULL, WINED3D_LOCATION_DIB); src_dc = front->hDC; window = swapchain->win_handle; dst_dc = GetDCEx(window, 0, DCX_CLIPSIBLINGS | DCX_CACHE); /* Front buffer coordinates are screen coordinates. Map them to the * destination window if not fullscreened. */ if (swapchain->desc.windowed) ClientToScreen(window, &offset); TRACE("offset %s.\n", wine_dbgstr_point(&offset)); draw_rect.left = 0; draw_rect.right = front->resource.width; draw_rect.top = 0; draw_rect.bottom = front->resource.height; if (rect) IntersectRect(&draw_rect, &draw_rect, rect); BitBlt(dst_dc, draw_rect.left - offset.x, draw_rect.top - offset.y, draw_rect.right - draw_rect.left, draw_rect.bottom - draw_rect.top, src_dc, draw_rect.left, draw_rect.top, SRCCOPY); ReleaseDC(window, dst_dc); }
/* Do not call while under the GL lock. */ static void texture_unload(struct wined3d_resource *resource) { IWineD3DBaseTextureImpl *texture = basetexture_from_resource(resource); unsigned int i; TRACE("texture %p.\n", texture); for (i = 0; i < texture->baseTexture.level_count; ++i) { struct wined3d_resource *sub_resource = texture->baseTexture.sub_resources[i]; IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource); sub_resource->resource_ops->resource_unload(sub_resource); surface_set_texture_name(surface, 0, FALSE); /* Delete rgb name */ surface_set_texture_name(surface, 0, TRUE); /* delete srgb name */ } basetexture_unload(texture); }
static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRegion(IWineD3DBaseTexture *iface, UINT layer, const WINED3DBOX *dirty_region) { IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface; struct wined3d_resource *sub_resource; TRACE("iface %p, layer %u, dirty_region %p.\n", iface, layer, dirty_region); if (!(sub_resource = basetexture_get_sub_resource(texture, layer * texture->baseTexture.level_count))) { WARN("Failed to get sub-resource.\n"); return WINED3DERR_INVALIDCALL; } basetexture_set_dirty(texture, TRUE); surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region); return WINED3D_OK; }
/* Do not call while under the GL lock. */ static void texture2d_unload(struct wined3d_resource *resource) { struct wined3d_texture *texture = wined3d_texture_from_resource(resource); UINT sub_count = texture->level_count * texture->layer_count; UINT i; TRACE("texture %p.\n", texture); for (i = 0; i < sub_count; ++i) { struct wined3d_resource *sub_resource = texture->sub_resources[i]; struct wined3d_surface *surface = surface_from_resource(sub_resource); sub_resource->resource_ops->resource_unload(sub_resource); surface_set_texture_name(surface, 0, FALSE); /* Delete RGB name */ surface_set_texture_name(surface, 0, TRUE); /* Delete sRGB name */ } wined3d_texture_unload(texture); }
HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain, struct wined3d_surface *dst_surface) { struct wined3d_surface *src_surface; RECT src_rect, dst_rect; TRACE("swapchain %p, dst_surface %p.\n", swapchain, dst_surface); src_surface = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); SetRect(&src_rect, 0, 0, src_surface->resource.width, src_surface->resource.height); dst_rect = src_rect; if (swapchain->desc.windowed) { MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2); FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n", wine_dbgstr_rect(&dst_rect)); } return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT); }
HRESULT CDECL wined3d_rendertarget_view_create_from_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_rendertarget_view **view) { struct wined3d_resource *sub_resource; TRACE("texture %p, sub_resource_idx %u, parent %p, parent_ops %p, view %p.\n", texture, sub_resource_idx, parent, parent_ops, view); if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx))) return WINED3DERR_INVALIDCALL; if (sub_resource->type != WINED3D_RTYPE_SURFACE) { FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(texture->resource.type)); return WINED3DERR_INVALIDCALL; } return wined3d_rendertarget_view_create_from_surface(surface_from_resource(sub_resource), parent, parent_ops, view); }
/* Do not call while under the GL lock. */ static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb) { UINT sub_count = texture->level_count * texture->layer_count; struct wined3d_device *device = texture->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_context *context = NULL; struct gl_texture *gl_tex; BOOL srgb_mode; UINT i; TRACE("texture %p, srgb %#x.\n", texture, srgb); srgb_mode = texture_srgb_mode(texture, srgb); gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_mode); if (!device->isInDraw) { /* No danger of recursive calls, context_acquire() sets isInDraw to TRUE * when loading offscreen render targets into the texture. */ context = context_acquire(device, NULL); } if (gl_tex->dirty) { /* Reload the surfaces if the texture is marked dirty. */ for (i = 0; i < sub_count; ++i) { surface_load(surface_from_resource(texture->sub_resources[i]), srgb_mode); } } else { TRACE("Texture %p not dirty, nothing to do.\n", texture); } /* No longer dirty. */ gl_tex->dirty = FALSE; if (context) context_release(context); }
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) { struct wined3d_swapchain *swapchain; if (resource->type == WINED3D_RTYPE_SURFACE) resource = &surface_from_resource(resource)->container->resource; /* Only texture resources can be onscreen. */ if (resource->type != WINED3D_RTYPE_TEXTURE) return TRUE; /* Not on a swapchain - must be offscreen */ if (!(swapchain = wined3d_texture_from_resource(resource)->swapchain)) return TRUE; /* The front buffer is always onscreen */ if (resource == &swapchain->front_buffer->resource) return FALSE; /* If the swapchain is rendered to an FBO, the backbuffer is * offscreen, otherwise onscreen */ return swapchain->render_to_fbo; }
struct wined3d_surface * CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain, UINT back_buffer_idx, enum wined3d_backbuffer_type type) { TRACE("swapchain %p, back_buffer_idx %u, type %#x.\n", swapchain, back_buffer_idx, type); /* Return invalid if there is no backbuffer array, otherwise it will * crash when ddraw is used (there swapchain->back_buffers is always * NULL). We need this because this function is called from * stateblock_init_default_state() to get the default scissorrect * dimensions. */ if (!swapchain->back_buffers || back_buffer_idx >= swapchain->desc.backbuffer_count) { WARN("Invalid back buffer index.\n"); /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it * here in wined3d to avoid problems in other libs. */ return NULL; } TRACE("Returning back buffer %p.\n", swapchain->back_buffers[back_buffer_idx]); return surface_from_resource(wined3d_texture_get_sub_resource(swapchain->back_buffers[back_buffer_idx], 0)); }
static void wined3d_resource_sync(struct wined3d_resource *resource) { struct wined3d_resource *real_res = resource; struct wined3d_surface *surface; struct wined3d_volume *volume; switch (resource->type) { case WINED3D_RTYPE_SURFACE: surface = surface_from_resource(resource); if (surface->container) real_res = &surface->container->resource; break; case WINED3D_RTYPE_VOLUME: volume = volume_from_resource(resource); real_res = &volume->container->resource; break; default: break; } wined3d_resource_wait_fence(real_res); }
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); }
static void texture2d_sub_resource_load(struct wined3d_resource *sub_resource, struct wined3d_context *context, BOOL srgb) { surface_load(surface_from_resource(sub_resource), srgb); }
/* Do not call while under the GL lock. */ static void texture_preload(IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb) { IWineD3DDeviceImpl *device = texture->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_context *context = NULL; struct gl_texture *gl_tex; unsigned int i; BOOL srgb_mode; TRACE("texture %p, srgb %#x.\n", texture, srgb); switch (srgb) { case SRGB_RGB: srgb_mode = FALSE; break; case SRGB_BOTH: texture_preload(texture, SRGB_RGB); /* Fallthrough */ case SRGB_SRGB: srgb_mode = TRUE; break; default: srgb_mode = texture->baseTexture.is_srgb; break; } gl_tex = basetexture_get_gl_texture(texture, gl_info, srgb_mode); if (!device->isInDraw) { /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture, * thus no danger of recursive calls. */ context = context_acquire(device, NULL); } if (texture->resource.format->id == WINED3DFMT_P8_UINT || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) { for (i = 0; i < texture->baseTexture.level_count; ++i) { IWineD3DSurfaceImpl *surface = surface_from_resource(texture->baseTexture.sub_resources[i]); if (palette9_changed(surface)) { TRACE("Reloading surface because the d3d8/9 palette was changed.\n"); /* TODO: This is not necessarily needed with hw palettized texture support. */ surface_load_location(surface, SFLAG_INSYSMEM, NULL); /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); } } } /* If the texture is marked dirty or the srgb sampler setting has changed * since the last load then reload the surfaces. */ if (gl_tex->dirty) { for (i = 0; i < texture->baseTexture.level_count; ++i) { surface_load(surface_from_resource(texture->baseTexture.sub_resources[i]), srgb_mode); } } else { TRACE("Texture %p not dirty, nothing to do.\n", texture); } if (context) context_release(context); /* No longer dirty. */ gl_tex->dirty = FALSE; }
static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource) { struct wined3d_surface *surface = surface_from_resource(sub_resource); wined3d_surface_destroy(surface); }
static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, const struct wined3d_box *dirty_region) { surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region); }
static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3d_device *device, struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_adapter *adapter = device->adapter; struct wined3d_resource_desc texture_desc; struct wined3d_surface *front_buffer; BOOL displaymode_set = FALSE; RECT client_rect; HWND window; HRESULT hr; UINT i; if (desc->backbuffer_count > 1) { FIXME("The application requested more than one back buffer, this is not properly supported.\n" "Please configure the application to use double buffering (1 back buffer) if possible.\n"); } if (device->wined3d->flags & WINED3D_NO3D) swapchain->swapchain_ops = &swapchain_gdi_ops; else swapchain->swapchain_ops = &swapchain_gl_ops; window = desc->device_window ? desc->device_window : device->create_parms.focus_window; swapchain->device = device; swapchain->parent = parent; swapchain->parent_ops = parent_ops; swapchain->ref = 1; swapchain->win_handle = window; swapchain->device_window = window; if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &swapchain->original_mode, NULL))) { ERR("Failed to get current display mode, hr %#x.\n", hr); goto err; } GetClientRect(window, &client_rect); if (desc->windowed && (!desc->backbuffer_width || !desc->backbuffer_height || desc->backbuffer_format == WINED3DFMT_UNKNOWN)) { if (!desc->backbuffer_width) { desc->backbuffer_width = client_rect.right; TRACE("Updating width to %u.\n", desc->backbuffer_width); } if (!desc->backbuffer_height) { desc->backbuffer_height = client_rect.bottom; TRACE("Updating height to %u.\n", desc->backbuffer_height); } if (desc->backbuffer_format == WINED3DFMT_UNKNOWN) { desc->backbuffer_format = swapchain->original_mode.format_id; TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->original_mode.format_id)); } } swapchain->desc = *desc; swapchain_update_render_to_fbo(swapchain); TRACE("Creating front buffer.\n"); texture_desc.resource_type = WINED3D_RTYPE_TEXTURE; texture_desc.format = swapchain->desc.backbuffer_format; texture_desc.multisample_type = swapchain->desc.multisample_type; texture_desc.multisample_quality = swapchain->desc.multisample_quality; texture_desc.usage = 0; texture_desc.pool = WINED3D_POOL_DEFAULT; texture_desc.width = swapchain->desc.backbuffer_width; texture_desc.height = swapchain->desc.backbuffer_height; texture_desc.depth = 1; texture_desc.size = 0; if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent, parent, &texture_desc, &swapchain->front_buffer))) { WARN("Failed to create front buffer, hr %#x.\n", hr); goto err; } wined3d_texture_set_swapchain(swapchain->front_buffer, swapchain); front_buffer = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); if (!(device->wined3d->flags & WINED3D_NO3D)) { surface_validate_location(front_buffer, WINED3D_LOCATION_DRAWABLE); surface_invalidate_location(front_buffer, ~WINED3D_LOCATION_DRAWABLE); } /* MSDN says we're only allowed a single fullscreen swapchain per device, * so we should really check to see if there is a fullscreen swapchain * already. Does a single head count as full screen? */ if (!desc->windowed) { /* Change the display settings */ swapchain->d3d_mode.width = desc->backbuffer_width; swapchain->d3d_mode.height = desc->backbuffer_height; swapchain->d3d_mode.format_id = desc->backbuffer_format; swapchain->d3d_mode.refresh_rate = desc->refresh_rate; swapchain->d3d_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN; if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, adapter->ordinal, &swapchain->d3d_mode))) { WARN("Failed to set display mode, hr %#x.\n", hr); goto err; } displaymode_set = TRUE; } if (!(device->wined3d->flags & WINED3D_NO3D)) { static const enum wined3d_format_id formats[] = { WINED3DFMT_D24_UNORM_S8_UINT, WINED3DFMT_D32_UNORM, WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_D16_UNORM, WINED3DFMT_S1_UINT_D15_UNORM }; const struct wined3d_gl_info *gl_info = &adapter->gl_info; swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context)); if (!swapchain->context) { ERR("Failed to create the context array.\n"); hr = E_OUTOFMEMORY; goto err; } swapchain->num_contexts = 1; /* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate. * You are able to add a depth + stencil surface at a later stage when you need it. * In order to support this properly in WineD3D we need the ability to recreate the opengl context and * drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new * context, need torecreate shaders, textures and other resources. * * The context manager already takes care of the state problem and for the other tasks code from Reset * can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now. * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this * issue needs to be fixed. */ for (i = 0; i < (sizeof(formats) / sizeof(*formats)); i++) { swapchain->ds_format = wined3d_get_format(gl_info, formats[i]); swapchain->context[0] = context_create(swapchain, front_buffer, swapchain->ds_format); if (swapchain->context[0]) break; TRACE("Depth stencil format %s is not supported, trying next format\n", debug_d3dformat(formats[i])); } if (!swapchain->context[0]) { WARN("Failed to create context.\n"); hr = WINED3DERR_NOTAVAILABLE; goto err; } if (wined3d_settings.offscreen_rendering_mode != ORM_FBO && (!desc->enable_auto_depth_stencil || swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id)) { FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n"); } context_release(swapchain->context[0]); } if (swapchain->desc.backbuffer_count > 0) { swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->back_buffers) * swapchain->desc.backbuffer_count); if (!swapchain->back_buffers) { ERR("Failed to allocate backbuffer array memory.\n"); hr = E_OUTOFMEMORY; goto err; } texture_desc.usage |= WINED3DUSAGE_RENDERTARGET; for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { TRACE("Creating back buffer %u.\n", i); if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent, parent, &texture_desc, &swapchain->back_buffers[i]))) { WARN("Failed to create back buffer %u, hr %#x.\n", i, hr); swapchain->desc.backbuffer_count = i; goto err; } wined3d_texture_set_swapchain(swapchain->back_buffers[i], swapchain); } } /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */ if (desc->enable_auto_depth_stencil && !(device->wined3d->flags & WINED3D_NO3D)) { TRACE("Creating depth/stencil buffer.\n"); if (!device->auto_depth_stencil_view) { struct wined3d_texture *ds; struct wined3d_rendertarget_view_desc desc; texture_desc.format = swapchain->desc.auto_depth_stencil_format; texture_desc.usage = WINED3DUSAGE_DEPTHSTENCIL; if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent, device->device_parent, &texture_desc, &ds))) { WARN("Failed to create the auto depth/stencil surface, hr %#x.\n", hr); goto err; } desc.format_id = ds->resource.format->id; desc.u.texture.level_idx = 0; desc.u.texture.layer_idx = 0; desc.u.texture.layer_count = 1; hr = wined3d_rendertarget_view_create(&desc, &ds->resource, NULL, &wined3d_null_parent_ops, &device->auto_depth_stencil_view); wined3d_texture_decref(ds); if (FAILED(hr)) { ERR("Failed to create rendertarget view, hr %#x.\n", hr); goto err; } } } wined3d_swapchain_get_gamma_ramp(swapchain, &swapchain->orig_gamma); return WINED3D_OK; err: if (displaymode_set) { if (FAILED(wined3d_set_adapter_display_mode(device->wined3d, adapter->ordinal, &swapchain->original_mode))) ERR("Failed to restore display mode.\n"); ClipCursor(NULL); } if (swapchain->back_buffers) { for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { if (swapchain->back_buffers[i]) { wined3d_texture_set_swapchain(swapchain->back_buffers[i], NULL); wined3d_texture_decref(swapchain->back_buffers[i]); } } HeapFree(GetProcessHeap(), 0, swapchain->back_buffers); } if (swapchain->context) { if (swapchain->context[0]) { context_release(swapchain->context[0]); context_destroy(device, swapchain->context[0]); swapchain->num_contexts = 0; } HeapFree(GetProcessHeap(), 0, swapchain->context); } if (swapchain->front_buffer) { wined3d_texture_set_swapchain(swapchain->front_buffer, NULL); wined3d_texture_decref(swapchain->front_buffer); } return hr; }
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 *depth_stencil) { struct wined3d_surface *back_buffer = swapchain->back_buffers[0]; 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); } 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) { wined3d_resource_load_location(&back_buffer->resource, context, WINED3D_LOCATION_TEXTURE_RGB); wined3d_resource_invalidate_location(&back_buffer->resource, WINED3D_LOCATION_DRAWABLE); swapchain->render_to_fbo = TRUE; swapchain_update_draw_bindings(swapchain); } else { wined3d_resource_load_location(&back_buffer->resource, context, 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 && !wined3d_settings.cs_multithreaded) gl_info->gl_ops.gl.p_glFlush(); /* 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; } } wined3d_resource_validate_location(&swapchain->front_buffer->resource, WINED3D_LOCATION_DRAWABLE); wined3d_resource_invalidate_location(&swapchain->front_buffer->resource, ~WINED3D_LOCATION_DRAWABLE); switch (swapchain->desc.swap_effect) { case WINED3D_SWAP_EFFECT_DISCARD: wined3d_resource_validate_location(&back_buffer->resource, WINED3D_LOCATION_DISCARDED); break; case WINED3D_SWAP_EFFECT_FLIP: wined3d_resource_validate_location(&back_buffer->resource, back_buffer->draw_binding); wined3d_resource_invalidate_location(&back_buffer->resource, ~back_buffer->draw_binding); break; default: break; } if (depth_stencil) { if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || depth_stencil->flags & SFLAG_DISCARD) { surface_modify_ds_location(depth_stencil, WINED3D_LOCATION_DISCARDED, depth_stencil->resource.width, depth_stencil->resource.height); if (depth_stencil == swapchain->device->cs->onscreen_depth_stencil) { wined3d_surface_decref(swapchain->device->cs->onscreen_depth_stencil); swapchain->device->cs->onscreen_depth_stencil = NULL; } } } context_release(context); }
/* A GL context is provided by the caller */ static void swapchain_blit(const struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect) { struct wined3d_surface *backbuffer = surface_from_resource( wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0)); UINT src_w = src_rect->right - src_rect->left; UINT src_h = src_rect->bottom - src_rect->top; GLenum gl_filter; const struct wined3d_gl_info *gl_info = context->gl_info; RECT win_rect; UINT win_h; TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n", swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect)); if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top) gl_filter = GL_NEAREST; else gl_filter = GL_LINEAR; GetClientRect(swapchain->win_handle, &win_rect); win_h = win_rect.bottom - win_rect.top; if (gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format->color_fixup)) { DWORD location = WINED3D_LOCATION_TEXTURE_RGB; if (backbuffer->resource.multisample_type) { location = WINED3D_LOCATION_RB_RESOLVED; surface_load_location(backbuffer, context, location); } context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, location); gl_info->gl_ops.gl.p_glReadBuffer(GL_COLOR_ATTACHMENT0); context_check_fbo_status(context, GL_READ_FRAMEBUFFER); context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)), NULL, WINED3D_LOCATION_DRAWABLE); context_set_draw_buffer(context, GL_BACK); context_invalidate_state(context, STATE_FRAMEBUFFER); gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); /* Note that the texture is upside down */ gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, dst_rect->left, win_h - dst_rect->top, dst_rect->right, win_h - dst_rect->bottom, GL_COLOR_BUFFER_BIT, gl_filter); checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n"); } else { struct wined3d_device *device = swapchain->device; struct wined3d_context *context2; float tex_left = src_rect->left; float tex_top = src_rect->top; float tex_right = src_rect->right; float tex_bottom = src_rect->bottom; context2 = context_acquire(device, backbuffer); context_apply_blit_state(context2, device); if (backbuffer->container->flags & WINED3D_TEXTURE_NORMALIZED_COORDS) { tex_left /= backbuffer->pow2Width; tex_right /= backbuffer->pow2Width; tex_top /= backbuffer->pow2Height; tex_bottom /= backbuffer->pow2Height; } if (is_complex_fixup(backbuffer->resource.format->color_fixup)) gl_filter = GL_NEAREST; context_apply_fbo_state_blit(context2, GL_FRAMEBUFFER, surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)), NULL, WINED3D_LOCATION_DRAWABLE); context_bind_texture(context2, backbuffer->texture_target, backbuffer->container->texture_rgb.name); /* Set up the texture. The surface is not in a wined3d_texture * container, so there are no D3D texture settings to dirtify. */ device->blitter->set_shader(device->blit_priv, context2, backbuffer, NULL); gl_info->gl_ops.gl.p_glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter); gl_info->gl_ops.gl.p_glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter); context_set_draw_buffer(context, GL_BACK); /* Set the viewport to the destination rectandle, disable any projection * transformation set up by context_apply_blit_state(), and draw a * (-1,-1)-(1,1) quad. * * Back up viewport and matrix to avoid breaking last_was_blit * * Note that context_apply_blit_state() set up viewport and ortho to * match the surface size - we want the GL drawable(=window) size. */ gl_info->gl_ops.gl.p_glPushAttrib(GL_VIEWPORT_BIT); gl_info->gl_ops.gl.p_glViewport(dst_rect->left, win_h - dst_rect->bottom, dst_rect->right, win_h - dst_rect->top); gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION); gl_info->gl_ops.gl.p_glPushMatrix(); gl_info->gl_ops.gl.p_glLoadIdentity(); gl_info->gl_ops.gl.p_glBegin(GL_QUADS); /* bottom left */ gl_info->gl_ops.gl.p_glTexCoord2f(tex_left, tex_bottom); gl_info->gl_ops.gl.p_glVertex2i(-1, -1); /* top left */ gl_info->gl_ops.gl.p_glTexCoord2f(tex_left, tex_top); gl_info->gl_ops.gl.p_glVertex2i(-1, 1); /* top right */ gl_info->gl_ops.gl.p_glTexCoord2f(tex_right, tex_top); gl_info->gl_ops.gl.p_glVertex2i(1, 1); /* bottom right */ gl_info->gl_ops.gl.p_glTexCoord2f(tex_right, tex_bottom); gl_info->gl_ops.gl.p_glVertex2i(1, -1); gl_info->gl_ops.gl.p_glEnd(); gl_info->gl_ops.gl.p_glPopMatrix(); gl_info->gl_ops.gl.p_glPopAttrib(); device->blitter->unset_shader(context->gl_info); checkGLcall("Swapchain present blit(manual)\n"); context_release(context2); } }