gfx/layers/D3D9SurfaceImage.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e15aa6399747
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef GFX_D3DSURFACEIMAGE_H
7 #define GFX_D3DSURFACEIMAGE_H
8
9 #include "mozilla/RefPtr.h"
10 #include "ImageContainer.h"
11 #include "nsAutoPtr.h"
12 #include "d3d9.h"
13
14 namespace mozilla {
15 namespace layers {
16
17 // Image class that wraps a IDirect3DSurface9. This class copies the image
18 // passed into SetData(), so that it can be accessed from other D3D devices.
19 // This class also manages the synchronization of the copy, to ensure the
20 // resource is ready to use.
21 class D3D9SurfaceImage : public Image
22 , public ISharedImage {
23 public:
24
25 struct Data {
26 Data(IDirect3DSurface9* aSurface, const nsIntRect& aRegion)
27 : mSurface(aSurface), mRegion(aRegion) {}
28 RefPtr<IDirect3DSurface9> mSurface;
29 nsIntRect mRegion;
30 };
31
32 D3D9SurfaceImage();
33 virtual ~D3D9SurfaceImage();
34
35 virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
36
37 // Copies the surface into a sharable texture's surface, and initializes
38 // the image.
39 HRESULT SetData(const Data& aData);
40
41 // Returns the description of the shared surface.
42 const D3DSURFACE_DESC& GetDesc() const;
43
44 // Returns the HANDLE that can be used to open the image as a shared resource.
45 // If the operation to copy the original resource to the shared resource
46 // hasn't finished yet, this function blocks until the synchronization is
47 // complete.
48 HANDLE GetShareHandle();
49
50 gfx::IntSize GetSize() MOZ_OVERRIDE;
51
52 virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
53
54 virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
55 virtual uint8_t* GetBuffer() MOZ_OVERRIDE { return nullptr; }
56
57 private:
58
59 // Blocks the calling thread until the copy operation started in SetData()
60 // is complete, whereupon the texture is safe to use.
61 void EnsureSynchronized();
62
63 gfx::IntSize mSize;
64 RefPtr<IDirect3DTexture9> mTexture;
65 RefPtr<IDirect3DQuery9> mQuery;
66 RefPtr<TextureClient> mTextureClient;
67 HANDLE mShareHandle;
68 D3DSURFACE_DESC mDesc;
69 };
70
71 } // namepace layers
72 } // namespace mozilla
73
74 #endif // GFX_D3DSURFACEIMAGE_H

mercurial