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 "MacIOSurfaceTextureHostBasic.h" michael@0: #include "mozilla/layers/BasicCompositor.h" michael@0: #include "mozilla/gfx/MacIOSurface.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: MacIOSurfaceTextureSourceBasic::MacIOSurfaceTextureSourceBasic( michael@0: BasicCompositor* aCompositor, michael@0: MacIOSurface* aSurface) michael@0: : mCompositor(aCompositor) michael@0: , mSurface(aSurface) michael@0: {} michael@0: michael@0: MacIOSurfaceTextureSourceBasic::~MacIOSurfaceTextureSourceBasic() michael@0: { michael@0: } michael@0: michael@0: gfx::IntSize michael@0: MacIOSurfaceTextureSourceBasic::GetSize() const michael@0: { michael@0: return gfx::IntSize(mSurface->GetDevicePixelWidth(), michael@0: mSurface->GetDevicePixelHeight()); michael@0: } michael@0: michael@0: gfx::SurfaceFormat michael@0: MacIOSurfaceTextureSourceBasic::GetFormat() const michael@0: { michael@0: return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8; michael@0: } michael@0: michael@0: MacIOSurfaceTextureHostBasic::MacIOSurfaceTextureHostBasic( michael@0: TextureFlags aFlags, michael@0: const SurfaceDescriptorMacIOSurface& aDescriptor michael@0: ) michael@0: : TextureHost(aFlags) michael@0: { michael@0: mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(), michael@0: aDescriptor.scaleFactor(), michael@0: aDescriptor.hasAlpha()); michael@0: } michael@0: michael@0: gfx::SourceSurface* michael@0: MacIOSurfaceTextureSourceBasic::GetSurface(gfx::DrawTarget* aTarget) michael@0: { michael@0: if (!mSourceSurface) { michael@0: mSourceSurface = mSurface->GetAsSurface(); michael@0: } michael@0: return mSourceSurface; michael@0: } michael@0: michael@0: void michael@0: MacIOSurfaceTextureSourceBasic::SetCompositor(Compositor* aCompositor) michael@0: { michael@0: mCompositor = static_cast(aCompositor); michael@0: } michael@0: michael@0: bool michael@0: MacIOSurfaceTextureHostBasic::Lock() michael@0: { michael@0: if (!mCompositor) { michael@0: return false; michael@0: } michael@0: michael@0: if (!mTextureSource) { michael@0: mTextureSource = new MacIOSurfaceTextureSourceBasic(mCompositor, mSurface); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: MacIOSurfaceTextureHostBasic::SetCompositor(Compositor* aCompositor) michael@0: { michael@0: BasicCompositor* compositor = static_cast(aCompositor); michael@0: mCompositor = compositor; michael@0: if (mTextureSource) { michael@0: mTextureSource->SetCompositor(compositor); michael@0: } michael@0: } michael@0: michael@0: gfx::SurfaceFormat michael@0: MacIOSurfaceTextureHostBasic::GetFormat() const { michael@0: return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8; michael@0: } michael@0: michael@0: gfx::IntSize michael@0: MacIOSurfaceTextureHostBasic::GetSize() const { michael@0: return gfx::IntSize(mSurface->GetDevicePixelWidth(), michael@0: mSurface->GetDevicePixelHeight()); michael@0: } michael@0: michael@0: } michael@0: }