2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
26 /* for marking dirty */
27 #include "basetexture9.h"
29 #include "cubetexture9.h"
31 #include "nine_helpers.h"
32 #include "nine_pipe.h"
33 #include "nine_dump.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_screen.h"
37 #include "pipe/p_state.h"
39 #include "util/u_math.h"
40 #include "util/u_inlines.h"
41 #include "util/u_surface.h"
43 #define DBG_CHANNEL DBG_SURFACE
46 NineSurface9_ctor( struct NineSurface9
*This
,
47 struct NineUnknownParams
*pParams
,
48 struct NineUnknown
*pContainer
,
49 struct pipe_resource
*pResource
,
54 D3DSURFACE_DESC
*pDesc
)
57 union pipe_color_union rgba
= {0};
58 struct pipe_surface
*surf
;
59 struct pipe_context
*pipe
= pParams
->device
->pipe
;
60 bool allocate
= !pContainer
&& pDesc
->Format
!= D3DFMT_NULL
;
61 D3DMULTISAMPLE_TYPE multisample_type
;
63 DBG("This=%p pDevice=%p pResource=%p Level=%u Layer=%u pDesc=%p\n",
64 This
, pParams
->device
, pResource
, Level
, Layer
, pDesc
);
66 /* Mark this as a special surface held by another internal resource. */
67 pParams
->container
= pContainer
;
68 /* Make sure there's a Desc */
71 /* D3DUSAGE_DYNAMIC isn't allowed on managed buffers */
72 user_assert(!(pDesc
->Usage
& D3DUSAGE_DYNAMIC
) ||
73 (pDesc
->Pool
!= D3DPOOL_MANAGED
), D3DERR_INVALIDCALL
);
75 assert(allocate
|| pResource
|| user_buffer
||
76 pDesc
->Format
== D3DFMT_NULL
);
77 assert(!allocate
|| (!pResource
&& !user_buffer
));
78 assert(!pResource
|| !user_buffer
);
79 assert(!user_buffer
|| pDesc
->Pool
!= D3DPOOL_DEFAULT
);
80 assert(!pResource
|| pDesc
->Pool
== D3DPOOL_DEFAULT
);
81 /* Allocation only from create_zs_or_rt_surface with params 0 0 0 */
82 assert(!allocate
|| (Level
== 0 && Layer
== 0 && TextureType
== 0));
84 This
->data
= (uint8_t *)user_buffer
;
86 multisample_type
= pDesc
->MultiSampleType
;
88 /* Map MultiSampleQuality to MultiSampleType */
89 hr
= d3dmultisample_type_check(pParams
->device
->screen
,
92 pDesc
->MultiSampleQuality
,
98 /* TODO: this is (except width and height) duplicate from
99 * container info (in the pContainer case). Some refactoring is
100 * needed to avoid duplication */
101 This
->base
.info
.screen
= pParams
->device
->screen
;
102 This
->base
.info
.target
= PIPE_TEXTURE_2D
;
103 This
->base
.info
.width0
= pDesc
->Width
;
104 This
->base
.info
.height0
= pDesc
->Height
;
105 This
->base
.info
.depth0
= 1;
106 This
->base
.info
.last_level
= 0;
107 This
->base
.info
.array_size
= 1;
108 This
->base
.info
.nr_samples
= multisample_type
;
109 This
->base
.info
.usage
= PIPE_USAGE_DEFAULT
;
110 This
->base
.info
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
112 if (pDesc
->Usage
& D3DUSAGE_RENDERTARGET
) {
113 This
->base
.info
.bind
|= PIPE_BIND_RENDER_TARGET
;
114 } else if (pDesc
->Usage
& D3DUSAGE_DEPTHSTENCIL
) {
115 This
->base
.info
.bind
= d3d9_get_pipe_depth_format_bindings(pDesc
->Format
);
117 This
->base
.info
.bind
|= PIPE_BIND_SAMPLER_VIEW
;
120 This
->base
.info
.flags
= 0;
121 This
->base
.info
.format
= d3d9_to_pipe_format_checked(This
->base
.info
.screen
,
123 This
->base
.info
.target
,
124 This
->base
.info
.nr_samples
,
125 This
->base
.info
.bind
,
127 pDesc
->Pool
== D3DPOOL_SCRATCH
);
129 if (This
->base
.info
.format
== PIPE_FORMAT_NONE
&& pDesc
->Format
!= D3DFMT_NULL
)
130 return D3DERR_INVALIDCALL
;
132 if (allocate
&& compressed_format(pDesc
->Format
)) {
133 const unsigned w
= util_format_get_blockwidth(This
->base
.info
.format
);
134 const unsigned h
= util_format_get_blockheight(This
->base
.info
.format
);
136 /* Note: In the !allocate case, the test could fail (lower levels of a texture) */
137 user_assert(!(pDesc
->Width
% w
) && !(pDesc
->Height
% h
), D3DERR_INVALIDCALL
);
140 /* Get true format */
141 This
->format_conversion
= d3d9_to_pipe_format_checked(This
->base
.info
.screen
,
143 This
->base
.info
.target
,
144 This
->base
.info
.nr_samples
,
145 This
->base
.info
.bind
,
148 if (This
->base
.info
.format
!= This
->format_conversion
) {
149 This
->data_conversion
= align_malloc(
150 nine_format_get_level_alloc_size(This
->format_conversion
,
154 if (!This
->data_conversion
)
155 return E_OUTOFMEMORY
;
156 This
->stride_conversion
= nine_format_get_stride(This
->format_conversion
,
160 if ((allocate
&& pDesc
->Pool
!= D3DPOOL_DEFAULT
) || pDesc
->Format
== D3DFMT_NULL
) {
161 /* Ram buffer with no parent. Has to allocate the resource itself */
162 assert(!user_buffer
);
163 This
->data
= align_malloc(
164 nine_format_get_level_alloc_size(This
->base
.info
.format
,
169 return E_OUTOFMEMORY
;
172 hr
= NineResource9_ctor(&This
->base
, pParams
, pResource
,
173 allocate
&& (pDesc
->Pool
== D3DPOOL_DEFAULT
),
174 D3DRTYPE_SURFACE
, pDesc
->Pool
, pDesc
->Usage
);
179 This
->pipe
= This
->base
.base
.device
->pipe
;
180 This
->transfer
= NULL
;
182 This
->texture
= TextureType
;
184 This
->level_actual
= Level
;
188 This
->stride
= nine_format_get_stride(This
->base
.info
.format
, pDesc
->Width
);
190 if (pDesc
->Usage
& D3DUSAGE_DYNAMIC
)
191 pResource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
193 /* TODO: investigate what else exactly needs to be cleared */
194 if (This
->base
.resource
&& (pDesc
->Usage
& D3DUSAGE_RENDERTARGET
)) {
195 surf
= NineSurface9_GetSurface(This
, 0);
196 pipe
->clear_render_target(pipe
, surf
, &rgba
, 0, 0, pDesc
->Width
, pDesc
->Height
, false);
199 NineSurface9_Dump(This
);
205 NineSurface9_dtor( struct NineSurface9
*This
)
207 DBG("This=%p\n", This
);
210 NineSurface9_UnlockRect(This
);
212 pipe_surface_reference(&This
->surface
[0], NULL
);
213 pipe_surface_reference(&This
->surface
[1], NULL
);
215 /* Release system memory when we have to manage it (no parent) */
216 if (!This
->base
.base
.container
&& This
->data
)
217 align_free(This
->data
);
218 if (This
->data_conversion
)
219 align_free(This
->data_conversion
);
220 NineResource9_dtor(&This
->base
);
223 struct pipe_surface
*
224 NineSurface9_CreatePipeSurface( struct NineSurface9
*This
, const int sRGB
)
226 struct pipe_context
*pipe
= This
->pipe
;
227 struct pipe_screen
*screen
= pipe
->screen
;
228 struct pipe_resource
*resource
= This
->base
.resource
;
229 struct pipe_surface templ
;
230 enum pipe_format srgb_format
;
232 assert(This
->desc
.Pool
== D3DPOOL_DEFAULT
);
235 srgb_format
= util_format_srgb(resource
->format
);
236 if (sRGB
&& srgb_format
!= PIPE_FORMAT_NONE
&&
237 screen
->is_format_supported(screen
, srgb_format
,
238 resource
->target
, 0, resource
->bind
))
239 templ
.format
= srgb_format
;
241 templ
.format
= resource
->format
;
242 templ
.u
.tex
.level
= This
->level
;
243 templ
.u
.tex
.first_layer
= This
->layer
;
244 templ
.u
.tex
.last_layer
= This
->layer
;
246 This
->surface
[sRGB
] = pipe
->create_surface(pipe
, resource
, &templ
);
247 assert(This
->surface
[sRGB
]);
248 return This
->surface
[sRGB
];
253 NineSurface9_Dump( struct NineSurface9
*This
)
255 struct NineBaseTexture9
*tex
;
256 GUID id
= IID_IDirect3DBaseTexture9
;
259 DBG("\nNineSurface9(%p->%p/%p): Pool=%s Type=%s Usage=%s\n"
260 "Dims=%ux%u Format=%s Stride=%u Lockable=%i\n"
261 "Level=%u(%u), Layer=%u\n", This
, This
->base
.resource
, This
->data
,
262 nine_D3DPOOL_to_str(This
->desc
.Pool
),
263 nine_D3DRTYPE_to_str(This
->desc
.Type
),
264 nine_D3DUSAGE_to_str(This
->desc
.Usage
),
265 This
->desc
.Width
, This
->desc
.Height
,
266 d3dformat_to_string(This
->desc
.Format
), This
->stride
,
267 This
->base
.resource
&&
268 (This
->base
.resource
->flags
& NINE_RESOURCE_FLAG_LOCKABLE
),
269 This
->level
, This
->level_actual
, This
->layer
);
271 if (!This
->base
.base
.container
)
273 NineUnknown_QueryInterface(This
->base
.base
.container
, ref
, (void **)&tex
);
275 NineBaseTexture9_Dump(tex
);
276 NineUnknown_Release(NineUnknown(tex
));
282 NineSurface9_GetContainer( struct NineSurface9
*This
,
289 DBG("This=%p riid=%p id=%s ppContainer=%p\n",
290 This
, riid
, riid
? GUID_sprintf(guid_str
, riid
) : "", ppContainer
);
292 if (!ppContainer
) return E_POINTER
;
294 /* Return device for OffscreenPlainSurface, DepthStencilSurface and RenderTarget */
295 if (!NineUnknown(This
)->container
) {
296 *ppContainer
= NineUnknown(This
)->device
;
297 NineUnknown_AddRef(NineUnknown(*ppContainer
));
302 hr
= NineUnknown_QueryInterface(NineUnknown(This
)->container
, riid
, ppContainer
);
304 DBG("QueryInterface FAILED!\n");
309 NineSurface9_MarkContainerDirty( struct NineSurface9
*This
)
312 struct NineBaseTexture9
*tex
=
313 NineBaseTexture9(This
->base
.base
.container
);
315 assert(This
->texture
== D3DRTYPE_TEXTURE
||
316 This
->texture
== D3DRTYPE_CUBETEXTURE
);
317 if (This
->base
.pool
== D3DPOOL_MANAGED
)
318 tex
->managed
.dirty
= TRUE
;
320 if (This
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
)
321 tex
->dirty_mip
= TRUE
;
323 BASETEX_REGISTER_UPDATE(tex
);
328 NineSurface9_GetDesc( struct NineSurface9
*This
,
329 D3DSURFACE_DESC
*pDesc
)
331 user_assert(pDesc
!= NULL
, E_POINTER
);
336 /* Add the dirty rects to the source texture */
338 NineSurface9_AddDirtyRect( struct NineSurface9
*This
,
339 const struct pipe_box
*box
)
343 DBG("This=%p box=%p\n", This
, box
);
345 assert (This
->base
.pool
!= D3DPOOL_MANAGED
||
346 This
->texture
== D3DRTYPE_CUBETEXTURE
||
347 This
->texture
== D3DRTYPE_TEXTURE
);
349 if (This
->base
.pool
== D3DPOOL_DEFAULT
)
352 /* Add a dirty rect to level 0 of the parent texture */
353 dirty_rect
.left
= box
->x
<< This
->level_actual
;
354 dirty_rect
.right
= dirty_rect
.left
+ (box
->width
<< This
->level_actual
);
355 dirty_rect
.top
= box
->y
<< This
->level_actual
;
356 dirty_rect
.bottom
= dirty_rect
.top
+ (box
->height
<< This
->level_actual
);
358 if (This
->texture
== D3DRTYPE_TEXTURE
) {
359 struct NineTexture9
*tex
=
360 NineTexture9(This
->base
.base
.container
);
362 NineTexture9_AddDirtyRect(tex
, &dirty_rect
);
363 } else if (This
->texture
== D3DRTYPE_CUBETEXTURE
) {
364 struct NineCubeTexture9
*ctex
=
365 NineCubeTexture9(This
->base
.base
.container
);
367 NineCubeTexture9_AddDirtyRect(ctex
, This
->layer
, &dirty_rect
);
371 static inline uint8_t *
372 NineSurface9_GetSystemMemPointer(struct NineSurface9
*This
, int x
, int y
)
374 unsigned x_offset
= util_format_get_stride(This
->base
.info
.format
, x
);
376 y
= util_format_get_nblocksy(This
->base
.info
.format
, y
);
379 return This
->data
+ (y
* This
->stride
+ x_offset
);
383 NineSurface9_LockRect( struct NineSurface9
*This
,
384 D3DLOCKED_RECT
*pLockedRect
,
388 struct pipe_resource
*resource
= This
->base
.resource
;
392 DBG("This=%p pLockedRect=%p pRect=%p[%u..%u,%u..%u] Flags=%s\n", This
,
394 pRect
? pRect
->left
: 0, pRect
? pRect
->right
: 0,
395 pRect
? pRect
->top
: 0, pRect
? pRect
->bottom
: 0,
396 nine_D3DLOCK_to_str(Flags
));
397 NineSurface9_Dump(This
);
399 /* check if it's already locked */
400 user_assert(This
->lock_count
== 0, D3DERR_INVALIDCALL
);
402 /* set pBits to NULL after lock_count check */
403 user_assert(pLockedRect
, E_POINTER
);
404 pLockedRect
->pBits
= NULL
;
407 user_assert(This
->base
.pool
!= D3DPOOL_DEFAULT
||
408 (resource
&& (resource
->flags
& NINE_RESOURCE_FLAG_LOCKABLE
)),
411 user_assert(!(Flags
& ~(D3DLOCK_DISCARD
|
413 D3DLOCK_NO_DIRTY_UPDATE
|
414 D3DLOCK_NOOVERWRITE
|
415 D3DLOCK_NOSYSLOCK
| /* ignored */
416 D3DLOCK_READONLY
)), D3DERR_INVALIDCALL
);
417 user_assert(!((Flags
& D3DLOCK_DISCARD
) && (Flags
& D3DLOCK_READONLY
)),
420 user_assert(This
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
,
423 if (pRect
&& This
->desc
.Pool
== D3DPOOL_DEFAULT
&&
424 util_format_is_compressed(This
->base
.info
.format
)) {
425 const unsigned w
= util_format_get_blockwidth(This
->base
.info
.format
);
426 const unsigned h
= util_format_get_blockheight(This
->base
.info
.format
);
427 user_assert((pRect
->left
== 0 && pRect
->right
== This
->desc
.Width
&&
428 pRect
->top
== 0 && pRect
->bottom
== This
->desc
.Height
) ||
429 (!(pRect
->left
% w
) && !(pRect
->right
% w
) &&
430 !(pRect
->top
% h
) && !(pRect
->bottom
% h
)),
434 if (Flags
& D3DLOCK_DISCARD
) {
435 usage
= PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD_RANGE
;
437 usage
= (Flags
& D3DLOCK_READONLY
) ?
438 PIPE_TRANSFER_READ
: PIPE_TRANSFER_READ_WRITE
;
440 if (Flags
& D3DLOCK_DONOTWAIT
)
441 usage
|= PIPE_TRANSFER_DONTBLOCK
;
444 /* Windows XP accepts invalid locking rectangles, Windows 7 rejects
445 * them. Use Windows XP behaviour for now. */
446 rect_to_pipe_box(&box
, pRect
);
448 u_box_origin_2d(This
->desc
.Width
, This
->desc
.Height
, &box
);
451 user_warn(This
->desc
.Format
== D3DFMT_NULL
);
453 if (This
->data_conversion
) {
454 /* For now we only have uncompressed formats here */
455 pLockedRect
->Pitch
= This
->stride_conversion
;
456 pLockedRect
->pBits
= This
->data_conversion
+ box
.y
* This
->stride_conversion
+
457 util_format_get_stride(This
->format_conversion
, box
.x
);
458 } else if (This
->data
) {
459 DBG("returning system memory\n");
460 /* ATI1 and ATI2 need special handling, because of d3d9 bug.
461 * We must advertise to the application as if it is uncompressed
462 * and bpp 8, and the app has a workaround to work with the fact
463 * that it is actually compressed. */
464 if (is_ATI1_ATI2(This
->base
.info
.format
)) {
465 pLockedRect
->Pitch
= This
->desc
.Width
;
466 pLockedRect
->pBits
= This
->data
+ box
.y
* This
->desc
.Width
+ box
.x
;
468 pLockedRect
->Pitch
= This
->stride
;
469 pLockedRect
->pBits
= NineSurface9_GetSystemMemPointer(This
,
474 DBG("mapping pipe_resource %p (level=%u usage=%x)\n",
475 resource
, This
->level
, usage
);
477 pLockedRect
->pBits
= This
->pipe
->transfer_map(This
->pipe
, resource
,
478 This
->level
, usage
, &box
,
480 if (!This
->transfer
) {
481 DBG("transfer_map failed\n");
482 if (Flags
& D3DLOCK_DONOTWAIT
)
483 return D3DERR_WASSTILLDRAWING
;
484 return D3DERR_INVALIDCALL
;
486 pLockedRect
->Pitch
= This
->transfer
->stride
;
489 if (!(Flags
& (D3DLOCK_NO_DIRTY_UPDATE
| D3DLOCK_READONLY
))) {
490 NineSurface9_MarkContainerDirty(This
);
491 NineSurface9_AddDirtyRect(This
, &box
);
499 NineSurface9_UnlockRect( struct NineSurface9
*This
)
501 DBG("This=%p lock_count=%u\n", This
, This
->lock_count
);
502 user_assert(This
->lock_count
, D3DERR_INVALIDCALL
);
503 if (This
->transfer
) {
504 This
->pipe
->transfer_unmap(This
->pipe
, This
->transfer
);
505 This
->transfer
= NULL
;
509 if (This
->data_conversion
) {
510 struct pipe_transfer
*transfer
;
511 uint8_t *dst
= This
->data
;
514 u_box_origin_2d(This
->desc
.Width
, This
->desc
.Height
, &box
);
517 dst
= This
->pipe
->transfer_map(This
->pipe
,
520 PIPE_TRANSFER_WRITE
|
521 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
527 (void) util_format_translate(This
->base
.info
.format
,
528 dst
, This
->data
? This
->stride
: transfer
->stride
,
530 This
->format_conversion
,
531 This
->data_conversion
,
532 This
->stride_conversion
,
534 This
->desc
.Width
, This
->desc
.Height
);
537 pipe_transfer_unmap(This
->pipe
, transfer
);
543 NineSurface9_GetDC( struct NineSurface9
*This
,
546 STUB(D3DERR_INVALIDCALL
);
550 NineSurface9_ReleaseDC( struct NineSurface9
*This
,
553 STUB(D3DERR_INVALIDCALL
);
556 IDirect3DSurface9Vtbl NineSurface9_vtable
= {
557 (void *)NineUnknown_QueryInterface
,
558 (void *)NineUnknown_AddRef
,
559 (void *)NineUnknown_Release
,
560 (void *)NineUnknown_GetDevice
, /* actually part of Resource9 iface */
561 (void *)NineUnknown_SetPrivateData
,
562 (void *)NineUnknown_GetPrivateData
,
563 (void *)NineUnknown_FreePrivateData
,
564 (void *)NineResource9_SetPriority
,
565 (void *)NineResource9_GetPriority
,
566 (void *)NineResource9_PreLoad
,
567 (void *)NineResource9_GetType
,
568 (void *)NineSurface9_GetContainer
,
569 (void *)NineSurface9_GetDesc
,
570 (void *)NineSurface9_LockRect
,
571 (void *)NineSurface9_UnlockRect
,
572 (void *)NineSurface9_GetDC
,
573 (void *)NineSurface9_ReleaseDC
576 /* When this function is called, we have already checked
577 * The copy regions fit the surfaces */
579 NineSurface9_CopyMemToDefault( struct NineSurface9
*This
,
580 struct NineSurface9
*From
,
581 const POINT
*pDestPoint
,
582 const RECT
*pSourceRect
)
584 struct pipe_context
*pipe
= This
->pipe
;
585 struct pipe_transfer
*transfer
= NULL
;
586 struct pipe_resource
*r_dst
= This
->base
.resource
;
587 struct pipe_box dst_box
;
589 int src_x
, src_y
, dst_x
, dst_y
, copy_width
, copy_height
;
591 assert(This
->base
.pool
== D3DPOOL_DEFAULT
&&
592 From
->base
.pool
== D3DPOOL_SYSTEMMEM
);
595 dst_x
= pDestPoint
->x
;
596 dst_y
= pDestPoint
->y
;
603 src_x
= pSourceRect
->left
;
604 src_y
= pSourceRect
->top
;
605 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
606 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
610 copy_width
= From
->desc
.Width
;
611 copy_height
= From
->desc
.Height
;
614 u_box_2d_zslice(dst_x
, dst_y
, This
->layer
,
615 copy_width
, copy_height
, &dst_box
);
617 map
= pipe
->transfer_map(pipe
,
620 PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD_RANGE
,
621 &dst_box
, &transfer
);
625 /* Note: if formats are the sames, it will revert
626 * to normal memcpy */
627 (void) util_format_translate(r_dst
->format
,
628 map
, transfer
->stride
,
630 From
->base
.info
.format
,
631 From
->data
, From
->stride
,
633 copy_width
, copy_height
);
635 pipe_transfer_unmap(pipe
, transfer
);
637 if (This
->data_conversion
)
638 (void) util_format_translate(This
->format_conversion
,
639 This
->data_conversion
,
640 This
->stride_conversion
,
642 From
->base
.info
.format
,
643 From
->data
, From
->stride
,
645 copy_width
, copy_height
);
647 NineSurface9_MarkContainerDirty(This
);
651 NineSurface9_CopyDefaultToMem( struct NineSurface9
*This
,
652 struct NineSurface9
*From
)
654 struct pipe_context
*pipe
= This
->pipe
;
655 struct pipe_resource
*r_src
= From
->base
.resource
;
656 struct pipe_transfer
*transfer
;
657 struct pipe_box src_box
;
659 const uint8_t *p_src
;
661 assert(This
->base
.pool
== D3DPOOL_SYSTEMMEM
&&
662 From
->base
.pool
== D3DPOOL_DEFAULT
);
664 assert(This
->desc
.Width
== From
->desc
.Width
);
665 assert(This
->desc
.Height
== From
->desc
.Height
);
667 u_box_origin_2d(This
->desc
.Width
, This
->desc
.Height
, &src_box
);
668 src_box
.z
= From
->layer
;
670 p_src
= pipe
->transfer_map(pipe
, r_src
, From
->level
,
672 &src_box
, &transfer
);
673 p_dst
= NineSurface9_GetSystemMemPointer(This
, 0, 0);
675 assert (p_src
&& p_dst
);
677 util_copy_rect(p_dst
, This
->base
.info
.format
,
679 This
->desc
.Width
, This
->desc
.Height
,
681 transfer
->stride
, 0, 0);
683 pipe
->transfer_unmap(pipe
, transfer
);
687 /* Gladly, rendering to a MANAGED surface is not permitted, so we will
688 * never have to do the reverse, i.e. download the surface.
691 NineSurface9_UploadSelf( struct NineSurface9
*This
,
692 const struct pipe_box
*damaged
)
694 struct pipe_context
*pipe
= This
->pipe
;
695 struct pipe_resource
*res
= This
->base
.resource
;
699 DBG("This=%p damaged=%p\n", This
, damaged
);
701 assert(This
->base
.pool
== D3DPOOL_MANAGED
);
711 box
.width
= This
->desc
.Width
;
712 box
.height
= This
->desc
.Height
;
716 ptr
= NineSurface9_GetSystemMemPointer(This
, box
.x
, box
.y
);
718 pipe
->texture_subdata(pipe
, res
, This
->level
, 0,
719 &box
, ptr
, This
->stride
, 0);
725 NineSurface9_SetResourceResize( struct NineSurface9
*This
,
726 struct pipe_resource
*resource
)
728 assert(This
->level
== 0 && This
->level_actual
== 0);
729 assert(!This
->lock_count
);
730 assert(This
->desc
.Pool
== D3DPOOL_DEFAULT
);
731 assert(!This
->texture
);
733 pipe_resource_reference(&This
->base
.resource
, resource
);
735 This
->desc
.Width
= This
->base
.info
.width0
= resource
->width0
;
736 This
->desc
.Height
= This
->base
.info
.height0
= resource
->height0
;
737 This
->base
.info
.nr_samples
= resource
->nr_samples
;
739 This
->stride
= nine_format_get_stride(This
->base
.info
.format
,
742 pipe_surface_reference(&This
->surface
[0], NULL
);
743 pipe_surface_reference(&This
->surface
[1], NULL
);
747 static const GUID
*NineSurface9_IIDs
[] = {
748 &IID_IDirect3DSurface9
,
749 &IID_IDirect3DResource9
,
755 NineSurface9_new( struct NineDevice9
*pDevice
,
756 struct NineUnknown
*pContainer
,
757 struct pipe_resource
*pResource
,
762 D3DSURFACE_DESC
*pDesc
,
763 struct NineSurface9
**ppOut
)
765 NINE_DEVICE_CHILD_NEW(Surface9
, ppOut
, pDevice
, /* args */
766 pContainer
, pResource
, user_buffer
,
767 TextureType
, Level
, Layer
, pDesc
);