gfx/2d/SourceSurfaceD2D.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:aaeff2aab135
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/. */
5
6 #ifndef MOZILLA_GFX_SOURCESURFACED2D_H_
7 #define MOZILLA_GFX_SOURCESURFACED2D_H_
8
9 #include "2D.h"
10 #include "HelpersD2D.h"
11 #include <vector>
12
13 namespace mozilla {
14 namespace gfx {
15
16 class DataSourceSurfaceD2D;
17
18 class SourceSurfaceD2D : public SourceSurface
19 {
20 public:
21 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D)
22 SourceSurfaceD2D();
23 ~SourceSurfaceD2D();
24
25 virtual SurfaceType GetType() const { return SurfaceType::D2D1_BITMAP; }
26 virtual IntSize GetSize() const;
27 virtual SurfaceFormat GetFormat() const;
28 virtual bool IsValid() const;
29
30 virtual TemporaryRef<DataSourceSurface> GetDataSurface();
31
32 ID2D1Bitmap *GetBitmap() { return mBitmap; }
33
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;
45
46 uint32_t GetByteSize() const;
47
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 };
54
55
56 class DataSourceSurfaceD2D : public DataSourceSurface
57 {
58 public:
59 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D)
60 DataSourceSurfaceD2D(SourceSurfaceD2D* aSourceSurface);
61 virtual ~DataSourceSurfaceD2D();
62
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();
69
70 bool IsValid()
71 {
72 return mTexture;
73 }
74
75 private:
76 void EnsureMappedTexture();
77
78 RefPtr<ID3D10Texture2D> mTexture;
79
80 D3D10_MAPPED_TEXTURE2D mData;
81
82 SurfaceFormat mFormat;
83 IntSize mSize;
84 bool mMapped;
85 };
86
87 }
88 }
89
90 #endif /* MOZILLA_GFX_SOURCESURFACED2D_H_ */

mercurial