Bug 1641886 [wpt PR 23851] - Support interpolating contain-intrinsic-size, a=testonly
[gecko.git] / gfx / 2d / SourceSurfaceSkia.h
blobfb5eb4864fa2467b28404ad98e3695e4577a5206
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_SOURCESURFACESKIA_H_
8 #define MOZILLA_GFX_SOURCESURFACESKIA_H_
10 #include "2D.h"
11 #include <vector>
12 #include "mozilla/Mutex.h"
13 #include "skia/include/core/SkCanvas.h"
14 #include "skia/include/core/SkImage.h"
16 namespace mozilla {
18 namespace gfx {
20 class DrawTargetSkia;
21 class SnapshotLock;
23 class SourceSurfaceSkia : public DataSourceSurface {
24 public:
25 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia, override)
27 SourceSurfaceSkia();
28 virtual ~SourceSurfaceSkia();
30 SurfaceType GetType() const override { return SurfaceType::SKIA; }
31 IntSize GetSize() const override;
32 SurfaceFormat GetFormat() const override;
34 // This is only ever called by the DT destructor, which can only ever happen
35 // from one place at a time. Therefore it doesn't need to hold the ChangeMutex
36 // as mSurface is never read to directly and is just there to keep the object
37 // alive, which itself is refcounted in a thread-safe manner.
38 void GiveSurface(sk_sp<SkSurface>& aSurface) {
39 mSurface = aSurface;
40 mDrawTarget = nullptr;
43 sk_sp<SkImage> GetImage();
45 bool InitFromData(unsigned char* aData, const IntSize& aSize, int32_t aStride,
46 SurfaceFormat aFormat);
48 bool InitFromImage(const sk_sp<SkImage>& aImage,
49 SurfaceFormat aFormat = SurfaceFormat::UNKNOWN,
50 DrawTargetSkia* aOwner = nullptr);
52 uint8_t* GetData() override;
54 /**
55 * The caller is responsible for ensuring aMappedSurface is not null.
57 bool Map(MapType, MappedSurface* aMappedSurface) override;
59 void Unmap() override;
61 int32_t Stride() override { return mStride; }
63 private:
64 friend class DrawTargetSkia;
66 void DrawTargetWillChange();
68 sk_sp<SkImage> mImage;
69 // This keeps a surface alive if needed because its DrawTarget has gone away.
70 sk_sp<SkSurface> mSurface;
71 SurfaceFormat mFormat;
72 IntSize mSize;
73 int32_t mStride;
74 DrawTargetSkia* mDrawTarget;
75 Mutex mChangeMutex;
76 bool mIsMapped;
79 } // namespace gfx
80 } // namespace mozilla
82 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */