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 MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ |
michael@0 | 7 | #define MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "2D.h" |
michael@0 | 10 | #include "HelpersD2D.h" |
michael@0 | 11 | #include <vector> |
michael@0 | 12 | #include <d3d10_1.h> |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace gfx { |
michael@0 | 16 | |
michael@0 | 17 | class DrawTargetD2D; |
michael@0 | 18 | |
michael@0 | 19 | class SourceSurfaceD2DTarget : public SourceSurface |
michael@0 | 20 | { |
michael@0 | 21 | public: |
michael@0 | 22 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2DTarget) |
michael@0 | 23 | SourceSurfaceD2DTarget(DrawTargetD2D* aDrawTarget, ID3D10Texture2D* aTexture, |
michael@0 | 24 | SurfaceFormat aFormat); |
michael@0 | 25 | ~SourceSurfaceD2DTarget(); |
michael@0 | 26 | |
michael@0 | 27 | virtual SurfaceType GetType() const { return SurfaceType::D2D1_DRAWTARGET; } |
michael@0 | 28 | virtual IntSize GetSize() const; |
michael@0 | 29 | virtual SurfaceFormat GetFormat() const; |
michael@0 | 30 | virtual TemporaryRef<DataSourceSurface> GetDataSurface(); |
michael@0 | 31 | virtual void *GetNativeSurface(NativeSurfaceType aType); |
michael@0 | 32 | |
michael@0 | 33 | DrawTargetD2D* GetDT() { return mDrawTarget; } |
michael@0 | 34 | ID2D1Bitmap *GetBitmap(ID2D1RenderTarget *aRT); |
michael@0 | 35 | |
michael@0 | 36 | private: |
michael@0 | 37 | friend class DrawTargetD2D; |
michael@0 | 38 | |
michael@0 | 39 | ID3D10ShaderResourceView *GetSRView(); |
michael@0 | 40 | |
michael@0 | 41 | // This function is called by the draw target this texture belongs to when |
michael@0 | 42 | // it is about to be changed. The texture will be required to make a copy |
michael@0 | 43 | // of itself when this happens. |
michael@0 | 44 | void DrawTargetWillChange(); |
michael@0 | 45 | |
michael@0 | 46 | // This will mark the surface as no longer depending on its drawtarget, |
michael@0 | 47 | // this may happen on destruction or copying. |
michael@0 | 48 | void MarkIndependent(); |
michael@0 | 49 | |
michael@0 | 50 | RefPtr<ID3D10ShaderResourceView> mSRView; |
michael@0 | 51 | RefPtr<ID2D1Bitmap> mBitmap; |
michael@0 | 52 | // Non-null if this is a "lazy copy" of the given draw target. |
michael@0 | 53 | // Null if we've made a copy. The target is not kept alive, otherwise we'd |
michael@0 | 54 | // have leaks since it might keep us alive. If the target is destroyed, it |
michael@0 | 55 | // will notify us. |
michael@0 | 56 | DrawTargetD2D* mDrawTarget; |
michael@0 | 57 | mutable RefPtr<ID3D10Texture2D> mTexture; |
michael@0 | 58 | SurfaceFormat mFormat; |
michael@0 | 59 | bool mOwnsCopy; |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | class DataSourceSurfaceD2DTarget : public DataSourceSurface |
michael@0 | 63 | { |
michael@0 | 64 | public: |
michael@0 | 65 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2DTarget) |
michael@0 | 66 | DataSourceSurfaceD2DTarget(SurfaceFormat aFormat); |
michael@0 | 67 | ~DataSourceSurfaceD2DTarget(); |
michael@0 | 68 | |
michael@0 | 69 | virtual SurfaceType GetType() const { return SurfaceType::DATA; } |
michael@0 | 70 | virtual IntSize GetSize() const; |
michael@0 | 71 | virtual SurfaceFormat GetFormat() const; |
michael@0 | 72 | virtual uint8_t *GetData(); |
michael@0 | 73 | virtual int32_t Stride(); |
michael@0 | 74 | virtual bool Map(MapType, MappedSurface *aMappedSurface); |
michael@0 | 75 | virtual void Unmap(); |
michael@0 | 76 | |
michael@0 | 77 | private: |
michael@0 | 78 | friend class SourceSurfaceD2DTarget; |
michael@0 | 79 | void EnsureMapped(); |
michael@0 | 80 | |
michael@0 | 81 | mutable RefPtr<ID3D10Texture2D> mTexture; |
michael@0 | 82 | SurfaceFormat mFormat; |
michael@0 | 83 | D3D10_MAPPED_TEXTURE2D mMap; |
michael@0 | 84 | bool mMapped; |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | #endif /* MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ */ |