Bug 1866777 - Disable test_race_cache_with_network.js on windows opt for frequent...
[gecko.git] / gfx / 2d / SourceSurfaceSkia.h
blobe0f085d2d4fe4de5f0fe423ed437d379136f7399
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 "mozilla/Mutex.h"
12 #include "skia/include/core/SkRefCnt.h"
14 class SkImage;
15 class SkSurface;
17 namespace mozilla {
19 namespace gfx {
21 class DrawTargetSkia;
22 class SnapshotLock;
24 class SourceSurfaceSkia : public DataSourceSurface {
25 public:
26 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia, override)
28 SourceSurfaceSkia();
29 virtual ~SourceSurfaceSkia();
31 SurfaceType GetType() const override { return SurfaceType::SKIA; }
32 IntSize GetSize() const override;
33 SurfaceFormat GetFormat() const override;
35 void GiveSurface(SkSurface* aSurface);
37 sk_sp<SkImage> GetImage(Maybe<MutexAutoLock>* aLock);
39 bool InitFromData(unsigned char* aData, const IntSize& aSize, int32_t aStride,
40 SurfaceFormat aFormat);
42 bool InitFromImage(const sk_sp<SkImage>& aImage,
43 SurfaceFormat aFormat = SurfaceFormat::UNKNOWN,
44 DrawTargetSkia* aOwner = nullptr);
46 already_AddRefed<SourceSurface> ExtractSubrect(const IntRect& aRect) override;
48 uint8_t* GetData() override;
50 /**
51 * The caller is responsible for ensuring aMappedSurface is not null.
53 bool Map(MapType, MappedSurface* aMappedSurface) override;
55 void Unmap() override;
57 int32_t Stride() override { return mStride; }
59 private:
60 friend class DrawTargetSkia;
62 void DrawTargetWillChange();
64 sk_sp<SkImage> mImage;
65 // This keeps a surface alive if needed because its DrawTarget has gone away.
66 sk_sp<SkSurface> mSurface;
67 SurfaceFormat mFormat;
68 IntSize mSize;
69 int32_t mStride;
70 Atomic<DrawTargetSkia*> mDrawTarget;
71 Mutex mChangeMutex MOZ_UNANNOTATED;
72 bool mIsMapped;
75 } // namespace gfx
76 } // namespace mozilla
78 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */