2017-10-28 02:10:06 +03: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 15:12:37 +04: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 23:55:03 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_SOURCESURFACESKIA_H_
|
|
|
|
#define MOZILLA_GFX_SOURCESURFACESKIA_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include <vector>
|
2017-10-03 06:23:09 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/core/SkCanvas.h"
|
2016-10-25 05:40:59 +03:00
|
|
|
#include "skia/include/core/SkImage.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-11-11 23:14:00 +03:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
namespace gfx {
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
class DrawTargetSkia;
|
2017-11-08 22:49:40 +03:00
|
|
|
class SnapshotLock;
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
class SourceSurfaceSkia : public DataSourceSurface {
|
|
|
|
public:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia, override)
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
SourceSurfaceSkia();
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~SourceSurfaceSkia();
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
SurfaceType GetType() const override { return SurfaceType::SKIA; }
|
|
|
|
IntSize GetSize() const override;
|
|
|
|
SurfaceFormat GetFormat() const override;
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2017-12-06 06:59:19 +03:00
|
|
|
// This is only ever called by the DT destructor, which can only ever happen
|
|
|
|
// from one place at a time. Therefore it doesn't need to hold the ChangeMutex
|
|
|
|
// as mSurface is never read to directly and is just there to keep the object
|
|
|
|
// alive, which itself is refcounted in a thread-safe manner.
|
|
|
|
void GiveSurface(sk_sp<SkSurface>& aSurface) {
|
|
|
|
mSurface = aSurface;
|
|
|
|
mDrawTarget = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-10-03 06:23:09 +03:00
|
|
|
sk_sp<SkImage> GetImage();
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
bool InitFromData(unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
|
|
|
SurfaceFormat aFormat);
|
|
|
|
|
2016-11-15 01:16:18 +03:00
|
|
|
bool InitFromImage(const sk_sp<SkImage>& aImage,
|
2016-10-25 05:40:59 +03:00
|
|
|
SurfaceFormat aFormat = SurfaceFormat::UNKNOWN,
|
2017-12-06 06:59:19 +03:00
|
|
|
DrawTargetSkia* aOwner = nullptr);
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
uint8_t* GetData() override;
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2017-10-03 06:23:09 +03:00
|
|
|
/**
|
|
|
|
* The caller is responsible for ensuring aMappedSurface is not null.
|
|
|
|
*/
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Map(MapType, MappedSurface* aMappedSurface) override;
|
2017-10-03 06:23:09 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Unmap() override;
|
2017-10-03 06:23:09 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t Stride() override { return mStride; }
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class DrawTargetSkia;
|
2015-05-26 10:00:19 +03:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void DrawTargetWillChange();
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> mImage;
|
2017-12-06 06:59:19 +03:00
|
|
|
// This keeps a surface alive if needed because its DrawTarget has gone away.
|
|
|
|
sk_sp<SkSurface> mSurface;
|
2011-11-02 23:55:03 +04:00
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
|
|
|
int32_t mStride;
|
2017-12-06 06:59:19 +03:00
|
|
|
DrawTargetSkia* mDrawTarget;
|
2017-10-03 06:23:09 +03:00
|
|
|
Mutex mChangeMutex;
|
2018-11-07 00:04:02 +03:00
|
|
|
bool mIsMapped;
|
2011-11-02 23:55:03 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */
|