1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/D3D9SurfaceImage.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef GFX_D3DSURFACEIMAGE_H 1.10 +#define GFX_D3DSURFACEIMAGE_H 1.11 + 1.12 +#include "mozilla/RefPtr.h" 1.13 +#include "ImageContainer.h" 1.14 +#include "nsAutoPtr.h" 1.15 +#include "d3d9.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace layers { 1.19 + 1.20 +// Image class that wraps a IDirect3DSurface9. This class copies the image 1.21 +// passed into SetData(), so that it can be accessed from other D3D devices. 1.22 +// This class also manages the synchronization of the copy, to ensure the 1.23 +// resource is ready to use. 1.24 +class D3D9SurfaceImage : public Image 1.25 + , public ISharedImage { 1.26 +public: 1.27 + 1.28 + struct Data { 1.29 + Data(IDirect3DSurface9* aSurface, const nsIntRect& aRegion) 1.30 + : mSurface(aSurface), mRegion(aRegion) {} 1.31 + RefPtr<IDirect3DSurface9> mSurface; 1.32 + nsIntRect mRegion; 1.33 + }; 1.34 + 1.35 + D3D9SurfaceImage(); 1.36 + virtual ~D3D9SurfaceImage(); 1.37 + 1.38 + virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; } 1.39 + 1.40 + // Copies the surface into a sharable texture's surface, and initializes 1.41 + // the image. 1.42 + HRESULT SetData(const Data& aData); 1.43 + 1.44 + // Returns the description of the shared surface. 1.45 + const D3DSURFACE_DESC& GetDesc() const; 1.46 + 1.47 + // Returns the HANDLE that can be used to open the image as a shared resource. 1.48 + // If the operation to copy the original resource to the shared resource 1.49 + // hasn't finished yet, this function blocks until the synchronization is 1.50 + // complete. 1.51 + HANDLE GetShareHandle(); 1.52 + 1.53 + gfx::IntSize GetSize() MOZ_OVERRIDE; 1.54 + 1.55 + virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE; 1.56 + 1.57 + virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE; 1.58 + virtual uint8_t* GetBuffer() MOZ_OVERRIDE { return nullptr; } 1.59 + 1.60 +private: 1.61 + 1.62 + // Blocks the calling thread until the copy operation started in SetData() 1.63 + // is complete, whereupon the texture is safe to use. 1.64 + void EnsureSynchronized(); 1.65 + 1.66 + gfx::IntSize mSize; 1.67 + RefPtr<IDirect3DTexture9> mTexture; 1.68 + RefPtr<IDirect3DQuery9> mQuery; 1.69 + RefPtr<TextureClient> mTextureClient; 1.70 + HANDLE mShareHandle; 1.71 + D3DSURFACE_DESC mDesc; 1.72 +}; 1.73 + 1.74 +} // namepace layers 1.75 +} // namespace mozilla 1.76 + 1.77 +#endif // GFX_D3DSURFACEIMAGE_H