1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/basic/X11TextureSourceBasic.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 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 + 1.9 +#include "X11TextureSourceBasic.h" 1.10 +#include "mozilla/layers/BasicCompositor.h" 1.11 +#include "gfxXlibSurface.h" 1.12 +#include "gfx2DGlue.h" 1.13 + 1.14 +using namespace mozilla; 1.15 +using namespace mozilla::layers; 1.16 +using namespace mozilla::gfx; 1.17 + 1.18 +X11TextureSourceBasic::X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface) 1.19 + : mCompositor(aCompositor), 1.20 + mSurface(aSurface) 1.21 +{ 1.22 +} 1.23 + 1.24 +IntSize 1.25 +X11TextureSourceBasic::GetSize() const 1.26 +{ 1.27 + return ToIntSize(mSurface->GetSize()); 1.28 +} 1.29 + 1.30 +SurfaceFormat 1.31 +X11TextureSourceBasic::GetFormat() const 1.32 +{ 1.33 + gfxContentType type = mSurface->GetContentType(); 1.34 + return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); 1.35 +} 1.36 + 1.37 +SourceSurface* 1.38 +X11TextureSourceBasic::GetSurface(DrawTarget* aTarget) 1.39 +{ 1.40 + if (!mSourceSurface) { 1.41 + NativeSurface surf; 1.42 + surf.mFormat = GetFormat(); 1.43 + surf.mType = NativeSurfaceType::CAIRO_SURFACE; 1.44 + surf.mSurface = mSurface->CairoSurface(); 1.45 + surf.mSize = GetSize(); 1.46 + mSourceSurface = aTarget->CreateSourceSurfaceFromNativeSurface(surf); 1.47 + } 1.48 + return mSourceSurface; 1.49 +} 1.50 + 1.51 +void 1.52 +X11TextureSourceBasic::SetCompositor(Compositor* aCompositor) 1.53 +{ 1.54 + MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC); 1.55 + BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor); 1.56 + mCompositor = compositor; 1.57 +} 1.58 + 1.59 +SurfaceFormat 1.60 +X11TextureSourceBasic::ContentTypeToSurfaceFormat(gfxContentType aType) 1.61 +{ 1.62 + switch (aType) { 1.63 + case gfxContentType::COLOR: 1.64 + return SurfaceFormat::B8G8R8X8; 1.65 + case gfxContentType::ALPHA: 1.66 + return SurfaceFormat::A8; 1.67 + case gfxContentType::COLOR_ALPHA: 1.68 + return SurfaceFormat::B8G8R8A8; 1.69 + default: 1.70 + return SurfaceFormat::UNKNOWN; 1.71 + } 1.72 +}