Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  8.  * license, and/or sell copies of the Software, and to permit persons to whom
  9.  * the Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21.  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22.  
  23. #ifndef _NINE_SURFACE9_H_
  24. #define _NINE_SURFACE9_H_
  25.  
  26. #include "resource9.h"
  27.  
  28. #include "pipe/p_state.h"
  29. #include "util/list.h"
  30. #include "util/u_rect.h"
  31. #include "util/u_inlines.h"
  32.  
  33. struct NineSurface9
  34. {
  35.     struct NineResource9 base;
  36.  
  37.     /* G3D state */
  38.     struct pipe_context *pipe;
  39.     struct pipe_transfer *transfer;
  40.     struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */
  41.     int lock_count;
  42.     uint8_t texture; /* rtype of container BaseTex or 0 */
  43.  
  44.     /* resource description */
  45.     unsigned level;        /* refers to the pipe_resource (SetLOD !) */
  46.     unsigned level_actual; /* refers to the NineTexture */
  47.     unsigned layer;
  48.     D3DSURFACE_DESC desc;
  49.  
  50.     uint8_t *data; /* system memory backing */
  51.     unsigned stride; /* for system memory backing */
  52. };
  53. static INLINE struct NineSurface9 *
  54. NineSurface9( void *data )
  55. {
  56.     return (struct NineSurface9 *)data;
  57. }
  58.  
  59. HRESULT
  60. NineSurface9_new( struct NineDevice9 *pDevice,
  61.                   struct NineUnknown *pContainer,
  62.                   struct pipe_resource *pResource,
  63.                   void *user_buffer,
  64.                   uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
  65.                   unsigned Level,
  66.                   unsigned Layer,
  67.                   D3DSURFACE_DESC *pDesc,
  68.                   struct NineSurface9 **ppOut );
  69.  
  70. HRESULT
  71. NineSurface9_ctor( struct NineSurface9 *This,
  72.                    struct NineUnknownParams *pParams,
  73.                    struct NineUnknown *pContainer,
  74.                    struct pipe_resource *pResource,
  75.                    void *user_buffer,
  76.                    uint8_t TextureType,
  77.                    unsigned Level,
  78.                    unsigned Layer,
  79.                    D3DSURFACE_DESC *pDesc );
  80.  
  81. void
  82. NineSurface9_dtor( struct NineSurface9 *This );
  83.  
  84. /*** Nine private ***/
  85.  
  86. void
  87. NineSurface9_MarkContainerDirty( struct NineSurface9 *This );
  88.  
  89. struct pipe_surface *
  90. NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB );
  91.  
  92. static INLINE struct pipe_surface *
  93. NineSurface9_GetSurface( struct NineSurface9 *This, int sRGB )
  94. {
  95.     if (This->surface[sRGB])
  96.         return This->surface[sRGB];
  97.     return NineSurface9_CreatePipeSurface(This, sRGB);
  98. }
  99.  
  100. static INLINE struct pipe_resource *
  101. NineSurface9_GetResource( struct NineSurface9 *This )
  102. {
  103.     return This->base.resource;
  104. }
  105.  
  106. static INLINE void
  107. NineSurface9_SetResource( struct NineSurface9 *This,
  108.                           struct pipe_resource *resource, unsigned level )
  109. {
  110.     This->level = level;
  111.     pipe_resource_reference(&This->base.resource, resource);
  112.     pipe_surface_reference(&This->surface[0], NULL);
  113.     pipe_surface_reference(&This->surface[1], NULL);
  114. }
  115.  
  116. void
  117. NineSurface9_SetResourceResize( struct NineSurface9 *This,
  118.                                 struct pipe_resource *resource );
  119.  
  120. void
  121. NineSurface9_AddDirtyRect( struct NineSurface9 *This,
  122.                            const struct pipe_box *box );
  123.  
  124. HRESULT
  125. NineSurface9_UploadSelf( struct NineSurface9 *This,
  126.                          const struct pipe_box *damaged );
  127.  
  128. HRESULT
  129. NineSurface9_CopySurface( struct NineSurface9 *This,
  130.                           struct NineSurface9 *From,
  131.                           const POINT *pDestPoint,
  132.                           const RECT *pSourceRect );
  133.  
  134. static INLINE boolean
  135. NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
  136. {
  137.     return This->base.usage == 0 && !This->texture;
  138. }
  139.  
  140. #ifdef DEBUG
  141. void
  142. NineSurface9_Dump( struct NineSurface9 *This );
  143. #else
  144. static INLINE void
  145. NineSurface9_Dump( struct NineSurface9 *This ) { }
  146. #endif
  147.  
  148. /*** Direct3D public ***/
  149.  
  150. HRESULT WINAPI
  151. NineSurface9_GetContainer( struct NineSurface9 *This,
  152.                            REFIID riid,
  153.                            void **ppContainer );
  154.  
  155. HRESULT WINAPI
  156. NineSurface9_GetDesc( struct NineSurface9 *This,
  157.                       D3DSURFACE_DESC *pDesc );
  158.  
  159. HRESULT WINAPI
  160. NineSurface9_LockRect( struct NineSurface9 *This,
  161.                        D3DLOCKED_RECT *pLockedRect,
  162.                        const RECT *pRect,
  163.                        DWORD Flags );
  164.  
  165. HRESULT WINAPI
  166. NineSurface9_UnlockRect( struct NineSurface9 *This );
  167.  
  168. HRESULT WINAPI
  169. NineSurface9_GetDC( struct NineSurface9 *This,
  170.                     HDC *phdc );
  171.  
  172. HRESULT WINAPI
  173. NineSurface9_ReleaseDC( struct NineSurface9 *This,
  174.                         HDC hdc );
  175.  
  176. #endif /* _NINE_SURFACE9_H_ */
  177.