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: michael@0: #include "X11TextureSourceBasic.h" michael@0: #include "mozilla/layers/BasicCompositor.h" michael@0: #include "gfxXlibSurface.h" michael@0: #include "gfx2DGlue.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::layers; michael@0: using namespace mozilla::gfx; michael@0: michael@0: X11TextureSourceBasic::X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface) michael@0: : mCompositor(aCompositor), michael@0: mSurface(aSurface) michael@0: { michael@0: } michael@0: michael@0: IntSize michael@0: X11TextureSourceBasic::GetSize() const michael@0: { michael@0: return ToIntSize(mSurface->GetSize()); michael@0: } michael@0: michael@0: SurfaceFormat michael@0: X11TextureSourceBasic::GetFormat() const michael@0: { michael@0: gfxContentType type = mSurface->GetContentType(); michael@0: return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); michael@0: } michael@0: michael@0: SourceSurface* michael@0: X11TextureSourceBasic::GetSurface(DrawTarget* aTarget) michael@0: { michael@0: if (!mSourceSurface) { michael@0: NativeSurface surf; michael@0: surf.mFormat = GetFormat(); michael@0: surf.mType = NativeSurfaceType::CAIRO_SURFACE; michael@0: surf.mSurface = mSurface->CairoSurface(); michael@0: surf.mSize = GetSize(); michael@0: mSourceSurface = aTarget->CreateSourceSurfaceFromNativeSurface(surf); michael@0: } michael@0: return mSourceSurface; michael@0: } michael@0: michael@0: void michael@0: X11TextureSourceBasic::SetCompositor(Compositor* aCompositor) michael@0: { michael@0: MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC); michael@0: BasicCompositor* compositor = static_cast(aCompositor); michael@0: mCompositor = compositor; michael@0: } michael@0: michael@0: SurfaceFormat michael@0: X11TextureSourceBasic::ContentTypeToSurfaceFormat(gfxContentType aType) michael@0: { michael@0: switch (aType) { michael@0: case gfxContentType::COLOR: michael@0: return SurfaceFormat::B8G8R8X8; michael@0: case gfxContentType::ALPHA: michael@0: return SurfaceFormat::A8; michael@0: case gfxContentType::COLOR_ALPHA: michael@0: return SurfaceFormat::B8G8R8A8; michael@0: default: michael@0: return SurfaceFormat::UNKNOWN; michael@0: } michael@0: }