1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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_image_RecyclingSourceSurface_h
8 #define mozilla_image_RecyclingSourceSurface_h
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/NotNull.h"
19 * This surface subclass will prevent the underlying surface from being recycled
20 * as long as it is still alive. We will create this surface to wrap imgFrame's
21 * mLockedSurface, if we are accessing it on a path that will keep the surface
22 * alive for an indeterminate period of time (e.g. imgFrame::GetSourceSurface,
23 * imgFrame::Draw with a recording or capture DrawTarget).
25 class RecyclingSourceSurface final
: public gfx::DataSourceSurface
{
27 RecyclingSourceSurface(imgFrame
* aParent
, gfx::DataSourceSurface
* aSurface
);
29 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(RecyclingSourceSurface
, override
);
31 uint8_t* GetData() override
{ return mSurface
->GetData(); }
32 int32_t Stride() override
{ return mSurface
->Stride(); }
33 gfx::SurfaceType
GetType() const override
{ return mType
; }
34 gfx::IntSize
GetSize() const override
{ return mSurface
->GetSize(); }
35 gfx::SurfaceFormat
GetFormat() const override
{
36 return mSurface
->GetFormat();
39 bool OnHeap() const override
{ return mSurface
->OnHeap(); }
40 bool Map(MapType aType
, MappedSurface
* aMappedSurface
) override
{
41 return mSurface
->Map(aType
, aMappedSurface
);
43 void Unmap() override
{ mSurface
->Unmap(); }
45 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
46 SizeOfInfo
& aInfo
) const override
{
48 mSurface
->SizeOfExcludingThis(aMallocSizeOf
, aInfo
);
51 gfx::DataSourceSurface
* GetChildSurface() const { return mSurface
.get(); }
54 void GuaranteePersistance() override
{}
56 ~RecyclingSourceSurface() override
;
58 NotNull
<RefPtr
<imgFrame
>> mParent
;
59 NotNull
<RefPtr
<DataSourceSurface
>> mSurface
;
60 gfx::SurfaceType mType
;
64 } // namespace mozilla
66 #endif // mozilla_image_RecyclingSourceSurface_h