1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_SOURCESURFACED2D1_H_
8 #define MOZILLA_GFX_SOURCESURFACED2D1_H_
11 #include "HelpersD2D.h"
21 class SourceSurfaceD2D1
: public SourceSurface
{
23 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D1
, override
)
25 SourceSurfaceD2D1(ID2D1Image
* aImage
, ID2D1DeviceContext
* aDC
,
26 SurfaceFormat aFormat
, const IntSize
& aSize
,
27 DrawTargetD2D1
* aDT
= nullptr);
30 SurfaceType
GetType() const override
{ return SurfaceType::D2D1_1_IMAGE
; }
31 IntSize
GetSize() const override
{ return mSize
; }
32 SurfaceFormat
GetFormat() const override
{ return mFormat
; }
33 bool IsValid() const override
;
34 already_AddRefed
<DataSourceSurface
> GetDataSurface() override
;
36 ID2D1Image
* GetImage() { return mImage
; }
38 void EnsureIndependent() {
39 if (!mDrawTarget
) return;
40 DrawTargetWillChange();
44 friend class DrawTargetD2D1
;
46 bool EnsureRealizedBitmap();
48 // This function is called by the draw target this texture belongs to when
49 // it is about to be changed. The texture will be required to make a copy
50 // of itself when this happens.
51 void DrawTargetWillChange();
53 // This will mark the surface as no longer depending on its drawtarget,
54 // this may happen on destruction or copying.
55 void MarkIndependent();
57 RefPtr
<ID2D1Image
> mImage
;
58 // This may be null if we were created for a non-bitmap image and have not
59 // had a reason yet to realize ourselves.
60 RefPtr
<ID2D1Bitmap1
> mRealizedBitmap
;
61 RefPtr
<ID2D1DeviceContext
> mDC
;
62 // Keep this around to verify whether out image is still valid in the future.
63 RefPtr
<ID2D1Device
> mDevice
;
65 const SurfaceFormat mFormat
;
67 DrawTargetD2D1
* mDrawTarget
;
68 std::shared_ptr
<Mutex
> mSnapshotLock
;
72 class DataSourceSurfaceD2D1
: public DataSourceSurface
{
74 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D1
, override
)
76 DataSourceSurfaceD2D1(ID2D1Bitmap1
* aMappableBitmap
, SurfaceFormat aFormat
);
77 ~DataSourceSurfaceD2D1();
79 SurfaceType
GetType() const override
{ return SurfaceType::DATA
; }
80 IntSize
GetSize() const override
;
81 SurfaceFormat
GetFormat() const override
{ return mFormat
; }
82 bool IsValid() const override
{ return !!mBitmap
; }
83 uint8_t* GetData() override
;
84 int32_t Stride() override
;
85 bool Map(MapType
, MappedSurface
* aMappedSurface
) override
;
86 void Unmap() override
;
89 friend class SourceSurfaceD2DTarget
;
92 mutable RefPtr
<ID2D1Bitmap1
> mBitmap
;
93 SurfaceFormat mFormat
;
94 D2D1_MAPPED_RECT mMap
;
100 } // namespace mozilla
102 #endif /* MOZILLA_GFX_SOURCESURFACED2D2TARGET_H_ */