Source code

Revision control

Other Tools

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/. */
6
7
#ifndef GFX_D3DSURFACEIMAGE_H
8
#define GFX_D3DSURFACEIMAGE_H
9
10
#include "mozilla/RefPtr.h"
11
#include "ImageContainer.h"
12
#include "d3d9.h"
13
#include "mozilla/layers/TextureClientRecycleAllocator.h"
14
15
namespace mozilla {
16
namespace layers {
17
18
class TextureClient;
19
20
class D3D9RecycleAllocator : public TextureClientRecycleAllocator {
21
public:
22
D3D9RecycleAllocator(KnowsCompositor* aAllocator, IDirect3DDevice9* aDevice)
23
: TextureClientRecycleAllocator(aAllocator), mDevice(aDevice) {}
24
25
already_AddRefed<TextureClient> CreateOrRecycleClient(
26
gfx::SurfaceFormat aFormat, const gfx::IntSize& aSize);
27
28
protected:
29
already_AddRefed<TextureClient> Allocate(
30
gfx::SurfaceFormat aFormat, gfx::IntSize aSize, BackendSelector aSelector,
31
TextureFlags aTextureFlags, TextureAllocationFlags aAllocFlags) override;
32
33
RefPtr<IDirect3DDevice9> mDevice;
34
};
35
36
/**
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.
40
*/
41
class DXGID3D9TextureData : public TextureData {
42
public:
43
static DXGID3D9TextureData* Create(gfx::IntSize aSize,
44
gfx::SurfaceFormat aFormat,
45
TextureFlags aFlags,
46
IDirect3DDevice9* aDevice);
47
48
virtual ~DXGID3D9TextureData();
49
50
void FillInfo(TextureData::Info& aInfo) const override;
51
52
bool Lock(OpenMode) override { return true; }
53
54
void Unlock() override {}
55
56
bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
57
58
void Deallocate(LayersIPCChannel* aAllocator) override {}
59
60
IDirect3DDevice9* GetD3D9Device() { return mDevice; }
61
IDirect3DTexture9* GetD3D9Texture() { return mTexture; }
62
HANDLE GetShareHandle() const { return mHandle; }
63
already_AddRefed<IDirect3DSurface9> GetD3D9Surface() const;
64
65
const D3DSURFACE_DESC& GetDesc() const { return mDesc; }
66
67
gfx::IntSize GetSize() const {
68
return gfx::IntSize(mDesc.Width, mDesc.Height);
69
}
70
71
protected:
72
DXGID3D9TextureData(gfx::SurfaceFormat aFormat, IDirect3DTexture9* aTexture,
73
HANDLE aHandle, IDirect3DDevice9* aDevice);
74
75
RefPtr<IDirect3DDevice9> mDevice;
76
RefPtr<IDirect3DTexture9> mTexture;
77
gfx::SurfaceFormat mFormat;
78
HANDLE mHandle;
79
D3DSURFACE_DESC mDesc;
80
};
81
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 {
87
public:
88
D3D9SurfaceImage();
89
virtual ~D3D9SurfaceImage();
90
91
HRESULT AllocateAndCopy(D3D9RecycleAllocator* aAllocator,
92
IDirect3DSurface9* aSurface,
93
const gfx::IntRect& aRegion);
94
95
// Returns the description of the shared surface.
96
const D3DSURFACE_DESC& GetDesc() const;
97
98
gfx::IntSize GetSize() const override;
99
100
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
101
102
TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
103
104
already_AddRefed<IDirect3DSurface9> GetD3D9Surface() const;
105
106
HANDLE GetShareHandle() const;
107
108
bool IsValid() const override { return mValid; }
109
110
void Invalidate() { mValid = false; }
111
112
private:
113
gfx::IntSize mSize;
114
RefPtr<TextureClient> mTextureClient;
115
RefPtr<IDirect3DTexture9> mTexture;
116
HANDLE mShareHandle;
117
D3DSURFACE_DESC mDesc;
118
bool mValid;
119
};
120
121
} // namespace layers
122
} // namespace mozilla
123
124
#endif // GFX_D3DSURFACEIMAGE_H