Bug 1444940 [wpt PR 9917] - Writable streams: test changes to abort() under error...
[gecko.git] / gfx / 2d / SourceSurfaceCapture.h
blobfef5a463b53257df2881d1d2550b3a4cdf88d81f
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_2d_SourceSurfaceCapture_h
8 #define mozilla_gfx_2d_SourceSurfaceCapture_h
10 #include "2D.h"
11 #include "CaptureCommandList.h"
12 #include "mozilla/Mutex.h"
14 namespace mozilla {
15 namespace gfx {
17 class DrawTargetCaptureImpl;
19 class SourceSurfaceCapture : public SourceSurface
21 friend class DrawTargetCaptureImpl;
22 public:
23 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceCapture, override)
25 explicit SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner);
26 explicit SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner,
27 LuminanceType aLuminanceType,
28 float aOpacity);
29 ~SourceSurfaceCapture();
31 SurfaceType GetType() const override { return SurfaceType::CAPTURE; }
32 IntSize GetSize() const override { return mSize; }
33 SurfaceFormat GetFormat() const override { return mFormat; }
35 bool IsValid() const override;
36 already_AddRefed<DataSourceSurface> GetDataSurface() override;
38 // The backend hint is not guaranteed to be honored, so callers must check
39 // the resulting type if needed.
40 RefPtr<SourceSurface> Resolve(BackendType aBackendType = BackendType::NONE);
42 protected:
43 RefPtr<SourceSurface> ResolveImpl(BackendType aBackendType);
44 void DrawTargetWillDestroy();
45 void DrawTargetWillChange();
47 private:
48 IntSize mSize;
49 SurfaceFormat mFormat;
50 int32_t mStride;
51 int32_t mSurfaceAllocationSize;
52 RefPtr<DrawTarget> mRefDT;
53 DrawTargetCaptureImpl* mOwner;
54 CaptureCommandList mCommands;
55 bool mHasCommandList;
57 bool mShouldResolveToLuminance;
58 LuminanceType mLuminanceType;
59 float mOpacity;
61 // Note that we have to keep a reference around. Internal methods like
62 // GetSkImageForSurface expect their callers to hold a reference, which
63 // isn't easily possible for nested surfaces.
64 mutable Mutex mLock;
65 RefPtr<SourceSurface> mResolved;
68 } // namespace gfx
69 } // namespace mozilla
71 #endif // mozilla_gfx_2d_SourceSurfaceCapture_h