gfx/layers/D3D9SurfaceImage.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

     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/. */
     6 #ifndef GFX_D3DSURFACEIMAGE_H
     7 #define GFX_D3DSURFACEIMAGE_H
     9 #include "mozilla/RefPtr.h"
    10 #include "ImageContainer.h"
    11 #include "nsAutoPtr.h"
    12 #include "d3d9.h"
    14 namespace mozilla {
    15 namespace layers {
    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:
    25   struct Data {
    26     Data(IDirect3DSurface9* aSurface, const nsIntRect& aRegion)
    27       : mSurface(aSurface), mRegion(aRegion) {}
    28     RefPtr<IDirect3DSurface9> mSurface;
    29     nsIntRect mRegion;
    30   };
    32   D3D9SurfaceImage();
    33   virtual ~D3D9SurfaceImage();
    35   virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
    37   // Copies the surface into a sharable texture's surface, and initializes
    38   // the image.
    39   HRESULT SetData(const Data& aData);
    41   // Returns the description of the shared surface.
    42   const D3DSURFACE_DESC& GetDesc() const;
    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();
    50   gfx::IntSize GetSize() MOZ_OVERRIDE;
    52   virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
    54   virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
    55   virtual uint8_t* GetBuffer() MOZ_OVERRIDE { return nullptr; }
    57 private:
    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();
    63   gfx::IntSize mSize;
    64   RefPtr<IDirect3DTexture9> mTexture;
    65   RefPtr<IDirect3DQuery9> mQuery;
    66   RefPtr<TextureClient> mTextureClient;
    67   HANDLE mShareHandle;
    68   D3DSURFACE_DESC mDesc;
    69 };
    71 } // namepace layers
    72 } // namespace mozilla
    74 #endif // GFX_D3DSURFACEIMAGE_H

mercurial