gecko-dev/gfx/layers/basic/TextureClientX11.cpp
Nathan Froyd 01583602a9 Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat
The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.

CLOSED TREE makes big refactorings like this a piece of cake.

 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'

 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h

 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py

 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'

if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi

--HG--
rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 01:24:48 -04:00

169 lines
4.6 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 "mozilla/layers/TextureClientX11.h"
#include "mozilla/layers/CompositableClient.h"
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/ShadowLayerUtilsX11.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Logging.h"
#include "gfxXlibSurface.h"
#include "gfx2DGlue.h"
#include "mozilla/X11Util.h"
#include <X11/Xlib.h>
using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;
TextureClientX11::TextureClientX11(ISurfaceAllocator* aAllocator,
SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags),
mFormat(aFormat),
mLocked(false)
{
MOZ_COUNT_CTOR(TextureClientX11);
}
TextureClientX11::~TextureClientX11()
{
MOZ_COUNT_DTOR(TextureClientX11);
}
already_AddRefed<TextureClient>
TextureClientX11::CreateSimilar(TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{
RefPtr<TextureClient> tex = new TextureClientX11(mAllocator, mFormat, mFlags);
// mSize is guaranteed to be non-negative
MOZ_ASSERT(mSize.width >= 0 && mSize.height >= 0);
if (!tex->AllocateForSurface(mSize, aAllocFlags)) {
return nullptr;
}
return tex.forget();
}
bool
TextureClientX11::IsAllocated() const
{
return !!mSurface;
}
bool
TextureClientX11::Lock(OpenMode aMode)
{
MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
mLocked = IsValid() && IsAllocated();
return mLocked;
}
void
TextureClientX11::Unlock()
{
MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
mLocked = false;
if (mDrawTarget) {
// see the comment on TextureClient::BorrowDrawTarget.
// This DrawTarget is internal to the TextureClient and is only exposed to the
// outside world between Lock() and Unlock(). This assertion checks that no outside
// reference remains by the time Unlock() is called.
MOZ_ASSERT(mDrawTarget->refCount() == 1);
mDrawTarget->Flush();
mDrawTarget = nullptr;
}
if (mSurface && !mAllocator->IsSameProcess()) {
FinishX(DefaultXDisplay());
}
}
bool
TextureClientX11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(IsValid());
if (!mSurface) {
return false;
}
if (!(mFlags & TextureFlags::DEALLOCATE_CLIENT)) {
// Pass to the host the responsibility of freeing the pixmap. ReleasePixmap means
// the underlying pixmap will not be deallocated in mSurface's destructor.
// ToSurfaceDescriptor is at most called once per TextureClient.
mSurface->ReleasePixmap();
}
aOutDescriptor = SurfaceDescriptorX11(mSurface);
return true;
}
bool
TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags)
{
MOZ_ASSERT(IsValid());
MOZ_ASSERT(!IsAllocated());
//MOZ_ASSERT(mFormat != gfx::FORMAT_YUV, "This TextureClient cannot use YCbCr data");
MOZ_ASSERT(aSize.width >= 0 && aSize.height >= 0);
if (aSize.width <= 0 || aSize.height <= 0 ||
aSize.width > XLIB_IMAGE_SIDE_SIZE_LIMIT ||
aSize.height > XLIB_IMAGE_SIDE_SIZE_LIMIT) {
gfxDebug() << "Asking for X11 surface of invalid size " << aSize.width << "x" << aSize.height;
return false;
}
gfxImageFormat imageFormat = SurfaceFormatToImageFormat(mFormat);
RefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, imageFormat);
if (!surface || surface->GetType() != gfxSurfaceType::Xlib) {
NS_ERROR("creating Xlib surface failed!");
return false;
}
mSize = aSize;
mSurface = static_cast<gfxXlibSurface*>(surface.get());
if (!mAllocator->IsSameProcess()) {
FinishX(DefaultXDisplay());
}
return true;
}
DrawTarget*
TextureClientX11::BorrowDrawTarget()
{
MOZ_ASSERT(IsValid());
MOZ_ASSERT(mLocked);
if (!mSurface) {
return nullptr;
}
if (!mDrawTarget) {
IntSize size = mSurface->GetSize();
mDrawTarget = Factory::CreateDrawTargetForCairoSurface(mSurface->CairoSurface(), size);
}
return mDrawTarget;
}
void
TextureClientX11::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
MOZ_ASSERT(CanExposeDrawTarget());
DrawTarget* dt = BorrowDrawTarget();
if (!dt) {
gfxCriticalError() << "Failed to borrow drawtarget for TextureClientX11::UpdateFromSurface";
return;
}
dt->CopySurface(aSurface, IntRect(IntPoint(), aSurface->GetSize()), IntPoint());
}