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