Lines Matching refs:This

15  * This library is free software; you can redistribute it and/or
20 * This library is distributed in the hope that it will be useful,
49 void surface_shrc_lock_surf(IWineD3DSurfaceImpl *This)
51 VBOXSHRC_LOCK(This);
54 void surface_shrc_unlock_surf(IWineD3DSurfaceImpl *This)
56 VBOXSHRC_UNLOCK(This);
57 if (VBOXSHRC_IS_LOCKED(This))
61 IWineD3DSurface_LoadLocation((IWineD3DSurface*)This, SFLAG_INTEXTURE, NULL);
64 void surface_shrc_lock(IWineD3DSurfaceImpl *This)
66 if (!VBOXSHRC_IS_SHARED(This))
69 surface_shrc_lock_surf(This);
72 void surface_shrc_unlock(IWineD3DSurfaceImpl *This)
74 if (!VBOXSHRC_IS_SHARED(This))
76 surface_shrc_unlock_surf(This);
80 static void surface_cleanup(IWineD3DSurfaceImpl *This)
82 IWineD3DDeviceImpl *device = This->resource.device;
87 TRACE("(%p) : Cleaning up.\n", This);
100 if (This->texture_name)
103 TRACE("Deleting texture %u.\n", This->texture_name);
104 texture_gl_delete(This, This->texture_name);
107 if (This->Flags & SFLAG_PBO)
110 GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
113 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry)
121 if (This->Flags & SFLAG_DIBSECTION)
124 SelectObject(This->hDC, This->dib.holdbitmap);
125 DeleteDC(This->hDC);
127 DeleteObject(This->dib.DIBsection);
128 This->dib.bitmap_data = NULL;
129 This->resource.allocatedMemory = NULL;
132 if (This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
133 if (This->overlay_dest) list_remove(&This->overlay_entry);
135 HeapFree(GetProcessHeap(), 0, This->palette9);
137 resource_cleanup((IWineD3DResource *)This);
317 static inline void surface_get_rect(IWineD3DSurfaceImpl *This, const RECT *rect_in, RECT *rect_out)
325 rect_out->right = This->currentDesc.Width;
326 rect_out->bottom = This->currentDesc.Height;
399 void (*cleanup)(IWineD3DSurfaceImpl *This);
574 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
576 This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
581 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
587 name = &This->texture_name_srgb;
592 name = &This->texture_name;
596 TRACE("(%p) : setting texture name %u\n", This, new_name);
603 if (This->Flags & flag)
606 if (VBOXSHRC_IS_SHARED_OPENED(This))
615 if (VBOXSHRC_IS_SHARED(This))
617 Assert(VBOXSHRC_GET_SHAREHANDLE(This) == NULL
618 || (GLuint)VBOXSHRC_GET_SHAREHANDLE(This) == new_name
620 VBOXSHRC_SET_SHAREHANDLE(This, new_name);
629 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
631 TRACE("(%p) : setting target %#x\n", This, target);
633 if (This->texture_target != target)
637 This->Flags &= ~SFLAG_NORMCOORD;
639 else if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
641 This->Flags |= SFLAG_NORMCOORD;
644 This->texture_target = target;
649 static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This, BOOL srgb) {
657 * from sampler() in state.c. This means we can't touch anything other than
667 active_sampler = This->resource.device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
671 IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(active_sampler));
673 IWineD3DSurface_BindTexture((IWineD3DSurface *)This, srgb);
677 /* This function checks if the primary render target uses the 8bit paletted format. */
689 /* This call just downloads data, the caller is responsible for binding the
692 static void surface_download_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
694 const struct wined3d_format_desc *format_desc = This->resource.format_desc;
697 if (This->Flags & SFLAG_CONVERTED && format_desc->format != WINED3DFMT_P8_UINT)
708 This, This->texture_level, format_desc->glFormat, format_desc->glType,
709 This->resource.allocatedMemory);
711 if (This->Flags & SFLAG_PBO)
713 GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
715 GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target, This->texture_level, NULL));
722 GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target,
723 This->texture_level, This->resource.allocatedMemory));
736 if (format_desc->format == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.device))
742 if (This->Flags & SFLAG_NONPOW2) {
743 unsigned char alignment = This->resource.device->surface_alignment;
744 src_pitch = format_desc->byte_count * This->pow2Width;
745 dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);
747 mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height);
749 mem = This->resource.allocatedMemory;
753 This, This->texture_level, format, type, mem);
755 if(This->Flags & SFLAG_PBO) {
756 GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
759 glGetTexImage(This->texture_target, This->texture_level, format, type, NULL);
765 glGetTexImage(This->texture_target, This->texture_level, format, type, mem);
770 if (This->Flags & SFLAG_NONPOW2) {
825 dst_data = This->resource.allocatedMemory;
826 TRACE("(%p) : Repacking the surface data from pitch %d to pitch %d\n", This, src_pitch, dst_pitch);
827 for (y = 1 ; y < This->currentDesc.Height; y++) {
839 This->Flags |= SFLAG_INSYSMEM;
842 /* This call just uploads data, the caller is responsible for binding the
845 static void surface_upload_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
848 GLsizei width = This->currentDesc.Width;
849 GLsizei height = This->currentDesc.Height;
856 else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
857 && surface_is_offscreen((IWineD3DSurface *)This))
866 TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
867 This, internal, width, height, format_desc->glFormat, format_desc->glType, data);
869 This->texture_target, This->texture_level, This->resource.size);
875 if (This->Flags & SFLAG_PBO)
877 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
880 TRACE("(%p) pbo: %#x, data: %p.\n", This, This->pbo, data);
888 GL_EXTCALL(glCompressedTexSubImage2DARB(This->texture_target, This->texture_level,
889 0, 0, width, height, internal, This->resource.size, data));
896 glTexSubImage2D(This->texture_target, This->texture_level,
901 if (This->Flags & SFLAG_PBO)
911 IWineD3DDeviceImpl *device = This->resource.device;
916 context_surface_update(device->contexts[i], This);
922 static void surface_upload_data_rect(IWineD3DSurfaceImpl *This, IWineD3DSurfaceImpl *Src, const struct wined3d_gl_info *gl_info,
933 else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
934 && surface_is_offscreen((IWineD3DSurface *)This))
943 TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
944 This, internal, width, height, format_desc->glFormat, format_desc->glType, data);
946 This->texture_target, This->texture_level, This->resource.size);
965 GL_EXTCALL(glCompressedTexSubImage2DARB(This->texture_target, This->texture_level,
966 pRect->left, pRect->top, width, height, internal, This->resource.size, data));
973 glTexSubImage2D(This->texture_target, This->texture_level,
988 IWineD3DDeviceImpl *device = This->resource.device;
993 context_surface_update(device->contexts[i], This);
999 /* This call just allocates the texture, the caller is responsible for binding
1002 static void surface_allocate_surface(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
1006 GLsizei width = This->pow2Width;
1007 GLsizei height = This->pow2Height;
1012 if (VBOXSHRC_IS_SHARED_OPENED(This))
1023 else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
1024 && surface_is_offscreen((IWineD3DSurface *)This))
1036 This, This->texture_target, This->texture_level, debug_d3dformat(format_desc->format),
1043 if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
1052 This->Flags &= ~SFLAG_CLIENT;
1055 This->Flags |= SFLAG_CLIENT;
1060 mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
1066 GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
1067 internal, width, height, 0, This->resource.size, mem));
1071 glTexImage2D(This->texture_target, This->texture_level,
1088 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1089 const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
1094 src_width = This->pow2Width;
1095 src_height = This->pow2Height;
1104 This->current_renderbuffer = NULL;
1109 LIST_FOR_EACH_ENTRY(entry, &This->renderbuffers, renderbuffer_entry_t, entry) {
1112 This->current_renderbuffer = entry;
1121 This->resource.format_desc->glInternal, width, height);
1127 list_add_head(&This->renderbuffers, &entry->entry);
1129 This->current_renderbuffer = entry;
1137 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1138 IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->container;
1142 if (!(This->Flags & SFLAG_SWAPCHAIN))
1175 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1178 if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
1185 This->dirtyRect.left = min(This->dirtyRect.left, dirty_rect->left);
1186 This->dirtyRect.top = min(This->dirtyRect.top, dirty_rect->top);
1187 This->dirtyRect.right = max(This->dirtyRect.right, dirty_rect->right);
1188 This->dirtyRect.bottom = max(This->dirtyRect.bottom, dirty_rect->bottom);
1192 This->dirtyRect.left = 0;
1193 This->dirtyRect.top = 0;
1194 This->dirtyRect.right = This->currentDesc.Width;
1195 This->dirtyRect.bottom = This->currentDesc.Height;
1198 TRACE("(%p) : Dirty: yes, Rect:(%d, %d, %d, %d)\n", This, This->dirtyRect.left,
1199 This->dirtyRect.top, This->dirtyRect.right, This->dirtyRect.bottom);
1210 static BOOL surface_convert_color_to_argb(IWineD3DSurfaceImpl *This, DWORD color, DWORD *argb_color)
1212 IWineD3DDeviceImpl *device = This->resource.device;
1214 switch(This->resource.format_desc->format)
1225 if (This->palette) {
1227 (This->palette->palents[color].peRed << 16) |
1228 (This->palette->palents[color].peGreen << 8) |
1229 (This->palette->palents[color].peBlue));
1259 ERR("Unhandled conversion from %s to ARGB!\n", debug_d3dformat(This->resource.format_desc->format));
1267 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1268 ULONG ref = InterlockedDecrement(&This->resource.ref);
1269 TRACE("(%p) : Releasing from %d\n", This, ref + 1);
1274 IWineD3DDeviceImpl *device = This->resource.device;
1278 surface_cleanup(This);
1279 This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
1286 if (context->current_rt == (IWineD3DSurface*)This)
1293 TRACE("(%p) Released.\n", This);
1294 HeapFree(GetProcessHeap(), 0, This);
1307 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1308 IWineD3DDeviceImpl *device = This->resource.device;
1311 TRACE("(%p)Checking to see if the container is a base texture\n", This);
1320 TRACE("(%p) : About to load surface\n", This);
1324 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
1325 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
1327 if(palette9_changed(This)) {
1329 /* TODO: This is not necessarily needed with hw palettized texture support */
1338 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
1344 glPrioritizeTextures(1, &This->texture_name, &tmp);
1361 static void surface_remove_pbo(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
1363 This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
1364 This->resource.allocatedMemory =
1365 (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
1368 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
1369 checkGLcall("glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
1370 GL_EXTCALL(glGetBufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0, This->resource.size, This->resource.allocatedMemory));
1372 GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
1376 This->pbo = 0;
1377 This->Flags &= ~SFLAG_PBO;
1382 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
1384 if(!This->resource.allocatedMemory)
1386 This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
1387 if(!This->resource.heapMemory)
1392 This->resource.allocatedMemory =
1393 (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
1397 memset(This->resource.allocatedMemory, 0, This->resource.size);
1406 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
1407 IWineD3DDeviceImpl *device = This->resource.device;
1414 if(This->resource.pool == WINED3DPOOL_DEFAULT) {
1433 This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
1439 if (This->Flags & SFLAG_PBO)
1440 surface_remove_pbo(This, gl_info);
1442 /* Destroy fbo render buffers. This is needed for implicit render targets, for
1446 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
1453 list_init(&This->renderbuffers);
1454 This->current_renderbuffer = NULL;
1462 texture_gl_delete(This, This->texture_name);
1463 texture_gl_delete(This, This->texture_name_srgb);
1464 This->texture_name = 0;
1465 This->texture_name_srgb = 0;
1479 static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, void *dest, UINT pitch)
1481 IWineD3DDeviceImpl *myDevice = This->resource.device;
1510 context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
1519 if (surface_is_offscreen((IWineD3DSurface *) This))
1531 GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
1542 local_rect.right = This->currentDesc.Width;
1543 local_rect.bottom = This->currentDesc.Height;
1549 switch(This->resource.format_desc->format)
1558 bpp = This->resource.format_desc->byte_count;
1572 mem = HeapAlloc(GetProcessHeap(), 0, This->resource.size * 3);
1578 bpp = This->resource.format_desc->byte_count * 3;
1585 fmt = This->resource.format_desc->glFormat;
1586 type = This->resource.format_desc->glType;
1587 bpp = This->resource.format_desc->byte_count;
1590 if(This->Flags & SFLAG_PBO) {
1591 GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
1608 glPixelStorei(GL_PACK_ROW_LENGTH, This->currentDesc.Width);
1615 glReadPixels(local_rect.left, (!srcIsUpsideDown) ? (This->currentDesc.Height - local_rect.bottom) : local_rect.top ,
1629 if(This->Flags & SFLAG_PBO) {
1634 * to get a pointer to it and perform the flipping in software. This is a lot
1638 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
1657 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT) HeapFree(GetProcessHeap(), 0, mem);
1674 if(This->Flags & SFLAG_PBO) {
1683 /* For P8 textures we need to perform an inverse palette lookup. This is done by searching for a palette
1688 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(myDevice))
1694 if(This->palette) {
1695 pal = This->palette->palents;
1725 static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This, BOOL srgb)
1727 IWineD3DDeviceImpl *device = This->resource.device;
1737 context = context_acquire(device, (IWineD3DSurface *) This, CTXUSAGE_RESOURCELOAD);
1740 surface_bind_and_dirtify(This, srgb);
1750 if (!surface_is_offscreen((IWineD3DSurface *)This))
1752 GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
1772 if (!(This->Flags & alloc_flag))
1774 surface_allocate_surface(This, gl_info, This->resource.format_desc, srgb);
1775 This->Flags |= alloc_flag;
1780 * This can be done using glCopyTexSubImage2D but this
1785 glCopyTexSubImage2D(This->texture_target, This->texture_level,
1786 0, 0, 0, 0, This->currentDesc.Width, This->currentDesc.Height);
1796 TRACE("Updated target %d\n", This->texture_target);
1818 void surface_setup_location_onopen(IWineD3DSurfaceImpl *This)
1820 IWineD3DDeviceImpl *device = This->resource.device;
1828 d3dfmt_get_conv(This, TRUE, TRUE, &desc, &convert);
1829 if(convert != NO_CONVERSION) This->Flags |= SFLAG_CONVERTED;
1830 else This->Flags &= ~SFLAG_CONVERTED;
1832 if (IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
1851 GL_EXTCALL(glChromiumParameteriCR(GL_RCUSAGE_TEXTURE_SET_CR, (GLuint)VBOXSHRC_GET_SHAREHANDLE(This)));
1855 This->Flags |= alloc_flag;
1856 This->texture_name = (GLuint)VBOXSHRC_GET_SHAREHANDLE(This);
1858 IWineD3DSurface_ModifyLocation((IWineD3DSurface*)This, SFLAG_INTEXTURE, TRUE);
1862 static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This)
1864 IWineD3DDeviceImpl *device = This->resource.device;
1868 * This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
1871 if(!(This->Flags & SFLAG_DYNLOCK)) {
1872 This->lockCount++;
1874 if(This->lockCount > MAXLOCKCOUNT) {
1876 This->Flags |= SFLAG_DYNLOCK;
1883 if (gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] && (This->Flags & SFLAG_DYNLOCK)
1884 && !(This->Flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2))
1885 && (This->resource.pool != WINED3DPOOL_SYSTEMMEM))
1893 GL_EXTCALL(glGenBuffersARB(1, &This->pbo));
1896 if(This->pbo == 0 || error != GL_NO_ERROR) {
1900 if(This->pbo == 0) {
1906 TRACE("Attaching pbo=%#x to (%p)\n", This->pbo, This);
1908 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
1911 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->resource.size + 4, This->resource.allocatedMemory, GL_STREAM_DRAW_ARB));
1918 if(!(This->Flags & SFLAG_CLIENT)) {
1919 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
1920 This->resource.heapMemory = NULL;
1922 This->resource.allocatedMemory = NULL;
1923 This->Flags |= SFLAG_PBO;
1927 else if (!(This->resource.allocatedMemory || This->Flags & SFLAG_PBO))
1932 if(!This->resource.heapMemory) {
1933 This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
1935 This->resource.allocatedMemory =
1936 (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
1937 if(This->Flags & SFLAG_INSYSMEM) {
1944 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
1945 IWineD3DDeviceImpl *myDevice = This->resource.device;
1949 TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory);
1951 /* This is also done in the base class, but we have to verify this before loading any data from
1955 if (This->Flags & SFLAG_LOCKED) {
1961 surface_shrc_lock(This);
1964 This->Flags |= SFLAG_LOCKED;
1966 if (!(This->Flags & SFLAG_LOCKABLE))
1968 TRACE("Warning: trying to lock unlockable surf@%p\n", This);
1974 surface_prepare_system_memory(This); /* Makes sure memory is allocated */
1975 This->Flags |= SFLAG_INSYSMEM;
1979 if (This->Flags & SFLAG_INSYSMEM) {
1981 surface_prepare_system_memory(This); /* Makes sure memory is allocated */
1988 && pRect->right == This->currentDesc.Width
1989 && pRect->bottom == This->currentDesc.Height)
1995 && ((This->Flags & SFLAG_SWAPCHAIN) || iface == myDevice->render_targets[0])))
2001 if (This->Flags & SFLAG_PBO)
2010 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
2013 /* This shouldn't happen but could occur if some other function didn't handle the PBO properly */
2014 if(This->resource.allocatedMemory) {
2018 This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
2054 surface_shrc_unlock(This);
2061 static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This, GLenum fmt, GLenum type, UINT bpp, const BYTE *mem) {
2065 UINT pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); /* target is argb, 4 byte */
2066 IWineD3DDeviceImpl *myDevice = This->resource.device;
2071 context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
2076 if (!surface_is_offscreen((IWineD3DSurface *)This))
2078 GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
2098 glPixelStorei(GL_UNPACK_ROW_LENGTH, This->currentDesc.Width);
2100 glRasterPos3i(This->lockedRect.left, This->lockedRect.top, 1);
2114 if((This->Flags & SFLAG_DIBSECTION) && !(This->Flags & SFLAG_PBO)) {
2116 read = This->resource.allocatedMemory[0];
2119 if(This->Flags & SFLAG_PBO) {
2120 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
2125 if(This->Flags & SFLAG_LOCKED) {
2126 glDrawPixels(This->lockedRect.right - This->lockedRect.left,
2127 (This->lockedRect.bottom - This->lockedRect.top)-1,
2129 mem + bpp * This->lockedRect.left + pitch * This->lockedRect.top);
2132 glDrawPixels(This->currentDesc.Width,
2133 This->currentDesc.Height,
2138 if(This->Flags & SFLAG_PBO) {
2158 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2159 IWineD3DDeviceImpl *myDevice = This->resource.device;
2162 if (!(This->Flags & SFLAG_LOCKED)) {
2163 WARN("trying to Unlock an unlocked surf@%p\n", This);
2167 if (This->Flags & SFLAG_PBO)
2178 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
2185 This->resource.allocatedMemory = NULL;
2188 TRACE("(%p) : dirtyfied(%d)\n", This, This->Flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE) ? 0 : 1);
2190 if (This->Flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE)) {
2191 TRACE("(%p) : Not Dirtified so nothing to do, return now\n", This);
2195 if ((This->Flags & SFLAG_SWAPCHAIN) || (myDevice->render_targets && iface == myDevice->render_targets[0]))
2206 if(This->dirtyRect.left == 0 &&
2207 This->dirtyRect.top == 0 &&
2208 This->dirtyRect.right == This->currentDesc.Width &&
2209 This->dirtyRect.bottom == This->currentDesc.Height) {
2214 This->Flags |= SFLAG_INSYSMEM;
2223 IWineD3DSurface_LoadLocation(iface, SFLAG_INDRAWABLE, fullsurface ? NULL : &This->dirtyRect);
2234 This->Flags &= ~SFLAG_INSYSMEM;
2235 This->Flags |= SFLAG_INDRAWABLE;
2238 This->dirtyRect.left = This->currentDesc.Width;
2239 This->dirtyRect.top = This->currentDesc.Height;
2240 This->dirtyRect.right = 0;
2241 This->dirtyRect.bottom = 0;
2260 This->Flags &= ~SFLAG_LOCKED;
2261 memset(&This->lockedRect, 0, sizeof(RECT));
2264 if(This->overlay_dest) {
2269 surface_shrc_unlock(This);
2277 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
2281 if (VBOXSHRC_IS_SHARED(This))
2288 context = context_acquire(This->resource.device, NULL, CTXUSAGE_RESOURCELOAD);
2292 if(This->texture_name)
2294 surface_bind_and_dirtify(This, FALSE);
2295 glTexImage2D(This->texture_target, This->texture_level,
2298 if(This->texture_name_srgb)
2300 surface_bind_and_dirtify(This, TRUE);
2301 glTexImage2D(This->texture_target, This->texture_level,
2316 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2321 TRACE("(%p)->(%p)\n",This,pHDC);
2323 if(This->Flags & SFLAG_USERPTR) {
2329 if (This->Flags & SFLAG_DCINUSE)
2333 if (This->Flags & SFLAG_LOCKED)
2339 if(!This->hDC) {
2340 if(This->Flags & SFLAG_CLIENT) {
2348 if(!(This->Flags & SFLAG_PBO))
2349 This->resource.allocatedMemory = This->dib.bitmap_data;
2358 if(This->Flags & SFLAG_PBO) {
2359 /* Sync the DIB with the PBO. This can't be done earlier because LockRect activates the allocatedMemory */
2360 memcpy(This->dib.bitmap_data, This->resource.allocatedMemory, This->dib.bitmap_size);
2369 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
2370 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
2377 if(This->palette) {
2378 pal = This->palette->palents;
2384 swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[This->resource.device->NumberOfSwapChains-1];
2386 swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
2400 SetDIBColorTable(This->hDC, 0, 256, col);
2404 *pHDC = This->hDC;
2406 This->Flags |= SFLAG_DCINUSE;
2413 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2415 TRACE("(%p)->(%p)\n",This,hDC);
2417 if (!(This->Flags & SFLAG_DCINUSE))
2420 if (This->hDC !=hDC) {
2421 WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
2425 if((This->Flags & SFLAG_PBO) && This->resource.allocatedMemory) {
2427 memcpy(This->resource.allocatedMemory, This->dib.bitmap_data, This->dib.bitmap_size);
2433 This->Flags &= ~SFLAG_DCINUSE;
2442 HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, struct wined3d_format_desc *desc, CONVERT_TYPES *convert)
2444 BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
2445 IWineD3DDeviceImpl *device = This->resource.device;
2447 RECT rect = {0, 0, This->pow2Width, This->pow2Height};
2451 *desc = *This->resource.format_desc;
2455 switch(This->resource.format_desc->format)
2463 &rect, This->resource.usage, This->resource.pool,
2464 This->resource.format_desc, &rect, This->resource.usage,
2465 This->resource.pool, This->resource.format_desc);
2473 if (!((blit_supported && device->render_targets && This == (IWineD3DSurfaceImpl*)device->render_targets[0]))
2493 /* This texture format will never be used.. So do not care about color keying
2546 void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
2548 IWineD3DDeviceImpl *device = This->resource.device;
2549 IWineD3DPaletteImpl *pal = This->palette;
2567 ERR("This code should never get entered for DirectDraw!, expect problems\n");
2609 else if (colorkey && (i >= This->SrcBltCKey.dwColorSpaceLowValue)
2610 && (i <= This->SrcBltCKey.dwColorSpaceHighValue))
2627 UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *This)
2631 TRACE("(%p)->(%p),(%d,%d,%d,%d,%p)\n", src, dst, pitch, height, outpitch, convert,This);
2642 IWineD3DPaletteImpl* pal = This->palette;
2650 d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
2656 /* This is an 1 bpp format, using the width here is fine */
2674 prevent 'color bleeding'. This will be done later on if ever it is
2692 if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
2693 (color > This->SrcBltCKey.dwColorSpaceHighValue)) {
2715 if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
2716 (color > This->SrcBltCKey.dwColorSpaceHighValue)) {
2739 if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
2740 (color > This->SrcBltCKey.dwColorSpaceHighValue)) {
2762 if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
2763 (color > This->SrcBltCKey.dwColorSpaceHighValue)) {
2780 BOOL palette9_changed(IWineD3DSurfaceImpl *This)
2782 IWineD3DDeviceImpl *device = This->resource.device;
2784 if (This->palette || (This->resource.format_desc->format != WINED3DFMT_P8_UINT
2785 && This->resource.format_desc->format != WINED3DFMT_P8_UINT_A8_UNORM))
2793 if (This->palette9)
2795 if (!memcmp(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256))
2800 This->palette9 = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
2802 memcpy(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256);
2807 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2810 if (!(This->Flags & flag)) {
2813 ((This->Flags & SFLAG_GLCKEY) && (!(This->CKeyFlags & WINEDDSD_CKSRCBLT))) ||
2815 ((!(This->Flags & SFLAG_GLCKEY)) && (This->CKeyFlags & WINEDDSD_CKSRCBLT)) ||
2817 ((This->CKeyFlags & WINEDDSD_CKSRCBLT) && (
2818 (This->glCKey.dwColorSpaceLowValue != This->SrcBltCKey.dwColorSpaceLowValue) ||
2819 (This->glCKey.dwColorSpaceHighValue != This->SrcBltCKey.dwColorSpaceHighValue)))) {
2827 /* TODO: This is not necessarily needed with hw palettized texture support */
2839 if (This->resource.pool == WINED3DPOOL_SCRATCH )
2841 FIXME("(%p) Operation not supported for scratch textures\n",This);
2854 This, This->texture_target, This->texture_level, gen);
2867 if (!(This->Flags & SFLAG_DONOTFREE) && !This->resource.format_desc->convert) {
2868 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
2869 This->resource.allocatedMemory = NULL;
2870 This->resource.heapMemory = NULL;
2880 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2883 TRACE("(%p)Checking to see if the container is a base texture\n", This);
2893 TRACE("(%p) : Binding surface\n", This);
2895 name = srgb ? &This->texture_name_srgb : &This->texture_name;
2899 if (!This->texture_level)
2903 if (VBOXSHRC_IS_SHARED_OPENED(This))
2905 struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
2907 *name = (GLuint)VBOXSHRC_GET_SHAREHANDLE(This);
2915 TRACE("Surface %p given name %d\n", This, *name);
2917 glBindTexture(This->texture_target, *name);
2919 glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2921 glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2923 glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
2925 glTexParameteri(This->texture_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2927 glTexParameteri(This->texture_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2930 if (VBOXSHRC_IS_SHARED(This))
2932 VBOXSHRC_SET_SHAREHANDLE(This, *name);
2937 /* This is where we should be reducing the amount of GLMemoryUsed */
2943 glBindTexture(This->texture_target, *name);
2955 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
2975 width = This->pow2Width;
2976 height = This->pow2Height;
2980 if (This->Flags & SFLAG_INDRAWABLE && !(This->Flags & SFLAG_INTEXTURE)) {
2987 TRACE("(%p) Reading render target into texture\n", This);
3004 glReadBuffer(swapChain ? GL_BACK : This->resource.device->offscreenBuffer);
3021 surface_bind_and_dirtify(This, FALSE);
3025 FIXME("Saving texture level %d width %d height %d\n", This->texture_level, width, height);
3026 glGetTexImage(GL_TEXTURE_2D, This->texture_level, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, allocatedMemory);
3040 TRACE("(%p) opened %s with format %s\n", This, filename, debug_d3dformat(This->resource.format_desc->format));
3092 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
3095 TRACE("(%p) : Calling base function first\n", This);
3098 This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
3099 TRACE("(%p) : glFormat %d, glFormatInternal %d, glType %d\n", This, This->resource.format_desc->glFormat,
3100 This->resource.format_desc->glInternal, This->resource.format_desc->glType);
3106 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
3108 if(This->Flags & (SFLAG_LOCKED | SFLAG_DCINUSE)) {
3113 if(Mem && Mem != This->resource.allocatedMemory) {
3117 if(This->Flags & SFLAG_DIBSECTION) {
3122 SelectObject(This->hDC, This->dib.holdbitmap);
3123 DeleteDC(This->hDC);
3125 DeleteObject(This->dib.DIBsection);
3126 This->dib.bitmap_data = NULL;
3127 This->resource.allocatedMemory = NULL;
3128 This->hDC = NULL;
3129 This->Flags &= ~SFLAG_DIBSECTION;
3130 } else if(!(This->Flags & SFLAG_USERPTR)) {
3131 release = This->resource.heapMemory;
3132 This->resource.heapMemory = NULL;
3134 This->resource.allocatedMemory = Mem;
3135 This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
3141 if(This->Flags & SFLAG_CLIENT) {
3147 } else if(This->Flags & SFLAG_USERPTR) {
3149 This->resource.allocatedMemory = NULL;
3151 if(This->resource.heapMemory != NULL) ERR("User pointer surface has heap memory allocated\n");
3152 This->Flags &= ~SFLAG_USERPTR;
3154 if(This->Flags & SFLAG_CLIENT) {
3239 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
3242 TRACE("(%p)->(%p,%x)\n", This, override, Flags);
3245 if( !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_OVERLAY)) ) {
3250 if(This->resource.usage & WINED3DUSAGE_OVERLAY) {
3251 flip_surface(This, (IWineD3DSurfaceImpl *) override);
3254 if(This->overlay_dest) {
3255 return IWineD3DSurface_DrawOverlay((IWineD3DSurface *) This);
3263 * FIXME("(%p) Target override is not supported by now\n", This);
3275 /* Just overwrite the swapchain presentation interval. This is ok because only ddraw apps can call Flip,
3302 static inline BOOL fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
3305 IWineD3DDeviceImpl *myDevice = This->resource.device;
3360 surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
3364 glBindTexture(This->texture_target, This->texture_name);
3382 glCopyTexSubImage2D(This->texture_target, This->texture_level,
3399 glCopyTexSubImage2D(This->texture_target, This->texture_level,
3415 glCopyTexSubImage2D(This->texture_target, This->texture_level,
3420 glCopyTexSubImage2D(This->texture_target, This->texture_level,
3435 IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
3441 static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
3444 IWineD3DDeviceImpl *myDevice = This->resource.device;
3462 surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
3473 /* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
3474 * This way we don't have to wait for the 2nd readback to finish to leave this function.
3630 if (texture_target != This->texture_target)
3633 glEnable(This->texture_target);
3634 texture_target = This->texture_target;
3638 glBindTexture(texture_target, This->texture_name);
3709 IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
3720 static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const RECT *DestRect,
3724 IWineD3DDeviceImpl *myDevice = This->resource.device;
3732 TRACE("(%p)->(%p,%p,%p,%08x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
3735 if(This->resource.pool == WINED3DPOOL_SYSTEMMEM) {
3739 IWineD3DSurface_GetContainer( (IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&dstSwapchain);
3752 SrcSurface != myDevice->render_targets[0] && This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
3753 TRACE("No surface is render target, not using hardware blit. Src = %p, dst = %p\n", Src, This);
3768 surface_get_rect(This, DestRect, &dst_rect);
3773 ((IWineD3DSurface *) This == dstSwapchain->frontBuffer) && SrcSurface == dstSwapchain->backBuffer[0]) {
3780 * This path will only be entered for d3d7 and ddraw apps, because d3d8/9 offer no way to blit TO the front buffer
3802 if(This->clipper && ((IWineD3DClipperImpl *) This->clipper)->hWnd)
3806 GetClientRect(((IWineD3DClipperImpl *) This->clipper)->hWnd, &cliprect);
3811 MapWindowPoints(GetDesktopWindow(), ((IWineD3DClipperImpl *) This->clipper)->hWnd,
3826 dst_rect.right != This->currentDesc.Width || dst_rect.bottom != This->currentDesc.Height) {
3840 * This applies to Half-Life, which does such Blts every time it finished
3842 * menu. This is also used by all apps when they do windowed rendering
3880 } else if(srcSwapchain && This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
3895 This->resource.format_desc->format == WINED3DFMT_P8_UINT)
3920 * back buffer. This is slower than reading line per line, thus not used for flipping
3930 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc)
3932 || (dst_rect.right==This->currentDesc.Width && dst_rect.bottom==This->currentDesc.Height
3941 || !fb_copy_to_texture_direct(This, SrcSurface, &src_rect, &dst_rect, Filter, TRUE /* fast only */))
3945 (IWineD3DSurface *)This, &dst_rect, Filter);
3950 fb_copy_to_texture_direct(This, SrcSurface, &src_rect, &dst_rect, Filter, FALSE /* do it always */);
3953 fb_copy_to_texture_hwstretch(This, SrcSurface, &src_rect, &dst_rect, Filter);
3956 if(!(This->Flags & SFLAG_DONOTFREE)) {
3957 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
3958 This->resource.allocatedMemory = NULL;
3959 This->resource.heapMemory = NULL;
3961 This->Flags &= ~SFLAG_INSYSMEM;
3971 TRACE("Blt from surface %p to rendertarget %p\n", Src, This);
3976 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc)
3978 || (dst_rect.right==This->currentDesc.Width && dst_rect.bottom==This->currentDesc.Height
3988 (IWineD3DSurface *)This, &dst_rect, Filter);
3995 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc))
3997 return arbfp_blit_surface(myDevice, Src, &src_rect, This, &dst_rect, BLIT_OP_BLIT, Filter);
4022 context = context_acquire(myDevice, (IWineD3DSurface *)This, CTXUSAGE_BLIT);
4030 if (dstSwapchain && (IWineD3DSurface *)This == dstSwapchain->frontBuffer) {
4046 dst_rect.top += This->currentDesc.Height - h; dst_rect.bottom += This->currentDesc.Height - h;
4049 else if (surface_is_offscreen((IWineD3DSurface *)This))
4051 dst_rect.top = This->currentDesc.Height-dst_rect.top;
4052 dst_rect.bottom = This->currentDesc.Height-dst_rect.bottom;
4057 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc))
4067 /* This is for color keying */
4104 && ((IWineD3DSurface *)This == dstSwapchain->frontBuffer
4119 IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INDRAWABLE, TRUE);
4132 if (!surface_convert_color_to_argb(This, DDBltFx->u5.dwFillColor, &color))
4140 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc))
4142 return ffp_blit.color_fill(myDevice, This, &dst_rect, color);
4146 &dst_rect, This->resource.usage, This->resource.pool, This->resource.format_desc))
4148 return cpu_blit.color_fill(myDevice, This, &dst_rect, color);
4159 static HRESULT IWineD3DSurfaceImpl_BltZ(IWineD3DSurfaceImpl *This, const RECT *DestRect,
4162 IWineD3DDeviceImpl *myDevice = This->resource.device;
4166 switch(This->resource.format_desc->format)
4183 ERR("Unexpected format for depth fill: %s\n", debug_d3dformat(This->resource.format_desc->format));
4195 FIXME("(%p): Unsupp depthstencil blit\n", This);
4201 static HRESULT IWineD3DSurfaceImpl_BltSys2Vram(IWineD3DSurfaceImpl *This, const RECT *DestRect,
4205 IWineD3DDeviceImpl *myDevice = This->resource.device;
4217 TRACE("(%p)->(%p,%p,%p,%08x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
4219 if(This->Flags & SFLAG_INSYSMEM) {
4224 if(!(This->Flags & SFLAG_INTEXTURE)
4225 && !(This->Flags & SFLAG_INSRGBTEX)) {
4230 srgb = !(This->Flags & SFLAG_INTEXTURE);
4237 if(This->resource.format_desc != Src->resource.format_desc) {
4249 surface_get_rect(This, DestRect, &dst_rect);
4281 surface_bind_and_dirtify(This, srgb);
4283 if(This->CKeyFlags & WINEDDSD_CKSRCBLT) {
4284 This->Flags |= SFLAG_GLCKEY;
4285 This->glCKey = This->SrcBltCKey;
4287 else This->Flags &= ~SFLAG_GLCKEY;
4294 /* This code is entered for texture formats which need a fixup. */
4311 /* This code is only entered for color keying fixups */
4341 surface_upload_data_rect(This, Src, gl_info, &desc, srgb, updateMem, &dst_rect);
4356 IWineD3DSurface_ModifyLocation((IWineD3DSurface *)This, srgb ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE, TRUE);
4364 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
4366 IWineD3DDeviceImpl *myDevice = This->resource.device;
4369 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
4370 TRACE("(%p): Usage is %s\n", This, debug_d3dusage(This->resource.usage));
4372 if ( (This->Flags & SFLAG_LOCKED) || ((Src != NULL) && (Src->Flags & SFLAG_LOCKED)))
4379 surface_shrc_lock(This);
4391 } else if(IWineD3DSurfaceImpl_BltZ(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx) == WINED3D_OK) {
4400 if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
4404 if(IWineD3DSurfaceImpl_BltOverride(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK)
4412 if (SrcSurface && IWineD3DSurfaceImpl_BltSys2Vram(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK)
4426 surface_shrc_unlock(This);
4435 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
4437 IWineD3DDeviceImpl *myDevice = This->resource.device;
4442 if ( (This->Flags & SFLAG_LOCKED) || (srcImpl->Flags & SFLAG_LOCKED))
4456 surface_shrc_lock(This);
4461 if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
4484 if(IWineD3DSurfaceImpl_BltOverride(This, &DstRect, Source, &SrcRect, Flags, NULL, WINED3DTEXF_POINT) == WINED3D_OK)
4492 if (IWineD3DSurfaceImpl_BltSys2Vram(This, &DstRect, Source, &SrcRect, Flags, NULL, WINED3DTEXF_POINT) == WINED3D_OK)
4502 surface_shrc_unlock(This);
4510 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
4512 IWineD3DPaletteImpl *pal = This->palette;
4514 TRACE("(%p)\n", This);
4518 if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
4519 || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
4521 if(This->resource.usage & WINED3DUSAGE_RENDERTARGET)
4523 /* Make sure the texture is up to date. This call doesn't do anything if the texture is already up to date. */
4529 if(!(This->Flags & SFLAG_INSYSMEM)) {
4538 if(This->Flags & SFLAG_DIBSECTION) {
4539 TRACE("(%p): Updating the hdc's palette\n", This);
4546 SetDIBColorTable(This->hDC, 0, 256, col);
4550 if(This->resource.usage & WINED3DUSAGE_RENDERTARGET)
4562 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
4563 const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
4566 This->texture_name = 0;
4567 This->texture_target = GL_TEXTURE_2D;
4572 pow2Width = This->currentDesc.Width;
4573 pow2Height = This->currentDesc.Height;
4579 while (pow2Width < This->currentDesc.Width) pow2Width <<= 1;
4580 while (pow2Height < This->currentDesc.Height) pow2Height <<= 1;
4582 This->pow2Width = pow2Width;
4583 This->pow2Height = pow2Height;
4585 if (pow2Width > This->currentDesc.Width || pow2Height > This->currentDesc.Height) {
4587 if (This->resource.format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
4590 This, This->currentDesc.Width, This->currentDesc.Height);
4595 if(pow2Width != This->currentDesc.Width ||
4596 pow2Height != This->currentDesc.Height) {
4597 This->Flags |= SFLAG_NONPOW2;
4600 TRACE("%p\n", This);
4601 if ((This->pow2Width > gl_info->limits.texture_size || This->pow2Height > gl_info->limits.texture_size)
4602 && !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
4610 if(This->resource.pool == WINED3DPOOL_DEFAULT || This->resource.pool == WINED3DPOOL_MANAGED)
4612 WARN("(%p) Unable to allocate a surface which exceeds the maximum OpenGL texture size\n", This);
4617 TRACE("(%p) Creating an oversized surface: %ux%u\n", This, This->pow2Width, This->pow2Height);
4625 if (This->Flags & SFLAG_NONPOW2 && gl_info->supported[ARB_TEXTURE_RECTANGLE]
4626 && !(This->resource.format_desc->format == WINED3DFMT_P8_UINT
4630 This->texture_target = GL_TEXTURE_RECTANGLE_ARB;
4631 This->pow2Width = This->currentDesc.Width;
4632 This->pow2Height = This->currentDesc.Height;
4633 This->Flags &= ~(SFLAG_NONPOW2 | SFLAG_NORMCOORD);
4637 if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
4639 case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
4640 case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
4644 This->Flags |= SFLAG_INSYSMEM;
4650 static void surface_depth_blt(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
4653 IWineD3DDeviceImpl *device = This->resource.device;
4696 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
4698 TRACE("(%p) New location %#x\n", This, location);
4701 FIXME("(%p) Invalid location (%#x) specified\n", This, location);
4704 This->Flags &= ~SFLAG_DS_LOCATIONS;
4705 This->Flags |= location;
4711 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
4712 IWineD3DDeviceImpl *device = This->resource.device;
4715 TRACE("(%p) New location %#x\n", This, location);
4720 if (This->Flags & location) {
4721 TRACE("(%p) Location (%#x) is already up to date\n", This, location);
4725 if (This->current_renderbuffer) {
4726 FIXME("(%p) Not supported with fixed up depth stencil\n", This);
4731 if (This->Flags & SFLAG_DS_ONSCREEN) {
4735 TRACE("(%p) Copying onscreen depth buffer to depth texture\n", This);
4746 if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
4755 glCopyTexImage2D(bind_target, This->texture_level, This->resource.format_desc->glInternal,
4756 0, 0, This->currentDesc.Width, This->currentDesc.Height, 0);
4770 if (device->depth_blt_rb_w != This->currentDesc.Width
4771 || device->depth_blt_rb_h != This->currentDesc.Height) {
4775 This->currentDesc.Width, This->currentDesc.Height);
4777 device->depth_blt_rb_w = This->currentDesc.Width;
4778 device->depth_blt_rb_h = This->currentDesc.Height;
4785 context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, This, FALSE);
4788 surface_depth_blt(This, gl_info, device->depth_blt_texture,
4789 This->currentDesc.Width, This->currentDesc.Height, bind_target);
4804 if (This->Flags & SFLAG_DS_OFFSCREEN) {
4805 TRACE("(%p) Copying depth texture to onscreen depth buffer\n", This);
4810 surface_depth_blt(This, gl_info, This->texture_name,
4811 This->currentDesc.Width, This->currentDesc.Height, This->texture_target);
4825 ERR("(%p) Invalid location (%#x) specified\n", This, location);
4828 This->Flags |= location;
4832 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
4852 if(((This->Flags & SFLAG_INTEXTURE) && !(flag & SFLAG_INTEXTURE)) ||
4853 ((This->Flags & SFLAG_INSRGBTEX) && !(flag & SFLAG_INSRGBTEX))) {
4867 if (!This->texture_name)
4869 Assert(!(This->Flags & SFLAG_INTEXTURE));
4873 IWineD3DDeviceImpl *device = This->resource.device;
4879 surface_prepare_texture(This, gl_info, FALSE);
4885 if (!This->texture_name_srgb)
4887 Assert(!(This->Flags & SFLAG_INSRGBTEX));
4891 IWineD3DDeviceImpl *device = This->resource.device;
4897 surface_prepare_texture(This, gl_info, TRUE);
4905 This->Flags &= ~SFLAG_LOCATIONS;
4906 This->Flags |= flag;
4909 if(flag & SFLAG_INDRAWABLE && !list_empty(&This->overlays)) {
4910 LIST_FOR_EACH_ENTRY(overlay, &This->overlays, IWineD3DSurfaceImpl, overlay_entry) {
4915 if((This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))) {
4923 This->Flags &= ~flag;
4927 if(VBOXSHRC_IS_SHARED_UNLOCKED(This)) {
4931 * This is why we ensure texture location is the one and only which is always valid */
4932 if(!(This->Flags & SFLAG_INTEXTURE)) {
4935 This->Flags &= ~SFLAG_LOCATIONS;
4936 This->Flags |= SFLAG_INTEXTURE;
4939 else if (This->Flags & SFLAG_CLIENTMEM)
4941 if(!(This->Flags & SFLAG_INSYSMEM)) {
4944 This->Flags &= ~SFLAG_LOCATIONS;
4945 This->Flags |= SFLAG_INSYSMEM;
4951 if(!(This->Flags & SFLAG_LOCATIONS)) {
4952 ERR("%p: Surface does not have any up to date location\n", This);
4956 static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT *rect_in)
4958 IWineD3DDeviceImpl *device = This->resource.device;
4963 surface_get_rect(This, rect_in, &src_rect);
4965 context = context_acquire(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
4978 device->blitter->set_shader((IWineD3DDevice *) device, This);
4981 draw_textured_quad(This, &src_rect, &dst_rect, WINED3DTEXF_POINT);
4984 device->blitter->set_shader((IWineD3DDevice *) device, This);
4986 swapchain = (This->Flags & SFLAG_SWAPCHAIN) ? (IWineD3DSwapChainImpl *)This->container : NULL;
4988 && ((IWineD3DSurface *)This == swapchain->frontBuffer
5022 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
5023 IWineD3DDeviceImpl *device = This->resource.device;
5052 if(This->Flags & flag) {
5061 if(!(This->Flags & SFLAG_LOCATIONS)) {
5062 ERR("%p: Surface does not have any up to date location\n", This);
5063 This->Flags |= SFLAG_LOST;
5068 surface_prepare_system_memory(This);
5071 if (This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))
5077 surface_bind_and_dirtify(This, !(This->Flags & SFLAG_INTEXTURE));
5078 surface_download_data(This, gl_info);
5085 read_from_framebuffer(This, rect,
5086 This->resource.allocatedMemory,
5090 if(This->Flags & SFLAG_INTEXTURE) {
5091 surface_blt_to_drawable(This, rect);
5094 if((This->Flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX) {
5095 /* This needs a shader to convert the srgb data sampled from the GL texture into RGB
5102 d3dfmt_get_conv(This, FALSE /* We need color keying */, FALSE /* We won't use textures */, &desc, &convert);
5105 width = This->currentDesc.Width;
5110 if ((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO))
5114 TRACE("Removing the pbo attached to surface %p\n", This);
5117 surface_remove_pbo(This, gl_info);
5121 if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
5122 int height = This->currentDesc.Height;
5134 d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
5136 This->Flags |= SFLAG_CONVERTED;
5138 This->Flags &= ~SFLAG_CONVERTED;
5139 mem = This->resource.allocatedMemory;
5143 flush_to_framebuffer_drawpixels(This, desc.glFormat, desc.glType, byte_count, mem);
5146 if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
5150 if (drawable_read_ok && (This->Flags & SFLAG_INDRAWABLE)) {
5151 read_from_framebuffer_texture(This, flag == SFLAG_INSRGBTEX);
5159 d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */,
5163 if((This->Flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)) == SFLAG_INTEXTURE) {
5165 FIXME("%p: Downloading rgb texture to reload it as srgb\n", This);
5169 if((This->Flags & (SFLAG_INSRGBTEX | SFLAG_INSYSMEM)) == SFLAG_INSRGBTEX) {
5171 FIXME("%p: Downloading srgb texture to reload it as rgb\n", This);
5175 if(!(This->Flags & SFLAG_INSYSMEM)) {
5184 surface_prepare_texture(This, gl_info, srgb);
5185 surface_bind_and_dirtify(This, srgb);
5187 if(This->CKeyFlags & WINEDDSD_CKSRCBLT) {
5188 This->Flags |= SFLAG_GLCKEY;
5189 This->glCKey = This->SrcBltCKey;
5191 else This->Flags &= ~SFLAG_GLCKEY;
5194 width = This->currentDesc.Width;
5199 if((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO)) {
5200 TRACE("Removing the pbo attached to surface %p\n", This);
5201 surface_remove_pbo(This, gl_info);
5205 /* This code is entered for texture formats which need a fixup. */
5206 int height = This->currentDesc.Height;
5218 desc.convert(This->resource.allocatedMemory, mem, pitch, width, height);
5219 } else if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
5220 /* This code is only entered for color keying fixups */
5221 int height = This->currentDesc.Height;
5233 d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
5235 mem = This->resource.allocatedMemory;
5243 if (mem || (This->Flags & SFLAG_PBO))
5244 surface_upload_data(This, gl_info, &desc, srgb, mem);
5254 if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
5262 if (VBOXSHRC_IS_SHARED_UNLOCKED(This))
5269 Assert(!!(This->Flags & SFLAG_INTEXTURE) || !!(flag & SFLAG_INTEXTURE));
5270 This->Flags &= ~SFLAG_LOCATIONS;
5271 This->Flags |= SFLAG_INTEXTURE;
5275 // This->Flags |= SFLAG_INDRAWABLE;
5278 else if (This->Flags & SFLAG_CLIENTMEM)
5280 Assert(!!(This->Flags & SFLAG_INSYSMEM));
5281 This->Flags &= ~SFLAG_LOCATIONS;
5282 This->Flags |= SFLAG_INSYSMEM;
5288 This->Flags |= flag;
5291 if (in_fbo && (This->Flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE))) {
5293 This->Flags |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
5302 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
5310 This->get_drawable_size = get_drawable_size_swapchain;
5312 } else if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
5314 case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
5315 case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
5327 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
5331 if(!This->overlay_dest) return WINED3D_OK;
5336 if(This->overlay_dest->Flags & SFLAG_INOVERLAYDRAW) {
5339 This->overlay_dest->Flags |= SFLAG_INOVERLAYDRAW;
5340 hr = IWineD3DSurfaceImpl_Blt((IWineD3DSurface *) This->overlay_dest, &This->overlay_destrect,
5341 iface, &This->overlay_srcrect, WINEDDBLT_WAIT,
5343 This->overlay_dest->Flags &= ~SFLAG_INOVERLAYDRAW;
5350 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
5351 IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) This->container;
5354 if (!(This->Flags & SFLAG_SWAPCHAIN)) return TRUE;
5442 /* This function is used in case of 8bit paletted textures using GL_EXT_paletted_texture */