michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: // * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include "mozilla/layers/TextureClientX11.h" michael@0: #include "mozilla/layers/CompositableClient.h" michael@0: #include "mozilla/layers/CompositableForwarder.h" michael@0: #include "mozilla/layers/ISurfaceAllocator.h" michael@0: #include "mozilla/layers/ShadowLayerUtilsX11.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "gfxXlibSurface.h" michael@0: #include "gfx2DGlue.h" michael@0: michael@0: #include "mozilla/X11Util.h" michael@0: #include michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::gfx; michael@0: using namespace mozilla::layers; michael@0: michael@0: TextureClientX11::TextureClientX11(SurfaceFormat aFormat, TextureFlags aFlags) michael@0: : TextureClient(aFlags), michael@0: mFormat(aFormat), michael@0: mLocked(false) michael@0: { michael@0: MOZ_COUNT_CTOR(TextureClientX11); michael@0: } michael@0: michael@0: TextureClientX11::~TextureClientX11() michael@0: { michael@0: MOZ_COUNT_DTOR(TextureClientX11); michael@0: } michael@0: michael@0: bool michael@0: TextureClientX11::IsAllocated() const michael@0: { michael@0: return !!mSurface; michael@0: } michael@0: michael@0: bool michael@0: TextureClientX11::Lock(OpenMode aMode) michael@0: { michael@0: MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!"); michael@0: mLocked = IsValid() && IsAllocated(); michael@0: return mLocked; michael@0: } michael@0: michael@0: void michael@0: TextureClientX11::Unlock() michael@0: { michael@0: MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!"); michael@0: mLocked = false; michael@0: michael@0: if (mSurface) { michael@0: FinishX(DefaultXDisplay()); michael@0: } michael@0: } michael@0: michael@0: bool michael@0: TextureClientX11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) michael@0: { michael@0: MOZ_ASSERT(IsValid()); michael@0: if (!mSurface) { michael@0: return false; michael@0: } michael@0: michael@0: aOutDescriptor = SurfaceDescriptorX11(mSurface); michael@0: return true; michael@0: } michael@0: michael@0: TextureClientData* michael@0: TextureClientX11::DropTextureData() michael@0: { michael@0: MOZ_ASSERT(!(mFlags & TEXTURE_DEALLOCATE_CLIENT)); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags) michael@0: { michael@0: MOZ_ASSERT(IsValid()); michael@0: //MOZ_ASSERT(mFormat != gfx::FORMAT_YUV, "This TextureClient cannot use YCbCr data"); michael@0: michael@0: gfxContentType contentType = ContentForFormat(mFormat); michael@0: nsRefPtr surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, contentType); michael@0: if (!surface || surface->GetType() != gfxSurfaceType::Xlib) { michael@0: NS_ERROR("creating Xlib surface failed!"); michael@0: return false; michael@0: } michael@0: michael@0: mSize = aSize; michael@0: mSurface = static_cast(surface.get()); michael@0: michael@0: // The host is always responsible for freeing the pixmap. michael@0: mSurface->ReleasePixmap(); michael@0: return true; michael@0: } michael@0: michael@0: TemporaryRef michael@0: TextureClientX11::GetAsDrawTarget() michael@0: { michael@0: MOZ_ASSERT(IsValid()); michael@0: if (!mSurface) { michael@0: return nullptr; michael@0: } michael@0: michael@0: IntSize size = ToIntSize(mSurface->GetSize()); michael@0: return Factory::CreateDrawTargetForCairoSurface(mSurface->CairoSurface(), size); michael@0: }