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); }
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 HRESULT WINAPI d3d8_texture_cube_GetLevelDesc(IDirect3DCubeTexture8 *iface, UINT level, D3DSURFACE_DESC *desc) { struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface); struct wined3d_resource *sub_resource; HRESULT hr = D3D_OK; TRACE("iface %p, level %u, desc %p.\n", iface, level, desc); wined3d_mutex_lock(); if (level >= wined3d_texture_get_level_count(texture->wined3d_texture)) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { struct wined3d_resource_desc wined3d_desc; wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; } wined3d_mutex_unlock(); return hr; }
static HRESULT STDMETHODCALLTYPE d3d10_texture3d_Map(ID3D10Texture3D *iface, UINT sub_resource_idx, D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE3D *mapped_texture) { struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface); struct wined3d_map_desc wined3d_map_desc; struct wined3d_resource *sub_resource; HRESULT hr; TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n", iface, sub_resource_idx, map_type, map_flags, mapped_texture); if (map_type != D3D10_MAP_READ_WRITE) FIXME("Ignoring map_type %#x.\n", map_type); if (map_flags) FIXME("Ignoring map_flags %#x.\n", map_flags); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) hr = E_INVALIDARG; else if (SUCCEEDED(hr = wined3d_volume_map(wined3d_volume_from_resource(sub_resource), &wined3d_map_desc, NULL, 0))) { mapped_texture->pData = wined3d_map_desc.data; mapped_texture->RowPitch = wined3d_map_desc.row_pitch; mapped_texture->DepthPitch = wined3d_map_desc.slice_pitch; } return hr; }
static HRESULT WINAPI d3d8_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture8 *iface, D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface8 **surface) { struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface); struct wined3d_resource *sub_resource; struct d3d8_surface *surface_impl; UINT sub_resource_idx; DWORD level_count; TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface); wined3d_mutex_lock(); level_count = wined3d_texture_get_level_count(texture->wined3d_texture); if (level >= level_count) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } sub_resource_idx = level_count * face + level; if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } surface_impl = wined3d_resource_get_parent(sub_resource); *surface = &surface_impl->IDirect3DSurface8_iface; IDirect3DSurface8_AddRef(*surface); wined3d_mutex_unlock(); return D3D_OK; }
static HRESULT WINAPI d3d8_texture_cube_LockRect(IDirect3DCubeTexture8 *iface, D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface); struct wined3d_resource *sub_resource; struct d3d8_surface *surface_impl; UINT sub_resource_idx; HRESULT hr; TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n", iface, face, level, locked_rect, rect, flags); wined3d_mutex_lock(); sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level; if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) hr = D3DERR_INVALIDCALL; else { surface_impl = wined3d_resource_get_parent(sub_resource); hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags); } wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetLevelDesc(IDirect3DVolumeTexture8 *iface, UINT level, D3DVOLUME_DESC *desc) { IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *sub_resource; HRESULT hr = D3D_OK; TRACE("iface %p, level %u, desc %p.\n", iface, level, desc); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { struct wined3d_resource_desc wined3d_desc; wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; desc->Depth = wined3d_desc.depth; } wined3d_mutex_unlock(); return hr; }
/* IDirect3DCubeTexture9 Interface follow: */ static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTexture9 *iface, UINT level, D3DSURFACE_DESC *desc) { IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface); struct wined3d_resource *sub_resource; HRESULT hr = D3D_OK; TRACE("iface %p, level %u, desc %p.\n", iface, level, desc); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { struct wined3d_resource_desc wined3d_desc; wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; desc->Usage = wined3d_desc.usage; desc->Pool = wined3d_desc.pool; desc->MultiSampleType = wined3d_desc.multisample_type; desc->MultiSampleQuality = wined3d_desc.multisample_quality; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; } wined3d_mutex_unlock(); return hr; }
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 STDMETHODCALLTYPE d3d10_texture3d_Unmap(ID3D10Texture3D *iface, UINT sub_resource_idx) { struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface); struct wined3d_resource *sub_resource; TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) return; wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource)); }
void * CDECL wined3d_rendertarget_view_get_sub_resource_parent(const struct wined3d_rendertarget_view *view) { struct wined3d_resource *sub_resource; TRACE("view %p.\n", view); if (view->resource->type == WINED3D_RTYPE_BUFFER) return wined3d_buffer_get_parent(buffer_from_resource(view->resource)); if (!(sub_resource = wined3d_texture_get_sub_resource(wined3d_texture_from_resource(view->resource), view->sub_resource_idx))) return NULL; return wined3d_resource_get_parent(sub_resource); }
static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(IDirect3DTexture8 *iface, UINT level) { IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface); struct wined3d_resource *sub_resource; HRESULT hr; TRACE("iface %p, level %u.\n", iface, level); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else hr = IDirect3DSurface8_UnlockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource)); wined3d_mutex_unlock(); return hr; }
HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region) { struct wined3d_resource *sub_resource; TRACE("texture %p, layer %u, dirty_region %p.\n", texture, layer, dirty_region); if (!(sub_resource = wined3d_texture_get_sub_resource(texture, layer * texture->level_count))) { WARN("Failed to get sub-resource.\n"); return WINED3DERR_INVALIDCALL; } texture->texture_ops->texture_sub_resource_add_dirty_region(sub_resource, dirty_region); 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); }
static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(IDirect3DTexture8 *iface, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface); struct wined3d_resource *sub_resource; HRESULT hr; TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n", iface, level, locked_rect, rect, flags); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else hr = IDirect3DSurface8_LockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource), locked_rect, rect, flags); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(IDirect3DCubeTexture9 *iface, D3DCUBEMAP_FACES face, UINT level) { IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface); struct wined3d_resource *sub_resource; UINT sub_resource_idx; HRESULT hr; TRACE("iface %p, face %#x, level %u.\n", iface, face, level); wined3d_mutex_lock(); sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level; if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) hr = D3DERR_INVALIDCALL; else hr = IDirect3DSurface9_UnlockRect((IDirect3DSurface9 *)wined3d_resource_get_parent(sub_resource)); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DVolumeTexture8Impl_LockBox(IDirect3DVolumeTexture8 *iface, UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags) { IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *sub_resource; HRESULT hr; TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n", iface, level, locked_box, box, flags); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else hr = IDirect3DVolume8_LockBox((IDirect3DVolume8 *)wined3d_resource_get_parent(sub_resource), locked_box, box, flags); wined3d_mutex_unlock(); return hr; }
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); }
static HRESULT WINAPI d3d9_texture_3d_UnlockBox(IDirect3DVolumeTexture9 *iface, UINT level) { struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface); struct wined3d_resource *sub_resource; struct d3d9_volume *volume_impl; HRESULT hr; TRACE("iface %p, level %u.\n", iface, level); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { volume_impl = wined3d_resource_get_parent(sub_resource); hr = IDirect3DVolume9_UnlockBox(&volume_impl->IDirect3DVolume9_iface); } wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d8_texture_2d_UnlockRect(IDirect3DTexture8 *iface, UINT level) { struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface); struct wined3d_resource *sub_resource; struct d3d8_surface *surface_impl; HRESULT hr; TRACE("iface %p, level %u.\n", iface, level); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { surface_impl = wined3d_resource_get_parent(sub_resource); hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface); } wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetVolumeLevel(IDirect3DVolumeTexture8 *iface, UINT level, IDirect3DVolume8 **volume) { IDirect3DVolumeTexture8Impl *texture = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *sub_resource; TRACE("iface %p, level %u, volume %p.\n", iface, level, volume); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } *volume = wined3d_resource_get_parent(sub_resource); IDirect3DVolume8_AddRef(*volume); wined3d_mutex_unlock(); return D3D_OK; }
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); }
static HRESULT WINAPI d3d9_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture9 *iface, UINT level, IDirect3DVolume9 **volume) { struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface); struct wined3d_resource *sub_resource; struct d3d9_volume *volume_impl; TRACE("iface %p, level %u, volume %p.\n", iface, level, volume); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } volume_impl = wined3d_resource_get_parent(sub_resource); *volume = &volume_impl->IDirect3DVolume9_iface; IDirect3DVolume9_AddRef(*volume); wined3d_mutex_unlock(); return D3D_OK; }
static HRESULT WINAPI d3d9_texture_2d_LockRect(IDirect3DTexture9 *iface, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface); struct wined3d_resource *sub_resource; struct d3d9_surface *surface_impl; HRESULT hr; TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n", iface, level, locked_rect, rect, flags); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { surface_impl = wined3d_resource_get_parent(sub_resource); hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags); } wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(IDirect3DCubeTexture9 *iface, D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface) { IDirect3DCubeTexture9Impl *texture = impl_from_IDirect3DCubeTexture9(iface); struct wined3d_resource *sub_resource; UINT sub_resource_idx; TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface); wined3d_mutex_lock(); sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level; if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx))) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } *surface = wined3d_resource_get_parent(sub_resource); IDirect3DSurface9_AddRef(*surface); wined3d_mutex_unlock(); return D3D_OK; }
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 HRESULT WINAPI d3d8_texture_2d_GetSurfaceLevel(IDirect3DTexture8 *iface, UINT level, IDirect3DSurface8 **surface) { struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface); struct wined3d_resource *sub_resource; struct d3d8_surface *surface_impl; TRACE("iface %p, level %u, surface %p.\n", iface, level, surface); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) { wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } surface_impl = wined3d_resource_get_parent(sub_resource); *surface = &surface_impl->IDirect3DSurface8_iface; IDirect3DSurface8_AddRef(*surface); wined3d_mutex_unlock(); return D3D_OK; }
static HRESULT WINAPI d3d9_texture_3d_LockBox(IDirect3DVolumeTexture9 *iface, UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags) { struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface); struct wined3d_resource *sub_resource; struct d3d9_volume *volume_impl; HRESULT hr; TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n", iface, level, locked_box, box, flags); wined3d_mutex_lock(); if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level))) hr = D3DERR_INVALIDCALL; else { volume_impl = wined3d_resource_get_parent(sub_resource); hr = IDirect3DVolume9_LockBox(&volume_impl->IDirect3DVolume9_iface, locked_box, box, flags); } wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d9_swapchain_GetBackBuffer(IDirect3DSwapChain9Ex *iface, UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer) { struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface); struct wined3d_resource *wined3d_resource; struct wined3d_texture *wined3d_texture; struct d3d9_surface *surface_impl; HRESULT hr = D3D_OK; TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", iface, backbuffer_idx, backbuffer_type, backbuffer); /* backbuffer_type is ignored by native. */ if (!backbuffer) { WARN("The output pointer is NULL, returning D3DERR_INVALIDCALL.\n"); return D3DERR_INVALIDCALL; } wined3d_mutex_lock(); if ((wined3d_texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, backbuffer_idx))) { wined3d_resource = wined3d_texture_get_sub_resource(wined3d_texture, 0); surface_impl = wined3d_resource_get_parent(wined3d_resource); *backbuffer = &surface_impl->IDirect3DSurface9_iface; IDirect3DSurface9_AddRef(*backbuffer); } else { /* Do not set *backbuffer = NULL, see tests/device.c, test_swapchain(). */ hr = D3DERR_INVALIDCALL; } wined3d_mutex_unlock(); return hr; }
static void wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view, const struct wined3d_rendertarget_view_desc *desc, struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info; view->refcount = 1; view->resource = resource; wined3d_resource_incref(resource); view->parent = parent; view->parent_ops = parent_ops; view->format = wined3d_get_format(gl_info, desc->format_id); view->format_flags = view->format->flags[resource->gl_type]; if (resource->type == WINED3D_RTYPE_BUFFER) { view->sub_resource_idx = 0; view->buffer_offset = desc->u.buffer.start_idx; view->width = desc->u.buffer.count; view->height = 1; view->depth = 1; } else { struct wined3d_texture *texture = wined3d_texture_from_resource(resource); struct wined3d_resource *sub_resource; view->sub_resource_idx = desc->u.texture.layer_idx * texture->level_count + desc->u.texture.level_idx; sub_resource = wined3d_texture_get_sub_resource(texture, view->sub_resource_idx); view->buffer_offset = 0; view->width = sub_resource->width; view->height = sub_resource->height; view->depth = desc->u.texture.layer_count; } }