mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
3b276a5398
- Bug 1077651 Measure frame uniformity by synthesizing native events. r=kats,mrbkap (95a796145) - Bug 1154231 - Part 2. Reclaim cached resources when memory-pressure occurs. r=mattwoodrow (cff6ac1f9) - fix build (15112d396) - Bug 1155649 - XFlush at the end of frames when OMTC is enabled on Linux. r=jrmuizel (8bc22dd42) - Bug 1158120 - Edit include and comments that contained gfxIntSize and nsIntSize. r=nical (fc25c0c96) - Bug 1167235 - Part 1: Add code exposing a PersistentBufferProvider. r=nical (8340f8ede) - Bug 1134251 - Disable broken B2G Desktop tests on Mulet. r=jmaher, r=jgilbert (db4d4253c) - Bug 1134271 - Skip conformance/canvas/buffer-offscreen-test.html on Android; r=jgilbert (2fe8d8623) - Bug 1124996 - Remove expected fail on OSX 10.10. r=jgilbert (388438a7e) - Bug 1145492 - Update FramebufferTexture2D to allow binding mipmaps. r=jgilbert (5e4c6bf95) - Bug 1158089 - Remove LAYERS_D3D10 enum value since it's unused. r=Bas (720d3b3b4) - Bug 1156058 - Null pointer check. r=jgilbert (f9b9c6ca6) - Bug 1131463 - Report AtomicRefCounterWithFinalize doing the wrong thing with AddRef and Release in release build as well. r=sotaro (7c009766e) - Bug 1142071 - Re-add WaitForBufferOwnership() r=jgilbert (0753bcd25) - partial revert of patch not found... (4ed1e76f1) - Bug 1143979 - Use RAII local instead of useless temporary. - r=kamidphish (d8a50143f) - Bug 1017865 - Refactor attach/detach for FB attachments. - r=kamidphish (9c7e41065) - Bug 1144906 - Add accel E10S backend for WebGL compositing. - r=jrmuizel,mattwoodrow,nical,sotaro (559ab767f) - Bug 1167235 - Part 2: Add support for the basic buffer provider to CanvasLayer. r=nical (4ac399c16) - Bug 1155252 - Add a pref to control the maximum canvas 2d size and set it to 0x7ff. r=jrmuizel (7ae6cde3f) - Bug 1167235 - Part 3: Switch CanvasRenderingContext2D to use the new BufferProvider API. r=nical (f678c14ab) - Bug 1192159: Do not forget about the transform when not using an active target. r=jrmuizel (a4bd28a75) - Bug 1167235 - Part 4: Remove DrawTarget as a possible means of initializing Canvas layers. r=nical (dbd153cfb) - Bug 1167235 - Part 5: Make CanvasLayerComposite ImageHost type agnostic. r=nical (df15bd85d) - Bug 1167235 - Part 6: Fix up HasInternalBuffer return value on TextureHostDirectUpload. r=nical (437cd1680) - Bug 1091851 - Fix a race condition in Sqlite.jsm shutdown. r=mak (8b6ac8848)
174 lines
4.8 KiB
C++
174 lines
4.8 KiB
C++
/* -*- 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/. */
|
|
|
|
#include "ImageDataSerializer.h"
|
|
#include "gfx2DGlue.h" // for SurfaceFormatToImageFormat
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface, Factory
|
|
#include "mozilla/gfx/Logging.h" // for gfxDebug
|
|
#include "mozilla/gfx/Tools.h" // for GetAlignedStride, etc
|
|
#include "mozilla/mozalloc.h" // for operator delete, etc
|
|
|
|
namespace mozilla {
|
|
namespace layers {
|
|
|
|
using namespace gfx;
|
|
|
|
// The Data is layed out as follows:
|
|
//
|
|
// +-------------------+ -++ --+ <-- ImageDataSerializerBase::mData pointer
|
|
// | SurfaceBufferInfo | | |
|
|
// +-------------------+ --+ | offset
|
|
// | ... | |
|
|
// +-------------------+ ------+
|
|
// | |
|
|
// | data |
|
|
// | |
|
|
// +-------------------+
|
|
|
|
// Structure written at the beginning of the data blob containing the image
|
|
// (as shown in the figure above). It contains the necessary informations to
|
|
// read the image in the blob.
|
|
namespace {
|
|
struct SurfaceBufferInfo
|
|
{
|
|
int32_t width;
|
|
int32_t height;
|
|
SurfaceFormat format;
|
|
|
|
static int32_t GetOffset()
|
|
{
|
|
return GetAlignedStride<16>(sizeof(SurfaceBufferInfo));
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
static SurfaceBufferInfo*
|
|
GetBufferInfo(uint8_t* aData, size_t aDataSize)
|
|
{
|
|
return aDataSize >= sizeof(SurfaceBufferInfo)
|
|
? reinterpret_cast<SurfaceBufferInfo*>(aData)
|
|
: nullptr;
|
|
}
|
|
|
|
void
|
|
ImageDataSerializer::InitializeBufferInfo(IntSize aSize,
|
|
SurfaceFormat aFormat)
|
|
{
|
|
SurfaceBufferInfo* info = GetBufferInfo(mData, mDataSize);
|
|
MOZ_ASSERT(info); // OK to assert here, this method is client-side-only
|
|
info->width = aSize.width;
|
|
info->height = aSize.height;
|
|
info->format = aFormat;
|
|
Validate();
|
|
}
|
|
|
|
static inline int32_t
|
|
ComputeStride(SurfaceFormat aFormat, int32_t aWidth)
|
|
{
|
|
CheckedInt<int32_t> size = BytesPerPixel(aFormat);
|
|
size *= aWidth;
|
|
if (!size.isValid() || size.value() <= 0) {
|
|
gfxDebug() << "ComputeStride overflow " << aWidth;
|
|
return 0;
|
|
}
|
|
|
|
return GetAlignedStride<4>(size.value());
|
|
}
|
|
|
|
uint32_t
|
|
ImageDataSerializerBase::ComputeMinBufferSize(IntSize aSize,
|
|
SurfaceFormat aFormat)
|
|
{
|
|
MOZ_ASSERT(aSize.height >= 0 && aSize.width >= 0);
|
|
|
|
// This takes care of checking whether there could be overflow
|
|
// with enough margin for the metadata.
|
|
if (!gfx::Factory::AllowedSurfaceSize(aSize)) {
|
|
return 0;
|
|
}
|
|
|
|
int32_t bufsize = GetAlignedStride<16>(ComputeStride(aFormat, aSize.width)
|
|
* aSize.height)
|
|
+ SurfaceBufferInfo::GetOffset();
|
|
|
|
if (bufsize < 0) {
|
|
// This should not be possible thanks to Factory::AllowedSurfaceSize
|
|
return 0;
|
|
}
|
|
|
|
return bufsize;
|
|
}
|
|
|
|
void
|
|
ImageDataSerializerBase::Validate()
|
|
{
|
|
mIsValid = false;
|
|
if (!mData) {
|
|
return;
|
|
}
|
|
SurfaceBufferInfo* info = GetBufferInfo(mData, mDataSize);
|
|
if (!info) {
|
|
return;
|
|
}
|
|
size_t requiredSize =
|
|
ComputeMinBufferSize(IntSize(info->width, info->height), info->format);
|
|
|
|
mIsValid = !!requiredSize && requiredSize <= mDataSize;
|
|
}
|
|
|
|
uint8_t*
|
|
ImageDataSerializerBase::GetData()
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
return mData + SurfaceBufferInfo::GetOffset();
|
|
}
|
|
|
|
uint32_t
|
|
ImageDataSerializerBase::GetStride() const
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
SurfaceBufferInfo* info = GetBufferInfo(mData, mDataSize);
|
|
return ComputeStride(GetFormat(), info->width);
|
|
}
|
|
|
|
IntSize
|
|
ImageDataSerializerBase::GetSize() const
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
SurfaceBufferInfo* info = GetBufferInfo(mData, mDataSize);
|
|
return IntSize(info->width, info->height);
|
|
}
|
|
|
|
SurfaceFormat
|
|
ImageDataSerializerBase::GetFormat() const
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
return GetBufferInfo(mData, mDataSize)->format;
|
|
}
|
|
|
|
already_AddRefed<DrawTarget>
|
|
ImageDataSerializerBase::GetAsDrawTarget(gfx::BackendType aBackend)
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
return gfx::Factory::CreateDrawTargetForData(aBackend,
|
|
GetData(), GetSize(),
|
|
GetStride(), GetFormat());
|
|
}
|
|
|
|
already_AddRefed<gfx::DataSourceSurface>
|
|
ImageDataSerializerBase::GetAsSurface()
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
return Factory::CreateWrappingDataSourceSurface(GetData(),
|
|
GetStride(),
|
|
GetSize(),
|
|
GetFormat());
|
|
}
|
|
|
|
} // namespace layers
|
|
} // namespace mozilla
|