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