gfx/2d/SourceSurfaceD2DTarget.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:56a79301c53f
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_SOURCESURFACED2DTARGET_H_
7 #define MOZILLA_GFX_SOURCESURFACED2DTARGET_H_
8
9 #include "2D.h"
10 #include "HelpersD2D.h"
11 #include <vector>
12 #include <d3d10_1.h>
13
14 namespace mozilla {
15 namespace gfx {
16
17 class DrawTargetD2D;
18
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();
26
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);
32
33 DrawTargetD2D* GetDT() { return mDrawTarget; }
34 ID2D1Bitmap *GetBitmap(ID2D1RenderTarget *aRT);
35
36 private:
37 friend class DrawTargetD2D;
38
39 ID3D10ShaderResourceView *GetSRView();
40
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();
45
46 // This will mark the surface as no longer depending on its drawtarget,
47 // this may happen on destruction or copying.
48 void MarkIndependent();
49
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 };
61
62 class DataSourceSurfaceD2DTarget : public DataSourceSurface
63 {
64 public:
65 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2DTarget)
66 DataSourceSurfaceD2DTarget(SurfaceFormat aFormat);
67 ~DataSourceSurfaceD2DTarget();
68
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();
76
77 private:
78 friend class SourceSurfaceD2DTarget;
79 void EnsureMapped();
80
81 mutable RefPtr<ID3D10Texture2D> mTexture;
82 SurfaceFormat mFormat;
83 D3D10_MAPPED_TEXTURE2D mMap;
84 bool mMapped;
85 };
86
87 }
88 }
89
90 #endif /* MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ */

mercurial