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 19:27:30 +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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_SOURCESURFACERAWDATA_H_
|
|
|
|
#define MOZILLA_GFX_SOURCESURFACERAWDATA_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
2013-11-20 20:20:51 +04:00
|
|
|
#include "Tools.h"
|
2015-07-16 10:36:00 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2012-05-21 19:27:30 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class SourceSurfaceRawData : public DataSourceSurface {
|
|
|
|
public:
|
2015-07-17 19:58:16 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRawData, override)
|
2016-05-10 21:44:00 +03:00
|
|
|
|
2015-07-16 10:36:00 +03:00
|
|
|
SourceSurfaceRawData()
|
2016-05-10 21:44:00 +03:00
|
|
|
: mRawData(0),
|
|
|
|
mStride(0),
|
|
|
|
mFormat(SurfaceFormat::UNKNOWN),
|
|
|
|
mOwnData(false),
|
|
|
|
mDeallocator(nullptr),
|
|
|
|
mClosure(nullptr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-10 21:44:00 +03:00
|
|
|
virtual ~SourceSurfaceRawData() {
|
|
|
|
if (mDeallocator) {
|
|
|
|
mDeallocator(mClosure);
|
|
|
|
} else if (mOwnData) {
|
|
|
|
// The buffer is created from GuaranteePersistance().
|
|
|
|
delete[] mRawData;
|
|
|
|
}
|
2015-07-16 10:36:00 +03:00
|
|
|
}
|
2012-05-21 19:27:30 +04:00
|
|
|
|
2015-07-17 19:58:16 +03:00
|
|
|
virtual uint8_t* GetData() override { return mRawData; }
|
|
|
|
virtual int32_t Stride() override { return mStride; }
|
2012-05-21 19:27:30 +04:00
|
|
|
|
2015-07-17 19:58:16 +03:00
|
|
|
virtual SurfaceType GetType() const override { return SurfaceType::DATA; }
|
|
|
|
virtual IntSize GetSize() const override { return mSize; }
|
|
|
|
virtual SurfaceFormat GetFormat() const override { return mFormat; }
|
2012-05-21 19:27:30 +04:00
|
|
|
|
2015-07-17 19:58:16 +03:00
|
|
|
virtual void GuaranteePersistance() override;
|
2014-08-01 20:01:47 +04:00
|
|
|
|
2012-05-21 19:27:30 +04:00
|
|
|
private:
|
2016-05-10 21:44:00 +03:00
|
|
|
friend class Factory;
|
|
|
|
|
|
|
|
// If we have a custom deallocator, the |aData| will be released using the
|
2016-09-15 17:36:21 +03:00
|
|
|
// custom deallocator and |aClosure| in dtor. The assumption is that the
|
|
|
|
// caller will check for valid size and stride before making this call.
|
2016-05-10 21:44:00 +03:00
|
|
|
void InitWrappingData(unsigned char* aData, const IntSize& aSize,
|
|
|
|
int32_t aStride, SurfaceFormat aFormat,
|
|
|
|
Factory::SourceSurfaceDeallocator aDeallocator,
|
|
|
|
void* aClosure);
|
|
|
|
|
2012-05-21 19:27:30 +04:00
|
|
|
uint8_t* mRawData;
|
|
|
|
int32_t mStride;
|
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
2016-05-10 21:44:00 +03:00
|
|
|
|
2012-05-21 19:27:30 +04:00
|
|
|
bool mOwnData;
|
2016-05-10 21:44:00 +03:00
|
|
|
Factory::SourceSurfaceDeallocator mDeallocator;
|
|
|
|
void* mClosure;
|
2012-05-21 19:27:30 +04:00
|
|
|
};
|
|
|
|
|
2013-07-17 18:07:44 +04:00
|
|
|
class SourceSurfaceAlignedRawData : public DataSourceSurface {
|
|
|
|
public:
|
2015-07-17 19:58:16 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceAlignedRawData,
|
|
|
|
override)
|
2016-05-10 21:44:00 +03:00
|
|
|
SourceSurfaceAlignedRawData() : mStride(0), mFormat(SurfaceFormat::UNKNOWN) {}
|
2015-07-16 10:36:00 +03:00
|
|
|
~SourceSurfaceAlignedRawData() {}
|
2013-07-17 18:07:44 +04:00
|
|
|
|
2018-02-22 22:26:29 +03:00
|
|
|
bool Init(const IntSize& aSize, SurfaceFormat aFormat, bool aClearMem,
|
|
|
|
uint8_t aClearValue, int32_t aStride = 0);
|
|
|
|
|
2016-07-26 02:36:36 +03:00
|
|
|
virtual uint8_t* GetData() override { return mArray; }
|
2015-07-17 19:58:16 +03:00
|
|
|
virtual int32_t Stride() override { return mStride; }
|
2013-07-17 18:07:44 +04:00
|
|
|
|
2015-07-17 19:58:16 +03:00
|
|
|
virtual SurfaceType GetType() const override { return SurfaceType::DATA; }
|
|
|
|
virtual IntSize GetSize() const override { return mSize; }
|
|
|
|
virtual SurfaceFormat GetFormat() const override { return mFormat; }
|
2013-07-17 18:07:44 +04:00
|
|
|
|
2018-02-22 22:26:29 +03:00
|
|
|
void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut,
|
|
|
|
size_t& aNonHeapSizeOut, size_t& aExtHandlesOut,
|
2018-09-25 16:13:51 +03:00
|
|
|
uint64_t& aExtIdOut) const override;
|
2018-02-22 22:26:29 +03:00
|
|
|
|
2013-07-17 18:07:44 +04:00
|
|
|
private:
|
2016-05-10 21:44:00 +03:00
|
|
|
friend class Factory;
|
|
|
|
|
2013-07-17 18:07:44 +04:00
|
|
|
AlignedArray<uint8_t> mArray;
|
|
|
|
int32_t mStride;
|
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-05-21 19:27:30 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_SOURCESURFACERAWDATA_H_ */
|