|
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_SOURCESURFACED2D1_H_ |
|
7 #define MOZILLA_GFX_SOURCESURFACED2D1_H_ |
|
8 |
|
9 #include "2D.h" |
|
10 #include "HelpersD2D.h" |
|
11 #include <vector> |
|
12 #include <d3d11.h> |
|
13 #include <d2d1_1.h> |
|
14 |
|
15 namespace mozilla { |
|
16 namespace gfx { |
|
17 |
|
18 class DrawTargetD2D1; |
|
19 |
|
20 class SourceSurfaceD2D1 : public SourceSurface |
|
21 { |
|
22 public: |
|
23 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D1) |
|
24 SourceSurfaceD2D1(ID2D1Image* aImage, ID2D1DeviceContext *aDC, |
|
25 SurfaceFormat aFormat, const IntSize &aSize, |
|
26 DrawTargetD2D1 *aDT = nullptr); |
|
27 ~SourceSurfaceD2D1(); |
|
28 |
|
29 virtual SurfaceType GetType() const { return SurfaceType::D2D1_1_IMAGE; } |
|
30 virtual IntSize GetSize() const { return mSize; } |
|
31 virtual SurfaceFormat GetFormat() const { return mFormat; } |
|
32 virtual TemporaryRef<DataSourceSurface> GetDataSurface(); |
|
33 |
|
34 ID2D1Image *GetImage() { return mImage; } |
|
35 |
|
36 void EnsureIndependent() { if (!mDrawTarget) return; DrawTargetWillChange(); } |
|
37 |
|
38 private: |
|
39 friend class DrawTargetD2D1; |
|
40 |
|
41 void EnsureRealizedBitmap(); |
|
42 |
|
43 // This function is called by the draw target this texture belongs to when |
|
44 // it is about to be changed. The texture will be required to make a copy |
|
45 // of itself when this happens. |
|
46 void DrawTargetWillChange(); |
|
47 |
|
48 // This will mark the surface as no longer depending on its drawtarget, |
|
49 // this may happen on destruction or copying. |
|
50 void MarkIndependent(); |
|
51 |
|
52 RefPtr<ID2D1Image> mImage; |
|
53 // This may be null if we were created for a non-bitmap image and have not |
|
54 // had a reason yet to realize ourselves. |
|
55 RefPtr<ID2D1Bitmap1> mRealizedBitmap; |
|
56 RefPtr<ID2D1DeviceContext> mDC; |
|
57 |
|
58 SurfaceFormat mFormat; |
|
59 IntSize mSize; |
|
60 RefPtr<DrawTargetD2D1> mDrawTarget; |
|
61 }; |
|
62 |
|
63 class DataSourceSurfaceD2D1 : public DataSourceSurface |
|
64 { |
|
65 public: |
|
66 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D1) |
|
67 DataSourceSurfaceD2D1(ID2D1Bitmap1 *aMappableBitmap, SurfaceFormat aFormat); |
|
68 ~DataSourceSurfaceD2D1(); |
|
69 |
|
70 virtual SurfaceType GetType() const { return SurfaceType::DATA; } |
|
71 virtual IntSize GetSize() const; |
|
72 virtual SurfaceFormat GetFormat() const { return mFormat; } |
|
73 virtual uint8_t *GetData(); |
|
74 virtual int32_t Stride(); |
|
75 virtual bool Map(MapType, MappedSurface *aMappedSurface); |
|
76 virtual void Unmap(); |
|
77 |
|
78 private: |
|
79 friend class SourceSurfaceD2DTarget; |
|
80 void EnsureMapped(); |
|
81 |
|
82 mutable RefPtr<ID2D1Bitmap1> mBitmap; |
|
83 SurfaceFormat mFormat; |
|
84 D2D1_MAPPED_RECT mMap; |
|
85 bool mMapped; |
|
86 }; |
|
87 |
|
88 } |
|
89 } |
|
90 |
|
91 #endif /* MOZILLA_GFX_SOURCESURFACED2D2TARGET_H_ */ |