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 "MacIOSurfaceTextureClientOGL.h" michael@0: #include "mozilla/gfx/MacIOSurface.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(TextureFlags aFlags) michael@0: : TextureClient(aFlags) michael@0: , mIsLocked(false) michael@0: {} michael@0: michael@0: MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL() michael@0: {} michael@0: michael@0: void michael@0: MacIOSurfaceTextureClientOGL::InitWith(MacIOSurface* aSurface) michael@0: { michael@0: MOZ_ASSERT(IsValid()); michael@0: MOZ_ASSERT(!IsAllocated()); michael@0: mSurface = aSurface; michael@0: } michael@0: michael@0: bool michael@0: MacIOSurfaceTextureClientOGL::Lock(OpenMode aMode) michael@0: { michael@0: MOZ_ASSERT(!mIsLocked); michael@0: mIsLocked = true; michael@0: return IsValid() && IsAllocated(); michael@0: } michael@0: michael@0: void michael@0: MacIOSurfaceTextureClientOGL::Unlock() michael@0: { michael@0: MOZ_ASSERT(mIsLocked); michael@0: mIsLocked = false; michael@0: } michael@0: michael@0: bool michael@0: MacIOSurfaceTextureClientOGL::IsLocked() const michael@0: { michael@0: return mIsLocked; michael@0: } michael@0: michael@0: bool michael@0: MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) michael@0: { michael@0: MOZ_ASSERT(IsValid()); michael@0: if (!IsAllocated()) { michael@0: return false; michael@0: } michael@0: aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(), michael@0: mSurface->GetContentsScaleFactor(), michael@0: mSurface->HasAlpha()); michael@0: return true; michael@0: } michael@0: michael@0: gfx::IntSize michael@0: MacIOSurfaceTextureClientOGL::GetSize() const michael@0: { michael@0: return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight()); michael@0: } michael@0: michael@0: class MacIOSurfaceTextureClientData : public TextureClientData michael@0: { michael@0: public: michael@0: MacIOSurfaceTextureClientData(MacIOSurface* aSurface) michael@0: : mSurface(aSurface) michael@0: {} michael@0: michael@0: virtual void DeallocateSharedData(ISurfaceAllocator*) MOZ_OVERRIDE michael@0: { michael@0: mSurface = nullptr; michael@0: } michael@0: michael@0: private: michael@0: RefPtr mSurface; michael@0: }; michael@0: michael@0: TextureClientData* michael@0: MacIOSurfaceTextureClientOGL::DropTextureData() michael@0: { michael@0: TextureClientData* data = new MacIOSurfaceTextureClientData(mSurface); michael@0: mSurface = nullptr; michael@0: MarkInvalid(); michael@0: return data; michael@0: } michael@0: michael@0: } michael@0: }