michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_D3DSURFACEIMAGE_H michael@0: #define GFX_D3DSURFACEIMAGE_H michael@0: michael@0: #include "mozilla/RefPtr.h" michael@0: #include "ImageContainer.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "d3d9.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: // Image class that wraps a IDirect3DSurface9. This class copies the image michael@0: // passed into SetData(), so that it can be accessed from other D3D devices. michael@0: // This class also manages the synchronization of the copy, to ensure the michael@0: // resource is ready to use. michael@0: class D3D9SurfaceImage : public Image michael@0: , public ISharedImage { michael@0: public: michael@0: michael@0: struct Data { michael@0: Data(IDirect3DSurface9* aSurface, const nsIntRect& aRegion) michael@0: : mSurface(aSurface), mRegion(aRegion) {} michael@0: RefPtr mSurface; michael@0: nsIntRect mRegion; michael@0: }; michael@0: michael@0: D3D9SurfaceImage(); michael@0: virtual ~D3D9SurfaceImage(); michael@0: michael@0: virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; } michael@0: michael@0: // Copies the surface into a sharable texture's surface, and initializes michael@0: // the image. michael@0: HRESULT SetData(const Data& aData); michael@0: michael@0: // Returns the description of the shared surface. michael@0: const D3DSURFACE_DESC& GetDesc() const; michael@0: michael@0: // Returns the HANDLE that can be used to open the image as a shared resource. michael@0: // If the operation to copy the original resource to the shared resource michael@0: // hasn't finished yet, this function blocks until the synchronization is michael@0: // complete. michael@0: HANDLE GetShareHandle(); michael@0: michael@0: gfx::IntSize GetSize() MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef GetAsSourceSurface() MOZ_OVERRIDE; michael@0: michael@0: virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE; michael@0: virtual uint8_t* GetBuffer() MOZ_OVERRIDE { return nullptr; } michael@0: michael@0: private: michael@0: michael@0: // Blocks the calling thread until the copy operation started in SetData() michael@0: // is complete, whereupon the texture is safe to use. michael@0: void EnsureSynchronized(); michael@0: michael@0: gfx::IntSize mSize; michael@0: RefPtr mTexture; michael@0: RefPtr mQuery; michael@0: RefPtr mTextureClient; michael@0: HANDLE mShareHandle; michael@0: D3DSURFACE_DESC mDesc; michael@0: }; michael@0: michael@0: } // namepace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif // GFX_D3DSURFACEIMAGE_H