2012-05-21 19:27:30 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRawData)
|
2015-07-16 10:36:00 +03:00
|
|
|
SourceSurfaceRawData()
|
|
|
|
: mMapCount(0)
|
|
|
|
{}
|
|
|
|
~SourceSurfaceRawData()
|
|
|
|
{
|
|
|
|
if(mOwnData) delete [] mRawData;
|
|
|
|
MOZ_ASSERT(mMapCount == 0);
|
|
|
|
}
|
2012-05-21 19:27:30 +04:00
|
|
|
|
|
|
|
virtual uint8_t *GetData() { return mRawData; }
|
|
|
|
virtual int32_t Stride() { return mStride; }
|
|
|
|
|
2014-01-10 22:55:24 +04:00
|
|
|
virtual SurfaceType GetType() const { return SurfaceType::DATA; }
|
2012-05-21 19:27:30 +04:00
|
|
|
virtual IntSize GetSize() const { return mSize; }
|
|
|
|
virtual SurfaceFormat GetFormat() const { return mFormat; }
|
|
|
|
|
|
|
|
bool InitWrappingData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
bool aOwnData);
|
|
|
|
|
2014-08-01 20:01:47 +04:00
|
|
|
virtual void GuaranteePersistance();
|
|
|
|
|
2015-07-16 10:36:00 +03:00
|
|
|
// Althought Map (and Moz2D in general) isn't normally threadsafe,
|
|
|
|
// we want to allow it for SourceSurfaceRawData since it should
|
|
|
|
// always be fine (for reading at least).
|
|
|
|
//
|
|
|
|
// This is the same as the base class implementation except using
|
|
|
|
// mMapCount instead of mIsMapped since that breaks for multithread.
|
|
|
|
//
|
|
|
|
// Once mfbt supports Monitors we should implement proper read/write
|
|
|
|
// locking to prevent write races.
|
|
|
|
virtual bool Map(MapType, MappedSurface *aMappedSurface) override
|
|
|
|
{
|
|
|
|
aMappedSurface->mData = GetData();
|
|
|
|
aMappedSurface->mStride = Stride();
|
|
|
|
bool success = !!aMappedSurface->mData;
|
|
|
|
if (success) {
|
|
|
|
mMapCount++;
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Unmap() override
|
|
|
|
{
|
|
|
|
mMapCount--;
|
|
|
|
MOZ_ASSERT(mMapCount >= 0);
|
|
|
|
}
|
|
|
|
|
2012-05-21 19:27:30 +04:00
|
|
|
private:
|
|
|
|
uint8_t *mRawData;
|
|
|
|
int32_t mStride;
|
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
2015-07-16 10:36:00 +03:00
|
|
|
Atomic<int32_t> mMapCount;
|
2012-05-21 19:27:30 +04:00
|
|
|
bool mOwnData;
|
|
|
|
};
|
|
|
|
|
2013-07-17 18:07:44 +04:00
|
|
|
class SourceSurfaceAlignedRawData : public DataSourceSurface
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceAlignedRawData)
|
2015-07-16 10:36:00 +03:00
|
|
|
SourceSurfaceAlignedRawData()
|
|
|
|
: mMapCount(0)
|
|
|
|
{}
|
|
|
|
~SourceSurfaceAlignedRawData()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMapCount == 0);
|
|
|
|
}
|
2013-07-17 18:07:44 +04:00
|
|
|
|
|
|
|
virtual uint8_t *GetData() { return mArray; }
|
|
|
|
virtual int32_t Stride() { return mStride; }
|
|
|
|
|
2014-01-10 22:55:24 +04:00
|
|
|
virtual SurfaceType GetType() const { return SurfaceType::DATA; }
|
2013-07-17 18:07:44 +04:00
|
|
|
virtual IntSize GetSize() const { return mSize; }
|
|
|
|
virtual SurfaceFormat GetFormat() const { return mFormat; }
|
|
|
|
|
|
|
|
bool Init(const IntSize &aSize,
|
2014-09-11 01:54:16 +04:00
|
|
|
SurfaceFormat aFormat,
|
|
|
|
bool aZero);
|
2013-12-19 19:31:07 +04:00
|
|
|
bool InitWithStride(const IntSize &aSize,
|
|
|
|
SurfaceFormat aFormat,
|
2014-09-11 01:54:16 +04:00
|
|
|
int32_t aStride,
|
|
|
|
bool aZero);
|
2013-07-17 18:07:44 +04:00
|
|
|
|
2015-07-16 10:36:00 +03:00
|
|
|
virtual bool Map(MapType, MappedSurface *aMappedSurface) override
|
|
|
|
{
|
|
|
|
aMappedSurface->mData = GetData();
|
|
|
|
aMappedSurface->mStride = Stride();
|
|
|
|
bool success = !!aMappedSurface->mData;
|
|
|
|
if (success) {
|
|
|
|
mMapCount++;
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Unmap() override
|
|
|
|
{
|
|
|
|
mMapCount--;
|
|
|
|
MOZ_ASSERT(mMapCount >= 0);
|
|
|
|
}
|
|
|
|
|
2013-07-17 18:07:44 +04:00
|
|
|
private:
|
|
|
|
AlignedArray<uint8_t> mArray;
|
|
|
|
int32_t mStride;
|
|
|
|
SurfaceFormat mFormat;
|
|
|
|
IntSize mSize;
|
2015-07-16 10:36:00 +03:00
|
|
|
Atomic<int32_t> mMapCount;
|
2013-07-17 18:07:44 +04:00
|
|
|
};
|
|
|
|
|
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_ */
|