1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/basic/TextureClientX11.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 +// * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#include "mozilla/layers/TextureClientX11.h" 1.9 +#include "mozilla/layers/CompositableClient.h" 1.10 +#include "mozilla/layers/CompositableForwarder.h" 1.11 +#include "mozilla/layers/ISurfaceAllocator.h" 1.12 +#include "mozilla/layers/ShadowLayerUtilsX11.h" 1.13 +#include "mozilla/gfx/2D.h" 1.14 +#include "gfxXlibSurface.h" 1.15 +#include "gfx2DGlue.h" 1.16 + 1.17 +#include "mozilla/X11Util.h" 1.18 +#include <X11/Xlib.h> 1.19 + 1.20 +using namespace mozilla; 1.21 +using namespace mozilla::gfx; 1.22 +using namespace mozilla::layers; 1.23 + 1.24 +TextureClientX11::TextureClientX11(SurfaceFormat aFormat, TextureFlags aFlags) 1.25 + : TextureClient(aFlags), 1.26 + mFormat(aFormat), 1.27 + mLocked(false) 1.28 +{ 1.29 + MOZ_COUNT_CTOR(TextureClientX11); 1.30 +} 1.31 + 1.32 +TextureClientX11::~TextureClientX11() 1.33 +{ 1.34 + MOZ_COUNT_DTOR(TextureClientX11); 1.35 +} 1.36 + 1.37 +bool 1.38 +TextureClientX11::IsAllocated() const 1.39 +{ 1.40 + return !!mSurface; 1.41 +} 1.42 + 1.43 +bool 1.44 +TextureClientX11::Lock(OpenMode aMode) 1.45 +{ 1.46 + MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!"); 1.47 + mLocked = IsValid() && IsAllocated(); 1.48 + return mLocked; 1.49 +} 1.50 + 1.51 +void 1.52 +TextureClientX11::Unlock() 1.53 +{ 1.54 + MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!"); 1.55 + mLocked = false; 1.56 + 1.57 + if (mSurface) { 1.58 + FinishX(DefaultXDisplay()); 1.59 + } 1.60 +} 1.61 + 1.62 +bool 1.63 +TextureClientX11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) 1.64 +{ 1.65 + MOZ_ASSERT(IsValid()); 1.66 + if (!mSurface) { 1.67 + return false; 1.68 + } 1.69 + 1.70 + aOutDescriptor = SurfaceDescriptorX11(mSurface); 1.71 + return true; 1.72 +} 1.73 + 1.74 +TextureClientData* 1.75 +TextureClientX11::DropTextureData() 1.76 +{ 1.77 + MOZ_ASSERT(!(mFlags & TEXTURE_DEALLOCATE_CLIENT)); 1.78 + return nullptr; 1.79 +} 1.80 + 1.81 +bool 1.82 +TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags) 1.83 +{ 1.84 + MOZ_ASSERT(IsValid()); 1.85 + //MOZ_ASSERT(mFormat != gfx::FORMAT_YUV, "This TextureClient cannot use YCbCr data"); 1.86 + 1.87 + gfxContentType contentType = ContentForFormat(mFormat); 1.88 + nsRefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, contentType); 1.89 + if (!surface || surface->GetType() != gfxSurfaceType::Xlib) { 1.90 + NS_ERROR("creating Xlib surface failed!"); 1.91 + return false; 1.92 + } 1.93 + 1.94 + mSize = aSize; 1.95 + mSurface = static_cast<gfxXlibSurface*>(surface.get()); 1.96 + 1.97 + // The host is always responsible for freeing the pixmap. 1.98 + mSurface->ReleasePixmap(); 1.99 + return true; 1.100 +} 1.101 + 1.102 +TemporaryRef<DrawTarget> 1.103 +TextureClientX11::GetAsDrawTarget() 1.104 +{ 1.105 + MOZ_ASSERT(IsValid()); 1.106 + if (!mSurface) { 1.107 + return nullptr; 1.108 + } 1.109 + 1.110 + IntSize size = ToIntSize(mSurface->GetSize()); 1.111 + return Factory::CreateDrawTargetForCairoSurface(mSurface->CairoSurface(), size); 1.112 +}