зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1256572
- create DataSourceSurface with current data. r=bas
This commit is contained in:
Родитель
c1dec946da
Коммит
4e7ff09f94
|
@ -15,6 +15,63 @@
|
|||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
already_AddRefed<DataSourceSurface>
|
||||
CreateDataSourceSurfaceFromData(const IntSize& aSize,
|
||||
SurfaceFormat aFormat,
|
||||
const uint8_t* aData,
|
||||
int32_t aDataStride)
|
||||
{
|
||||
RefPtr<DataSourceSurface> srcSurface =
|
||||
Factory::CreateWrappingDataSourceSurface(const_cast<uint8_t*>(aData),
|
||||
aDataStride,
|
||||
aSize,
|
||||
aFormat);
|
||||
RefPtr<DataSourceSurface> destSurface =
|
||||
Factory::CreateDataSourceSurface(aSize, aFormat, false);
|
||||
|
||||
if (!srcSurface || !destSurface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (CopyRect(srcSurface,
|
||||
destSurface,
|
||||
IntRect(IntPoint(), srcSurface->GetSize()),
|
||||
IntPoint())) {
|
||||
return destSurface.forget();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<DataSourceSurface>
|
||||
CreateDataSourceSurfaceWithStrideFromData(const IntSize &aSize,
|
||||
SurfaceFormat aFormat,
|
||||
int32_t aStride,
|
||||
const uint8_t* aData,
|
||||
int32_t aDataStride)
|
||||
{
|
||||
RefPtr<DataSourceSurface> srcSurface =
|
||||
Factory::CreateWrappingDataSourceSurface(const_cast<uint8_t*>(aData),
|
||||
aDataStride,
|
||||
aSize,
|
||||
aFormat);
|
||||
RefPtr<DataSourceSurface> destSurface =
|
||||
Factory::CreateDataSourceSurfaceWithStride(aSize, aFormat, aStride, false);
|
||||
|
||||
if (!srcSurface || !destSurface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (CopyRect(srcSurface,
|
||||
destSurface,
|
||||
IntRect(IntPoint(), srcSurface->GetSize()),
|
||||
IntPoint())) {
|
||||
return destSurface.forget();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t*
|
||||
DataAtOffset(DataSourceSurface* aSurface,
|
||||
const DataSourceSurface::MappedSurface* aMap,
|
||||
|
@ -232,7 +289,7 @@ BufferSizeFromStrideAndHeight(int32_t aStride,
|
|||
* aSrcRect: Rect relative to the aSrc surface
|
||||
* aDestPoint: Point inside aDest surface
|
||||
*/
|
||||
void
|
||||
bool
|
||||
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
|
||||
IntRect aSrcRect, IntPoint aDestPoint)
|
||||
{
|
||||
|
@ -249,13 +306,13 @@ CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
|
|||
"dest surface too small");
|
||||
|
||||
if (aSrcRect.IsEmpty()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
DataSourceSurface::ScopedMap srcMap(aSrc, DataSourceSurface::READ);
|
||||
DataSourceSurface::ScopedMap destMap(aDest, DataSourceSurface::WRITE);
|
||||
if (MOZ2D_WARN_IF(!srcMap.IsMapped() || !destMap.IsMapped())) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* sourceData = DataAtOffset(aSrc, srcMap.GetMappedSurface(), aSrcRect.TopLeft());
|
||||
|
@ -276,6 +333,8 @@ CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
|
|||
destData += destStride;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
already_AddRefed<DataSourceSurface>
|
||||
|
|
|
@ -13,6 +13,28 @@
|
|||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* Create a DataSourceSurface and init the surface with the |aData|. The stride
|
||||
* of this source surface might be different from the input data's |aDataStride|.
|
||||
* System will try to use the optimal one.
|
||||
*/
|
||||
already_AddRefed<DataSourceSurface>
|
||||
CreateDataSourceSurfaceFromData(const IntSize& aSize,
|
||||
SurfaceFormat aFormat,
|
||||
const uint8_t* aData,
|
||||
int32_t aDataStride);
|
||||
|
||||
/**
|
||||
* Similar to CreateDataSourceSurfaceFromData(), but could setup the stride for
|
||||
* this surface.
|
||||
*/
|
||||
already_AddRefed<DataSourceSurface>
|
||||
CreateDataSourceSurfaceWithStrideFromData(const IntSize &aSize,
|
||||
SurfaceFormat aFormat,
|
||||
int32_t aStride,
|
||||
const uint8_t* aData,
|
||||
int32_t aDataStride);
|
||||
|
||||
void
|
||||
ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, const int32_t aStride);
|
||||
|
||||
|
@ -72,8 +94,9 @@ BufferSizeFromStrideAndHeight(int32_t aStride,
|
|||
|
||||
/**
|
||||
* Copy aSrcRect from aSrc to aDest starting at aDestPoint.
|
||||
* @returns false if the copy is not successful or the aSrc's size is empty.
|
||||
*/
|
||||
void
|
||||
bool
|
||||
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
|
||||
IntRect aSrcRect, IntPoint aDestPoint);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче