17ec681f3Smrg/* 27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com> 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom 97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 227ec681f3Smrg 237ec681f3Smrg#ifndef _NINE_SURFACE9_H_ 247ec681f3Smrg#define _NINE_SURFACE9_H_ 257ec681f3Smrg 267ec681f3Smrg#include "nine_memory_helper.h" 277ec681f3Smrg#include "resource9.h" 287ec681f3Smrg 297ec681f3Smrg#include "pipe/p_state.h" 307ec681f3Smrg#include "util/list.h" 317ec681f3Smrg#include "util/u_rect.h" 327ec681f3Smrg#include "util/u_inlines.h" 337ec681f3Smrg 347ec681f3Smrgstruct NineSurface9 357ec681f3Smrg{ 367ec681f3Smrg struct NineResource9 base; 377ec681f3Smrg 387ec681f3Smrg /* G3D state */ 397ec681f3Smrg struct pipe_transfer *transfer; 407ec681f3Smrg struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */ 417ec681f3Smrg int lock_count; 427ec681f3Smrg uint8_t texture; /* rtype of container BaseTex or 0 */ 437ec681f3Smrg 447ec681f3Smrg /* resource description */ 457ec681f3Smrg unsigned level; /* refers to the pipe_resource (SetLOD !) */ 467ec681f3Smrg unsigned level_actual; /* refers to the NineTexture */ 477ec681f3Smrg unsigned layer; 487ec681f3Smrg D3DSURFACE_DESC desc; 497ec681f3Smrg 507ec681f3Smrg struct nine_allocation *data; /* system memory backing */ 517ec681f3Smrg struct nine_allocation *data_internal; /* for conversions */ 527ec681f3Smrg enum pipe_format format_internal; 537ec681f3Smrg unsigned stride; /* for system memory backing */ 547ec681f3Smrg unsigned stride_internal; 557ec681f3Smrg 567ec681f3Smrg unsigned pending_uploads_counter; /* pending uploads */ 577ec681f3Smrg}; 587ec681f3Smrgstatic inline struct NineSurface9 * 597ec681f3SmrgNineSurface9( void *data ) 607ec681f3Smrg{ 617ec681f3Smrg return (struct NineSurface9 *)data; 627ec681f3Smrg} 637ec681f3Smrg 647ec681f3SmrgHRESULT 657ec681f3SmrgNineSurface9_new( struct NineDevice9 *pDevice, 667ec681f3Smrg struct NineUnknown *pContainer, 677ec681f3Smrg struct pipe_resource *pResource, 687ec681f3Smrg struct nine_allocation *user_buffer, 697ec681f3Smrg uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */ 707ec681f3Smrg unsigned Level, 717ec681f3Smrg unsigned Layer, 727ec681f3Smrg D3DSURFACE_DESC *pDesc, 737ec681f3Smrg struct NineSurface9 **ppOut ); 747ec681f3Smrg 757ec681f3SmrgHRESULT 767ec681f3SmrgNineSurface9_ctor( struct NineSurface9 *This, 777ec681f3Smrg struct NineUnknownParams *pParams, 787ec681f3Smrg struct NineUnknown *pContainer, 797ec681f3Smrg struct pipe_resource *pResource, 807ec681f3Smrg struct nine_allocation *user_buffer, 817ec681f3Smrg uint8_t TextureType, 827ec681f3Smrg unsigned Level, 837ec681f3Smrg unsigned Layer, 847ec681f3Smrg D3DSURFACE_DESC *pDesc ); 857ec681f3Smrg 867ec681f3Smrgvoid 877ec681f3SmrgNineSurface9_dtor( struct NineSurface9 *This ); 887ec681f3Smrg 897ec681f3Smrg/*** Nine private ***/ 907ec681f3Smrg 917ec681f3Smrgvoid 927ec681f3SmrgNineSurface9_MarkContainerDirty( struct NineSurface9 *This ); 937ec681f3Smrg 947ec681f3Smrgstatic inline struct pipe_surface * 957ec681f3SmrgNineSurface9_GetSurface( struct NineSurface9 *This, int sRGB ) 967ec681f3Smrg{ 977ec681f3Smrg assert(This->surface[sRGB]); 987ec681f3Smrg return This->surface[sRGB]; 997ec681f3Smrg} 1007ec681f3Smrg 1017ec681f3Smrgstatic inline struct pipe_resource * 1027ec681f3SmrgNineSurface9_GetResource( struct NineSurface9 *This ) 1037ec681f3Smrg{ 1047ec681f3Smrg return This->base.resource; 1057ec681f3Smrg} 1067ec681f3Smrg 1077ec681f3Smrgvoid 1087ec681f3SmrgNineSurface9_SetResource( struct NineSurface9 *This, 1097ec681f3Smrg struct pipe_resource *resource, unsigned level ); 1107ec681f3Smrg 1117ec681f3Smrgvoid 1127ec681f3SmrgNineSurface9_SetMultiSampleType( struct NineSurface9 *This, 1137ec681f3Smrg D3DMULTISAMPLE_TYPE mst ); 1147ec681f3Smrg 1157ec681f3Smrgvoid 1167ec681f3SmrgNineSurface9_SetResourceResize( struct NineSurface9 *This, 1177ec681f3Smrg struct pipe_resource *resource ); 1187ec681f3Smrg 1197ec681f3Smrgvoid 1207ec681f3SmrgNineSurface9_AddDirtyRect( struct NineSurface9 *This, 1217ec681f3Smrg const struct pipe_box *box ); 1227ec681f3Smrg 1237ec681f3SmrgHRESULT 1247ec681f3SmrgNineSurface9_UploadSelf( struct NineSurface9 *This, 1257ec681f3Smrg const struct pipe_box *damaged ); 1267ec681f3Smrg 1277ec681f3Smrgvoid 1287ec681f3SmrgNineSurface9_CopyMemToDefault( struct NineSurface9 *This, 1297ec681f3Smrg struct NineSurface9 *From, 1307ec681f3Smrg const POINT *pDestPoint, 1317ec681f3Smrg const RECT *pSourceRect ); 1327ec681f3Smrg 1337ec681f3Smrgvoid 1347ec681f3SmrgNineSurface9_CopyDefaultToMem( struct NineSurface9 *This, 1357ec681f3Smrg struct NineSurface9 *From ); 1367ec681f3Smrg 1377ec681f3Smrgstatic inline boolean 1387ec681f3SmrgNineSurface9_IsOffscreenPlain (struct NineSurface9 *This ) 1397ec681f3Smrg{ 1407ec681f3Smrg return This->base.usage == 0 && !This->texture; 1417ec681f3Smrg} 1427ec681f3Smrg 1437ec681f3Smrg#if defined(DEBUG) || !defined(NDEBUG) 1447ec681f3Smrgvoid 1457ec681f3SmrgNineSurface9_Dump( struct NineSurface9 *This ); 1467ec681f3Smrg#else 1477ec681f3Smrgstatic inline void 1487ec681f3SmrgNineSurface9_Dump( struct NineSurface9 *This ) { } 1497ec681f3Smrg#endif 1507ec681f3Smrg 1517ec681f3Smrg/*** Direct3D public ***/ 1527ec681f3Smrg 1537ec681f3SmrgHRESULT NINE_WINAPI 1547ec681f3SmrgNineSurface9_GetContainer( struct NineSurface9 *This, 1557ec681f3Smrg REFIID riid, 1567ec681f3Smrg void **ppContainer ); 1577ec681f3Smrg 1587ec681f3SmrgHRESULT NINE_WINAPI 1597ec681f3SmrgNineSurface9_GetDesc( struct NineSurface9 *This, 1607ec681f3Smrg D3DSURFACE_DESC *pDesc ); 1617ec681f3Smrg 1627ec681f3SmrgHRESULT NINE_WINAPI 1637ec681f3SmrgNineSurface9_LockRect( struct NineSurface9 *This, 1647ec681f3Smrg D3DLOCKED_RECT *pLockedRect, 1657ec681f3Smrg const RECT *pRect, 1667ec681f3Smrg DWORD Flags ); 1677ec681f3Smrg 1687ec681f3SmrgHRESULT NINE_WINAPI 1697ec681f3SmrgNineSurface9_UnlockRect( struct NineSurface9 *This ); 1707ec681f3Smrg 1717ec681f3SmrgHRESULT NINE_WINAPI 1727ec681f3SmrgNineSurface9_GetDC( struct NineSurface9 *This, 1737ec681f3Smrg HDC *phdc ); 1747ec681f3Smrg 1757ec681f3SmrgHRESULT NINE_WINAPI 1767ec681f3SmrgNineSurface9_ReleaseDC( struct NineSurface9 *This, 1777ec681f3Smrg HDC hdc ); 1787ec681f3Smrg 1797ec681f3Smrg#endif /* _NINE_SURFACE9_H_ */ 180