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_SOURCESURFACED2D_H_
7 #define MOZILLA_GFX_SOURCESURFACED2D_H_
9 #include "2D.h"
10 #include "HelpersD2D.h"
11 #include <vector>
13 namespace mozilla {
14 namespace gfx {
16 class DataSourceSurfaceD2D;
18 class SourceSurfaceD2D : public SourceSurface
19 {
20 public:
21 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D)
22 SourceSurfaceD2D();
23 ~SourceSurfaceD2D();
25 virtual SurfaceType GetType() const { return SurfaceType::D2D1_BITMAP; }
26 virtual IntSize GetSize() const;
27 virtual SurfaceFormat GetFormat() const;
28 virtual bool IsValid() const;
30 virtual TemporaryRef<DataSourceSurface> GetDataSurface();
32 ID2D1Bitmap *GetBitmap() { return mBitmap; }
34 bool InitFromData(unsigned char *aData,
35 const IntSize &aSize,
36 int32_t aStride,
37 SurfaceFormat aFormat,
38 ID2D1RenderTarget *aRT);
39 bool InitFromTexture(ID3D10Texture2D *aTexture,
40 SurfaceFormat aFormat,
41 ID2D1RenderTarget *aRT);
42 private:
43 friend class DrawTargetD2D;
44 friend class DataSourceSurfaceD2D;
46 uint32_t GetByteSize() const;
48 RefPtr<ID2D1Bitmap> mBitmap;
49 // We need to keep this pointer here to check surface validity.
50 RefPtr<ID3D10Device> mDevice;
51 SurfaceFormat mFormat;
52 IntSize mSize;
53 };
56 class DataSourceSurfaceD2D : public DataSourceSurface
57 {
58 public:
59 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D)
60 DataSourceSurfaceD2D(SourceSurfaceD2D* aSourceSurface);
61 virtual ~DataSourceSurfaceD2D();
63 virtual unsigned char* GetData();
64 virtual int32_t Stride();
65 virtual IntSize GetSize() const;
66 virtual SurfaceFormat GetFormat() const;
67 virtual bool Map(MapType, MappedSurface *aMappedSurface);
68 virtual void Unmap();
70 bool IsValid()
71 {
72 return mTexture;
73 }
75 private:
76 void EnsureMappedTexture();
78 RefPtr<ID3D10Texture2D> mTexture;
80 D3D10_MAPPED_TEXTURE2D mData;
82 SurfaceFormat mFormat;
83 IntSize mSize;
84 bool mMapped;
85 };
87 }
88 }
90 #endif /* MOZILLA_GFX_SOURCESURFACED2D_H_ */