2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 19:55:03 +00:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_SOURCESURFACESKIA_H_
|
|
|
|
#define MOZILLA_GFX_SOURCESURFACESKIA_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
2017-10-03 03:23:09 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2021-11-11 07:16:57 +00:00
|
|
|
#include "skia/include/core/SkRefCnt.h"
|
|
|
|
|
|
|
|
class SkImage;
|
|
|
|
class SkSurface;
|
2011-11-02 19:55:03 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-11-11 20:14:00 +00:00
|
|
|
|
2011-11-02 19:55:03 +00:00
|
|
|
namespace gfx {
|
|
|
|
|
2011-11-02 19:55:03 +00:00
|
|
|
class DrawTargetSkia;
|
2017-11-08 19:49:40 +00:00
|
|
|
class SnapshotLock;
|
2011-11-02 19:55:03 +00:00
|
|
|
|
2011-11-02 19:55:03 +00:00
|
|
|
class SourceSurfaceSkia : public DataSourceSurface {
|
|
|
|
public:
|
2017-11-06 03:37:28 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia, override)
|
|
|
|
|
2011-11-02 19:55:03 +00:00
|
|
|
SourceSurfaceSkia();
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~SourceSurfaceSkia();
|
2011-11-02 19:55:03 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
SurfaceType GetType() const override { return SurfaceType::SKIA; }
|
|
|
|
IntSize GetSize() const override;
|
|
|
|
SurfaceFormat GetFormat() const override;
|
2011-11-02 19:55:03 +00:00
|
|
|
|
2021-11-11 07:16:57 +00:00
|
|
|
void GiveSurface(SkSurface* aSurface);
|
2017-12-06 03:59:19 +00:00
|
|
|
|
2020-10-29 17:19:52 +00:00
|
|
|
sk_sp<SkImage> GetImage(Maybe<MutexAutoLock>* aLock);
|
2011-11-02 19:55:03 +00:00
|
|
|
|
|
|
|
bool InitFromData(unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
|
|
|
SurfaceFormat aFormat);
|
|
|
|
|
2016-11-14 22:16:18 +00:00
|
|
|
bool InitFromImage(const sk_sp<SkImage>& aImage,
|
2016-10-25 02:40:59 +00:00
|
|
|
SurfaceFormat aFormat = SurfaceFormat::UNKNOWN,
|
2017-12-06 03:59:19 +00:00
|
|
|
DrawTargetSkia* aOwner = nullptr);
|
2011-11-02 19:55:03 +00:00
|
|
|
|
2022-12-07 21:06:32 +00:00
|
|
|
already_AddRefed<SourceSurface> ExtractSubrect(const IntRect& aRect) override;
|
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
uint8_t* GetData() override;
|
2011-11-02 19:55:03 +00:00
|
|
|
|
2017-10-03 03:23:09 +00:00
|
|
|
/**
|
|
|
|
* The caller is responsible for ensuring aMappedSurface is not null.
|
|
|
|
*/
|
2019-04-11 12:36:51 +00:00
|
|
|
bool Map(MapType, MappedSurface* aMappedSurface) override;
|
2017-10-03 03:23:09 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void Unmap() override;
|
2017-10-03 03:23:09 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
int32_t Stride() override { return mStride; }
|
2011-11-02 19:55:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class DrawTargetSkia;
|
2015-05-26 07:00:19 +00:00
|
|
|
|
2011-11-02 19:55:03 +00:00
|
|
|
void DrawTargetWillChange();
|
|
|
|
|
2016-10-25 02:40:59 +00:00
|
|
|
sk_sp<SkImage> mImage;
|
2017-12-06 03:59:19 +00:00
|
|
|
// This keeps a surface alive if needed because its DrawTarget has gone away.
|
|
|
|
sk_sp<SkSurface> mSurface;
|
2011-11-02 19:55:03 +00:00
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
|
|
|
int32_t mStride;
|
2020-11-12 02:30:53 +00:00
|
|
|
Atomic<DrawTargetSkia*> mDrawTarget;
|
2022-03-16 18:47:08 +00:00
|
|
|
Mutex mChangeMutex MOZ_UNANNOTATED;
|
2018-11-06 21:04:02 +00:00
|
|
|
bool mIsMapped;
|
2011-11-02 19:55:03 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-11-02 19:55:03 +00:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */
|