summaryrefslogtreecommitdiffstats
path: root/gfx/layers
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/layers')
-rw-r--r--gfx/layers/AtomicRefCountedWithFinalize.h10
-rw-r--r--gfx/layers/ImageContainer.cpp23
-rw-r--r--gfx/layers/basic/BasicImages.cpp9
-rw-r--r--gfx/layers/composite/FPSCounter.cpp27
-rw-r--r--gfx/layers/composite/TextureHost.cpp65
-rw-r--r--gfx/layers/composite/X11TextureHost.cpp13
-rw-r--r--gfx/layers/d3d11/TextureD3D11.cpp6
-rw-r--r--gfx/layers/opengl/CompositingRenderTargetOGL.cpp2
-rw-r--r--gfx/layers/opengl/CompositingRenderTargetOGL.h2
-rw-r--r--gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp8
-rw-r--r--gfx/layers/opengl/TextureHostOGL.cpp27
11 files changed, 127 insertions, 65 deletions
diff --git a/gfx/layers/AtomicRefCountedWithFinalize.h b/gfx/layers/AtomicRefCountedWithFinalize.h
index 7bd8f0203..1dd35e626 100644
--- a/gfx/layers/AtomicRefCountedWithFinalize.h
+++ b/gfx/layers/AtomicRefCountedWithFinalize.h
@@ -101,8 +101,12 @@ public:
private:
void AddRef() {
MOZ_ASSERT(mRefCount >= 0, "AddRef() during/after Finalize()/dtor.");
- mRefCount++;
- NS_LOG_ADDREF(this, mRefCount, mName, sizeof(*this));
+#ifdef NS_BUILD_REFCNT_LOGGING
+ int currCount = ++mRefCount;
+ NS_LOG_ADDREF(this, currCount, mName, sizeof(*this));
+#else
+ ++mRefCount;
+#endif
}
void Release() {
@@ -118,7 +122,9 @@ private:
++mRefCount;
return;
}
+#ifdef NS_BUILD_REFCNT_LOGGING
NS_LOG_RELEASE(this, currCount, mName);
+#endif
if (0 == currCount) {
mRefCount = detail::DEAD;
diff --git a/gfx/layers/ImageContainer.cpp b/gfx/layers/ImageContainer.cpp
index 8072e0401..5e4019e86 100644
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -438,12 +438,15 @@ static void
CopyPlane(uint8_t *aDst, const uint8_t *aSrc,
const gfx::IntSize &aSize, int32_t aStride, int32_t aSkip)
{
+ int32_t height = aSize.height;
+ int32_t width = aSize.width;
+
+ MOZ_RELEASE_ASSERT(width <= aStride);
+
if (!aSkip) {
// Fast path: planar input.
- memcpy(aDst, aSrc, aSize.height * aStride);
+ memcpy(aDst, aSrc, height * aStride);
} else {
- int32_t height = aSize.height;
- int32_t width = aSize.width;
for (int y = 0; y < height; ++y) {
const uint8_t *src = aSrc;
uint8_t *dst = aDst;
@@ -461,13 +464,11 @@ CopyPlane(uint8_t *aDst, const uint8_t *aSrc,
bool
RecyclingPlanarYCbCrImage::CopyData(const Data& aData)
{
- mData = aData;
-
// update buffer size
// Use uint32_t throughout to match AllocateBuffer's param and mBufferSize
const auto checkedSize =
- CheckedInt<uint32_t>(mData.mCbCrStride) * mData.mCbCrSize.height * 2 +
- CheckedInt<uint32_t>(mData.mYStride) * mData.mYSize.height;
+ CheckedInt<uint32_t>(aData.mCbCrStride) * aData.mCbCrSize.height * 2 +
+ CheckedInt<uint32_t>(aData.mYStride) * aData.mYSize.height;
if (!checkedSize.isValid())
return false;
@@ -482,16 +483,18 @@ RecyclingPlanarYCbCrImage::CopyData(const Data& aData)
// update buffer size
mBufferSize = size;
+ mData = aData;
mData.mYChannel = mBuffer.get();
mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height;
mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height;
+ mData.mYSkip = mData.mCbSkip = mData.mCrSkip = 0;
CopyPlane(mData.mYChannel, aData.mYChannel,
- mData.mYSize, mData.mYStride, mData.mYSkip);
+ aData.mYSize, aData.mYStride, aData.mYSkip);
CopyPlane(mData.mCbChannel, aData.mCbChannel,
- mData.mCbCrSize, mData.mCbCrStride, mData.mCbSkip);
+ aData.mCbCrSize, aData.mCbCrStride, aData.mCbSkip);
CopyPlane(mData.mCrChannel, aData.mCrChannel,
- mData.mCbCrSize, mData.mCbCrStride, mData.mCrSkip);
+ aData.mCbCrSize, aData.mCbCrStride, aData.mCrSkip);
mSize = aData.mPicSize;
mOrigin = gfx::IntPoint(aData.mPicX, aData.mPicY);
diff --git a/gfx/layers/basic/BasicImages.cpp b/gfx/layers/basic/BasicImages.cpp
index ed9447207..fc1be6e9a 100644
--- a/gfx/layers/basic/BasicImages.cpp
+++ b/gfx/layers/basic/BasicImages.cpp
@@ -11,6 +11,7 @@
#include "gfxASurface.h" // for gfxASurface, etc
#include "gfxPlatform.h" // for gfxPlatform, gfxImageFormat
#include "gfxUtils.h" // for gfxUtils
+#include "mozilla/CheckedInt.h"
#include "mozilla/mozalloc.h" // for operator delete[], etc
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
@@ -111,7 +112,13 @@ BasicPlanarYCbCrImage::CopyData(const Data& aData)
gfxImageFormat iFormat = gfx::SurfaceFormatToImageFormat(format);
mStride = gfxASurface::FormatStrideForWidth(iFormat, size.width);
- mDecodedBuffer = AllocateBuffer(size.height * mStride);
+ mozilla::CheckedInt32 requiredBytes =
+ mozilla::CheckedInt32(size.height) * mozilla::CheckedInt32(mStride);
+ if (!requiredBytes.isValid()) {
+ // invalid size
+ return false;
+ }
+ mDecodedBuffer = AllocateBuffer(requiredBytes.value());
if (!mDecodedBuffer) {
// out of memory
return false;
diff --git a/gfx/layers/composite/FPSCounter.cpp b/gfx/layers/composite/FPSCounter.cpp
index 02ffc4b2c..b8e93eb97 100644
--- a/gfx/layers/composite/FPSCounter.cpp
+++ b/gfx/layers/composite/FPSCounter.cpp
@@ -210,7 +210,10 @@ FPSCounter::WriteFrameTimeStamps(PRFileDesc* fd)
const int bufferSize = 256;
char buffer[bufferSize];
int writtenCount = SprintfLiteral(buffer, "FPS Data for: %s\n", mFPSName);
- MOZ_ASSERT(writtenCount >= 0);
+ MOZ_ASSERT(writtenCount < bufferSize);
+ if (writtenCount >= bufferSize) {
+ return;
+ }
PR_Write(fd, buffer, writtenCount);
ResetReverseIterator();
@@ -225,8 +228,10 @@ FPSCounter::WriteFrameTimeStamps(PRFileDesc* fd)
while (HasNext(startTimeStamp)) {
TimeDuration duration = previousSample - nextTimeStamp;
writtenCount = SprintfLiteral(buffer, "%f,\n", duration.ToMilliseconds());
-
- MOZ_ASSERT(writtenCount >= 0);
+ MOZ_ASSERT(writtenCount < bufferSize);
+ if (writtenCount >= bufferSize) {
+ continue;
+ }
PR_Write(fd, buffer, writtenCount);
previousSample = nextTimeStamp;
@@ -299,8 +304,13 @@ FPSCounter::PrintFPS()
void
FPSCounter::PrintHistogram(std::map<int, int>& aHistogram)
{
+ if (aHistogram.size() == 0) {
+ return;
+ }
+
int length = 0;
const int kBufferLength = 512;
+ int availableSpace = kBufferLength;
char buffer[kBufferLength];
for (std::map<int, int>::iterator iter = aHistogram.begin();
@@ -309,9 +319,14 @@ FPSCounter::PrintHistogram(std::map<int, int>& aHistogram)
int fps = iter->first;
int count = iter->second;
- length += snprintf(buffer + length, kBufferLength - length,
- "FPS: %d = %d. ", fps, count);
- NS_ASSERTION(length >= kBufferLength, "Buffer overrun while printing FPS histogram.");
+ int lengthRequired = snprintf(buffer + length, availableSpace,
+ "FPS: %d = %d. ", fps, count);
+ // Ran out of buffer space. Oh well - just print what we have.
+ if (lengthRequired > availableSpace) {
+ break;
+ }
+ length += lengthRequired;
+ availableSpace -= lengthRequired;
}
printf_stderr("%s\n", buffer);
diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp
index 8c5b8c7b7..c93037384 100644
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -100,15 +100,9 @@ TextureHost::CreateIPDLActor(HostIPCAllocator* aAllocator,
TextureFlags aFlags,
uint64_t aSerial)
{
- if (aSharedData.type() == SurfaceDescriptor::TSurfaceDescriptorBuffer &&
- aSharedData.get_SurfaceDescriptorBuffer().data().type() == MemoryOrShmem::Tuintptr_t &&
- !aAllocator->IsSameProcess())
- {
- NS_ERROR("A client process is trying to peek at our address space using a MemoryTexture!");
- return nullptr;
- }
TextureParent* actor = new TextureParent(aAllocator, aSerial);
if (!actor->Init(aSharedData, aLayersBackend, aFlags)) {
+ actor->ActorDestroy(ipc::IProtocol::ActorDestroyReason::FailedConstructor);
delete actor;
return nullptr;
}
@@ -210,6 +204,11 @@ TextureHost::Create(const SurfaceDescriptor& aDesc,
#ifdef MOZ_X11
case SurfaceDescriptor::TSurfaceDescriptorX11: {
+ if (!aDeallocator->IsSameProcess()) {
+ NS_ERROR("A client process is trying to peek at our address space using a X11Texture!");
+ return nullptr;
+ }
+
const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
return MakeAndAddRef<X11TextureHost>(aFlags, desc);
}
@@ -244,13 +243,49 @@ CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
const MemoryOrShmem& data = bufferDesc.data();
switch (data.type()) {
case MemoryOrShmem::TShmem: {
- result = new ShmemTextureHost(data.get_Shmem(),
- bufferDesc.desc(),
- aDeallocator,
- aFlags);
+ const ipc::Shmem& shmem = data.get_Shmem();
+ const BufferDescriptor& desc = bufferDesc.desc();
+ if (!shmem.IsReadable()) {
+ // We failed to map the shmem so we can't verify its size. This
+ // should not be a fatal error, so just create the texture with
+ // nothing backing it.
+ result = new ShmemTextureHost(shmem, desc, aDeallocator, aFlags);
+ break;
+ }
+
+ size_t bufSize = shmem.Size<char>();
+ size_t reqSize = SIZE_MAX;
+ switch (desc.type()) {
+ case BufferDescriptor::TYCbCrDescriptor: {
+ const YCbCrDescriptor& ycbcr = desc.get_YCbCrDescriptor();
+ reqSize =
+ ImageDataSerializer::ComputeYCbCrBufferSize(ycbcr.ySize(), ycbcr.cbCrSize());
+ break;
+ }
+ case BufferDescriptor::TRGBDescriptor: {
+ const RGBDescriptor& rgb = desc.get_RGBDescriptor();
+ reqSize = ImageDataSerializer::ComputeRGBBufferSize(rgb.size(), rgb.format());
+ break;
+ }
+ default:
+ gfxCriticalError() << "Bad buffer host descriptor " << (int)desc.type();
+ MOZ_CRASH("GFX: Bad descriptor");
+ }
+
+ if (bufSize < reqSize) {
+ NS_ERROR("A client process gave a shmem too small to fit for its descriptor!");
+ return nullptr;
+ }
+
+ result = new ShmemTextureHost(shmem, desc, aDeallocator, aFlags);
break;
}
case MemoryOrShmem::Tuintptr_t: {
+ if (!aDeallocator->IsSameProcess()) {
+ NS_ERROR("A client process is trying to peek at our address space using a MemoryTexture!");
+ return nullptr;
+ }
+
result = new MemoryTextureHost(reinterpret_cast<uint8_t*>(data.get_uintptr_t()),
bufferDesc.desc(),
aFlags);
@@ -268,6 +303,11 @@ CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
}
#ifdef XP_WIN
case SurfaceDescriptor::TSurfaceDescriptorDIB: {
+ if (!aDeallocator->IsSameProcess()) {
+ NS_ERROR("A client process is trying to peek at our address space using a DIBTexture!");
+ return nullptr;
+ }
+
result = new DIBTextureHost(aFlags, aDesc);
break;
}
@@ -848,8 +888,7 @@ BufferTextureHost::Upload(nsIntRegion *aRegion)
mFirstSource = mCompositor->CreateDataTextureSource(mFlags|TextureFlags::RGB_FROM_YCBCR);
mFirstSource->SetOwner(this);
}
- mFirstSource->Update(surf, aRegion);
- return true;
+ return mFirstSource->Update(surf, aRegion);
}
RefPtr<DataTextureSource> srcY;
diff --git a/gfx/layers/composite/X11TextureHost.cpp b/gfx/layers/composite/X11TextureHost.cpp
index 7ca42426d..92b6f8e91 100644
--- a/gfx/layers/composite/X11TextureHost.cpp
+++ b/gfx/layers/composite/X11TextureHost.cpp
@@ -22,10 +22,9 @@ X11TextureHost::X11TextureHost(TextureFlags aFlags,
const SurfaceDescriptorX11& aDescriptor)
: TextureHost(aFlags)
{
- RefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
- mSurface = surface.get();
+ mSurface = aDescriptor.OpenForeign();
- if (!(aFlags & TextureFlags::DEALLOCATE_CLIENT)) {
+ if (mSurface && !(aFlags & TextureFlags::DEALLOCATE_CLIENT)) {
mSurface->TakePixmap();
}
}
@@ -33,7 +32,7 @@ X11TextureHost::X11TextureHost(TextureFlags aFlags,
bool
X11TextureHost::Lock()
{
- if (!mCompositor) {
+ if (!mCompositor || !mSurface) {
return false;
}
@@ -69,6 +68,9 @@ X11TextureHost::SetCompositor(Compositor* aCompositor)
SurfaceFormat
X11TextureHost::GetFormat() const
{
+ if (!mSurface) {
+ return SurfaceFormat::UNKNOWN;
+ }
gfxContentType type = mSurface->GetContentType();
#ifdef GL_PROVIDER_GLX
if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) {
@@ -81,6 +83,9 @@ X11TextureHost::GetFormat() const
IntSize
X11TextureHost::GetSize() const
{
+ if (!mSurface) {
+ return IntSize();
+ }
return mSurface->GetSize();
}
diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp
index 8fbcfd234..954242585 100644
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -632,10 +632,6 @@ CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
{
RefPtr<TextureHost> result;
switch (aDesc.type()) {
- case SurfaceDescriptor::TSurfaceDescriptorBuffer: {
- result = CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
- break;
- }
case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
result = new DXGITextureHostD3D11(aFlags,
aDesc.get_SurfaceDescriptorD3D10());
@@ -647,7 +643,7 @@ CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
break;
}
default: {
- NS_WARNING("Unsupported SurfaceDescriptor type");
+ MOZ_ASSERT_UNREACHABLE("Unsupported SurfaceDescriptor type");
}
}
return result.forget();
diff --git a/gfx/layers/opengl/CompositingRenderTargetOGL.cpp b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
index c05b8edfd..a1521c56d 100644
--- a/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
@@ -60,7 +60,7 @@ CompositingRenderTargetOGL::BindRenderTarget()
msg.AppendPrintf("Framebuffer not complete -- CheckFramebufferStatus returned 0x%x, "
"GLContext=%p, IsOffscreen()=%d, mFBO=%d, aFBOTextureTarget=0x%x, "
"aRect.width=%d, aRect.height=%d",
- result, mGL, mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget,
+ result, mGL.get(), mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget,
mInitParams.mSize.width, mInitParams.mSize.height);
NS_WARNING(msg.get());
}
diff --git a/gfx/layers/opengl/CompositingRenderTargetOGL.h b/gfx/layers/opengl/CompositingRenderTargetOGL.h
index 501701d6f..071dc5cac 100644
--- a/gfx/layers/opengl/CompositingRenderTargetOGL.h
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.h
@@ -184,7 +184,7 @@ private:
* the target is always cleared at the end of a frame.
*/
RefPtr<CompositorOGL> mCompositor;
- GLContext* mGL;
+ RefPtr<GLContext> mGL;
GLuint mTextureHandle;
GLuint mFBO;
};
diff --git a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
index 05f8cf38f..9736618f7 100644
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -28,6 +28,8 @@ MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL()
GLTextureSource*
MacIOSurfaceTextureHostOGL::CreateTextureSourceForPlane(size_t aPlane)
{
+ MOZ_ASSERT(mSurface);
+
GLuint textureHandle;
gl::GLContext* gl = mCompositor->gl();
gl->fGenTextures(1, &textureHandle);
@@ -84,11 +86,17 @@ MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
gfx::SurfaceFormat
MacIOSurfaceTextureHostOGL::GetFormat() const {
+ if (!mSurface) {
+ return gfx::SurfaceFormat::UNKNOWN;
+ }
return mSurface->GetFormat();
}
gfx::SurfaceFormat
MacIOSurfaceTextureHostOGL::GetReadFormat() const {
+ if (!mSurface) {
+ return gfx::SurfaceFormat::UNKNOWN;
+ }
return mSurface->GetReadFormat();
}
diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp
index 854160bc6..ec6ba9131 100644
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -25,10 +25,6 @@
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
#endif
-#ifdef GL_PROVIDER_GLX
-#include "mozilla/layers/X11TextureHost.h"
-#endif
-
using namespace mozilla::gl;
using namespace mozilla::gfx;
@@ -44,12 +40,6 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
{
RefPtr<TextureHost> result;
switch (aDesc.type()) {
- case SurfaceDescriptor::TSurfaceDescriptorBuffer: {
- result = CreateBackendIndependentTextureHost(aDesc,
- aDeallocator, aFlags);
- break;
- }
-
#ifdef MOZ_WIDGET_ANDROID
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
@@ -79,14 +69,6 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
}
#endif
-#ifdef GL_PROVIDER_GLX
- case SurfaceDescriptor::TSurfaceDescriptorX11: {
- const auto& desc = aDesc.get_SurfaceDescriptorX11();
- result = new X11TextureHost(aFlags, desc);
- break;
- }
-#endif
-
case SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture: {
const auto& desc = aDesc.get_SurfaceDescriptorSharedGLTexture();
result = new GLTextureHost(aFlags, desc.texture(),
@@ -96,7 +78,10 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
desc.hasAlpha());
break;
}
- default: return nullptr;
+ default: {
+ MOZ_ASSERT_UNREACHABLE("Unsupported SurfaceDescriptor type");
+ break;
+ }
}
return result.forget();
}
@@ -176,9 +161,7 @@ TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
}
}
- mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
-
- return true;
+ return mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
}
void