Bug 1577498 - Part 3: Ensure actor and conduit cleanup r=rpl
[gecko.git] / image / RecyclingSourceSurface.h
blobb33ebd344a3492c976731e4193332e1debe1fdda
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"
12 namespace mozilla {
13 namespace image {
15 class imgFrame;
17 /**
18 * This surface subclass will prevent the underlying surface from being recycled
19 * as long as it is still alive. We will create this surface to wrap imgFrame's
20 * mLockedSurface, if we are accessing it on a path that will keep the surface
21 * alive for an indeterminate period of time (e.g. imgFrame::GetSourceSurface,
22 * imgFrame::Draw with a recording or capture DrawTarget).
24 class RecyclingSourceSurface final : public gfx::DataSourceSurface {
25 public:
26 RecyclingSourceSurface(imgFrame* aParent, gfx::DataSourceSurface* aSurface);
28 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(RecyclingSourceSurface, override);
30 uint8_t* GetData() override { return mSurface->GetData(); }
31 int32_t Stride() override { return mSurface->Stride(); }
32 gfx::SurfaceType GetType() const override { return mType; }
33 gfx::IntSize GetSize() const override { return mSurface->GetSize(); }
34 gfx::SurfaceFormat GetFormat() const override {
35 return mSurface->GetFormat();
38 void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut,
39 size_t& aNonHeapSizeOut, size_t& aExtHandlesOut,
40 uint64_t& aExtIdOut) const override {}
42 bool OnHeap() const override { return mSurface->OnHeap(); }
43 bool Map(MapType aType, MappedSurface* aMappedSurface) override {
44 return mSurface->Map(aType, aMappedSurface);
46 void Unmap() override { mSurface->Unmap(); }
48 gfx::DataSourceSurface* GetChildSurface() const { return mSurface; }
50 protected:
51 void GuaranteePersistance() override {}
53 ~RecyclingSourceSurface() override;
55 RefPtr<imgFrame> mParent;
56 RefPtr<DataSourceSurface> mSurface;
57 gfx::SurfaceType mType;
60 } // namespace image
61 } // namespace mozilla
63 #endif // mozilla_image_RecyclingSourceSurface_h