1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_D3DSURFACEIMAGE_H
8 #define GFX_D3DSURFACEIMAGE_H
10 #include "mozilla/RefPtr.h"
11 #include "ImageContainer.h"
13 #include "mozilla/layers/TextureClientRecycleAllocator.h"
20 class D3D9RecycleAllocator
: public TextureClientRecycleAllocator
{
22 D3D9RecycleAllocator(KnowsCompositor
* aAllocator
, IDirect3DDevice9
* aDevice
)
23 : TextureClientRecycleAllocator(aAllocator
), mDevice(aDevice
) {}
25 already_AddRefed
<TextureClient
> CreateOrRecycleClient(
26 gfx::SurfaceFormat aFormat
, const gfx::IntSize
& aSize
);
29 already_AddRefed
<TextureClient
> Allocate(
30 gfx::SurfaceFormat aFormat
, gfx::IntSize aSize
, BackendSelector aSelector
,
31 TextureFlags aTextureFlags
, TextureAllocationFlags aAllocFlags
) override
;
33 RefPtr
<IDirect3DDevice9
> mDevice
;
37 * Wraps a D3D9 texture, shared with the compositor though DXGI.
38 * At the moment it is only used with D3D11 compositing, and the corresponding
39 * TextureHost is DXGITextureHostD3D11.
41 class DXGID3D9TextureData
: public TextureData
{
43 static DXGID3D9TextureData
* Create(gfx::IntSize aSize
,
44 gfx::SurfaceFormat aFormat
,
46 IDirect3DDevice9
* aDevice
);
48 virtual ~DXGID3D9TextureData();
50 void FillInfo(TextureData::Info
& aInfo
) const override
;
52 bool Lock(OpenMode
) override
{ return true; }
54 void Unlock() override
{}
56 bool Serialize(SurfaceDescriptor
& aOutDescriptor
) override
;
58 void Deallocate(LayersIPCChannel
* aAllocator
) override
{}
60 IDirect3DDevice9
* GetD3D9Device() { return mDevice
; }
61 IDirect3DTexture9
* GetD3D9Texture() { return mTexture
; }
62 HANDLE
GetShareHandle() const { return mHandle
; }
63 already_AddRefed
<IDirect3DSurface9
> GetD3D9Surface() const;
65 const D3DSURFACE_DESC
& GetDesc() const { return mDesc
; }
67 gfx::IntSize
GetSize() const {
68 return gfx::IntSize(mDesc
.Width
, mDesc
.Height
);
72 DXGID3D9TextureData(gfx::SurfaceFormat aFormat
, IDirect3DTexture9
* aTexture
,
73 HANDLE aHandle
, IDirect3DDevice9
* aDevice
);
75 RefPtr
<IDirect3DDevice9
> mDevice
;
76 RefPtr
<IDirect3DTexture9
> mTexture
;
77 gfx::SurfaceFormat mFormat
;
79 D3DSURFACE_DESC mDesc
;
82 // Image class that wraps a IDirect3DSurface9. This class copies the image
83 // passed into SetData(), so that it can be accessed from other D3D devices.
84 // This class also manages the synchronization of the copy, to ensure the
85 // resource is ready to use.
86 class D3D9SurfaceImage
: public Image
{
89 virtual ~D3D9SurfaceImage();
91 HRESULT
AllocateAndCopy(D3D9RecycleAllocator
* aAllocator
,
92 IDirect3DSurface9
* aSurface
,
93 const gfx::IntRect
& aRegion
);
95 // Returns the description of the shared surface.
96 gfx::IntSize
GetSize() const override
;
98 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
100 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
102 already_AddRefed
<IDirect3DSurface9
> GetD3D9Surface() const;
104 HANDLE
GetShareHandle() const;
106 bool IsValid() const override
{ return mValid
; }
108 void Invalidate() { mValid
= false; }
112 RefPtr
<TextureClient
> mTextureClient
;
113 RefPtr
<IDirect3DTexture9
> mTexture
;
115 D3DSURFACE_DESC mDesc
;
119 } // namespace layers
120 } // namespace mozilla
122 #endif // GFX_D3DSURFACEIMAGE_H